Search in sources :

Example 81 with Parameter

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

the class ParameterNameParser method parseNameList.

private ParameterList parseNameList(Type type, Function method) {
    ParameterList pl = new ParameterList();
    List<Parameter> parameters = pl.getParameters();
    // startParameterList();
    lexer.eat(LEFT_PAREN);
    if (!lexer.lookingAt(RIGHT_PAREN)) {
        Iterator<Type> ct = loader.getSimpleCallableArgumentTypes(type).iterator();
        if (!ct.hasNext()) {
            throw new ParameterNameParserException("Too few parameter types");
        }
        parameters.add(parseName(ct.next(), method));
        // addParameter()
        while (lexer.lookingAt(COMMA)) {
            lexer.eat();
            if (!ct.hasNext()) {
                throw new ParameterNameParserException("Too few parameter types");
            }
            parameters.add(parseName(ct.next(), method));
        }
        if (ct.hasNext()) {
            throw new ParameterNameParserException("Too many parameter types");
        }
    }
    lexer.eat(RIGHT_PAREN);
    // endParameterList();
    return pl;
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) ParameterList(org.eclipse.ceylon.model.typechecker.model.ParameterList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter)

Example 82 with Parameter

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

the class Metamodel method getTypeDescriptorForArguments.

public static TypeDescriptor getTypeDescriptorForArguments(org.eclipse.ceylon.model.typechecker.model.Unit unit, org.eclipse.ceylon.model.typechecker.model.Functional decl, Reference producedReference) {
    if (!decl.getParameterLists().isEmpty()) {
        List<Parameter> parameters = decl.getFirstParameterList().getParameters();
        org.eclipse.ceylon.model.typechecker.model.Type tupleType = unit.getParameterTypesAsTupleType(parameters, producedReference);
        return Metamodel.getTypeDescriptorForProducedType(tupleType);
    } else {
        return TypeDescriptor.NothingType;
    }
}
Also used : Type(org.eclipse.ceylon.model.typechecker.model.Type) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel)

Example 83 with Parameter

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

the class Metamodel method getParameterProducedTypes.

public static List<Type> getParameterProducedTypes(List<Parameter> parameters, Reference producedReference) {
    List<Type> parameterProducedTypes = new ArrayList<Type>(parameters.size());
    for (Parameter parameter : parameters) {
        Type ft = producedReference.getTypedParameter(parameter).getFullType();
        parameterProducedTypes.add(ft);
    }
    return parameterProducedTypes;
}
Also used : ReifiedType(org.eclipse.ceylon.compiler.java.runtime.model.ReifiedType) NothingType(org.eclipse.ceylon.model.typechecker.model.NothingType) OpenClassOrInterfaceType(ceylon.language.meta.declaration.OpenClassOrInterfaceType) OpenType(ceylon.language.meta.declaration.OpenType) DeclarationType(org.eclipse.ceylon.model.loader.ModelLoader.DeclarationType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ArrayList(java.util.ArrayList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter)

Example 84 with Parameter

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

the class Metamodel method getJavaConstructors.

/**
 * Return all the Java constructors for the given named Ceylon constructor,
 * including the overloaded ones.
 */
public static List<java.lang.reflect.Constructor<?>> getJavaConstructors(org.eclipse.ceylon.model.typechecker.model.Constructor declaration) {
    Class<?> javaClass = getJavaClass((org.eclipse.ceylon.model.typechecker.model.Class) declaration.getContainer());
    ArrayList<java.lang.reflect.Constructor<?>> result = new ArrayList<java.lang.reflect.Constructor<?>>();
    // find the appropriate ultimate constructor
    java.lang.reflect.Constructor<?> ultimate = getJavaConstructor(declaration);
    result.add(ultimate);
    List<Parameter> parameters = declaration.getFirstParameterList().getParameters();
    Class<?>[] javapl = ultimate.getParameterTypes();
    // according to the parameter list
    for (int ii = parameters.size() - 1, jj = javapl.length; ii >= 0; ii--, jj--) {
        Parameter p = parameters.get(ii);
        if (p.isDefaulted() || (p.isSequenced() && !p.isAtLeastOne())) {
            Class<?>[] sig = Arrays.copyOfRange(javapl, 0, jj - 1);
            try {
                Constructor<?> overloaded = javaClass.getDeclaredConstructor(sig);
                result.add(overloaded);
            } catch (NoSuchMethodException e) {
                throw Metamodel.newModelError("Could not find overloaded constructor with signature " + Arrays.toString(sig), e);
            }
        }
    }
    return result;
}
Also used : Constructor(java.lang.reflect.Constructor) ArrayList(java.util.ArrayList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) Metamodel(org.eclipse.ceylon.compiler.java.runtime.metamodel.Metamodel) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) ReflectionClass(org.eclipse.ceylon.model.loader.impl.reflect.mirror.ReflectionClass) LazyClass(org.eclipse.ceylon.model.loader.model.LazyClass)

Example 85 with Parameter

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

the class ExpressionVisitor method inferParameterTypesFromCallableParameter.

private boolean inferParameterTypesFromCallableParameter(Reference pr, Parameter param, Tree.FunctionArgument anon, boolean error) {
    boolean result = true;
    Declaration declaration = param.getDeclaration();
    Functional fun = (Functional) param.getModel();
    List<ParameterList> fpls = fun.getParameterLists();
    List<Tree.ParameterList> apls = anon.getParameterLists();
    if (!fpls.isEmpty() && !apls.isEmpty()) {
        List<Parameter> fps = fpls.get(0).getParameters();
        List<Tree.Parameter> aps = apls.get(0).getParameters();
        for (int j = 0; j < fps.size() && j < aps.size(); j++) {
            Parameter fp = fps.get(j);
            Tree.Parameter ap = aps.get(j);
            if (isInferrableParameter(ap)) {
                result = result & createInferredParameter(anon, declaration, ap, ap.getParameterModel(), pr.getTypedParameter(fp).getType(), fp.getModel(), error);
            }
        }
    }
    return result;
}
Also used : 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) 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) AnalyzerUtil.checkCasesDisjoint(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.checkCasesDisjoint) ModelUtil.argumentSatisfiesEnumeratedConstraint(org.eclipse.ceylon.model.typechecker.model.ModelUtil.argumentSatisfiesEnumeratedConstraint)

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