private JDefinedClass buildTemplateConstraint(String name) {
try {
JDefinedClass tplConstraint = codeModel._class(Config.CFG.getBasePackageName() + ".annot."+name, ClassType.ANNOTATION_TYPE_DECL);
tplConstraint.annotate(Documented.class);
tplConstraint.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
tplConstraint.annotate(Target.class).paramArray("value").param(ElementType.TYPE).param(ElementType.ANNOTATION_TYPE).param(ElementType.FIELD).param(ElementType.METHOD);
// Using direct as I don't know how to build default { } with code model
tplConstraint.direct("\n" + " Class<?>[] groups() default {};\n" + " String message() default \"Invalid value\";\n" + " Class<? extends Payload>[] payload() default {};\n");
// Hack to force the import of javax.validation.Payload
tplConstraint.javadoc().addThrows((JClass) codeModel._ref(Payload.class)).add("Force import");
return tplConstraint;
} catch (JClassAlreadyExistsException e) {
throw new RuntimeException("Tried to create an already existing class: " + name, e);
}
}
java类java.lang.annotation.Documented的实例源码
Jsr303Annotator.java 文件源码
项目:beanvalidation-benchmark
阅读 29
收藏 0
点赞 0
评论 0
NoPrivateTypesExported.java 文件源码
项目:openjdk-jdk10
阅读 31
收藏 0
点赞 0
评论 0
private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations,
Set<String> acceptable) {
for (AnnotationMirror mirror : annotations) {
Element annotationElement = mirror.getAnnotationType().asElement();
if (annotationElement.getAnnotation(Documented.class) == null) {
note("Ignoring undocumented annotation: " + mirror.getAnnotationType());
}
verifyTypeAcceptable(mirror.getAnnotationType(), acceptable);
for (AnnotationValue value : mirror.getElementValues().values()) {
verifyAnnotationValue(value, acceptable);
}
}
}
NoPrivateTypesExported.java 文件源码
项目:openjdk9
阅读 35
收藏 0
点赞 0
评论 0
private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations,
Set<String> acceptable) {
for (AnnotationMirror mirror : annotations) {
Element annotationElement = mirror.getAnnotationType().asElement();
if (annotationElement.getAnnotation(Documented.class) == null) {
note("Ignoring undocumented annotation: " + mirror.getAnnotationType());
}
verifyTypeAcceptable(mirror.getAnnotationType(), acceptable);
for (AnnotationValue value : mirror.getElementValues().values()) {
verifyAnnotationValue(value, acceptable);
}
}
}
AnnotationMetadataTests.java 文件源码
项目:spring4-understanding
阅读 39
收藏 0
点赞 0
评论 0
private void doTestMetadataForAnnotationClass(AnnotationMetadata metadata) {
assertThat(metadata.getClassName(), is(Component.class.getName()));
assertThat(metadata.isInterface(), is(true));
assertThat(metadata.isAnnotation(), is(true));
assertThat(metadata.isAbstract(), is(true));
assertThat(metadata.isConcrete(), is(false));
assertThat(metadata.hasSuperClass(), is(false));
assertThat(metadata.getSuperClassName(), nullValue());
assertThat(metadata.getInterfaceNames().length, is(1));
assertThat(metadata.getInterfaceNames()[0], is(Annotation.class.getName()));
assertThat(metadata.isAnnotated(Documented.class.getName()), is(false));
assertThat(metadata.isAnnotated(Scope.class.getName()), is(false));
assertThat(metadata.isAnnotated(SpecialAttr.class.getName()), is(false));
assertThat(metadata.hasAnnotation(Documented.class.getName()), is(true));
assertThat(metadata.hasAnnotation(Scope.class.getName()), is(false));
assertThat(metadata.hasAnnotation(SpecialAttr.class.getName()), is(false));
assertThat(metadata.getAnnotationTypes().size(), is(3));
}
NoPrivateTypesExported.java 文件源码
项目:lookaside_java-1.8.0-openjdk
阅读 27
收藏 0
点赞 0
评论 0
private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations,
Set<String> acceptable) {
for (AnnotationMirror mirror : annotations) {
Element annotationElement = mirror.getAnnotationType().asElement();
if (annotationElement.getAnnotation(Documented.class) == null) {
note("Ignoring undocumented annotation: " + mirror.getAnnotationType());
}
verifyTypeAcceptable(mirror.getAnnotationType(), acceptable);
for (AnnotationValue value : mirror.getElementValues().values()) {
verifyAnnotationValue(value, acceptable);
}
}
}
NoPrivateTypesExported.java 文件源码
项目:jsr308-langtools
阅读 31
收藏 0
点赞 0
评论 0
private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations,
Set<String> acceptable) {
for (AnnotationMirror mirror : annotations) {
Element annotationElement = mirror.getAnnotationType().asElement();
if (annotationElement.getAnnotation(Documented.class) == null) {
note("Ignoring undocumented annotation: " + mirror.getAnnotationType());
}
verifyTypeAcceptable(mirror.getAnnotationType(), acceptable);
for (AnnotationValue value : mirror.getElementValues().values()) {
verifyAnnotationValue(value, acceptable);
}
}
}
ReflectAllInOneCreator.java 文件源码
项目:gwt-backbone
阅读 43
收藏 0
点赞 0
评论 0
private void getAllReflectionClasses() throws NotFoundException{
//System annotations
addClassIfNotExists(typeOracle.getType(Retention.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
addClassIfNotExists(typeOracle.getType(Documented.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
addClassIfNotExists(typeOracle.getType(Inherited.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
addClassIfNotExists(typeOracle.getType(Target.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
addClassIfNotExists(typeOracle.getType(Deprecated.class.getCanonicalName()), ReflectableHelper.getDefaultSettings(typeOracle));
//typeOracle.getType("org.lirazs.gbackbone.client.test.reflection.TestReflectionGenerics.TestReflection1");
//=====GWT0.7
for (JClassType classType : typeOracle.getTypes()) {
Reflectable reflectable = GenUtils.getClassTypeAnnotationWithMataAnnotation(classType, Reflectable.class);
if (reflectable != null){
processClass(classType, reflectable);
if (reflectable.assignableClasses()){
for (JClassType type : classType.getSubtypes()){
processClass(type, reflectable);
}
}
}
}
//======end of gwt0.7
}
ClasspathScannerTest.java 文件源码
项目:dolphin-platform
阅读 40
收藏 0
点赞 0
评论 0
@Test
public void testScanOtherPackage() {
//There can't be a class that is annotated with Inject
final DefaultClasspathScanner scanner = new DefaultClasspathScanner(CLASSPATH_SCAN);
Set<Class<?>> classes = scanner.getTypesAnnotatedWith(Resources.class);
assertNotNull(classes);
assertEquals(classes.size(), 0);
classes = scanner.getTypesAnnotatedWith(AnnotationForClasspathScanTest.class);
assertNotNull(classes);
assertEquals(classes.size(), 0);
classes = scanner.getTypesAnnotatedWith(Documented.class);
assertNotNull(classes);
assertEquals(classes.size(), 1);
assertTrue(classes.contains(DocumentAnnotatedClass.class));
}
NoPrivateTypesExported.java 文件源码
项目:infobip-open-jdk-8
阅读 31
收藏 0
点赞 0
评论 0
private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations,
Set<String> acceptable) {
for (AnnotationMirror mirror : annotations) {
Element annotationElement = mirror.getAnnotationType().asElement();
if (annotationElement.getAnnotation(Documented.class) == null) {
note("Ignoring undocumented annotation: " + mirror.getAnnotationType());
}
verifyTypeAcceptable(mirror.getAnnotationType(), acceptable);
for (AnnotationValue value : mirror.getElementValues().values()) {
verifyAnnotationValue(value, acceptable);
}
}
}
CompositeOperatorEstimatorTest.java 文件源码
项目:asakusafw-compiler
阅读 33
收藏 0
点赞 0
评论 0
/**
* user operators.
*/
@Test
public void user() {
OperatorEstimator estimator = CompositeOperatorEstimator.builder()
.withUser(Deprecated.class, engine("a"))
.withUser(Documented.class, engine("b"))
.build();
Operator o0 = user(classOf(Deprecated.class));
Operator o1 = user(classOf(Documented.class));
Operator o2 = user(clazz("Unknown"));
OperatorEstimate e0 = perform(context(), estimator, o0);
OperatorEstimate e1 = perform(context(), estimator, o1);
OperatorEstimate e2 = perform(context(), estimator, o2);
assertThat(e0, hasMark("a"));
assertThat(e1, hasMark("b"));
assertThat(e2, hasMark(null));
}
ClassDepsParserTest.java 文件源码
项目:jadecy
阅读 35
收藏 0
点赞 0
评论 0
public void test_computeDependencies_packageInfo() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
if (apiOnly) {
} else {
addSlashedName(expected, TestAnno1.class);
addSlashedName(expected, TestAnno2.class);
addSlashedName(expected, Object.class);
// String doesn't make it into the class file,
// only types of other arguments.
addSlashedName(expected, Integer.class);
addSlashedName(expected, RoundingMode.class);
addSlashedName(expected, Documented.class);
}
computeDepsAndCheck(TestAnno1.class.getPackage().getName() + ".package-info", apiOnly, expected);
}
}
ClassDepsParserTest.java 文件源码
项目:jadecy
阅读 34
收藏 0
点赞 0
评论 0
public void test_computeDependencies_methodCodeStaticInitBlock() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
addSlashedName(expected, Object.class);
//
if (apiOnly) {
} else {
addSlashedName(expected, ClassDepsParserTest.class);
//
if (BUG_JDK_8136419_FIXED) {
addSlashedName(expected, A_TYPE_USE_R_COMPLEX.class);
addSlashedName(expected, Long.class);
addSlashedName(expected, RoundingMode.class);
addSlashedName(expected, Documented.class);
}
addSlashedName(expected, Integer.class);
addSlashedName(expected, MyBlackHole.class);
addSlashedName(expected, RuntimeException.class);
}
computeDepsAndCheck(MyMethodCodeStaticInitBlock.class.getName(), apiOnly, expected);
}
}
ClassDepsParserTest.java 文件源码
项目:jadecy
阅读 37
收藏 0
点赞 0
评论 0
public void test_computeDependencies_methodCodeInitBlock() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
addSlashedName(expected, Object.class);
//
if (apiOnly) {
} else {
addSlashedName(expected, ClassDepsParserTest.class);
//
if (BUG_JDK_8136419_FIXED) {
addSlashedName(expected, A_TYPE_USE_R_COMPLEX.class);
addSlashedName(expected, Long.class);
addSlashedName(expected, RoundingMode.class);
addSlashedName(expected, Documented.class);
}
addSlashedName(expected, Integer.class);
addSlashedName(expected, MyBlackHole.class);
addSlashedName(expected, RuntimeException.class);
}
computeDepsAndCheck(MyMethodCodeInitBlock.class.getName(), apiOnly, expected);
}
}
ClassDepsParserTest.java 文件源码
项目:jadecy
阅读 38
收藏 0
点赞 0
评论 0
public void test_computeDependencies_methodCodeConstructor() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
addSlashedName(expected, Object.class);
//
if (apiOnly) {
} else {
addSlashedName(expected, ClassDepsParserTest.class);
//
addSlashedName(expected, A_TYPE_USE_R_COMPLEX.class);
addSlashedName(expected, Long.class);
addSlashedName(expected, RoundingMode.class);
addSlashedName(expected, Documented.class);
addSlashedName(expected, Integer.class);
addSlashedName(expected, MyBlackHole.class);
addSlashedName(expected, RuntimeException.class);
}
computeDepsAndCheck(MyMethodCodeConstructor.class.getName(), apiOnly, expected);
}
}
ClassDepsParserTest.java 文件源码
项目:jadecy
阅读 31
收藏 0
点赞 0
评论 0
public void test_computeDependencies_methodCodeNonGen() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
addSlashedName(expected, Object.class);
//
if (apiOnly) {
} else {
addSlashedName(expected, ClassDepsParserTest.class);
//
addSlashedName(expected, A_TYPE_USE_R_COMPLEX.class);
addSlashedName(expected, Long.class);
addSlashedName(expected, RoundingMode.class);
addSlashedName(expected, Documented.class);
addSlashedName(expected, Integer.class);
addSlashedName(expected, MyBlackHole.class);
addSlashedName(expected, RuntimeException.class);
}
computeDepsAndCheck(MyMethodCodeNonGen.class.getName(), apiOnly, expected);
}
}
ClassDepsParserTest.java 文件源码
项目:jadecy
阅读 36
收藏 0
点赞 0
评论 0
public void test_computeDependencies_methodCodeGenStrict() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
addSlashedName(expected, Object.class);
//
if (apiOnly) {
} else {
addSlashedName(expected, ClassDepsParserTest.class);
//
addSlashedName(expected, A_TYPE_USE_R_COMPLEX.class);
addSlashedName(expected, Long.class);
addSlashedName(expected, RoundingMode.class);
addSlashedName(expected, Documented.class);
addSlashedName(expected, Comparable.class);
addSlashedName(expected, MyBlackHole.class);
addSlashedName(expected, RuntimeException.class);
}
computeDepsAndCheck(MyMethodCodeGenStrict.class.getName(), apiOnly, expected);
}
}
ClassDepsParserTest.java 文件源码
项目:jadecy
阅读 33
收藏 0
点赞 0
评论 0
public void test_computeDependencies_methodCodeGenLoose() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
addSlashedName(expected, Object.class);
//
if (apiOnly) {
} else {
addSlashedName(expected, ClassDepsParserTest.class);
//
addSlashedName(expected, A_TYPE_USE_R_COMPLEX.class);
addSlashedName(expected, Long.class);
addSlashedName(expected, RoundingMode.class);
addSlashedName(expected, Documented.class);
addSlashedName(expected, Comparable.class);
addSlashedName(expected, MyBlackHole.class);
addSlashedName(expected, RuntimeException.class);
}
computeDepsAndCheck(MyMethodCodeGenLoose.class.getName(), apiOnly, expected);
}
}
NoPrivateTypesExported.java 文件源码
项目:OLD-OpenJDK8
阅读 27
收藏 0
点赞 0
评论 0
private void verifyAnnotations(Iterable<? extends AnnotationMirror> annotations,
Set<String> acceptable) {
for (AnnotationMirror mirror : annotations) {
Element annotationElement = mirror.getAnnotationType().asElement();
if (annotationElement.getAnnotation(Documented.class) == null) {
note("Ignoring undocumented annotation: " + mirror.getAnnotationType());
}
verifyTypeAcceptable(mirror.getAnnotationType(), acceptable);
for (AnnotationValue value : mirror.getElementValues().values()) {
verifyAnnotationValue(value, acceptable);
}
}
}
Class1_5Test.java 文件源码
项目:cn1
阅读 36
收藏 0
点赞 0
评论 0
/**
*
*/
public void test_isAnnotationPresent_Cla() {
class e {};
assertFalse("zzz annotation is not presented for e class!",
e.class.isAnnotationPresent(zzz.class));
assertFalse("zzz annotation is not presented for zzz class!",
zzz.class.isAnnotationPresent(zzz.class));
assertTrue("Target annotation is presented for zzz class!",
zzz.class.isAnnotationPresent(java.lang.annotation
.Target.class));
assertTrue("Documented annotation is presented for zzz class!",
zzz.class.isAnnotationPresent(java.lang.annotation
.Documented.class));
assertTrue("Retention annotation is presented for zzz class!",
zzz.class.isAnnotationPresent(java.lang.annotation
.Retention.class));
}
Class1_5Test.java 文件源码
项目:cn1
阅读 31
收藏 0
点赞 0
评论 0
/**
*
*/
public void test_getAnnotation_Cla() {
class e {};
assertNull("zzz annotation is not presented in e class!",
e.class.getAnnotation(zzz.class));
assertNull("zzz annotation is not presented in zzz class!",
zzz.class.getAnnotation(zzz.class));
assertFalse("Target annotation is presented in zzz class!",
zzz.class.getAnnotation(java.lang.annotation.Target.class)
.toString().indexOf("java.lang.annotation.Target") == -1);
assertFalse("Documented annotation is presented in zzz class!",
zzz.class.getAnnotation(java.lang.annotation.Documented.class)
.toString().indexOf("java.lang.annotation.Documented") == -1);
assertFalse("Retention annotation is presented in zzz class!",
zzz.class.getAnnotation(java.lang.annotation.Retention.class)
.toString().indexOf("java.lang.annotation.Retention") == -1);
}
Class1_5Test.java 文件源码
项目:freeVM
阅读 38
收藏 0
点赞 0
评论 0
/**
*
*/
public void test_isAnnotationPresent_Cla() {
class e {};
assertFalse("zzz annotation is not presented for e class!",
e.class.isAnnotationPresent(zzz.class));
assertFalse("zzz annotation is not presented for zzz class!",
zzz.class.isAnnotationPresent(zzz.class));
assertTrue("Target annotation is presented for zzz class!",
zzz.class.isAnnotationPresent(java.lang.annotation
.Target.class));
assertTrue("Documented annotation is presented for zzz class!",
zzz.class.isAnnotationPresent(java.lang.annotation
.Documented.class));
assertTrue("Retention annotation is presented for zzz class!",
zzz.class.isAnnotationPresent(java.lang.annotation
.Retention.class));
}
Class1_5Test.java 文件源码
项目:freeVM
阅读 32
收藏 0
点赞 0
评论 0
/**
*
*/
public void test_getAnnotation_Cla() {
class e {};
assertNull("zzz annotation is not presented in e class!",
e.class.getAnnotation(zzz.class));
assertNull("zzz annotation is not presented in zzz class!",
zzz.class.getAnnotation(zzz.class));
assertFalse("Target annotation is presented in zzz class!",
zzz.class.getAnnotation(java.lang.annotation.Target.class)
.toString().indexOf("java.lang.annotation.Target") == -1);
assertFalse("Documented annotation is presented in zzz class!",
zzz.class.getAnnotation(java.lang.annotation.Documented.class)
.toString().indexOf("java.lang.annotation.Documented") == -1);
assertFalse("Retention annotation is presented in zzz class!",
zzz.class.getAnnotation(java.lang.annotation.Retention.class)
.toString().indexOf("java.lang.annotation.Retention") == -1);
}
ProcessorUtil.java 文件源码
项目:react4j
阅读 40
收藏 0
点赞 0
评论 0
static void copyDocumentedAnnotations( @Nonnull final AnnotatedConstruct element,
@Nonnull final MethodSpec.Builder builder )
{
for ( final AnnotationMirror annotation : element.getAnnotationMirrors() )
{
final DeclaredType annotationType = annotation.getAnnotationType();
if ( !annotationType.toString().startsWith( "react4j.annotations." ) &&
null != annotationType.asElement().getAnnotation( Documented.class ) )
{
builder.addAnnotation( AnnotationSpec.get( annotation ) );
}
}
}
ProcessorUtil.java 文件源码
项目:react4j
阅读 31
收藏 0
点赞 0
评论 0
static void copyDocumentedAnnotations( @Nonnull final AnnotatedConstruct element,
@Nonnull final ParameterSpec.Builder builder )
{
for ( final AnnotationMirror annotation : element.getAnnotationMirrors() )
{
if ( null != annotation.getAnnotationType().asElement().getAnnotation( Documented.class ) )
{
builder.addAnnotation( AnnotationSpec.get( annotation ) );
}
}
}
Utils.java 文件源码
项目:openjdk-jdk10
阅读 30
收藏 0
点赞 0
评论 0
/**
* Given an annotation, return true if it should be documented and false
* otherwise.
*
* @param annotation the annotation to check.
*
* @return true return true if it should be documented and false otherwise.
*/
public boolean isDocumentedAnnotation(TypeElement annotation) {
for (AnnotationMirror anno : annotation.getAnnotationMirrors()) {
if (getFullyQualifiedName(anno.getAnnotationType().asElement()).equals(
Documented.class.getName())) {
return true;
}
}
return false;
}
ProcessorUtil.java 文件源码
项目:arez
阅读 44
收藏 0
点赞 0
评论 0
static void copyDocumentedAnnotations( @Nonnull final AnnotatedConstruct element,
@Nonnull final MethodSpec.Builder builder )
{
for ( final AnnotationMirror annotation : element.getAnnotationMirrors() )
{
final DeclaredType annotationType = annotation.getAnnotationType();
if ( !annotationType.toString().startsWith( "arez.annotations." ) &&
null != annotationType.asElement().getAnnotation( Documented.class ) )
{
builder.addAnnotation( AnnotationSpec.get( annotation ) );
}
}
}
ProcessorUtil.java 文件源码
项目:arez
阅读 41
收藏 0
点赞 0
评论 0
static void copyDocumentedAnnotations( @Nonnull final AnnotatedConstruct element,
@Nonnull final ParameterSpec.Builder builder )
{
for ( final AnnotationMirror annotation : element.getAnnotationMirrors() )
{
if ( null != annotation.getAnnotationType().asElement().getAnnotation( Documented.class ) )
{
builder.addAnnotation( AnnotationSpec.get( annotation ) );
}
}
}
Utils.java 文件源码
项目:openjdk9
阅读 28
收藏 0
点赞 0
评论 0
/**
* Given an annotation, return true if it should be documented and false
* otherwise.
*
* @param annotation the annotation to check.
*
* @return true return true if it should be documented and false otherwise.
*/
public boolean isDocumentedAnnotation(TypeElement annotation) {
for (AnnotationMirror anno : annotation.getAnnotationMirrors()) {
if (getFullyQualifiedName(anno.getAnnotationType().asElement()).equals(
Documented.class.getName())) {
return true;
}
}
return false;
}
Utils.java 文件源码
项目:openjdk9
阅读 28
收藏 0
点赞 0
评论 0
/**
* Given an annotation, return true if it should be documented and false
* otherwise.
*
* @param annotationDoc the annotation to check.
*
* @return true return true if it should be documented and false otherwise.
*/
public boolean isDocumentedAnnotation(AnnotationTypeDoc annotationDoc) {
for (AnnotationDesc anno : annotationDoc.annotations()) {
if (anno.annotationType().qualifiedName().equals(
Documented.class.getName())) {
return true;
}
}
return false;
}
ClassUtilsTests.java 文件源码
项目:cp-elements
阅读 37
收藏 0
点赞 0
评论 0
@Test
public void isNotArray() {
assertFalse(ClassUtils.isArray(null));
assertFalse(ClassUtils.isArray(Object.class));
assertFalse(ClassUtils.isArray(Documented.class));
assertFalse(ClassUtils.isArray(Object.class));
assertFalse(ClassUtils.isArray(Thread.State.class));
assertFalse(ClassUtils.isArray(Cloneable.class));
assertFalse(ClassUtils.isArray(Integer.TYPE));
}