Search in sources :

Example 1 with Setter

use of com.redhat.ceylon.model.typechecker.model.Setter in project ceylon-compiler by ceylon.

the class ClassOrPackageDoc method doc.

protected final void doc(String name, Declaration d) throws IOException {
    String declarationName = Util.getDeclarationName(d);
    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='" + name + "' nowrap");
    writeIcon(d);
    if (!(d instanceof Constructor)) {
        around("code class='decl-label'", name);
        close("td");
        open("td");
    }
    writeLinkOneSelf(d);
    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 (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();
            }
        }
        write(" ");
        open("span class='identifier'");
        write(name);
        close("span");
        if (isConstantValue(d)) {
            writeConstantValue((Value) d);
        }
        if (d instanceof Generic) {
            Generic f = (Generic) d;
            writeTypeParameters(f.getTypeParameters(), d);
        }
        if (d instanceof Functional) {
            writeParameterList((Functional) d, d);
        }
        if (d instanceof Generic) {
            Generic f = (Generic) d;
            writeTypeParametersConstraints(f.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(com.redhat.ceylon.model.typechecker.model.Functional) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Constructor(com.redhat.ceylon.model.typechecker.model.Constructor) Generic(com.redhat.ceylon.model.typechecker.model.Generic) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) Setter(com.redhat.ceylon.model.typechecker.model.Setter)

Example 2 with Setter

use of com.redhat.ceylon.model.typechecker.model.Setter in project ceylon-compiler by ceylon.

the class CeylonTransformer method transformAttribute.

public List<JCTree> transformAttribute(TypedDeclaration declarationModel, String attrName, String attrClassName, final Tree.Declaration annotated, final Tree.Block block, final Tree.SpecifierOrInitializerExpression expression, final Tree.TypedDeclaration decl, final Tree.AttributeSetterDefinition setterDecl) {
    // For everything else generate a getter/setter method
    AttributeDefinitionBuilder builder = AttributeDefinitionBuilder.wrapped(this, attrClassName, null, attrName, declarationModel, declarationModel.isToplevel()).is(Flags.PUBLIC, declarationModel.isShared());
    final JCExpression initialValue;
    final HasErrorException expressionError;
    if (expression != null) {
        expressionError = errors().getFirstExpressionErrorAndMarkBrokenness(expression.getExpression());
        if (expressionError != null) {
            initialValue = make().Erroneous();
        } else {
            initialValue = transformValueInit(declarationModel, attrName, expression);
        }
    } else {
        expressionError = null;
        initialValue = transformValueInit(declarationModel, attrName, expression);
    }
    // For captured local variable Values, use a VariableBox
    if (Decl.isBoxedVariable(declarationModel)) {
        if (expressionError != null) {
            return List.<JCTree>of(this.makeThrowUnresolvedCompilationError(expressionError));
        } else {
            return List.<JCTree>of(makeVariableBoxDecl(initialValue, declarationModel));
        }
    }
    // For late-bound getters we only generate a declaration
    if (block == null && expression == null && !Decl.isToplevel(declarationModel)) {
        JCExpression typeExpr = makeJavaType(getGetterInterfaceType(declarationModel));
        JCTree.JCVariableDecl var = makeVar(attrClassName, typeExpr, null);
        return List.<JCTree>of(var);
    }
    // Set the local declarations annotation
    if (decl != null) {
        List<JCAnnotation> scopeAnnotations;
        if (Decl.isToplevel(declarationModel) && setterDecl != null) {
            scopeAnnotations = makeAtLocalDeclarations(decl, setterDecl);
        } else {
            scopeAnnotations = makeAtLocalDeclarations(decl);
        }
        builder.classAnnotations(scopeAnnotations);
    } else if (block != null) {
        List<JCAnnotation> scopeAnnotations = makeAtLocalDeclarations(block);
        builder.classAnnotations(scopeAnnotations);
    }
    // Remember the setter class if we generate a getter
    if (Decl.isGetter(declarationModel) && declarationModel.isVariable() && Decl.isLocal(declarationModel)) {
        // we must have a setter class
        Setter setter = ((Value) declarationModel).getSetter();
        if (setter != null) {
            String setterClassName = Naming.getAttrClassName(setter, 0);
            JCExpression setterClassNameExpr = naming.makeUnquotedIdent(setterClassName);
            builder.setterClass(makeSelect(setterClassNameExpr, "class"));
        }
    }
    if (declarationModel instanceof Setter || (declarationModel instanceof FunctionOrValue && ((FunctionOrValue) declarationModel).isParameter())) {
        // For local setters
        JCBlock setterBlock = makeSetterBlock(declarationModel, block, expression);
        builder.setterBlock(setterBlock);
        builder.skipGetter();
        if (Decl.isLocal(decl)) {
            // we need to find back the Setter model for local setters, because 
            // in transformAttribute(Tree.TypedDeclaration decl, Tree.AttributeSetterDefinition setterDecl)
            // we turn the declaration model from the Setter to its single parameter
            Setter setter = (Setter) declarationModel.getContainer();
            String getterClassName = Naming.getAttrClassName(setter.getGetter(), 0);
            JCExpression getterClassNameExpr = naming.makeUnquotedIdent(getterClassName);
            builder.isSetter(makeSelect(getterClassNameExpr, "class"));
        }
    } else {
        if (Decl.isValue(declarationModel)) {
            // For local and toplevel value attributes
            if (!declarationModel.isVariable() && !declarationModel.isLate()) {
                builder.immutable();
            }
        } else {
            // For local and toplevel getters
            boolean prevSyntheticClassBody;
            if (Decl.isLocal(declarationModel)) {
                prevSyntheticClassBody = expressionGen().withinSyntheticClassBody(true);
            } else {
                prevSyntheticClassBody = expressionGen().isWithinSyntheticClassBody();
            }
            JCBlock getterBlock = makeGetterBlock(declarationModel, block, expression);
            prevSyntheticClassBody = expressionGen().withinSyntheticClassBody(prevSyntheticClassBody);
            builder.getterBlock(getterBlock);
            if (Decl.isLocal(declarationModel)) {
                // For local getters
                builder.immutable();
            } else {
                // For toplevel getters
                if (setterDecl != null) {
                    JCBlock setterBlock = makeSetterBlock(setterDecl.getDeclarationModel(), setterDecl.getBlock(), setterDecl.getSpecifierExpression());
                    builder.setterBlock(setterBlock);
                    //builder.userAnnotationsSetter(expressionGen().transformAnnotations(true, OutputElement.METHOD, setterDecl));
                    builder.userAnnotationsSetter(expressionGen().transformAnnotations(OutputElement.SETTER, setterDecl));
                } else {
                    builder.immutable();
                }
            }
        }
    }
    if (annotated != null) {
        builder.userAnnotations(expressionGen().transformAnnotations(OutputElement.GETTER, annotated));
    }
    if (Decl.isLocal(declarationModel)) {
        if (expressionError != null) {
            return List.<JCTree>of(this.makeThrowUnresolvedCompilationError(expressionError));
        }
        builder.classAnnotations(makeAtLocalDeclaration(declarationModel.getQualifier(), false));
        if (initialValue != null)
            builder.valueConstructor();
        JCExpression typeExpr;
        if (declarationModel instanceof Setter || (declarationModel instanceof FunctionOrValue && ((FunctionOrValue) declarationModel).isParameter())) {
            typeExpr = makeQuotedIdent(attrClassName);
        } else {
            typeExpr = makeJavaType(getGetterInterfaceType(declarationModel));
        }
        return builder.build().append(makeLocalIdentityInstance(typeExpr, attrClassName, attrClassName, declarationModel.isShared(), initialValue));
    } else {
        if (expressionError != null) {
            builder.initialValueError(expressionError);
        } else if (initialValue != null) {
            builder.initialValue(initialValue);
        }
        builder.is(Flags.STATIC, true);
        return builder.build();
    }
}
Also used : JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JCTree(com.sun.tools.javac.tree.JCTree) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) HasErrorException(com.redhat.ceylon.compiler.java.codegen.recovery.HasErrorException) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) Setter(com.redhat.ceylon.model.typechecker.model.Setter) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue) Value(com.redhat.ceylon.model.typechecker.model.Value) List(com.sun.tools.javac.util.List) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) FunctionOrValue(com.redhat.ceylon.model.typechecker.model.FunctionOrValue)

Example 3 with Setter

use of com.redhat.ceylon.model.typechecker.model.Setter in project ceylon-compiler by ceylon.

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(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Setter(com.redhat.ceylon.model.typechecker.model.Setter)

Example 4 with Setter

use of com.redhat.ceylon.model.typechecker.model.Setter in project ceylon-compiler by ceylon.

the class InterfaceVisitor method visit.

@Override
public void visit(Tree.AttributeSetterDefinition that) {
    Setter model = that.getDeclarationModel();
    // locals and toplevels get a type generated for them
    if (!model.isMember() && !model.isToplevel()) {
        Set<String> old = localCompanionClasses;
        localCompanionClasses = new HashSet<String>();
        super.visit(that);
        localCompanionClasses = old;
    } else {
        super.visit(that);
    }
}
Also used : Setter(com.redhat.ceylon.model.typechecker.model.Setter)

Example 5 with Setter

use of com.redhat.ceylon.model.typechecker.model.Setter in project ceylon-compiler by ceylon.

the class MethodOrValueReferenceVisitor method visit.

@Override
public void visit(Tree.Declaration that) {
    Declaration dm = that.getDeclarationModel();
    if (dm == declaration.getContainer() || (Decl.equal(dm, declaration) && !isClassWithConstructorMember(declaration)) || (dm instanceof Setter && ((Setter) dm).getGetter() == declaration)) {
        if (!isCapturableMplParameter(declaration)) {
            this.inCapturingScope = false;
        }
    }
    super.visit(that);
}
Also used : Setter(com.redhat.ceylon.model.typechecker.model.Setter) TypedDeclaration(com.redhat.ceylon.model.typechecker.model.TypedDeclaration) Declaration(com.redhat.ceylon.model.typechecker.model.Declaration) TypeDeclaration(com.redhat.ceylon.model.typechecker.model.TypeDeclaration)

Aggregations

Setter (com.redhat.ceylon.model.typechecker.model.Setter)10 TypedDeclaration (com.redhat.ceylon.model.typechecker.model.TypedDeclaration)8 Declaration (com.redhat.ceylon.model.typechecker.model.Declaration)6 FunctionOrValue (com.redhat.ceylon.model.typechecker.model.FunctionOrValue)6 Value (com.redhat.ceylon.model.typechecker.model.Value)6 TypeDeclaration (com.redhat.ceylon.model.typechecker.model.TypeDeclaration)5 Constructor (com.redhat.ceylon.model.typechecker.model.Constructor)4 AttributeDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.AttributeDeclaration)3 MethodDeclaration (com.redhat.ceylon.compiler.typechecker.tree.Tree.MethodDeclaration)3 JavaBeanValue (com.redhat.ceylon.model.loader.model.JavaBeanValue)3 Class (com.redhat.ceylon.model.typechecker.model.Class)3 Function (com.redhat.ceylon.model.typechecker.model.Function)3 Type (com.redhat.ceylon.model.typechecker.model.Type)3 JCTree (com.sun.tools.javac.tree.JCTree)3 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)3 ThrowerCatchallConstructor (com.redhat.ceylon.compiler.java.codegen.recovery.ThrowerCatchallConstructor)2 Tree (com.redhat.ceylon.compiler.typechecker.tree.Tree)2 AnnotationList (com.redhat.ceylon.compiler.typechecker.tree.Tree.AnnotationList)2 ClassOrInterface (com.redhat.ceylon.model.typechecker.model.ClassOrInterface)2 Interface (com.redhat.ceylon.model.typechecker.model.Interface)2