Search in sources :

Example 21 with TypeDeclaration

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.QualifiedTypeExpression that) {
    super.visit(that);
    boolean notIndirectlyInvoked = !that.getIndirectlyInvoked();
    boolean notDirectlyInvoked = !that.getDirectlyInvoked();
    TypeDeclaration type = resolveQualifiedTypeExpression(that, notIndirectlyInvoked);
    boolean inferrableAnyway = !notDirectlyInvoked && inferrableAnyway(type);
    if (type != null && notDirectlyInvoked || inferrableAnyway) {
        Tree.Primary primary = that.getPrimary();
        Tree.TypeArguments tal = that.getTypeArguments();
        Type receiverType = primary.getTypeModel().resolveAliases();
        List<Type> typeArgs;
        if (explicitTypeArguments(type, tal)) {
            typeArgs = getTypeArguments(tal, receiverType, type.getTypeParameters());
        } else {
            typeArgs = new TypeArgumentInference(unit).getInferredTypeArgsForFunctionRef(that, receiverType, inferrableAnyway);
        }
        if (typeArgs != null) {
            tal.setTypeModels(typeArgs);
            if (primary instanceof Tree.Package) {
                visitBaseTypeExpression(that, type, typeArgs, tal, null);
            } else {
                visitQualifiedTypeExpression(that, receiverType, type, typeArgs, tal);
            }
        } else if (notDirectlyInvoked) {
            if (!that.getStaticMethodReferencePrimary()) {
                if (primary instanceof Tree.Package) {
                    visitGenericBaseTypeReference(that, type);
                } else {
                    visitGenericQualifiedTypeReference(that, receiverType, type);
                }
            }
        }
        if (that.getStaticMethodReference()) {
            handleStaticReferenceImplicitTypeArguments(that);
        }
    // otherwise infer type arguments later
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.declaredInPackage(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.declaredInPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) AnalyzerUtil.importedPackage(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.importedPackage) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 22 with TypeDeclaration

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

the class ExpressionVisitor method resolveQualifiedTypeExpression.

private TypeDeclaration resolveQualifiedTypeExpression(Tree.QualifiedTypeExpression that, boolean error) {
    if (checkMember(that)) {
        Tree.Primary primary = that.getPrimary();
        Tree.Identifier id = that.getIdentifier();
        List<Type> signature = that.getSignature();
        boolean spread = that.getEllipsis();
        String name = name(id);
        String container;
        boolean ambiguous;
        TypeDeclaration type;
        Type pt;
        if (primary instanceof Tree.Package) {
            Package pack = unit.getPackage();
            container = "package '" + pack.getNameAsString() + "'";
            type = getPackageTypeDeclaration(name, signature, spread, unit);
            ambiguous = false;
            pt = null;
        } else {
            pt = primary.getTypeModel().resolveAliases();
            TypeDeclaration d = getDeclaration(that, pt);
            if (d instanceof Constructor) {
                d = d.getExtendedType().getDeclaration();
            }
            container = "type '" + d.getName(unit) + "'";
            Scope scope = that.getScope();
            type = getTypeMember(d, name, signature, spread, unit, scope);
            ambiguous = type == null && d.isMemberAmbiguous(name, unit, signature, spread);
            if (type == null) {
                container += memberCorrectionMessage(name, d, scope, unit, cancellable);
            }
        }
        if (type == null) {
            if (error) {
                if (ambiguous) {
                    that.addError("member type is ambiguous: '" + name + "' for " + container);
                } else {
                    that.addError("member type is not defined: '" + name + "' in " + container, 100);
                    unit.setUnresolvedReferences();
                }
            }
        } else {
            type = (TypeDeclaration) handleAbstractionOrHeader(type, that, error);
            if (error) {
                checkStaticPrimary(that, primary, type, pt);
            }
            that.setDeclaration(type);
            resetSuperReference(that);
            if (!isSelfReference(primary) && !type.isShared()) {
                type.setOtherInstanceAccess(true);
            }
            if (error) {
                if (checkConcreteClass(type, that)) {
                    if (checkVisibleConstructor(that, type)) {
                        checkQualifiedTypeAndConstructorVisibility(that, type, name, container);
                    }
                }
                if (!inExtendsClause) {
                    checkSuperMember(that, signature, spread);
                }
            }
        }
        return type;
    } else {
        return null;
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) NativeUtil.declarationScope(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) AnalyzerUtil.unwrapAliasedTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.declaredInPackage(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.declaredInPackage) Package(org.eclipse.ceylon.model.typechecker.model.Package) AnalyzerUtil.importedPackage(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.importedPackage) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 23 with TypeDeclaration

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

the class ExpressionVisitor method checkStaticPrimary.

private void checkStaticPrimary(Tree.QualifiedMemberOrTypeExpression that, Tree.Primary primary, Declaration member, Type pt) {
    if (member.isStatic() && !that.getStaticMethodReference()) {
        Tree.MemberOperator mo = that.getMemberOperator();
        TypeDeclaration outer = (TypeDeclaration) member.getContainer();
        if (member.isJava()) {
            primary.addUsageWarning(Warning.syntaxDeprecation, "reference to static member should be qualified by type: '" + member.getName(unit) + "' is a static member of '" + outer.getName(unit) + "'");
        } else if (!(mo instanceof Tree.MemberOp)) {
            mo.addError("operator '" + mo.getText() + "' may not be followed by reference to static member: '" + member.getName(unit) + "' is a static member of '" + outer.getName(unit) + "'");
        } else {
            primary.addError("reference to static member must be qualified by type: '" + member.getName(unit) + "' is a static member of '" + pt.getSupertype(outer).asString(unit) + "'", 14000);
        }
    }
}
Also used : CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 24 with TypeDeclaration

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

the class ExpressionVisitor method checkDelegatedConstructor.

protected void checkDelegatedConstructor(Tree.DelegatedConstructor dc, Constructor c, Node node) {
    if (dc == null) {
        if (c.isClassMember()) {
            Class clazz = (Class) c.getContainer();
            Type et = clazz.getExtendedType();
            if (et != null && !et.isBasic()) {
                TypeDeclaration superclass = et.getDeclaration();
                if (superclass != null) {
                    node.addError("constructor must explicitly delegate to some superclass constructor: '" + clazz.getName() + "' extends '" + superclass.getName() + "'");
                }
            }
        }
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) ModelUtil.findMatchingOverloadedClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.findMatchingOverloadedClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 25 with TypeDeclaration

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.ClassDeclaration that) {
    super.visit(that);
    Class alias = that.getDeclarationModel();
    Type et = alias.getExtendedType();
    Tree.ClassSpecifier cs = that.getClassSpecifier();
    if (cs != null && et != null) {
        TypeDeclaration etd = et.getDeclaration();
        if (etd instanceof Constructor) {
            etd = etd.getExtendedType().getDeclaration();
        }
        if (etd instanceof Class) {
            // TODO: some of this belongs in InheritanceVisitor!
            Class c = (Class) etd;
            if (c.isAbstract()) {
                if (!alias.isFormal() && !alias.isAbstract()) {
                    that.addError("alias of abstract class must be annotated abstract", 310);
                }
            }
            if (c.isAbstraction()) {
                that.addError("class alias may not alias overloaded class");
            } else {
                Tree.InvocationExpression ie = cs.getInvocationExpression();
                if (ie != null) {
                    checkClassAliasParameters(alias, that, ie);
                }
            }
        }
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) AnalyzerUtil.unwrapAliasedTypeConstructor(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.unwrapAliasedTypeConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) ModelUtil.findMatchingOverloadedClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.findMatchingOverloadedClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

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