aboutsummaryrefslogtreecommitdiff
path: root/src/core/lombok/eclipse/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/lombok/eclipse/handlers')
-rw-r--r--src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java31
-rw-r--r--src/core/lombok/eclipse/handlers/HandleBuilder.java2
-rw-r--r--src/core/lombok/eclipse/handlers/HandleConstructor.java11
-rw-r--r--src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java2
-rw-r--r--src/core/lombok/eclipse/handlers/NonNullHandler.java5
5 files changed, 45 insertions, 6 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
index d74b8981..5e322c90 100644
--- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
+++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java
@@ -1125,6 +1125,37 @@ public class EclipseHandlerUtil {
return true;
}
+ public static char[] removePrefixFromField(EclipseNode field) {
+ String[] prefixes = null;
+ for (EclipseNode node : field.down()) {
+ if (annotationTypeMatches(Accessors.class, node)) {
+ prefixes = createAnnotation(Accessors.class, node).getInstance().prefix();
+ break;
+ }
+ }
+
+ if (prefixes == null) {
+ EclipseNode current = field.up();
+ outer:
+ while (current != null) {
+ for (EclipseNode node : current.down()) {
+ if (annotationTypeMatches(Accessors.class, node)) {
+ prefixes = createAnnotation(Accessors.class, node).getInstance().prefix();
+ break outer;
+ }
+ }
+ current = current.up();
+ }
+ }
+
+ if (prefixes != null && prefixes.length > 0) {
+ CharSequence newName = TransformationsUtil.removePrefix(field.getName(), prefixes);
+ if (newName != null) return newName.toString().toCharArray();
+ }
+
+ return ((FieldDeclaration) field.get()).name;
+ }
+
public static AnnotationValues<Accessors> getAccessorsForField(EclipseNode field) {
for (EclipseNode node : field.down()) {
if (annotationTypeMatches(Accessors.class, node)) {
diff --git a/src/core/lombok/eclipse/handlers/HandleBuilder.java b/src/core/lombok/eclipse/handlers/HandleBuilder.java
index 70110a9c..981d77dc 100644
--- a/src/core/lombok/eclipse/handlers/HandleBuilder.java
+++ b/src/core/lombok/eclipse/handlers/HandleBuilder.java
@@ -113,7 +113,7 @@ public class HandleBuilder extends EclipseAnnotationHandler<Builder> {
// non-final fields final, but @Value's handler hasn't done this yet, so we have to do this math ourselves.
// Value will only skip making a field final if it has an explicit @NonFinal annotation, so we check for that.
if (fd.initialization != null && valuePresent && !hasAnnotation(NonFinal.class, fieldNode)) continue;
- namesOfParameters.add(fd.name);
+ namesOfParameters.add(removePrefixFromField(fieldNode));
typesOfParameters.add(fd.type);
fields.add(fieldNode);
}
diff --git a/src/core/lombok/eclipse/handlers/HandleConstructor.java b/src/core/lombok/eclipse/handlers/HandleConstructor.java
index 1ae680d9..22285b2d 100644
--- a/src/core/lombok/eclipse/handlers/HandleConstructor.java
+++ b/src/core/lombok/eclipse/handlers/HandleConstructor.java
@@ -230,7 +230,8 @@ public class HandleConstructor {
int ctr = 0;
for (EclipseNode field : fields) {
- fieldNames.expressions[ctr] = new StringLiteral(field.getName().toCharArray(), pS, pE, 0);
+ char[] fieldName = removePrefixFromField(field);
+ fieldNames.expressions[ctr] = new StringLiteral(fieldName, pS, pE, 0);
setGeneratedBy(fieldNames.expressions[ctr], source);
ctr++;
}
@@ -273,15 +274,17 @@ public class HandleConstructor {
for (EclipseNode fieldNode : fields) {
FieldDeclaration field = (FieldDeclaration) fieldNode.get();
- FieldReference thisX = new FieldReference(field.name, p);
+ char[] rawName = field.name;
+ char[] fieldName = removePrefixFromField(fieldNode);
+ FieldReference thisX = new FieldReference(rawName, p);
thisX.receiver = new ThisReference((int)(p >> 32), (int)p);
- SingleNameReference assignmentNameRef = new SingleNameReference(field.name, p);
+ SingleNameReference assignmentNameRef = new SingleNameReference(fieldName, p);
Assignment assignment = new Assignment(thisX, assignmentNameRef, (int)p);
assignment.sourceStart = (int)(p >> 32); assignment.sourceEnd = assignment.statementEnd = (int)(p >> 32);
assigns.add(assignment);
long fieldPos = (((long)field.sourceStart) << 32) | field.sourceEnd;
- Argument parameter = new Argument(field.name, fieldPos, copyType(field.type, source), Modifier.FINAL);
+ Argument parameter = new Argument(fieldName, fieldPos, copyType(field.type, source), Modifier.FINAL);
Annotation[] nonNulls = findAnnotations(field, TransformationsUtil.NON_NULL_PATTERN);
Annotation[] nullables = findAnnotations(field, TransformationsUtil.NULLABLE_PATTERN);
if (nonNulls.length != 0) {
diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
index 6990e609..3c8a7039 100644
--- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
+++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java
@@ -221,7 +221,7 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH
// The user code couldn't possibly (barring really weird subclassing shenanigans) be in a shippable state anyway; the implementations of these 3 methods are
// all inter-related and should be written by the same entity.
String msg = String.format("Not generating %s: One of equals, hashCode, and canEqual exists. " +
- "You should either write all of these are none of these (in the latter case, lombok generates them).",
+ "You should either write all of these or none of these (in the latter case, lombok generates them).",
equalsExists == MemberExistsResult.NOT_EXISTS && hashCodeExists == MemberExistsResult.NOT_EXISTS ? "equals and hashCode" :
equalsExists == MemberExistsResult.NOT_EXISTS ? "equals" : "hashCode");
errorNode.addWarning(msg);
diff --git a/src/core/lombok/eclipse/handlers/NonNullHandler.java b/src/core/lombok/eclipse/handlers/NonNullHandler.java
index 5c58069c..59fda801 100644
--- a/src/core/lombok/eclipse/handlers/NonNullHandler.java
+++ b/src/core/lombok/eclipse/handlers/NonNullHandler.java
@@ -82,6 +82,11 @@ public class NonNullHandler extends EclipseAnnotationHandler<NonNull> {
if (isGenerated(declaration)) return;
+ if (declaration.isAbstract()) {
+ annotationNode.addWarning("@NonNull is meaningless on a parameter of an abstract method.");
+ return;
+ }
+
// Possibly, if 'declaration instanceof ConstructorDeclaration', fetch declaration.constructorCall, search it for any references to our parameter,
// and if they exist, create a new method in the class: 'private static <T> T lombok$nullCheck(T expr, String msg) {if (expr == null) throw NPE; return expr;}' and
// wrap all references to it in the super/this to a call to this method.