Search in sources :

Example 71 with Type

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

the class Types method firstUnimplementedAbstractImpl.

// where:
private MethodSymbol firstUnimplementedAbstractImpl(ClassSymbol impl, ClassSymbol c) {
    MethodSymbol undef = null;
    // since they cannot have abstract members.
    if (c == impl || (c.flags() & (ABSTRACT | INTERFACE)) != 0) {
        Scope s = c.members();
        for (Scope.Entry e = s.elems; undef == null && e != null; e = e.sibling) {
            if (e.sym.kind == MTH && (e.sym.flags() & (ABSTRACT | IPROXY | DEFAULT)) == ABSTRACT) {
                MethodSymbol absmeth = (MethodSymbol) e.sym;
                MethodSymbol implmeth = absmeth.implementation(impl, this, true);
                if (implmeth == null || implmeth == absmeth) {
                    // look for default implementations
                    if (allowDefaultMethods) {
                        MethodSymbol prov = interfaceCandidates(impl.type, absmeth).head;
                        if (prov != null && prov.overrides(absmeth, impl, this, true)) {
                            implmeth = prov;
                        }
                    }
                }
                if (implmeth == null || implmeth == absmeth) {
                    undef = absmeth;
                } else if (sourceLanguage.isCeylon())
                    implmeth.flags_field |= CEYLON_METHOD_OVERRIDE_CHECKED;
            }
        }
        if (undef == null) {
            Type st = supertype(c.type);
            if (st.hasTag(CLASS))
                undef = firstUnimplementedAbstractImpl(impl, (ClassSymbol) st.tsym);
        }
        for (List<Type> l = interfaces(c.type); undef == null && l.nonEmpty(); l = l.tail) {
            undef = firstUnimplementedAbstractImpl(impl, (ClassSymbol) l.head.tsym);
        }
    }
    return undef;
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type) Scope(org.eclipse.ceylon.langtools.tools.javac.code.Scope)

Example 72 with Type

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

the class Types method typaramsString.

// where
private String typaramsString(List<Type> tvars) {
    StringBuilder s = new StringBuilder();
    s.append('<');
    boolean first = true;
    for (Type t : tvars) {
        if (!first)
            s.append(", ");
        first = false;
        appendTyparamString(((TypeVar) t.unannotatedType()), s);
    }
    s.append('>');
    return s.toString();
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 73 with Type

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

the class Types method substBound.

public TypeVar substBound(TypeVar t, List<Type> from, List<Type> to) {
    Type bound1 = subst(t.bound, from, to);
    if (bound1 == t.bound)
        return t;
    else {
        // create new type variable without bounds
        TypeVar tv = new TypeVar(t.tsym, null, syms.botType);
        // the new bound should use the new type variable in place
        // of the old
        tv.bound = subst(bound1, List.<Type>of(t), List.<Type>of(tv));
        // Fix for Ceylon: try really hard not to make recursive bounds
        if (tv.bound == tv)
            tv.bound = t;
        return tv;
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 74 with Type

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

the class Types method removeWildcards.

public Type removeWildcards(Type site) {
    Type capturedSite = capture(site);
    if (capturedSite != site) {
        Type formalInterface = site.tsym.type;
        ListBuffer<Type> typeargs = new ListBuffer<>();
        List<Type> actualTypeargs = site.getTypeArguments();
        List<Type> capturedTypeargs = capturedSite.getTypeArguments();
        // simply replace the wildcards with its bound
        for (Type t : formalInterface.getTypeArguments()) {
            if (actualTypeargs.head.hasTag(WILDCARD)) {
                WildcardType wt = (WildcardType) actualTypeargs.head.unannotatedType();
                Type bound;
                switch(wt.kind) {
                    case EXTENDS:
                    case UNBOUND:
                        CapturedType capVar = (CapturedType) capturedTypeargs.head.unannotatedType();
                        // use declared bound if it doesn't depend on formal type-args
                        bound = capVar.bound.containsAny(capturedSite.getTypeArguments()) ? wt.type : capVar.bound;
                        break;
                    default:
                        bound = wt.type;
                }
                typeargs.append(bound);
            } else {
                typeargs.append(actualTypeargs.head);
            }
            actualTypeargs = actualTypeargs.tail;
            capturedTypeargs = capturedTypeargs.tail;
        }
        return subst(formalInterface, formalInterface.getTypeArguments(), typeargs.toList());
    } else {
        return site;
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Example 75 with Type

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

the class Types method asOuterSuper.

/**
 * Return the base type of t or any of its outer types that starts
 * with the given symbol.  If none exists, return null.
 *
 * @param t a type
 * @param sym a symbol
 */
public Type asOuterSuper(Type t, Symbol sym) {
    switch(t.getTag()) {
        case CLASS:
            do {
                Type s = asSuper(t, sym);
                if (s != null)
                    return s;
                t = t.getEnclosingType();
            } while (t.hasTag(CLASS));
            return null;
        case ARRAY:
            return isSubtype(t, sym.type) ? sym.type : null;
        case TYPEVAR:
            return asSuper(t, sym);
        case ERROR:
            return t;
        default:
            return null;
    }
}
Also used : Type(org.eclipse.ceylon.langtools.tools.javac.code.Type)

Aggregations

Type (org.eclipse.ceylon.langtools.tools.javac.code.Type)164 Symbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol)46 DeferredType (org.eclipse.ceylon.langtools.tools.javac.comp.DeferredAttr.DeferredType)13 DiagnosticType (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticType)13 ArrayType (org.eclipse.ceylon.langtools.tools.javac.code.Type.ArrayType)10 MethodType (org.eclipse.ceylon.langtools.tools.javac.code.Type.MethodType)10 ClassSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.ClassSymbol)9 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)9 MethodSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.MethodSymbol)8 JavaFileObject (org.eclipse.ceylon.javax.tools.JavaFileObject)7 TypeSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.TypeSymbol)7 DiagnosticPosition (org.eclipse.ceylon.langtools.tools.javac.util.JCDiagnostic.DiagnosticPosition)7 JavacType (org.eclipse.ceylon.compiler.java.loader.mirror.JavacType)5 PackageSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.PackageSymbol)5 FunctionalInterfaceType (org.eclipse.ceylon.model.loader.mirror.FunctionalInterfaceType)5 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)5 HashSet (java.util.HashSet)4 CompletionFailure (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.CompletionFailure)4 VarSymbol (org.eclipse.ceylon.langtools.tools.javac.code.Symbol.VarSymbol)4 FreeTypeListener (org.eclipse.ceylon.langtools.tools.javac.comp.Infer.FreeTypeListener)4