use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findType.
/**
* Find an unqualified type symbol.
* @param env The current environment.
* @param name The type's name.
*/
Symbol findType(Env<AttrContext> env, Name name) {
Symbol bestSoFar = typeNotFound;
Symbol sym;
boolean staticOnly = false;
for (Env<AttrContext> env1 = env; env1.outer != null; env1 = env1.outer) {
if (isStatic(env1))
staticOnly = true;
// First, look for a type variable and the first member type
final Symbol tyvar = findTypeVar(env1, name, staticOnly);
sym = findImmediateMemberType(env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
// immediate member, OR the type variable is for a method.
if (tyvar != typeNotFound) {
if (sym == typeNotFound || (tyvar.kind == TYP && tyvar.exists() && tyvar.owner.kind == MTH))
return tyvar;
}
// otherwise, do the entire findMemberType
if (sym == typeNotFound)
sym = findInheritedMemberType(env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
if (staticOnly && sym.kind == TYP && sym.type.hasTag(CLASS) && sym.type.getEnclosingType().hasTag(CLASS) && env1.enclClass.sym.type.isParameterized() && sym.type.getEnclosingType().isParameterized())
return new StaticError(sym);
else if (sym.exists())
return sym;
else if (sym.kind < bestSoFar.kind)
bestSoFar = sym;
JCClassDecl encl = env1.baseClause ? (JCClassDecl) env1.tree : env1.enclClass;
if ((encl.sym.flags() & STATIC) != 0)
staticOnly = true;
}
if (!env.tree.hasTag(IMPORT)) {
sym = findGlobalType(env, env.toplevel.namedImportScope, name);
if (sym.exists())
return sym;
else if (sym.kind < bestSoFar.kind)
bestSoFar = sym;
sym = findGlobalType(env, env.toplevel.packge.members(), name);
if (sym.exists())
return sym;
else if (sym.kind < bestSoFar.kind)
bestSoFar = sym;
sym = findGlobalType(env, env.toplevel.starImportScope, name);
if (sym.exists())
return sym;
else if (sym.kind < bestSoFar.kind)
bestSoFar = sym;
}
return bestSoFar;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findIdentInPackage.
/**
* Find an identifier in a package which matches a specified kind set.
* @param env The current environment.
* @param name The identifier's name.
* @param kind Indicates the possible symbol kinds
* (a nonempty subset of TYP, PCK).
*/
Symbol findIdentInPackage(Env<AttrContext> env, TypeSymbol pck, Name name, int kind) {
Name fullname = TypeSymbol.formFullName(name, pck);
Symbol bestSoFar = typeNotFound;
PackageSymbol pack = null;
if ((kind & PCK) != 0) {
pack = reader.enterPackage(fullname);
if (pack.exists())
return pack;
}
if ((kind & TYP) != 0) {
Symbol sym = loadClass(env, fullname);
if (sym.exists()) {
// don't allow programs to use flatnames
if (name == sym.name)
return sym;
} else if (sym.kind < bestSoFar.kind)
bestSoFar = sym;
}
return (pack != null) ? pack : bestSoFar;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method resolveInternalConstructor.
/**
* Resolve a constructor, throw a fatal error if not found.
* @param pos The position to use for error reporting.
* @param env The environment current at the method invocation.
* @param site The type to be constructed.
* @param argtypes The types of the invocation's value arguments.
* @param typeargtypes The types of the invocation's type arguments.
*/
public MethodSymbol resolveInternalConstructor(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes) {
MethodResolutionContext resolveContext = new MethodResolutionContext();
resolveContext.internalResolution = true;
Symbol sym = resolveConstructor(resolveContext, pos, env, site, argtypes, typeargtypes);
if (sym.kind == MTH)
return (MethodSymbol) sym;
else
throw new FatalError(diags.fragment("fatal.err.cant.locate.ctor", site));
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findFun.
/**
* Find unqualified method matching given name, type and value arguments.
* @param env The current environment.
* @param name The method's name.
* @param argtypes The method's value arguments.
* @param typeargtypes The method's type arguments.
* @param allowBoxing Allow boxing conversions of arguments.
* @param useVarargs Box trailing arguments into an array for varargs.
*/
Symbol findFun(Env<AttrContext> env, Name name, List<Type> argtypes, List<Type> typeargtypes, boolean allowBoxing, boolean useVarargs) {
Symbol bestSoFar = methodNotFound;
Symbol sym;
Env<AttrContext> env1 = env;
boolean staticOnly = false;
while (env1.outer != null) {
if (isStatic(env1))
staticOnly = true;
Assert.check(env1.info.preferredTreeForDiagnostics == null);
env1.info.preferredTreeForDiagnostics = env.tree;
try {
sym = findMethod(env1, env1.enclClass.sym.type, name, argtypes, typeargtypes, allowBoxing, useVarargs, false);
if (sym.exists()) {
if (staticOnly && sym.kind == MTH && sym.owner.kind == TYP && (sym.flags() & STATIC) == 0)
return new StaticError(sym);
else
return sym;
} else if (sym.kind < bestSoFar.kind) {
bestSoFar = sym;
}
} finally {
env1.info.preferredTreeForDiagnostics = null;
}
if ((env1.enclClass.sym.flags() & STATIC) != 0)
staticOnly = true;
env1 = env1.outer;
}
sym = findMethod(env, syms.predefClass.type, name, argtypes, typeargtypes, allowBoxing, useVarargs, false);
if (sym.exists())
return sym;
Scope.Entry e = env.toplevel.namedImportScope.lookup(name);
for (; e.scope != null; e = e.next()) {
sym = e.sym;
Type origin = e.getOrigin().owner.type;
if (sym.kind == MTH) {
if (e.sym.owner.type != origin)
sym = sym.clone(e.getOrigin().owner);
if (!isAccessible(env, origin, sym))
sym = new AccessError(env, origin, sym);
bestSoFar = selectBest(env, origin, argtypes, typeargtypes, sym, bestSoFar, allowBoxing, useVarargs, false);
}
}
if (bestSoFar.exists())
return bestSoFar;
e = env.toplevel.starImportScope.lookup(name);
for (; e.scope != null; e = e.next()) {
sym = e.sym;
Type origin = e.getOrigin().owner.type;
if (sym.kind == MTH) {
if (e.sym.owner.type != origin)
sym = sym.clone(e.getOrigin().owner);
if (!isAccessible(env, origin, sym))
sym = new AccessError(env, origin, sym);
bestSoFar = selectBest(env, origin, argtypes, typeargtypes, sym, bestSoFar, allowBoxing, useVarargs, false);
}
}
return bestSoFar;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findVar.
/**
* Find unqualified variable or field with given name.
* Synthetic fields always skipped.
* @param env The current environment.
* @param name The name of the variable or field.
*/
Symbol findVar(Env<AttrContext> env, Name name) {
Symbol bestSoFar = varNotFound;
Symbol sym;
Env<AttrContext> env1 = env;
boolean staticOnly = false;
while (env1.outer != null) {
if (isStatic(env1))
staticOnly = true;
Scope.Entry e = env1.info.scope.lookup(name);
while (e.scope != null && (e.sym.kind != VAR || (e.sym.flags_field & SYNTHETIC) != 0)) e = e.next();
sym = (e.scope != null) ? e.sym : findField(env1, env1.enclClass.sym.type, name, env1.enclClass.sym);
if (sym.exists()) {
if (staticOnly && sym.kind == VAR && sym.owner.kind == TYP && (sym.flags() & STATIC) == 0)
return new StaticError(sym);
else
return sym;
} else if (sym.kind < bestSoFar.kind) {
bestSoFar = sym;
}
if ((env1.enclClass.sym.flags() & STATIC) != 0)
staticOnly = true;
env1 = env1.outer;
}
sym = findField(env, syms.predefClass.type, name, syms.predefClass);
if (sym.exists())
return sym;
if (bestSoFar.exists())
return bestSoFar;
Symbol origin = null;
for (Scope sc : new Scope[] { env.toplevel.namedImportScope, env.toplevel.starImportScope }) {
Scope.Entry e = sc.lookup(name);
for (; e.scope != null; e = e.next()) {
sym = e.sym;
if (sym.kind != VAR)
continue;
// invariant: sym.kind == VAR
if (bestSoFar.kind < AMBIGUOUS && sym.owner != bestSoFar.owner)
return new AmbiguityError(bestSoFar, sym);
else if (bestSoFar.kind >= VAR) {
origin = e.getOrigin().owner;
bestSoFar = isAccessible(env, origin.type, sym) ? sym : new AccessError(env, origin.type, sym);
}
}
if (bestSoFar.exists())
break;
}
if (bestSoFar.kind == VAR && bestSoFar.owner.type != origin.type)
return bestSoFar.clone(origin);
else
return bestSoFar;
}
Aggregations