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

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


    }

    @Override
    public void visit(Tree.AnyMethod that) {
        super.visit(that);
        Method a = that.getDeclarationModel();
        if (a.isAnnotation()) {
            checkAnnotationConstructor(that, a);
        }
       
        TypedDeclaration dm = that.getDeclarationModel();
        Unit unit = that.getUnit();
View Full Code Here


        if (!sm.isFormal() && !sm.isDefault()
                && !sm.isShortcutRefinement()) { //this condition is here to squash a dupe message
            that.addError("inherited method is neither formal nor default so may not be refined: " +
                    message(sm));
        }
        Method m = new Method();
        m.setName(sm.getName());
        List<Tree.ParameterList> tpls;
        Tree.Term me = that.getBaseMemberExpression();
        if (me instanceof Tree.ParameterizedExpression) {
            tpls = ((Tree.ParameterizedExpression) me).getParameterLists();
        }
        else {
            tpls = Collections.emptyList();
        }
        int i=0;
        for (ParameterList pl: sm.getParameterLists()) {
            ParameterList l = new ParameterList();
            Tree.ParameterList tpl = tpls.size()<=i ?
                    null : tpls.get(i++);
            int j=0;
            for (final Parameter p: pl.getParameters()) {
                //TODO: meaningful errors when parameters don't line up
                //      currently this is handled elsewhere, but we can
                //      probably do it better right here
                if (tpl==null || tpl.getParameters().size()<=j) {
                    Parameter vp = new Parameter();
                    Value v = new Value();
                    vp.setModel(v);
                    v.setInitializerParameter(vp);
                    vp.setSequenced(p.isSequenced());
                    vp.setAtLeastOne(p.isAtLeastOne());
                    vp.setDefaulted(p.isDefaulted());
                    vp.setName(p.getName());
                    v.setName(p.getName());
                    vp.setDeclaration(m);
                    v.setContainer(m);
                    v.setScope(m);
                    l.getParameters().add(vp);
                    v.setType(new LazyProducedType(that.getUnit()) {
                        @Override
                        public Map<TypeParameter, ProducedType> initTypeArguments() {
                            return rm.getTypedParameter(p).getFullType()
                                    .getTypeArguments();
                        }
                        @Override
                        public TypeDeclaration initDeclaration() {
                            return rm.getTypedParameter(p).getFullType()
                                    .getDeclaration();
                        }
                    });
                }
                else {
                    Tree.Parameter tp = tpl.getParameters().get(j);
                    Parameter rp = tp.getParameterModel();
                    rp.setDefaulted(p.isDefaulted());
                    rp.setDeclaration(m);
                    l.getParameters().add(rp);
                }
                j++;
            }
            m.getParameterLists().add(l);
        }
        if (!sm.getTypeParameters().isEmpty()) {
            bme.addError("method has type parameters: "
                    message(sm));
        }
        m.setShared(true);
        m.setActual(true);
        m.getAnnotations().add(new Annotation("shared"));
        m.getAnnotations().add(new Annotation("actual"));
        m.setRefinedDeclaration(sm.getRefinedDeclaration()); //Note: this is not the real root, so we set it again in ExpressionVisitor
        m.setUnit(that.getUnit());
        m.setContainer(c);
        m.setShortcutRefinement(true);
        m.setDeclaredVoid(sm.isDeclaredVoid());
        setVisibleScope(m);
        c.addMember(m);
        that.setRefinement(true);
        that.setDeclaration(m);
        that.setRefined(sm);
        that.getUnit().addDeclaration(m);
        if (that.getScope() instanceof Specification){
            ((Specification) that.getScope()).setDeclaration(m);
        }
        m.setType(new LazyProducedType(that.getUnit()) {
            @Override
            public Map<TypeParameter, ProducedType> initTypeArguments() {
                return rm.getType().getTypeArguments();
            }
            @Override
View Full Code Here

                getRefinedMember(refinedValue, ci);
        value.setType(refinedProducedReference.getType());
    }

    private void refineMethod(Tree.SpecifierStatement that) {
        Method refinedMethod = (Method) that.getRefined();
        Method method = (Method) that.getDeclaration();
        ClassOrInterface ci = (ClassOrInterface) method.getContainer();
        Declaration root = refinedMethod.getRefinedDeclaration();
        method.setRefinedDeclaration(root);
        if (getInterveningRefinements(method.getName(),
                getSignature(method), root,
                ci, (TypeDeclaration) root.getContainer())
                .isEmpty()) {
            that.getBaseMemberExpression()
                .addError("shortcut refinement does not exactly refine any overloaded inherited member");
        }
        else {
            ProducedReference refinedProducedReference =
                    getRefinedMember(refinedMethod, ci);
            method.setType(refinedProducedReference.getType());
            List<Tree.ParameterList> parameterLists;
            Tree.Term me = that.getBaseMemberExpression();
            if (me instanceof Tree.ParameterizedExpression) {
                parameterLists =
                        ((Tree.ParameterizedExpression) me).getParameterLists();
            }
            else {
                parameterLists = emptyList();
            }
            for (int i=0; i<refinedMethod.getParameterLists().size(); i++) {
                ParameterList refinedParameters =
                        refinedMethod.getParameterLists().get(i);
                ParameterList parameters =
                        method.getParameterLists().get(i);
                Tree.ParameterList parameterList =
                        parameterLists.size()<=i ?
                                null : parameterLists.get(i);
                for (int j=0; j<refinedParameters.getParameters().size(); j++) {
                    Parameter refinedParameter =
                            refinedParameters.getParameters().get(j);
                    ProducedType refinedParameterType =
                            refinedProducedReference
                            .getTypedParameter(refinedParameter)
                            .getFullType();
                    if (parameterList==null ||
                            parameterList.getParameters().size()<=j) {
                        Parameter p = parameters.getParameters().get(j);
                        p.getModel().setType(refinedParameterType);
                    }
                    else {
                        Tree.Parameter parameter =
                                parameterList.getParameters().get(j);
                        Parameter p = parameter.getParameterModel();
                        ProducedType parameterType =
                                p.getModel().getTypedReference().getFullType();
                        Node typeNode = parameter;
                        if (parameter instanceof Tree.ParameterDeclaration) {
                            Tree.Type type =
                                    ((Tree.ParameterDeclaration) parameter)
                                    .getTypedDeclaration().getType();
                            if (type!=null) {
                                typeNode = type;
                            }
                        }
                        checkIsExactlyForInterop(that.getUnit(),
                                refinedParameters.isNamedParametersSupported(),
                                parameterType, refinedParameterType, typeNode,
                                "type of parameter '" + p.getName() +
                                "' of '" + method.getName() +
                                "' declared by '" + ci.getName() +
                                "' is different to type of corresponding parameter '" +
                                refinedParameter.getName() + "' of refined method '" +
                                refinedMethod.getName() + "' of '" +
                                ((Declaration) refinedMethod.getContainer()).getName() +
View Full Code Here

                            that.getDeclarationModel().getName() + "' is declared 'void'");
                }
            }
        }
        if (type instanceof Tree.LocalModifier) {
            Method dec = that.getDeclarationModel();
            if (dec.isParameter()) {
                type.addError("parameter may not have inferred type: '" +
                        dec.getName() + "' must declare an explicit type");
            }
            else if (isTypeUnknown(type.getTypeModel())) {
                if (se==null) {
                    type.addError("function must specify an explicit return type or definition", 200);
                }
View Full Code Here

        }
    }

    @Override public void visit(Tree.MethodArgument that) {
        Tree.SpecifierExpression se = that.getSpecifierExpression();
        Method d = that.getDeclarationModel();
        Tree.Type type = that.getType();
        if (se==null) {
            Tree.Type rt = beginReturnScope(type);          
            Declaration od = beginReturnDeclaration(d);
            super.visit(that);
            endReturnDeclaration(od);
            endReturnScope(rt, d);
        }
        else {
            super.visit(that);
            Tree.Expression e = se.getExpression();
            if (e!=null) {
                ProducedType returnType = e.getTypeModel();
                inferFunctionType(that, returnType);
                if (type!=null &&
                        !(type instanceof Tree.DynamicModifier)) {
                    checkFunctionType(returnType, type, se);
                }
                if (d.isDeclaredVoid() && !isSatementExpression(e)) {
                    se.addError("functional argument is declared void so specified expression must be a statement: '" +
                            d.getName() + "' is declared 'void'");
                }
            }
        }
        if (type instanceof Tree.LocalModifier) {
            if (isTypeUnknown(type.getTypeModel())) {
View Full Code Here

                        model.setUnit(unit);
                        model.setType(type);
                        model.setName(parameter.getName());
                        parameter.setModel(model);
                        model.setInitializerParameter(parameter);
                        Method fun = anon.getDeclarationModel();
                        model.setContainer(fun);
                        fun.addMember(model);
                    }
                }
            }
        }
    }
View Full Code Here

                        model.setUnit(unit);
                        model.setType(t);
                        model.setName(parameter.getName());
                        parameter.setModel(model);
                        model.setInitializerParameter(parameter);
                        Method fun = anon.getDeclarationModel();
                        model.setContainer(fun);
                        fun.addMember(model);
                    }
                }
            }
        }
    }
View Full Code Here

        }
        else {
            outerType = null;
        }
        if (result instanceof Method) {
            Method method = (Method) result;
            if (method.isAbstraction()) {
                that.addError("method is overloaded");
            }
            else {
                Tree.TypeArgumentList tal = that.getTypeArgumentList();
                if (explicitTypeArguments(method, tal)) {
                    List<ProducedType> ta = getTypeArguments(tal,
                        getTypeParameters(method), outerType);
                    if (tal != null) {
                        tal.setTypeModels(ta);
                    }
                    if (acceptsTypeArguments(outerType, method, ta, tal, that, false)) {
                        ProducedTypedReference pr = outerType==null ?
                                method.getProducedTypedReference(null, ta) :
                                    outerType.getTypedMember(method, ta);
                                that.setTarget(pr);
                                that.setTypeModel(unit.getFunctionMetatype(pr));
                    }
                }
                else {
                    that.addError("missing type arguments to: '" + method.getName(unit) + "'");
                }
            }
        }
        else if (result instanceof Value) {
            Value value = (Value) result;
View Full Code Here

    }

    @Override
    public void visit(Tree.FunctionArgument that) {
        super.visit(that);
        Method m = that.getDeclarationModel();
        checkVisibility(that, m);
        checkParameterVisibility(m, that.getParameterLists());
    }
View Full Code Here

   
    @Override
    public void visit(Tree.MethodDeclaration that) {
        super.visit(that);
        Tree.SpecifierExpression sie = that.getSpecifierExpression();
        Method dec = that.getDeclarationModel();
        if (dec!=null && dec.isParameter() &&
                dec.getInitializerParameter().isHidden()) {
            if (sie!=null) {
                sie.addError("function is an initializer parameter and may not have an initial value: '" +
                        dec.getName() + "'");
            }
        }
    }
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.