public GroovyDocTool(ResourceManager resourceManager, String[] sourcepaths, String[] docTemplates, String[] packageTemplates, String[] classTemplates, List<LinkArgument> links, Properties properties) { rootDocBuilder = new GroovyRootDocBuilder(this, sourcepaths, links, properties); String defaultCharset = Charset.defaultCharset().name(); String fileEncoding = properties.getProperty("fileEncoding"); String charset = properties.getProperty("charset"); if (fileEncoding == null || fileEncoding.length() == 0) fileEncoding = charset; if (charset == null || charset.length() == 0) charset = fileEncoding; properties.setProperty("fileEncoding", fileEncoding != null && fileEncoding.length() != 0 ? fileEncoding : defaultCharset); properties.setProperty("charset", charset != null && charset.length() != 0 ? charset : defaultCharset); this.properties = properties; if (resourceManager == null) { templateEngine = null; } else { templateEngine = new GroovyDocTemplateEngine(this, resourceManager, docTemplates, packageTemplates, classTemplates, properties); } }
public void add(List<String> filenames) throws RecognitionException, TokenStreamException, IOException { if (templateEngine != null) { // only print out if we are being used for template generation log.debug("Loading source files for " + filenames); } rootDocBuilder.buildTree(filenames); }
packagePath = relPackage; processPackageInfo(src, filename, packageDoc); rootDoc.put(packagePath, packageDoc); return; Map<String, GroovyClassDoc> classDocs = getClassDocsFromSingleSource(packagePath, file, src); rootDoc.putAllClasses(classDocs); if (isAbsolute) {
public Map<String, GroovyClassDoc> getClassDocsFromSingleSource(String packagePath, String file, String src) throws RecognitionException, TokenStreamException { if (file.indexOf(".java") > 0) { // simple (for now) decision on java or groovy // java return parseJava(packagePath, file, src); } if (file.indexOf(".sourcefile") > 0) { // java (special name used for testing) return parseJava(packagePath, file, src); } // not java, try groovy instead :-) return parseGroovy(packagePath, file, src); }
/* package private */ void processPackageInfo(String src, String filename, SimpleGroovyPackageDoc packageDoc) { String relPath = packageDoc.getRelativeRootPath(); String description = calcThenSetPackageDescription(src, filename, relPath); packageDoc.setDescription(description); // get same description but with paths relative to root String altDescription = calcThenSetPackageDescription(src, filename, ""); calcThenSetSummary(altDescription, packageDoc); }
public void testCommentExtraction() throws Exception { GroovyRootDocBuilder builder = new GroovyRootDocBuilder(null, null, new ArrayList<LinkArgument>(), null); SimpleGroovyPackageDoc doc = new SimpleGroovyPackageDoc("org.dummy.cmdline"); builder.processPackageInfo(src, "package-info.groovy", doc); assertEquals("<h1>Description</h1>\n" + " This class is used by an application to process the command line\n" + " that invokes it. The processing of the command line proceeds in\n" + " the following steps.\n" + " <ol>\n" + " <li>Create an <code>CmdLine</code> object specifying the properties\n" + " that control how the command line is to be processed and what\n" + " options the program supports.</li>\n" + " <li>Call \n" + " org.dummy.cmdline.CmdLine#processCmdLine()\n" + " to process the command line.</li>", doc.description().trim()); } }
public GroovyRootDoc getRootDoc() { return rootDocBuilder.getRootDoc(); }
private Map<String, GroovyClassDoc> parseGroovy(String packagePath, String file, String src) throws RecognitionException, TokenStreamException { SourceBuffer sourceBuffer = new SourceBuffer(); GroovyRecognizer parser = getGroovyParser(src, sourceBuffer); try { parser.compilationUnit(); } catch (OutOfMemoryError e) { log.error("Out of memory while processing: " + packagePath + "/" + file); throw e; } AST ast = parser.getAST(); // now do the business Visitor visitor = new SimpleGroovyClassDocAssembler(packagePath, file, sourceBuffer, links, properties, true); AntlrASTProcessor traverser = new SourceCodeTraversal(visitor); traverser.process(ast); return ((SimpleGroovyClassDocAssembler) visitor).getGroovyClassDocs(); }
private Map<String, GroovyClassDoc> parseJava(String packagePath, String file, String src) throws RecognitionException, TokenStreamException { SourceBuffer sourceBuffer = new SourceBuffer(); JavaRecognizer parser = getJavaParser(src, sourceBuffer); String[] tokenNames = parser.getTokenNames(); try { parser.compilationUnit(); } catch (OutOfMemoryError e) { log.error("Out of memory while processing: " + packagePath + "/" + file); throw e; } AST ast = parser.getAST(); // modify the Java AST into a Groovy AST (just token types) Visitor java2groovyConverter = new Java2GroovyConverter(tokenNames); AntlrASTProcessor java2groovyTraverser = new PreOrderTraversal(java2groovyConverter); java2groovyTraverser.process(ast); // now mutate (groovify) the ast into groovy Visitor groovifier = new Groovifier(tokenNames, false); AntlrASTProcessor groovifierTraverser = new PreOrderTraversal(groovifier); groovifierTraverser.process(ast); // now do the business Visitor visitor = new SimpleGroovyClassDocAssembler(packagePath, file, sourceBuffer, links, properties, false); AntlrASTProcessor traverser = new SourceCodeTraversal(visitor); traverser.process(ast); return ((SimpleGroovyClassDocAssembler) visitor).getGroovyClassDocs(); }
private void setOverview() { String path = properties.getProperty("overviewFile"); if (path != null && path.length() > 0) { try { String content = ResourceGroovyMethods.getText(new File(path)); calcThenSetOverviewDescription(content); } catch (IOException e) { System.err.println("Unable to load overview file: " + e.getMessage()); } } }
private void processFile(String filename, File srcFile) throws IOException { String src = DefaultGroovyMethods.getText(srcFile); String packagePath = tool.getPath(filename).replace('\\', FS); String file = tool.getFile(filename); SimpleGroovyPackageDoc packageDoc = (SimpleGroovyPackageDoc) rootDoc.packageNamed(packagePath); if (packageDoc == null) { packageDoc = new SimpleGroovyPackageDoc(packagePath); } if (filename.endsWith("package.html")) { processHtmlPackage(src, packageDoc); return; } try { Map<String, GroovyClassDoc> classDocs = getClassDocsFromSingleSource(packagePath, file, src); rootDoc.putAllClasses(classDocs); packageDoc.putAll(classDocs); rootDoc.put(packagePath, packageDoc); } catch (RecognitionException e) { System.err.println("ignored due to RecognitionException: " + filename + " [" + e.getMessage() + "]"); } catch (TokenStreamException e) { System.err.println("ignored due to TokenStreamException: " + filename + " [" + e.getMessage() + "]"); } }
String file = tool.getFile(filename); try { Map classDocs = getClassDocsFromSingleSource(packagePath, file, src);
public Map<String, GroovyClassDoc> getClassDocsFromSingleSource(String packagePath, String file, String src) throws RecognitionException, TokenStreamException { if (file.indexOf(".java") > 0) { // simple (for now) decision on java or groovy // java return parseJava(packagePath, file, src); } if (file.indexOf(".sourcefile") > 0) { // java (special name used for testing) return parseJava(packagePath, file, src); } // not java, try groovy instead :-) return parseGroovy(packagePath, file, src); }
private void processHtmlPackage(String src, SimpleGroovyPackageDoc packageDoc) { String description = calcThenSetPackageDescription(src, packageDoc); calcThenSetSummary(description, packageDoc); }
public void renderToOutput(OutputTool output, String destdir) throws Exception { // expect just one scope to be set on the way in but now also set higher levels of visibility if ("true".equals(properties.getProperty("privateScope"))) properties.setProperty("packageScope", "true"); if ("true".equals(properties.getProperty("packageScope"))) properties.setProperty("protectedScope", "true"); if ("true".equals(properties.getProperty("protectedScope"))) properties.setProperty("publicScope", "true"); if (templateEngine != null) { GroovyDocWriter writer = new GroovyDocWriter(this, output, templateEngine, properties); GroovyRootDoc rootDoc = rootDocBuilder.getRootDoc(); writer.writeRoot(rootDoc, destdir); writer.writePackages(rootDoc, destdir); writer.writeClasses(rootDoc, destdir); } else { throw new UnsupportedOperationException("No template engine was found"); } }
private Map<String, GroovyClassDoc> parseGroovy(String packagePath, String file, String src) throws RecognitionException, TokenStreamException { SourceBuffer sourceBuffer = new SourceBuffer(); GroovyRecognizer parser = getGroovyParser(src, sourceBuffer); try { parser.compilationUnit(); } catch (OutOfMemoryError e) { System.out.println("Out of memory while processing: " + packagePath + "/" + file); throw e; } AST ast = parser.getAST(); // now do the business Visitor visitor = new SimpleGroovyClassDocAssembler(packagePath, file, sourceBuffer, links, properties, true); AntlrASTProcessor traverser = new SourceCodeTraversal(visitor); traverser.process(ast); return ((SimpleGroovyClassDocAssembler) visitor).getGroovyClassDocs(); }
private Map<String, GroovyClassDoc> parseJava(String packagePath, String file, String src) throws RecognitionException, TokenStreamException { SourceBuffer sourceBuffer = new SourceBuffer(); JavaRecognizer parser = getJavaParser(src, sourceBuffer); String[] tokenNames = parser.getTokenNames(); try { parser.compilationUnit(); } catch (OutOfMemoryError e) { System.out.println("Out of memory while processing: " + packagePath + "/" + file); throw e; } AST ast = parser.getAST(); // modify the Java AST into a Groovy AST (just token types) Visitor java2groovyConverter = new Java2GroovyConverter(tokenNames); AntlrASTProcessor java2groovyTraverser = new PreOrderTraversal(java2groovyConverter); java2groovyTraverser.process(ast); // now mutate (groovify) the ast into groovy Visitor groovifier = new Groovifier(tokenNames); AntlrASTProcessor groovifierTraverser = new PreOrderTraversal(groovifier); groovifierTraverser.process(ast); // now do the business Visitor visitor = new SimpleGroovyClassDocAssembler(packagePath, file, sourceBuffer, links, properties, false); AntlrASTProcessor traverser = new SourceCodeTraversal(visitor); traverser.process(ast); return ((SimpleGroovyClassDocAssembler) visitor).getGroovyClassDocs(); }
private void setOverview() { String path = properties.getProperty("overviewFile"); if (path != null && path.length() > 0) { try { String content = DefaultGroovyMethods.getText(new File(path)); calcThenSetOverviewDescription(content); } catch (IOException e) { System.err.println("Unable to load overview file: " + e.getMessage()); } } }
public Map<String, GroovyClassDoc> getClassDocsFromSingleSource(String packagePath, String file, String src) throws RecognitionException, TokenStreamException { if (file.indexOf(".java") > 0) { // simple (for now) decision on java or groovy // java return parseJava(packagePath, file, src); } if (file.indexOf(".sourcefile") > 0) { // java (special name used for testing) return parseJava(packagePath, file, src); } // not java, try groovy instead :-) return parseGroovy(packagePath, file, src); }
/* package private */ void processPackageInfo(String src, String filename, SimpleGroovyPackageDoc packageDoc) { String description = calcThenSetPackageDescription(src, filename, packageDoc); calcThenSetSummary(description, packageDoc); }