if (errors) thrownew AssertionError("errors occurred creating trees");
ScopeScanner s = new ScopeScanner(); for (CompilationUnitTree unit: units) {
TreePath p = new TreePath(unit);
s.scan(p, getTrees());
additionalChecks(getTrees(), unit);
}
task = null;
if (errors) thrownew AssertionError("errors occurred checking scopes");
}
}
// default impl: split ref at ";" and call checkLocal(scope, ref_segment) on scope and its enclosing scopes protectedboolean check(Scope s, String ref) { // System.err.println("check scope: " + s); // System.err.println("check ref: " + ref); if (s == null && (ref == null || ref.trim().length() == 0)) returntrue;
if (s == null) {
error(s, ref, "scope missing"); returnfalse;
}
protected Elements getElements() { return task.getElements();
}
protected Trees getTrees() { return Trees.instance(task);
}
boolean errors = false; protected JavacTask task;
// scan a parse tree, and for every string literal found, call check(scope, string) with // the string value at the scope at that point class ScopeScanner extends TreePathScanner<Boolean,Trees> { publicBoolean visitLiteral(LiteralTree tree, Trees trees) {
TreePath path = getCurrentPath();
CompilationUnitTree unit = path.getCompilationUnit();
Position.LineMap lineMap = ((JCCompilationUnit)unit).lineMap; // long line = lineMap.getLineNumber(((JCTree)tree).pos/*trees.getSourcePositions().getStartPosition(tree)*/); // System.err.println(line + ": " + abbrev(tree));
Scope s = trees.getScope(path); if (tree.getKind() == Tree.Kind.STRING_LITERAL)
check(s, tree.getValue().toString().trim()); returnnull;
}
private String abbrev(Tree tree) { int max = 48;
String s = tree.toString().replaceAll("[ \n]+", " "); return (s.length() < max ? s : s.substring(0, max-3) + "...");
}
}
// prefix filenames with a directory static Iterable<File> getFiles(File dir, String... names) {
List<File> files = new ArrayList<File>(names.length); for (String name: names)
files.add(new File(dir, name)); return files;
}
staticprivate <T> List<T> asList(Iterable<T> iter) {
List<T> l = new ArrayList<T>(); for (T t: iter)
l.add(t); return l;
}
}
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 und die Messung sind noch experimentell.