@Override public CtModel buildModel() { long tstart = System.currentTimeMillis(); modelBuilder.build(); getEnvironment().debugMessage("model built in " + (System.currentTimeMillis() - tstart)); return modelBuilder.getFactory().getModel(); }
/** * Utility method for testing: creates the model of the given `classesToBuild` from src/test/java and returns the factory * and allows to configure the Launcher first using `config` */ public static Factory build(Consumer<Launcher> config, Class<?>... classesToBuild) throws Exception { final Launcher launcher = new Launcher(); config.accept(launcher); SpoonModelBuilder comp = launcher.createCompiler(); for (Class<?> classToBuild : classesToBuild) { comp.addInputSources(SpoonResourceHelper.resources("./src/test/java/" + classToBuild.getName().replace('.', '/') + ".java")); } comp.build(); return comp.getFactory(); }
/** Utility method for testing: creates the model of `packageName` and the factory from src/test/java and returns the CtType corresponding to `className` */ public static <T extends CtType<?>> T build(String packageName, String className, final Factory f) throws Exception { Launcher launcher = new Launcher() { @Override public Factory createFactory() { return f; } }; SpoonModelBuilder comp = launcher.createCompiler(); comp.addInputSources(SpoonResourceHelper.resources("./src/test/java/" + packageName.replace('.', '/') + "/" + className + ".java")); comp.build(); return comp.getFactory().Package().get(packageName).getType(className); }
/** Builds the Spoon mode of the `filesToBuild` given as parameter */ public static Factory build(File... filesToBuild) { final Launcher launcher = new Launcher(); launcher.getEnvironment().setNoClasspath(true); SpoonModelBuilder comp = launcher.createCompiler(); for (File fileToBuild : filesToBuild) { try { comp.addInputSource(SpoonResourceHelper.createResource(fileToBuild)); } catch (FileNotFoundException e) { throw new RuntimeException("File not found", e); } } comp.build(); return comp.getFactory(); }
/** Utility method for testing: creates the model of `packageName` from src/test/java and returns the CtType corresponding to `className` */ public static <T extends CtType<?>> T build(String packageName, String className) throws Exception { Launcher launcher = new Launcher(); launcher.getEnvironment().setCommentEnabled(false); // we don't want to parse the comments for equals SpoonModelBuilder comp = launcher.createCompiler(); comp.addInputSources(SpoonResourceHelper.resources("./src/test/java/" + packageName.replace('.', '/') + "/" + className + ".java")); comp.build(); return comp.getFactory().Package().get(packageName).getType(className); }
Environment env = modelBuilder.getFactory().getEnvironment(); env.reportProgressMessage(getVersionMessage()); env.reportProgressMessage("running Spoon...");
public CtType getCtType(SpoonResource resource) { Factory factory = createFactory(); factory.getModel().setBuildModelIsFinished(false); SpoonModelBuilder compiler = new JDTBasedSpoonCompiler(factory); compiler.getFactory().getEnvironment().setLevel("OFF"); compiler.addInputSource(resource); compiler.build(); if (factory.Type().getAll().size() == 0) { return null; } // let's first take the first type. CtType type = factory.Type().getAll().get(0); // Now, let's ask to the factory the type (which it will set up the // corresponding // package) return factory.Type().get(type.getQualifiedName()); }
public CtType getCtType(SpoonResource resource) { Factory factory = createFactory(); factory.getModel().setBuildModelIsFinished(false); SpoonModelBuilder compiler = new JDTBasedSpoonCompiler(factory); compiler.getFactory().getEnvironment().setLevel("OFF"); compiler.addInputSource(resource); compiler.build(); if (factory.Type().getAll().size() == 0) { return null; } // let's first take the first type. CtType type = factory.Type().getAll().get(0); // Now, let's ask to the factory the type (which it will set up the // corresponding // package) return factory.Type().get(type.getQualifiedName()); }