use of com.sun.tools.javac.tree.JCTree.JCCompilationUnit in project lombok by rzwitserloot.
the class JavacAST method removeFromDeferredDiagnostics.
public void removeFromDeferredDiagnostics(int startPos, int endPos) {
JCCompilationUnit self = (JCCompilationUnit) top().get();
new CompilerMessageSuppressor(getContext()).removeAllBetween(self.sourcefile, startPos, endPos);
}
use of com.sun.tools.javac.tree.JCTree.JCCompilationUnit in project lombok by rzwitserloot.
the class JavacAST method printMessage.
/** Supply either a position or a node (in that case, position of the node is used) */
void printMessage(Diagnostic.Kind kind, String message, JavacNode node, DiagnosticPosition pos, boolean attemptToRemoveErrorsInRange) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
JCTree astObject = node == null ? null : node.get();
JCCompilationUnit top = (JCCompilationUnit) top().get();
newSource = top.sourcefile;
if (newSource != null) {
oldSource = log.useSource(newSource);
if (pos == null)
pos = astObject.pos();
}
if (pos != null && attemptToRemoveErrorsInRange) {
removeFromDeferredDiagnostics(pos.getStartPosition(), node.getEndPosition(pos));
}
try {
switch(kind) {
case ERROR:
increaseErrorCount(messager);
boolean prev = log.multipleErrors;
log.multipleErrors = true;
try {
log.error(pos, "proc.messager", message);
} finally {
log.multipleErrors = prev;
}
break;
default:
case WARNING:
log.warning(pos, "proc.messager", message);
break;
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}
use of com.sun.tools.javac.tree.JCTree.JCCompilationUnit in project lombok by rzwitserloot.
the class LombokProcessor method process.
/** {@inheritDoc} */
@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
if (lombokDisabled)
return false;
if (roundEnv.processingOver())
return false;
for (Element element : roundEnv.getRootElements()) {
JCCompilationUnit unit = toUnit(element);
if (unit == null)
continue;
if (roots.containsKey(unit))
continue;
roots.put(unit, priorityLevels[0]);
}
while (true) {
for (long prio : priorityLevels) {
List<JCCompilationUnit> cusForThisRound = new ArrayList<JCCompilationUnit>();
for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) {
Long prioOfCu = entry.getValue();
if (prioOfCu == null || prioOfCu != prio)
continue;
cusForThisRound.add(entry.getKey());
}
transformer.transform(prio, processingEnv.getContext(), cusForThisRound);
}
// Step 3: Push up all CUs to the next level. Set level to null if there is no next level.
Set<Long> newLevels = new HashSet<Long>();
for (int i = priorityLevels.length - 1; i >= 0; i--) {
Long curLevel = priorityLevels[i];
Long nextLevel = (i == priorityLevels.length - 1) ? null : priorityLevels[i + 1];
List<JCCompilationUnit> cusToAdvance = new ArrayList<JCCompilationUnit>();
for (Map.Entry<JCCompilationUnit, Long> entry : roots.entrySet()) {
if (curLevel.equals(entry.getValue())) {
cusToAdvance.add(entry.getKey());
newLevels.add(nextLevel);
}
}
for (JCCompilationUnit unit : cusToAdvance) {
roots.put(unit, nextLevel);
}
}
newLevels.remove(null);
if (newLevels.isEmpty())
return false;
newLevels.retainAll(priorityLevelsRequiringResolutionReset);
if (!newLevels.isEmpty()) {
// Force a new round to reset resolution. The next round will cause this method (process) to be called again.
forceNewRound((JavacFiler) processingEnv.getFiler());
return false;
}
// None of the new levels need resolution, so just keep going.
}
}
use of com.sun.tools.javac.tree.JCTree.JCCompilationUnit in project lombok by rzwitserloot.
the class JavacTransformer method transform.
public void transform(long priority, Context context, java.util.List<JCCompilationUnit> compilationUnitsRaw) {
List<JCCompilationUnit> compilationUnits;
if (compilationUnitsRaw instanceof List<?>) {
compilationUnits = (List<JCCompilationUnit>) compilationUnitsRaw;
} else {
compilationUnits = List.nil();
for (int i = compilationUnitsRaw.size() - 1; i >= 0; i--) {
compilationUnits = compilationUnits.prepend(compilationUnitsRaw.get(i));
}
}
java.util.List<JavacAST> asts = new ArrayList<JavacAST>();
for (JCCompilationUnit unit : compilationUnits) asts.add(new JavacAST(messager, context, unit));
for (JavacAST ast : asts) {
ast.traverse(new AnnotationVisitor(priority));
handlers.callASTVisitors(ast, priority);
}
for (JavacAST ast : asts) if (ast.isChanged())
LombokOptions.markChanged(context, (JCCompilationUnit) ast.top().get());
}
use of com.sun.tools.javac.tree.JCTree.JCCompilationUnit in project ceylon-compiler by ceylon.
the class JavadocTool method getRootDocImpl.
public RootDocImpl getRootDocImpl(String doclocale, String encoding, ModifierFilter filter, List<String> javaNames, List<String[]> options, boolean breakiterator, List<String> subPackages, List<String> excludedPackages, boolean docClasses, boolean legacyDoclet, boolean quiet) throws IOException {
docenv = DocEnv.instance(context);
docenv.showAccess = filter;
docenv.quiet = quiet;
docenv.breakiterator = breakiterator;
docenv.setLocale(doclocale);
docenv.setEncoding(encoding);
docenv.docClasses = docClasses;
docenv.legacyDoclet = legacyDoclet;
reader.sourceCompleter = docClasses ? null : this;
ListBuffer<String> names = new ListBuffer<String>();
ListBuffer<JCCompilationUnit> classTrees = new ListBuffer<JCCompilationUnit>();
ListBuffer<JCCompilationUnit> packTrees = new ListBuffer<JCCompilationUnit>();
try {
StandardJavaFileManager fm = (StandardJavaFileManager) docenv.fileManager;
for (List<String> it = javaNames; it.nonEmpty(); it = it.tail) {
String name = it.head;
if (!docClasses && name.endsWith(".java") && new File(name).exists()) {
JavaFileObject fo = fm.getJavaFileObjects(name).iterator().next();
docenv.notice("main.Loading_source_file", name);
JCCompilationUnit tree = parse(fo);
classTrees.append(tree);
} else if (isValidPackageName(name)) {
names = names.append(name);
} else if (name.endsWith(".java")) {
docenv.error(null, "main.file_not_found", name);
} else {
docenv.error(null, "main.illegal_package_name", name);
}
}
if (!docClasses) {
// Recursively search given subpackages. If any packages
//are found, add them to the list.
Map<String, List<JavaFileObject>> packageFiles = searchSubPackages(subPackages, names, excludedPackages);
// Parse the packages
for (List<String> packs = names.toList(); packs.nonEmpty(); packs = packs.tail) {
// Parse sources ostensibly belonging to package.
String packageName = packs.head;
parsePackageClasses(packageName, packageFiles.get(packageName), packTrees, excludedPackages);
}
if (messager.nerrors() != 0)
return null;
// Enter symbols for all files
docenv.notice("main.Building_tree");
enter.main(classTrees.toList().appendList(packTrees.toList()));
}
} catch (Abort ex) {
}
if (messager.nerrors() != 0)
return null;
if (docClasses)
return new RootDocImpl(docenv, javaNames, options);
else
return new RootDocImpl(docenv, listClasses(classTrees.toList()), names.toList(), options);
}
Aggregations