/* * @test /nodynamiccopyright/ * @bug 6406771 * @summary CompilationUnitTree needs access to a line map * @modules jdk.compiler/com.sun.tools.javac.api * jdk.compiler/com.sun.tools.javac.file * jdk.compiler/com.sun.tools.javac.tree
*/
// WARNING: White-space and layout is important in this file, especially tab characters. // Editing the imports and other leading text may affect the golden text in the tests field. // Also beware of scripts that auto-expand tabs to spaces.
if (!task.call()) thrownew AssertionError("failed");
}
}
publicboolean process(Set<? extends TypeElement> elems, RoundEnvironment rEnv) { final String LINE = "line" + ':'; // avoid matching this string final String COLUMN = "col" + ':'; final Messager messager = processingEnv.getMessager(); final Trees trees = Trees.instance(processingEnv);
TreeScanner<Void,LineMap> s = new TreeScanner<Void,LineMap>() { publicVoid visitLiteral(LiteralTree tree, LineMap lineMap) { if (tree.getKind() == Tree.Kind.STRING_LITERAL) {
String s = (String) tree.getValue(); int pos = ((JCTree) tree).pos; // can't get through public api, bug 6412669 filed
String prefix; long found; if (s.startsWith(LINE)) {
prefix = LINE;
found = lineMap.getLineNumber(pos);
} elseif (s.startsWith(COLUMN)) {
prefix = COLUMN;
found = lineMap.getColumnNumber(pos);
} else returnnull; int expect = Integer.parseInt(s.substring(prefix.length())); if (expect != found) {
messager.printError("Error: " + prefix + " pos=" + pos
+ " expect=" + expect + " found=" + found);
}
} returnnull;
}
};
for (Element e: rEnv.getRootElements()) {
System.err.println(e);
Tree t = trees.getTree(e);
TreePath p = trees.getPath(e);
s.scan(p.getLeaf(), p.getCompilationUnit().getLineMap());
}
returntrue;
}
@Override public SourceVersion getSupportedSourceVersion() { return SourceVersion.latest();
}
}
¤ Dauer der Verarbeitung: 0.11 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.