Search in sources :

Example 16 with Parameter

use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.

the class AnalyzerUtil method getUnspecifiedParameter.

static Parameter getUnspecifiedParameter(Reference pr, ParameterList pl, Set<Parameter> foundParameters) {
    for (Parameter p : pl.getParameters()) {
        Type t = pr == null ? p.getType() : pr.getTypedParameter(p).getFullType();
        if (t != null) {
            t = t.resolveAliases();
            Unit unit = p.getDeclaration().getUnit();
            if (!foundParameters.contains(p) && unit.isIterableParameterType(t)) {
                return p;
            }
        }
    }
    return null;
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Unit(org.eclipse.ceylon.model.typechecker.model.Unit)

Example 17 with Parameter

use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.

the class AnnotationVisitor method checkServiceImplementation.

private void checkServiceImplementation(Class clazz, Declaration d, Node that) {
    if (d instanceof ClassOrInterface) {
        ClassOrInterface service = (ClassOrInterface) d;
        ParameterList pl = clazz.getParameterList();
        if (pl == null) {
            that.addError("service class must have a parameter list or default constructor");
        } else {
            List<Parameter> params = pl.getParameters();
            if (!params.isEmpty() && !params.get(0).isDefaulted()) {
                that.addError("service class must be instantiable with an empty argument list");
            }
        }
        if (clazz.inherits(service)) {
            ModelUtil.getModule(clazz).addService(service, clazz);
        } else {
            that.addError("service class does not implement service '" + service + "'");
        }
    } else {
        that.addError("service must be an interface or class");
    }
}
Also used : ClassOrInterface(org.eclipse.ceylon.model.typechecker.model.ClassOrInterface) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter)

Example 18 with Parameter

use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.

the class AnnotationVisitor method checkPositionalArguments.

private void checkPositionalArguments(Functional a, List<Tree.PositionalArgument> pal) {
    for (Tree.PositionalArgument pa : pal) {
        if (pa != null) {
            Parameter p = pa.getParameter();
            if (p != null) {
                if (pa instanceof Tree.ListedArgument) {
                    Tree.ListedArgument la = (Tree.ListedArgument) pa;
                    checkAnnotationArgument(a, la.getExpression());
                } else if (pa instanceof Tree.SpreadArgument) {
                    Tree.SpreadArgument sa = (Tree.SpreadArgument) pa;
                    checkAnnotationArgument(a, sa.getExpression());
                } else {
                    pa.addError("illegal annotation argument");
                }
            }
        }
    }
}
Also used : Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter)

Example 19 with Parameter

use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.

the class ExpressionVisitor method setupTargetParametersDirectly.

/**
 * Sets references from arguments back to parameters
 * in a direct invocation with positional arguments,
 * special casing "coercion points" generated by the
 * model loader.
 */
private void setupTargetParametersDirectly(Tree.PositionalArgumentList pal, Tree.MemberOrTypeExpression mte, Declaration dec, boolean error) {
    // coercion point and use that instead
    if (!error && isOverloadedVersion(dec) && !dec.isCoercionPoint()) {
        Declaration abstraction = dec.getContainer().getDirectMember(dec.getName(), null, false);
        if (abstraction.isAbstraction()) {
            List<Declaration> overloads = abstraction.getOverloads();
            if (overloads.size() == 2) {
                for (Declaration overload : overloads) {
                    if (overload.isCoercionPoint()) {
                        dec = overload;
                        break;
                    }
                }
            }
        }
    }
    List<Tree.PositionalArgument> args = pal.getPositionalArguments();
    int argCount = args.size();
    Functional fun = (Functional) dec;
    List<ParameterList> pls = fun.getParameterLists();
    if (!pls.isEmpty()) {
        List<Parameter> params = pls.get(0).getParameters();
        Reference reference = getInvokedProducedReference(dec, mte);
        int paramsSize = params.size();
        for (int i = 0, j = 0; i < argCount && j < paramsSize; i++) {
            Parameter param = params.get(j);
            Tree.PositionalArgument arg = args.get(i);
            arg.setParameter(param);
            if (arg instanceof Tree.ListedArgument) {
                Tree.ListedArgument la = (Tree.ListedArgument) arg;
                setupTargetParameters(reference, param, la.getExpression());
            }
            if (!param.isSequenced()) {
                j++;
            }
        }
    }
}
Also used : TypedReference(org.eclipse.ceylon.model.typechecker.model.TypedReference) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) AnalyzerUtil.getUnspecifiedParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) AnalyzerUtil.getMatchingParameter(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) PositionalArgument(org.eclipse.ceylon.compiler.typechecker.tree.Tree.PositionalArgument) AnalyzerUtil.getPackageTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypedDeclaration) AnalyzerUtil.getTypedDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypedDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) AnalyzerUtil.getPackageTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) AnalyzerUtil.getTypeDeclaration(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)

Example 20 with Parameter

use of org.eclipse.ceylon.model.typechecker.model.Parameter in project ceylon by eclipse.

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.FunctionalParameterDeclaration that) {
    Parameter p = new Parameter();
    p.setDeclaration(declaration);
    p.setDefaulted(getSpecifier(that) != null);
    Tree.TypedDeclaration td = that.getTypedDeclaration();
    Tree.Type type = td.getType();
    p.setDeclaredAnything(type instanceof Tree.VoidModifier);
    that.setParameterModel(p);
    super.visit(that);
    Function m = (Function) td.getDeclarationModel();
    p.setModel(m);
    p.setName(m.getName());
    m.setInitializerParameter(p);
    parameterList.getParameters().add(p);
    if (type instanceof Tree.SequencedType) {
        type.addError("functional parameter type may not be variadic");
    }
    if (m.isFormal()) {
        that.addError("parameter may not be annotated 'formal'", 1312);
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Aggregations

Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)160 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)123 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)71 Type (org.eclipse.ceylon.model.typechecker.model.Type)71 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)57 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)48 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)45 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)45 Function (org.eclipse.ceylon.model.typechecker.model.Function)43 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)42 Value (org.eclipse.ceylon.model.typechecker.model.Value)42 ArrayList (java.util.ArrayList)38 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)30 AnalyzerUtil.getMatchingParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter)27 AnalyzerUtil.getUnspecifiedParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter)27 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)27 Class (org.eclipse.ceylon.model.typechecker.model.Class)23 JCTree (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree)21 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)19 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)19