use of spoon.support.reflect.declaration.CtMethodImpl in project spoon by INRIA.
the class FactoryTest method testFactoryOverriding.
@Test
public void testFactoryOverriding() throws Exception {
@SuppressWarnings("serial")
class MyCtMethod<T> extends CtMethodImpl<T> {
}
;
@SuppressWarnings("serial") final CoreFactory specialCoreFactory = new DefaultCoreFactory() {
@Override
public <T> CtMethod<T> createMethod() {
MyCtMethod<T> m = new MyCtMethod<T>();
m.setFactory(getMainFactory());
return m;
}
};
Launcher launcher = new Launcher() {
@Override
public Factory createFactory() {
return new FactoryImpl(specialCoreFactory, new StandardEnvironment());
}
};
CtClass<?> type = build("spoon.test.testclasses", "SampleClass", launcher.getFactory());
CtMethod<?> m = type.getMethodsByName("method3").get(0);
assertTrue(m instanceof MyCtMethod);
}
use of spoon.support.reflect.declaration.CtMethodImpl 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);
}
use of spoon.support.reflect.declaration.CtMethodImpl in project spoon by INRIA.
the class ElementTest method testGetFactory.
@Test
public void testGetFactory() {
// contract: getFactory should always return an object
// even if an element is created via its constructor
// and not through the factory
Launcher spoon = new Launcher();
CtElement element = spoon.getFactory().createAnnotation();
assertNotNull(element.getFactory());
CtElement otherElement = new CtAnnotationImpl<>();
assertNotNull(otherElement.getFactory());
CtElement yetAnotherOne = new CtMethodImpl<>();
assertNotNull(yetAnotherOne.getFactory());
// contract: a singleton is used for the default factory
assertSame(otherElement.getFactory(), yetAnotherOne.getFactory());
}
Aggregations