use of org.eclipse.jdt.internal.compiler.ast.EqualExpression in project lombok by rzwitserloot.
the class EclipseJavaUtilListSetSingularizer method generateClearMethod.
private void generateClearMethod(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;
injectMethod(builderType, md);
}
use of org.eclipse.jdt.internal.compiler.ast.EqualExpression in project lombok by rzwitserloot.
the class EclipseJavaUtilMapSingularizer method generateClearMethod.
private void generateClearMethod(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;
String pN = new String(data.getPluralName());
char[] keyFieldName = (pN + "$key").toCharArray();
char[] valueFieldName = (pN + "$value").toCharArray();
FieldReference thisDotField = new FieldReference(keyFieldName, 0L);
thisDotField.receiver = new ThisReference(0, 0);
FieldReference thisDotField2 = new FieldReference(keyFieldName, 0L);
thisDotField2.receiver = new ThisReference(0, 0);
FieldReference thisDotField3 = new FieldReference(valueFieldName, 0L);
thisDotField3.receiver = new ThisReference(0, 0);
md.selector = HandlerUtil.buildAccessorName("clear", new String(data.getPluralName())).toCharArray();
MessageSend clearMsg1 = new MessageSend();
clearMsg1.receiver = thisDotField2;
clearMsg1.selector = "clear".toCharArray();
MessageSend clearMsg2 = new MessageSend();
clearMsg2.receiver = thisDotField3;
clearMsg2.selector = "clear".toCharArray();
Block clearMsgs = new Block(2);
clearMsgs.statements = new Statement[] { clearMsg1, clearMsg2 };
Statement clearStatement = new IfStatement(new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.NOT_EQUAL), clearMsgs, 0, 0);
md.statements = returnStatement != null ? new Statement[] { clearStatement, returnStatement } : new Statement[] { clearStatement };
md.returnType = returnType;
injectMethod(builderType, md);
}
use of org.eclipse.jdt.internal.compiler.ast.EqualExpression in project lombok by rzwitserloot.
the class EclipseJavaUtilSingularizer method createConstructBuilderVarIfNeeded.
protected Statement createConstructBuilderVarIfNeeded(SingularData data, EclipseNode builderType, boolean mapMode) {
char[] v1Name, v2Name;
if (mapMode) {
String n = new String(data.getPluralName());
v1Name = (n + "$key").toCharArray();
v2Name = (n + "$value").toCharArray();
} else {
v1Name = data.getPluralName();
v2Name = null;
}
FieldReference thisDotField = new FieldReference(v1Name, 0L);
thisDotField.receiver = new ThisReference(0, 0);
Expression cond = new EqualExpression(thisDotField, new NullLiteral(0, 0), OperatorIds.EQUAL_EQUAL);
thisDotField = new FieldReference(v1Name, 0L);
thisDotField.receiver = new ThisReference(0, 0);
TypeReference v1Type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
v1Type = addTypeArgs(1, false, builderType, v1Type, data.getTypeArgs());
AllocationExpression constructArrayList = new AllocationExpression();
constructArrayList.type = v1Type;
Assignment initV1 = new Assignment(thisDotField, constructArrayList, 0);
Statement thenPart;
if (mapMode) {
thisDotField = new FieldReference(v2Name, 0L);
thisDotField.receiver = new ThisReference(0, 0);
TypeReference v2Type = new QualifiedTypeReference(JAVA_UTIL_ARRAYLIST, NULL_POSS);
List<TypeReference> tArgs = data.getTypeArgs();
if (tArgs != null && tArgs.size() > 1)
tArgs = Collections.singletonList(tArgs.get(1));
else
tArgs = Collections.emptyList();
v2Type = addTypeArgs(1, false, builderType, v2Type, tArgs);
constructArrayList = new AllocationExpression();
constructArrayList.type = v2Type;
Assignment initV2 = new Assignment(thisDotField, constructArrayList, 0);
Block b = new Block(0);
b.statements = new Statement[] { initV1, initV2 };
thenPart = b;
} else {
thenPart = initV1;
}
return new IfStatement(cond, thenPart, 0, 0);
}
Aggregations