use of com.sun.tools.javac.comp.AttrContext in project ceylon-compiler by ceylon.
the class JavacTrees method getAttrContext.
private Env<AttrContext> getAttrContext(TreePath path) {
if (// implicit null-check
!(path.getLeaf() instanceof JCTree))
throw new IllegalArgumentException();
// then the classes 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 = new Copier(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;
break;
case VARIABLE:
// System.err.println("FIELD: " + ((JCVariableDecl)tree).sym.getSimpleName());
field = (JCVariableDecl) tree;
break;
case BLOCK:
{
// System.err.println("BLOCK: ");
if (method != null)
env = memberEnter.getMethodEnv(method, env);
JCTree body = copier.copy((JCTree) 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 com.sun.tools.javac.comp.AttrContext in project ceylon-compiler by ceylon.
the class ClassDocImpl method searchClass.
private ClassDoc searchClass(String className) {
Names names = tsym.name.table.names;
// search by qualified name first
ClassDoc cd = env.lookupClass(className);
if (cd != null) {
return cd;
}
// search inner classes
// ### Add private entry point to avoid creating array?
// ### Replicate code in innerClasses here to avoid consing?
ClassDoc[] innerClasses = innerClasses();
for (int i = 0; i < innerClasses.length; i++) {
if (innerClasses[i].name().equals(className) || // ### 'name' of the inner class, rather than the true simple name.
innerClasses[i].name().endsWith(className)) {
return innerClasses[i];
} else {
ClassDoc innercd = ((ClassDocImpl) innerClasses[i]).searchClass(className);
if (innercd != null) {
return innercd;
}
}
}
// check in this package
cd = containingPackage().findClass(className);
if (cd != null) {
return cd;
}
// make sure that this symbol has been completed
if (tsym.completer != null) {
tsym.complete();
}
if (tsym.sourcefile != null) {
// ### This information is available only for source classes.
Env<AttrContext> compenv = env.enter.getEnv(tsym);
if (compenv == null)
return null;
Scope s = compenv.toplevel.namedImportScope;
for (Scope.Entry e = s.lookup(names.fromString(className)); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.TYP) {
ClassDoc c = env.getClassDoc((ClassSymbol) e.sym);
return c;
}
}
s = compenv.toplevel.starImportScope;
for (Scope.Entry e = s.lookup(names.fromString(className)); e.scope != null; e = e.next()) {
if (e.sym.kind == Kinds.TYP) {
ClassDoc c = env.getClassDoc((ClassSymbol) e.sym);
return c;
}
}
}
// not found
return null;
}
use of com.sun.tools.javac.comp.AttrContext in project ceylon-compiler by ceylon.
the class ClassDocImpl method importedClasses.
/**
* Get the list of classes declared as imported.
* These are called "single-type-import declarations" in the JLS.
* This method is deprecated in the ClassDoc interface.
*
* @return an array of ClassDocImpl representing the imported classes.
*
* @deprecated Import declarations are implementation details that
* should not be exposed here. In addition, not all imported
* classes are imported through single-type-import declarations.
*/
@Deprecated
public ClassDoc[] importedClasses() {
// information is not available for binary classfiles
if (tsym.sourcefile == null)
return new ClassDoc[0];
ListBuffer<ClassDocImpl> importedClasses = new ListBuffer<ClassDocImpl>();
Env<AttrContext> compenv = env.enter.getEnv(tsym);
if (compenv == null)
return new ClassDocImpl[0];
Name asterisk = tsym.name.table.names.asterisk;
for (JCTree t : compenv.toplevel.defs) {
if (t.getTag() == JCTree.IMPORT) {
JCTree imp = ((JCImport) t).qualid;
if ((TreeInfo.name(imp) != asterisk) && (imp.type.tsym.kind & Kinds.TYP) != 0) {
importedClasses.append(env.getClassDoc((ClassSymbol) imp.type.tsym));
}
}
}
return importedClasses.toArray(new ClassDocImpl[importedClasses.length()]);
}
use of com.sun.tools.javac.comp.AttrContext in project ceylon-compiler by ceylon.
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 com.sun.tools.javac.comp.AttrContext in project lombok by rzwitserloot.
the class JavacResolution method memberEnterAndAttribute.
private void memberEnterAndAttribute(JCTree copy, Env<AttrContext> env, Context context) {
MemberEnter memberEnter = MemberEnter.instance(context);
Env<AttrContext> oldEnv = getEnvOfMemberEnter(memberEnter);
setEnvOfMemberEnter(memberEnter, env);
try {
copy.accept(memberEnter);
} catch (Exception ignore) {
// intentionally ignored; usually even if this step fails, val will work (but not for val in method local inner classes and anonymous inner classes).
AssertionLogger.assertLog("member enter failed.", ignore);
} finally {
setEnvOfMemberEnter(memberEnter, oldEnv);
}
attrib(copy, env);
}
Aggregations