aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/lombok/EqualsAndHashCode.java2
-rw-r--r--src/core/lombok/core/LombokNode.java13
-rw-r--r--src/core/lombok/core/handlers/HandlerUtil.java21
-rw-r--r--src/core/lombok/core/handlers/InclusionExclusionUtils.java4
-rw-r--r--src/core/lombok/eclipse/EclipseNode.java23
-rw-r--r--src/core/lombok/javac/JavacNode.java13
6 files changed, 73 insertions, 3 deletions
diff --git a/src/core/lombok/EqualsAndHashCode.java b/src/core/lombok/EqualsAndHashCode.java
index 2f53bdec..6805d214 100644
--- a/src/core/lombok/EqualsAndHashCode.java
+++ b/src/core/lombok/EqualsAndHashCode.java
@@ -126,7 +126,7 @@ public @interface EqualsAndHashCode {
/**
* Higher ranks are considered first. Members of the same rank are considered in the order they appear in the source file.
*
- * If not explicitly set, the {@code default} rank for primitives is 1000.
+ * If not explicitly set, the {@code default} rank for primitives is 1000, and for primitive wrappers 800.
*
* @return ordering within the generating {@code equals} and {@code hashCode} methods; higher numbers are considered first.
*/
diff --git a/src/core/lombok/core/LombokNode.java b/src/core/lombok/core/LombokNode.java
index 46054077..abfc66a6 100644
--- a/src/core/lombok/core/LombokNode.java
+++ b/src/core/lombok/core/LombokNode.java
@@ -292,6 +292,19 @@ public abstract class LombokNode<A extends AST<A, L, N>, L extends LombokNode<A,
public abstract boolean isEnumMember();
public abstract boolean isEnumType();
+ /**
+ * The 'type' of the field or method, or {@code null} if this node is neither.
+ *
+ * The type is as it is written in the code (no resolution), includes array dimensions,
+ * but not necessarily generics.
+ *
+ * The main purpose of this method is to verify this type against a list of known types,
+ * like primitives or primitive wrappers.
+ *
+ * @return The 'type' of the field or method, or {@code null} if this node is neither.
+ */
+ public abstract String fieldOrMethodBaseType();
+
public abstract int countMethodParameters();
public abstract int getStartPos();
diff --git a/src/core/lombok/core/handlers/HandlerUtil.java b/src/core/lombok/core/handlers/HandlerUtil.java
index f7bfd735..46ce3825 100644
--- a/src/core/lombok/core/handlers/HandlerUtil.java
+++ b/src/core/lombok/core/handlers/HandlerUtil.java
@@ -27,6 +27,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
+import java.util.regex.Pattern;
import lombok.AllArgsConstructor;
import lombok.ConfigurationKeys;
@@ -365,6 +366,7 @@ public class HandlerUtil {
public static String autoSingularize(String plural) {
return Singulars.autoSingularize(plural);
}
+
public static void handleFlagUsage(LombokNode<?, ?, ?> node, ConfigurationKey<FlagUsageType> key, String featureName) {
FlagUsageType fut = node.getAst().readConfiguration(key);
@@ -742,4 +744,23 @@ public class HandlerUtil {
}
return b.toString();
}
+
+ /** Matches any of the 8 primitive names, such as {@code boolean}. */
+ private static final Pattern PRIMITIVE_TYPE_NAME_PATTERN = Pattern.compile("^(?:boolean|byte|short|int|long|float|double|char)$");
+
+ public static boolean isPrimitive(String typeName) {
+ return PRIMITIVE_TYPE_NAME_PATTERN.matcher(typeName).matches();
+ }
+
+ /** Matches any of the 8 primitive wrapper names, such as {@code Boolean}. */
+ private static final Pattern PRIMITIVE_WRAPPER_TYPE_NAME_PATTERN = Pattern.compile("^(?:java\\.lang\\.)?(?:Boolean|Byte|Short|Integer|Long|Float|Double|Character)$");
+
+ public static int defaultEqualsAndHashcodeIncludeRank(String typeName) {
+ // Modification in this code should be documented
+ // 1. In the changelog this should be marked as an INPROBABLE BREAKING CHANGE, since the hashcode will change
+ // 2. In the javadoc of EqualsAndHashcode.Include#rank
+ if (isPrimitive(typeName)) return 1000;
+ if (PRIMITIVE_WRAPPER_TYPE_NAME_PATTERN.matcher(typeName).matches()) return 800;
+ return 0;
+ }
}
diff --git a/src/core/lombok/core/handlers/InclusionExclusionUtils.java b/src/core/lombok/core/handlers/InclusionExclusionUtils.java
index 609a5e36..e785db3f 100644
--- a/src/core/lombok/core/handlers/InclusionExclusionUtils.java
+++ b/src/core/lombok/core/handlers/InclusionExclusionUtils.java
@@ -225,8 +225,8 @@ public class InclusionExclusionUtils {
Collections.sort(members, new Comparator<Included<L, EqualsAndHashCode.Include>>() {
@Override public int compare(Included<L, EqualsAndHashCode.Include> a, Included<L, EqualsAndHashCode.Include> b) {
- int ra = a.hasExplicitRank() ? a.getInc().rank() : a.node.isPrimitive() ? 1000 : 0;
- int rb = b.hasExplicitRank() ? b.getInc().rank() : b.node.isPrimitive() ? 1000 : 0;
+ int ra = a.hasExplicitRank() ? a.getInc().rank() : HandlerUtil.defaultEqualsAndHashcodeIncludeRank(a.node.fieldOrMethodBaseType());
+ int rb = b.hasExplicitRank() ? b.getInc().rank() : HandlerUtil.defaultEqualsAndHashcodeIncludeRank(b.node.fieldOrMethodBaseType());
return compareRankOrPosition(ra, rb, a.getNode(), b.getNode());
}
diff --git a/src/core/lombok/eclipse/EclipseNode.java b/src/core/lombok/eclipse/EclipseNode.java
index 5aa29466..12e9ccdb 100644
--- a/src/core/lombok/eclipse/EclipseNode.java
+++ b/src/core/lombok/eclipse/EclipseNode.java
@@ -275,6 +275,29 @@ public class EclipseNode extends lombok.core.LombokNode<EclipseAST, EclipseNode,
return false;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override public String fieldOrMethodBaseType() {
+ TypeReference typeReference = null;
+ if (node instanceof FieldDeclaration && !isEnumMember()) {
+ typeReference = ((FieldDeclaration) node).type;
+ }
+ if (node instanceof MethodDeclaration) {
+ typeReference = ((MethodDeclaration) node).returnType;
+ }
+ if (typeReference == null) return null;
+
+ String fqn = Eclipse.toQualifiedName(typeReference.getTypeName());
+ if (typeReference.dimensions() == 0) return fqn;
+ StringBuilder result = new StringBuilder(fqn.length() + 2 * typeReference.dimensions());
+ result.append(fqn);
+ for (int i = 0; i < typeReference.dimensions(); i++) {
+ result.append("[]");
+ }
+ return result.toString();
+ }
+
@Override public boolean isTransient() {
if (getKind() != Kind.FIELD) return false;
Integer i = getModifiers();
diff --git a/src/core/lombok/javac/JavacNode.java b/src/core/lombok/javac/JavacNode.java
index 08d22d98..3de3f38b 100644
--- a/src/core/lombok/javac/JavacNode.java
+++ b/src/core/lombok/javac/JavacNode.java
@@ -355,6 +355,19 @@ public class JavacNode extends lombok.core.LombokNode<JavacAST, JavacNode, JCTre
return false;
}
+ /**
+ * {@inheritDoc}
+ */
+ @Override public String fieldOrMethodBaseType() {
+ if (node instanceof JCVariableDecl && !isEnumMember()) {
+ return (((JCVariableDecl) node).vartype).toString();
+ }
+ if (node instanceof JCMethodDecl) {
+ return (((JCMethodDecl) node).restype).toString();
+ }
+ return null;
+ }
+
@Override public boolean isTransient() {
if (getKind() != Kind.FIELD) return false;
JCModifiers mods = getModifiers();