Skip to content

Commit

Permalink
<R extends Object> List<R> list()
Browse files Browse the repository at this point in the history
  • Loading branch information
pvojtechovsky committed Jan 8, 2017
1 parent 06bd983 commit 639e5ce
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/main/java/spoon/reflect/visitor/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,9 @@ public static <E extends CtElement> List<E> getElements(Factory factory,
* @param filter
* the filter which defines the matching criteria
*/
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <E extends CtElement> List<E> getElements(
CtElement rootElement, Filter<E> filter) {
return (List<E>) (List) rootElement.filterChildren(filter).list();
return rootElement.filterChildren(filter).list();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/spoon/reflect/visitor/chain/CtQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface CtQuery extends CtQueryable {
* @return the list of elements collected by the query.
* @see #forEach(CtConsumer) for an efficient way of manipulating the elements without creating an intermediate list.
*/
List<Object> list();
<R extends Object> List<R> list();
/**
* actually evaluates the query and returns these produced elements as a List,
* which are assignable to `itemClass`
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/spoon/reflect/visitor/chain/CtQueryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,10 @@ public <R> void forEach(CtConsumer<R> consumer) {
}
}

@SuppressWarnings("unchecked")
@Override
public List<Object> list() {
return list(Object.class);
public <R extends Object> List<R> list() {
return (List<R>) list(Object.class);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public Set<CtTypeReference<?>> getReferencedTypes() {

@SuppressWarnings({ "unchecked", "rawtypes" })
public <E extends CtElement> List<E> getElements(Filter<E> filter) {
return (List<E>) (List) filterChildren(filter).list();
return filterChildren(filter).list();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void noTreeSetInSpoon() throws Exception {
spoon.addInputResource("src/main/java/");
spoon.buildModel();

List<Object> treeSetWithoutComparators = spoon.getFactory().Package().getRootPackage().filterChildren(new AbstractFilter<CtConstructorCall>() {
List<CtConstructorCall> treeSetWithoutComparators = spoon.getFactory().Package().getRootPackage().filterChildren(new AbstractFilter<CtConstructorCall>() {
@Override
public boolean matches(CtConstructorCall element) {
return element.getType().getActualClass().equals(TreeSet.class) && element.getArguments().size() == 0;
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/filters/FilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public void testElementMapConsumableFunction() throws Exception {
public void testElementMapFunctionArray() throws Exception {
final Launcher launcher = new Launcher();
CtQueryImpl q = new CtQueryImpl().map((String s)->new String[]{"a", null, s});
List<Object> list = q.setInput(null).list();
List<String> list = q.setInput(null).list();
assertEquals(0, list.size());

list = q.setInput("c").list();
Expand All @@ -642,7 +642,7 @@ public void testElementMapFunctionArray() throws Exception {
public void testElementMapFunctionNull() throws Exception {
final Launcher launcher = new Launcher();
CtQueryImpl q = new CtQueryImpl().map((String s)->null);
List<Object> list = q.setInput(null).list();
List<String> list = q.setInput(null).list();
assertEquals(0, list.size());

list = q.setInput("c").list();
Expand Down

0 comments on commit 639e5ce

Please sign in to comment.