Search in sources :

Example 16 with Statement

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

the class EclipseJavaUtilListSetSingularizer method generateClearMethod.

private void generateClearMethod(boolean deprecate, TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;
    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    FieldReference thisDotField2 = new FieldReference(data.getPluralName(), 0L);
    thisDotField2.receiver = new ThisReference(0, 0);
    md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
    MessageSend clearMsg = new MessageSend();
    clearMsg.receiver = thisDotField2;
    clearMsg.selector = "clear".toCharArray();
    Statement clearStatement = new IfStatement(new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL), clearMsg, 0, 0);
    md.statements = returnStatement != null ? new Statement[] { clearStatement, returnStatement } : new Statement[] { clearStatement };
    md.returnType = returnType;
    md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
    injectMethod(builderType, md);
}
Also used : MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) EqualExpression(org.eclipse.jdt.internal.compiler.ast.EqualExpression) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) NullLiteral(org.eclipse.jdt.internal.compiler.ast.NullLiteral) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation)

Example 17 with Statement

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

the class EclipseJavaUtilListSetSingularizer method generatePluralMethod.

void generatePluralMethod(boolean deprecate, TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;
    List<Statement> statements = new ArrayList<Statement>();
    statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));
    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 = "addAll".toCharArray();
    statements.add(thisDotFieldDotAddAll);
    if (returnStatement != null)
        statements.add(returnStatement);
    md.statements = statements.toArray(new Statement[statements.size()]);
    TypeReference paramType = new QualifiedTypeReference(TypeConstants.JAVA_UTIL_COLLECTION, NULL_POSS);
    paramType = addTypeArgs(1, true, builderType, paramType, data.getTypeArgs());
    Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
    md.arguments = new Argument[] { param };
    md.returnType = returnType;
    md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("addAll", new String(data.getPluralName())).toCharArray();
    md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
    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) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) 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)

Example 18 with Statement

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

the class EclipseJavaUtilListSetSingularizer method generateSingularMethod.

void generateSingularMethod(boolean deprecate, TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;
    List<Statement> statements = new ArrayList<Statement>();
    statements.add(createConstructBuilderVarIfNeeded(data, builderType, false));
    FieldReference thisDotField = new FieldReference(data.getPluralName(), 0L);
    thisDotField.receiver = new ThisReference(0, 0);
    MessageSend thisDotFieldDotAdd = new MessageSend();
    thisDotFieldDotAdd.arguments = new Expression[] { new SingleNameReference(data.getSingularName(), 0L) };
    thisDotFieldDotAdd.receiver = thisDotField;
    thisDotFieldDotAdd.selector = "add".toCharArray();
    statements.add(thisDotFieldDotAdd);
    if (returnStatement != null)
        statements.add(returnStatement);
    md.statements = statements.toArray(new Statement[statements.size()]);
    TypeReference paramType = cloneParamType(0, data.getTypeArgs(), builderType);
    Argument param = new Argument(data.getSingularName(), 0, paramType, 0);
    md.arguments = new Argument[] { param };
    md.returnType = returnType;
    md.selector = fluent ? data.getSingularName() : HandlerUtil.buildAccessorName("add", new String(data.getSingularName())).toCharArray();
    md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
Also used : MessageSend(org.eclipse.jdt.internal.compiler.ast.MessageSend) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) Argument(org.eclipse.jdt.internal.compiler.ast.Argument) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ArrayList(java.util.ArrayList) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference) SingleNameReference(org.eclipse.jdt.internal.compiler.ast.SingleNameReference) Annotation(org.eclipse.jdt.internal.compiler.ast.Annotation)

Example 19 with Statement

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

the class EclipseJavaUtilMapSingularizer method generatePluralMethod.

private void generatePluralMethod(boolean deprecate, TypeReference returnType, Statement returnStatement, SingularData data, EclipseNode builderType, boolean fluent) {
    MethodDeclaration md = new MethodDeclaration(((CompilationUnitDeclaration) builderType.top().get()).compilationResult);
    md.bits |= ECLIPSE_DO_NOT_TOUCH_FLAG;
    md.modifiers = ClassFileConstants.AccPublic;
    String pN = new String(data.getPluralName());
    char[] keyFieldName = (pN + "$key").toCharArray();
    char[] valueFieldName = (pN + "$value").toCharArray();
    List<Statement> statements = new ArrayList<Statement>();
    statements.add(createConstructBuilderVarIfNeeded(data, builderType, true));
    char[] entryName = "$lombokEntry".toCharArray();
    TypeReference forEachType = new QualifiedTypeReference(JAVA_UTIL_MAP_ENTRY, NULL_POSS);
    forEachType = addTypeArgs(2, true, builderType, forEachType, data.getTypeArgs());
    MessageSend keyArg = new MessageSend();
    keyArg.receiver = new SingleNameReference(entryName, 0L);
    keyArg.selector = "getKey".toCharArray();
    MessageSend addKey = new MessageSend();
    FieldReference thisDotKeyField = new FieldReference(keyFieldName, 0L);
    thisDotKeyField.receiver = new ThisReference(0, 0);
    addKey.receiver = thisDotKeyField;
    addKey.selector = new char[] { 'a', 'd', 'd' };
    addKey.arguments = new Expression[] { keyArg };
    MessageSend valueArg = new MessageSend();
    valueArg.receiver = new SingleNameReference(entryName, 0L);
    valueArg.selector = "getValue".toCharArray();
    MessageSend addValue = new MessageSend();
    FieldReference thisDotValueField = new FieldReference(valueFieldName, 0L);
    thisDotValueField.receiver = new ThisReference(0, 0);
    addValue.receiver = thisDotValueField;
    addValue.selector = new char[] { 'a', 'd', 'd' };
    addValue.arguments = new Expression[] { valueArg };
    LocalDeclaration elementVariable = new LocalDeclaration(entryName, 0, 0);
    elementVariable.type = forEachType;
    ForeachStatement forEach = new ForeachStatement(elementVariable, 0);
    MessageSend invokeEntrySet = new MessageSend();
    invokeEntrySet.selector = new char[] { 'e', 'n', 't', 'r', 'y', 'S', 'e', 't' };
    invokeEntrySet.receiver = new SingleNameReference(data.getPluralName(), 0L);
    forEach.collection = invokeEntrySet;
    Block forEachContent = new Block(0);
    forEachContent.statements = new Statement[] { addKey, addValue };
    forEach.action = forEachContent;
    statements.add(forEach);
    if (returnStatement != null)
        statements.add(returnStatement);
    md.statements = statements.toArray(new Statement[statements.size()]);
    TypeReference paramType = new QualifiedTypeReference(JAVA_UTIL_MAP, NULL_POSS);
    paramType = addTypeArgs(2, true, builderType, paramType, data.getTypeArgs());
    Argument param = new Argument(data.getPluralName(), 0, paramType, 0);
    md.arguments = new Argument[] { param };
    md.returnType = returnType;
    md.selector = fluent ? data.getPluralName() : HandlerUtil.buildAccessorName("putAll", new String(data.getPluralName())).toCharArray();
    md.annotations = deprecate ? new Annotation[] { generateDeprecatedAnnotation(data.getSource()) } : null;
    data.setGeneratedByRecursive(md);
    injectMethod(builderType, md);
}
Also used : LocalDeclaration(org.eclipse.jdt.internal.compiler.ast.LocalDeclaration) FieldReference(org.eclipse.jdt.internal.compiler.ast.FieldReference) Argument(org.eclipse.jdt.internal.compiler.ast.Argument) MethodDeclaration(org.eclipse.jdt.internal.compiler.ast.MethodDeclaration) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ForeachStatement(org.eclipse.jdt.internal.compiler.ast.ForeachStatement) 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) Block(org.eclipse.jdt.internal.compiler.ast.Block) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ForeachStatement(org.eclipse.jdt.internal.compiler.ast.ForeachStatement)

Example 20 with Statement

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

the class EclipseJavaUtilMapSingularizer method generateMethods.

@Override
public void generateMethods(SingularData data, boolean deprecate, EclipseNode builderType, boolean fluent, boolean chain) {
    if (useGuavaInstead(builderType)) {
        guavaMapSingularizer.generateMethods(data, deprecate, builderType, fluent, chain);
        return;
    }
    TypeReference returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    Statement returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateSingularMethod(deprecate, returnType, returnStatement, data, builderType, fluent);
    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generatePluralMethod(deprecate, returnType, returnStatement, data, builderType, fluent);
    returnType = chain ? cloneSelfType(builderType) : TypeReference.baseTypeReference(TypeIds.T_void, 0);
    returnStatement = chain ? new ReturnStatement(new ThisReference(0, 0), 0, 0) : null;
    generateClearMethod(deprecate, returnType, returnStatement, data, builderType);
}
Also used : ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) Statement(org.eclipse.jdt.internal.compiler.ast.Statement) IfStatement(org.eclipse.jdt.internal.compiler.ast.IfStatement) ForeachStatement(org.eclipse.jdt.internal.compiler.ast.ForeachStatement) ReturnStatement(org.eclipse.jdt.internal.compiler.ast.ReturnStatement) TypeReference(org.eclipse.jdt.internal.compiler.ast.TypeReference) QualifiedTypeReference(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference) ThisReference(org.eclipse.jdt.internal.compiler.ast.ThisReference)

Aggregations

Statement (org.eclipse.jdt.internal.compiler.ast.Statement)38 IfStatement (org.eclipse.jdt.internal.compiler.ast.IfStatement)27 ReturnStatement (org.eclipse.jdt.internal.compiler.ast.ReturnStatement)27 ThisReference (org.eclipse.jdt.internal.compiler.ast.ThisReference)27 MethodDeclaration (org.eclipse.jdt.internal.compiler.ast.MethodDeclaration)23 MessageSend (org.eclipse.jdt.internal.compiler.ast.MessageSend)21 SingleNameReference (org.eclipse.jdt.internal.compiler.ast.SingleNameReference)21 FieldReference (org.eclipse.jdt.internal.compiler.ast.FieldReference)19 TypeReference (org.eclipse.jdt.internal.compiler.ast.TypeReference)19 QualifiedTypeReference (org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference)18 ArrayList (java.util.ArrayList)17 Argument (org.eclipse.jdt.internal.compiler.ast.Argument)15 Expression (org.eclipse.jdt.internal.compiler.ast.Expression)15 Annotation (org.eclipse.jdt.internal.compiler.ast.Annotation)14 EqualExpression (org.eclipse.jdt.internal.compiler.ast.EqualExpression)14 Assignment (org.eclipse.jdt.internal.compiler.ast.Assignment)12 NullLiteral (org.eclipse.jdt.internal.compiler.ast.NullLiteral)12 AllocationExpression (org.eclipse.jdt.internal.compiler.ast.AllocationExpression)10 ConditionalExpression (org.eclipse.jdt.internal.compiler.ast.ConditionalExpression)9 LocalDeclaration (org.eclipse.jdt.internal.compiler.ast.LocalDeclaration)9