Search in sources :

Example 86 with Symbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.

the class Resolve method findMethod.

// where
private Symbol findMethod(Env<AttrContext> env, Type site, Name name, List<Type> argtypes, List<Type> typeargtypes, Type intype, Symbol bestSoFar, boolean allowBoxing, boolean useVarargs, boolean operator) {
    @SuppressWarnings({ "unchecked", "rawtypes" }) List<Type>[] itypes = (List<Type>[]) new List[] { List.<Type>nil(), List.<Type>nil() };
    InterfaceLookupPhase iphase = InterfaceLookupPhase.ABSTRACT_OK;
    for (TypeSymbol s : superclasses(intype)) {
        bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes, s.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
        if (name == names.init)
            return bestSoFar;
        iphase = (iphase == null) ? null : iphase.update(s, this);
        if (iphase != null) {
            for (Type itype : types.interfaces(s.type)) {
                itypes[iphase.ordinal()] = types.union(types.closure(itype), itypes[iphase.ordinal()]);
            }
        }
    }
    Symbol concrete = bestSoFar.kind < ERR && (bestSoFar.flags() & ABSTRACT) == 0 ? bestSoFar : methodNotFound;
    for (InterfaceLookupPhase iphase2 : InterfaceLookupPhase.values()) {
        // keep searching for abstract methods
        for (Type itype : itypes[iphase2.ordinal()]) {
            // skip j.l.Object (included by Types.closure())
            if (!itype.isInterface())
                continue;
            if (iphase2 == InterfaceLookupPhase.DEFAULT_OK && (itype.tsym.flags() & DEFAULT) == 0)
                continue;
            bestSoFar = findMethodInScope(env, site, name, argtypes, typeargtypes, itype.tsym.members(), bestSoFar, allowBoxing, useVarargs, operator, true);
            if (concrete != bestSoFar && concrete.kind < ERR && bestSoFar.kind < ERR && types.isSubSignature(concrete.type, bestSoFar.type)) {
                // this is an hack - as javac does not do full membership checks
                // most specific ends up comparing abstract methods that might have
                // been implemented by some concrete method in a subclass and,
                // because of raw override, it is possible for an abstract method
                // to be more specific than the concrete method - so we need
                // to explicitly call that out (see CR 6178365)
                bestSoFar = concrete;
            }
        }
    }
    return bestSoFar;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) DeferredType(org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType) DiagnosticType(org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 87 with Symbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.

the class Resolve method resolveSelfContainingInternal.

private Symbol resolveSelfContainingInternal(Env<AttrContext> env, Symbol member, boolean isSuperCall) {
    Name name = names._this;
    Env<AttrContext> env1 = isSuperCall ? env.outer : env;
    boolean staticOnly = false;
    if (env1 != null) {
        while (env1 != null && env1.outer != null) {
            if (isStatic(env1))
                staticOnly = true;
            if (env1.enclClass.sym.isSubClass(member.owner, types)) {
                Symbol sym = env1.info.scope.lookup(name).sym;
                if (sym != null) {
                    if (staticOnly)
                        sym = new StaticError(sym);
                    return sym;
                }
            }
            if ((env1.enclClass.sym.flags() & STATIC) != 0)
                staticOnly = true;
            env1 = env1.outer;
        }
    }
    return null;
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) DeferredAttrContext(org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredAttrContext)

Example 88 with Symbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.

the class Check method checkCyclicConstructors.

/* *************************************************************************
 * Check for cycles in the constructor call graph.
 **************************************************************************/
/**
 * Check for cycles in the graph of constructors calling other
 *  constructors.
 */
void checkCyclicConstructors(JCClassDecl tree) {
    Map<Symbol, Symbol> callMap = new HashMap<Symbol, Symbol>();
    // enter each constructor this-call into the map
    for (List<JCTree> l = tree.defs; l.nonEmpty(); l = l.tail) {
        JCMethodInvocation app = TreeInfo.firstConstructorCall(l.head);
        if (app == null)
            continue;
        JCMethodDecl meth = (JCMethodDecl) l.head;
        if (TreeInfo.name(app.meth) == names._this) {
            callMap.put(meth.sym, TreeInfo.symbol(app.meth));
        } else {
            meth.sym.flags_field |= ACYCLIC;
        }
    }
    // Check for cycles in the map
    Symbol[] ctors = new Symbol[0];
    ctors = callMap.keySet().toArray(ctors);
    for (Symbol caller : ctors) {
        checkCyclicConstructor(tree, caller, callMap);
    }
}
Also used : Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol) JCTree(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)

Example 89 with Symbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.

the class Check method checkCompatibleConcretes.

/**
 * Check that a class does not inherit two concrete methods
 *  with the same signature.
 *  @param pos          Position to be used for error reporting.
 *  @param site         The class type to be checked.
 */
public void checkCompatibleConcretes(DiagnosticPosition pos, Type site) {
    Type sup = types.supertype(site);
    if (!sup.hasTag(CLASS))
        return;
    for (Type t1 = sup; t1.hasTag(CLASS) && t1.tsym.type.isParameterized(); t1 = types.supertype(t1)) {
        for (Scope.Entry e1 = t1.tsym.members().elems; e1 != null; e1 = e1.sibling) {
            Symbol s1 = e1.sym;
            if (s1.kind != MTH || (s1.flags() & (STATIC | SYNTHETIC | BRIDGE)) != 0 || !s1.isInheritedIn(site.tsym, types) || ((MethodSymbol) s1).implementation(site.tsym, types, true) != s1)
                continue;
            Type st1 = types.memberType(t1, s1);
            int s1ArgsLength = st1.getParameterTypes().length();
            if (st1 == s1.type)
                continue;
            for (Type t2 = sup; t2.hasTag(CLASS); t2 = types.supertype(t2)) {
                for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) {
                    Symbol s2 = e2.sym;
                    if (s2 == s1 || s2.kind != MTH || (s2.flags() & (STATIC | SYNTHETIC | BRIDGE)) != 0 || s2.type.getParameterTypes().length() != s1ArgsLength || !s2.isInheritedIn(site.tsym, types) || ((MethodSymbol) s2).implementation(site.tsym, types, true) != s2)
                        continue;
                    Type st2 = types.memberType(t2, s2);
                    if (types.overrideEquivalent(st1, st2))
                        log.error(pos, "concrete.inheritance.conflict", s1, t1, s2, t2, sup);
                }
            }
        }
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Example 90 with Symbol

use of org.eclipse.ceylon.langtools.tools.javac.code.Symbol in project ceylon by eclipse.

the class Check method firstDirectIncompatibility.

/**
 * Return the first method in t2 that conflicts with a method from t1.
 */
private Symbol firstDirectIncompatibility(DiagnosticPosition pos, Type t1, Type t2, Type site) {
    for (Scope.Entry e1 = t1.tsym.members().elems; e1 != null; e1 = e1.sibling) {
        Symbol s1 = e1.sym;
        Type st1 = null;
        if (s1.kind != MTH || !s1.isInheritedIn(site.tsym, types) || (s1.flags() & SYNTHETIC) != 0)
            continue;
        Symbol impl = ((MethodSymbol) s1).implementation(site.tsym, types, false);
        if (impl != null && (impl.flags() & ABSTRACT) == 0)
            continue;
        for (Scope.Entry e2 = t2.tsym.members().lookup(s1.name); e2.scope != null; e2 = e2.next()) {
            Symbol s2 = e2.sym;
            if (s1 == s2)
                continue;
            if (s2.kind != MTH || !s2.isInheritedIn(site.tsym, types) || (s2.flags() & SYNTHETIC) != 0)
                continue;
            if (st1 == null)
                st1 = types.memberType(t1, s1);
            Type st2 = types.memberType(t2, s2);
            if (types.overrideEquivalent(st1, st2)) {
                List<Type> tvars1 = st1.getTypeArguments();
                List<Type> tvars2 = st2.getTypeArguments();
                Type rt1 = st1.getReturnType();
                Type rt2 = types.subst(st2.getReturnType(), tvars2, tvars1);
                boolean compat = types.isSameType(rt1, rt2) || !rt1.isPrimitiveOrVoid() && !rt2.isPrimitiveOrVoid() && (types.covariantReturnType(rt1, rt2, types.noWarnings) || types.covariantReturnType(rt2, rt1, types.noWarnings)) || checkCommonOverriderIn(s1, s2, site);
                if (!compat) {
                    log.error(pos, "types.incompatible.diff.ret", t1, t2, s2.name + "(" + types.memberType(t2, s2).getParameterTypes() + ")");
                    return s2;
                }
            } else if (checkNameClash((ClassSymbol) site.tsym, s1, s2) && !checkCommonOverriderIn(s1, s2, site)) {
                log.error(pos, "name.clash.same.erasure.no.override", s1, s1.location(), s2, s2.location());
                return s2;
            }
        }
    }
    return null;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Symbol(org.eclipse.ceylon.langtools.tools.javac.code.Symbol)

Aggregations

Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)115 Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)42 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)16 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)15 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)12 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)11 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)11 DeferredAttrContext (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredAttrContext)8 DeferredType (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType)8 DiagnosticType (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType)8 DynamicMethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.DynamicMethodSymbol)6 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)6 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)5 DiagnosticPosition (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)4 ErrorType (org.eclipse.ceylon.javax.lang.model.type.ErrorType)3 Scope (org.eclipse.ceylon.langtools.tools.javac.code.Scope)3 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)3 HashSet (java.util.HashSet)2 LinkedList (java.util.LinkedList)2 DeclaredType (org.eclipse.ceylon.javax.lang.model.type.DeclaredType)2