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

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


        // all bounds are equal
        return true;
    }

    ProducedType nonWideningType(ProducedTypedReference declaration, ProducedTypedReference refinedDeclaration){
        final ProducedReference pr;
        if (declaration.equals(refinedDeclaration)) {
            pr = declaration;
        } else {
            ProducedType refinedType = refinedDeclaration.getType();
            // if the refined type is a method TypeParam, use the original decl that will be more correct,
            // since it may have changed name
            if(refinedType.getDeclaration() instanceof TypeParameter
                    && refinedType.getDeclaration().getContainer() instanceof Method){
                // find its index in the refined declaration
                TypeParameter refinedTypeParameter = (TypeParameter) refinedType.getDeclaration();
                Method refinedMethod = (Method) refinedTypeParameter.getContainer();
                int i=0;
                for(TypeParameter tp : refinedMethod.getTypeParameters()){
                    if(tp.getName().equals(refinedTypeParameter.getName()))
                        break;
                    i++;
                }
                if(i >= refinedMethod.getTypeParameters().size()){
                    throw new BugException("can't find type parameter "+refinedTypeParameter.getName()+" in its container "+refinedMethod.getName());
                }
                // the refining method type parameter should be at the same index
                if(declaration.getDeclaration() instanceof Method == false)
                    throw new BugException("refining declaration is not a method: "+declaration);
                Method refiningMethod = (Method) declaration.getDeclaration();
                if(i >= refiningMethod.getTypeParameters().size()){
                    throw new BugException("refining method does not have enough type parameters to refine "+refinedMethod.getName());
                }
                pr = refiningMethod.getTypeParameters().get(i).getType();
            } else {
                pr = refinedType;
            }
        }
        if (pr.getDeclaration() instanceof Functional
                && Decl.isMpl((Functional)pr.getDeclaration())) {
            // Methods with MPL have a Callable return type, not the type of
            // the innermost Callable.
            return getReturnTypeOfCallable(pr.getFullType());
        }
        return pr.getType();
    }
View Full Code Here


            return makeTopLevelValueOrFunctionLiteral(expr);
        }else if(expr.getWantsDeclaration()){
            return makeMemberValueOrFunctionDeclarationLiteral(expr, declaration);
        }else{
            // get its produced ref
            ProducedReference producedReference = expr.getTarget();
            // it's a member we get from its container type
            ProducedType containerType = producedReference.getQualifyingType();
            // if we have no container type it means we have an object member
            boolean objectMember = containerType == null;
           
            JCExpression memberCall;

            if(objectMember){
                // We don't care about the type args for the cast, nor for the reified container expr, because
                // we take the real reified container type from the container instance, and that one has the type
                // arguments
                containerType = ((Class)declaration.getContainer()).getType();
            }
            JCExpression typeCall = makeTypeLiteralCall(containerType, false, expr.getTypeModel());
            // make sure we cast it to ClassOrInterface
            TypeDeclaration classOrInterfaceDeclaration = (TypeDeclaration) typeFact().getLanguageModuleModelDeclaration("ClassOrInterface");
            JCExpression classOrInterfaceTypeExpr = makeJavaType(
                    classOrInterfaceDeclaration.getProducedReference(null, Arrays.asList(containerType)).getType());

            typeCall = make().TypeCast(classOrInterfaceTypeExpr, typeCall);
            // we will need a TD for the container
            // Note that we don't use Basic for the container for object members, because that's not how we represent
            // anonymous types.
            JCExpression reifiedContainerExpr = makeReifiedTypeArgument(containerType);
           
            // make a raw call and cast
            if(declaration instanceof Method){
                // we need to get types for each type argument
                JCExpression closedTypesExpr;
                if(expr.getTypeArgumentList() != null)
                    closedTypesExpr = getClosedTypesSequential(expr.getTypeArgumentList().getTypeModels());
                else
                    closedTypesExpr = null;
                // we also need type descriptors for ret and args
                ProducedType callableType = producedReference.getFullType();
                JCExpression reifiedReturnTypeExpr = makeReifiedTypeArgument(typeFact().getCallableReturnType(callableType));
                JCExpression reifiedArgumentsExpr = makeReifiedTypeArgument(typeFact().getCallableTuple(callableType));
                List<JCExpression> arguments;
                if(closedTypesExpr != null)
                    arguments = List.of(reifiedContainerExpr, reifiedReturnTypeExpr, reifiedArgumentsExpr,
                            ceylonLiteral(declaration.getName()), closedTypesExpr);
                else
                    arguments = List.of(reifiedContainerExpr, reifiedReturnTypeExpr, reifiedArgumentsExpr,
                            ceylonLiteral(declaration.getName()));
                memberCall = make().Apply(null, makeSelect(typeCall, "getMethod"), arguments);
            }else if(declaration instanceof Value){
                JCExpression reifiedGetExpr = makeReifiedTypeArgument(producedReference.getType());
                String getterName = "getAttribute";
                ProducedType ptype;
                if(!((Value)declaration).isVariable())
                    ptype = typeFact().getNothingDeclaration().getType();
                else
                    ptype = producedReference.getType();

                JCExpression reifiedSetExpr = makeReifiedTypeArgument(ptype);
                memberCall = make().Apply(null, makeSelect(typeCall, getterName), List.of(reifiedContainerExpr, reifiedGetExpr, reifiedSetExpr,
                        ceylonLiteral(declaration.getName())));
            }else{
View Full Code Here

        if(ret != null)
            return ret;
       
        Tree.Term primary = Decl.unwrapExpressionsUntilTerm(ce.getPrimary());
        Declaration primaryDeclaration = null;
        ProducedReference producedReference = null;
        if (primary instanceof Tree.MemberOrTypeExpression) {
            producedReference = ((Tree.MemberOrTypeExpression)primary).getTarget();
            primaryDeclaration = ((Tree.MemberOrTypeExpression)primary).getDeclaration();
        }
        Invocation invocation;
View Full Code Here

        boolean prevSyntheticClassBody = withinSyntheticClassBody(true);
        try {
            if (member.isStaticallyImportable()) {
                if (member instanceof Method) {
                    Method method = (Method)member;
                    ProducedReference producedReference = method.getProducedReference(qualifyingType, typeArguments.getTypeModels());
                    return CallableBuilder.javaStaticMethodReference(
                            gen(),
                            expr.getTypeModel(),
                            method,
                            producedReference).build();
                } else if (member instanceof FieldValue) {
                    return naming.makeName(
                            (TypedDeclaration)member, Naming.NA_FQ | Naming.NA_WRAPPER_UNQUOTED);
                } else if (member instanceof Value) {
                    CallBuilder callBuilder = CallBuilder.instance(this);
                    JCExpression qualExpr = naming.makeTypeDeclarationExpression(null, (TypeDeclaration)member.getContainer(), DeclNameFlag.QUALIFIED);
                    callBuilder.invoke(naming.makeQualifiedName(qualExpr, (TypedDeclaration)member, Naming.NA_GETTER | Naming.NA_MEMBER));
                    return callBuilder.build();
                } else if (member instanceof Class) {
                    ProducedReference producedReference = expr.getTarget();
                    return CallableBuilder.javaStaticMethodReference(
                            gen(),
                            expr.getTypeModel(),
                            (Class)member,
                            producedReference).build();
                }
            }
            if (member instanceof Method) {
                Method method = (Method)member;
                if (!method.isParameter()) {
                    ProducedReference producedReference = method.getProducedReference(qualifyingType, typeArguments.getTypeModels());
                    return CallableBuilder.unboundFunctionalMemberReference(
                            gen(),
                            expr,
                            expr.getTypeModel(),
                            method,
                            producedReference).build();
                } else {
                    ProducedReference producedReference = method.getProducedReference(qualifyingType, typeArguments.getTypeModels());
                    return CallableBuilder.unboundFunctionalMemberReference(
                            gen(),
                            expr,
                            expr.getTypeModel(),
                            method,
                            producedReference).build();
                }
            } else if (member instanceof Value) {
                return CallableBuilder.unboundValueMemberReference(
                        gen(),
                        expr,
                        expr.getTypeModel(),
                        ((TypedDeclaration)member)).build();
            } else if (member instanceof Class) {
                ProducedReference producedReference = expr.getTarget();
                return CallableBuilder.unboundFunctionalMemberReference(
                        gen(),
                        expr,
                        expr.getTypeModel(),
                        (Class)member,
View Full Code Here

        } else if (decl instanceof Method) {
            Method method = (Method)decl;
            final ParameterList parameterList = method.getParameterLists().get(0);
            ProducedType qualifyingType = qmte.getPrimary().getTypeModel();
            Tree.TypeArguments typeArguments = qmte.getTypeArguments();
            ProducedReference producedReference = method.getProducedReference(qualifyingType, typeArguments.getTypeModels());
            return utilInvocation().checkNull(makeJavaStaticInvocation(gen(),
                    method, producedReference, parameterList));
        } else if (decl instanceof Class) {
            Class class_ = (Class)decl;
            final ParameterList parameterList = class_.getParameterLists().get(0);
            ProducedReference producedReference = qmte.getTarget();
            return utilInvocation().checkNull(makeJavaStaticInvocation(gen(),
                    class_, producedReference, parameterList));
        } else {
            return makeErroneous(qmte, "compiler bug: unsupported static");
        }
View Full Code Here

            Invocation invocation;
            if ((lazy || inlined)
                    && term instanceof Tree.MemberOrTypeExpression
                    && ((Tree.MemberOrTypeExpression)term).getDeclaration() instanceof Functional) {
                Declaration primaryDeclaration = ((Tree.MemberOrTypeExpression)term).getDeclaration();
                ProducedReference producedReference = ((Tree.MemberOrTypeExpression)term).getTarget();
                invocation = new MethodReferenceSpecifierInvocation(
                        this,
                        (Tree.MemberOrTypeExpression)term,
                        primaryDeclaration,
                        producedReference,
View Full Code Here

            @Ignore TypeDescriptor $reifiedSet,
            ArrayList<ceylon.language.meta.model.Attribute<? super Container,? extends Get,? super Set>> members,
            FreeValue decl, ProducedType qualifyingType, ceylon.language.meta.model.Type<Container> qualifyingMetamodel,
            ProducedType reifiedGet, ProducedType reifiedSet){
        // now the types
        ProducedReference producedReference = decl.declaration.getProducedReference(qualifyingType, Collections.<ProducedType>emptyList());
        ProducedType type = producedReference.getType();
        if(!type.isSubtypeOf(reifiedGet))
            return;
        ProducedType setType = decl.getVariable() ? type : decl.declaration.getUnit().getNothingDeclaration().getType();
        if(!reifiedSet.isSubtypeOf(setType))
            return;
View Full Code Here

            ArrayList<ceylon.language.meta.model.Method<? super Container,? extends Type,? super Arguments>> members,
            FreeFunction decl, ProducedType qualifyingType,
            AppliedClassOrInterface<Container> containerMetamodel,
            ProducedType reifiedType, ProducedType reifiedArguments){
        // now the types
        ProducedReference producedReference = decl.declaration.getProducedReference(qualifyingType, Collections.<ProducedType>emptyList());
        ProducedType type = producedReference.getType();
        if(!type.isSubtypeOf(reifiedType))
            return;
        ProducedType argumentsType = Metamodel.getProducedTypeForArguments(decl.declaration.getUnit(), (Functional) decl.declaration, producedReference);
        if(!reifiedArguments.isSubtypeOf(argumentsType))
            return;
View Full Code Here

            ArrayList<ceylon.language.meta.model.MemberClass<? super Container,? extends Type,? super Arguments>> members,
            FreeClass decl, ProducedType qualifyingType,
            AppliedClassOrInterface<Container> containerMetamodel,
            ProducedType reifiedType, ProducedType reifiedArguments){
        // now the types
        ProducedReference producedReference = decl.declaration.getProducedReference(qualifyingType, Collections.<ProducedType>emptyList());
        ProducedType type = producedReference.getType();
        if(!type.isSubtypeOf(reifiedType))
            return;
        ProducedType argumentsType = Metamodel.getProducedTypeForArguments(decl.declaration.getUnit(), (Functional) decl.declaration, producedReference);
        if(!reifiedArguments.isSubtypeOf(argumentsType))
            return;
View Full Code Here

            @Ignore TypeDescriptor $reifiedType,
            ArrayList<ceylon.language.meta.model.MemberInterface<? super Container,? extends Type>> members,
            FreeInterface decl, ProducedType qualifyingType, AppliedClassOrInterface<Container> containerMetamodel,
            ProducedType reifiedType){
        // now the types
        ProducedReference producedReference = decl.declaration.getProducedReference(qualifyingType, Collections.<ProducedType>emptyList());
        ProducedType type = producedReference.getType();
        if(!type.isSubtypeOf(reifiedType))
            return;
        // it's compatible!
        members.add(decl.<Container,Type>memberInterfaceApply($reifiedContainer, $reifiedType, containerMetamodel));
    }
View Full Code Here

TOP

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

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.