use of org.eclipse.ceylon.langtools.tools.javac.comp.AttrContext in project ceylon by eclipse.
the class SymbolMetadata method complete.
/*
* Replace Placeholders for repeating annotations with their containers
*/
private <T extends Attribute.Compound> void complete(Annotate.AnnotateRepeatedContext<T> ctx) {
Log log = ctx.log;
Env<AttrContext> env = ctx.env;
JavaFileObject oldSource = log.useSource(env.toplevel.sourcefile);
try {
// TODO: can we reduce duplication in the following branches?
if (ctx.isTypeCompound) {
Assert.check(!isTypesEmpty());
if (isTypesEmpty()) {
return;
}
List<Attribute.TypeCompound> result = List.nil();
for (Attribute.TypeCompound a : getTypeAttributes()) {
if (a instanceof Placeholder) {
@SuppressWarnings("unchecked") Placeholder<Attribute.TypeCompound> ph = (Placeholder<Attribute.TypeCompound>) a;
Attribute.TypeCompound replacement = replaceOne(ph, ph.getRepeatedContext());
if (null != replacement) {
result = result.prepend(replacement);
}
} else {
result = result.prepend(a);
}
}
type_attributes = result.reverse();
Assert.check(SymbolMetadata.this.getTypePlaceholders().isEmpty());
} else {
Assert.check(!pendingCompletion());
if (isEmpty()) {
return;
}
List<Attribute.Compound> result = List.nil();
for (Attribute.Compound a : getDeclarationAttributes()) {
if (a instanceof Placeholder) {
@SuppressWarnings("unchecked") Attribute.Compound replacement = replaceOne((Placeholder<T>) a, ctx);
if (null != replacement) {
result = result.prepend(replacement);
}
} else {
result = result.prepend(a);
}
}
attributes = result.reverse();
Assert.check(SymbolMetadata.this.getPlaceholders().isEmpty());
}
} finally {
log.useSource(oldSource);
}
}
use of org.eclipse.ceylon.langtools.tools.javac.comp.AttrContext in project ceylon by eclipse.
the class JavacElements method getTreeAndTopLevel.
/**
* Returns the tree node and compilation unit corresponding to this
* element, or null if they can't be found.
*/
private Pair<JCTree, JCCompilationUnit> getTreeAndTopLevel(Element e) {
Symbol sym = cast(Symbol.class, e);
Env<AttrContext> enterEnv = getEnterEnv(sym);
if (enterEnv == null)
return null;
JCTree tree = TreeInfo.declarationFor(sym, enterEnv.tree);
if (tree == null || enterEnv.toplevel == null)
return null;
return new Pair<JCTree, JCCompilationUnit>(tree, enterEnv.toplevel);
}
use of org.eclipse.ceylon.langtools.tools.javac.comp.AttrContext in project ceylon by eclipse.
the class JavacTrees method getAttrContext.
private Env<AttrContext> getAttrContext(TreePath path) {
if (// implicit null-check
!(path.getLeaf() instanceof JCTree))
throw new IllegalArgumentException();
// will already have been entered.
if (javacTaskImpl != null) {
try {
javacTaskImpl.enter(null);
} catch (IOException e) {
throw new Error("unexpected error while entering symbols: " + e);
}
}
JCCompilationUnit unit = (JCCompilationUnit) path.getCompilationUnit();
Copier copier = createCopier(treeMaker.forToplevel(unit));
Env<AttrContext> env = null;
JCMethodDecl method = null;
JCVariableDecl field = null;
List<Tree> l = List.nil();
TreePath p = path;
while (p != null) {
l = l.prepend(p.getLeaf());
p = p.getParentPath();
}
for (; l.nonEmpty(); l = l.tail) {
Tree tree = l.head;
switch(tree.getKind()) {
case COMPILATION_UNIT:
// System.err.println("COMP: " + ((JCCompilationUnit)tree).sourcefile);
env = enter.getTopLevelEnv((JCCompilationUnit) tree);
break;
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
// System.err.println("CLASS: " + ((JCClassDecl)tree).sym.getSimpleName());
env = enter.getClassEnv(((JCClassDecl) tree).sym);
break;
case METHOD:
// System.err.println("METHOD: " + ((JCMethodDecl)tree).sym.getSimpleName());
method = (JCMethodDecl) tree;
env = memberEnter.getMethodEnv(method, env);
break;
case VARIABLE:
// System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName());
field = (JCVariableDecl) tree;
break;
case BLOCK:
{
// System.err.println("BLOCK: ");
if (method != null) {
try {
Assert.check(method.body == tree);
method.body = copier.copy((JCBlock) tree, (JCTree) path.getLeaf());
env = attribStatToTree(method.body, env, copier.leafCopy);
} finally {
method.body = (JCBlock) tree;
}
} else {
JCBlock body = copier.copy((JCBlock) tree, (JCTree) path.getLeaf());
env = attribStatToTree(body, env, copier.leafCopy);
}
return env;
}
default:
// System.err.println("DEFAULT: " + tree.getKind());
if (field != null && field.getInitializer() == tree) {
env = memberEnter.getInitEnv(field, env);
JCExpression expr = copier.copy((JCExpression) tree, (JCTree) path.getLeaf());
env = attribExprToTree(expr, env, copier.leafCopy);
return env;
}
}
}
return (field != null) ? memberEnter.getInitEnv(field, env) : env;
}
use of org.eclipse.ceylon.langtools.tools.javac.comp.AttrContext in project ceylon by eclipse.
the class JavacTrees method getTree.
public JCTree getTree(Element element) {
Symbol symbol = (Symbol) element;
TypeSymbol enclosing = symbol.enclClass();
Env<AttrContext> env = enter.getEnv(enclosing);
if (env == null)
return null;
JCClassDecl classNode = env.enclClass;
if (classNode != null) {
if (TreeInfo.symbolFor(classNode) == element)
return classNode;
for (JCTree node : classNode.getMembers()) if (TreeInfo.symbolFor(node) == element)
return node;
}
return null;
}
Aggregations