Search in sources :

Example 66 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.ObjectDefinition that) {
    Class ac = that.getAnonymousClass();
    Declaration od = beginReturnDeclaration(ac);
    Tree.Type rt = beginReturnScope(fakeVoid(that));
    super.visit(that);
    endReturnScope(rt, null);
    endReturnDeclaration(od);
}
Also used : 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.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 67 with Class

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

the class DeprecationVisitor method visit.

@Override
public void visit(Tree.MemberOrTypeExpression that) {
    super.visit(that);
    Declaration d = that.getDeclaration();
    if (d != null && d.isDeprecated()) {
        that.addUsageWarning(Warning.deprecation, "declaration is deprecated: '" + d.getName() + "' is annotated 'deprecated' in " + module(d));
    }
    if (d instanceof Class && that.getDirectlyInvoked()) {
        Class c = (Class) d;
        Constructor dc = c.getDefaultConstructor();
        if (dc != null && dc.isDeprecated()) {
            that.addUsageWarning(Warning.deprecation, "declaration is deprecated: default constructor of '" + d.getName() + "' is annotated 'deprecated' in " + module(d));
        }
    }
}
Also used : Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 68 with Class

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

the class ClassImpl method getCaseValues.

@Override
@TypeInfo("ceylon.language::Sequential<Type>")
public ceylon.language.Sequential<? extends Type> getCaseValues() {
    Class classDecl = (Class) declaration.declaration;
    if (classDecl.hasEnumerated()) {
        // can only possibly have value constructor cases
        if (classDecl.getCaseTypes() == null || classDecl.getCaseTypes().isEmpty()) {
            // it's not a closed enum of value constructors
            return (Sequential) empty_.get_();
        }
        ArrayList<Type> ctors = new ArrayList<>();
        for (ceylon.language.meta.declaration.Declaration d : ((ClassDeclarationImpl) declaration).constructors()) {
            Declaration dd = null;
            if (d instanceof CallableConstructorDeclarationImpl) {
                continue;
            } else if (d instanceof ValueConstructorDeclarationImpl) {
                dd = ((ValueConstructorDeclarationImpl) d).declaration;
            }
            // ATM this is an AND WRT annotation types: all must be present
            ctors.add(((ValueConstructor<Type>) getDeclaredConstructor(TypeDescriptor.NothingType, d.getName())).get());
        }
        Object[] array = ctors.toArray(new Object[ctors.size()]);
        ObjectArrayIterable<ceylon.language.meta.declaration.Declaration> iterable = new ObjectArrayIterable<ceylon.language.meta.declaration.Declaration>(this.$reifiedType, (Object[]) array);
        return (ceylon.language.Sequential) iterable.sequence();
    } else {
        return super.getCaseValues();
    }
}
Also used : CallableConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.CallableConstructorDeclarationImpl) ArrayList(java.util.ArrayList) ObjectArrayIterable(org.eclipse.ceylon.compiler.java.language.ObjectArrayIterable) Sequential(ceylon.language.Sequential) ValueConstructorDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ValueConstructorDeclarationImpl) ClassDeclarationImpl(org.eclipse.ceylon.compiler.java.runtime.metamodel.decl.ClassDeclarationImpl) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) CallableConstructorDeclaration(ceylon.language.meta.declaration.CallableConstructorDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ValueConstructorDeclaration(ceylon.language.meta.declaration.ValueConstructorDeclaration) TypeInfo(org.eclipse.ceylon.compiler.java.metadata.TypeInfo)

Example 69 with Class

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

the class ClassImpl method getDispatch.

ConstructorDispatch<Type, Arguments> getDispatch() {
    if (!initialized) {
        synchronized (this) {
            if (!initialized) {
                checkConstructor();
                Reference reference;
                if (!hasConstructors() && !hasEnumerated()) {
                    reference = producedType;
                } else {
                    reference = ((org.eclipse.ceylon.model.typechecker.model.Class) declaration.declaration).getDefaultConstructor().appliedReference(producedType, null);
                }
                this.dispatch = new ConstructorDispatch<Type, Arguments>(reference, this, null, ((Class) producedType.getDeclaration()).getFirstParameterList().getParameters(), instance);
                this.initialized = true;
            }
        }
    }
    return dispatch;
}
Also used : Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 70 with Class

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

the class ClassDeclarationImpl method init.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void init() {
    super.init();
    // anonymous classes don't have parameter lists
    if (!declaration.isAnonymous()) {
        org.eclipse.ceylon.model.typechecker.model.Class classDeclaration = (org.eclipse.ceylon.model.typechecker.model.Class) declaration;
        if (classDeclaration.isAbstraction()) {
            List<Declaration> overloads = classDeclaration.getOverloads();
            if (overloads.size() == 1) {
                classDeclaration = (org.eclipse.ceylon.model.typechecker.model.Class) overloads.get(0);
            }
        // else{
        // throw Metamodel.newModelError("Class has more than one overloaded constructor: "+classDeclaration.getNameAsString());
        // }
        }
        ParameterList parameterList = classDeclaration.getParameterList();
        if (parameterList != null) {
            this.parameters = FunctionalUtil.getParameters(classDeclaration);
        } else {
            this.parameters = null;
        }
    } else {
        this.parameters = null;
    }
    if (((Class) declaration).hasConstructors() || ((Class) declaration).hasEnumerated()) {
        this.constructors = new LinkedList<ceylon.language.meta.declaration.Declaration>();
        for (Declaration d : declaration.getMembers()) {
            if (d instanceof Constructor) {
                this.constructors.add(Metamodel.<ceylon.language.meta.declaration.Declaration>getOrCreateMetamodel(d));
            }
        }
    } else {
        this.constructors = Collections.emptyList();
    }
}
Also used : Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Class(org.eclipse.ceylon.model.typechecker.model.Class) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) Class(org.eclipse.ceylon.model.typechecker.model.Class) CallableConstructorDeclaration(ceylon.language.meta.declaration.CallableConstructorDeclaration) FunctionOrValueDeclaration(ceylon.language.meta.declaration.FunctionOrValueDeclaration) ValueDeclaration(ceylon.language.meta.declaration.ValueDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) ConstructorDeclaration(ceylon.language.meta.declaration.ConstructorDeclaration) ValueConstructorDeclaration(ceylon.language.meta.declaration.ValueConstructorDeclaration)

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