Search in sources :

Example 46 with ParameterList

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.ParameterList that) {
    ParameterList pl = parameterList;
    parameterList = new ParameterList();
    that.setModel(parameterList);
    super.visit(that);
    parameterList = pl;
}
Also used : ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList)

Example 47 with ParameterList

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

the class DeclarationVisitor method visit.

@Override
public void visit(Tree.Constructor that) {
    Constructor c = new Constructor();
    that.setConstructor(c);
    if (scope instanceof Class) {
        Class clazz = (Class) scope;
        if (that.getIdentifier() == null && clazz.getDefaultConstructor() != null) {
            // found an overloaded default constructor
            // we'll set up the class overloads later
            // when exiting visit(Tree.ClassDefinition)
            clazz.setOverloaded(true);
            clazz.setAbstraction(true);
        }
    }
    visitDeclaration(that, c, false);
    Type at;
    Scope realScope = getRealScope(scope);
    if (realScope instanceof Class) {
        Class clazz = (Class) realScope;
        Type ot = clazz.getType();
        c.setExtendedType(ot);
        at = c.appliedType(ot, NO_TYPE_ARGS);
        clazz.setConstructors(true);
        if (clazz.isAnonymous()) {
            that.addError("anonymous class may not have constructor: '" + clazz.getName() + "' is an anonymous class");
        }
    } else {
        at = null;
        that.addError("constructor declaration must occur directly in the body of a class");
    }
    Function f = new Function();
    f.setType(at);
    that.setDeclarationModel(f);
    visitDeclaration(that, f);
    Scope o = enterScope(c);
    super.visit(that);
    exitScope(o);
    f.setImplemented(that.getBlock() != null);
    if (that.getParameterList() == null) {
        that.addError("missing parameter list in constructor declaration: '" + name(that.getIdentifier()) + "' must have a parameter list", 1000);
    } else {
        ParameterList model = that.getParameterList().getModel();
        model.setFirst(true);
        if (model != null) {
            c.addParameterList(model);
            // TODO: fix this
            f.addParameterList(model);
        }
    }
    if (c.isAbstract()) {
        if (that.getIdentifier() == null) {
            that.addError("default constructor may not be annotated 'abstract'", 1601);
        } else if (c.isShared()) {
            that.addError("abstract constructor may not be annotated 'shared'", 1610);
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) LazyType(org.eclipse.ceylon.model.typechecker.model.LazyType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) TypeVisitor.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.TypeVisitor.getTupleType) Scope(org.eclipse.ceylon.model.typechecker.model.Scope) ConditionScope(org.eclipse.ceylon.model.typechecker.model.ConditionScope) ModelUtil.getRealScope(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getRealScope) ModelUtil.isDefaultConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isDefaultConstructor) ModelUtil.isConstructor(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isConstructor) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Class(org.eclipse.ceylon.model.typechecker.model.Class) AnalyzerUtil.isVeryAbstractClass(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.isVeryAbstractClass) ModelUtil.isAnonymousClass(org.eclipse.ceylon.model.typechecker.model.ModelUtil.isAnonymousClass)

Example 48 with ParameterList

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

the class TypeHierarchyVisitor method checkForFormalsNotImplemented.

private void checkForFormalsNotImplemented(Node that, List<Type> orderedTypes, Class clazz) {
    Type aggregation = buildAggregatedType(orderedTypes);
    for (Type.Members members : aggregation.membersByName.values()) {
        if (!members.formals.isEmpty()) {
            if (members.actualsNonFormals.isEmpty()) {
                Declaration example = members.formals.iterator().next();
                Declaration declaringType = (Declaration) example.getContainer();
                if (!clazz.equals(declaringType)) {
                    String name = example.getName();
                    if (isJavaSetter(example) && aggregation.membersByName.containsKey(setterToProperty(name))) {
                        // (i.e. a setter with no getter)
                        continue;
                    }
                    addUnimplementedFormal(clazz, example);
                    that.addError("formal member '" + name + "' of '" + declaringType.getName() + "' not implemented for concrete class '" + clazz.getName() + "': '" + clazz.getName() + "' neither directly implements nor inherits a concrete implementation of '" + name + "'", 300);
                    continue;
                }
            }
            for (Declaration f : members.formals) {
                if (isOverloadedVersion(f) && !f.isCoercionPoint()) {
                    boolean found = false;
                    // boolean variadic = f.isVariadic();
                    for (Declaration a : members.actualsNonFormals) {
                        if (f.getRefinedDeclaration().equals(a.getRefinedDeclaration())) {
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        StringBuilder paramTypes = new StringBuilder();
                        List<ParameterList> parameterLists = ((Functional) f).getParameterLists();
                        if (!parameterLists.isEmpty()) {
                            for (Parameter p : parameterLists.get(0).getParameters()) {
                                if (paramTypes.length() > 0) {
                                    paramTypes.append(", ");
                                }
                                if (!isTypeUnknown(p.getType())) {
                                    paramTypes.append(p.getType().asString());
                                }
                            }
                        }
                        Declaration declaringType = (Declaration) f.getContainer();
                        addUnimplementedFormal(clazz, f);
                        that.addError("overloaded formal member '" + f.getName() + "(" + paramTypes + ")' of '" + declaringType.getName() + "' not implemented in class hierarchy");
                    }
                }
            }
        }
    /*if (!members.concretesOnInterfaces.isEmpty() && members.actualsNonFormals.isEmpty()) {
                Declaration declaringType = (Declaration) members.concretesOnInterfaces.iterator().next().getContainer();
                that.addWarning("interface member " + members.name + 
                        " of " + declaringType.getName() +
                        " not implemented in class hierarchy (concrete interface members not yet supported)");
            }*/
    }
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) IntersectionType(org.eclipse.ceylon.model.typechecker.model.IntersectionType) UnionType(org.eclipse.ceylon.model.typechecker.model.UnionType) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) ModelUtil.getNativeDeclaration(org.eclipse.ceylon.model.typechecker.model.ModelUtil.getNativeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration)

Example 49 with ParameterList

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

the class ExpressionVisitor method checkJavaAnnotationElements.

private void checkJavaAnnotationElements(List<Tree.PositionalArgument> args, List<Parameter> params, Declaration target) {
    if (target instanceof Function && target.isAnnotation()) {
        Function method = (Function) target;
        ParameterList parameterList = method.getFirstParameterList();
        if (!parameterList.isPositionalParametersSupported()) {
            for (int i = 0; i < params.size() && i < args.size(); i++) {
                Parameter parameter = parameterList.getParameters().get(i);
                Tree.PositionalArgument arg = args.get(i);
                boolean isJavaAnnotationValueParameter = "value".equals(parameter.getName());
                if (arg != null && !isJavaAnnotationValueParameter) {
                    arg.addUsageWarning(Warning.javaAnnotationElement, "positional argument to Java annotation element: '" + parameter.getName() + "' (use named arguments)");
                }
            }
        }
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) 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.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint)

Example 50 with ParameterList

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

the class InvocationGenerator method applyNamedArguments.

void applyNamedArguments(Tree.NamedArgumentList argList, Functional func, Map<String, String> argVarNames, boolean superAccess, Map<TypeParameter, Type> targs) {
    final ParameterList plist = func.getFirstParameterList();
    boolean first = true;
    if (superAccess) {
        gen.out(".call(this");
        if (!plist.getParameters().isEmpty()) {
            gen.out(",");
        }
    } else {
        gen.out("(");
    }
    for (Parameter p : plist.getParameters()) {
        if (!first)
            gen.out(",");
        final String vname = argVarNames.get(p.getName());
        if (vname == null) {
            if (p.isDefaulted()) {
                gen.out("undefined");
            } else {
                gen.out(gen.getClAlias(), "empty()");
            }
        } else {
            gen.out(vname);
        }
        first = false;
    }
    if (targs != null && !targs.isEmpty()) {
        if (!first) {
            gen.out(",");
        }
        TypeUtils.printTypeArguments(argList, targs, gen, false, null);
    }
    gen.out(")");
}
Also used : ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Aggregations

ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)69 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)47 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)44 Type (org.eclipse.ceylon.model.typechecker.model.Type)25 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)24 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)24 Functional (org.eclipse.ceylon.model.typechecker.model.Functional)23 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)22 Function (org.eclipse.ceylon.model.typechecker.model.Function)21 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)20 Value (org.eclipse.ceylon.model.typechecker.model.Value)20 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)19 ArrayList (java.util.ArrayList)16 AnalyzerUtil.getMatchingParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getMatchingParameter)12 AnalyzerUtil.getUnspecifiedParameter (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getUnspecifiedParameter)12 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)12 FieldValue (org.eclipse.ceylon.model.loader.model.FieldValue)12 Class (org.eclipse.ceylon.model.typechecker.model.Class)11 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)10 HashMap (java.util.HashMap)9