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


Java JPackage._annotationTypeDeclaration方法代码示例

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


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

示例1: testAnnotationImplements

import com.sun.codemodel.JPackage; //导入方法依赖的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

示例2: createCustomHttpMethodAnnotation

import com.sun.codemodel.JPackage; //导入方法依赖的package包/类
private JDefinedClass createCustomHttpMethodAnnotation(final String httpMethod)
    throws JClassAlreadyExistsException
{
    final JPackage pkg = codeModel._package(getSupportPackage());
    final JDefinedClass annotationClazz = pkg._annotationTypeDeclaration(httpMethod);
    annotationClazz.annotate(Target.class).param("value", ElementType.METHOD);
    annotationClazz.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
    annotationClazz.annotate(HttpMethod.class).param("value", httpMethod);
    annotationClazz.javadoc().add("Custom JAX-RS support for HTTP " + httpMethod + ".");
    httpMethodAnnotations.put(httpMethod.toUpperCase(), annotationClazz);
    return annotationClazz;
}
 
开发者ID:OnPositive,项目名称:aml,代码行数:13,代码来源:Context.java

示例3: testNestedAnnotations

import com.sun.codemodel.JPackage; //导入方法依赖的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


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