当前位置: 首页>>代码示例>>Java>>正文


Java SingleStreamCodeWriter类代码示例

本文整理汇总了Java中com.sun.codemodel.writer.SingleStreamCodeWriter的典型用法代码示例。如果您正苦于以下问题:Java SingleStreamCodeWriter类的具体用法?Java SingleStreamCodeWriter怎么用?Java SingleStreamCodeWriter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SingleStreamCodeWriter类属于com.sun.codemodel.writer包,在下文中一共展示了SingleStreamCodeWriter类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateJava

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
private byte[] generateJava() throws Exception {
	
	JDefinedClass classModel = codeModel._class(JMod.PUBLIC | JMod.FINAL, className, ClassType.CLASS);
	Class<?> contractInterface = Class.forName(contractInterfaceName);
	classModel._implements(contractInterface);
          classModel._extends(AbstractDataTransferObject.class);
	
	List<FieldModel> fields = determineFields(contractInterface);
	
	renderConstantsClass(classModel);
	renderElementsClass(classModel, fields);
	renderClassLevelAnnotations(classModel, fields);
	renderFields(classModel, fields);
	renderFutureElementsField(classModel);			
	renderPrivateJaxbConstructor(classModel, fields);
	renderBuilderConstructor(classModel, fields);
	renderGetters(classModel, fields);
	renderBuilderClass(classModel, fields, contractInterface);

	ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
	codeModel.build(new SingleStreamCodeWriter(outputStream));
	return outputStream.toByteArray();
	
}
 
开发者ID:kuali,项目名称:kc-rice,代码行数:25,代码来源:ImmutableJaxbGenerator.java

示例2: test

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
/**
 * Test method for
 * {@link ServiceStubGenerator#generateStubInterface(Class, String, String, com.sun.codemodel.CodeWriter)}
 * .
 *
 * @throws NotRestInterfaceException
 * @throws Exception
 */
@Test
public void test() throws NotRestInterfaceException, Exception {
    @Cleanup
    final ByteArrayOutputStream out = new ByteArrayOutputStream();

    final SingleStreamCodeWriter writer = new SingleStreamCodeWriter(out);
    stubGenerator.generateStubInterface(TestWebserviceWithPath.class,
            TestWebserviceWithPath.class.getSimpleName() + "Stub", TestWebserviceWithPath.class
                    .getPackage().getName() + ".stub", writer);
    writer.close();

    assertEquals(FileUtils.readFileToString(
            new File("src/test/resources/com/strandls/alchemy/rest/client/stubgenerator"
                    + "/TestWebserviceWithPathStub.txt")).trim(), new String(out.toByteArray(),
            Charset.defaultCharset()).trim());
}
 
开发者ID:strandls,项目名称:alchemy-rest-client-generator,代码行数:25,代码来源:ServiceStubGeneratorTest.java

示例3: testGenericTypes

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
/**
 * Test method for
 * {@link ServiceStubGenerator#generateStubInterface(Class, String, String, com.sun.codemodel.CodeWriter)}
 * .
 *
 * Ensures generic types are handled correctly.
 *
 * @throws NotRestInterfaceException
 * @throws Exception
 */
@Test
public void testGenericTypes() throws NotRestInterfaceException, Exception {
    @Cleanup
    final ByteArrayOutputStream out = new ByteArrayOutputStream();

    final SingleStreamCodeWriter writer = new SingleStreamCodeWriter(out);
    stubGenerator.generateStubInterface(TestWebserviceWithGenericTypes.class,
            TestWebserviceWithGenericTypes.class.getSimpleName() + "Stub",
            TestWebserviceWithGenericTypes.class.getPackage().getName() + ".stub", writer);
    writer.close();
    System.out.println(new String(out.toByteArray(), Charset.defaultCharset()).trim());
    assertEquals(FileUtils.readFileToString(
            new File("src/test/resources/com/strandls/alchemy/rest/client/stubgenerator"
                    + "/TestWebserviceWithGenericTypes.txt")).trim(),
            new String(out.toByteArray(), Charset.defaultCharset()).trim());

}
 
开发者ID:strandls,项目名称:alchemy-rest-client-generator,代码行数:28,代码来源:ServiceStubGeneratorTest.java

示例4: testAnnotationImplements

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
public void testAnnotationImplements() throws Exception{
	JCodeModel jmod = new JCodeModel();
	
	// adding a test package
	JPackage pack = jmod._package("testAnnotationImplements");
	
	// building an interface 
	JDefinedClass interface1 = pack._interface("Interface1");

	// adding annotations
	JDefinedClass annotation1 = pack._annotationTypeDeclaration("Annot1");
	
	try{
		//this is perfectly legal in CodeModel:
		annotation1._implements(interface1);
		
		fail("No Exception was thrown for Illegal behavior");
	} catch ( IllegalArgumentException ie){
		
	}
	
	jmod.build(new SingleStreamCodeWriter(System.out));
}
 
开发者ID:tranchis,项目名称:jaob,代码行数:24,代码来源:SmallJModelTest.java

示例5: writeToString

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
public String writeToString(ITypeLibrary lib) {
	write(lib);
	ByteArrayOutputStream os = new ByteArrayOutputStream();
	CodeWriter wr = new SingleStreamCodeWriter(os);
	try {
		getModel().build(wr);
		return new String(os.toByteArray(), "UTF-8");
	} catch (IOException e) {
		throw new IllegalStateException();
	}
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:12,代码来源:JavaWriter.java

示例6: schemaHelper_ExtractsPojo_NestedUsingClasspath

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
@Test
  public void schemaHelper_ExtractsPojo_NestedUsingClasspath() throws Exception {
URL url = Resources.getResource(path + "A.json");
String text = Resources.toString(url, Charsets.UTF_8);
      ApiBodyMetadata mapSchemaToPojo = SchemaHelper.mapSchemaToPojo(null, text, "com.test", "Fallback", null);
      assertNotNull(mapSchemaToPojo);
      ByteArrayOutputStream bos = new ByteArrayOutputStream();
      
      try {
      	 mapSchemaToPojo.getCodeModel().build(new SingleStreamCodeWriter(bos));
      	 printModel(bos);
      } catch (IOException e) {
          assertThat(e.getMessage(), is(nullValue()));
      }
  }
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:16,代码来源:JsonSchema2PojoTest.java

示例7: serializeModel

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
protected String serializeModel(JCodeModel jCodeModel) {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {
        jCodeModel.build(new SingleStreamCodeWriter(bos));
    } catch (IOException e) {
        assertThat(e.getMessage(), is(nullValue()));
    }
    return bos.toString();
}
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:10,代码来源:AbstractRuleTestBase.java

示例8: serialiseModel

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
private String serialiseModel(JCodeModel codeModel) {
       ByteArrayOutputStream bos = new ByteArrayOutputStream();
	try {
		jCodeModel.build(new SingleStreamCodeWriter(bos));
		return bos.toString();
	} catch (IOException e) {
		//do nothing
	}
	return "";
}
 
开发者ID:phoenixnap,项目名称:springmvc-raml-plugin,代码行数:11,代码来源:RamlInterpreterTest.java

示例9: testNestedAnnotations

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
/**
 * Adding nested Annotations in JModel
 * @throws Exception
 */
// unused
//@Test
public void testNestedAnnotations() throws Exception{
	JCodeModel jmod = new JCodeModel();
	
	// adding a test package
	JPackage pack = jmod._package("testNestedAnnotations");
	
	// building an interface 
	JDefinedClass interface1 = pack._interface("Interface1");

	// adding annotations
	JDefinedClass annotation1 = pack._annotationTypeDeclaration("Annot1");
	JDefinedClass annotation2 = pack._annotationTypeDeclaration("Annot2");
	
	// adding a method for annotation2
	annotation1.method(JMod.NONE, String.class, "value");
	
	//adding a method which has an annotation as type to annotation1
	annotation2.method(JMod.NONE, annotation1.array(), "value");

	// add an annotation to the Interface
	JAnnotationArrayMember paramarray = interface1.annotate(annotation2).paramArray("value");
	paramarray.annotate(annotation1).param("value", "a");
	//paramarray.annotate(annotation1).param("value", "b");
	//paramarray.annotate(annotation1).param("value", "c");
	
	jmod.build(new SingleStreamCodeWriter(System.out));

}
 
开发者ID:tranchis,项目名称:jaob,代码行数:35,代码来源:SmallJModelTest.java

示例10: generate

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
public void generate(final OutputStream ouputStream) throws IOException {
  this.codeModel.build(new SingleStreamCodeWriter(ouputStream));
}
 
开发者ID:AndreasWBartels,项目名称:libraries,代码行数:4,代码来源:BeanGenerator.java

示例11: write

import com.sun.codemodel.writer.SingleStreamCodeWriter; //导入依赖的package包/类
public void write(OutputStream outputstream)
	throws java.io.IOException
{
	this.model.build(new SingleStreamCodeWriter(outputstream));
}
 
开发者ID:BrainTech,项目名称:jsignalml,代码行数:6,代码来源:JavaClassGen.java


注:本文中的com.sun.codemodel.writer.SingleStreamCodeWriter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。