Search in sources :

Example 11 with Function

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

the class BoxingVisitor method visit.

@Override
public void visit(QualifiedMemberExpression that) {
    super.visit(that);
    // handle errors gracefully
    if (that.getDeclaration() == null)
        return;
    if (that.getMemberOperator() instanceof Tree.SafeMemberOp) {
        TypedDeclaration decl = (TypedDeclaration) that.getDeclaration();
        if (CodegenUtil.isRaw(decl))
            CodegenUtil.markRaw(that);
        if (CodegenUtil.hasTypeErased(decl))
            CodegenUtil.markTypeErased(that);
        if (CodegenUtil.hasUntrustedType(decl) || hasTypeParameterWithConstraintsOutsideScope(decl.getType(), that.getScope()))
            CodegenUtil.markUntrustedType(that);
    // we must be boxed, since safe member op "?." returns an optional type
    // return;
    } else if (that.getMemberOperator() instanceof Tree.MemberOp && Decl.isValueTypeDecl(that.getPrimary()) && CodegenUtil.isUnBoxed(that.getPrimary())) {
        // it's unboxed if it's an unboxable type or it's declared void
        if (Decl.isValueTypeDecl((TypedDeclaration) that.getDeclaration()) || (that.getDeclaration() instanceof Function && ((Function) that.getDeclaration()).isDeclaredVoid()))
            CodegenUtil.markUnBoxed(that);
        if (CodegenUtil.isRaw((TypedDeclaration) that.getDeclaration()))
            CodegenUtil.markRaw(that);
        if (CodegenUtil.hasTypeErased((TypedDeclaration) that.getDeclaration()))
            CodegenUtil.markTypeErased(that);
    } else {
        propagateFromDeclaration(that, (TypedDeclaration) that.getDeclaration());
    }
    // be (ex: <String>), and in that case we will generate a proper Sequential<String> which is not raw at all
    if (that.getMemberOperator() instanceof Tree.SpreadOp) {
        // find the return element type
        Type elementType = that.getTarget().getType();
        CodegenUtil.markTypeErased(that, hasErasure(elementType));
    }
    if (ExpressionTransformer.isSuperOrSuperOf(that.getPrimary())) {
        // if the target is an interface whose type arguments have been turned to raw, make this expression
        // as erased
        Reference target = that.getTarget();
        if (target != null && target.getQualifyingType() != null && target.getQualifyingType().getDeclaration() instanceof Interface) {
            if (isRaw(target.getQualifyingType())) {
                CodegenUtil.markTypeErased(that);
            } else // See note in ClassTransformer.makeDelegateToCompanion for a similar test
            {
                TypeDeclaration declaration = target.getQualifyingType().getDeclaration();
                if (needsRawCastForMixinSuperCall(declaration, target.getType()))
                    CodegenUtil.markTypeErased(that);
            }
        }
    }
    Type primaryType;
    if (that.getPrimary() instanceof Tree.Package || that.getTarget() == null) {
        primaryType = that.getPrimary().getTypeModel();
    } else {
        primaryType = that.getTarget().getQualifyingType();
    }
    if (primaryType != null && (isRaw(primaryType) || willEraseToSequence(primaryType)) && that.getTarget() != null && that.getTarget().getDeclaration() instanceof TypedDeclaration && CodegenUtil.containsTypeParameter(((TypedDeclaration) that.getTarget().getDeclaration()).getType())) {
        CodegenUtil.markTypeErased(that);
    }
    if (isRaw(primaryType) && that.getTypeModel().getDeclaration().isParameterized()) {
        CodegenUtil.markRaw(that);
    }
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Function(org.eclipse.ceylon.model.typechecker.model.Function) Type(org.eclipse.ceylon.model.typechecker.model.Type) Reference(org.eclipse.ceylon.model.typechecker.model.Reference) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Interface(org.eclipse.ceylon.model.typechecker.model.Interface)

Example 12 with Function

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

the class CallableBuilder method getParameterTypesFromParameterModels.

private java.util.List<Type> getParameterTypesFromParameterModels() {
    java.util.List<Type> parameterTypes = new ArrayList<Type>(numParams);
    // get them from our declaration
    for (Parameter p : paramLists.getParameters()) {
        Type pt;
        FunctionOrValue pm = p.getModel();
        if (pm instanceof Function && ((Function) pm).isParameter())
            pt = gen.getTypeForFunctionalParameter((Function) pm);
        else
            pt = p.getType();
        parameterTypes.add(pt);
    }
    return parameterTypes;
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Type(org.eclipse.ceylon.model.typechecker.model.Type) ArrayList(java.util.ArrayList) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) TypeParameter(org.eclipse.ceylon.model.typechecker.model.TypeParameter) JCTypeParameter(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCTypeParameter) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)

Example 13 with Function

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

the class ClassDoc method writeMethods.

private void writeMethods() throws IOException {
    if (methods.isEmpty()) {
        return;
    }
    openTable(null, "Methods", 2, true);
    for (Entry<String, SortedSet<Function>> entry : methods.entrySet()) {
        int index = 1;
        for (Function f : entry.getValue()) {
            String id = null;
            if (index > 1) {
                id = entry.getKey() + "_" + index;
            }
            doc(id, entry.getKey(), f);
            index++;
        }
    }
    closeTable();
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) SortedSet(java.util.SortedSet)

Example 14 with Function

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

the class AnnotationInvocationVisitor method annoClass.

public static Class annoClass(Tree.InvocationExpression invocation) {
    Declaration declaration = ((Tree.BaseMemberOrTypeExpression) invocation.getPrimary()).getDeclaration();
    Set<Declaration> ctors = new HashSet<Declaration>();
    while (declaration instanceof Function) {
        if (!ctors.add(declaration)) {
            throw new BugException(invocation, "recursive annotation constructor");
        }
        declaration = ((AnnotationInvocation) ((Function) declaration).getAnnotationConstructor()).getPrimary();
    }
    if (declaration instanceof Class) {
        return (Class) declaration;
    } else {
        throw new BugException(invocation, "invocation primary has unexpected declaration: " + declaration);
    }
}
Also used : Function(org.eclipse.ceylon.model.typechecker.model.Function) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) HashSet(java.util.HashSet)

Example 15 with Function

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

the class AnnotationInvocationVisitor method transformConstructor.

private static JCAnnotation transformConstructor(ExpressionTransformer exprGen, Tree.InvocationExpression invocation, AnnotationInvocation ai, org.eclipse.ceylon.langtools.tools.javac.util.List<AnnotationFieldName> fieldPath) {
    Map<Parameter, ListBuffer<JCExpression>> args = new LinkedHashMap<Parameter, ListBuffer<JCExpression>>();
    List<Parameter> classParameters = ai.getClassParameters();
    // The class parameter's we've not yet figured out the value for
    ArrayList<Parameter> unbound = new ArrayList<Parameter>(classParameters);
    for (Parameter classParameter : classParameters) {
        for (AnnotationArgument argument : ai.findAnnotationArgumentForClassParameter(invocation, new HashSet<Function>(), classParameter)) {
            JCExpression expr = transformConstructorArgument(exprGen, invocation, classParameter, argument, fieldPath);
            appendArgument(args, classParameter, expr);
            unbound.remove(classParameter);
        }
    }
    outer: for (Parameter classParameter : new ArrayList<>(unbound)) {
        // Defaulted argument
        if (ai.isInstantiation()) {
            if (classParameter.isDefaulted()) {
                // That's OK, we'll pick up the default argument from
                // the Java Annotation type
                unbound.remove(classParameter);
                continue outer;
            }
        } else {
            Function ac2 = (Function) ai.getPrimary();
            AnnotationInvocation i = (AnnotationInvocation) ac2.getAnnotationConstructor();
            for (AnnotationArgument aa : i.getAnnotationArguments()) {
                if (aa.getParameter().equals(classParameter)) {
                    appendArgument(args, classParameter, aa.getTerm().makeAnnotationArgumentValue(exprGen, i, org.eclipse.ceylon.langtools.tools.javac.util.List.<AnnotationFieldName>of(aa)));
                    unbound.remove(classParameter);
                    continue outer;
                }
            }
        }
        if (Strategy.hasEmptyDefaultArgument(classParameter)) {
            appendArgument(args, classParameter, exprGen.make().NewArray(null, null, org.eclipse.ceylon.langtools.tools.javac.util.List.<JCExpression>nil()));
            unbound.remove(classParameter);
            continue outer;
        }
    }
    for (Parameter classParameter : unbound) {
        appendArgument(args, classParameter, exprGen.makeErroneous(invocation, "compiler bug: unbound annotation class parameter " + classParameter.getName()));
    }
    ListBuffer<JCExpression> assignments = new ListBuffer<JCExpression>();
    for (Map.Entry<Parameter, ListBuffer<JCExpression>> entry : args.entrySet()) {
        ListBuffer<JCExpression> exprs = entry.getValue();
        if (exprs.size() == 1) {
            assignments.append(makeArgument(exprGen, invocation, entry.getKey(), exprs.first()));
        } else {
            assignments.append(makeArgument(exprGen, invocation, entry.getKey(), exprGen.make().NewArray(null, null, exprs.toList())));
        }
    }
    JCAnnotation annotation = exprGen.at(invocation).Annotation(ai.makeAnnotationType(exprGen), assignments.toList());
    return annotation;
}
Also used : ListBuffer(org.eclipse.ceylon.langtools.tools.javac.util.ListBuffer) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) Function(org.eclipse.ceylon.model.typechecker.model.Function) JCExpression(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression) Parameter(org.eclipse.ceylon.model.typechecker.model.Parameter) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) JCAnnotation(org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCAnnotation)

Aggregations

Function (org.eclipse.ceylon.model.typechecker.model.Function)167 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)71 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)70 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)69 Type (org.eclipse.ceylon.model.typechecker.model.Type)68 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)62 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)57 Value (org.eclipse.ceylon.model.typechecker.model.Value)50 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)46 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)43 Class (org.eclipse.ceylon.model.typechecker.model.Class)39 ArrayList (java.util.ArrayList)32 ParameterList (org.eclipse.ceylon.model.typechecker.model.ParameterList)29 JCExpression (org.eclipse.ceylon.langtools.tools.javac.tree.JCTree.JCExpression)26 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)23 Scope (org.eclipse.ceylon.model.typechecker.model.Scope)23 TypedReference (org.eclipse.ceylon.model.typechecker.model.TypedReference)23 UnknownType (org.eclipse.ceylon.model.typechecker.model.UnknownType)23 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)22 ModelUtil.appliedType (org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType)21