本文整理汇总了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));
}
示例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;
}
示例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));
}