Search in sources :

Example 76 with JavacTreeMaker

use of lombok.javac.JavacTreeMaker in project lombok by rzwitserloot.

the class HandleBuilder method generateCleanMethod.

private JCMethodDecl generateCleanMethod(BuilderJob job) {
    JavacTreeMaker maker = job.getTreeMaker();
    ListBuffer<JCStatement> statements = new ListBuffer<JCStatement>();
    for (BuilderFieldData bfd : job.builderFields) {
        if (bfd.singularData != null && bfd.singularData.getSingularizer() != null) {
            bfd.singularData.getSingularizer().appendCleaningCode(bfd.singularData, job.builderType, job.sourceNode, statements);
        }
    }
    statements.append(maker.Exec(maker.Assign(maker.Select(maker.Ident(job.toName("this")), job.toName(CLEAN_FIELD_NAME)), maker.Literal(CTC_BOOLEAN, 0))));
    JCBlock body = maker.Block(0, statements.toList());
    JCMethodDecl method = maker.MethodDef(maker.Modifiers(toJavacModifier(AccessLevel.PRIVATE)), job.toName(CLEAN_METHOD_NAME), maker.Type(Javac.createVoidType(job.builderType.getSymbolTable(), CTC_VOID)), List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), body, null);
    recursiveSetGeneratedBy(method, job.sourceNode);
    return method;
}
Also used : JCBlock(com.sun.tools.javac.tree.JCTree.JCBlock) JavacTreeMaker(lombok.javac.JavacTreeMaker) JCMethodDecl(com.sun.tools.javac.tree.JCTree.JCMethodDecl) ListBuffer(com.sun.tools.javac.util.ListBuffer) JCStatement(com.sun.tools.javac.tree.JCTree.JCStatement)

Example 77 with JavacTreeMaker

use of lombok.javac.JavacTreeMaker in project lombok by rzwitserloot.

the class HandleBuilder method makePrefixedSetterMethodForBuilder.

private void makePrefixedSetterMethodForBuilder(BuilderJob job, BuilderFieldData bfd, boolean deprecate, String prefix) {
    JavacNode fieldNode = bfd.createdFields.get(0);
    String setterPrefix = !prefix.isEmpty() ? prefix : job.oldFluent ? "" : "set";
    String setterName = HandlerUtil.buildAccessorName(job.sourceNode, setterPrefix, bfd.name.toString());
    Name setterName_ = job.builderType.toName(setterName);
    for (JavacNode child : job.builderType.down()) {
        if (child.getKind() != Kind.METHOD)
            continue;
        JCMethodDecl methodDecl = (JCMethodDecl) child.get();
        Name existingName = methodDecl.name;
        if (existingName.equals(setterName_) && !isTolerate(fieldNode, methodDecl))
            return;
    }
    JavacTreeMaker maker = fieldNode.getTreeMaker();
    List<JCAnnotation> methodAnns = JavacHandlerUtil.findCopyableToSetterAnnotations(bfd.originalFieldNode);
    JCMethodDecl newMethod = HandleSetter.createSetter(toJavacModifier(job.accessInners), deprecate, fieldNode, maker, setterName, bfd.name, bfd.nameOfSetFlag, job.oldChain, job.sourceNode, methodAnns, bfd.annotations);
    recursiveSetGeneratedBy(newMethod, job.sourceNode);
    if (job.sourceNode.up().getKind() == Kind.METHOD) {
        copyJavadocFromParam(bfd.originalFieldNode.up(), newMethod, bfd.name.toString());
    } else {
        copyJavadoc(bfd.originalFieldNode, newMethod, CopyJavadoc.SETTER, true);
    }
    injectMethod(job.builderType, newMethod);
}
Also used : JCMethodDecl(com.sun.tools.javac.tree.JCTree.JCMethodDecl) JavacTreeMaker(lombok.javac.JavacTreeMaker) JavacNode(lombok.javac.JavacNode) ToString(lombok.ToString) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) Name(com.sun.tools.javac.util.Name)

Example 78 with JavacTreeMaker

use of lombok.javac.JavacTreeMaker in project lombok by rzwitserloot.

the class HandleLog method selfType.

public static JCFieldAccess selfType(JavacNode typeNode) {
    JavacTreeMaker maker = typeNode.getTreeMaker();
    Name name = ((JCClassDecl) typeNode.get()).name;
    return maker.Select(maker.Ident(name), typeNode.toName("class"));
}
Also used : JCClassDecl(com.sun.tools.javac.tree.JCTree.JCClassDecl) JavacTreeMaker(lombok.javac.JavacTreeMaker) IdentifierName(lombok.core.configuration.IdentifierName) Name(com.sun.tools.javac.util.Name)

Example 79 with JavacTreeMaker

use of lombok.javac.JavacTreeMaker in project lombok by rzwitserloot.

the class JavacHandlerUtil method copyTypeParams.

public static List<JCTypeParameter> copyTypeParams(JavacNode source, List<JCTypeParameter> params) {
    if (params == null || params.isEmpty())
        return params;
    ListBuffer<JCTypeParameter> out = new ListBuffer<JCTypeParameter>();
    JavacTreeMaker maker = source.getTreeMaker();
    for (JCTypeParameter tp : params) {
        List<JCExpression> bounds = tp.bounds;
        if (bounds != null && !bounds.isEmpty()) {
            ListBuffer<JCExpression> boundsCopy = new ListBuffer<JCExpression>();
            for (JCExpression expr : tp.bounds) {
                boundsCopy.append(cloneType(maker, expr, source));
            }
            bounds = boundsCopy.toList();
        }
        out.append(maker.TypeParameter(tp.name, bounds));
    }
    return out.toList();
}
Also used : JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) JavacTreeMaker(lombok.javac.JavacTreeMaker) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) ListBuffer(com.sun.tools.javac.util.ListBuffer)

Example 80 with JavacTreeMaker

use of lombok.javac.JavacTreeMaker in project lombok by rzwitserloot.

the class HandleSuperBuilder method generateAbstractBuildMethod.

private JCMethodDecl generateAbstractBuildMethod(SuperBuilderJob job, boolean override, String classGenericName) {
    JavacTreeMaker maker = job.getTreeMaker();
    List<JCAnnotation> annotations = List.nil();
    if (override) {
        JCAnnotation overrideAnnotation = maker.Annotation(genJavaLangTypeRef(job.builderType, "Override"), List.<JCExpression>nil());
        annotations = List.of(overrideAnnotation);
    }
    if (job.checkerFramework.generateSideEffectFree())
        annotations = annotations.prepend(maker.Annotation(genTypeRef(job.builderType, CheckerFrameworkVersion.NAME__SIDE_EFFECT_FREE), List.<JCExpression>nil()));
    JCModifiers modifiers = maker.Modifiers(Flags.PUBLIC | Flags.ABSTRACT, annotations);
    Name name = job.toName(job.buildMethodName);
    JCExpression returnType = maker.Ident(job.toName(classGenericName));
    JCVariableDecl recv = HandleBuilder.generateReceiver(job);
    JCMethodDecl methodDef;
    if (recv != null && maker.hasMethodDefWithRecvParam()) {
        methodDef = maker.MethodDefWithRecvParam(modifiers, name, returnType, List.<JCTypeParameter>nil(), recv, List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null);
    } else {
        methodDef = maker.MethodDef(modifiers, name, returnType, List.<JCTypeParameter>nil(), List.<JCVariableDecl>nil(), List.<JCExpression>nil(), null, null);
    }
    return methodDef;
}
Also used : JCTypeParameter(com.sun.tools.javac.tree.JCTree.JCTypeParameter) JavacTreeMaker(lombok.javac.JavacTreeMaker) JCExpression(com.sun.tools.javac.tree.JCTree.JCExpression) JCMethodDecl(com.sun.tools.javac.tree.JCTree.JCMethodDecl) JCModifiers(com.sun.tools.javac.tree.JCTree.JCModifiers) JCAnnotation(com.sun.tools.javac.tree.JCTree.JCAnnotation) JCVariableDecl(com.sun.tools.javac.tree.JCTree.JCVariableDecl) Name(com.sun.tools.javac.util.Name)

Aggregations

JavacTreeMaker (lombok.javac.JavacTreeMaker)94 JCExpression (com.sun.tools.javac.tree.JCTree.JCExpression)70 JCVariableDecl (com.sun.tools.javac.tree.JCTree.JCVariableDecl)43 Name (com.sun.tools.javac.util.Name)42 JCBlock (com.sun.tools.javac.tree.JCTree.JCBlock)34 JCStatement (com.sun.tools.javac.tree.JCTree.JCStatement)34 ListBuffer (com.sun.tools.javac.util.ListBuffer)34 JCAnnotation (com.sun.tools.javac.tree.JCTree.JCAnnotation)33 JCModifiers (com.sun.tools.javac.tree.JCTree.JCModifiers)30 JavacNode (lombok.javac.JavacNode)29 JCTypeParameter (com.sun.tools.javac.tree.JCTree.JCTypeParameter)26 JCMethodDecl (com.sun.tools.javac.tree.JCTree.JCMethodDecl)23 JCClassDecl (com.sun.tools.javac.tree.JCTree.JCClassDecl)18 JCFieldAccess (com.sun.tools.javac.tree.JCTree.JCFieldAccess)12 JCMethodInvocation (com.sun.tools.javac.tree.JCTree.JCMethodInvocation)12 ArrayList (java.util.ArrayList)12 JCPrimitiveTypeTree (com.sun.tools.javac.tree.JCTree.JCPrimitiveTypeTree)10 JCArrayTypeTree (com.sun.tools.javac.tree.JCTree.JCArrayTypeTree)9 JCTypeApply (com.sun.tools.javac.tree.JCTree.JCTypeApply)9 ToString (lombok.ToString)9