Skip to content

Commit

Permalink
fix: undo #1798 for backward compatibility (#1811)
Browse files Browse the repository at this point in the history
  • Loading branch information
surli authored and monperrus committed Jan 4, 2018
1 parent cef5e07 commit 711a87b
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 22 deletions.
9 changes: 1 addition & 8 deletions src/main/java/spoon/reflect/visitor/Filter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
*/
package spoon.reflect.visitor;

import java.util.function.Predicate;

import spoon.reflect.declaration.CtElement;

/**
Expand All @@ -27,15 +25,10 @@
* the type of the filtered elements (an element belonging to the
* filtered element must be assignable from <code>T</code>).
*/
public interface Filter<T extends CtElement> extends Predicate<T> {
public interface Filter<T extends CtElement> {
/**
* Tells if the given element matches.
* @param element - the element to be checked for a match. Parameter element is never null if {@link Query} is used.
*/
boolean matches(T element);

@Override
default boolean test(T element) {
return matches(element);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,4 @@ public Class<T> getType() {
public boolean matches(T element) {
return type.isAssignableFrom(element.getClass());
}

@Override
public boolean test(T element) {
return matches(element);
}
}
9 changes: 0 additions & 9 deletions src/test/java/spoon/test/filters/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1285,13 +1285,4 @@ public void testNameFilterWithGenericType() {
assertEquals(1, ctFields.size());
assertTrue(ctFields.get(0) instanceof CtField);
}

@Test
public void testFilterAsPredicate() throws Exception {
CtClass<?> foo = factory.Package().get("spoon.test.filters").getType("Foo");
//contract: Spoon Filter is compatible with java.util.function.Predicate
Predicate predicate = new NamedElementFilter<>(CtClass.class, "Foo");
assertTrue(predicate.test(foo));
assertFalse(predicate.test(foo.getTypeMembers().get(0)));
}
}

0 comments on commit 711a87b

Please sign in to comment.