Search in sources :

Example 1 with Setter

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

the class BoxingDeclarationVisitor method visit.

@Override
public void visit(AttributeSetterDefinition that) {
    super.visit(that);
    Setter declaration = that.getDeclarationModel();
    // deal with invalid input
    if (declaration == null)
        return;
    // To determine boxing for a setter we use its parameter
    TypedDeclaration paramDeclaration = declaration.getParameter().getModel();
    boxAttribute(paramDeclaration, that);
    // Now copy the settings from the parameter to the setter itself
    declaration.setUnboxed(paramDeclaration.getUnboxed());
    // Then we check if there are any overriding compiler annotations
    boxFromAnnotation(declaration, that);
    // And finally we copy the setting back again to make sure they're really the same
    paramDeclaration.setUnboxed(declaration.getUnboxed());
}
Also used : TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Setter(org.eclipse.ceylon.model.typechecker.model.Setter)

Example 2 with Setter

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

the class ClassOrPackageDoc method doc.

protected final void doc(String id, String name, Declaration d) throws IOException {
    String declarationName = Util.getDeclarationName(d);
    id = (id != null ? id : name);
    boolean alias = Util.nullSafeCompare(name, declarationName) != 0;
    // put the id on the td because IE8 doesn't support id attributes on tr (yeah right)
    open("tr");
    open("td id='" + id + "' nowrap");
    writeIcon(d);
    if (!(d instanceof Constructor)) {
        around("code class='decl-label'", name);
        close("td");
        open("td");
    }
    writeLinkOneSelf(id);
    if (alias) {
        writeTagged(d);
        writeAlias(d);
    } else {
        writeLinkSource(d);
        writeTagged(d);
        if (d instanceof Functional) {
            writeParameterLinksIfRequired((Functional) d);
        }
        open("code class='signature'");
        around("span class='modifiers'", getModifiers(d));
        write(" ");
        if (!ModelUtil.isConstructor(d)) {
            if (!Decl.isDynamic(d)) {
                if (d instanceof Functional && ((Functional) d).isDeclaredVoid()) {
                    around("span class='void'", "void");
                } else if (d instanceof TypedDeclaration) {
                    linkRenderer().to(((TypedDeclaration) d).getType()).useScope(d).write();
                } else {
                    linkRenderer().to(d).useScope(d).write();
                }
            } else {
                around("span class='dynamic'", "dynamic");
            }
        }
        write(" ");
        open("span class='identifier'");
        write(name);
        close("span");
        if (isConstantValue(d)) {
            writeConstantValue((Value) d);
        }
        if (d instanceof Generic) {
            writeTypeParameters(d.getTypeParameters(), d);
        }
        if (d instanceof Functional) {
            writeParameterList((Functional) d, d);
        }
        if (d instanceof Generic) {
            writeTypeParametersConstraints(d.getTypeParameters(), d);
        }
        if (d instanceof Value) {
            Setter setter = ((Value) d).getSetter();
            if (setter != null && Util.getAnnotation(setter.getUnit(), setter.getAnnotations(), "doc") != null) {
                tool.warningSetterDoc(d.getQualifiedNameString(), d);
            }
        }
        close("code");
        writeDescription(d);
    }
    close("td");
    close("tr");
}
Also used : Functional(org.eclipse.ceylon.model.typechecker.model.Functional) TypedDeclaration(org.eclipse.ceylon.model.typechecker.model.TypedDeclaration) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) Generic(org.eclipse.ceylon.model.typechecker.model.Generic) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Value(org.eclipse.ceylon.model.typechecker.model.Value) Setter(org.eclipse.ceylon.model.typechecker.model.Setter)

Example 3 with Setter

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

the class AnnotationUtil method isNaturalTarget.

/**
 * Whether an annotation (with the given {@code annotationCtorDecl}
 * annotation constructor) used on the given declaration ({@code useSite})
 * should be added to the Java annotations of the given generated program
 * elements ({@code target})
 * @param annotationCtorDecl
 * @param useSite
 * @param target
 * @return
 */
public static boolean isNaturalTarget(// use site is either a Declaration, or a Package, or a Module,
Function annotationCtorDecl, // module imports
Object useSite, OutputElement target) {
    EnumSet<AnnotationTarget> interopTargets;
    if (annotationCtorDecl instanceof AnnotationProxyMethod) {
        AnnotationProxyMethod annotationProxyMethod = (AnnotationProxyMethod) annotationCtorDecl;
        if (annotationProxyMethod.getAnnotationTarget() == target) {
            // Foo__WHATEVER, so honour the WHATEVER
            return true;
        }
        interopTargets = annotationProxyMethod.getAnnotationTargets();
    } else {
        interopTargets = null;
    }
    if (useSite instanceof Declaration) {
        if (ModelUtil.isConstructor((Declaration) useSite)) {
            if (useSite instanceof Functional) {
                return target == OutputElement.CONSTRUCTOR;
            } else if (useSite instanceof Value) {
                // If the constructor has a getter we can't annotate, let's
                // put the annotations on the constructor
                Class constructedClass = ModelUtil.getConstructedClass((Declaration) useSite);
                // See CeylonVisitor.transformSingletonConstructor for those tests
                if (constructedClass.isToplevel() || constructedClass.isClassMember())
                    return target == OutputElement.GETTER;
                return target == OutputElement.CONSTRUCTOR;
            }
        } else if (useSite instanceof Class) {
            if (((Class) useSite).getParameterList() != null && interopTargets != null && interopTargets.contains(AnnotationTarget.CONSTRUCTOR) && !interopTargets.contains(AnnotationTarget.TYPE)) {
                return target == OutputElement.CONSTRUCTOR;
            }
            return target == OutputElement.TYPE;
        } else if (useSite instanceof Interface) {
            return target == OutputElement.TYPE;
        } else if (useSite instanceof Value) {
            Value value = (Value) useSite;
            boolean p = value.isParameter() && target == OutputElement.PARAMETER;
            if (annotationCtorDecl instanceof AnnotationProxyMethod) {
                if (!value.isTransient() && (interopTargets == null || interopTargets.contains(AnnotationTarget.FIELD))) {
                    return target == OutputElement.FIELD;
                } else {
                    return target == OutputElement.GETTER;
                }
            } else {
                return p || target == OutputElement.GETTER;
            }
        } else if (useSite instanceof Setter) {
            return target == OutputElement.SETTER;
        } else if (useSite instanceof Function) {
            return target == OutputElement.METHOD;
        } else if (useSite instanceof Constructor) {
            return target == OutputElement.CONSTRUCTOR;
        } else if (useSite instanceof TypeAlias) {
            return target == OutputElement.TYPE;
        }
    } else if (useSite instanceof Package) {
        return (annotationCtorDecl instanceof AnnotationProxyMethod) ? target == OutputElement.PACKAGE : target == OutputElement.TYPE;
    } else if (useSite instanceof Module) {
        return target == OutputElement.TYPE;
    } else if (useSite instanceof Tree.ImportModule) {
        return target == OutputElement.FIELD;
    }
    throw new RuntimeException("" + useSite);
}
Also used : AnnotationTarget(org.eclipse.ceylon.model.loader.model.AnnotationTarget) AnnotationProxyMethod(org.eclipse.ceylon.model.loader.model.AnnotationProxyMethod) Constructor(org.eclipse.ceylon.model.typechecker.model.Constructor) TypeAlias(org.eclipse.ceylon.model.typechecker.model.TypeAlias) Functional(org.eclipse.ceylon.model.typechecker.model.Functional) Function(org.eclipse.ceylon.model.typechecker.model.Function) Value(org.eclipse.ceylon.model.typechecker.model.Value) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree) AnnotationProxyClass(org.eclipse.ceylon.model.loader.model.AnnotationProxyClass) Class(org.eclipse.ceylon.model.typechecker.model.Class) TypeDeclaration(org.eclipse.ceylon.model.typechecker.model.TypeDeclaration) Declaration(org.eclipse.ceylon.model.typechecker.model.Declaration) Package(org.eclipse.ceylon.model.typechecker.model.Package) Module(org.eclipse.ceylon.model.typechecker.model.Module) Interface(org.eclipse.ceylon.model.typechecker.model.Interface)

Example 4 with Setter

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

the class ExpressionVisitor method visit.

/*private void checkKeyValueType(Tree.Variable key, Tree.Variable value, 
            Tree.SpecifierExpression se) {
        if (key.getType()!=null && value.getType()!=null) {
            Type kt = key.getType().getTypeModel();
            Type vt = value.getType().getTypeModel();
            if (!isTypeUnknown(kt) && !isTypeUnknown(vt)) {
                checkType(unit.getIterableType(unit.getEntryType(kt, vt)), se);
            }
        }
    }*/
@Override
public void visit(Tree.AttributeGetterDefinition that) {
    Value val = that.getDeclarationModel();
    Declaration od = beginReturnDeclaration(val);
    Tree.Type type = that.getType();
    Tree.Type rt = beginReturnScope(type);
    super.visit(that);
    endReturnScope(rt, val);
    endReturnDeclaration(od);
    Setter setter = val.getSetter();
    if (setter != null) {
        setter.getParameter().getModel().setType(val.getType());
    }
    if (type instanceof Tree.LocalModifier) {
        if (isTypeUnknown(type.getTypeModel())) {
            type.addError("getter type could not be inferred");
        }
    }
}
Also used : Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) 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)

Example 5 with Setter

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

the class ExpressionVisitor method visit.

@Override
public void visit(Tree.AttributeDeclaration that) {
    super.visit(that);
    Value val = that.getDeclarationModel();
    Tree.SpecifierOrInitializerExpression sie = that.getSpecifierOrInitializerExpression();
    if (!val.isActual() || // accountForIntermediateRefinements()
    isTypeUnknown(val.getType())) {
        inferType(that, sie);
    }
    Tree.Type type = that.getType();
    if (type != null) {
        Type t = type.getTypeModel();
        if (type instanceof Tree.LocalModifier && !isNativeForWrongBackend(val, unit)) {
            if (val.isParameter() && !val.isInferred()) {
                type.addError("parameter may not have inferred type: '" + val.getName() + "' must declare an explicit type");
            } else if (isTypeUnknown(t)) {
                if (sie == null) {
                    type.addError("value must specify an explicit type or definition", 200);
                } else if (!hasError(sie)) {
                    type.addError("value type could not be inferred: '" + val.getName() + "'" + getTypeUnknownError(t));
                }
            }
        }
        if (!isTypeUnknown(t)) {
            checkType(t, val, sie, 2100);
        }
    }
    Setter setter = val.getSetter();
    if (setter != null) {
        setter.getParameter().getModel().setType(val.getType());
    }
}
Also used : ModelUtil.intersectionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.intersectionType) ModelUtil.unionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.unionType) AnalyzerUtil.spreadType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.spreadType) AnalyzerUtil.getTupleType(org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTupleType) Type(org.eclipse.ceylon.model.typechecker.model.Type) UnknownType(org.eclipse.ceylon.model.typechecker.model.UnknownType) ModelUtil.appliedType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.appliedType) ModelUtil.genericFunctionType(org.eclipse.ceylon.model.typechecker.model.ModelUtil.genericFunctionType) Value(org.eclipse.ceylon.model.typechecker.model.Value) FunctionOrValue(org.eclipse.ceylon.model.typechecker.model.FunctionOrValue) Setter(org.eclipse.ceylon.model.typechecker.model.Setter) CustomTree(org.eclipse.ceylon.compiler.typechecker.tree.CustomTree) Tree(org.eclipse.ceylon.compiler.typechecker.tree.Tree)

Aggregations

Setter (org.eclipse.ceylon.model.typechecker.model.Setter)30 Declaration (org.eclipse.ceylon.model.typechecker.model.Declaration)18 TypedDeclaration (org.eclipse.ceylon.model.typechecker.model.TypedDeclaration)17 TypeDeclaration (org.eclipse.ceylon.model.typechecker.model.TypeDeclaration)16 Value (org.eclipse.ceylon.model.typechecker.model.Value)16 FunctionOrValue (org.eclipse.ceylon.model.typechecker.model.FunctionOrValue)14 Class (org.eclipse.ceylon.model.typechecker.model.Class)8 Constructor (org.eclipse.ceylon.model.typechecker.model.Constructor)8 Function (org.eclipse.ceylon.model.typechecker.model.Function)8 Tree (org.eclipse.ceylon.compiler.typechecker.tree.Tree)7 Type (org.eclipse.ceylon.model.typechecker.model.Type)7 ArrayList (java.util.ArrayList)6 ClassOrInterface (org.eclipse.ceylon.model.typechecker.model.ClassOrInterface)5 Interface (org.eclipse.ceylon.model.typechecker.model.Interface)5 Parameter (org.eclipse.ceylon.model.typechecker.model.Parameter)5 TypeParameter (org.eclipse.ceylon.model.typechecker.model.TypeParameter)5 AnalyzerUtil.getPackageTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getPackageTypeDeclaration)4 AnalyzerUtil.getTypeDeclaration (org.eclipse.ceylon.compiler.typechecker.analyzer.AnalyzerUtil.getTypeDeclaration)4 CustomTree (org.eclipse.ceylon.compiler.typechecker.tree.CustomTree)4 MethodDeclaration (org.eclipse.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)4