Search in sources :

Example 66 with Value

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

the class InheritanceVisitor method visit.

@Override
public void visit(Tree.Enumerated that) {
    super.visit(that);
    Value v = that.getDeclarationModel();
    Scope container = v.getContainer();
    if (container instanceof Class) {
        Class cl = (Class) container;
        List<TypedDeclaration> caseValues = cl.getCaseValues();
        if (caseValues != null && !caseValues.contains(v) && !cl.isAbstract()) {
            that.addError("value constructor is not a case of enumerated class: '" + v.getName() + "' is not listed in the 'of' clause of '" + cl.getName() + "'");
        }
    }
}
Also used : AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Value(org.eclipse.ceylon.model.typechecker.model.Value) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 67 with Value

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

the class LocalDeclarationVisitor method visit.

@Override
public void visit(Tree.ObjectDefinition that) {
    visitLocalDecl(that);
    // use the same qualifier for the object type
    Class c = that.getAnonymousClass();
    Value v = that.getDeclarationModel();
    if (c != null && v != null) {
        c.setQualifier(v.getQualifier());
    }
    Map<String, Integer> oldLocalNames = localNames;
    localNames = new HashMap<String, Integer>();
    super.visit(that);
    localNames = oldLocalNames;
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 68 with Value

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

the class TypeArgumentInference method constrainInferredTypes.

private List<Type> constrainInferredTypes(List<TypeParameter> typeParameters, List<Type> inferredTypeArgs, Type qualifyingType, Declaration declaration) {
    int size = inferredTypeArgs.size();
    boolean found = false;
    for (int i = 0; i < size; i++) {
        TypeParameter tp = typeParameters.get(i);
        // if (!tp.isCovariant()) {
        List<Type> bounds = tp.getSatisfiedTypes();
        if (!bounds.isEmpty()) {
            found = true;
        }
    // }
    }
    if (found) {
        Reference ref;
        if (declaration instanceof Value) {
            Value value = (Value) declaration;
            if (value.getType().isTypeConstructor()) {
                if (qualifyingType == null) {
                    ref = declaration.appliedReference(null, NO_TYPE_ARGS);
                } else {
                    ref = qualifyingType.getTypedReference(declaration, NO_TYPE_ARGS);
                }
                TypeDeclaration dec = ref.getType().getDeclaration();
                ref = dec.appliedReference(null, inferredTypeArgs);
            } else {
                return inferredTypeArgs;
            }
        } else {
            if (qualifyingType == null) {
                ref = declaration.appliedReference(null, inferredTypeArgs);
            } else {
                ref = qualifyingType.getTypedReference(declaration, inferredTypeArgs);
            }
        }
        Map<TypeParameter, Type> args = ref.getTypeArguments();
        ArrayList<Type> result = new ArrayList<Type>(size);
        for (int i = 0; i < size; i++) {
            TypeParameter tp = typeParameters.get(i);
            Type arg = inferredTypeArgs.get(i);
            Type constrainedArg = // tp.isCovariant() ? arg :
            constrainInferredType(tp, arg, args);
            result.add(constrainedArg);
        }
        return result;
    } else {
        return inferredTypeArgs;
    }
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) ArrayList(java.util.ArrayList) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Example 69 with Value

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

the class TypeHierarchyVisitor method visit.

@Override
public void visit(Tree.ObjectDefinition that) {
    super.visit(that);
    Value value = that.getDeclarationModel();
    Class anonymousClass = that.getAnonymousClass();
    // an object definition is always concrete
    List<Type> orderedTypes = sortDAGAndBuildMetadata(value.getTypeDeclaration(), that);
    checkForFormalsNotImplemented(that, orderedTypes, anonymousClass);
    checkForDoubleMemberInheritanceNotOverridden(that, orderedTypes, anonymousClass);
    checkForDoubleMemberInheritanceWoCommonAncestor(that, orderedTypes, anonymousClass);
    validateMemberRefinement(that, anonymousClass);
}
Also used : IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Class(org.eclipse.ceylon.model.typechecker.model.Class)

Example 70 with Value

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

the class TypeVisitor method visit.

@Override
public void visit(Tree.AnyAttribute that) {
    super.visit(that);
    Tree.Type type = that.getType();
    if (type instanceof Tree.SequencedType) {
        Value v = (Value) that.getDeclarationModel();
        Parameter p = v.getInitializerParameter();
        if (p == null) {
            type.addError("value is not a parameter, so may not be variadic: '" + v.getName() + "'");
        } else {
            p.setSequenced(true);
        }
    }
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Aggregations

Value (org.eclipse.ceylon.model.typechecker.model.Value)190 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)135 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)77 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)74 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)70 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)69 Type (org.eclipse.ceylon.model.typechecker.model.Type)68 Function (org.eclipse.ceylon.model.typechecker.model.Function)50 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)47 Class (org.eclipse.ceylon.model.typechecker.model.Class)46 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)42 JavaBeanValue (org.eclipse.ceylon.model.loader.model.JavaBeanValue)30 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)30 ArrayList (java.util.ArrayList)29 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)29 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)28 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)27 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)26 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)24 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)23