use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class Attr method visitParens.
public void visitParens(JCParens tree) {
Type owntype = attribTree(tree.expr, env, pkind, pt);
result = check(tree, owntype, pkind, pkind, pt);
Symbol sym = TreeInfo.symbol(tree);
if (sym != null && (sym.kind & (TYP | PCK)) != 0)
log.error(tree.pos(), "illegal.start.of.type");
}
use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class Attr method selectSym.
private Symbol selectSym(JCFieldAccess tree, Symbol location, Type site, Env<AttrContext> env, Type pt, int pkind) {
DiagnosticPosition pos = tree.pos();
Name name = tree.name;
switch(site.tag) {
case PACKAGE:
return rs.access(rs.findIdentInPackage(env, site.tsym, name, pkind), pos, location, site, name, true);
case ARRAY:
case CLASS:
if (pt.tag == METHOD || pt.tag == FORALL) {
return rs.resolveQualifiedMethod(pos, env, location, site, name, pt.getParameterTypes(), pt.getTypeArguments());
} else if (name == names._this || name == names._super) {
return rs.resolveSelf(pos, env, site.tsym, name);
} else if (name == names._class) {
// In this case, we have already made sure in
// visitSelect that qualifier expression is a type.
Type t = syms.classType;
List<Type> typeargs = allowGenerics ? List.of(types.erasure(site)) : List.<Type>nil();
t = new ClassType(t.getEnclosingType(), typeargs, t.tsym);
return new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
} else {
// We are seeing a plain identifier as selector.
Symbol sym = rs.findIdentInType(env, site, name, pkind);
if ((pkind & ERRONEOUS) == 0)
sym = rs.access(sym, pos, location, site, name, true);
return sym;
}
case WILDCARD:
throw new AssertionError(tree);
case TYPEVAR:
// Normally, site.getUpperBound() shouldn't be null.
// It should only happen during memberEnter/attribBase
// when determining the super type which *must* beac
// done before attributing the type variables. In
// other words, we are seeing this illegal program:
// class B<T> extends A<T.foo> {}
Symbol sym = (site.getUpperBound() != null) ? selectSym(tree, location, capture(site.getUpperBound()), env, pt, pkind) : null;
if (sym == null) {
log.error(pos, "type.var.cant.be.deref");
return syms.errSymbol;
} else {
// Ceylon: relax the rules for private methods in wildcards, damnit, we want the private
// method to be called, not any subtype's method we can't possibly know about, this is really
// a lame Java decision.
Symbol sym2 = (!sourceLanguage.isCeylon() && (sym.flags() & Flags.PRIVATE) != 0) ? rs.new AccessError(env, site, sym) : sym;
rs.access(sym2, pos, location, site, name, true);
return sym;
}
case ERROR:
// preserve identifier names through errors
return types.createErrorType(name, site.tsym, site).tsym;
default:
// .class is allowed for these.
if (name == names._class) {
// In this case, we have already made sure in Select that
// qualifier expression is a type.
Type t = syms.classType;
Type arg = types.boxedClass(site).type;
t = new ClassType(t.getEnclosingType(), List.of(arg), t.tsym);
return new VarSymbol(STATIC | PUBLIC | FINAL, names._class, t, site.tsym);
} else {
log.error(pos, "cant.deref", site);
return syms.errSymbol;
}
}
}
use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class Attr method visitIdent.
public void visitIdent(JCIdent tree) {
Symbol sym;
boolean varArgs = false;
// Added by Ceylon
if (tree instanceof JCIndyIdent) {
sym = resolveIndyCall((JCIndyIdent) tree, pt.getParameterTypes());
} else if (pt.tag == METHOD || pt.tag == FORALL) {
// If we are looking for a method, the prototype `pt' will be a
// method type with the type of the call's arguments as parameters.
env.info.varArgs = false;
sym = rs.resolveMethod(tree.pos(), env, tree.name, pt.getParameterTypes(), pt.getTypeArguments());
varArgs = env.info.varArgs;
} else if (tree.sym != null && tree.sym.kind != VAR) {
sym = tree.sym;
} else {
sym = rs.resolveIdent(tree.pos(), env, tree.name, pkind);
}
tree.sym = sym;
// (1) Also find the environment current for the class where
// sym is defined (`symEnv').
// Only for pre-tiger versions (1.4 and earlier):
// (2) Also determine whether we access symbol out of an anonymous
// class in a this or super call. This is illegal for instance
// members since such classes don't carry a this$n link.
// (`noOuterThisPath').
Env<AttrContext> symEnv = env;
boolean noOuterThisPath = false;
if (// we are in an inner class
env.enclClass.sym.owner.kind != PCK && (sym.kind & (VAR | MTH | TYP)) != 0 && sym.owner.kind == TYP && tree.name != names._this && tree.name != names._super) {
// Find environment in which identifier is defined.
while (symEnv.outer != null && !sym.isMemberOf(symEnv.enclClass.sym, types)) {
if ((symEnv.enclClass.sym.flags() & NOOUTERTHIS) != 0)
noOuterThisPath = !allowAnonOuterThis;
symEnv = symEnv.outer;
}
}
// If symbol is a variable, ...
if (sym.kind == VAR) {
VarSymbol v = (VarSymbol) sym;
// ..., evaluate its initializer, if it has one, and check for
// illegal forward reference.
checkInit(tree, env, v, false);
// inner class check that it is final.
if (v.owner.kind == MTH && v.owner != env.info.scope.owner && (v.flags_field & FINAL) == 0) {
log.error(tree.pos(), "local.var.accessed.from.icls.needs.final", v);
}
// that the variable is assignable in the current environment.
if (pkind == VAR)
checkAssignable(tree.pos(), v, null, env);
}
// not accessed before the supertype constructor is called.
if ((symEnv.info.isSelfCall || noOuterThisPath) && (sym.kind & (VAR | MTH)) != 0 && sym.owner.kind == TYP && (sym.flags() & STATIC) == 0) {
chk.earlyRefError(tree.pos(), sym.kind == VAR ? sym : thisSym(tree.pos(), env));
}
Env<AttrContext> env1 = env;
if (sym.kind != ERR && sym.kind != TYP && sym.owner != null && sym.owner != env1.enclClass.sym) {
// enclosing instance:
while (env1.outer != null && !rs.isAccessible(env, env1.enclClass.sym.type, sym)) env1 = env1.outer;
}
result = checkId(tree, env1.enclClass.sym.type, sym, env, pkind, pt, varArgs);
}
use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
the class JavacTrees method getElement.
public Element getElement(TreePath path) {
JCTree tree = (JCTree) path.getLeaf();
Symbol sym = TreeInfo.symbolFor(tree);
if (sym == null && TreeInfo.isDeclaration(tree)) {
for (TreePath p = path; p != null; p = p.getParentPath()) {
JCTree t = (JCTree) p.getLeaf();
if (t.getTag() == JCTree.CLASSDEF) {
JCClassDecl ct = (JCClassDecl) t;
if (ct.sym != null) {
if ((ct.sym.flags_field & Flags.UNATTRIBUTED) != 0) {
attr.attribClass(ct.pos(), ct.sym);
sym = TreeInfo.symbolFor(tree);
}
break;
}
}
}
}
return sym;
}
use of com.sun.tools.javac.code.Symbol in project ceylon-compiler by ceylon.
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