Search in sources :

Example 71 with Type

use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.

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(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeParameter(com.redhat.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) TypedReference(com.redhat.ceylon.model.typechecker.model.TypedReference)

Example 72 with Type

use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.

the class Util method getSuperInterfaces.

public static List<TypeDeclaration> getSuperInterfaces(TypeDeclaration decl) {
    Set<TypeDeclaration> superInterfaces = new HashSet<TypeDeclaration>();
    for (Type satisfiedType : decl.getSatisfiedTypes()) {
        superInterfaces.add(satisfiedType.getDeclaration());
        superInterfaces.addAll(getSuperInterfaces(satisfiedType.getDeclaration()));
    }
    List<TypeDeclaration> list = new ArrayList<TypeDeclaration>();
    list.addAll(superInterfaces);
    removeDuplicates(list);
    return list;
}
Also used : Type(com.redhat.ceylon.model.typechecker.model.Type) ArrayList(java.util.ArrayList) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration) HashSet(java.util.HashSet)

Example 73 with Type

use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.

the class AbstractTransformer method collectRefinedMembers.

private void collectRefinedMembers(Type currentType, String name, java.util.List<Type> signature, boolean ellipsis, java.util.Set<TypeDeclaration> visited, Set<TypedDeclaration> ret, boolean ignoreFirst) {
    TypeDeclaration decl = currentType.getDeclaration();
    if (visited.contains(decl)) {
        return;
    } else {
        visited.add(decl);
        Type et = currentType.getExtendedType();
        if (et != null) {
            collectRefinedMembers(et, name, signature, ellipsis, visited, ret, false);
        }
        for (Type st : currentType.getSatisfiedTypes()) {
            collectRefinedMembers(st, name, signature, ellipsis, visited, ret, false);
        }
        // we're collecting refined members, not the refining one
        if (!ignoreFirst) {
            TypedDeclaration found = (TypedDeclaration) decl.getDirectMember(name, signature, ellipsis);
            if (found instanceof Function) {
                // do not trust getDirectMember because if you ask it for [Integer,String] and it has [Integer,E] it does not
                // know that E=String and will not make it match, and will just return any member when there is overloading,
                // including one with signature [String] when you asked for [Integer,String]
                java.util.List<Type> typedSignature = getTypedSignature(currentType, found);
                if (typedSignature != null && hasMatchingSignature(signature, typedSignature))
                    ret.add(found);
            }
        }
    }
}
Also used : TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Example 74 with Type

use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.

the class AbstractTransformer method makeJavaTypeAnnotations.

List<JCTree.JCAnnotation> makeJavaTypeAnnotations(TypedDeclaration decl, boolean handleFunctionalParameter) {
    if (decl == null || decl.getType() == null)
        return List.nil();
    Type type;
    if (decl instanceof Function && ((Function) decl).isParameter() && handleFunctionalParameter) {
        type = getTypeForFunctionalParameter((Function) decl);
    } else if (decl instanceof Functional && Decl.isMpl((Functional) decl)) {
        type = getReturnTypeOfCallable(decl.appliedTypedReference(null, Collections.<Type>emptyList()).getFullType());
    } else {
        type = decl.getType();
    }
    boolean declaredVoid = decl instanceof Function && Strategy.useBoxedVoid((Function) decl) && Decl.isUnboxedVoid(decl);
    return makeJavaTypeAnnotations(type, declaredVoid, CodegenUtil.hasTypeErased(decl), CodegenUtil.hasUntrustedType(decl), needsJavaTypeAnnotations(decl));
}
Also used : Functional(com.redhat.ceylon.model.typechecker.model.Functional) Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)

Example 75 with Type

use of com.redhat.ceylon.model.typechecker.model.Type in project ceylon-compiler by ceylon.

the class AbstractTransformer method makeJavaType.

/**
     * This function is used solely for method return types and parameters 
     */
JCExpression makeJavaType(TypedDeclaration typeDecl, Type type, int flags) {
    if (typeDecl instanceof Function && ((Function) typeDecl).isParameter()) {
        Function p = (Function) typeDecl;
        Type pt = type;
        for (int ii = 1; ii < p.getParameterLists().size(); ii++) {
            pt = typeFact().getCallableType(pt);
        }
        return makeJavaType(typeFact().getCallableType(pt), flags);
    } else {
        boolean usePrimitives = CodegenUtil.isUnBoxed(typeDecl);
        return makeJavaType(type, flags | (usePrimitives ? 0 : AbstractTransformer.JT_NO_PRIMITIVES));
    }
}
Also used : Function(com.redhat.ceylon.model.typechecker.model.Function) Type(com.redhat.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)

Aggregations

Type (com.redhat.ceylon.model.typechecker.model.Type)237 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)98 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)87 TypeParameter (com.redhat.ceylon.model.typechecker.model.TypeParameter)56 JCTree (com.sun.tools.javac.tree.JCTree)53 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)51 ModelUtil.appliedType (com.redhat.ceylon.model.typechecker.model.ModelUtil.appliedType)46 Class (com.redhat.ceylon.model.typechecker.model.Class)45 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)43 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)41 IntersectionType (com.redhat.ceylon.model.typechecker.model.IntersectionType)37 UnionType (com.redhat.ceylon.model.typechecker.model.UnionType)37 Test (org.junit.Test)37 TypeParser (com.redhat.ceylon.model.loader.TypeParser)36 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)34 Function (com.redhat.ceylon.model.typechecker.model.Function)33 Interface (com.redhat.ceylon.model.typechecker.model.Interface)30 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)30 TypedReference (com.redhat.ceylon.model.typechecker.model.TypedReference)29 ArrayList (java.util.ArrayList)28