Search in sources :

Example 6 with Scope

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

the class LinkRenderer method processTypedDeclaration.

private String processTypedDeclaration(TypedDeclaration decl) {
    String declName = Util.getDeclarationName(decl);
    Scope declContainer = decl.getContainer();
    if (isLinkable(decl)) {
        String url = getUrl(declContainer, declName);
        if (url != null) {
            return buildLinkElement(url, getLinkText(decl), "Go to " + decl.getQualifiedNameString());
        }
    }
    String result = declName;
    if (withinText) {
        result = "<code>" + result + "</code>";
    }
    if (customText != null) {
        result = customText;
    }
    return result;
}
Also used : Scope(org.eclipse.ceylon.model.typechecker.model.Scope)

Example 7 with Scope

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

the class ExpressionVisitor method getBaseReceivingType.

protected Type getBaseReceivingType(Tree.InvocationExpression that, Declaration dec) {
    Scope scope = that.getScope();
    if (dec.isClassOrInterfaceMember() && !dec.isStatic() && !dec.isDefinedInScope(scope)) {
        ClassOrInterface ci = (ClassOrInterface) dec.getContainer();
        Type qualifyingType = scope.getDeclaringType(dec);
        List<Type> inferredArgs = new TypeArgumentInference(unit).getInferredTypeArgsForReference(that, dec, ci, qualifyingType);
        return ci.appliedType(null, inferredArgs);
    } else {
        return null;
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) ModelUtil.getOuterClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getOuterClassOrInterface) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) 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)

Example 8 with Scope

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

the class ExpressionVisitor method visitBaseMemberExpression.

private void visitBaseMemberExpression(Tree.StaticMemberOrTypeExpression that, TypedDeclaration member, List<Type> typeArgs, Tree.TypeArguments tal, Type receivingType) {
    if (acceptsTypeArguments(member, null, typeArgs, tal, that) || true) {
        Scope scope = that.getScope();
        Type outerType = scope.getDeclaringType(member);
        if (outerType == null) {
            outerType = receivingType;
        }
        TypedReference pr = member.appliedTypedReference(outerType, typeArgs, that.getAssigned());
        that.setTarget(pr);
        boolean direct = that.getDirectlyInvoked();
        Type fullType = accountForGenericFunctionRef(direct, tal, outerType, typeArgs, pr.getFullType());
        if (!dynamic && !isNativeForWrongBackend(scope, unit) && !isAbstraction(member) && isTypeUnknown(fullType) && !hasError(that)) {
            that.addError("could not determine type of function or value reference: the type of '" + member.getName(unit) + "' is not known" + getTypeUnknownError(fullType));
        }
        if (dynamic && isTypeUnknown(fullType)) {
            // type information we have
            return;
        }
        that.setTypeModel(fullType);
    }
}
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) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference)

Example 9 with Scope

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

the class ExpressionVisitor method resolveBaseTypeExpression.

private TypeDeclaration resolveBaseTypeExpression(Tree.BaseTypeExpression that, boolean error) {
    Tree.Identifier id = that.getIdentifier();
    String name = name(id);
    Scope scope = that.getScope();
    TypeDeclaration type = getTypeDeclaration(scope, name, that.getSignature(), that.getEllipsis(), that.getUnit());
    if (type == null) {
        if (error && !dynamic && !isNativeForWrongBackend(scope, unit)) {
            that.addError("type is not defined: '" + name + "'" + correctionMessage(name, scope, unit, cancellable), 102);
            unit.setUnresolvedReferences();
        }
    } else {
        type = (TypeDeclaration) handleAbstractionOrHeader(type, that, error);
        that.setDeclaration(type);
        if (error) {
            if (checkConcreteClass(type, that)) {
                if (checkVisibleConstructor(that, type)) {
                    checkBaseTypeAndConstructorVisibility(that, name, type);
                }
            }
        }
    }
    return type;
}
Also used : NativeUtil.declarationScope(org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) 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 10 with Scope

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

Aggregations

Scope (org.eclipse.ceylon.model.typechecker.model.Scope)142 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)71 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)57 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)50 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)44 Type (org.eclipse.ceylon.model.typechecker.model.Type)44 ConditionScope (org.eclipse.ceylon.model.typechecker.model.ConditionScope)35 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)34 Class (org.eclipse.ceylon.model.typechecker.model.Class)33 ModelUtil.getRealScope (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope)31 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)30 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)26 Value (org.eclipse.ceylon.model.typechecker.model.Value)26 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)25 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)24 Function (org.eclipse.ceylon.model.typechecker.model.Function)23 Package (org.eclipse.ceylon.model.typechecker.model.Package)22 ArrayList (java.util.ArrayList)21 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)20 NativeUtil.declarationScope (org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope)15