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

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


        ListBuffer<JCStatement> statements;
        final Value model = attrArg.getDeclarationModel();
        final String name = model.getName();
        final Naming.SyntheticName alias = gen.naming.alias(name);
        final List<JCTree> attrClass = gen.gen().transformAttribute(model, alias.getName(), alias.getName(), null, attrArg.getBlock(), attrArg.getSpecifierExpression(), null, null);
        ProducedTypedReference typedRef = gen.getTypedReference(model);
        ProducedTypedReference nonWideningTypedRef = gen.nonWideningTypeDecl(typedRef);
        ProducedType nonWideningType = gen.nonWideningType(typedRef, nonWideningTypedRef);
        ProducedType type = parameterType(declaredParam, model.getType(), 0);
        final BoxingStrategy boxType = getNamedParameterBoxingStrategy(declaredParam);
        JCExpression initValue = gen.make().Apply(null,
                gen.makeSelect(alias.makeIdent(), Naming.getGetterName(model)),
                List.<JCExpression>nil());
        initValue = gen.expressionGen().applyErasureAndBoxing(
                initValue,
                nonWideningType,
                !CodegenUtil.isUnBoxed(nonWideningTypedRef.getDeclaration()),
                boxType,
                type);
        JCTree.JCVariableDecl var = gen.make().VarDef(
                gen.make().Modifiers(FINAL, List.<JCAnnotation>nil()),
                argName.asName(),
View Full Code Here


    private JCExpression getterClass;

    private AttributeDefinitionBuilder(AbstractTransformer owner, TypedDeclaration attrType,
            String javaClassName, ClassDefinitionBuilder classBuilder, String attrName, String fieldName, boolean toplevel, boolean indirect) {
        int typeFlags = 0;
        ProducedTypedReference typedRef = owner.getTypedReference(attrType);
        ProducedTypedReference nonWideningTypedRef = owner.nonWideningTypeDecl(typedRef);
        ProducedType nonWideningType = owner.nonWideningType(typedRef, nonWideningTypedRef);
        if(attrType.isActual()
                && CodegenUtil.hasTypeErased(attrType))
            typeFlags |= AbstractTransformer.JT_RAW;
        if (!CodegenUtil.isUnBoxed(nonWideningTypedRef.getDeclaration())) {
            typeFlags |= AbstractTransformer.JT_NO_PRIMITIVES;
        }
        this.isHash = CodegenUtil.isHashAttribute((MethodOrValue) attrType);
        this.attrTypedDecl = attrType;
        this.owner = owner;
        this.javaClassName = javaClassName;
        if (javaClassName != null) {
            this.classBuilder =
                    ClassDefinitionBuilder
                    .klass(owner, javaClassName, null, false);
        } else {
            this.classBuilder = classBuilder;
        }
        this.attrType = nonWideningType;
        this.typeFlags = typeFlags;
        this.attrName = attrName;
        this.fieldName = fieldName;
        this.toplevel = toplevel;
        this.late = attrType.isLate();
        this.variable = attrType.isVariable();
       
        // Make sure we use the declaration for building the getter/setter names, as we might be trying to
        // override a JavaBean property with an "isFoo" getter, or non-Ceylon casing, and we have to respect that.
        getterBuilder = MethodDefinitionBuilder
            .getter(owner, attrType, indirect)
            .block(generateDefaultGetterBlock())
            .isOverride(attrType.isActual())
            .isTransient(Decl.isTransient(attrType))
            .modelAnnotations(attrType.getAnnotations())
            .resultType(attrType(), attrType);
       
        ParameterDefinitionBuilder pdb = ParameterDefinitionBuilder.systemParameter(owner, attrName);
        pdb.modifiers(Flags.FINAL);
       
        pdb.aliasName(attrName);
        pdb.type(MethodDefinitionBuilder.paramType(owner, nonWideningTypedRef.getDeclaration(), nonWideningType, 0, true),
                owner.makeJavaTypeAnnotations(attrType));
       
       
        setterBuilder = MethodDefinitionBuilder
            .setter(owner, attrType)
View Full Code Here

    ProducedTypedReference nonWideningTypeDecl(ProducedTypedReference typedReference) {
        return nonWideningTypeDecl(typedReference, typedReference.getQualifyingType());
    }
   
    ProducedTypedReference nonWideningTypeDecl(ProducedTypedReference typedReference, ProducedType currentType) {
        ProducedTypedReference refinedTypedReference = getRefinedDeclaration(typedReference, currentType);
        if(refinedTypedReference != null){
            /*
             * We are widening if the type:
             * - is not object
             * - is erased to object
             * - refines a declaration that is not erased to object
             */
            ProducedType declType = typedReference.getType();
            ProducedType refinedDeclType = refinedTypedReference.getType();
            if(declType == null || refinedDeclType == null)
                return typedReference;
            boolean isWidening = isWidening(declType, refinedDeclType);
           
            if(!isWidening){
View Full Code Here

        }
        return typedReference;
    }

    public boolean isWideningTypeDecl(TypedDeclaration typedDeclaration) {
        ProducedTypedReference typedReference = getTypedReference(typedDeclaration);
        return isWideningTypeDecl(typedReference, typedReference.getQualifyingType());
    }
View Full Code Here

        ProducedTypedReference typedReference = getTypedReference(typedDeclaration);
        return isWideningTypeDecl(typedReference, typedReference.getQualifyingType());
    }

    public boolean isWideningTypeDecl(ProducedTypedReference typedReference, ProducedType currentType) {
        ProducedTypedReference refinedTypedReference = getRefinedDeclaration(typedReference, currentType);
        if(refinedTypedReference == null)
            return false;
        /*
         * We are widening if the type:
         * - is not object
         * - is erased to object
         * - refines a declaration that is not erased to object
         */
        ProducedType declType = typedReference.getType();
        ProducedType refinedDeclType = refinedTypedReference.getType();
        if(declType == null || refinedDeclType == null)
            return false;
        if(isWidening(declType, refinedDeclType))
            return true;

        // make sure we get the instantiated refined decl
        if(refinedDeclType.getDeclaration() instanceof TypeParameter
                && !(declType.getDeclaration() instanceof TypeParameter))
            refinedDeclType = nonWideningType(typedReference, refinedTypedReference);
        if(isWideningTypeArguments(declType, refinedDeclType, true))
            return true;
       
        if(CodegenUtil.hasTypeErased(refinedTypedReference.getDeclaration())
                && !willEraseToObject(declType))
           return true;

        return false;
    }
View Full Code Here

                // now we must select a different refined declaration if we refine it more than once
                if(refinedMembers.size() > (forMixinMethod ? 0 : 1)){
                    // first case
                    for(TypedDeclaration refinedDecl : refinedMembers){
                        // get the type reference to see if any eventual type param is instantiated in our inheritance of this type/method
                        ProducedTypedReference refinedTypedReference = getRefinedTypedReference(typedReference, refinedDecl);
                        // if it is not instantiated, that's the one we're looking for
                        if(isTypeParameter(refinedTypedReference.getType()))
                            return refinedTypedReference;
                    }
                    // second case
                    for(TypedDeclaration refinedDecl : refinedMembers){
                        // get the type reference to see if any eventual type param is instantiated in our inheritance of this type/method
                        ProducedTypedReference refinedTypedReference = getRefinedTypedReference(typedReference, refinedDecl);
                        // if we're not erasing this one to Object let's select it
                        if(!willEraseToObject(refinedTypedReference.getType()) && !isWideningTypeArguments(refinedDecl.getType(), modelRefinedDecl.getType(), true))
                            return refinedTypedReference;
                    }
                    // third case
                    if(isTypeParameter(modelRefinedDecl.getType())){
                        // it can happen that we have inherited a method twice from a single refined declaration
                        // via different supertype instantiations, without having ever refined them in supertypes
                        // so we try each super type to see if we already have a matching typed reference
                        // first super type
                        ProducedType extendedType = declaringType.getExtendedType();
                        if(extendedType != null){
                            ProducedTypedReference refinedTypedReference = getRefinedTypedReference(extendedType, modelRefinedDecl);
                            ProducedType refinedType = refinedTypedReference.getType();
                            if(!isTypeParameter(refinedType)
                                    && !willEraseToObject(refinedType))
                                return refinedTypedReference;
                        }
                        // then satisfied interfaces
                        for(ProducedType satisfiedType : declaringType.getSatisfiedTypes()){
                            ProducedTypedReference refinedTypedReference = getRefinedTypedReference(satisfiedType, modelRefinedDecl);
                            ProducedType refinedType = refinedTypedReference.getType();
                            if(!isTypeParameter(refinedType)
                                    && !willEraseToObject(refinedType))
                                return refinedTypedReference;
                        }
                    }
                }
            }
            /*
             * Now there's another crazy case:
             *
             * interface Top<out Element> {
             *  Top<Element> ret => nothing;
             * }
             * interface Left satisfies Top<Integer> {}
             * interface Right satisfies Top<String> {}
             * class Bottom() satisfies Left&Right {}
             *
             * Where Bottom.ret does not exist and is typed as returning Integer&String which is Nothing, erased to Object,
             * and we look at what it refines and find only a single definition Top.ret typed as returning Integer&String (Nothing),
             * so we think there's no widening, but Java will only see Top<Integer>.ret from Left, and that's the one we want
             * to use for determining widening.
             * See https://github.com/ceylon/ceylon-compiler/issues/1765
             */
            ProducedType firstInstantiation = isInheritedWithDifferentTypeArguments(modelRefinedDecl.getContainer(), currentType);
            if(firstInstantiation != null){
                ProducedTypedReference firstInstantiationTypedReference = getRefinedTypedReference(firstInstantiation, modelRefinedDecl);
                ProducedType firstInstantiationType = firstInstantiationTypedReference.getType();
                if(isWidening(decl.getType(), firstInstantiationType)
                        || isWideningTypeArguments(decl.getType(), firstInstantiationType, true))
                    return firstInstantiationTypedReference;

            }
View Full Code Here

            return null;
        // only consider first param list
        java.util.List<Parameter> parameters = parameterLists.get(0).getParameters();
        if(parameters == null)
            return null;
        ProducedTypedReference typedMember = currentType.getTypedMember(found, Collections.<ProducedType>emptyList());
        if(typedMember == null)
            return null;
        java.util.List<ProducedType> typedSignature = new ArrayList<ProducedType>(parameters.size());
        for(Parameter p : parameters){
            ProducedType parameterType = typedMember.getTypedParameter(p).getFullType();
            typedSignature.add(parameterType);
        }
        return typedSignature;
    }
View Full Code Here

         */
        boolean functional = parameter.getModel() instanceof Method;
        if (producedReference == null) {
            return parameter.getType();
        }
        final ProducedTypedReference producedTypedReference = producedReference.getTypedParameter(parameter);
        final ProducedType type = functional ? producedTypedReference.getFullType() : producedTypedReference.getType();
        final TypedDeclaration producedParameterDecl = producedTypedReference.getDeclaration();
        final ProducedType declType = producedParameterDecl.getType();
        // be more resilient to upstream errors
        if(declType == null)
            return typeFact.getUnknownType();
        final TypeDeclaration declTypeDecl = declType.getDeclaration();
View Full Code Here

    private Module getJDKBaseModule() {
        return loader.getJDKBaseModule();
    }

    ProducedType getGetterInterfaceType(TypedDeclaration attrTypedDecl) {
        ProducedTypedReference typedRef = getTypedReference(attrTypedDecl);
        ProducedTypedReference nonWideningTypedRef = nonWideningTypeDecl(typedRef);
        ProducedType nonWideningType = nonWideningType(typedRef, nonWideningTypedRef);
       
        ProducedType type;
        boolean unboxed = CodegenUtil.isUnBoxed(attrTypedDecl);
        if (unboxed && isCeylonBoolean(nonWideningType)) {
View Full Code Here

    //
    // Any sort of expression
   
    JCExpression transformExpression(final TypedDeclaration declaration, final Tree.Term expr) {
        // make sure we use the best declaration for boxing and type
        ProducedTypedReference typedRef = getTypedReference(declaration);
        ProducedTypedReference nonWideningTypedRef = nonWideningTypeDecl(typedRef);
        ProducedType nonWideningType = nonWideningType(typedRef, nonWideningTypedRef);
        // If this is a return statement in a MPL method we want to know
        // the non-widening type of the innermost callable
        if (declaration instanceof Functional
                && Decl.isMpl((Functional)declaration)) {
            for (int i = ((Functional)declaration).getParameterLists().size(); i > 1; i--) {
                nonWideningType = getReturnTypeOfCallable(nonWideningType);
            }
        }
        // respect the refining definition of optionality
        nonWideningType = propagateOptionality(declaration.getType(), nonWideningType);
        BoxingStrategy boxing = CodegenUtil.getBoxingStrategy(nonWideningTypedRef.getDeclaration());
        return transformExpression(expr, boxing, nonWideningType);
    }
View Full Code Here

TOP

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

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.