use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method resolveSelf.
/**
* Resolve `c.name' where name == this or name == super.
* @param pos The position to use for error reporting.
* @param env The environment current at the expression.
* @param c The qualifier.
* @param name The identifier's name.
*/
Symbol resolveSelf(DiagnosticPosition pos, Env<AttrContext> env, TypeSymbol c, Name name) {
Env<AttrContext> env1 = env;
boolean staticOnly = false;
while (env1.outer != null) {
if (isStatic(env1))
staticOnly = true;
if (env1.enclClass.sym == c) {
Symbol sym = env1.info.scope.lookup(name).sym;
if (sym != null) {
if (staticOnly)
sym = new StaticError(sym);
return accessBase(sym, pos, env.enclClass.sym.type, name, true);
}
}
if ((env1.enclClass.sym.flags() & STATIC) != 0)
staticOnly = true;
env1 = env1.outer;
}
if (c.isInterface() && name == names._super && !isStatic(env) && types.isDirectSuperInterface(c, env.enclClass.sym)) {
// this might be a default super call if one of the superinterfaces is 'c'
for (Type t : pruneInterfaces(env.enclClass.type)) {
if (t.tsym == c) {
env.info.defaultSuperCallSite = t;
return new VarSymbol(0, names._super, types.asSuper(env.enclClass.type, c), env.enclClass.sym);
}
}
// find a direct superinterface that is a subtype of 'c'
for (Type i : types.interfaces(env.enclClass.type)) {
if (i.tsym.isSubClass(c, types) && i.tsym != c) {
log.error(pos, "illegal.default.super.call", c, diags.fragment("redundant.supertype", c, i));
return syms.errSymbol;
}
}
Assert.error();
}
log.error(pos, "not.encl.class", c);
return syms.errSymbol;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method resolveMemberReference.
/**
* Resolution of member references is typically done as a single
* overload resolution step, where the argument types A are inferred from
* the target functional descriptor.
*
* If the member reference is a method reference with a type qualifier,
* a two-step lookup process is performed. The first step uses the
* expected argument list A, while the second step discards the first
* type from A (which is treated as a receiver type).
*
* There are two cases in which inference is performed: (i) if the member
* reference is a constructor reference and the qualifier type is raw - in
* which case diamond inference is used to infer a parameterization for the
* type qualifier; (ii) if the member reference is an unbound reference
* where the type qualifier is raw - in that case, during the unbound lookup
* the receiver argument type is used to infer an instantiation for the raw
* qualifier type.
*
* When a multi-step resolution process is exploited, it is an error
* if two candidates are found (ambiguity).
*
* This routine returns a pair (T,S), where S is the member reference symbol,
* and T is the type of the class in which S is defined. This is necessary as
* the type T might be dynamically inferred (i.e. if constructor reference
* has a raw qualifier).
*/
Pair<Symbol, ReferenceLookupHelper> resolveMemberReference(Env<AttrContext> env, JCMemberReference referenceTree, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes, MethodCheck methodCheck, InferenceContext inferenceContext, AttrMode mode) {
site = types.capture(site);
ReferenceLookupHelper boundLookupHelper = makeReferenceLookupHelper(referenceTree, site, name, argtypes, typeargtypes, VARARITY);
// step 1 - bound lookup
Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup());
Symbol origBoundSym;
boolean staticErrorForBound = false;
MethodResolutionContext boundSearchResolveContext = new MethodResolutionContext();
boundSearchResolveContext.methodCheck = methodCheck;
Symbol boundSym = origBoundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, boundSearchResolveContext, boundLookupHelper);
SearchResultKind boundSearchResultKind = SearchResultKind.NOT_APPLICABLE_MATCH;
boolean isStaticSelector = TreeInfo.isStaticSelector(referenceTree.expr, names);
boolean shouldCheckForStaticness = isStaticSelector && referenceTree.getMode() == ReferenceMode.INVOKE;
if (boundSym.kind != WRONG_MTHS && boundSym.kind != WRONG_MTH) {
if (shouldCheckForStaticness) {
if (!boundSym.isStatic()) {
staticErrorForBound = true;
if (hasAnotherApplicableMethod(boundSearchResolveContext, boundSym, true)) {
boundSearchResultKind = SearchResultKind.BAD_MATCH_MORE_SPECIFIC;
} else {
boundSearchResultKind = SearchResultKind.BAD_MATCH;
if (boundSym.kind < Kinds.ERRONEOUS) {
boundSym = methodWithCorrectStaticnessNotFound;
}
}
} else if (boundSym.kind < Kinds.ERRONEOUS) {
boundSearchResultKind = SearchResultKind.GOOD_MATCH;
}
}
}
// step 2 - unbound lookup
Symbol origUnboundSym = null;
Symbol unboundSym = methodNotFound;
ReferenceLookupHelper unboundLookupHelper = null;
Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup());
SearchResultKind unboundSearchResultKind = SearchResultKind.NOT_APPLICABLE_MATCH;
boolean staticErrorForUnbound = false;
if (isStaticSelector) {
unboundLookupHelper = boundLookupHelper.unboundLookup(inferenceContext);
MethodResolutionContext unboundSearchResolveContext = new MethodResolutionContext();
unboundSearchResolveContext.methodCheck = methodCheck;
unboundSym = origUnboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, unboundSearchResolveContext, unboundLookupHelper);
if (unboundSym.kind != WRONG_MTH && unboundSym.kind != WRONG_MTHS) {
if (shouldCheckForStaticness) {
if (unboundSym.isStatic()) {
staticErrorForUnbound = true;
if (hasAnotherApplicableMethod(unboundSearchResolveContext, unboundSym, false)) {
unboundSearchResultKind = SearchResultKind.BAD_MATCH_MORE_SPECIFIC;
} else {
unboundSearchResultKind = SearchResultKind.BAD_MATCH;
if (unboundSym.kind < Kinds.ERRONEOUS) {
unboundSym = methodWithCorrectStaticnessNotFound;
}
}
} else if (unboundSym.kind < Kinds.ERRONEOUS) {
unboundSearchResultKind = SearchResultKind.GOOD_MATCH;
}
}
}
}
// merge results
Pair<Symbol, ReferenceLookupHelper> res;
Symbol bestSym = choose(boundSym, unboundSym);
if (bestSym.kind < Kinds.ERRONEOUS && (staticErrorForBound || staticErrorForUnbound)) {
if (staticErrorForBound) {
boundSym = methodWithCorrectStaticnessNotFound;
}
if (staticErrorForUnbound) {
unboundSym = methodWithCorrectStaticnessNotFound;
}
bestSym = choose(boundSym, unboundSym);
}
if (bestSym == methodWithCorrectStaticnessNotFound && mode == AttrMode.CHECK) {
Symbol symToPrint = origBoundSym;
String errorFragmentToPrint = "non-static.cant.be.ref";
if (staticErrorForBound && staticErrorForUnbound) {
if (unboundSearchResultKind == SearchResultKind.BAD_MATCH_MORE_SPECIFIC) {
symToPrint = origUnboundSym;
errorFragmentToPrint = "static.method.in.unbound.lookup";
}
} else {
if (!staticErrorForBound) {
symToPrint = origUnboundSym;
errorFragmentToPrint = "static.method.in.unbound.lookup";
}
}
log.error(referenceTree.expr.pos(), "invalid.mref", Kinds.kindName(referenceTree.getMode()), diags.fragment(errorFragmentToPrint, Kinds.kindName(symToPrint), symToPrint));
}
res = new Pair<>(bestSym, bestSym == unboundSym ? unboundLookupHelper : boundLookupHelper);
env.info.pendingResolutionPhase = bestSym == unboundSym ? unboundEnv.info.pendingResolutionPhase : boundEnv.info.pendingResolutionPhase;
return res;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findConstructor.
Symbol findConstructor(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes, boolean allowBoxing, boolean useVarargs) {
Symbol sym = findMethod(env, site, names.init, argtypes, typeargtypes, allowBoxing, useVarargs, false);
chk.checkDeprecated(pos, env.info.scope.owner, sym);
return sym;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method resolveMemberReferenceByArity.
Symbol resolveMemberReferenceByArity(Env<AttrContext> env, JCMemberReference referenceTree, Type site, Name name, List<Type> argtypes, InferenceContext inferenceContext) {
boolean isStaticSelector = TreeInfo.isStaticSelector(referenceTree.expr, names);
site = types.capture(site);
ReferenceLookupHelper boundLookupHelper = makeReferenceLookupHelper(referenceTree, site, name, argtypes, null, VARARITY);
// step 1 - bound lookup
Env<AttrContext> boundEnv = env.dup(env.tree, env.info.dup());
Symbol boundSym = lookupMethod(boundEnv, env.tree.pos(), site.tsym, arityMethodCheck, boundLookupHelper);
if (isStaticSelector && !name.equals(names.init) && !boundSym.isStatic() && boundSym.kind < Kinds.ERRONEOUS) {
boundSym = methodNotFound;
}
// step 2 - unbound lookup
Symbol unboundSym = methodNotFound;
ReferenceLookupHelper unboundLookupHelper = null;
Env<AttrContext> unboundEnv = env.dup(env.tree, env.info.dup());
if (isStaticSelector) {
unboundLookupHelper = boundLookupHelper.unboundLookup(inferenceContext);
unboundSym = lookupMethod(unboundEnv, env.tree.pos(), site.tsym, arityMethodCheck, unboundLookupHelper);
if (unboundSym.isStatic() && unboundSym.kind < Kinds.ERRONEOUS) {
unboundSym = methodNotFound;
}
}
// merge results
Symbol bestSym = choose(boundSym, unboundSym);
env.info.pendingResolutionPhase = bestSym == unboundSym ? unboundEnv.info.pendingResolutionPhase : boundEnv.info.pendingResolutionPhase;
return bestSym;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method resolveInternalMethod.
/**
* Resolve a qualified method identifier, 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 of the qualifying expression, in which
* identifier is searched.
* @param name The identifier's name.
* @param argtypes The types of the invocation's value arguments.
* @param typeargtypes The types of the invocation's type arguments.
*/
public MethodSymbol resolveInternalMethod(DiagnosticPosition pos, Env<AttrContext> env, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
MethodResolutionContext resolveContext = new MethodResolutionContext();
resolveContext.internalResolution = true;
Symbol sym = resolveQualifiedMethod(resolveContext, pos, env, site.tsym, site, name, argtypes, typeargtypes);
if (sym.kind == MTH)
return (MethodSymbol) sym;
else
throw new FatalError(diags.fragment("fatal.err.cant.locate.meth", name));
}
Aggregations