JCodeModel cm = new JCodeModel(); JDefinedClass dc = cm._class("foo.Bar"); JMethod m = dc.method(0, int.class, "foo"); m.body()._return(JExpr.lit(5)); File file = new File("./target/classes"); file.mkdirs(); cm.build(file);
codeModel.build(directory);
CodeWriter sourcesWriter = new ScalaFileCodeWriter(config.getTargetDirectory(), config.getOutputEncoding()); CodeWriter resourcesWriter = new FileCodeWriterWithEncoding(config.getTargetDirectory(), config.getOutputEncoding()); codeModel.build(sourcesWriter, resourcesWriter); } else { CodeWriter sourcesWriter = new FileCodeWriterWithEncoding(config.getTargetDirectory(), config.getOutputEncoding()); CodeWriter resourcesWriter = new FileCodeWriterWithEncoding(config.getTargetDirectory(), config.getOutputEncoding()); codeModel.build(sourcesWriter, resourcesWriter);
@Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { cm = new JCodeModel(); for (TypeElement annotation : annotations) { for(javax.lang.model.element.Element d : roundEnv.getElementsAnnotatedWith(annotation)) { d.accept(visitor, null); } try { cm.build(new FilerCodeWriter(processingEnv.getFiler())); } catch (IOException e) { throw new Error(e); } } return true; }
private void generateSourceCode() throws IOException { List<Generator> generators = new ArrayList<Generator>(); generators.add(new MainActivityGenerator(appDetails)); if (appDetails.isViewPager() && !appDetails.isSample()) { generators.add(new ViewPagerAdapterGenerator(appDetails)); generators.add(new SampleFragmentGenerator(appDetails)); } if (appDetails.isRestTemplate() && appDetails.isAndroidAnnotations() && !appDetails.isSample()) { generators.add(new RestClientGenerator(appDetails)); } if (appDetails.isAcra() && !appDetails.isSample()) { generators.add(new ApplicationGenerator(appDetails)); } RefHelper refHelper = new RefHelper(jCodeModel); refHelper.r(appDetails.getR()); for (Generator generator : generators) { generator.generate(jCodeModel, refHelper); } jCodeModel.build(fileHelper.getTargetSourceDir()); }
@Override public void into(JCodeModel g) throws IOException { g.build(rootDirectory); } });
@Override public void into(JCodeModel g) throws IOException { g.build(rootDirectory); } });
/** * A convenience method for <code>build(out,out)</code>. */ public void build( CodeWriter out ) throws IOException { build(out,out); }
/** * A convenience method for <code>build(destDir,System.out)</code>. */ public void build( File destDir ) throws IOException { build(destDir,System.out); }
/** * Generates Java source code. * A convenience method for <code>build(destDir,destDir,System.out)</code>. * * @param destDir * source files are generated into this directory. * @param status * if non-null, progress indication will be sent to this stream. */ public void build( File destDir, PrintStream status ) throws IOException { build(destDir,destDir,status); }
/** * A convenience method for <code>build(destDir,System.out)</code>. */ public void build( File destDir ) throws IOException { build(destDir,System.out); }
/** * A convenience method for <code>build(out,out)</code>. */ public void build( CodeWriter out ) throws IOException { build(out,out); }
private void generate() throws IOException { CodeWriter codeWriter = new ProcessingEnvironmentCodeWriter(processingEnv); codeModel.build(codeWriter); } }
public void generate(final File targetFolder, final String comment) throws IOException { if (!targetFolder.exists()) { targetFolder.mkdirs(); } final CodeWriter sourceCodeWriter = new SourceCodeWriter(targetFolder, comment); final CodeWriter fileCodeWriter = new FileCodeWriter(targetFolder); this.codeModel.build(sourceCodeWriter, fileCodeWriter); }
public void generate(final File destDir) throws IOException { final PrintStream stream = new PrintStream(new NullStream()); try { model.build(destDir, stream); } finally { stream.close(); } }
public void write(CodeWriter codeWriter) throws IOException, BuildException { for (JAXBObjectBuilder builder : jaxbObjectBuilders.values()) { builder.write(); } buildContext.getCodeModel().build(codeWriter); }
SchemaCompiler sc = XJC.createSchemaCompiler(); File file = new File("D:\\my-dir\\my-schema.xsd"); sc.setErrorListener(... ); sc.parseSchema(new InputSource(file.toURI().toString())); S2JJAXBModel model = sc.bind(); JCodeModel cm = model.generateCode(null, null); cm.build(new File("."));
@Override public R innerRun(V value) { try { R result = worker.run(value); codeModel.build(codeWriter, resourceWriter); return result; } catch (IOException e) { throw new TransfuseRuntimeException("Unable to perform code generation", e); } } }
public void generate(ProcessResult processResult) throws IOException { SourceCodewriter sourceCodeWriter = new SourceCodewriter(filer, messager, processResult.originatingElementsByGeneratedClassQualifiedName); PrologCodeWriter prologCodeWriter = new PrologCodeWriter(sourceCodeWriter, "DO NOT EDIT THIS FILE, IT HAS BEEN GENERATED USING AndroidAnnotations.\n"); processResult.codeModel.build(prologCodeWriter, new ResourceCodeWriter(filer)); }
JCodeModel model = new JCodeModel(); JClass mapper = model.directClass("com.another.Mapper"); JClass factory = model.directClass("com.another.MapperSingleton"); JDefinedClass dc = model._class("com.example.Something"); JMethod method = dc.method(JMod.PUBLIC | JMod.STATIC, mapper, "testMethod"); method.body()._return(factory.staticInvoke("getMapperInstance")); model.build(destinationDirectory);