aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers
diff options
context:
space:
mode:
authorReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-01-07 22:31:43 +0100
committerReinier Zwitserloot <r.zwitserloot@projectlombok.org>2020-01-07 22:31:43 +0100
commit3f620e3b84dbb8d6625b4c13ca8ee9fd0aa5777c (patch)
tree4c06e0d16ba4d5e0fc2133b6bc9ed5dca8a63e49 /src/core/lombok/eclipse/handlers
parent889c935ec9f0e45bba1e88b0f256e1f29a734f39 (diff)
downloadlombok-3f620e3b84dbb8d6625b4c13ca8ee9fd0aa5777c.tar.gz
lombok-3f620e3b84dbb8d6625b4c13ca8ee9fd0aa5777c.tar.bz2
lombok-3f620e3b84dbb8d6625b4c13ca8ee9fd0aa5777c.zip
[fixes #2327] mostly trivial: Added this. for field access and unified code gen of build() methods for `@Builder`.
Diffstat (limited to 'src/core/lombok/eclipse/handlers')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java2
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java6
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleBuilder.java27
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleConstructor.java2
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleSuperBuilder.java2
5 files changed, 28 insertions, 11 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index 1c988d31..948902d5 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2009-2019 The Project Lombok Authors.
+ * Copyright (C) 2009-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
index cb2ebe18..9d79d75c 100755
--- a/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
+++ b/src/core/lombok/eclipse/handlers/EclipseSingularsRecipes.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2015-2019 The Project Lombok Authors.
+ * Copyright (C) 2015-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -273,6 +273,10 @@ public class EclipseSingularsRecipes {
public abstract void appendBuildCode(SingularData data, EclipseNode builderType, List<Statement> statements, char[] targetVariableName, String builderVariable);
+ public boolean shadowedDuringBuild() {
+ return true;
+ }
+
public boolean requiresCleaning() {
try {
return !getClass().getMethod("appendCleaningCode", SingularData.class, EclipseNode.class, List.class).getDeclaringClass().equals(EclipseSingularizer.class);
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index 6cc5bd57..3f711a19 100755
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2019 The Project Lombok Authors.
+ * Copyright (C) 2013-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -40,7 +40,6 @@ import org.eclipse.jdt.internal.compiler.ast.Argument;
import org.eclipse.jdt.internal.compiler.ast.ArrayInitializer;
import org.eclipse.jdt.internal.compiler.ast.Assignment;
import org.eclipse.jdt.internal.compiler.ast.CompilationUnitDeclaration;
-import org.eclipse.jdt.internal.compiler.ast.ConditionalExpression;
import org.eclipse.jdt.internal.compiler.ast.ConstructorDeclaration;
import org.eclipse.jdt.internal.compiler.ast.EqualExpression;
import org.eclipse.jdt.internal.compiler.ast.Expression;
@@ -713,6 +712,13 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
List<Expression> args = new ArrayList<Expression>();
for (BuilderFieldData bfd : builderFields) {
if (bfd.nameOfSetFlag != null) {
+ LocalDeclaration ld = new LocalDeclaration(bfd.builderFieldName, 0, 0);
+ ld.type = copyType(bfd.type);
+ FieldReference builderAssign = new FieldReference(bfd.builderFieldName, 0);
+ builderAssign.receiver = new ThisReference(0, 0);
+ ld.initialization = builderAssign;
+ statements.add(ld);
+
MessageSend inv = new MessageSend();
inv.sourceStart = source.sourceStart;
inv.sourceEnd = source.sourceEnd;
@@ -720,12 +726,19 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
inv.selector = bfd.nameOfDefaultProvider;
inv.typeArguments = typeParameterNames(((TypeDeclaration) type.get()).typeParameters);
- args.add(new ConditionalExpression(
- new SingleNameReference(bfd.nameOfSetFlag, 0L),
- new SingleNameReference(bfd.builderFieldName, 0L),
- inv));
- } else {
+ Assignment defaultAssign = new Assignment(new SingleNameReference(bfd.builderFieldName, 0L), inv, 0);
+ FieldReference thisSet = new FieldReference(bfd.nameOfSetFlag, 0L);
+ thisSet.receiver = new ThisReference(0, 0);
+ Expression thisNotSet = new UnaryExpression(thisSet, OperatorIds.NOT);
+ statements.add(new IfStatement(thisNotSet, defaultAssign, 0, 0));
+ }
+
+ if (bfd.nameOfSetFlag != null || (bfd.singularData != null && bfd.singularData.getSingularizer().shadowedDuringBuild())) {
args.add(new SingleNameReference(bfd.builderFieldName, 0L));
+ } else {
+ FieldReference fr = new FieldReference(bfd.builderFieldName, 0L);
+ fr.receiver = new ThisReference(0, 0);
+ args.add(fr);
}
}
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java
index 7cb2036b..a5716d9c 100755
--- a/src/core/lombok/eclipse/handlers/HandleConstructor.java
+++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010-2019 The Project Lombok Authors.
+ * Copyright (C) 2010-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
diff --git a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
index fbd4ce24..3a2e59f7 100755
--- a/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleSuperBuilder.java
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013-2019 The Project Lombok Authors.
+ * Copyright (C) 2013-2020 The Project Lombok Authors.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal