use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.
the class JavacMessager method printMessage.
/**
* Prints a message of the specified kind at the location of the
* annotation value inside the annotation mirror of the annotated
* element.
*
* @param kind the kind of message
* @param msg the message, or an empty string if none
* @param e the annotated element
* @param a the annotation containing the annotaiton value
* @param v the annotation value to use as a position hint
*/
public void printMessage(Diagnostic.Kind kind, CharSequence msg, Element e, AnnotationMirror a, AnnotationValue v) {
JavaFileObject oldSource = null;
JavaFileObject newSource = null;
JCDiagnostic.DiagnosticPosition pos = null;
JavacElements elemUtils = processingEnv.getElementUtils();
Pair<JCTree, JCCompilationUnit> treeTop = elemUtils.getTreeAndTopLevel(e, a, v);
if (treeTop != null) {
newSource = treeTop.snd.sourcefile;
if (newSource != null) {
oldSource = log.useSource(newSource);
pos = treeTop.fst.pos();
}
}
try {
switch(kind) {
case ERROR:
errorCount++;
boolean prev = log.multipleErrors;
log.multipleErrors = true;
try {
log.error(pos, "proc.messager", msg.toString());
} finally {
log.multipleErrors = prev;
}
break;
case WARNING:
warningCount++;
log.warning(pos, "proc.messager", msg.toString());
break;
case MANDATORY_WARNING:
warningCount++;
log.mandatoryWarning(pos, "proc.messager", msg.toString());
break;
default:
log.note(pos, "proc.messager", msg.toString());
break;
}
} finally {
if (oldSource != null)
log.useSource(oldSource);
}
}
use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.
the class JavacElements method matchAnnoToTree.
/**
* Returns the tree for an annotation given an Attribute to
* search (recursively) and its corresponding tree.
* Returns null if the tree cannot be found.
*/
private JCTree matchAnnoToTree(final Attribute.Compound findme, final Attribute attr, final JCTree tree) {
if (attr == findme)
return (tree.type.tsym == findme.type.tsym) ? tree : null;
class Vis implements Attribute.Visitor {
JCTree result = null;
public void visitConstant(Attribute.Constant value) {
}
public void visitClass(Attribute.Class clazz) {
}
public void visitCompound(Attribute.Compound anno) {
for (Pair<MethodSymbol, Attribute> pair : anno.values) {
JCExpression expr = scanForAssign(pair.fst, tree);
if (expr != null) {
JCTree match = matchAnnoToTree(findme, pair.snd, expr);
if (match != null) {
result = match;
return;
}
}
}
}
public void visitArray(Attribute.Array array) {
if (tree.getTag() == JCTree.NEWARRAY && types.elemtype(array.type).tsym == findme.type.tsym) {
List<JCExpression> elems = ((JCNewArray) tree).elems;
for (Attribute value : array.values) {
if (value == findme) {
result = elems.head;
return;
}
elems = elems.tail;
}
}
}
public void visitEnum(Attribute.Enum e) {
}
public void visitError(Attribute.Error e) {
}
}
Vis vis = new Vis();
attr.accept(vis);
return vis.result;
}
use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.
the class Pretty method visitTry.
public void visitTry(JCTry tree) {
try {
print("try ");
if (tree.resources.nonEmpty()) {
print("(");
boolean first = true;
for (JCTree var : tree.resources) {
if (!first) {
println();
indent();
}
printStat(var);
first = false;
}
print(") ");
}
printStat(tree.body);
for (List<JCCatch> l = tree.catchers; l.nonEmpty(); l = l.tail) {
printStat(l.head);
}
if (tree.finalizer != null) {
print(" finally ");
printStat(tree.finalizer);
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.
the class JavacProcessingEnvironment method getTopLevelClasses.
private List<ClassSymbol> getTopLevelClasses(List<? extends JCCompilationUnit> units) {
List<ClassSymbol> classes = List.nil();
for (JCCompilationUnit unit : units) {
for (JCTree node : unit.defs) {
if (node.getTag() == JCTree.CLASSDEF) {
ClassSymbol sym = ((JCClassDecl) node).sym;
Assert.checkNonNull(sym);
classes = classes.prepend(sym);
}
}
}
return classes.reverse();
}
use of com.sun.tools.javac.tree.JCTree in project ceylon-compiler by ceylon.
the class TreeCopier method visitImport.
public JCTree visitImport(ImportTree node, P p) {
JCImport t = (JCImport) node;
JCTree qualid = copy(t.qualid, p);
return M.at(t.pos).Import(qualid, t.staticImport);
}
Aggregations