Search in sources :

Example 11 with TypeParameter

use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.

the class AbstractTransformer method makeRawType.

protected JCExpression makeRawType(final int flags, Type type, Type simpleType) {
    JCExpression jt;
    TypeDeclaration tdecl = simpleType.getDeclaration();
    // - The Ceylon type T results in the Java type T
    if (isCeylonCallable(type) && (flags & JT_CLASS_NEW) != 0) {
        jt = makeIdent(syms().ceylonAbstractCallableType);
    } else if (tdecl instanceof TypeParameter)
        jt = makeQuotedIdent(tdecl.getName());
    else // don't use underlying type if we want no primitives
    if ((flags & (JT_SATISFIES | JT_NO_PRIMITIVES)) != 0 || simpleType.getUnderlyingType() == null) {
        jt = naming.makeDeclarationName(tdecl, jtFlagsToDeclNameOpts(flags));
    } else
        jt = makeQuotedFQIdent(simpleType.getUnderlyingType());
    return jt;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 12 with TypeParameter

use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.

the class AbstractTransformer method collectQualifyingTypeArguments.

/**
 * Collects all the type parameters and arguments required for an interface that's been pulled up to the
 * toplevel, including its containing type and method type parameters.
 */
private void collectQualifyingTypeArguments(java.util.List<TypeParameter> qualifyingTypeParameters, Map<TypeParameter, Type> qualifyingTypeArguments, java.util.List<Reference> qualifyingTypes) {
    // make sure we only add type parameters with the same name once, as duplicates are erased from the target interface
    // since they cannot be accessed
    Set<String> names = new HashSet<String>();
    // walk the qualifying types backwards to make sure we only add a TP with the same name once and the outer one wins
    for (int i = qualifyingTypes.size() - 1; i >= 0; i--) {
        Reference qualifiedType = qualifyingTypes.get(i);
        Map<TypeParameter, Type> tas = qualifiedType.getTypeArguments();
        java.util.List<TypeParameter> tps = qualifiedType.getDeclaration().getTypeParameters();
        // add any type params for this type
        if (tps != null) {
            int index = 0;
            for (TypeParameter tp : tps) {
                // add it only once
                if (names.add(tp.getName())) {
                    // start putting all these type parameters at 0 and then in order
                    // so that outer type params end up before inner type params but
                    // order is preserved within each type
                    qualifyingTypeParameters.add(index++, tp);
                    qualifyingTypeArguments.put(tp, tas.get(tp));
                }
            }
        }
        // add any container method TP
        Declaration declaration = qualifiedType.getDeclaration();
        if (Decl.isLocal(declaration)) {
            Scope scope = declaration.getContainer();
            // collect every container method until the next type or package
            java.util.List<Function> methods = new LinkedList<Function>();
            while (scope != null && scope instanceof ClassOrInterface == false && scope instanceof Package == false) {
                if (scope instanceof Function) {
                    methods.add((Function) scope);
                }
                scope = scope.getContainer();
            }
            // methods are sorted inner to outer, which is the order we're following here for types
            for (Function method : methods) {
                java.util.List<TypeParameter> methodTypeParameters = method.getTypeParameters();
                if (methodTypeParameters != null) {
                    int index = 0;
                    for (TypeParameter tp : methodTypeParameters) {
                        // add it only once
                        if (names.add(tp.getName())) {
                            // start putting all these type parameters at 0 and then in order
                            // so that outer type params end up before inner type params but
                            // order is preserved within each type
                            qualifyingTypeParameters.add(index++, tp);
                            qualifyingTypeArguments.put(tp, tp.getType());
                        }
                    }
                }
            }
        }
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) LinkedList(java.util.LinkedList) Function(org.eclipse.ceylon.model.typechecker.model.Function) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Package(org.eclipse.ceylon.model.typechecker.model.Package) HashSet(java.util.HashSet)

Example 13 with TypeParameter

use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.

the class AbstractTransformer method hasSubstitutedBounds.

boolean hasSubstitutedBounds(Type pt) {
    TypeDeclaration declaration = pt.getDeclaration();
    java.util.List<TypeParameter> tps = declaration.getTypeParameters();
    final Map<TypeParameter, Type> tas = pt.getTypeArguments();
    boolean isCallable = isCeylonCallable(pt);
    for (TypeParameter tp : tps) {
        Type ta = tas.get(tp);
        // error recovery
        if (ta == null)
            continue;
        if (!tp.getSatisfiedTypes().isEmpty()) {
            for (Type bound : tp.getSatisfiedTypes()) {
                bound = bound.substitute(pt);
                if (expressionGen().needsCast(ta, bound, false, false, false))
                    return true;
            }
        }
        if (hasSubstitutedBounds(ta))
            return true;
        // Callable ignores type parameters after the first
        if (isCallable)
            break;
    }
    return false;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 14 with TypeParameter

use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.

the class AbstractTransformer method getTypeArguments.

private java.util.List<Type> getTypeArguments(Function method) {
    java.util.List<TypeParameter> typeParameters = method.getTypeParameters();
    java.util.List<Type> typeArguments = new ArrayList<Type>(typeParameters.size());
    for (TypeParameter tp : typeParameters) typeArguments.add(tp.getType());
    return typeArguments;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ArrayList(java.util.ArrayList)

Example 15 with TypeParameter

use of org.eclipse.ceylon.model.typechecker.model.TypeParameter in project ceylon by eclipse.

the class AbstractTransformer method isWideningTypeDecl.

public boolean isWideningTypeDecl(TypedReference typedReference, Type currentType) {
    TypedReference refinedTypedReference = getRefinedDeclaration(typedReference, currentType);
    if (refinedTypedReference == null)
        return false;
    /*
         * We are widening if the type:
         * - is not object
         * - is erased to object
         * - refines a declaration that is not erased to object
         */
    Type declType = typedReference.getType();
    Type refinedDeclType = refinedTypedReference.getType();
    if (declType == null || refinedDeclType == null)
        return false;
    if (isWidening(declType, refinedDeclType))
        return true;
    // make sure we get the instantiated refined decl
    if (refinedDeclType.getDeclaration() instanceof TypeParameter && !(declType.getDeclaration() instanceof TypeParameter))
        refinedDeclType = nonWideningType(typedReference, refinedTypedReference);
    if (isWideningTypeArguments(declType, refinedDeclType, true))
        return true;
    if (CodegenUtil.hasTypeErased(refinedTypedReference.getDeclaration()) && !willEraseToObject(declType))
        return true;
    return false;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference)

Aggregations

TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)181 Type (org.eclipse.ceylon.model.typechecker.model.Type)138 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)82 ArrayList (java.util.ArrayList)57 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)57 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)54 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)46 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)45 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)35 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)32 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)30 Function (org.eclipse.ceylon.model.typechecker.model.Function)29 AnalyzerUtil.getTupleType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType)28 AnalyzerUtil.spreadType (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType)28 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)28 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)27 JCTypeParameter (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter)26 Class (org.eclipse.ceylon.model.typechecker.model.Class)26 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)25 HashMap (java.util.HashMap)24