diff options
Diffstat (limited to 'src/core/lombok/eclipse')
5 files changed, 28 insertions, 10 deletions
diff --git a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java index 67a2d07c..56f51573 100644 --- a/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java +++ b/src/core/lombok/eclipse/handlers/EclipseHandlerUtil.java @@ -977,8 +977,8 @@ public class EclipseHandlerUtil { /** * Wrapper for {@link #methodExists(String, EclipseNode, boolean)} with {@code caseSensitive} = {@code true}. */ - public static MemberExistsResult methodExists(String methodName, EclipseNode node) { - return methodExists(methodName, node, true); + public static MemberExistsResult methodExists(String methodName, EclipseNode node, int params) { + return methodExists(methodName, node, true, params); } /** @@ -988,8 +988,9 @@ public class EclipseHandlerUtil { * @param methodName the method name to check for. * @param node Any node that represents the Type (TypeDeclaration) to look in, or any child node thereof. * @param caseSensitive If the search should be case sensitive. + * @param params The number of parameters the method should have; varargs count as 0-*. Set to -1 to find any method with the appropriate name regardless of parameter count. */ - public static MemberExistsResult methodExists(String methodName, EclipseNode node, boolean caseSensitive) { + public static MemberExistsResult methodExists(String methodName, EclipseNode node, boolean caseSensitive, int params) { while (node != null && !(node.get() instanceof TypeDeclaration)) { node = node.up(); } @@ -1001,7 +1002,24 @@ public class EclipseHandlerUtil { char[] mName = def.selector; if (mName == null) continue; boolean nameEquals = caseSensitive ? methodName.equals(new String(mName)) : methodName.equalsIgnoreCase(new String(mName)); - if (nameEquals) return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK; + if (nameEquals) { + if (params > -1) { + int minArgs = 0; + int maxArgs = 0; + if (def.arguments != null && def.arguments.length > 0) { + minArgs = def.arguments.length; + if ((def.arguments[def.arguments.length - 1].type.bits & ASTNode.IsVarArgs) != 0) { + minArgs--; + maxArgs = Integer.MAX_VALUE; + } else { + maxArgs = minArgs; + } + } + + if (params < minArgs || params > maxArgs) continue; + } + return getGeneratedBy(def) == null ? MemberExistsResult.EXISTS_BY_USER : MemberExistsResult.EXISTS_BY_LOMBOK; + } } } } diff --git a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java index ef01835c..82a8f00e 100644 --- a/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java +++ b/src/core/lombok/eclipse/handlers/HandleEqualsAndHashCode.java @@ -204,9 +204,9 @@ public class HandleEqualsAndHashCode extends EclipseAnnotationHandler<EqualsAndH boolean isFinal = (typeDecl.modifiers & ClassFileConstants.AccFinal) != 0; boolean needsCanEqual = !isDirectDescendantOfObject || !isFinal; java.util.List<MemberExistsResult> existsResults = new ArrayList<MemberExistsResult>(); - existsResults.add(methodExists("equals", typeNode)); - existsResults.add(methodExists("hashCode", typeNode)); - existsResults.add(methodExists("canEqual", typeNode)); + existsResults.add(methodExists("equals", typeNode, 1)); + existsResults.add(methodExists("hashCode", typeNode, 0)); + existsResults.add(methodExists("canEqual", typeNode, 1)); switch (Collections.max(existsResults)) { case EXISTS_BY_LOMBOK: return; diff --git a/src/core/lombok/eclipse/handlers/HandleGetter.java b/src/core/lombok/eclipse/handlers/HandleGetter.java index 3bdba74e..5aeda5a5 100644 --- a/src/core/lombok/eclipse/handlers/HandleGetter.java +++ b/src/core/lombok/eclipse/handlers/HandleGetter.java @@ -194,7 +194,7 @@ public class HandleGetter extends EclipseAnnotationHandler<Getter> { int modifier = toEclipseModifier(level) | (field.modifiers & ClassFileConstants.AccStatic); for (String altName : TransformationsUtil.toAllGetterNames(fieldName, isBoolean)) { - switch (methodExists(altName, fieldNode, false)) { + switch (methodExists(altName, fieldNode, false, 0)) { case EXISTS_BY_LOMBOK: return; case EXISTS_BY_USER: diff --git a/src/core/lombok/eclipse/handlers/HandleSetter.java b/src/core/lombok/eclipse/handlers/HandleSetter.java index 8599fca7..01926155 100644 --- a/src/core/lombok/eclipse/handlers/HandleSetter.java +++ b/src/core/lombok/eclipse/handlers/HandleSetter.java @@ -153,7 +153,7 @@ public class HandleSetter extends EclipseAnnotationHandler<Setter> { int modifier = toEclipseModifier(level) | (field.modifiers & ClassFileConstants.AccStatic); for (String altName : TransformationsUtil.toAllSetterNames(new String(field.name), isBoolean)) { - switch (methodExists(altName, fieldNode, false)) { + switch (methodExists(altName, fieldNode, false, 1)) { case EXISTS_BY_LOMBOK: return; case EXISTS_BY_USER: diff --git a/src/core/lombok/eclipse/handlers/HandleToString.java b/src/core/lombok/eclipse/handlers/HandleToString.java index 07d88f5f..26f0e9be 100644 --- a/src/core/lombok/eclipse/handlers/HandleToString.java +++ b/src/core/lombok/eclipse/handlers/HandleToString.java @@ -159,7 +159,7 @@ public class HandleToString extends EclipseAnnotationHandler<ToString> { } } - switch (methodExists("toString", typeNode)) { + switch (methodExists("toString", typeNode, 0)) { case NOT_EXISTS: MethodDeclaration toString = createToString(typeNode, nodesForToString, includeFieldNames, callSuper, errorNode.get(), fieldAccess); injectMethod(typeNode, toString); |