com.sun.codemodel.fmt.JTextFile Java Examples

The following examples show how to use com.sun.codemodel.fmt.JTextFile. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JaxbIndexPlugin.java    From jaxb2-basics with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@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;
}
 
Example #2
Source File: AvroSchemagenPlugin.java    From Avro-Schema-Generator with Apache License 2.0 6 votes vote down vote up
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);
	}
}
 
Example #3
Source File: CodeModelProgramWriter.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #4
Source File: CodeModelJsonStructureWriter.java    From jsonix-schema-compiler with BSD 2-Clause "Simplified" License 5 votes vote down vote up
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;
}
 
Example #5
Source File: PersistenceMarshaller.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 3 votes vote down vote up
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());

}