Search in sources :

Example 1 with MethodResolutionPhase

use of com.sun.tools.javac.comp.Resolve.MethodResolutionPhase in project ceylon-compiler by ceylon.

the class Resolve method resolveMethod.

/**
 * Resolve an unqualified method identifier.
 *  @param pos       The position to use for error reporting.
 *  @param env       The environment current at the method invocation.
 *  @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.
 */
Symbol resolveMethod(DiagnosticPosition pos, Env<AttrContext> env, Name name, List<Type> argtypes, List<Type> typeargtypes) {
    Symbol sym = startResolution();
    List<MethodResolutionPhase> steps = methodResolutionSteps;
    while (steps.nonEmpty() && steps.head.isApplicable(boxingEnabled, varargsEnabled) && sym.kind >= ERRONEOUS) {
        currentStep = steps.head;
        sym = findFun(env, name, argtypes, typeargtypes, steps.head.isBoxingRequired, env.info.varArgs = steps.head.isVarargsRequired);
        methodResolutionCache.put(steps.head, sym);
        steps = steps.tail;
    }
    if (sym.kind >= AMBIGUOUS) {
        // if nothing is found return the 'first' error
        MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
        sym = access(methodResolutionCache.get(errPhase), pos, env.enclClass.sym.type, name, false, argtypes, typeargtypes);
        env.info.varArgs = errPhase.isVarargsRequired;
    }
    return sym;
}
Also used : MethodResolutionPhase(com.sun.tools.javac.comp.Resolve.MethodResolutionPhase) Symbol(com.sun.tools.javac.code.Symbol)

Example 2 with MethodResolutionPhase

use of com.sun.tools.javac.comp.Resolve.MethodResolutionPhase in project ceylon-compiler by ceylon.

the class Resolve method resolveDiamond.

/**
 * Resolve constructor using diamond inference.
 *  @param pos       The position to use for error reporting.
 *  @param env       The environment current at the constructor invocation.
 *  @param site      The type of class for which a constructor is searched.
 *                   The scope of this class has been touched in attribution.
 *  @param argtypes  The types of the constructor invocation's value
 *                   arguments.
 *  @param typeargtypes  The types of the constructor invocation's type
 *                   arguments.
 */
Symbol resolveDiamond(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes) {
    Symbol sym = startResolution();
    List<MethodResolutionPhase> steps = methodResolutionSteps;
    while (steps.nonEmpty() && steps.head.isApplicable(boxingEnabled, varargsEnabled) && sym.kind >= ERRONEOUS) {
        currentStep = steps.head;
        sym = resolveConstructor(pos, env, site, argtypes, typeargtypes, steps.head.isBoxingRequired(), env.info.varArgs = steps.head.isVarargsRequired());
        methodResolutionCache.put(steps.head, sym);
        steps = steps.tail;
    }
    if (sym.kind >= AMBIGUOUS) {
        final JCDiagnostic details = sym.kind == WRONG_MTH ? ((InapplicableSymbolError) sym).explanation : null;
        Symbol errSym = new ResolveError(WRONG_MTH, "diamond error") {

            @Override
            JCDiagnostic getDiagnostic(DiagnosticType dkind, DiagnosticPosition pos, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
                String key = details == null ? "cant.apply.diamond" : "cant.apply.diamond.1";
                return diags.create(dkind, log.currentSource(), pos, key, diags.fragment("diamond", site.tsym), details);
            }
        };
        MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
        sym = access(errSym, pos, site, names.init, true, argtypes, typeargtypes);
        env.info.varArgs = errPhase.isVarargsRequired();
    }
    return sym;
}
Also used : DiagnosticType(com.sun.tools.javac.util.JCDiagnostic.DiagnosticType) Type(com.sun.tools.javac.code.Type) MethodResolutionPhase(com.sun.tools.javac.comp.Resolve.MethodResolutionPhase) Symbol(com.sun.tools.javac.code.Symbol) DiagnosticType(com.sun.tools.javac.util.JCDiagnostic.DiagnosticType) DiagnosticPosition(com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition) LocalizedString(com.sun.tools.javac.api.Formattable.LocalizedString)

Example 3 with MethodResolutionPhase

use of com.sun.tools.javac.comp.Resolve.MethodResolutionPhase in project ceylon-compiler by ceylon.

the class Resolve method resolveConstructor.

/**
 * Resolve constructor.
 *  @param pos       The position to use for error reporting.
 *  @param env       The environment current at the constructor invocation.
 *  @param site      The type of class for which a constructor is searched.
 *  @param argtypes  The types of the constructor invocation's value
 *                   arguments.
 *  @param typeargtypes  The types of the constructor invocation's type
 *                   arguments.
 */
Symbol resolveConstructor(DiagnosticPosition pos, Env<AttrContext> env, Type site, List<Type> argtypes, List<Type> typeargtypes) {
    Symbol sym = startResolution();
    List<MethodResolutionPhase> steps = methodResolutionSteps;
    while (steps.nonEmpty() && steps.head.isApplicable(boxingEnabled, varargsEnabled) && sym.kind >= ERRONEOUS) {
        currentStep = steps.head;
        sym = resolveConstructor(pos, env, site, argtypes, typeargtypes, steps.head.isBoxingRequired(), env.info.varArgs = steps.head.isVarargsRequired());
        methodResolutionCache.put(steps.head, sym);
        steps = steps.tail;
    }
    if (sym.kind >= AMBIGUOUS) {
        // if nothing is found return the 'first' error
        MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
        sym = access(methodResolutionCache.get(errPhase), pos, site, names.init, true, argtypes, typeargtypes);
        env.info.varArgs = errPhase.isVarargsRequired();
    }
    return sym;
}
Also used : MethodResolutionPhase(com.sun.tools.javac.comp.Resolve.MethodResolutionPhase) Symbol(com.sun.tools.javac.code.Symbol)

Example 4 with MethodResolutionPhase

use of com.sun.tools.javac.comp.Resolve.MethodResolutionPhase in project ceylon-compiler by ceylon.

the class Resolve method firstErroneousResolutionPhase.

private MethodResolutionPhase firstErroneousResolutionPhase() {
    MethodResolutionPhase bestSoFar = BASIC;
    Symbol sym = methodNotFound;
    List<MethodResolutionPhase> steps = methodResolutionSteps;
    while (steps.nonEmpty() && steps.head.isApplicable(boxingEnabled, varargsEnabled) && sym.kind >= WRONG_MTHS) {
        sym = methodResolutionCache.get(steps.head);
        bestSoFar = steps.head;
        steps = steps.tail;
    }
    return bestSoFar;
}
Also used : MethodResolutionPhase(com.sun.tools.javac.comp.Resolve.MethodResolutionPhase) Symbol(com.sun.tools.javac.code.Symbol)

Example 5 with MethodResolutionPhase

use of com.sun.tools.javac.comp.Resolve.MethodResolutionPhase in project ceylon-compiler by ceylon.

the class Resolve method resolveQualifiedMethod.

Symbol resolveQualifiedMethod(DiagnosticPosition pos, Env<AttrContext> env, Symbol location, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes) {
    Symbol sym = startResolution();
    List<MethodResolutionPhase> steps = methodResolutionSteps;
    while (steps.nonEmpty() && steps.head.isApplicable(boxingEnabled, varargsEnabled) && sym.kind >= ERRONEOUS) {
        currentStep = steps.head;
        sym = findMethod(env, site, name, argtypes, typeargtypes, steps.head.isBoxingRequired(), env.info.varArgs = steps.head.isVarargsRequired(), false);
        methodResolutionCache.put(steps.head, sym);
        steps = steps.tail;
    }
    if (sym.kind >= AMBIGUOUS) {
        if (site.tsym.isPolymorphicSignatureGeneric()) {
            // polymorphic receiver - synthesize new method symbol
            env.info.varArgs = false;
            sym = findPolymorphicSignatureInstance(env, site, name, null, argtypes);
        } else {
            // if nothing is found return the 'first' error
            MethodResolutionPhase errPhase = firstErroneousResolutionPhase();
            sym = access(methodResolutionCache.get(errPhase), pos, location, site, name, true, argtypes, typeargtypes);
            env.info.varArgs = errPhase.isVarargsRequired;
        }
    } else if (allowMethodHandles && sym.isPolymorphicSignatureGeneric()) {
        // non-instantiated polymorphic signature - synthesize new method symbol
        env.info.varArgs = false;
        sym = findPolymorphicSignatureInstance(env, site, name, (MethodSymbol) sym, argtypes);
    }
    return sym;
}
Also used : MethodResolutionPhase(com.sun.tools.javac.comp.Resolve.MethodResolutionPhase) Symbol(com.sun.tools.javac.code.Symbol)

Aggregations

Symbol (com.sun.tools.javac.code.Symbol)5 MethodResolutionPhase (com.sun.tools.javac.comp.Resolve.MethodResolutionPhase)5 LocalizedString (com.sun.tools.javac.api.Formattable.LocalizedString)1 Type (com.sun.tools.javac.code.Type)1 DiagnosticPosition (com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition)1 DiagnosticType (com.sun.tools.javac.util.JCDiagnostic.DiagnosticType)1