Java 类com.sun.codemodel.fmt.JTextFile 实例源码

项目:jaxb2-basics    文件:JaxbIndexPlugin.java   
@Override
public boolean run(Outline outline, Options opt, ErrorHandler errorHandler) {

    for (final PackageOutline packageOutline : outline
            .getAllPackageContexts()) {
        final StringBuilder sb = new StringBuilder();
        for (final ClassOutline classOutline : packageOutline.getClasses()) {
            sb.append(CodeModelUtils.getLocalClassName(classOutline.ref));
            sb.append("\n");
        }

        final JTextFile indexFile = new JTextFile("jaxb.index");
        indexFile.setContents(sb.toString());
        packageOutline._package().addResourceFile(indexFile);
    }
    return true;
}
项目:Avro-Schema-Generator    文件:AvroSchemagenPlugin.java   
private void outputSchema(JPackage avroPackage, List<NamedAvroType> types) {
    // set up the correct format for leading zeros (ensures proper order in filesystem)
    StringBuilder digits = new StringBuilder();
    for (int i=0; i < Integer.toString(types.size()).length(); ++i) {
        digits.append("0");
    }

    DecimalFormat format = new java.text.DecimalFormat(digits.toString());
    AtomicInteger counter = new AtomicInteger(1);

    for (NamedAvroType type : types) {
        String id = format.format(counter.getAndIncrement());
        JTextFile avroSchema = new JTextFile("avroSchema-"+ id +"_"+ type.name +".txt");
        avroSchema.setContents(getJson(type));
        avroPackage.addResourceFile(avroSchema);
    }
}
项目:jsonix-schema-compiler    文件:CodeModelProgramWriter.java   
private JTextFile createTextFile(String fileName, JSProgram... programs)
        throws IOException {
    Validate.notNull(fileName);
    final JTextFile textFile = new JTextFile(fileName);
    final StringWriter stringWriter = new StringWriter();
    final CodeWriter codeWriter = new CodeWriter(stringWriter);
    for (JSProgram program : programs) {
        codeWriter.program(program);
        codeWriter.lineTerminator();
    }
    textFile.setContents(stringWriter.toString());
    return textFile;
}
项目:jsonix-schema-compiler    文件:CodeModelJsonStructureWriter.java   
private JTextFile createTextFile(String fileName,
        JsonStructure jsonStructure) throws IOException {
    Validate.notNull(fileName);
    final JTextFile textFile = new JTextFile(fileName);
    final StringWriter stringWriter = new StringWriter();
    final JsonWriter jsonWriter = provider.createWriterFactory(
            Collections.singletonMap(JsonGenerator.PRETTY_PRINTING,
                    Boolean.TRUE)).createWriter(stringWriter);
    jsonWriter.write(jsonStructure);
    textFile.setContents(stringWriter.toString());
    return textFile;
}
项目:hyperjaxb3    文件:PersistenceMarshaller.java   
public void marshallPersistence(JCodeModel codeModel,
        Persistence persistence) throws Exception {

    // final JPackage defaultPackage = codeModel._package("");
    final JPackage metaInfPackage = codeModel._package("META-INF");

    final JTextFile persistenceXmlFile = new JTextFile("persistence.xml");

    metaInfPackage.addResourceFile(persistenceXmlFile);

    final Writer writer = new StringWriter();
    getMarshaller().marshal(persistence, writer);
    persistenceXmlFile.setContents(writer.toString());

}