aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRawi01 <Rawi01@users.noreply.github.com>2021-01-31 14:33:19 +0100
committerRawi01 <Rawi01@users.noreply.github.com>2021-01-31 14:33:38 +0100
commit191a8011ef5e8ae2a4446b9b357e121272526364 (patch)
tree0cafbd10414cb99507c7a69f9a882afcbfef898f
parent3d3a4c322af4cf7f27679661efaa9dcd685165bb (diff)
downloadlombok-191a8011ef5e8ae2a4446b9b357e121272526364.tar.gz
lombok-191a8011ef5e8ae2a4446b9b357e121272526364.tar.bz2
lombok-191a8011ef5e8ae2a4446b9b357e121272526364.zip
[fixes #1064] Only show super()-warning if lombok generates a method
-rwxr-xr-xsrc/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java48
-rw-r--r--src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java48
-rw-r--r--test/transform/resource/after-delombok/DataWithOverrideEqualsAndHashCode.java25
-rw-r--r--test/transform/resource/after-ecj/DataWithOverrideEqualsAndHashCode.java25
-rw-r--r--test/transform/resource/before/DataWithOverrideEqualsAndHashCode.java18
5 files changed, 116 insertions, 48 deletions
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index deb19c00..8115a91f 100755
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -168,30 +168,6 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
boolean isDirectDescendantOfObject = isDirectDescendantOfObject(typeNode);
- if (isDirectDescendantOfObject && callSuper) {
- errorNode.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless.");
- return;
- }
-
- if (implicitCallSuper && !isDirectDescendantOfObject) {
- CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_CALL_SUPER);
- if (cst == null) cst = CallSuperType.WARN;
-
- switch (cst) {
- default:
- case WARN:
- errorNode.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.");
- callSuper = false;
- break;
- case SKIP:
- callSuper = false;
- break;
- case CALL:
- callSuper = true;
- break;
- }
- }
-
boolean isFinal = (typeDecl.modifiers & ClassFileConstants.AccFinal) != 0;
boolean needsCanEqual = !isFinal || !isDirectDescendantOfObject;
MemberExistsResult equalsExists = methodExists("equals", typeNode, 1);
@@ -220,6 +196,30 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
//fallthrough
}
+ if (isDirectDescendantOfObject && callSuper) {
+ errorNode.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless.");
+ return;
+ }
+
+ if (implicitCallSuper && !isDirectDescendantOfObject) {
+ CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_CALL_SUPER);
+ if (cst == null) cst = CallSuperType.WARN;
+
+ switch (cst) {
+ default:
+ case WARN:
+ errorNode.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.");
+ callSuper = false;
+ break;
+ case SKIP:
+ callSuper = false;
+ break;
+ case CALL:
+ callSuper = true;
+ break;
+ }
+ }
+
MethodDeclaration equalsMethod = createEquals(typeNode, members, callSuper, errorNode.get(), fieldAccess, needsCanEqual, onParam);
equalsMethod.traverse(new SetGeneratedByVisitor(errorNode.get()), ((TypeDeclaration)typeNode.get()).scope);
injectMethod(typeNode, equalsMethod);
diff --git a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
index e76d701e..b17b0fdd 100644
--- a/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/javac/handlers/HandleEqualsAndHashCode.java
@@ -141,30 +141,6 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
boolean isDirectDescendantOfObject = isDirectDescendantOfObject(typeNode);
- if (isDirectDescendantOfObject && callSuper) {
- source.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless.");
- return;
- }
-
- if (implicitCallSuper && !isDirectDescendantOfObject) {
- CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_CALL_SUPER);
- if (cst == null) cst = CallSuperType.WARN;
-
- switch (cst) {
- default:
- case WARN:
- source.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.");
- callSuper = false;
- break;
- case SKIP:
- callSuper = false;
- break;
- case CALL:
- callSuper = true;
- break;
- }
- }
-
boolean isFinal = (((JCClassDecl) typeNode.get()).mods.flags & Flags.FINAL) != 0;
boolean needsCanEqual = !isFinal || !isDirectDescendantOfObject;
MemberExistsResult equalsExists = methodExists("equals", typeNode, 1);
@@ -193,6 +169,30 @@ public class HandleEqualsAndHashCode extends JavacAnnotationHandler<EqualsAndHas
//fallthrough
}
+ if (isDirectDescendantOfObject && callSuper) {
+ source.addError("Generating equals/hashCode with a supercall to java.lang.Object is pointless.");
+ return;
+ }
+
+ if (implicitCallSuper && !isDirectDescendantOfObject) {
+ CallSuperType cst = typeNode.getAst().readConfiguration(ConfigurationKeys.EQUALS_AND_HASH_CODE_CALL_SUPER);
+ if (cst == null) cst = CallSuperType.WARN;
+
+ switch (cst) {
+ default:
+ case WARN:
+ source.addWarning("Generating equals/hashCode implementation but without a call to superclass, even though this class does not extend java.lang.Object. If this is intentional, add '@EqualsAndHashCode(callSuper=false)' to your type.");
+ callSuper = false;
+ break;
+ case SKIP:
+ callSuper = false;
+ break;
+ case CALL:
+ callSuper = true;
+ break;
+ }
+ }
+
JCMethodDecl equalsMethod = createEquals(typeNode, members, callSuper, fieldAccess, needsCanEqual, source, onParam);
injectMethod(typeNode, equalsMethod);
diff --git a/test/transform/resource/after-delombok/DataWithOverrideEqualsAndHashCode.java b/test/transform/resource/after-delombok/DataWithOverrideEqualsAndHashCode.java
new file mode 100644
index 00000000..7e84dda4
--- /dev/null
+++ b/test/transform/resource/after-delombok/DataWithOverrideEqualsAndHashCode.java
@@ -0,0 +1,25 @@
+class DataWithOverrideEqualsAndHashCode {
+
+ class Data1 {
+ }
+
+ class Data2 extends Data1 {
+ public int hashCode() {
+ return 42;
+ }
+
+ public boolean equals(Object other) {
+ return false;
+ }
+
+ @java.lang.SuppressWarnings("all")
+ public Data2() {
+ }
+
+ @java.lang.Override
+ @java.lang.SuppressWarnings("all")
+ public java.lang.String toString() {
+ return "DataWithOverrideEqualsAndHashCode.Data2()";
+ }
+ }
+}
diff --git a/test/transform/resource/after-ecj/DataWithOverrideEqualsAndHashCode.java b/test/transform/resource/after-ecj/DataWithOverrideEqualsAndHashCode.java
new file mode 100644
index 00000000..2149321f
--- /dev/null
+++ b/test/transform/resource/after-ecj/DataWithOverrideEqualsAndHashCode.java
@@ -0,0 +1,25 @@
+import lombok.Data;
+class DataWithOverrideEqualsAndHashCode {
+ class Data1 {
+ Data1() {
+ super();
+ }
+ }
+ @Data class Data2 extends Data1 {
+ public int hashCode() {
+ return 42;
+ }
+ public boolean equals(Object other) {
+ return false;
+ }
+ public @java.lang.Override @java.lang.SuppressWarnings("all") java.lang.String toString() {
+ return "DataWithOverrideEqualsAndHashCode.Data2()";
+ }
+ public @java.lang.SuppressWarnings("all") Data2() {
+ super();
+ }
+ }
+ DataWithOverrideEqualsAndHashCode() {
+ super();
+ }
+}
diff --git a/test/transform/resource/before/DataWithOverrideEqualsAndHashCode.java b/test/transform/resource/before/DataWithOverrideEqualsAndHashCode.java
new file mode 100644
index 00000000..78138bbf
--- /dev/null
+++ b/test/transform/resource/before/DataWithOverrideEqualsAndHashCode.java
@@ -0,0 +1,18 @@
+import lombok.Data;
+
+class DataWithOverrideEqualsAndHashCode {
+ class Data1 {
+
+ }
+
+ @Data
+ class Data2 extends Data1 {
+ public int hashCode() {
+ return 42;
+ }
+
+ public boolean equals(Object other) {
+ return false;
+ }
+ }
+} \ No newline at end of file