Search in sources :

Example 56 with ClassOrInterface

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.Declaration that) {
    String filename = unit.getFilename();
    Declaration model = that.getDeclarationModel();
    if (isDescriptor(filename) && model.isToplevel()) {
        that.addError("declaration may not occur in a module or package descriptor file");
    }
    Declaration d = beginDeclaration(model);
    super.visit(that);
    endDeclaration(d);
    if (model.isClassOrInterfaceMember()) {
        ClassOrInterface container = (ClassOrInterface) model.getContainer();
        if (container.isFinal() && model.isDefault()) {
            that.addError("member of final class may not be annotated 'default'", 1350);
        }
    }
    if (model.isToplevel()) {
        String name = model.getName();
        if (name != null && name.endsWith("_")) {
            that.addUnsupportedError("toplevel declaration name ending in _ not currently supported");
        }
        if (pkg.getNameAsString().endsWith("_")) {
            that.addUnsupportedError("toplevel declaration belonging to package with name ending in _ not currently supported");
        }
    }
}
Also used : ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) 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)

Example 57 with ClassOrInterface

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

the class DeclarationVisitor method checkForDuplicateDeclaration.

private static void checkForDuplicateDeclaration(Tree.Declaration that, Declaration model, Scope scope) {
    String name = model.getName();
    Unit unit = model.getUnit();
    if (name != null) {
        if (model instanceof Setter) {
            Setter setter = (Setter) model;
            checkGetterForSetter(that, setter, scope);
        } else {
            // this isn't the correct scope for declaration
            // which follow an assertion, since it misses
            // condition scopes, so use the argument scope
            // Scope scope = model.getContainer();
            boolean isControl;
            do {
                Declaration member = scope.getDirectMember(name, null, false);
                if (member != null && member != model) {
                    boolean dup = false;
                    boolean possibleOverloadedMethod = member instanceof Function && model instanceof Function && scope instanceof ClassOrInterface && !member.isNative() && member.isShared() && model.isShared();
                    boolean legalOverloadedMethod = possibleOverloadedMethod;
                    if (legalOverloadedMethod) {
                        // anticipate that it might be
                        // an overloaded method - then
                        // further checking happens in
                        // RefinementVisitor
                        initFunctionOverload((Function) model, (Function) member, scope, unit);
                    } else if (canBeNative(member) && canBeNative(model) && model.isNative()) {
                    // just to make sure no error
                    // gets reported
                    } else {
                        dup = true;
                        if (possibleOverloadedMethod) {
                            // it as overloading anyway
                            if (initFunctionOverload((Function) model, (Function) member, scope, unit)) {
                                that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
                            }
                        } else {
                            that.addError("duplicate declaration: the name '" + name + "' is not unique in this scope");
                        }
                    }
                    if (dup) {
                        unit.getDuplicateDeclarations().add(member);
                    }
                }
                isControl = scope instanceof ControlBlock;
                scope = scope.getContainer();
            } while (isControl);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) ControlBlock(org.eclipse.ceylon.model.typechecker.model.ControlBlock) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) 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) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 58 with ClassOrInterface

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.ClassDefinition that) {
    Class c = new Class();
    if (!isVeryAbstractClass(that, unit)) {
        defaultExtendedToBasic(c);
    }
    that.setDeclarationModel(c);
    super.visit(that);
    if (that.getParameterList() == null) {
        if (c.isClassOrInterfaceMember() && (c.isFormal() || c.isDefault() || c.isActual())) {
            that.addError("member class declared 'formal', 'default', or 'actual' must have a parameter list");
        }
        Tree.AnnotationList al = that.getAnnotationList();
        if (hasAnnotation(al, "sealed", unit)) {
            that.addError("class without parameter list may not be annotated 'sealed'", 1800);
        }
    }
    if (c.isSealed() && c.isFormal() && c.isClassOrInterfaceMember()) {
        ClassOrInterface container = (ClassOrInterface) c.getContainer();
        if (!container.isSealed()) {
            that.addError("sealed formal member class does not belong to a sealed type", 1801);
        }
    }
    if (c.isNativeImplementation()) {
        addMissingHeaderMembers(c);
    }
    if (c.isAbstraction()) {
        initClassOverloads(getContainer(that), c, unit);
    }
}
Also used : ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) 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 59 with ClassOrInterface

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.ObjectDefinition that) {
    Class c = new Class();
    defaultExtendedToBasic(c);
    c.setAnonymous(true);
    that.setAnonymousClass(c);
    visitDeclaration(that, c, false);
    Value v = new Value();
    that.setDeclarationModel(v);
    visitDeclaration(that, v);
    Type t = c.getType();
    that.getType().setTypeModel(t);
    v.setType(t);
    v.setStatic(c.isStatic());
    if (c.isStatic()) {
        Scope container = v.getContainer();
        if (container instanceof ClassOrInterface) {
            ClassOrInterface ci = (ClassOrInterface) container;
            if (!ci.getTypeParameters().isEmpty()) {
                that.addError("anonymous class belonging to generic type may not be annotated 'static'");
            }
        }
    }
    Scope o = enterScope(c);
    super.visit(that);
    exitScope(o);
    if (c.isInterfaceMember()) {
        that.addError("object declaration may not occur directly in interface body");
    }
    if (c.isNativeImplementation()) {
        addMissingHeaderMembers(c);
    }
}
Also used : ModelUtil.getContainingClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface) ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) 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) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) 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 60 with ClassOrInterface

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

the class InheritanceVisitor method visit.

@Override
public void visit(Tree.SatisfiedTypes that) {
    super.visit(that);
    TypeDeclaration td = (TypeDeclaration) that.getScope();
    if (td.isAlias()) {
        return;
    }
    Set<TypeDeclaration> set = new HashSet<TypeDeclaration>();
    if (td.getSatisfiedTypes().isEmpty()) {
        // handle undecidable case
        return;
    }
    Unit unit = that.getUnit();
    for (Tree.StaticType t : that.getTypes()) {
        Type type = t.getTypeModel();
        if (!isTypeUnknown(type) && type.isClassOrInterface()) {
            type = type.resolveAliases();
            TypeDeclaration dec = type.getDeclaration();
            if (td instanceof ClassOrInterface && !unit.getPackage().getModule().isLanguageModule()) {
                if (unit.isCallableType(type)) {
                    t.addError("satisfies 'Callable'");
                }
                TypeDeclaration cad = unit.getConstrainedAnnotationDeclaration();
                if (dec.equals(cad)) {
                    t.addError("directly satisfies 'ConstrainedAnnotation'");
                }
            }
            if (!set.add(dec)) {
                // this error is not really truly necessary
                // but the spec says it is an error, and
                // the backend doesn't like it
                t.addError("duplicate satisfied type: '" + dec.getName(unit) + "' of '" + td.getName() + "'");
            }
            if (td instanceof ClassOrInterface) {
                TypeDeclaration std = dec;
                if (std.isSealed() && !unit.inSameModule(std)) {
                    String moduleName = std.getUnit().getPackage().getModule().getNameAsString();
                    t.addError("satisfies a sealed interface in a different module: '" + std.getName(unit) + "' in '" + moduleName + "'");
                }
            }
            checkSelfTypes(t, td, type);
            checkExtensionOfMemberType(t, td, type);
        /*if (!(td instanceof TypeParameter)) {
                    checkCaseOfSupertype(t, td, type);
                }*/
        }
        if (t instanceof Tree.SimpleType) {
            Tree.SimpleType st = (Tree.SimpleType) t;
            checkSupertypeVarianceAnnotations(st);
        }
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) Type(org.eclipse.ceylon.model.typechecker.model.Type) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Unit(org.eclipse.ceylon.model.typechecker.model.Unit) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) HashSet(java.util.HashSet)

Aggregations

ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)102 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)62 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)48 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)46 Type (org.eclipse.ceylon.model.typechecker.model.Type)44 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)27 Class (org.eclipse.ceylon.model.typechecker.model.Class)24 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)23 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)23 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)20 ModelUtil.getContainingClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getContainingClassOrInterface)19 Value (org.eclipse.ceylon.model.typechecker.model.Value)19 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)18 ArrayList (java.util.ArrayList)17 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)17 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)16 Function (org.eclipse.ceylon.model.typechecker.model.Function)14 LazyInterface (org.eclipse.ceylon.model.loader.model.LazyInterface)13 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)12 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)12