mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-13 10:15:53 +00:00
[fixes #1836] superbuilder didn’t play ball with field prefixes, at least in javac.
This commit is contained in:
1 parent
572222c54b
commit
ef90e2ec2d
10 files changed
+176
-10
No files matched your search
@@ -24,7 +24,6 @@ package lombok.eclipse.handlers;
|
||||
import static lombok.core.handlers.HandlerUtil.*;
|
||||
import static lombok.eclipse.Eclipse.*;
|
||||
import static lombok.eclipse.EclipseAugments.*;
|
||||
import static lombok.eclipse.handlers.EclipseHandlerUtil.setGeneratedBy;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
@@ -48,7 +48,6 @@ import org.eclipse.jdt.internal.compiler.ast.FieldReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.IfStatement;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MessageSend;
|
||||
import org.eclipse.jdt.internal.compiler.ast.MethodDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.OperatorIds;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ParameterizedQualifiedTypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.ParameterizedSingleTypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.QualifiedNameReference;
|
||||
@@ -61,7 +60,6 @@ import org.eclipse.jdt.internal.compiler.ast.ThisReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeDeclaration;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeParameter;
|
||||
import org.eclipse.jdt.internal.compiler.ast.TypeReference;
|
||||
import org.eclipse.jdt.internal.compiler.ast.UnaryExpression;
|
||||
import org.eclipse.jdt.internal.compiler.ast.Wildcard;
|
||||
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
|
||||
import org.eclipse.jdt.internal.compiler.lookup.ClassScope;
|
||||
|
||||
@@ -415,7 +415,7 @@ public class HandleSuperBuilder extends JavacAnnotationHandler<SuperBuilder> {
|
||||
bfd.singularData.getSingularizer().appendBuildCode(bfd.singularData, bfd.originalFieldNode, bfd.type, statements, bfd.name, "b");
|
||||
rhs = maker.Ident(bfd.singularData.getPluralName());
|
||||
} else {
|
||||
rhs = maker.Select(maker.Ident(builderVariableName), bfd.rawName);
|
||||
rhs = maker.Select(maker.Ident(builderVariableName), bfd.name);
|
||||
}
|
||||
JCFieldAccess fieldInThis = maker.Select(maker.Ident(typeNode.toName("this")), bfd.rawName);
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class SuperBuilderWithCustomBuilderMethod {
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected ParentBuilderImpl self() {
|
||||
protected ParentBuilderImpl<A> self() {
|
||||
return this;
|
||||
}
|
||||
@java.lang.Override
|
||||
@@ -111,7 +111,7 @@ public class SuperBuilderWithCustomBuilderMethod {
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected ChildBuilderImpl self() {
|
||||
protected ChildBuilderImpl<A> self() {
|
||||
return this;
|
||||
}
|
||||
@java.lang.Override
|
||||
|
||||
@@ -50,7 +50,7 @@ public class SuperBuilderWithDefaults {
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected ParentBuilderImpl self() {
|
||||
protected ParentBuilderImpl<N> self() {
|
||||
return this;
|
||||
}
|
||||
@java.lang.Override
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
class SuperBuilderWithPrefixes {
|
||||
int mField;
|
||||
int xOtherField;
|
||||
java.util.List<String> mItems;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public static abstract class SuperBuilderWithPrefixesBuilder<C extends SuperBuilderWithPrefixes, B extends SuperBuilderWithPrefixesBuilder<C, B>> {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private int field;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private int otherField;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private java.util.ArrayList<String> items;
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected abstract B self();
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public abstract C build();
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public B field(final int field) {
|
||||
this.field = field;
|
||||
return self();
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public B otherField(final int otherField) {
|
||||
this.otherField = otherField;
|
||||
return self();
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public B item(final String item) {
|
||||
if (this.items == null) this.items = new java.util.ArrayList<String>();
|
||||
this.items.add(item);
|
||||
return self();
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public B items(final java.util.Collection<? extends String> items) {
|
||||
if (this.items == null) this.items = new java.util.ArrayList<String>();
|
||||
this.items.addAll(items);
|
||||
return self();
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public B clearItems() {
|
||||
if (this.items != null) this.items.clear();
|
||||
return self();
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public java.lang.String toString() {
|
||||
return "SuperBuilderWithPrefixes.SuperBuilderWithPrefixesBuilder(field=" + this.field + ", otherField=" + this.otherField + ", items=" + this.items + ")";
|
||||
}
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private static final class SuperBuilderWithPrefixesBuilderImpl extends SuperBuilderWithPrefixesBuilder<SuperBuilderWithPrefixes, SuperBuilderWithPrefixesBuilderImpl> {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
private SuperBuilderWithPrefixesBuilderImpl() {
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected SuperBuilderWithPrefixesBuilderImpl self() {
|
||||
return this;
|
||||
}
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public SuperBuilderWithPrefixes build() {
|
||||
return new SuperBuilderWithPrefixes(this);
|
||||
}
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
protected SuperBuilderWithPrefixes(final SuperBuilderWithPrefixesBuilder<?, ?> b) {
|
||||
this.mField = b.field;
|
||||
this.xOtherField = b.otherField;
|
||||
java.util.List<String> items;
|
||||
switch (b.items == null ? 0 : b.items.size()) {
|
||||
case 0:
|
||||
items = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1:
|
||||
items = java.util.Collections.singletonList(b.items.get(0));
|
||||
break;
|
||||
default:
|
||||
items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
|
||||
}
|
||||
this.mItems = items;
|
||||
}
|
||||
@java.lang.SuppressWarnings("all")
|
||||
public static SuperBuilderWithPrefixesBuilder<?, ?> builder() {
|
||||
return new SuperBuilderWithPrefixesBuilderImpl();
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ public class SuperBuilderWithCustomBuilderMethod {
|
||||
private ParentBuilderImpl() {
|
||||
super();
|
||||
}
|
||||
protected @java.lang.Override @java.lang.SuppressWarnings("all") ParentBuilderImpl self() {
|
||||
protected @java.lang.Override @java.lang.SuppressWarnings("all") ParentBuilderImpl<A> self() {
|
||||
return this;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") Parent<A> build() {
|
||||
@@ -87,7 +87,7 @@ public class SuperBuilderWithCustomBuilderMethod {
|
||||
private ChildBuilderImpl() {
|
||||
super();
|
||||
}
|
||||
protected @java.lang.Override @java.lang.SuppressWarnings("all") ChildBuilderImpl self() {
|
||||
protected @java.lang.Override @java.lang.SuppressWarnings("all") ChildBuilderImpl<A> self() {
|
||||
return this;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") Child<A> build() {
|
||||
|
||||
@@ -29,7 +29,7 @@ public class SuperBuilderWithDefaults {
|
||||
private ParentBuilderImpl() {
|
||||
super();
|
||||
}
|
||||
protected @java.lang.Override @java.lang.SuppressWarnings("all") ParentBuilderImpl self() {
|
||||
protected @java.lang.Override @java.lang.SuppressWarnings("all") ParentBuilderImpl<N> self() {
|
||||
return this;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") Parent<N> build() {
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
@lombok.experimental.SuperBuilder class SuperBuilderWithPrefixes {
|
||||
public static abstract @java.lang.SuppressWarnings("all") class SuperBuilderWithPrefixesBuilder<C extends SuperBuilderWithPrefixes, B extends SuperBuilderWithPrefixesBuilder<C, B>> {
|
||||
private @java.lang.SuppressWarnings("all") int field;
|
||||
private @java.lang.SuppressWarnings("all") int otherField;
|
||||
private @java.lang.SuppressWarnings("all") java.util.ArrayList<String> items;
|
||||
public SuperBuilderWithPrefixesBuilder() {
|
||||
super();
|
||||
}
|
||||
protected abstract @java.lang.SuppressWarnings("all") B self();
|
||||
public abstract @java.lang.SuppressWarnings("all") C build();
|
||||
public @java.lang.SuppressWarnings("all") B field(final int field) {
|
||||
this.field = field;
|
||||
return self();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") B otherField(final int otherField) {
|
||||
this.otherField = otherField;
|
||||
return self();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") B item(String item) {
|
||||
if ((this.items == null))
|
||||
this.items = new java.util.ArrayList<String>();
|
||||
this.items.add(item);
|
||||
return self();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") B items(java.util.Collection<? extends String> items) {
|
||||
if ((this.items == null))
|
||||
this.items = new java.util.ArrayList<String>();
|
||||
this.items.addAll(items);
|
||||
return self();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") B clearItems() {
|
||||
if ((this.items != null))
|
||||
this.items.clear();
|
||||
return self();
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
|
||||
return (((((("SuperBuilderWithPrefixes.SuperBuilderWithPrefixesBuilder(field=" + this.field) + ", otherField=") + this.otherField) + ", items=") + this.items) + ")");
|
||||
}
|
||||
}
|
||||
private static final @java.lang.SuppressWarnings("all") class SuperBuilderWithPrefixesBuilderImpl extends SuperBuilderWithPrefixesBuilder<SuperBuilderWithPrefixes, SuperBuilderWithPrefixesBuilderImpl> {
|
||||
private SuperBuilderWithPrefixesBuilderImpl() {
|
||||
super();
|
||||
}
|
||||
protected @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithPrefixesBuilderImpl self() {
|
||||
return this;
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") SuperBuilderWithPrefixes build() {
|
||||
return new SuperBuilderWithPrefixes(this);
|
||||
}
|
||||
}
|
||||
int mField;
|
||||
int xOtherField;
|
||||
@lombok.Singular java.util.List<String> mItems;
|
||||
protected @java.lang.SuppressWarnings("all") SuperBuilderWithPrefixes(final SuperBuilderWithPrefixesBuilder<?, ?> b) {
|
||||
super();
|
||||
this.mField = b.field;
|
||||
this.xOtherField = b.otherField;
|
||||
java.util.List<String> items;
|
||||
switch (((b.items == null) ? 0 : b.items.size())) {
|
||||
case 0 :
|
||||
items = java.util.Collections.emptyList();
|
||||
break;
|
||||
case 1 :
|
||||
items = java.util.Collections.singletonList(b.items.get(0));
|
||||
break;
|
||||
default :
|
||||
items = java.util.Collections.unmodifiableList(new java.util.ArrayList<String>(b.items));
|
||||
}
|
||||
this.mItems = items;
|
||||
}
|
||||
public static @java.lang.SuppressWarnings("all") SuperBuilderWithPrefixesBuilder<?, ?> builder() {
|
||||
return new SuperBuilderWithPrefixesBuilderImpl();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
//CONF: lombok.accessors.prefix += m
|
||||
//CONF: lombok.accessors.prefix += x
|
||||
@lombok.experimental.SuperBuilder
|
||||
class SuperBuilderWithPrefixes {
|
||||
int mField;
|
||||
int xOtherField;
|
||||
@lombok.Singular java.util.List<String> mItems;
|
||||
}
|
||||
Reference in new issue
Block a user