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

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


        value.setType(type);
        return value;
    }

    private Method parseMethod(ProducedType type, boolean declaredVoid) {
        Method method = new Method();
        method.setDeclaredVoid(declaredVoid);
        method.setType(loader.getSimpleCallableReturnType(type));
        while (lexer.lookingAt(LEFT_PAREN)) {
            method.addParameterList(parseNameList(type, method));
            type = loader.getSimpleCallableReturnType(type);
        }
        return method;
    }
View Full Code Here


        klass.getSatisfiedTypes().add(iface.getType());
        klass.setUnit(iface.getUnit());
        ParameterList classpl = new ParameterList();
        klass.addParameterList(classpl);
       
        Method ctor = new AnnotationProxyMethod();
        ctor.setContainer(this);
        klass.setScope(this);
        ctor.setAnnotation(true);
        ctor.setName(iface.getName().substring(0, 1).toLowerCase() + iface.getName().substring(1));
        ctor.setShared(iface.isShared());
        Annotation annotationAnnotation2 = new Annotation();
        annotationAnnotation2.setName("annotation");
        ctor.getAnnotations().add(annotationAnnotation2);
        ctor.setType(((TypeDeclaration)iface).getType());
        ctor.setUnit(iface.getUnit());
       
        ParameterList ctorpl = new ParameterList();
        ctor.addParameterList(ctorpl);
       
        AnnotationInvocation ai = new AnnotationInvocation();
        ai.setConstructorDeclaration(ctor);
        ai.setPrimary(klass);
        ai.setInterop(true);
        ctor.setAnnotationConstructor(ai);
        List<AnnotationArgument> annotationArgs = new ArrayList<AnnotationArgument>();
        for (Declaration member : iface.getMembers()) {
            boolean isValue = member.getName().equals("value");
            if (member instanceof JavaMethod) {
                JavaMethod m = (JavaMethod)member;
               
                ParameterAnnotationTerm term = new ParameterAnnotationTerm();
                AnnotationArgument argument = new AnnotationArgument();
                argument.setTerm(term);
                {
                    Parameter klassParam = new Parameter();
                    Value value = new Value();
                    klassParam.setModel(value);
                    value.setInitializerParameter(klassParam);
                    klassParam.setDeclaration(klass);
                    value.setContainer(klass);
                    value.setScope(klass);
                    value.setName(member.getName());
                    klassParam.setName(member.getName());
                    value.setType(annotationParameterType(iface.getUnit(), m));
                    value.setUnboxed(true);
                    value.setUnit(iface.getUnit());
                    if(isValue)
                        classpl.getParameters().add(0, klassParam);
                    else
                        classpl.getParameters().add(klassParam);
                    argument.setParameter(klassParam);
                    klass.addMember(value);
                }
                {
                    Parameter ctorParam = new Parameter();
                    Value value = new Value();
                    ctorParam.setModel(value);
                    value.setInitializerParameter(ctorParam);
                    ctorParam.setDeclaration(ctor);
                    value.setContainer(klass);
                    value.setScope(klass);
                    ctorParam.setDefaulted(m.isDefaultedAnnotation());
                    value.setName(member.getName());
                    ctorParam.setName(member.getName());
                    value.setType(annotationParameterType(iface.getUnit(), m));
                    value.setUnboxed(true);
                    value.setUnit(iface.getUnit());
                    if(isValue)
                        ctorpl.getParameters().add(0, ctorParam);
                    else
                        ctorpl.getParameters().add(ctorParam);
                    term.setSourceParameter(ctorParam);
                    ctor.addMember(value);
                   
                    AnnotationConstructorParameter acp = new AnnotationConstructorParameter();
                    acp.setParameter(ctorParam);
                    if(isValue)
                        ai.getConstructorParameters().add(0, acp);
View Full Code Here

    }
   
    private void addRefinedThrowerMethod(ClassDefinitionBuilder classBuilder,
            String error, ClassOrInterface classModel,
            Method formalMethod) {
        Method refined = refineMethod(classModel,
                classModel.getType().getTypedMember(formalMethod, Collections.<ProducedType>emptyList()),
                classModel, formalMethod, classModel.getUnit());
        // TODO When the method in inherited from an interface and is defaulted
        // we need to generate a DPM as well, otherwise the class is missing
        // the DPM and javac barfs.
View Full Code Here

                if (formalP.getModel() instanceof Value) {
                    Value paramValueModel = refineValue((Value)formalP.getModel(), typedParameter, refined, classModel.getUnit());
                    paramValueModel.setInitializerParameter(refinedP);
                    paramModel = paramValueModel;
                } else {
                    Method paramFunctionModel = refineMethod(refined, typedParameter, classModel, (Method)formalP.getModel(), unit);
                    paramFunctionModel.setInitializerParameter(refinedP);
                    paramModel = paramFunctionModel;
                }
                refinedP.setModel(paramModel);
                refinedPl.getParameters().add(refinedP);
            }
View Full Code Here

            Scope container,
            ProducedTypedReference pr,
            ClassOrInterface classModel,
            Method formalMethod,
            Unit unit) {
        Method refined = new Method();
        refined.setActual(true);
        refined.setShared(formalMethod.isShared());
        refined.setContainer(container);
        refined.setDefault(true);// in case there are subclasses
        refined.setDeferred(false);
        refined.setDeprecated(formalMethod.isDeprecated());
        refined.setName(formalMethod.getName());
        refined.setRefinedDeclaration(formalMethod.getRefinedDeclaration());
        refined.setScope(container);
        refined.setType(pr.getType());
        refined.setUnit(unit);
        refined.setUnboxed(formalMethod.getUnboxed());
        refined.setUntrustedType(formalMethod.getUntrustedType());
        refined.setTypeErased(formalMethod.getTypeErased());
        ArrayList<TypeParameter> refinedTp = new ArrayList<TypeParameter>();;
        for (TypeParameter formalTp : formalMethod.getTypeParameters()) {
            refinedTp.add(formalTp);
        }
        refined.setTypeParameters(refinedTp);
        for (ParameterList formalPl : formalMethod.getParameterLists()) {
            ParameterList refinedPl = new ParameterList();
            for (Parameter formalP : formalPl.getParameters()){
                Parameter refinedP = new Parameter();
                refinedP.setAtLeastOne(formalP.isAtLeastOne());
                refinedP.setDeclaration(refined);
                refinedP.setDefaulted(formalP.isDefaulted());
                refinedP.setDeclaredAnything(formalP.isDeclaredAnything());
                refinedP.setHidden(formalP.isHidden());
                refinedP.setSequenced(formalP.isSequenced());
                refinedP.setName(formalP.getName());
                final ProducedTypedReference typedParameter = pr.getTypedParameter(formalP);
                MethodOrValue paramModel;
                if (formalP.getModel() instanceof Value) {
                    Value paramValueModel = refineValue((Value)formalP.getModel(), typedParameter, refined, classModel.getUnit());
                    paramValueModel.setInitializerParameter(refinedP);
                    paramModel = paramValueModel;
                } else {
                    Method paramFunctionModel = refineMethod(refined, typedParameter, classModel, (Method)formalP.getModel(), unit);
                    paramFunctionModel.setInitializerParameter(refinedP);
                    paramModel = paramFunctionModel;
                }
                refinedP.setModel(paramModel);
                refinedPl.getParameters().add(refinedP);
            }
View Full Code Here

        Parameter paramModel = paramTree.getParameterModel();

        if (Strategy.createMethod(paramModel)) {
            Tree.MethodDeclaration methodDecl = (Tree.MethodDeclaration)Decl.getMemberDeclaration(klass, paramTree);
            makeFieldForParameter(classBuilder, paramModel);
            Method method = (Method)paramModel.getModel();

            java.util.List<Parameter> parameters = method.getParameterLists().get(0).getParameters();
            CallBuilder callBuilder = CallBuilder.instance(this).invoke(
                    naming.makeQualIdent(naming.makeName(method, Naming.NA_IDENT),
                            Naming.getCallableMethodName(method)));
            for (Parameter parameter : parameters) {
                JCExpression parameterExpr = naming.makeName(parameter.getModel(), Naming.NA_IDENT);
                parameterExpr = expressionGen().applyErasureAndBoxing(parameterExpr, parameter.getType(),
                        !CodegenUtil.isUnBoxed(parameter.getModel()), BoxingStrategy.BOXED,
                        parameter.getType());
                callBuilder.argument(parameterExpr);
            }
            JCExpression expr = callBuilder.build();
            JCStatement body;
            if (isVoid(methodDecl) && Decl.isUnboxedVoid(method) && !Strategy.useBoxedVoid(method)) {
                body = make().Exec(expr);
            } else {
                expr = expressionGen().applyErasureAndBoxing(expr, paramModel.getType(), true, CodegenUtil.getBoxingStrategy(method), paramModel.getType());
                body = make().Return(expr);
            }
            classBuilder.methods(transformMethod(method, null, methodDecl.getParameterLists(),
                    methodDecl.getAnnotationList(),
                    true, method.isActual(), true,
                    List.of(body), daoThis, false));
        }
    }
View Full Code Here

                // non-shared interface methods don't need implementing
                // (they're just private methods on the $impl)
                continue;
            }
            if (member instanceof Method) {
                Method method = (Method)member;
                final ProducedTypedReference typedMember = satisfiedType.getTypedMember(method, Collections.<ProducedType>emptyList());
                Declaration sub = (Declaration)model.getMember(method.getName(), null, false);
                if (sub instanceof Method) {
                    Method subMethod = (Method)sub;
                    if (subMethod.getParameterLists().isEmpty()) {
                        continue;
                    }
                    java.util.List<java.util.List<ProducedType>> producedTypeParameterBounds = producedTypeParameterBounds(
                            typedMember, subMethod);
                    final ProducedTypedReference refinedTypedMember = model.getType().getTypedMember(subMethod, Collections.<ProducedType>emptyList());
                    final java.util.List<TypeParameter> typeParameters = subMethod.getTypeParameters();
                    final java.util.List<Parameter> parameters = subMethod.getParameterLists().get(0).getParameters();
                    boolean hasOverloads = false;
                    if (!satisfiedInterfaces.contains((Interface)method.getContainer())) {

                        for (Parameter param : parameters) {
                            if (Strategy.hasDefaultParameterValueMethod(param)
                                    && CodegenUtil.getTopmostRefinedDeclaration(param.getModel()).getContainer().equals(member)) {
                                final ProducedTypedReference typedParameter = refinedTypedMember.getTypedParameter(param);
                                // If that method has a defaulted parameter,
                                // we need to generate a default value method
                                // which also delegates to the $impl
                                final MethodDefinitionBuilder defaultValueDelegate = makeDelegateToCompanion(iface,
                                        typedParameter,
                                        model.getType(),
                                        PUBLIC | FINAL,
                                        typeParameters, producedTypeParameterBounds,
                                        typedParameter.getType(),
                                        Naming.getDefaultedParamMethodName(method, param),
                                        parameters.subList(0, parameters.indexOf(param)),
                                        param.getModel().getTypeErased(),
                                        null);
                                classBuilder.method(defaultValueDelegate);
                            }

                            if (Strategy.hasDefaultParameterOverload(param)) {
                                if ((method.isDefault() || method.isShared() && !method.isFormal())
                                        && Decl.equal(method, subMethod)) {
                                    MethodDefinitionBuilder overloadBuilder = MethodDefinitionBuilder.method(this, subMethod);
                                    MethodDefinitionBuilder overload = new DefaultedArgumentMethodTyped(daoThis, typedMember)
                                        .makeOverload(
                                            overloadBuilder,
                                            subMethod.getParameterLists().get(0),
                                            param,
                                            typeParameters);
                                    classBuilder.method(overload);
                                }

                                hasOverloads = true;
                            }
                        }
                    }
                    // if it has the *most refined* default concrete member,
                    // then generate a method on the class
                    // delegating to the $impl instance
                    if (needsCompanionDelegate(model, member)) {

                        final MethodDefinitionBuilder concreteMemberDelegate = makeDelegateToCompanion(iface,
                                typedMember,
                                model.getType(),
                                PUBLIC | (method.isDefault() ? 0 : FINAL),
                                typeParameters,
                                producedTypeParameterBounds,
                                typedMember.getType(),
                                naming.selector(method),
                                method.getParameterLists().get(0).getParameters(),
                                ((Method) member).getTypeErased(),
                                null);
                        classBuilder.method(concreteMemberDelegate);
                    }

                    if (hasOverloads
                            && (method.isDefault() || method.isShared() && !method.isFormal())
                            && Decl.equal(method, subMethod)) {
                        final MethodDefinitionBuilder canonicalMethod = makeDelegateToCompanion(iface,
                                typedMember,
                                model.getType(),
                                PRIVATE,
                                subMethod.getTypeParameters(),
                                producedTypeParameterBounds,
                                typedMember.getType(),
                                Naming.selector(method, Naming.NA_CANONICAL_METHOD),
                                method.getParameterLists().get(0).getParameters(),
                                ((Method) member).getTypeErased(),
View Full Code Here

                // Generate the attribute
                transform(attrDecl, classBuilder);
            } else if (decl instanceof Method) {
                // Now build a "fake" declaration for the method
                Tree.MethodDeclaration methDecl = new Tree.MethodDeclaration(null);
                Method m = (Method)decl;
                methDecl.setDeclarationModel(m);
                methDecl.setIdentifier(expr.getIdentifier());
                methDecl.setScope(op.getScope());
                methDecl.setAnnotationList(makeShortcutRefinementAnnotationTrees());
               
                Tree.SpecifierExpression specifierExpression = op.getSpecifierExpression();
                methDecl.setSpecifierExpression(specifierExpression);
               
                if(specifierExpression instanceof Tree.LazySpecifierExpression == false){
                    Tree.Expression expression = specifierExpression.getExpression();
                    Tree.Term expressionTerm = Decl.unwrapExpressionsUntilTerm(expression);
                    // we can optimise lambdas and static method calls
                    if(!CodegenUtil.canOptimiseMethodSpecifier(expressionTerm, m)){
                        // we need a field to save the callable value
                        String name = naming.getMethodSpecifierAttributeName(m);
                        JCExpression specifierType = makeJavaType(expression.getTypeModel());
                        JCExpression specifier = expressionGen().transformExpression(expression);
                        classBuilder.field(PRIVATE | FINAL, name, specifierType, specifier, false);
                    }
                }

                // copy from formal declaration
                for (ParameterList pl : m.getParameterLists()) {
                    Tree.ParameterList tpl = new Tree.ParameterList(null);
                    tpl.setModel(pl);
                    for (Parameter p : pl.getParameters()) {
                        Tree.Parameter tp = null;
                        if (p.getModel() instanceof Value) {
View Full Code Here

        AttributeDefinitionBuilder setter = AttributeDefinitionBuilder.setter(this, attrName, decl.getDeclarationModel());
        return makeGetterOrSetter(decl, forCompanion, lazy, setter, false);
    }

    public List<JCTree> transformWrappedMethod(Tree.AnyMethod def, TransformationPlan plan) {
        final Method model = def.getDeclarationModel();
        if (model.isParameter()) {
            return List.nil();
        }
        naming.clearSubstitutions(model);
        // Generate a wrapper class for the method
        String name = def.getIdentifier().getText();
        ClassDefinitionBuilder builder = ClassDefinitionBuilder.methodWrapper(this, name, Decl.isShared(def));
       
        if (Decl.isAnnotationConstructor(def)) {
            AnnotationInvocation ai = ((AnnotationInvocation)def.getDeclarationModel().getAnnotationConstructor());
            if (ai != null) {
                builder.annotations(List.of(makeAtAnnotationInstantiation(ai)));
                builder.annotations(makeExprAnnotations(def, ai));
            }
        }
       
        builder.methods(classGen().transform(def, plan, builder));
       
        // Toplevel method
        if (Strategy.generateMain(def)) {
            // Add a main() method
            builder.method(makeMainForFunction(model));
        }
       
        if(Decl.isLocal(model) || Decl.isToplevel(model)){
            builder.annotations(makeAtLocalDeclarations(def));
        }
        if(Decl.isLocal(model)){
            builder.annotations(makeAtLocalDeclaration(model.getQualifier(), false));
        }
       
        List<JCTree> result = builder.build();
       
        if (Decl.isLocal(def)) {
View Full Code Here

        return transform(def, classBuilder, body);
    }

    List<MethodDefinitionBuilder> transform(Tree.AnyMethod def,
            ClassDefinitionBuilder classBuilder, List<JCStatement> body) {
        final Method model = def.getDeclarationModel();
       
        List<MethodDefinitionBuilder> result = List.<MethodDefinitionBuilder>nil();
        if (!Decl.withinInterface(model)) {
            // Transform to the class
            boolean refinedResultType = !model.getType().isExactly(
                    ((TypedDeclaration)model.getRefinedDeclaration()).getType());
            result = transformMethod(def,
                    true,
                    true,
                    true,
                    transformMplBodyUnlessSpecifier(def, model, body),
                    refinedResultType
                    && !Decl.withinInterface(model.getRefinedDeclaration())? daoSuper : daoThis,
                    !Strategy.defaultParameterMethodOnSelf(model));
        } else {// Is within interface
            // Transform the definition to the companion class, how depends
            // on what kind of method it is
            List<MethodDefinitionBuilder> companionDefs;
            if (def instanceof Tree.MethodDeclaration) {
                final SpecifierExpression specifier = ((Tree.MethodDeclaration) def).getSpecifierExpression();
                if (specifier == null) {
                    // formal or abstract
                    // (still need overloads and DPMs on the companion)
                    companionDefs = transformMethod(def, 
                            false,
                            true,
                            true,
                            null,
                            daoCompanion,
                            false);  
                } else {
                    companionDefs = transformMethod(def,
                            true,
                            false,
                            !model.isShared(),
                            transformMplBodyUnlessSpecifier(def, model, body),
                            daoCompanion,
                            false);
                }
            } else if (def instanceof Tree.MethodDefinition) {
                companionDefs = transformMethod(def, 
                        true,
                        false,
                        !model.isShared(),
                        transformMplBodyUnlessSpecifier(def, model, body),
                        daoCompanion,
                        false);
            } else {
                throw BugException.unhandledNodeCase(def);
            }
            if(!companionDefs.isEmpty())
                classBuilder.getCompanionBuilder((TypeDeclaration)model.getContainer())
                    .methods(companionDefs);
           
            // Transform the declaration to the target interface
            // but only if it's shared
            if (Decl.isShared(model)) {
View Full Code Here

TOP

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

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.