Search in sources :

Example 6 with Class

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

the class AnnotationUtil method isNaturalTarget.

/**
 * Whether an annotation (with the given {@code annotationCtorDecl}
 * annotation constructor) used on the given declaration ({@code useSite})
 * should be added to the Java annotations of the given generated program
 * elements ({@code target})
 * @param annotationCtorDecl
 * @param useSite
 * @param target
 * @return
 */
public static boolean isNaturalTarget(// use site is either a Declaration, or a Package, or a Module,
Function annotationCtorDecl, // module imports
Object useSite, OutputElement target) {
    EnumSet<AnnotationTarget> interopTargets;
    if (annotationCtorDecl instanceof AnnotationProxyMethod) {
        AnnotationProxyMethod annotationProxyMethod = (AnnotationProxyMethod) annotationCtorDecl;
        if (annotationProxyMethod.getAnnotationTarget() == target) {
            // Foo__WHATEVER, so honour the WHATEVER
            return true;
        }
        interopTargets = annotationProxyMethod.getAnnotationTargets();
    } else {
        interopTargets = null;
    }
    if (useSite instanceof Declaration) {
        if (ModelUtil.isConstructor((Declaration) useSite)) {
            if (useSite instanceof Functional) {
                return target == OutputElement.CONSTRUCTOR;
            } else if (useSite instanceof Value) {
                // If the constructor has a getter we can't annotate, let's
                // put the annotations on the constructor
                Class constructedClass = ModelUtil.getConstructedClass((Declaration) useSite);
                // See CeylonVisitor.transformSingletonConstructor for those tests
                if (constructedClass.isToplevel() || constructedClass.isClassMember())
                    return target == OutputElement.GETTER;
                return target == OutputElement.CONSTRUCTOR;
            }
        } else if (useSite instanceof Class) {
            if (((Class) useSite).getParameterList() != null && interopTargets != null && interopTargets.contains(AnnotationTarget.CONSTRUCTOR) && !interopTargets.contains(AnnotationTarget.TYPE)) {
                return target == OutputElement.CONSTRUCTOR;
            }
            return target == OutputElement.TYPE;
        } else if (useSite instanceof Interface) {
            return target == OutputElement.TYPE;
        } else if (useSite instanceof Value) {
            Value value = (Value) useSite;
            boolean p = value.isParameter() && target == OutputElement.PARAMETER;
            if (annotationCtorDecl instanceof AnnotationProxyMethod) {
                if (!value.isTransient() && (interopTargets == null || interopTargets.contains(AnnotationTarget.FIELD))) {
                    return target == OutputElement.FIELD;
                } else {
                    return target == OutputElement.GETTER;
                }
            } else {
                return p || target == OutputElement.GETTER;
            }
        } else if (useSite instanceof Setter) {
            return target == OutputElement.SETTER;
        } else if (useSite instanceof Function) {
            return target == OutputElement.METHOD;
        } else if (useSite instanceof Constructor) {
            return target == OutputElement.CONSTRUCTOR;
        } else if (useSite instanceof TypeAlias) {
            return target == OutputElement.TYPE;
        }
    } else if (useSite instanceof Package) {
        return (annotationCtorDecl instanceof AnnotationProxyMethod) ? target == OutputElement.PACKAGE : target == OutputElement.TYPE;
    } else if (useSite instanceof Module) {
        return target == OutputElement.TYPE;
    } else if (useSite instanceof Tree.ImportModule) {
        return target == OutputElement.FIELD;
    }
    throw new RuntimeException("" + useSite);
}
Also used : AnnotationTarget(org.eclipse.ceylon.model.loader.model.AnnotationTarget) AnnotationProxyMethod(org.eclipse.ceylon.model.loader.model.AnnotationProxyMethod) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) Interface(org.eclipse.ceylon.model.typechecker.model.Interface)

Example 7 with Class

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

the class ExpressionVisitor method getCallableBottomType.

private Type getCallableBottomType(int size) {
    Type paramListType;
    Type nothingType = unit.getNothingType();
    Type anythingType = unit.getAnythingType();
    if (size < 0) {
        paramListType = anythingType;
    } else {
        paramListType = unit.getEmptyType();
        Class tuple = unit.getTupleDeclaration();
        for (int i = 0; i < size; i++) {
            paramListType = appliedType(tuple, anythingType, anythingType, paramListType);
        }
    }
    Interface callable = unit.getCallableDeclaration();
    return appliedType(callable, nothingType, paramListType);
}
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.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint) Interface(org.eclipse.ceylon.model.typechecker.model.Interface) 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)

Example 8 with Class

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

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

Example 10 with Class

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

the class ExpressionVisitor method visitGenericQualifiedTypeReference.

private void visitGenericQualifiedTypeReference(Tree.QualifiedTypeExpression that, Type outerType, TypeDeclaration type) {
    if (type instanceof Class && type.isParameterized()) {
        Class generic = (Class) type;
        Scope scope = that.getScope();
        Type target = outerType.getTypeMember(type, typeParametersAsArgList(generic));
        that.setTarget(target);
        Type functionType = genericFunctionType(generic, scope, type, target, unit);
        that.setTypeModel(functionType);
        checkNotJvm(that, "type functions are not supported on the JVM: '" + type.getName(unit) + "' is generic (specify explicit type arguments)");
    }
}
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) ModelUtil.findMatchingOverloadedClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.findMatchingOverloadedClass) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Aggregations

Class (org.eclipse.ceylon.model.typechecker.model.Class)184 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)110 Type (org.eclipse.ceylon.model.typechecker.model.Type)87 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)78 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)72 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)55 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)46 Value (org.eclipse.ceylon.model.typechecker.model.Value)46 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)42 UnionType (org.eclipse.ceylon.model.typechecker.model.UnionType)39 Function (org.eclipse.ceylon.model.typechecker.model.Function)38 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)36 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)35 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)33 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)33 ArrayList (java.util.ArrayList)32 IntersectionType (org.eclipse.ceylon.model.typechecker.model.IntersectionType)32 JCNewClass (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCNewClass)31 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)27 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)23