Search in sources :

Example 21 with Scope

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.AttributeSetterDefinition that) {
    Setter s = new Setter();
    s.setImplemented(that.getBlock() != null);
    that.setDeclarationModel(s);
    visitDeclaration(that, s);
    Scope o = enterScope(s);
    Parameter p = new Parameter();
    p.setHidden(true);
    Value v = new Value();
    v.setInitializerParameter(p);
    p.setModel(v);
    v.setName(s.getName());
    p.setName(s.getName());
    p.setDeclaration(s);
    visitElement(that, v);
    unit.addDeclaration(v);
    Scope sc = getContainer(that);
    sc.addMember(v);
    s.setParameter(p);
    super.visit(that);
    exitScope(o);
    if (that.getSpecifierExpression() == null && that.getBlock() == null && !isNativeHeader(s) && !isNativeHeader(s.getGetter())) {
        that.addError("setter declaration must have a body or => specifier");
    }
}
Also used : 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) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Example 22 with Scope

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

the class DeclarationVisitor method visit.

public void visit(Tree.SuperType that) {
    super.visit(that);
    if (inExtends) {
        final Scope scope = that.getScope();
        Type t = new LazyType(unit) {

            @Override
            public TypeDeclaration initDeclaration() {
                ClassOrInterface ci = getContainingClassOrInterface(scope);
                if (ci == null) {
                    return null;
                } else {
                    if (ci.isClassOrInterfaceMember()) {
                        ClassOrInterface oci = (ClassOrInterface) ci.getContainer();
                        return intersectionOfSupertypes(oci).getDeclaration();
                    } else {
                        return null;
                    }
                }
            }

            @Override
            public Map<TypeParameter, Type> initTypeArguments() {
                return emptyMap();
            }
        };
        that.setTypeModel(t);
    }
}
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) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) 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) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType)

Example 23 with Scope

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

the class ClassTransformer method typeParametersForInstantiator.

/**
 * When generating an instantiator method if the inner class has a type
 * parameter with the same name as a type parameter of an outer type, then the
 * instantiator method shouldn't declare its own type parameter of that
 * name -- it should use the captured one. This method filters out the
 * type parameters of the inner class which are the same as type parameters
 * of the outer class so that they can be captured.
 */
private java.util.List<TypeParameter> typeParametersForInstantiator(final Class model) {
    java.util.List<TypeParameter> filtered = new ArrayList<TypeParameter>();
    java.util.List<TypeParameter> tps = model.getTypeParameters();
    if (tps != null) {
        for (TypeParameter tp : tps) {
            boolean omit = false;
            Scope s = model.getContainer();
            while (!(s instanceof Package)) {
                if (s instanceof Generic) {
                    for (TypeParameter outerTp : ((Generic) s).getTypeParameters()) {
                        if (tp.getName().equals(outerTp.getName())) {
                            omit = true;
                        }
                    }
                }
                s = s.getContainer();
            }
            if (!omit) {
                filtered.add(tp);
            }
        }
    }
    return filtered;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) Package(org.eclipse.ceylon.model.typechecker.model.Package)

Example 24 with Scope

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

the class ClassTransformer method typeParametersOfAllContainers.

private java.util.List<TypeParameter> typeParametersOfAllContainers(final ClassOrInterface model, boolean includeModelTypeParameters) {
    java.util.List<java.util.List<TypeParameter>> r = new ArrayList<java.util.List<TypeParameter>>(1);
    Scope s = model.getContainer();
    while (!(s instanceof Package)) {
        if (s instanceof Generic) {
            r.add(0, ((Generic) s).getTypeParameters());
        }
        s = s.getContainer();
    }
    Set<String> names = new HashSet<String>();
    for (TypeParameter tp : model.getTypeParameters()) {
        names.add(tp.getName());
    }
    java.util.List<TypeParameter> result = new ArrayList<TypeParameter>(1);
    for (java.util.List<TypeParameter> tps : r) {
        for (TypeParameter tp : tps) {
            if (names.add(tp.getName())) {
                result.add(tp);
            }
        }
    }
    if (includeModelTypeParameters)
        result.addAll(model.getTypeParameters());
    return result;
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) ArrayList(java.util.ArrayList) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ArrayList(java.util.ArrayList) AnnotationList(org.eclipse.ceylon.compiler.typechecker.tree.Tree.AnnotationList) List(org.eclipse.ceylon.langtools.tools.javac.util.List) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Package(org.eclipse.ceylon.model.typechecker.model.Package) HashSet(java.util.HashSet)

Example 25 with Scope

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

the class ClassTransformer method transformTypeParameters.

<T> void transformTypeParameters(GenericBuilder<T> classBuilder, Declaration model) {
    java.util.List<TypeParameter> typeParameters = Strategy.getEffectiveTypeParameters(model);
    if (typeParameters != null) {
        for (TypeParameter param : typeParameters) {
            Scope cont = param.getContainer();
            if (cont instanceof TypeDeclaration) {
                TypeDeclaration container = (TypeDeclaration) cont;
                classBuilder.typeParameter(param);
                if (classBuilder instanceof ClassDefinitionBuilder) {
                    // Copy to the companion too
                    ClassDefinitionBuilder companionBuilder = ((ClassDefinitionBuilder) classBuilder).getCompanionBuilder(container);
                    if (companionBuilder != null)
                        companionBuilder.typeParameter(param);
                }
            }
        }
    }
}
Also used : TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

Scope (org.eclipse.ceylon.model.typechecker.model.Scope)142 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)71 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)57 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)50 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)44 Type (org.eclipse.ceylon.model.typechecker.model.Type)44 ConditionScope (org.eclipse.ceylon.model.typechecker.model.ConditionScope)35 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)34 Class (org.eclipse.ceylon.model.typechecker.model.Class)33 ModelUtil.getRealScope (org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope)31 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)30 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)26 Value (org.eclipse.ceylon.model.typechecker.model.Value)26 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)25 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)24 Function (org.eclipse.ceylon.model.typechecker.model.Function)23 Package (org.eclipse.ceylon.model.typechecker.model.Package)22 ArrayList (java.util.ArrayList)21 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)20 NativeUtil.declarationScope (org.eclipse.ceylon.compiler.typechecker.util.NativeUtil.declarationScope)15