Search in sources :

Example 56 with ThisReference

use of org.eclipse.jdt.internal.compiler.ast.ThisReference in project lombok by rzwitserloot.

the class EclipseGuavaSingularizer method generatePluralMethod.

void generatePluralMethod(CheckerFrameworkVersion cfv, boolean deprecate, TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent, AccessLevel access) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = toEclipseModifier(access);
    List<Statement> statements = new ArrayList<Statement>();
    statements.add(createConstructBuilderVarIfNeeded(data, builderType));
    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    MessageSend thisDotFieldDotAddAll = new MessageSend();
    thisDotFieldDotAddAll.arguments = new Expression[] { new SingleNameReference(data.getPluralName(), 0L) };
    thisDotFieldDotAddAll.receiver = thisDotField;
    thisDotFieldDotAddAll.selector = (getAddMethodName() + "All").toCharArray();
    statements.add(thisDotFieldDotAddAll);
    TypeReference paramType;
    paramType = new QualifiedTypeReference(fromQualifiedName(getAddAllTypeName()), NULL_POSS);
    paramType = addTypeArgs(getTypeArgumentsCount(), true, builderType, paramType, data.getTypeArgs());
    Argument param = new Argument(data.getPluralName(), 0, paramType, ClassFileConstants.AccFinal);
    nullBehaviorize(builderType, data, statements, param);
    if (returnStatement != null)
        statements.add(returnStatement);
    md.statements = statements.toArray(new Statement[0]);
    md.arguments = new Argument[] { param };
    md.returnType = returnType;
    addCheckerFrameworkReturnsReceiver(md.returnType, data.getSource(), cfv);
    char[] prefixedSelector = data.getSetterPrefix().length == 0 ? data.getPluralName() : HandlerUtil.buildAccessorName(builderType, new String(data.getSetterPrefix()), new String(data.getPluralName())).toCharArray();
    md.selector = fluent ? prefixedSelector : HandlerUtil.buildAccessorName(builderType, "addAll", new String(data.getPluralName())).toCharArray();
    Annotation[] selfReturnAnnotations = generateSelfReturnAnnotations(deprecate, data.getSource());
    Annotation[] copyToSetterAnnotations = copyAnnotations(md, findCopyableToSetterAnnotations(data.getAnnotation().up()));
    md.annotations = concat(selfReturnAnnotations, copyToSetterAnnotations, Annotation.class);
    if (returnStatement != null)
        createRelevantNonNullAnnotation(builderType, md);
    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
Also used : FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) Argument(org.eclipse.jdt.internal.compiler.ast.Argument) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ArrayList(java.util.ArrayList) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) SingleNameReference(org.eclipse.jdt.internal.compiler.ast.SingleNameReference) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation) MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)

Aggregations

ThisReference (org.eclipse.jdt.internal.compiler.ast.ThisReference)56 MethodDeclaration (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)44 Statement (org.eclipse.jdt.internal.compiler.ast.Statement)43 FieldReference (org.eclipse.jdt.internal.compiler.ast.FieldReference)38 IfStatement (org.eclipse.jdt.internal.compiler.ast.IfStatement)38 MessageSend (org.eclipse.jdt.internal.compiler.ast.MessageSend)37 ReturnStatement (org.eclipse.jdt.internal.compiler.ast.ReturnStatement)37 ArrayList (java.util.ArrayList)31 SingleNameReference (org.eclipse.jdt.internal.compiler.ast.SingleNameReference)31 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)27 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)26 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)26 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)22 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)21 EqualExpression (org.eclipse.jdt.internal.compiler.ast.EqualExpression)20 Assignment (org.eclipse.jdt.internal.compiler.ast.Assignment)16 NullLiteral (org.eclipse.jdt.internal.compiler.ast.NullLiteral)16 AbstractMethodDeclaration (org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration)15 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)15 EclipseNode (lombok.eclipse.EclipseNode)13