Search in sources :

Example 6 with TypeDeclaration

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

the class AbstractTransformer method makeParameterisedType.

public JCExpression makeParameterisedType(Type type, Type generalType, final int flags, JCExpression qualifyingExpression, java.util.List<Reference> qualifyingTypes, int firstQualifyingTypeWithTypeParameters, int index) {
    JCExpression baseType;
    TypeDeclaration tdecl = type.getDeclaration();
    ListBuffer<JCExpression> typeArgs = null;
    if (index >= firstQualifyingTypeWithTypeParameters) {
        int taFlags = flags;
        if (qualifyingTypes != null && index < qualifyingTypes.size() - 1) {
            // The qualifying types before the main one should
            // have type parameters with proper variance
            taFlags &= ~(JT_EXTENDS | JT_SATISFIES);
        }
        typeArgs = makeTypeArgs(type, taFlags);
    }
    if (isCeylonCallable(generalType) && (flags & JT_CLASS_NEW) != 0) {
        baseType = makeIdent(syms().ceylonAbstractCallableType);
    } else if (index == 0) {
        // qualified type is static
        if (tdecl instanceof Interface && qualifyingTypes != null && qualifyingTypes.size() > 1 && firstQualifyingTypeWithTypeParameters == 0 && (flags & JT_NON_QUALIFIED) == 0) {
            baseType = naming.makeCompanionClassName(tdecl);
        } else {
            baseType = naming.makeDeclarationName(tdecl, jtFlagsToDeclNameOpts(flags));
        }
    } else {
        baseType = naming.makeTypeDeclarationExpression(qualifyingExpression, tdecl, jtFlagsToDeclNameOpts(flags | JT_NON_QUALIFIED | (type.getDeclaration() instanceof Interface ? JT_COMPANION : 0)));
    }
    if (typeArgs != null && typeArgs.size() > 0) {
        qualifyingExpression = make().TypeApply(baseType, typeArgs.toList());
    } else {
        qualifyingExpression = baseType;
    }
    return qualifyingExpression;
}
Also used : JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)

Example 7 with TypeDeclaration

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

the class AbstractTransformer method declarationAppearsInInvariantPosition.

private boolean declarationAppearsInInvariantPosition(TypeDeclaration declaration, Type type) {
    if (type.isUnion()) {
        for (Type pt : type.getCaseTypes()) {
            if (declarationAppearsInInvariantPosition(declaration, pt))
                return true;
        }
        return false;
    }
    if (type.isIntersection()) {
        for (Type pt : type.getSatisfiedTypes()) {
            if (declarationAppearsInInvariantPosition(declaration, pt))
                return true;
        }
        return false;
    }
    if (type.isClassOrInterface()) {
        TypeDeclaration typeDeclaration = type.getDeclaration();
        java.util.List<TypeParameter> typeParameters = typeDeclaration.getTypeParameters();
        Map<TypeParameter, Type> typeArguments = type.getTypeArguments();
        for (TypeParameter tp : typeParameters) {
            Type typeArgument = typeArguments.get(tp);
            if (tp.isInvariant() || hasDependentTypeParameters(typeParameters, tp)) {
                if (Decl.equal(typeArgument.getDeclaration(), declaration)) {
                    return true;
                }
            }
            if (declarationAppearsInInvariantPosition(declaration, typeArgument))
                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) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 8 with TypeDeclaration

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

the class AbstractTransformer method getTypedReference.

TypedReference getTypedReference(TypedDeclaration decl) {
    java.util.List<Type> typeArgs = Collections.<Type>emptyList();
    if (decl instanceof Function) {
        // For methods create type arguments for any type parameters it might have
        Function m = (Function) decl;
        if (!m.getTypeParameters().isEmpty()) {
            typeArgs = new ArrayList<Type>(m.getTypeParameters().size());
            for (TypeParameter p : m.getTypeParameters()) {
                Type pt = p.getType();
                typeArgs.add(pt);
            }
        }
    }
    if (decl.getContainer() instanceof TypeDeclaration) {
        TypeDeclaration containerDecl = (TypeDeclaration) decl.getContainer();
        return containerDecl.getType().getTypedMember(decl, typeArgs);
    }
    return decl.appliedTypedReference(null, typeArgs);
}
Also used : 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) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 9 with TypeDeclaration

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

the class AbstractTransformer method canUseFastFailTypeTest.

private boolean canUseFastFailTypeTest(Type type) {
    if (type.getDeclaration() instanceof ClassOrInterface == false)
        return false;
    boolean isRaw = type.getDeclaration().isParameterized();
    Type qualifyingType = type.getQualifyingType();
    if (qualifyingType == null && // ignore qualifying types of static java declarations
    (ModelUtil.isCeylonDeclaration(type.getDeclaration()) || !type.getDeclaration().isStatic())) {
        Declaration declaration = type.getDeclaration();
        boolean local = false;
        do {
            // getDeclarationContainer will skip some containers we don't want to consider, so it's not good
            // for checking locality, rely on isLocal for that.
            local |= Decl.isLocal(declaration);
            // it may be contained in a function or value, and we want its type
            Declaration enclosingDeclaration = getDeclarationContainer(declaration);
            if (enclosingDeclaration instanceof TypedDeclaration) {
                local = true;
                // look up the containers
                declaration = enclosingDeclaration;
            } else if (enclosingDeclaration instanceof TypeDeclaration) {
                // contain type parameters, unless the local is raw
                if (enclosingDeclaration.isParameterized() && local && !isRaw)
                    return false;
                // look up the containers
                declaration = enclosingDeclaration;
            } else {
                // that's fucked up
                break;
            }
        // go up every containing typed declaration
        } while (declaration != null);
        // we can fast-fail!
        return true;
    } else if (qualifyingType != null) {
        // we can only fast-fail if the qualifying type can also be fast-failed
        return canUseFastFailTypeTest(qualifyingType);
    } else {
        // we can fast-fail!
        return true;
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 10 with TypeDeclaration

use of org.eclipse.ceylon.model.typechecker.model.TypeDeclaration 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)

Aggregations

TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)303 Type (org.eclipse.ceylon.model.typechecker.model.Type)180 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)88 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)86 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)80 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)70 Class (org.eclipse.ceylon.model.typechecker.model.Class)68 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)65 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)57 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)57 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)55 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)51 Test (org.junit.Test)51 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)49 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)49 ArrayList (java.util.ArrayList)48 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)44 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)43 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)39 ModelUtil.intersectionType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType)34