@Test public void testGetAllMethods() throws Exception { /* getAllMethods must not throw Exception in no classpath mode */ Launcher l = new Launcher(); l.getEnvironment().setNoClasspath(true); l.addInputResource("src/test/resources/noclasspath/A3.java"); l.buildModel(); Set<CtMethod<?>> methods = l.getFactory().Class().get("A3").getAllMethods(); assertEquals( 1, methods.stream().filter(method -> "foo".equals(method.getSimpleName())).count()); }
@Test public void testDestinationOfSpoon() throws Exception { final File binaryOutput = new File("./target/spoon/test/binary/"); final Launcher launcher = new Launcher(); launcher.getEnvironment().setShouldCompile(true); launcher.addInputResource("./src/test/java/spoon/test/api/testclasses"); launcher.setSourceOutputDirectory("./target/spooned"); launcher.setBinaryOutputDirectory(binaryOutput); launcher.run(); assertTrue(binaryOutput.exists()); }
// example usage (please do not use directly, use instead the spoon.Launcher // API to create the factory) public static void main(String[] args) throws Exception { Launcher main = new Launcher(); JDTBasedSpoonCompiler comp = new JDTBasedSpoonCompiler(main.createFactory()); comp.createBatchCompiler().printUsage(); SpoonFile file = new FileSystemFile(new File("./src/main/java/spoon/support/compiler/JDTCompiler.java")); comp.addInputSource(file); try { comp.build(); final Set<CtType<?>> types = comp.getFactory().Package().get("spoon.support.compiler").getTypes(); for (CtType<?> type : types) { main.getEnvironment().debugMessage(type.toString()); } } catch (Exception e) { throw new RuntimeException(e); } }
@Test public void testVariableAccessInNoClasspath() throws Exception { final Launcher launcher = new Launcher(); launcher.getEnvironment().setNoClasspath(true); launcher.addInputResource("./src/test/resources/variable"); launcher.setSourceOutputDirectory("./target/variable/"); launcher.run(); final CtClass<Object> aClass = launcher.getFactory().Class().get("org.argouml.uml.ui.behavior.use_cases.PropPanelUseCase"); final List<CtFieldRead> elements = aClass.getElements(new TypeFilter<>(CtFieldRead.class)); for (CtFieldRead element : elements) { assertNotNull(element.getVariable()); } assertEquals( "java.lang.Class mclass = ((java.lang.Class) (org.argouml.model.ModelFacade.USE_CASE))", elements.get(0).getParent().toString()); assertEquals( "new org.argouml.uml.ui.PropPanelButton(org.argouml.uml.ui.behavior.use_cases.PropPanelUseCase.this, buttonPanel, _navUpIcon, org.argouml.i18n.Translator.localize(\"UMLMenu\", \"button.go-up\"), \"navigateNamespace\", null)", elements.get(2).getParent().toString()); }