Package com.redhat.ceylon.compiler.typechecker.model

Examples of com.redhat.ceylon.compiler.typechecker.model.TypeParameter


                Tree.Type t = args.get(i);
                if (t instanceof Tree.StaticType) {
                    TypeVariance variance =
                            ((Tree.StaticType) t).getTypeVariance();
                    if (variance!=null) {
                        TypeParameter p = params.get(i);
                        if (p.isInvariant()) {
                            if (variance.getText().equals("out")) {
                                pt.setVariance(p, OUT);
                            }
                            else if (variance.getText().equals("in")) {
                                pt.setVariance(p, IN);
View Full Code Here


        super.visit(that);
    }

    @Override
    public void visit(Tree.TypeParameterDeclaration that) {
        TypeParameter tpd = that.getDeclarationModel();
        tpd.setExtendedType(null);
        tpd.getSatisfiedTypes().clear();
        Class vd = unit.getAnythingDeclaration();
        if (vd!=null) {
            tpd.setExtendedType(vd.getType());
        }
        super.visit(that);
        Tree.TypeSpecifier ts = that.getTypeSpecifier();
        if (ts!=null) {
            Tree.StaticType type = ts.getType();
            if (type!=null) {
                ProducedType dta = type.getTypeModel();
                if (dta!=null && dta.containsDeclaration(tpd.getDeclaration())) {
                    type.addError("default type argument involves parameterized type");
                }
                /*else if (t.containsTypeParameters()) {
                    type.addError("default type argument involves type parameters: " +
                    t.getProducedTypeName());
                }*/
                else {
                    tpd.setDefaultTypeArgument(dta);
                }
            }
        }
    }
View Full Code Here

        List<Tree.TypeParameterDeclaration> tpds = that.getTypeParameterDeclarations();
        List<TypeParameter> params = new ArrayList<TypeParameter>(tpds.size());
        for (int i=tpds.size()-1; i>=0; i--) {
            Tree.TypeParameterDeclaration tpd = tpds.get(i);
            if (tpd!=null) {
                TypeParameter tp = tpd.getDeclarationModel();
                if (tp.getDefaultTypeArgument()!=null) {
                    params.add(tp);
                    if (tp.getDefaultTypeArgument().containsTypeParameters(params)) {
                        tpd.getTypeSpecifier().addError("default type argument involves a type parameter not yet declared");
                    }
                }
            }
        }
View Full Code Here

                        st.addError("directly enumerates itself: '" + td.getName() + "'");
                        continue;
                    }
                    else if (ctd instanceof TypeParameter) {
                        if (!(td instanceof TypeParameter)) {
                            TypeParameter tp = (TypeParameter) ctd;
                            td.setSelfType(type);
                            if (tp.isSelfType()) {
                                st.addError("type parameter may not act as self type for two different types");
                            }
                            else {
                                tp.setSelfTypedDeclaration(td);
                            }
                            if (cts.size()>1) {
                                st.addError("a type may not have more than one self type");
                            }
                        }
View Full Code Here

    }
   
    @Override
    public void visit(Tree.TypeParameterDeclaration that) {
        super.visit(that);
        TypeParameter typeParameter = that.getDeclarationModel();
        if(typeParameter != null){
            visitTypeParameter(typeParameter);
        }
    }
View Full Code Here

            while(scope != null){
                if (Decl.equalScopes(scope,  typeParameterScope))
                    return false;
                scope = scope.getContainer();
            }
            TypeParameter tp = (TypeParameter) declaration;
            Boolean nonErasedBounds = tp.hasNonErasedBounds();
            if(nonErasedBounds == null)
                visitTypeParameter(tp);
            return nonErasedBounds != null ? nonErasedBounds.booleanValue() : false;
        }
       
View Full Code Here

                if(type.getDeclaredClass() != null)
                    typeParameterMirrors = type.getDeclaredClass().getTypeParameters();
                Map<TypeParameter,SiteVariance> siteVarianceMap = null;
                int len = hasTypeArguments ? javacTypeArguments.size() : typeParameters.size();
                for(int i=0 ; i<len ; i++){
                    TypeParameter typeParameter = null;
                    if(i < typeParameters.size())
                        typeParameter = typeParameters.get(i);
                    ProducedType producedTypeArgument = null;
                    // do we have a type argument?
                    TypeMirror typeArgument = null;
View Full Code Here

    @Override
    public Declaration getDeclaration(Module module, String pkgName, String name, Scope scope)  {
        synchronized(getLock()){
            if(scope != null){
                TypeParameter typeParameter = lookupTypeParameter(scope, name);
                if(typeParameter != null)
                    return typeParameter;
            }
            if(!isBootstrap || !name.startsWith(CEYLON_LANGUAGE)) {
                if(scope != null && pkgName != null){
View Full Code Here

    private ProducedType newUnknownType() {
        return new UnknownType(typeFactory).getType();
    }

    protected TypeParameter safeLookupTypeParameter(Scope scope, String name) {
        TypeParameter param = lookupTypeParameter(scope, name);
        if(param == null)
            throw new ModelResolutionException("Type param "+name+" not found in "+scope);
        return param;
    }
View Full Code Here

        // We must first add every type param, before we resolve the bounds, which can
        // refer to type params.
        String selfTypeName = getSelfTypeFromAnnotations(mirror);
        int i=0;
        for(AnnotationMirror typeParamAnnotation : typeParameterAnnotations){
            TypeParameter param = new TypeParameter();
            param.setUnit(((Element)scope).getUnit());
            param.setContainer(scope);
            param.setScope(scope);
            DeclarationVisitor.setVisibleScope(param);
            param.setDeclaration((Declaration) scope);
            // let's not trigger the lazy-loading if we're completing a LazyClass/LazyInterface
            if(scope instanceof LazyContainer)
                ((LazyContainer)scope).addMember(param);
            else // must be a method
                scope.getMembers().add(param);
            param.setName((String)typeParamAnnotation.getValue("value"));
            param.setExtendedType(typeFactory.getAnythingDeclaration().getType());
            if(i < typeParameterMirrors.size()){
                TypeParameterMirror typeParameterMirror = typeParameterMirrors.get(i);
                param.setNonErasedBounds(hasNonErasedBounds(typeParameterMirror));
            }
           
            String varianceName = (String) typeParamAnnotation.getValue("variance");
            if(varianceName != null){
                if(varianceName.equals("IN")){
                    param.setContravariant(true);
                }else if(varianceName.equals("OUT"))
                    param.setCovariant(true);
            }
           
            // If this is a self type param then link it to its type's declaration
            if (param.getName().equals(selfTypeName)) {
                param.setSelfTypedDeclaration((TypeDeclaration)scope);
            }
           
            params.add(param);
            i++;
        }

        Module moduleScope = Decl.getModuleContainer(scope);
        // Now all type params have been set, we can resolve the references parts
        Iterator<TypeParameter> paramsIterator = params.iterator();
        for(AnnotationMirror typeParamAnnotation : typeParameterAnnotations){
            TypeParameter param = paramsIterator.next();
           
            @SuppressWarnings("unchecked")
            List<String> satisfiesAttribute = (List<String>)typeParamAnnotation.getValue("satisfies");
            setListOfTypes(param.getSatisfiedTypes(), satisfiesAttribute, scope, moduleScope,
                    "type parameter '"+param.getName()+"' satisfied types");

            @SuppressWarnings("unchecked")
            List<String> caseTypesAttribute = (List<String>)typeParamAnnotation.getValue("caseTypes");
            if(caseTypesAttribute != null && !caseTypesAttribute.isEmpty())
                param.setCaseTypes(new LinkedList<ProducedType>());
            setListOfTypes(param.getCaseTypes(), caseTypesAttribute, scope, moduleScope,
                    "type parameter '"+param.getName()+"' case types");

            String defaultValueAttribute = (String)typeParamAnnotation.getValue("defaultValue");
            if(defaultValueAttribute != null && !defaultValueAttribute.isEmpty()){
                ProducedType decodedType = decodeType(defaultValueAttribute, scope, moduleScope,
                        "type parameter '"+param.getName()+"' defaultValue");
                param.setDefaultTypeArgument(decodedType);
                param.setDefaulted(true);
            }
        }
    }
View Full Code Here

TOP

Related Classes of com.redhat.ceylon.compiler.typechecker.model.TypeParameter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.