use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findPolymorphicSignatureInstance.
/**
* Find or create an implicit method of exactly the given type (after erasure).
* Searches in a side table, not the main scope of the site.
* This emulates the lookup process required by JSR 292 in JVM.
* @param env Attribution environment
* @param spMethod signature polymorphic method - i.e. MH.invokeExact
* @param argtypes The required argument types
*/
Symbol findPolymorphicSignatureInstance(Env<AttrContext> env, final Symbol spMethod, List<Type> argtypes) {
Type mtype = infer.instantiatePolymorphicSignatureInstance(env, (MethodSymbol) spMethod, currentResolutionContext, argtypes);
for (Symbol sym : polymorphicSignatureScope.getElementsByName(spMethod.name)) {
if (types.isSameType(mtype, sym.type)) {
return sym;
}
}
// create the desired method
long flags = ABSTRACT | HYPOTHETICAL | spMethod.flags() & Flags.AccessFlags;
Symbol msym = new MethodSymbol(flags, spMethod.name, mtype, spMethod.owner) {
@Override
public Symbol baseSymbol() {
return spMethod;
}
};
if (!mtype.isErroneous()) {
// Cache only if kosher.
polymorphicSignatureScope.enter(msym);
}
return msym;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findIdent.
/**
* Find an unqualified identifier 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 subset of VAL, TYP, PCK).
*/
Symbol findIdent(Env<AttrContext> env, Name name, int kind) {
Symbol bestSoFar = typeNotFound;
Symbol sym;
if ((kind & VAR) != 0) {
sym = findVar(env, name);
if (sym.exists())
return sym;
else if (sym.kind < bestSoFar.kind)
bestSoFar = sym;
}
if ((kind & TYP) != 0) {
sym = findType(env, name);
if (sym.kind == TYP) {
reportDependence(env.enclClass.sym, sym);
}
if (sym.exists())
return sym;
else if (sym.kind < bestSoFar.kind)
bestSoFar = sym;
}
if ((kind & PCK) != 0)
return reader.enterPackage(name);
else
return bestSoFar;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findField.
/* ***************************************************************************
* Symbol lookup
* the following naming conventions for arguments are used
*
* env is the environment where the symbol was mentioned
* site is the type of which the symbol is a member
* name is the symbol's name
* if no arguments are given
* argtypes are the value arguments, if we search for a method
*
* If no symbol was found, a ResolveError detailing the problem is returned.
****************************************************************************/
/**
* Find field. Synthetic fields are always skipped.
* @param env The current environment.
* @param site The original type from where the selection takes place.
* @param name The name of the field.
* @param c The class to search for the field. This is always
* a superclass or implemented interface of site's class.
*/
Symbol findField(Env<AttrContext> env, Type site, Name name, TypeSymbol c) {
while (c.type.hasTag(TYPEVAR)) c = c.type.getUpperBound().tsym;
Symbol bestSoFar = varNotFound;
Symbol sym;
Scope.Entry e = c.members().lookup(name);
while (e.scope != null) {
if (e.sym.kind == VAR && (e.sym.flags_field & SYNTHETIC) == 0) {
return isAccessible(env, site, e.sym) ? e.sym : new AccessError(env, site, e.sym);
}
e = e.next();
}
Type st = types.supertype(c.type);
if (st != null && (st.hasTag(CLASS) || st.hasTag(TYPEVAR))) {
sym = findField(env, site, name, st.tsym);
if (sym.kind < bestSoFar.kind)
bestSoFar = sym;
}
for (List<Type> l = types.interfaces(c.type); bestSoFar.kind != AMBIGUOUS && l.nonEmpty(); l = l.tail) {
sym = findField(env, site, name, l.head.tsym);
if (bestSoFar.exists() && sym.exists() && sym.owner != bestSoFar.owner)
bestSoFar = new AmbiguityError(bestSoFar, 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 findMethod.
/**
* Find best qualified method matching given name, type and value
* arguments.
* @param env The current environment.
* @param site The original type from where the selection
* takes place.
* @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 findMethod(Env<AttrContext> env, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes, boolean allowBoxing, boolean useVarargs, boolean operator) {
Symbol bestSoFar = methodNotFound;
bestSoFar = findMethod(env, site, name, argtypes, typeargtypes, site.tsym.type, bestSoFar, allowBoxing, useVarargs, operator);
return bestSoFar;
}
use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.
the class Resolve method findDiamond.
/**
* This method scans all the constructor symbol in a given class scope -
* assuming that the original scope contains a constructor of the kind:
* {@code Foo(X x, Y y)}, where X,Y are class type-variables declared in Foo,
* a method check is executed against the modified constructor type:
* {@code <X,Y>Foo<X,Y>(X x, Y y)}. This is crucial in order to enable diamond
* inference. The inferred return type of the synthetic constructor IS
* the inferred type for the diamond operator.
*/
private Symbol findDiamond(Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes, boolean allowBoxing, boolean useVarargs) {
Symbol bestSoFar = methodNotFound;
for (Scope.Entry e = site.tsym.members().lookup(names.init); e.scope != null; e = e.next()) {
final Symbol sym = e.sym;
// - System.out.println(" e " + e.sym);
if (sym.kind == MTH && (sym.flags_field & SYNTHETIC) == 0) {
List<Type> oldParams = e.sym.type.hasTag(FORALL) ? ((ForAll) sym.type).tvars : List.<Type>nil();
Type constrType = new ForAll(site.tsym.type.getTypeArguments().appendList(oldParams), types.createMethodTypeWithReturn(sym.type.asMethodType(), site));
MethodSymbol newConstr = new MethodSymbol(sym.flags(), names.init, constrType, site.tsym) {
@Override
public Symbol baseSymbol() {
return sym;
}
};
bestSoFar = selectBest(env, site, argtypes, typeargtypes, newConstr, bestSoFar, allowBoxing, useVarargs, false);
}
}
return bestSoFar;
}
Aggregations