@Test public void testReferenceProcessor() throws Exception { final String[] args = { "-i", "src/test/resources/factory/", "-o", "target/spooned/" }; final Launcher launcher = new Launcher(); launcher.setArgs(args); launcher.run(); final Factory factory = launcher.getFactory(); final ProcessingManager processingManager = new QueueProcessingManager(factory); List<CtInterface> listFactoryItf = factory.getModel().getElements(new NamedElementFilter<>(CtInterface.class, "Factory")); assertThat(listFactoryItf.size(), is(1)); final FactoryProcessor processor = new FactoryProcessor(listFactoryItf.get(0).getReference()); processingManager.addProcessor(processor); List<CtConstructorCall> ctNewClasses = factory.getModel().getElements(new TypeFilter<>(CtConstructorCall.class)); processingManager.process(ctNewClasses); assertThat(processor.listWrongUses.size(), is(2)); }
public void process(CtConstructorCall<?> newClass) { if (newClass.getExecutable().getDeclaringType().isSubtypeOf(getFactoryType())) return; if (newClass.getParent(CtClass.class).isSubtypeOf(getFactoryType())) return; for (CtTypeReference<?> t : getCreatedTypes()) { if (newClass.getType().isSubtypeOf(t)) { this.listWrongUses.add(newClass); } } }
FactoryProcessor extends AbstractProcessor<CtConstructorCall<?>> { public void process(CtConstructorCall<?> newClass) { if (newClass.getExecutable().getDeclaringType().isSubtypeOf(getFactoryType())) return; if (newClass.getParent(CtClass.class).isSubtypeOf(getFactoryType())) return; for (CtTypeReference<?> t : getCreatedTypes()) { if (newClass.getType().isSubtypeOf(t)) { this.listWrongUses.add(newClass); } } } }
FactoryProcessor extends AbstractProcessor<CtConstructorCall<?>> { public void process(CtConstructorCall<?> newClass) { if (newClass.getExecutable().getDeclaringType().isSubtypeOf(getFactoryType())) return; if (newClass.getParent(CtClass.class).isSubtypeOf(getFactoryType())) return; for (CtTypeReference<?> t : getCreatedTypes()) { if (newClass.getType().isSubtypeOf(t)) { this.listWrongUses.add(newClass); } } } FactoryProcessor(CtTypeReference factoryTypeRef); }
FactoryProcessor extends AbstractProcessor<CtConstructorCall<?>> { public void process(CtConstructorCall<?> newClass) { if (newClass.getExecutable().getDeclaringType().isSubtypeOf(getFactoryType())) return; if (newClass.getParent(CtClass.class).isSubtypeOf(getFactoryType())) return; for (CtTypeReference<?> t : getCreatedTypes()) { if (newClass.getType().isSubtypeOf(t)) { this.listWrongUses.add(newClass); } } } FactoryProcessor(CtTypeReference factoryTypeRef); void process(CtConstructorCall<?> newClass); }
FactoryProcessor extends AbstractProcessor<CtConstructorCall<?>> { public void process(CtConstructorCall<?> newClass) { if (newClass.getExecutable().getDeclaringType().isSubtypeOf(getFactoryType())) return; if (newClass.getParent(CtClass.class).isSubtypeOf(getFactoryType())) return; for (CtTypeReference<?> t : getCreatedTypes()) { if (newClass.getType().isSubtypeOf(t)) { this.listWrongUses.add(newClass); } } } FactoryProcessor(CtTypeReference factoryTypeRef); void process(CtConstructorCall<?> newClass); public List<CtConstructorCall> listWrongUses; }