test/jdk/javadoc/tool/T4994049/T4994049.java
Print this page
*** 28,52 ****
* @author Peter von der Ah\u00e9
* @modules jdk.javadoc
* @run main T4994049 FileWithTabs.java
*/
- import com.sun.javadoc.*;
import java.io.*;
! import static com.sun.tools.javadoc.Main.execute;
! public class T4994049 extends Doclet {
! public static boolean start(RootDoc root) {
! for (ClassDoc klass : root.classes()) {
! for (MethodDoc method : klass.methods()) {
! if (method.name().equals("tabbedMethod")) {
! if (method.position().column() == 21) {
! System.out.println(method.position().column() + ": OK!");
return true;
} else {
! System.err.println(method.position() + ": wrong tab expansion");
return false;
}
}
}
}
--- 28,79 ----
* @author Peter von der Ah\u00e9
* @modules jdk.javadoc
* @run main T4994049 FileWithTabs.java
*/
import java.io.*;
! import java.util.ArrayList;
! import java.util.Collections;
! import java.util.List;
! import java.util.Locale;
! import java.util.Set;
! import javax.lang.model.SourceVersion;
! import javax.lang.model.element.ElementKind;
! import javax.lang.model.element.ExecutableElement;
! import javax.lang.model.element.TypeElement;
! import com.sun.source.tree.CompilationUnitTree;
! import com.sun.source.tree.LineMap;
! import com.sun.source.util.DocTrees;
! import com.sun.source.util.SourcePositions;
! import com.sun.source.util.TreePath;
! import jdk.javadoc.doclet.Doclet;
! import jdk.javadoc.doclet.Reporter;
! import jdk.javadoc.doclet.DocletEnvironment;
!
! import static jdk.javadoc.internal.tool.Main.execute;
!
! public class T4994049 implements Doclet {
!
! public boolean run(DocletEnvironment root) {
! DocTrees trees = root.getDocTrees();
!
! SourcePositions sourcePositions = trees.getSourcePositions();
! for (TypeElement klass : root.getIncludedClasses()) {
! for (ExecutableElement method : getMethods(klass)) {
! if (method.getSimpleName().toString().equals("tabbedMethod")) {
! TreePath path = trees.getPath(method);
! CompilationUnitTree cu = path.getCompilationUnit();
! long pos = sourcePositions.getStartPosition(cu, path.getLeaf());
! LineMap lineMap = cu.getLineMap();
! long columnNumber = lineMap.getColumnNumber(pos);
! if (columnNumber == 9) {
! System.out.println(columnNumber + ": OK!");
return true;
} else {
! System.err.println(columnNumber + ": wrong tab expansion");
return false;
}
}
}
}
*** 56,69 ****
public static void main(String... args) throws Exception {
File testSrc = new File(System.getProperty("test.src"));
File tmpSrc = new File("tmpSrc");
initTabs(testSrc, tmpSrc);
for (String file : args) {
File source = new File(tmpSrc, file);
! int rc = execute("javadoc", "T4994049", T4994049.class.getClassLoader(),
! new String[]{ source.getPath() } );
if (rc != 0)
throw new Error("Unexpected return code from javadoc: " + rc);
}
}
--- 83,101 ----
public static void main(String... args) throws Exception {
File testSrc = new File(System.getProperty("test.src"));
File tmpSrc = new File("tmpSrc");
initTabs(testSrc, tmpSrc);
+
for (String file : args) {
File source = new File(tmpSrc, file);
! String[] array = {
! "-docletpath", System.getProperty("test.classes", "."),
! "-doclet", "T4994049",
! source.getPath()
! };
! int rc = execute(array);
if (rc != 0)
throw new Error("Unexpected return code from javadoc: " + rc);
}
}
*** 95,100 ****
--- 127,162 ----
try (Writer out = new FileWriter(f)) {
out.write(s);
}
}
+ List<ExecutableElement> getMethods(TypeElement klass) {
+ List<ExecutableElement> methods = new ArrayList<>();
+ klass.getEnclosedElements()
+ .stream()
+ .filter((e) -> (e.getKind() == ElementKind.METHOD))
+ .forEach((e) -> {
+ methods.add((ExecutableElement) e);
+ });
+ return methods;
+ }
+
+ @Override
+ public String getName() {
+ return "Test";
+ }
+
+ @Override
+ public Set<Option> getSupportedOptions() {
+ return Collections.emptySet();
+ }
+
+ @Override
+ public SourceVersion getSupportedSourceVersion() {
+ return SourceVersion.latest();
+ }
+
+ @Override
+ public void init(Locale locale, Reporter reporter) {
+ return;
+ }
}