protected DocGenerator generator() { return new JavaDocGenerator(); } }
@Override public String resolveTypeLink(TypeElement elt, Coordinate coordinate) { return javaGen.resolveTypeLink(elt, coordinate); }
@Override public String resolveConstructorLink(ExecutableElement elt, Coordinate coordinate) { return javaGen.resolveConstructorLink(elt, coordinate); }
} else { JavaDocGenerator javaGen = new JavaDocGenerator(); javaGen.init(processingEnv); fragment = javaGen.renderSource((ExecutableElement) elt, source); case ANNOTATION_TYPE: TypeElement typeElt = (TypeElement) elt; JavaDocGenerator javaGen = new JavaDocGenerator(); javaGen.init(processingEnv); fragment = javaGen.renderSource(typeElt, source); if (fragment != null) { writer.literalMode();
@Override public String renderSource(ExecutableElement elt, String source) { return super.renderSource(elt, source).toUpperCase(); } };
@Override public void init(ProcessingEnvironment processingEnv) { translator = new CodeTranslator(processingEnv); javaGen.init(processingEnv); }
@Override public String resolveMethodLink(ExecutableElement elt, Coordinate coordinate) { return toExecutableLink(elt, elt.getSimpleName().toString()); }
@Override public String resolveFieldLink(VariableElement elt, Coordinate coordinate) { return javaGen.resolveFieldLink(elt, coordinate); } }
@Override public String resolveMethodLink(ExecutableElement elt, Coordinate coordinate) { return javaGen.resolveMethodLink(elt, coordinate); }
@Override public String resolveLabel(Element elt, String defaultLabel) { return javaGen.resolveLabel(elt, defaultLabel); }
public String renderSource(TypeElement elt, String source) { TreePath path = docTrees.getPath(elt); ClassTree classTree = (ClassTree) path.getLeaf(); return renderSource(path, Collections.singletonList(classTree), source); }
@Override public String resolveConstructorLink(ExecutableElement elt, Coordinate coordinate) { return toExecutableLink(elt, elt.getEnclosingElement().getSimpleName().toString()); }
@Test public void testLinkGenerationWithAnnotation() throws Exception { String pkg = "io.vertx.test.linktomethod"; Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File file = new File(dir, pkg + ".adoc"); List<String> lines = Files.readAllLines(file.toPath()); for (String line : lines) { // The :: is used when the annotated type is used. assertFalse(line.contains("::")); } }
/** * Render the source fragment for the Java language. Java being the pivot language, we consider this method as the * _default_ behavior. This method is final as it must not be overridden by any extension. * * @param elt the element * @param source the source * @return the fragment */ @Override public String renderSource(ExecutableElement elt, String source) { // Get block TreePath path = docTrees.getPath(elt); MethodTree methodTree = (MethodTree) path.getLeaf(); BlockTree blockTree = methodTree.getBody(); List<? extends StatementTree> statements = blockTree.getStatements(); if (statements.size() > 0) { return renderSource(path, statements, source); } else { return null; } }
@Override public String resolveFieldLink(VariableElement elt, Coordinate coordinate) { TypeElement typeElt = (TypeElement) elt.getEnclosingElement(); String link = resolveTypeLink(typeElt, null); return link + "#" + elt.getSimpleName(); }
@Test public void testGeneration() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File file = new File(dir, pkg + ".adoc"); assertTrue(file.exists()); assertTrue(file.isFile()); } }
private String toExecutableLink(ExecutableElement elt, String name) { TypeElement typeElt = (TypeElement) elt.getEnclosingElement(); String link = resolveTypeLink(typeElt, null); StringBuilder anchor = new StringBuilder("#"); anchor.append(name).append('-'); TypeMirror type = elt.asType(); ExecutableType methodType = (ExecutableType) processingEnv.getTypeUtils().erasure(type); List<? extends TypeMirror> parameterTypes = methodType.getParameterTypes(); for (int i = 0; i < parameterTypes.size(); i++) { if (i > 0) { anchor.append('-'); } // We need to check whether or not the parameter is annotated. In this case, we must use the unannotated type. TypeMirror typeOfParameter = parameterTypes.get(i); if (typeOfParameter instanceof Type && ((Type) typeOfParameter).isAnnotated()) { anchor.append(((Type) typeOfParameter).unannotatedType().toString()); } else { anchor.append(typeOfParameter.toString()); } } anchor.append('-'); return link + anchor; }
@Test public void testOutputInterpolation() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", new File(dir, "$lang").getAbsolutePath()); compiler.setOption("docgen.extension", ".ad.txt"); compiler.assertCompile(); File file = new File(new File(dir, "java"), pkg + ".ad.txt"); assertTrue(file.exists()); assertTrue(file.isFile()); } } }
@Test public void testFileName() throws Exception { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), "io.vertx.test.filename"); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.assertCompile(); File f1 = new File(dir, "index.adoc"); assertTrue(f1.exists()); assertTrue(f1.isFile()); File f2 = new File(dir, "sub" + File.separator + "index.adoc"); assertTrue(f2.exists()); assertTrue(f2.isFile()); assertEquals("sub/index.adoc", new String(Files.readAllBytes(f1.toPath()))); }
@Test public void testExtension() throws Exception { for (String pkg : Arrays.asList("io.vertx.test.linktoclass", "io.vertx.test.linktoconstructor", "io.vertx.test.linktomethod", "io.vertx.test.linktofield")) { Compiler<DocGenProcessor> compiler = BaseProcessorTest.buildCompiler(new DocGenProcessor(new JavaDocGenerator()), pkg); File dir = Files.createTempDirectory("docgen").toFile(); dir.deleteOnExit(); compiler.setOption("docgen.output", dir.getAbsolutePath()); compiler.setOption("docgen.extension", ".ad.txt"); compiler.assertCompile(); File file = new File(dir, pkg + ".ad.txt"); assertTrue(file.exists()); assertTrue(file.isFile()); } }