use of org.eclipse.ceylon.langtools.tools.javac.code.Type 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.Type 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.Type in project ceylon by eclipse.
the class Resolve method adjustArgs.
List<Type> adjustArgs(List<Type> args, Symbol msym, int length, boolean allowVarargs) {
if ((msym.flags() & VARARGS) != 0 && allowVarargs) {
Type varargsElem = types.elemtype(args.last());
if (varargsElem == null) {
Assert.error("Bad varargs = " + args.last() + " " + msym);
}
List<Type> newArgs = args.reverse().tail.prepend(varargsElem).reverse();
while (newArgs.length() < length) {
newArgs = newArgs.append(newArgs.last());
}
return newArgs;
} else {
return args;
}
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Resolve method reportVerboseResolutionDiagnostic.
void reportVerboseResolutionDiagnostic(DiagnosticPosition dpos, Name name, Type site, List<Type> argtypes, List<Type> typeargtypes, Symbol bestSoFar) {
boolean success = bestSoFar.kind < Kinds.ERRONEOUS;
if (success && !verboseResolutionMode.contains(VerboseResolutionMode.SUCCESS)) {
return;
} else if (!success && !verboseResolutionMode.contains(VerboseResolutionMode.FAILURE)) {
return;
}
if (bestSoFar.name == names.init && bestSoFar.owner == syms.objectType.tsym && !verboseResolutionMode.contains(VerboseResolutionMode.OBJECT_INIT)) {
// skip diags for Object constructor resolution
return;
} else if (site == syms.predefClass.type && !verboseResolutionMode.contains(VerboseResolutionMode.PREDEF)) {
// skip spurious diags for predef symbols (i.e. operators)
return;
} else if (currentResolutionContext.internalResolution && !verboseResolutionMode.contains(VerboseResolutionMode.INTERNAL)) {
return;
}
int pos = 0;
int mostSpecificPos = -1;
ListBuffer<JCDiagnostic> subDiags = new ListBuffer<>();
for (Candidate c : currentResolutionContext.candidates) {
if (currentResolutionContext.step != c.step || (c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.APPLICABLE)) || (!c.isApplicable() && !verboseResolutionMode.contains(VerboseResolutionMode.INAPPLICABLE))) {
continue;
} else {
subDiags.append(c.isApplicable() ? getVerboseApplicableCandidateDiag(pos, c.sym, c.mtype) : getVerboseInapplicableCandidateDiag(pos, c.sym, c.details));
if (c.sym == bestSoFar)
mostSpecificPos = pos;
pos++;
}
}
String key = success ? "verbose.resolve.multi" : "verbose.resolve.multi.1";
List<Type> argtypes2 = Type.map(argtypes, deferredAttr.new RecoveryDeferredTypeMap(AttrMode.SPECULATIVE, bestSoFar, currentResolutionContext.step));
JCDiagnostic main = diags.note(log.currentSource(), dpos, key, name, site.tsym, mostSpecificPos, currentResolutionContext.step, methodArguments(argtypes2), methodArguments(typeargtypes));
JCDiagnostic d = new JCDiagnostic.MultilineDiagnostic(main, subDiags.toList());
log.report(d);
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Type in project ceylon by eclipse.
the class Resolve method signatureMoreSpecific.
// where
private boolean signatureMoreSpecific(List<Type> actuals, Env<AttrContext> env, Type site, Symbol m1, Symbol m2, boolean allowBoxing, boolean useVarargs) {
noteWarner.clear();
int maxLength = Math.max(Math.max(m1.type.getParameterTypes().length(), actuals.length()), m2.type.getParameterTypes().length());
MethodResolutionContext prevResolutionContext = currentResolutionContext;
try {
currentResolutionContext = new MethodResolutionContext();
currentResolutionContext.step = prevResolutionContext.step;
currentResolutionContext.methodCheck = prevResolutionContext.methodCheck.mostSpecificCheck(actuals, !allowBoxing);
Type mst = instantiate(env, site, m2, null, adjustArgs(types.cvarLowerBounds(types.memberType(site, m1).getParameterTypes()), m1, maxLength, useVarargs), null, allowBoxing, useVarargs, noteWarner);
return mst != null && !noteWarner.hasLint(Lint.LintCategory.UNCHECKED);
} finally {
currentResolutionContext = prevResolutionContext;
}
}
Aggregations