use of spoon.reflect.visitor.filter.CompositeFilter in project spoon by INRIA.
the class FilterTest method unionOfTwoFilters.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void unionOfTwoFilters() throws Exception {
Factory factory = build("spoon.test.testclasses", "SampleClass").getFactory();
TypeFilter<CtNewClass> newClassFilter = new TypeFilter<CtNewClass>(CtNewClass.class);
TypeFilter<CtMethod> methodFilter = new TypeFilter<CtMethod>(CtMethod.class);
CompositeFilter compositeFilter = new CompositeFilter(FilteringOperator.UNION, methodFilter, newClassFilter);
List filteredWithCompositeFilter = Query.getElements(factory, compositeFilter);
List<CtMethod> methods = Query.getElements(factory, methodFilter);
List<CtNewClass> newClasses = Query.getElements(factory, newClassFilter);
List<CtElement> union = new ArrayList<CtElement>();
union.addAll(methods);
union.addAll(newClasses);
assertEquals(methods.size() + newClasses.size(), union.size());
assertEquals(union.size(), filteredWithCompositeFilter.size());
assertTrue(filteredWithCompositeFilter.containsAll(union));
}
use of spoon.reflect.visitor.filter.CompositeFilter in project spoon by INRIA.
the class FilterTest method classCastExceptionIsNotThrown.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void classCastExceptionIsNotThrown() throws Exception {
Factory factory = build("spoon.test.testclasses", "SampleClass").getFactory();
NamedElementFilter<CtVariable> nameFilterA = new NamedElementFilter<>(CtVariable.class, "j");
NamedElementFilter<CtVariable> nameFilterB = new NamedElementFilter<>(CtVariable.class, "k");
CompositeFilter compositeFilter = new CompositeFilter(FilteringOperator.INTERSECTION, nameFilterA, nameFilterB);
List filteredWithCompositeFilter = Query.getElements(factory, compositeFilter);
assertTrue(filteredWithCompositeFilter.isEmpty());
}
use of spoon.reflect.visitor.filter.CompositeFilter in project spoon by INRIA.
the class FilterTest method intersectionOfTwoFilters.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void intersectionOfTwoFilters() throws Exception {
Factory factory = build("spoon.test.testclasses", "SampleClass").getFactory();
TypeFilter<CtMethod> statementFilter = new TypeFilter<CtMethod>(CtMethod.class);
TypeFilter<CtMethodImpl> statementImplFilter = new TypeFilter<CtMethodImpl>(CtMethodImpl.class);
CompositeFilter compositeFilter = new CompositeFilter(FilteringOperator.INTERSECTION, statementFilter, statementImplFilter);
List<CtMethod> methodsWithInterfaceSuperclass = Query.getElements(factory, statementFilter);
List<CtMethodImpl> methodWithConcreteClass = Query.getElements(factory, statementImplFilter);
assertEquals(methodsWithInterfaceSuperclass.size(), methodWithConcreteClass.size());
assertEquals(methodsWithInterfaceSuperclass, methodWithConcreteClass);
List intersection = Query.getElements(factory, compositeFilter);
assertEquals(methodsWithInterfaceSuperclass.size(), intersection.size());
assertEquals(methodsWithInterfaceSuperclass, intersection);
}
Aggregations