Search in sources :

Example 71 with JCBlock

use of com.sun.tools.javac.tree.JCTree.JCBlock in project lombok by rzwitserloot.

the class HandleEqualsAndHashCode method createHashCode.

public JCMethodDecl createHashCode(JavacNode typeNode, java.util.List<Included<JavacNode, EqualsAndHashCode.Include>> members, boolean callSuper, boolean cacheHashCode, FieldAccess fieldAccess, JavacNode source) {
    JavacTreeMaker maker = typeNode.getTreeMaker();
    JCAnnotation overrideAnnotation = maker.Annotation(genJavaLangTypeRef(typeNode, "Override"), List.<JCExpression>nil());
    List<JCAnnotation> annsOnMethod = List.of(overrideAnnotation);
    CheckerFrameworkVersion checkerFramework = getCheckerFrameworkVersion(typeNode);
    if (cacheHashCode && checkerFramework.generatePure()) {
        annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__PURE), List.<JCExpression>nil()));
    } else if (checkerFramework.generateSideEffectFree()) {
        annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
    }
    JCModifiers mods = maker.Modifiers(Flags.PUBLIC, annsOnMethod);
    JCExpression returnType = maker.TypeIdent(CTC_INT);
    ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
    Name primeName = typeNode.toName(PRIME_NAME);
    Name resultName = typeNode.toName(RESULT_NAME);
    long finalFlag = JavacHandlerUtil.addFinalIfNeeded(0L, typeNode.getContext());
    boolean isEmpty = members.isEmpty();
    /* if (this.$hashCodeCache != 0) return this.$hashCodeCache; */
    {
        if (cacheHashCode) {
            JCIdent receiver = maker.Ident(typeNode.toName("this"));
            JCFieldAccess cacheHashCodeFieldAccess = maker.Select(receiver, typeNode.toName(HASH_CODE_CACHE_NAME));
            JCExpression cacheNotZero = maker.Binary(CTC_NOT_EQUAL, cacheHashCodeFieldAccess, maker.Literal(CTC_INT, 0));
            statements.append(maker.If(cacheNotZero, maker.Return(cacheHashCodeFieldAccess), null));
        }
    }
    /* final int PRIME = X; */
    {
        if (!isEmpty) {
            statements.append(maker.VarDef(maker.Modifiers(finalFlag), primeName, maker.TypeIdent(CTC_INT), maker.Literal(HandlerUtil.primeForHashcode())));
        }
    }
    /* int result = ... */
    {
        final JCExpression init;
        if (callSuper) {
            /* ... super.hashCode(); */
            init = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(typeNode.toName("super")), typeNode.toName("hashCode")), List.<JCExpression>nil());
        } else {
            /* ... 1; */
            init = maker.Literal(1);
        }
        statements.append(maker.VarDef(maker.Modifiers(isEmpty && !cacheHashCode ? finalFlag : 0L), resultName, maker.TypeIdent(CTC_INT), init));
    }
    for (Included<JavacNode, EqualsAndHashCode.Include> member : members) {
        JavacNode memberNode = member.getNode();
        JCExpression fType = unnotate(getFieldType(memberNode, fieldAccess));
        boolean isMethod = memberNode.getKind() == Kind.METHOD;
        JCExpression fieldAccessor = isMethod ? createMethodAccessor(maker, memberNode) : createFieldAccessor(maker, memberNode, fieldAccess);
        if (fType instanceof JCPrimitiveTypeTree) {
            switch(((JCPrimitiveTypeTree) fType).getPrimitiveTypeKind()) {
                case BOOLEAN:
                    /* this.fieldName ? X : Y */
                    statements.append(createResultCalculation(typeNode, maker.Parens(maker.Conditional(fieldAccessor, maker.Literal(HandlerUtil.primeForTrue()), maker.Literal(HandlerUtil.primeForFalse())))));
                    break;
                case LONG:
                    {
                        Name dollarFieldName = memberNode.toName((isMethod ? "$$" : "$") + memberNode.getName());
                        statements.append(maker.VarDef(maker.Modifiers(finalFlag), dollarFieldName, maker.TypeIdent(CTC_LONG), fieldAccessor));
                        statements.append(createResultCalculation(typeNode, longToIntForHashCode(maker, maker.Ident(dollarFieldName), maker.Ident(dollarFieldName))));
                    }
                    break;
                case FLOAT:
                    /* Float.floatToIntBits(this.fieldName) */
                    statements.append(createResultCalculation(typeNode, maker.Apply(List.<JCExpression>nil(), genJavaLangTypeRef(typeNode, "Float", "floatToIntBits"), List.of(fieldAccessor))));
                    break;
                case DOUBLE:
                    {
                        /* longToIntForHashCode(Double.doubleToLongBits(this.fieldName)) */
                        Name dollarFieldName = memberNode.toName((isMethod ? "$$" : "$") + memberNode.getName());
                        JCExpression init = maker.Apply(List.<JCExpression>nil(), genJavaLangTypeRef(typeNode, "Double", "doubleToLongBits"), List.of(fieldAccessor));
                        statements.append(maker.VarDef(maker.Modifiers(finalFlag), dollarFieldName, maker.TypeIdent(CTC_LONG), init));
                        statements.append(createResultCalculation(typeNode, longToIntForHashCode(maker, maker.Ident(dollarFieldName), maker.Ident(dollarFieldName))));
                    }
                    break;
                default:
                case BYTE:
                case SHORT:
                case INT:
                case CHAR:
                    /* just the field */
                    statements.append(createResultCalculation(typeNode, fieldAccessor));
                    break;
            }
        } else if (fType instanceof JCArrayTypeTree) {
            JCArrayTypeTree array = (JCArrayTypeTree) fType;
            /* java.util.Arrays.deepHashCode(this.fieldName) //use just hashCode() for primitive arrays. */
            boolean multiDim = unnotate(array.elemtype) instanceof JCArrayTypeTree;
            boolean primitiveArray = unnotate(array.elemtype) instanceof JCPrimitiveTypeTree;
            boolean useDeepHC = multiDim || !primitiveArray;
            JCExpression hcMethod = chainDots(typeNode, "java", "util", "Arrays", useDeepHC ? "deepHashCode" : "hashCode");
            statements.append(createResultCalculation(typeNode, maker.Apply(List.<JCExpression>nil(), hcMethod, List.of(fieldAccessor))));
        } else /* objects */
        {
            /* final java.lang.Object $fieldName = this.fieldName; */
            /* ($fieldName == null ? NULL_PRIME : $fieldName.hashCode()) */
            Name dollarFieldName = memberNode.toName((isMethod ? "$$" : "$") + memberNode.getName());
            statements.append(maker.VarDef(maker.Modifiers(finalFlag), dollarFieldName, genJavaLangTypeRef(typeNode, "Object"), fieldAccessor));
            JCExpression hcCall = maker.Apply(List.<JCExpression>nil(), maker.Select(maker.Ident(dollarFieldName), typeNode.toName("hashCode")), List.<JCExpression>nil());
            JCExpression thisEqualsNull = maker.Binary(CTC_EQUAL, maker.Ident(dollarFieldName), maker.Literal(CTC_BOT, null));
            statements.append(createResultCalculation(typeNode, maker.Parens(maker.Conditional(thisEqualsNull, maker.Literal(HandlerUtil.primeForNull()), hcCall))));
        }
    }
    /* 
		 * if (result == 0) result = Integer.MIN_VALUE;
		 * this.$hashCodeCache = result;
		 * 
		 */
    {
        if (cacheHashCode) {
            statements.append(maker.If(maker.Binary(CTC_EQUAL, maker.Ident(resultName), maker.Literal(CTC_INT, 0)), maker.Exec(maker.Assign(maker.Ident(resultName), genJavaLangTypeRef(typeNode, "Integer", "MIN_VALUE"))), null));
            JCFieldAccess cacheHashCodeFieldAccess = maker.Select(maker.Ident(typeNode.toName("this")), typeNode.toName(HASH_CODE_CACHE_NAME));
            statements.append(maker.Exec(maker.Assign(cacheHashCodeFieldAccess, maker.Ident(resultName))));
        }
    }
    /* return result; */
    {
        statements.append(maker.Return(maker.Ident(resultName)));
    }
    JCBlock body = maker.Block(0, statements.toList());
    return recursiveSetGeneratedBy(maker.MethodDef(mods, typeNode.toName("hashCode"), returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null), source);
}
Also used : JCIdent(com.sun.tools.javac.tree.JCTree.JCIdent) JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JavacTreeMaker(lombok.javac.JavacTreeMaker) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) Name(com.sun.tools.javac.util.Name) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) JCPrimitiveTypeTree(com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JavacNode(lombok.javac.JavacNode) JCModifiers(com.sun.tools.javac.tree.JCTree.JCModifiers) CheckerFrameworkVersion(lombok.core.configuration.CheckerFrameworkVersion) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) JCArrayTypeTree(com.sun.tools.javac.tree.JCTree.JCArrayTypeTree)

Example 72 with JCBlock

use of com.sun.tools.javac.tree.JCTree.JCBlock in project lombok by rzwitserloot.

the class HandleEqualsAndHashCode method createCanEqual.

public JCMethodDecl createCanEqual(JavacNode typeNode, JavacNode source, List<JCAnnotation> onParam) {
    /* protected boolean canEqual(final java.lang.Object other) {
		 *     return other instanceof Outer.Inner.MyType;
		 * }
		 */
    JavacTreeMaker maker = typeNode.getTreeMaker();
    List<JCAnnotation> annsOnMethod = List.nil();
    CheckerFrameworkVersion checkerFramework = getCheckerFrameworkVersion(typeNode);
    if (checkerFramework.generatePure()) {
        annsOnMethod = annsOnMethod.prepend(maker.Annotation(genTypeRef(typeNode, CheckerFrameworkVersion.NAME__PURE), List.<JCExpression>nil()));
    }
    JCModifiers mods = maker.Modifiers(Flags.PROTECTED, annsOnMethod);
    JCExpression returnType = maker.TypeIdent(CTC_BOOLEAN);
    Name canEqualName = typeNode.toName("canEqual");
    JCExpression objectType = genJavaLangTypeRef(typeNode, "Object");
    Name otherName = typeNode.toName("other");
    long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, typeNode.getContext());
    JCVariableDecl param = maker.VarDef(maker.Modifiers(flags, onParam), otherName, objectType, null);
    createRelevantNullableAnnotation(typeNode, param);
    List<JCVariableDecl> params = List.of(param);
    JCBlock body = maker.Block(0, List.<JCStatement>of(maker.Return(maker.TypeTest(maker.Ident(otherName), createTypeReference(typeNode, false)))));
    return recursiveSetGeneratedBy(maker.MethodDef(mods, canEqualName, returnType, List.<JCTypeParameter>nil(), params, List.<JCExpression>nil(), body, null), source);
}
Also used : JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JavacTreeMaker(lombok.javac.JavacTreeMaker) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCModifiers(com.sun.tools.javac.tree.JCTree.JCModifiers) CheckerFrameworkVersion(lombok.core.configuration.CheckerFrameworkVersion) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) Name(com.sun.tools.javac.util.Name)

Example 73 with JCBlock

use of com.sun.tools.javac.tree.JCTree.JCBlock in project lombok by rzwitserloot.

the class HandleGetter method createGetter.

public JCMethodDecl createGetter(long access, JavacNode field, JavacTreeMaker treeMaker, JavacNode source, boolean lazy, List<JCAnnotation> onMethod) {
    JCVariableDecl fieldNode = (JCVariableDecl) field.get();
    // Remember the type; lazy will change it
    JCExpression methodType = cloneType(treeMaker, copyType(treeMaker, fieldNode), source);
    AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field);
    // Generate the methodName; lazy will change the field type
    Name methodName = field.toName(toGetterName(field, accessors));
    boolean makeFinal = shouldMakeFinal(field, accessors);
    List<JCStatement> statements;
    JCTree toClearOfMarkers = null;
    int[] methodArgPos = null;
    boolean addSuppressWarningsUnchecked = false;
    if (lazy && !inNetbeansEditor(field)) {
        toClearOfMarkers = fieldNode.init;
        if (toClearOfMarkers instanceof JCMethodInvocation) {
            List<JCExpression> args = ((JCMethodInvocation) toClearOfMarkers).args;
            methodArgPos = new int[args.length()];
            for (int i = 0; i < methodArgPos.length; i++) {
                methodArgPos[i] = args.get(i).pos;
            }
        }
        statements = createLazyGetterBody(treeMaker, field, source);
        addSuppressWarningsUnchecked = LombokOptionsFactory.getDelombokOptions(field.getContext()).getFormatPreferences().generateSuppressWarnings();
    } else {
        statements = createSimpleGetterBody(treeMaker, field);
    }
    JCBlock methodBody = treeMaker.Block(0, statements);
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.nil();
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;
    List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(field);
    List<JCAnnotation> delegates = findDelegatesAndRemoveFromField(field);
    List<JCAnnotation> annsOnMethod = copyAnnotations(onMethod).appendList(copyableAnnotations);
    if (field.isFinal()) {
        if (getCheckerFrameworkVersion(field).generatePure())
            annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genTypeRef(field, CheckerFrameworkVersion.NAME__PURE), List.<JCExpression>nil()));
    } else {
        if (getCheckerFrameworkVersion(field).generateSideEffectFree())
            annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genTypeRef(field, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
    }
    if (isFieldDeprecated(field))
        annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
    if (makeFinal)
        access |= Flags.FINAL;
    JCMethodDecl decl = recursiveSetGeneratedBy(treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue), source);
    if (toClearOfMarkers != null)
        recursiveSetGeneratedBy(toClearOfMarkers, null);
    if (methodArgPos != null) {
        for (int i = 0; i < methodArgPos.length; i++) {
            ((JCMethodInvocation) toClearOfMarkers).args.get(i).pos = methodArgPos[i];
        }
    }
    decl.mods.annotations = decl.mods.annotations.appendList(delegates);
    if (addSuppressWarningsUnchecked) {
        ListBuffer<JCExpression> suppressions = new ListBuffer<JCExpression>();
        if (!Boolean.FALSE.equals(field.getAst().readConfiguration(ConfigurationKeys.ADD_SUPPRESSWARNINGS_ANNOTATIONS))) {
            suppressions.append(treeMaker.Literal("all"));
        }
        suppressions.append(treeMaker.Literal("unchecked"));
        addAnnotation(decl.mods, field, source, "java.lang.SuppressWarnings", treeMaker.NewArray(null, List.<JCExpression>nil(), suppressions.toList()));
    }
    copyJavadoc(field, decl, CopyJavadoc.GETTER);
    return decl;
}
Also used : JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JCMethodDecl(com.sun.tools.javac.tree.JCTree.JCMethodDecl) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCTree(com.sun.tools.javac.tree.JCTree) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) Accessors(lombok.experimental.Accessors) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) Name(com.sun.tools.javac.util.Name) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) JCMethodInvocation(com.sun.tools.javac.tree.JCTree.JCMethodInvocation) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Example 74 with JCBlock

use of com.sun.tools.javac.tree.JCTree.JCBlock in project lombok by rzwitserloot.

the class HandleNonNull method returnVarNameIfNullCheck.

/**
 * Checks if the statement is of the form 'if (x == null) {throw WHATEVER;}' or 'assert x != null;',
 * where the block braces are optional. If it is of this form, returns "x".
 * If it is not of this form, returns null.
 */
public String returnVarNameIfNullCheck(JCStatement stat) {
    boolean isIf = stat instanceof JCIf;
    boolean isExpression = stat instanceof JCExpressionStatement;
    if (!isIf && !(stat instanceof JCAssert) && !isExpression)
        return null;
    if (isExpression) {
        /* Check if the statements contains a call to checkNotNull or requireNonNull */
        JCExpression expression = ((JCExpressionStatement) stat).expr;
        if (expression instanceof JCAssign)
            expression = ((JCAssign) expression).rhs;
        if (!(expression instanceof JCMethodInvocation))
            return null;
        JCMethodInvocation invocation = (JCMethodInvocation) expression;
        JCExpression method = invocation.meth;
        Name name = null;
        if (method instanceof JCFieldAccess) {
            name = ((JCFieldAccess) method).name;
        } else if (method instanceof JCIdent) {
            name = ((JCIdent) method).name;
        }
        if (name == null || (!name.contentEquals("checkNotNull") && !name.contentEquals("requireNonNull")))
            return null;
        if (invocation.args.isEmpty())
            return null;
        JCExpression firstArgument = invocation.args.head;
        if (!(firstArgument instanceof JCIdent))
            return null;
        return ((JCIdent) firstArgument).toString();
    }
    if (isIf) {
        /* Check that the if's statement is a throw statement, possibly in a block. */
        JCStatement then = ((JCIf) stat).thenpart;
        if (then instanceof JCBlock) {
            List<JCStatement> stats = ((JCBlock) then).stats;
            if (stats.length() == 0)
                return null;
            then = stats.get(0);
        }
        if (!(then instanceof JCThrow))
            return null;
    }
    /* Check that the if's conditional is like 'x == null'. Return from this method (don't generate
		   a nullcheck) if 'x' is equal to our own variable's name: There's already a nullcheck here. */
    {
        JCExpression cond = isIf ? ((JCIf) stat).cond : ((JCAssert) stat).cond;
        while (cond instanceof JCParens) cond = ((JCParens) cond).expr;
        if (!(cond instanceof JCBinary))
            return null;
        JCBinary bin = (JCBinary) cond;
        if (isIf) {
            if (!CTC_EQUAL.equals(treeTag(bin)))
                return null;
        } else {
            if (!CTC_NOT_EQUAL.equals(treeTag(bin)))
                return null;
        }
        if (!(bin.lhs instanceof JCIdent))
            return null;
        if (!(bin.rhs instanceof JCLiteral))
            return null;
        if (!CTC_BOT.equals(typeTag(bin.rhs)))
            return null;
        return ((JCIdent) bin.lhs).name.toString();
    }
}
Also used : JCIdent(com.sun.tools.javac.tree.JCTree.JCIdent) JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JCAssign(com.sun.tools.javac.tree.JCTree.JCAssign) JCFieldAccess(com.sun.tools.javac.tree.JCTree.JCFieldAccess) JCBinary(com.sun.tools.javac.tree.JCTree.JCBinary) JCParens(com.sun.tools.javac.tree.JCTree.JCParens) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) JCExpressionStatement(com.sun.tools.javac.tree.JCTree.JCExpressionStatement) Name(com.sun.tools.javac.util.Name) JCMethodInvocation(com.sun.tools.javac.tree.JCTree.JCMethodInvocation) JCAssert(com.sun.tools.javac.tree.JCTree.JCAssert) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCIf(com.sun.tools.javac.tree.JCTree.JCIf) JCLiteral(com.sun.tools.javac.tree.JCTree.JCLiteral) JCThrow(com.sun.tools.javac.tree.JCTree.JCThrow)

Example 75 with JCBlock

use of com.sun.tools.javac.tree.JCTree.JCBlock in project lombok by rzwitserloot.

the class HandleSetter method createSetterWithRecv.

public static JCMethodDecl createSetterWithRecv(long access, boolean deprecate, JavacNode field, JavacTreeMaker treeMaker, String setterName, Name paramName, Name booleanFieldToSet, JCExpression methodType, JCStatement returnStatement, JavacNode source, List<JCAnnotation> onMethod, List<JCAnnotation> onParam, JCVariableDecl recv) {
    if (setterName == null)
        return null;
    JCVariableDecl fieldDecl = (JCVariableDecl) field.get();
    if (paramName == null)
        paramName = fieldDecl.name;
    JCExpression fieldRef = createFieldAccessor(treeMaker, field, FieldAccess.ALWAYS_FIELD);
    JCAssign assign = treeMaker.Assign(fieldRef, treeMaker.Ident(paramName));
    ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
    List<JCAnnotation> copyableAnnotations = findCopyableAnnotations(field);
    Name methodName = field.toName(setterName);
    List<JCAnnotation> annsOnParam = copyAnnotations(onParam).appendList(copyableAnnotations);
    long flags = JavacHandlerUtil.addFinalIfNeeded(Flags.PARAMETER, field.getContext());
    JCExpression pType = cloneType(treeMaker, fieldDecl.vartype, source);
    JCVariableDecl param = treeMaker.VarDef(treeMaker.Modifiers(flags, annsOnParam), paramName, pType, null);
    if (!hasNonNullAnnotations(field) && !hasNonNullAnnotations(field, onParam)) {
        statements.append(treeMaker.Exec(assign));
    } else {
        JCStatement nullCheck = generateNullCheck(treeMaker, fieldDecl.vartype, paramName, source, null);
        if (nullCheck != null)
            statements.append(nullCheck);
        statements.append(treeMaker.Exec(assign));
    }
    if (booleanFieldToSet != null) {
        JCAssign setBool = treeMaker.Assign(treeMaker.Ident(booleanFieldToSet), treeMaker.Literal(CTC_BOOLEAN, 1));
        statements.append(treeMaker.Exec(setBool));
    }
    if (methodType == null) {
        // WARNING: Do not use field.getSymbolTable().voidType - that field has gone through non-backwards compatible API changes within javac1.6.
        methodType = treeMaker.Type(Javac.createVoidType(field.getSymbolTable(), CTC_VOID));
        returnStatement = null;
    }
    if (returnStatement != null)
        statements.append(returnStatement);
    JCBlock methodBody = treeMaker.Block(0, statements.toList());
    List<JCTypeParameter> methodGenericParams = List.nil();
    List<JCVariableDecl> parameters = List.of(param);
    List<JCExpression> throwsClauses = List.nil();
    JCExpression annotationMethodDefaultValue = null;
    List<JCAnnotation> annsOnMethod = mergeAnnotations(copyAnnotations(onMethod), findCopyableToSetterAnnotations(field));
    if (isFieldDeprecated(field) || deprecate) {
        annsOnMethod = annsOnMethod.prepend(treeMaker.Annotation(genJavaLangTypeRef(field, "Deprecated"), List.<JCExpression>nil()));
    }
    AnnotationValues<Accessors> accessors = JavacHandlerUtil.getAccessorsForField(field);
    if (shouldMakeFinal(field, accessors))
        access |= Flags.FINAL;
    JCMethodDecl methodDef;
    if (recv != null && treeMaker.hasMethodDefWithRecvParam()) {
        methodDef = treeMaker.MethodDefWithRecvParam(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, methodGenericParams, recv, parameters, throwsClauses, methodBody, annotationMethodDefaultValue);
    } else {
        methodDef = treeMaker.MethodDef(treeMaker.Modifiers(access, annsOnMethod), methodName, methodType, methodGenericParams, parameters, throwsClauses, methodBody, annotationMethodDefaultValue);
    }
    if (returnStatement != null)
        createRelevantNonNullAnnotation(source, methodDef);
    JCMethodDecl decl = recursiveSetGeneratedBy(methodDef, source);
    copyJavadoc(field, decl, CopyJavadoc.SETTER, returnStatement != null);
    return decl;
}
Also used : JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JCMethodDecl(com.sun.tools.javac.tree.JCTree.JCMethodDecl) JCAssign(com.sun.tools.javac.tree.JCTree.JCAssign) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement) Accessors(lombok.experimental.Accessors) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) Name(com.sun.tools.javac.util.Name) JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation)

Aggregations

JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)85 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)68 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)64 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)54 Name (com.sun.tools.javac.util.Name)48 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)45 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)41 ListBuffer (com.sun.tools.javac.util.ListBuffer)41 JCModifiers (com.sun.tools.javac.tree.JCTree.JCModifiers)37 JavacTreeMaker (lombok.javac.JavacTreeMaker)34 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)28 JavacNode (lombok.javac.JavacNode)14 JCTree (com.sun.tools.javac.tree.JCTree)13 JCMethodInvocation (com.sun.tools.javac.tree.JCTree.JCMethodInvocation)11 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)11 JCReturn (com.sun.tools.javac.tree.JCTree.JCReturn)9 JCArrayTypeTree (com.sun.tools.javac.tree.JCTree.JCArrayTypeTree)6 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)6 JCIf (com.sun.tools.javac.tree.JCTree.JCIf)6 JCNewClass (com.sun.tools.javac.tree.JCTree.JCNewClass)6