private ListBuffer<JCAnnotation> getAnnotations() { ListBuffer<JCAnnotation> result = ListBuffer.lb(); if (!noAnnotations) { if (!ignoreAnnotations) { result.appendList(this.annotations); } if (isOverride) { result.appendList(gen.makeAtOverride()); } if (ignoreAnnotations) { result.appendList(gen.makeAtIgnore()); } else { if (resultTypeAnnos != null) { result.appendList(resultTypeAnnos); } if (!typeParamAnnotations.isEmpty()) { result.appendList(gen.makeAtTypeParameters(typeParamAnnotations.toList())); } } } else { // only those two are preserved if (isOverride) { result.appendList(gen.makeAtOverride()); } if (ignoreAnnotations) { result.appendList(gen.makeAtIgnore()); } } return result; }
@Override public JCTree visitClassDecl(final lombok.ast.ClassDecl node, final Void p) { final JCModifiers mods = setGeneratedBy( M(node) .Modifiers( flagsFor(node.getModifiers()), build(node.getAnnotations(), JCAnnotation.class)), source); if (node.isInterface()) mods.flags |= Flags.INTERFACE; final ListBuffer<JCTree> defs = ListBuffer.lb(); defs.appendList(build(node.getFields())); defs.appendList(build(node.getMethods())); defs.appendList(build(node.getMemberTypes())); final List<JCTypeParameter> typarams = build(node.getTypeParameters()); final JCExpression extending = build(node.getSuperclass()); final List<JCExpression> implementing = build(node.getSuperInterfaces()); final JCClassDecl classDecl = setGeneratedBy( createClassDef( node, mods, name(node.getName()), typarams, extending, implementing, defs.toList()), source); return classDecl; }
@Override public JCTree visitNewArray(final lombok.ast.NewArray node, final Void p) { final ListBuffer<JCExpression> dims = ListBuffer.lb(); dims.appendList(build(node.getDimensionExpressions(), JCExpression.class)); final JCExpression elemtype = build(node.getType()); final List<JCExpression> initializerExpressions = build(node.getInitializerExpressions(), JCExpression.class); JCNewArray newClass = setGeneratedBy( M(node) .NewArray( elemtype, dims.toList(), initializerExpressions.isEmpty() ? null : initializerExpressions), source); return newClass; }
public MethodDefinitionBuilder parameters(List<ParameterDefinitionBuilder> pdbs) { params.appendList(pdbs); return this; }
private JCTree makeDefaultedCall( int i, boolean isVariadic, java.util.List<ProducedType> parameterTypes) { // collect every parameter int a = 0; ListBuffer<JCStatement> stmts = new ListBuffer<JCStatement>(); for (Parameter param : paramLists.getParameters()) { // don't read default parameter values for forwarded calls if (forwardCallTo != null && i == a) break; // read the value JCExpression paramExpression = getTypedParameter(param, a, i > 3, parameterTypes); JCExpression varInitialExpression; if (param.isDefaulted() || param.isSequenced()) { if (i > 3) { // must check if it's defined JCExpression test = gen.make() .Binary(JCTree.GT, gen.makeSelect(getParamName(0), "length"), gen.makeInteger(a)); JCExpression elseBranch = makeDefaultValueCall(param, a); varInitialExpression = gen.make().Conditional(test, paramExpression, elseBranch); } else if (a >= i) { // get its default value because we don't have it varInitialExpression = makeDefaultValueCall(param, a); } else { // we must have it varInitialExpression = paramExpression; } } else { varInitialExpression = paramExpression; } // store it in a local var JCStatement var = gen.make() .VarDef( gen.make().Modifiers(Flags.FINAL), gen.naming.makeUnquotedName(getCallableTempVarName(param)), gen.makeJavaType( parameterTypes.get(a), CodegenUtil.isUnBoxed(param) ? 0 : gen.JT_NO_PRIMITIVES), varInitialExpression); stmts.append(var); a++; } if (forwardCallTo != null) { InvocationBuilder invocationBuilder = InvocationBuilder.forCallableInvocation(gen, forwardCallTo, paramLists, i); boolean prevCallableInv = gen.expressionGen().withinCallableInvocation(true); try { stmts.append(gen.make().Return(invocationBuilder.build())); } finally { gen.expressionGen().withinCallableInvocation(prevCallableInv); } } else if (isVariadic) { // chain to n param typed method List<JCExpression> args = List.nil(); // pass along the parameters for (a = paramLists.getParameters().size() - 1; a >= 0; a--) { Parameter param = paramLists.getParameters().get(a); args = args.prepend(gen.makeUnquotedIdent(getCallableTempVarName(param))); } JCMethodInvocation chain = gen.make().Apply(null, gen.makeUnquotedIdent(Naming.getCallableTypedMethodName()), args); stmts.append(gen.make().Return(chain)); } else { // insert the method body directly stmts.appendList(this.body); } List<JCStatement> body = stmts.toList(); return makeCallMethod(body, i); }