Search in sources :

Example 11 with TypeDeclaration

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

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

the class BoxingVisitor method hasTypeParameterWithConstraintsOutsideScopeResolved.

private boolean hasTypeParameterWithConstraintsOutsideScopeResolved(Type type, Scope scope) {
    if (type == null)
        return false;
    if (type.isUnion()) {
        java.util.List<Type> caseTypes = type.getCaseTypes();
        for (Type pt : caseTypes) {
            if (hasTypeParameterWithConstraintsOutsideScopeResolved(pt, scope))
                return true;
        }
        return false;
    }
    if (type.isIntersection()) {
        java.util.List<Type> satisfiedTypes = type.getSatisfiedTypes();
        for (Type pt : satisfiedTypes) {
            if (hasTypeParameterWithConstraintsOutsideScopeResolved(pt, scope))
                return true;
        }
        return false;
    }
    TypeDeclaration declaration = type.getDeclaration();
    if (declaration == null)
        return false;
    if (type.isTypeParameter()) {
        // only look at it if it is defined outside our scope
        Scope typeParameterScope = declaration.getContainer();
        while (scope != null) {
            if (Decl.equalScopes(scope, typeParameterScope))
                return false;
            scope = scope.getContainer();
        }
        TypeParameter tp = (TypeParameter) declaration;
        Boolean nonErasedBounds = tp.hasNonErasedBounds();
        if (nonErasedBounds == null)
            visitTypeParameter(tp);
        return nonErasedBounds != null ? nonErasedBounds.booleanValue() : false;
    }
    // now check its type parameters
    for (Type pt : type.getTypeArgumentList()) {
        if (hasTypeParameterWithConstraintsOutsideScopeResolved(pt, scope))
            return true;
    }
    // no problem here
    return false;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 13 with TypeDeclaration

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

the class BoxingVisitor method visit.

@Override
public void visit(QualifiedMemberExpression that) {
    super.visit(that);
    // handle errors gracefully
    if (that.getDeclaration() == null)
        return;
    if (that.getMemberOperator() instanceof Tree.SafeMemberOp) {
        TypedDeclaration decl = (TypedDeclaration) that.getDeclaration();
        if (CodegenUtil.isRaw(decl))
            CodegenUtil.markRaw(that);
        if (CodegenUtil.hasTypeErased(decl))
            CodegenUtil.markTypeErased(that);
        if (CodegenUtil.hasUntrustedType(decl) || hasTypeParameterWithConstraintsOutsideScope(decl.getType(), that.getScope()))
            CodegenUtil.markUntrustedType(that);
    // we must be boxed, since safe member op "?." returns an optional type
    // return;
    } else if (that.getMemberOperator() instanceof Tree.MemberOp && Decl.isValueTypeDecl(that.getPrimary()) && CodegenUtil.isUnBoxed(that.getPrimary())) {
        // it's unboxed if it's an unboxable type or it's declared void
        if (Decl.isValueTypeDecl((TypedDeclaration) that.getDeclaration()) || (that.getDeclaration() instanceof Function && ((Function) that.getDeclaration()).isDeclaredVoid()))
            CodegenUtil.markUnBoxed(that);
        if (CodegenUtil.isRaw((TypedDeclaration) that.getDeclaration()))
            CodegenUtil.markRaw(that);
        if (CodegenUtil.hasTypeErased((TypedDeclaration) that.getDeclaration()))
            CodegenUtil.markTypeErased(that);
    } else {
        propagateFromDeclaration(that, (TypedDeclaration) that.getDeclaration());
    }
    // be (ex: <String>), and in that case we will generate a proper Sequential<String> which is not raw at all
    if (that.getMemberOperator() instanceof Tree.SpreadOp) {
        // find the return element type
        Type elementType = that.getTarget().getType();
        CodegenUtil.markTypeErased(that, hasErasure(elementType));
    }
    if (ExpressionTransformer.isSuperOrSuperOf(that.getPrimary())) {
        // if the target is an interface whose type arguments have been turned to raw, make this expression
        // as erased
        Reference target = that.getTarget();
        if (target != null && target.getQualifyingType() != null && target.getQualifyingType().getDeclaration() instanceof Interface) {
            if (isRaw(target.getQualifyingType())) {
                CodegenUtil.markTypeErased(that);
            } else // See note in ClassTransformer.makeDelegateToCompanion for a similar test
            {
                TypeDeclaration declaration = target.getQualifyingType().getDeclaration();
                if (needsRawCastForMixinSuperCall(declaration, target.getType()))
                    CodegenUtil.markTypeErased(that);
            }
        }
    }
    Type primaryType;
    if (that.getPrimary() instanceof Tree.Package || that.getTarget() == null) {
        primaryType = that.getPrimary().getTypeModel();
    } else {
        primaryType = that.getTarget().getQualifyingType();
    }
    if (primaryType != null && (isRaw(primaryType) || willEraseToSequence(primaryType)) && that.getTarget() != null && that.getTarget().getDeclaration() instanceof TypedDeclaration && CodegenUtil.containsTypeParameter(((TypedDeclaration) that.getTarget().getDeclaration()).getType())) {
        CodegenUtil.markTypeErased(that);
    }
    if (isRaw(primaryType) && that.getTypeModel().getDeclaration().isParameterized()) {
        CodegenUtil.markRaw(that);
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Function(org.eclipse.ceylon.model.typechecker.model.Function) Type(org.eclipse.ceylon.model.typechecker.model.Type) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface)

Example 14 with TypeDeclaration

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

the class ClassDoc method loadInheritedMembers.

private void loadInheritedMembers(MemberSpecification specification, List<TypeDeclaration> superClassOrInterfaceList, Map<MemberSpecification, Map<TypeDeclaration, SortedMap<String, Declaration>>> superClassOrInterfaceInheritedMemebers) {
    LinkedHashMap<TypeDeclaration, SortedMap<String, Declaration>> inheritedMembersMap = new LinkedHashMap<TypeDeclaration, SortedMap<String, Declaration>>();
    for (TypeDeclaration superClassOrInterface : superClassOrInterfaceList) {
        SortedMap<String, Declaration> inheritedMembers = new TreeMap<String, Declaration>();
        for (Declaration member : superClassOrInterface.getMembers()) {
            if (specification.isSatisfiedBy(member) && tool.shouldInclude(member)) {
                inheritedMembers.put(Util.getDeclarationName(member), member);
                for (String alias : member.getAliases()) {
                    inheritedMembers.put(alias, member);
                }
            }
        }
        if (!inheritedMembers.isEmpty()) {
            inheritedMembersMap.put(superClassOrInterface, inheritedMembers);
        }
    }
    superClassOrInterfaceInheritedMemebers.put(specification, inheritedMembersMap);
}
Also used : SortedMap(java.util.SortedMap) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TreeMap(java.util.TreeMap) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with TypeDeclaration

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

the class ClassDoc method writeInnerTypes.

private void writeInnerTypes(Map<String, ? extends TypeDeclaration> innerTypeDeclarations, String id, String title) throws IOException {
    if (!innerTypeDeclarations.isEmpty()) {
        openTable(id, title, 2, true);
        for (Entry<String, ? extends TypeDeclaration> entry : innerTypeDeclarations.entrySet()) {
            TypeDeclaration innerTypeDeclaration = entry.getValue();
            String name = entry.getKey();
            if (innerTypeDeclaration instanceof ClassOrInterface) {
                ClassOrInterface innerClassOrInterface = (ClassOrInterface) innerTypeDeclaration;
                tool.doc(innerClassOrInterface);
                doc(name, innerClassOrInterface);
            }
            if (innerTypeDeclaration instanceof TypeAlias) {
                TypeAlias innerAlias = (TypeAlias) innerTypeDeclaration;
                doc(name, innerAlias);
            }
        }
        closeTable();
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) 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