mirror of
https://github.com/tiennm99/lombok.git
synced 2026-10-11 12:19:00 +00:00
fix of the issue 1230. @Tolerate not working for @Builder methods?
This commit is contained in:
1 parent
4d9da60f4f
commit
105c32f4b6
7 files changed
+135
-17
No files matched your search
@@ -1168,9 +1168,8 @@ public class EclipseHandlerUtil {
|
||||
if (params < minArgs || params > maxArgs) continue;
|
||||
}
|
||||
|
||||
if (def.annotations != null) for (Annotation anno : def.annotations) {
|
||||
if (typeMatches(Tolerate.class, node, anno.type)) continue top;
|
||||
}
|
||||
|
||||
if (isTolerate(node, def)) continue top;
|
||||
|
||||
return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
|
||||
}
|
||||
@@ -1181,6 +1180,13 @@ public class EclipseHandlerUtil {
|
||||
return MemberExistsResult.NOT_EXISTS;
|
||||
}
|
||||
|
||||
public static boolean isTolerate(EclipseNode node, AbstractMethodDeclaration def) {
|
||||
if (def.annotations != null) for (Annotation anno : def.annotations) {
|
||||
if (typeMatches(Tolerate.class, node, anno.type)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
|
||||
* the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
|
||||
@@ -1198,9 +1204,7 @@ public class EclipseHandlerUtil {
|
||||
if (def instanceof ConstructorDeclaration) {
|
||||
if ((def.bits & ASTNode.IsDefaultConstructor) != 0) continue;
|
||||
|
||||
if (def.annotations != null) for (Annotation anno : def.annotations) {
|
||||
if (typeMatches(Tolerate.class, node, anno.type)) continue top;
|
||||
}
|
||||
if (isTolerate(node, def)) continue;
|
||||
|
||||
return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
|
||||
}
|
||||
|
||||
@@ -652,7 +652,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
|
||||
for (int i = 0; i < len; i++) {
|
||||
if (!(existing[i] instanceof MethodDeclaration)) continue;
|
||||
char[] existingName = existing[i].selector;
|
||||
if (Arrays.equals(name, existingName)) return;
|
||||
if (Arrays.equals(name, existingName) && !isTolerate(fieldNode, existing[i])) return;
|
||||
}
|
||||
|
||||
String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
|
||||
|
||||
@@ -608,8 +608,9 @@ public class HandleBuilder extends JavacAnnotationHandler<Builder> {
|
||||
|
||||
for (JavacNode child : builderType.down()) {
|
||||
if (child.getKind() != Kind.METHOD) continue;
|
||||
Name existingName = ((JCMethodDecl) child.get()).name;
|
||||
if (existingName.equals(fieldName)) return;
|
||||
JCMethodDecl methodDecl = (JCMethodDecl) child.get();
|
||||
Name existingName = methodDecl.name;
|
||||
if (existingName.equals(fieldName) && !isTolerate(fieldNode, methodDecl)) return;
|
||||
}
|
||||
|
||||
String setterName = fluent ? fieldNode.getName() : HandlerUtil.buildAccessorName("set", fieldNode.getName());
|
||||
|
||||
@@ -605,10 +605,7 @@ public class JavacHandlerUtil {
|
||||
if (params < minArgs || params > maxArgs) continue;
|
||||
}
|
||||
|
||||
List<JCAnnotation> annotations = md.getModifiers().getAnnotations();
|
||||
if (annotations != null) for (JCAnnotation anno : annotations) {
|
||||
if (typeMatches(Tolerate.class, node, anno.getAnnotationType())) continue top;
|
||||
}
|
||||
if (isTolerate(node, md)) continue top;
|
||||
|
||||
return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
|
||||
}
|
||||
@@ -619,6 +616,14 @@ public class JavacHandlerUtil {
|
||||
return MemberExistsResult.NOT_EXISTS;
|
||||
}
|
||||
|
||||
public static boolean isTolerate(JavacNode node, JCTree.JCMethodDecl md) {
|
||||
List<JCAnnotation> annotations = md.getModifiers().getAnnotations();
|
||||
if (annotations != null) for (JCTree.JCAnnotation anno : annotations) {
|
||||
if (typeMatches(Tolerate.class, node, anno.getAnnotationType())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if there is a (non-default) constructor. In case of multiple constructors (overloading), only
|
||||
* the first constructor decides if EXISTS_BY_USER or EXISTS_BY_LOMBOK is returned.
|
||||
@@ -634,10 +639,7 @@ public class JavacHandlerUtil {
|
||||
JCMethodDecl md = (JCMethodDecl) def;
|
||||
if (md.name.contentEquals("<init>")) {
|
||||
if ((md.mods.flags & Flags.GENERATEDCONSTR) != 0) continue;
|
||||
List<JCAnnotation> annotations = md.getModifiers().getAnnotations();
|
||||
if (annotations != null) for (JCAnnotation anno : annotations) {
|
||||
if (typeMatches(Tolerate.class, node, anno.getAnnotationType())) continue top;
|
||||
}
|
||||
if (isTolerate(node, md)) continue;
|
||||
return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
|
||||
import lombok.experimental.Tolerate;
|
||||
|
||||
public class BuilderWithTolerate {
|
||||
private final int value;
|
||||
|
||||
public static void main(String[] args) {
|
||||
BuilderWithTolerate.builder().value("42").build();
|
||||
}
|
||||
|
||||
|
||||
public static class BuilderWithTolerateBuilder {
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@javax.annotation.Generated("lombok")
|
||||
private int value;
|
||||
|
||||
@Tolerate
|
||||
public BuilderWithTolerateBuilder value(String s) {
|
||||
return this.value(Integer.parseInt(s));
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@javax.annotation.Generated("lombok")
|
||||
BuilderWithTolerateBuilder() {
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@javax.annotation.Generated("lombok")
|
||||
public BuilderWithTolerateBuilder value(final int value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@javax.annotation.Generated("lombok")
|
||||
public BuilderWithTolerate build() {
|
||||
return new BuilderWithTolerate(value);
|
||||
}
|
||||
|
||||
@java.lang.Override
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@javax.annotation.Generated("lombok")
|
||||
public java.lang.String toString() {
|
||||
return "BuilderWithTolerate.BuilderWithTolerateBuilder(value=" + this.value + ")";
|
||||
}
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@javax.annotation.Generated("lombok")
|
||||
BuilderWithTolerate(final int value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@java.lang.SuppressWarnings("all")
|
||||
@javax.annotation.Generated("lombok")
|
||||
public static BuilderWithTolerateBuilder builder() {
|
||||
return new BuilderWithTolerateBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import lombok.Builder;
|
||||
import lombok.experimental.Tolerate;
|
||||
public @Builder class BuilderWithTolerate {
|
||||
public static class BuilderWithTolerateBuilder {
|
||||
private @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") int value;
|
||||
public @Tolerate BuilderWithTolerateBuilder value(String s) {
|
||||
return this.value(Integer.parseInt(s));
|
||||
}
|
||||
@java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithTolerateBuilder() {
|
||||
super();
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithTolerateBuilder value(final int value) {
|
||||
this.value = value;
|
||||
return this;
|
||||
}
|
||||
public @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithTolerate build() {
|
||||
return new BuilderWithTolerate(value);
|
||||
}
|
||||
public @java.lang.Override @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") java.lang.String toString() {
|
||||
return (("BuilderWithTolerate.BuilderWithTolerateBuilder(value=" + this.value) + ")");
|
||||
}
|
||||
}
|
||||
private final int value;
|
||||
public static void main(String[] args) {
|
||||
BuilderWithTolerate.builder().value("42").build();
|
||||
}
|
||||
@java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithTolerate(final int value) {
|
||||
super();
|
||||
this.value = value;
|
||||
}
|
||||
public static @java.lang.SuppressWarnings("all") @javax.annotation.Generated("lombok") BuilderWithTolerateBuilder builder() {
|
||||
return new BuilderWithTolerateBuilder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import lombok.Builder;
|
||||
import lombok.experimental.Tolerate;
|
||||
|
||||
@Builder
|
||||
public class BuilderWithTolerate {
|
||||
private final int value;
|
||||
|
||||
public static void main(String[] args) {
|
||||
BuilderWithTolerate.builder().value("42").build();
|
||||
}
|
||||
|
||||
public static class BuilderWithTolerateBuilder {
|
||||
@Tolerate
|
||||
public BuilderWithTolerateBuilder value(String s) {
|
||||
return this.value(Integer.parseInt(s));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user