Search in sources :

Example 96 with Class

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

the class ExpressionVisitor method checkDefaultConstructorVisibility.

private boolean checkDefaultConstructorVisibility(Tree.MemberOrTypeExpression that, TypeDeclaration type) {
    if (type instanceof Class && !contains(type, that.getScope()) && !that.getStaticMethodReferencePrimary()) {
        Class c = (Class) type;
        Constructor dc = c.getDefaultConstructor();
        if (dc != null && !dc.isShared()) {
            that.addError("default constructor for class '" + c.getName(unit) + "' is not 'shared'");
            return false;
        }
    }
    return true;
}
Also used : 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) ModelUtil.findMatchingOverloadedClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.findMatchingOverloadedClass) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 97 with Class

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

the class RefinementVisitor method checkMember.

private void checkMember(Tree.Declaration that, Declaration member) {
    String name = member.getName();
    if (name == null) {
        return;
    }
    if (member instanceof Setter) {
        Setter setter = (Setter) member;
        Value getter = setter.getGetter();
        Declaration rd = getter.getRefinedDeclaration();
        member.setRefinedDeclaration(rd);
        return;
    }
    ClassOrInterface type = (ClassOrInterface) member.getContainer();
    if (member.isFormal() && type instanceof Class) {
        Class c = (Class) type;
        if (!c.isAbstract() && !c.isFormal()) {
            if (c.isClassOrInterfaceMember()) {
                that.addError("formal member belongs to concrete nested class: '" + member.getName() + "' is a member of class '" + c.getName() + "' which is neither 'abstract' nor 'formal'", 1100);
            } else {
                that.addError("formal member belongs to concrete class: '" + member.getName() + "' is a member of class '" + c.getName() + "' which is not annotated 'abstract'", 1100);
            }
        }
    }
    if (member.isStatic() && !type.isToplevel()) {
        that.addError("static member belongs to a nested class: '" + member.getName() + "' is a member of nested type '" + type.getName() + "'");
    }
    if (type.isDynamic()) {
        if (member instanceof Class) {
            that.addError("member class belongs to dynamic interface");
        } else if (!member.isFormal()) {
            that.addError("non-formal member belongs to dynamic interface");
        }
    }
    if (member instanceof Functional && !that.hasErrors() && isOverloadedVersion(member)) {
        checkOverloadedAnnotation(that, member);
        checkOverloadedParameters(that, member);
    }
    checkRefinement(that, member, type);
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 98 with Class

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

the class SpecificationVisitor method visit.

@Override
public void visit(Tree.DelegatedConstructor that) {
    boolean odc = inDelegatedContructor;
    inDelegatedContructor = true;
    super.visit(that);
    inDelegatedContructor = odc;
    Tree.SimpleType type = that.getType();
    if (type != null) {
        delegatedConstructor = type.getDeclarationModel();
        if (delegatedConstructor instanceof Class) {
            // this case is not actually legal
            Class c = (Class) delegatedConstructor;
            delegatedConstructor = c.getDefaultConstructor();
        }
    }
}
Also used : Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 99 with Class

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.AnyClass that) {
    Class c = that.getDeclarationModel();
    visitDeclaration(that, c);
    Scope o = enterScope(c);
    super.visit(that);
    exitScope(o);
    Tree.ParameterList pl = that.getParameterList();
    if (pl != null) {
        pl.getModel().setFirst(true);
        c.addParameterList(pl.getModel());
    }
    // TODO: is this still necessary??
    if (c.isClassOrInterfaceMember() && c.getContainer() instanceof TypedDeclaration) {
        that.addUnsupportedError("nested classes of inner classes are not yet supported");
    }
    Tree.Identifier identifier = that.getIdentifier();
    if (c.isAbstract() && c.isFinal()) {
        that.addError("class may not be both 'abstract' and 'final': '" + name(identifier) + "'");
    }
    if (c.isFormal() && c.isFinal()) {
        that.addError("class may not be both 'formal' and 'final': '" + name(identifier) + "'");
    }
    if (hasAnnotation(that.getAnnotationList(), "service", that.getUnit())) {
        if (!c.getTypeParameters().isEmpty()) {
            that.addError("service class may not be generic");
        }
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) ModelUtil.isAnonymousClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isAnonymousClass)

Example 100 with Class

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

the class DeclarationVisitor method initClassOverloads.

// A class with an overloaded default constructor
// is represented in the model as an overloaded
// class with multiple Class objects. The Constructor
// objects themselves are not represented as
// overloaded since we never look them up directly
// at the invocation site
private static void initClassOverloads(Scope scope, Class abstraction, Unit unit) {
    ArrayList<Declaration> overloads = new ArrayList<Declaration>(3);
    for (Declaration d : abstraction.getMembers()) {
        if (isDefaultConstructor(d)) {
            Constructor cc = (Constructor) d;
            Class overload = new Class();
            overload.setName(abstraction.getName());
            overload.setUnit(unit);
            overload.setScope(abstraction.getScope());
            overload.setContainer(abstraction.getContainer());
            overload.setOverloaded(true);
            overload.setExtendedType(abstraction.getType());
            overload.setParameterList(cc.getParameterList());
            overload.setNativeBackends(abstraction.getNativeBackends());
            overload.setFinal(abstraction.isFinal());
            overloads.add(overload);
            unit.addDeclaration(overload);
            scope.addMember(overload);
        }
    }
    abstraction.setOverloads(overloads);
}
Also used : ModelUtil.isDefaultConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isDefaultConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) ArrayList(java.util.ArrayList) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) ModelUtil.isAnonymousClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isAnonymousClass) 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) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

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