Skip to content

Commit

Permalink
Use method signatures to determine if interface declares java.lang.Ob…
Browse files Browse the repository at this point in the history
…ject methods
  • Loading branch information
krakowski committed Jun 1, 2018
1 parent 7b0cdad commit 34739fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/main/java/spoon/reflect/declaration/CtMethod.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ public interface CtMethod<T> extends CtExecutable<T>, CtTypeMember, CtFormalType
* </pre>
*/
boolean isOverriding(CtMethod<?> superMethod);

/**
* Compares this method's signature with another method.
*
* @param other The other method.
* @return true if both signatures are identical; false else
*/
boolean hasSameSignature(CtMethod<?> other);

/**
* Checks if the method is a default method. Default method can be in interfaces from
* Java 8: http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html.
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/support/reflect/code/CtLambdaImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public <R> CtMethod<R> getOverriddenMethod() {
lambdaExecutableMethod = lambdaTypeMethods.iterator().next();
} else {
for (CtMethod<?> method : lambdaTypeMethods) {
if (getFactory().Method().OBJECT_METHODS.contains(method)) {
if (getFactory().Method().OBJECT_METHODS.stream().anyMatch(method::hasSameSignature)) {
continue;
}
if (method.isDefaultMethod() || method.hasModifier(ModifierKind.PRIVATE) || method.hasModifier(ModifierKind.STATIC)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,11 @@ public boolean isOverriding(CtMethod<?> superMethod) {
return new ClassTypingContext(getDeclaringType()).isOverriding(this, superMethod);
}

@Override
public boolean hasSameSignature(CtMethod<?> other) {
return getSignature().equals(other.getSignature());
}

@MetamodelPropertyField(role = CtRole.IS_SHADOW)
boolean isShadow;

Expand Down

0 comments on commit 34739fe

Please sign in to comment.