项目:GitHub
文件:Annotations.java
static boolean annotationMatchesTarget(Element annotationElement,ElementType elementType) {
@Nullable Target target = annotationElement.getAnnotation(Target.class);
if (target != null) {
ElementType[] targettypes = target.value();
if (targettypes.length == 0) {
return false;
}
boolean found = false;
for (ElementType t : targettypes) {
if (t == elementType) {
found = true;
}
}
if (!found) {
return false;
}
}
return true;
}
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);
}
}
项目:openjdk9
文件:Utils.java
/**
* Returns true if the {@code annotationDoc} is to be treated
* as a declaration annotation,when targeting the
* {@code elemType} element type.
*
* @param annotationDoc the annotationDoc to check
* @param elemType the targeted elemType
* @return true if annotationDoc is a declaration annotation
*/
public boolean isDeclarationAnnotation(AnnotationTypeDoc annotationDoc,boolean isJava5DeclarationLocation) {
if (!isJava5DeclarationLocation)
return false;
AnnotationDesc[] annotationDescList = annotationDoc.annotations();
// Annotations with no target are treated as declaration as well
if (annotationDescList.length==0)
return true;
for (AnnotationDesc anno : annotationDescList) {
if (anno.annotationType().qualifiedname().equals(
Target.class.getName())) {
if (isDeclarationTarget(anno))
return true;
}
}
return false;
}
项目:xtext-extras
文件:XAnnotationUtil.java
public Set<ElementType> getAnnotationTargets(JvmAnnotationType annotation) {
EList<JvmAnnotationReference> annotations = annotation.getAnnotations();
for (JvmAnnotationReference annoref : annotations) {
if (Target.class.getName().equals(annoref.getAnnotation().getIdentifier())) {
EList<JvmAnnotationValue> values = annoref.getValues();
JvmAnnotationValue value = values.isEmpty() ? null : values.get(0);
if (value instanceof JvmEnumAnnotationValue) {
Set<ElementType> result = newHashSet();
for (JvmEnumerationLiteral elementType : ((JvmEnumAnnotationValue) value).getValues()) {
final String simpleName = elementType.getSimpleName();
result.add(ElementType.valueOf(simpleName));
}
return result;
}
}
}
return emptySet();
}
项目:listing
文件:JavaMirrorsTest.java
@Test
void rootAnnotation() {
compilationunit unit = compilationunit.of("test");
Annotation annotation = Annotation.of(All.class);
annotation.addobject("o",Annotation.of(Target.class,ElementType.TYPE));
annotation.addobject("p",4711);
annotation.addobject("r",Double.class);
annotation.addobject("r",Float.class);
normalClassDeclaration type = unit.declareClass("Root");
type.addAnnotation(annotation);
type.addTypeParameter(TypeParameter.of("X"));
mark(type.declareField(TypeVariable.of("X"),"i"));
Counter counter = new Counter();
Compilation.compile(null,emptyList(),asList(counter),asList(unit.toJavaFileObject()));
assertEquals(1,counter.annotations.size());
assertEquals(annotation.list(),counter.annotations.get(0).list());
}
@Test
public void loadAndCheckAnnotatedAnnotation() throws Exception {
ClassInfo classInfo = ClassInfo.newAnnotation()
.name("org.kordamp.naum.processor.klass.AnnotatedAnnotation")
.iface(Annotation.class.getName())
.build();
classInfo.addToAnnotations(annotationInfo()
.name(Retention.class.getName())
.annotationValue("value",new EnumValue(RetentionPolicy.class.getName(),"SOURCE"))
.build());
classInfo.addToAnnotations(annotationInfo()
.name(Target.class.getName())
.annotationValue("value",newArrayValue(asList(
newEnumValue(ElementType.class.getName(),ElementType.TYPE.name()),newEnumValue(ElementType.class.getName(),ElementType.FIELD.name()))
))
.build());
loadAndCheck("org/kordamp/naum/processor/klass/AnnotatedAnnotation.class",(klass) -> {
assertthat(klass.getContentHash(),equalTo(classInfo.getContentHash()));
assertthat(klass,equalTo(classInfo));
});
}
项目:JavaZone
文件:TestMain.java
private static void annotationTypeAnnotation() {
// @Target这个就是 此类型
ClassBinds classBinds = Test.class.getAnnotation(ClassBinds.class);
if (classBinds != null) {
Annotation[] annotations = classBinds.annotationType().getAnnotations();
Target target = classBinds.annotationType().getAnnotation(Target.class);
if (target != null)
System.out.print("ANNOTATION_TYPE---->targets:" );
for (ElementType elementType : target.value()) {
System.out.print("\t elementType:"+elementType);
}
System.out.println();
}
}
项目:gwt-backbone
文件:ReflectAllInOneCreator.java
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
}
项目:feilong-spring
文件:JoinPointUtilTest.java
/**
* 获得 method.
*
* @param joinPoint
* the join point
* @param klass
* the klass
* @return the method
* @deprecated 目前作用不大,将来会重构
*/
@Deprecated
protected Method getmethod(JoinPoint joinPoint,Class<? extends Annotation> klass){
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getmethod();
if (method.isAnnotationPresent(klass)){
return method;
}
Target annotation = klass.getAnnotation(Target.class);
ElementType[] value = annotation.value();
try{
Object target = joinPoint.getTarget();
Class<? extends Object> targetClass = target.getClass();
String methodName = method.getName();
Class<?>[] parameterTypes = method.getParameterTypes();
Method m1 = targetClass.getmethod(methodName,parameterTypes);
if (m1.isAnnotationPresent(klass)){
return m1;
}
}catch (Exception e){
LOGGER.error(e.getClass().getName(),e);
}
throw new RuntimeException("No Proper annotation found.");
}
项目:feilong-spring
文件:JoinPointUtilTest.java
/**
* Checks if is annotation present.
*
* @param joinPoint
* the join point
* @param klass
* the klass
* @return true,if checks if is annotation present
* @deprecated 目前作用不大,将来会重构
*/
@Deprecated
protected boolean isAnnotationPresent(JoinPoint joinPoint,Class<? extends Annotation> klass){
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature.getmethod();
if (method.isAnnotationPresent(klass)){
return true;
}
Target annotation = klass.getAnnotation(Target.class);
ElementType[] value = annotation.value();
try{
Object target = joinPoint.getTarget();
Class<? extends Object> targetClass = target.getClass();
String methodName = method.getName();
Class<?>[] parameterTypes = method.getParameterTypes();
Method m1 = targetClass.getmethod(methodName,parameterTypes);
if (m1.isAnnotationPresent(klass)){
return true;
}
}catch (Exception e){
LOGGER.error(e.getClass().getName(),e);
}
return false;
}
项目:autodata
文件:AutoDataAnnotationProcessor.java
@Nullable
private static Class<Annotation> getDeclaredAnnotationClass(AnnotationMirror mirror) throws ClassNotFoundException {
TypeElement element = (TypeElement) mirror.getAnnotationType().asElement();
// Ensure the annotation has the correct retention and targets.
Retention retention = element.getAnnotation(Retention.class);
if (retention != null && retention.value() != RetentionPolicy.RUNTIME) {
return null;
}
Target target = element.getAnnotation(Target.class);
if (target != null) {
if (target.value().length < 2) {
return null;
}
List<ElementType> targets = Arrays.asList(target.value());
if (!(targets.contains(ElementType.TYPE) && targets.contains(ElementType.ANNOTATION_TYPE))) {
return null;
}
}
return (Class<Annotation>) Class.forName(element.getQualifiedname().toString());
}
@Override
public final Description matchClass(Classtree classtree,VisitorState state) {
if (ANNOTATION_WITH_ScopE_AND_TARGET.matches(classtree,state)) {
MultiMatchResult<AnnotationTree> targetAnnotation =
HAS_TARGET_ANNOTATION.multiMatchResult(classtree,state);
if (targetAnnotation.matches()) {
AnnotationTree targetTree = targetAnnotation.onlyMatchingNode();
Target target = getAnnotation(classtree,Target.class);
if (target != null
&& // Unlikely to occur,but just in case Target isn't on the classpath.
!Arrays.asList(target.value()).containsAll(required_ELEMENT_TYPES)) {
return describeMatch(targetTree,replaceTargetAnnotation(target,targetTree));
}
}
}
return Description.NO_MATCH;
}
@MyRuntimeAnnotation(
intValue = 456,strValue = "test",enumValue = ElementType.METHOD,classValue = String.class,annotationValue = @Target({ElementType.METHOD}),arrayValue = {"X","Y","Z"}
)
@MyClassAnnotation(
intValue = 456,annotationValue = @Target({}),"Z"}
)
public void testMethodAnnotations() {
}
项目:cn1
文件:Class1_5Test.java
/**
*
*/
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));
}
项目:cn1
文件:Class1_5Test.java
/**
*
*/
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);
}
项目:mqnaas
文件:ReflectionUtilsTests.java
@Test
public void testGetAnnotationFieldsWithSimpelClass() {
List<Field> fields = ReflectionUtils.getAnnotationFields(SimpleClass.class,TestAnnotation.class);
Assert.assertEquals("SimpleClass does not contain any field annotated with TestAnnotation",fields.size());
fields = ReflectionUtils.getAnnotationFields(SimpleClassWithAnnotation.class,TestAnnotation.class);
Assert.assertEquals("SimpleClassWithAnnotation contains a field annotated with TestAnnotation",1,fields.size());
fields = ReflectionUtils.getAnnotationFields(SubClass.class,TestAnnotation.class);
Assert.assertEquals("SubClass contains a superclass field annotated with TestAnnotation",fields.size());
fields = ReflectionUtils.getAnnotationFields(SubSubClass.class,TestAnnotation.class);
Assert.assertEquals("SubClass contains a field and a superclass field annotated with TestAnnotation",2,Target.class);
Assert.assertEquals("SubClass contains no fields annotated with Target",fields.size());
}
@Override
@SuppressWarnings("unchecked")
public final Description matchClass(Classtree classtree,VisitorState state) {
Symbol classSymbol = ASTHelpers.getSymbol(classtree);
if ((classSymbol.flags() & Flags.ANNOTATION) != 0
&& ScopE_ANNOTATION_MATCHER.matches(classtree,state)) {
Target target = ASTHelpers.getAnnotation(classSymbol,Target.class);
boolean hasExclusivelyTypeAndOrMethodtargeting = false;
if (target != null) {
for (ElementType elementType : target.value()) {
if (elementType != METHOD && elementType != TYPE) {
return describe(classtree,state);
} else if (elementType == METHOD || elementType == TYPE) {
hasExclusivelyTypeAndOrMethodtargeting = true;
}
}
}
if(!hasExclusivelyTypeAndOrMethodtargeting) { // true for no target set and for @Target({})
return describe(classtree,state);
}
}
return Description.NO_MATCH;
}
项目:freeVM
文件:Class1_5Test.java
/**
*
*/
public void test_isAnnotationPresent_Cla() {
class e {};
assertFalse("zzz annotation is not presented for e class!",zzz.class.isAnnotationPresent(java.lang.annotation
.Retention.class));
}
项目:freeVM
文件:Class1_5Test.java
项目:immutables
文件:Annotations.java
static boolean annotationMatchesTarget(Element annotationElement,ElementType elementType) {
@Nullable Target target = annotationElement.getAnnotation(Target.class);
if (target != null) {
ElementType[] targettypes = target.value();
if (targettypes.length == 0) {
return false;
}
boolean found = false;
for (ElementType t : targettypes) {
if (t == elementType) {
found = true;
}
}
if (!found) {
return false;
}
}
return true;
}
@Before
public void setUp() {
mappers = new HashMap<>();
mappers.put(Retention.class,mapper1);
mappers.put(Target.class,mapper2);
converters = new HashMap<>();
converters.put(Retention.class,converter1);
converters.put(Target.class,converter2);
config = new QueriesConfigImpl(dialect,binder,mappers,converters);
}
项目:booter-injector
文件:AnnotationFactoryTest.java
@Test
public void shouldBeEqualToRealAnnotationWithArrayValues() throws Exception {
Map<String,Object> values = new HashMap<>();
values.put("value",new ElementType[] {ElementType.TYPE,ElementType.ParaMETER,ElementType.CONSTRUCTOR,ElementType.METHOD});
Target target = AnnotationFactory.create(Target.class,values);
Target real = TestAnnotation.class.getAnnotation(Target.class);
assertthat(target).isinstanceOf(Target.class);
assertthat(target).isEqualTo(real);
assertthat(target.hashCode()).isEqualTo(real.hashCode());
}
项目:aml
文件:Context.java
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;
}
项目:listing
文件:AnnotationTest.java
@Test
void singleElementAnnotationUsingEnumValues() {
Annotation target = Annotation.of(Target.class,ElementType.TYPE);
String t = Target.class.getCanonicalName();
String et = ElementType.class.getCanonicalName();
assertEquals("@" + t + "(" + et + ".TYPE)",target.list());
target.addobject("value",ElementType.PACKAGE);
assertEquals("@" + t + "({" + et + ".TYPE," + et + ".PACKAGE})",target.list());
}
项目:eclipse.jdt.ls
文件:TypeAnnotationRewrite.java
private static IAnnotationBinding findTargetAnnotation(IAnnotationBinding[] MetaAnnotations) {
for (int i= 0; i < MetaAnnotations.length; i++) {
IAnnotationBinding binding= MetaAnnotations[i];
ITypeBinding annotationType= binding.getAnnotationType();
if (annotationType != null && annotationType.getQualifiedname().equals(Target.class.getName())) {
return binding;
}
}
return null;
}
项目:vertx-jspare
文件:AbstractModule.java
/**
* Execute one hook if is present.
*
* @param ann the annotation
* @param execute the bi consumer
* @param <T> the type
*/
protected <T> void doHookIfPresent(Class<T> ann,BiConsumer<AnnotatedElement,T> execute) {
Class<? extends Annotation> annClass = (Class<? extends Annotation>) ann;
Target target = annClass.getAnnotation(Target.class);
if (isCheckType(target,ElementType.TYPE))
executeHookType(annClass,execute);
if (isCheckType(target,ElementType.METHOD))
executeHookMethods(annClass,execute);
}
项目:vertx-jspare
文件:AbstractModule.java
/**
* Execute one hook if is present.
*
* @param ann the annotation
* @param execute the handler
* @param <T> the type
*/
protected <T> void doHookIfPresent(Class<T> ann,Handler<T> execute) {
Class<? extends Annotation> annClass = (Class<? extends Annotation>) ann;
Target target = annClass.getAnnotation(Target.class);
if (isCheckType(target,ElementType.TYPE)) {
executeHookType(annClass,(a,t) -> execute.handle((T) t));
}
if (isCheckType(target,ElementType.METHOD)) {
executeHookMethods(annClass,t) -> execute.handle((T) t));
}
}
public sqliteMagicImplicitUsageProvider() {
for (Class<? extends Annotation> annotation : ANNOTATIONS) {
final EnumSet<ElementType> elementTypes = EnumSet.copyOf(Arrays.asList(annotation.getAnnotation(Target.class).value()));
if (elementTypes.contains(ElementType.FIELD)) {
FIELD_ANNOTATIONS.add(annotation.getName());
}
if (elementTypes.contains(ElementType.METHOD) || elementTypes.contains(ElementType.CONSTRUCTOR)) {
METHOD_ANNOTATIONS.add(annotation.getName());
}
if (elementTypes.contains(ElementType.TYPE)) {
CLASS_ANNOTATIONS.add(annotation.getName());
}
}
}
项目:anno4j
文件:RDFProperty.java
private void annotationHeader(JavaMessageBuilder builder)
throws ObjectStoreConfigException {
String pkg = builder.getPackageName(this.getURI());
String simple = builder.getSimpleName(this.getURI());
if (pkg == null) {
builder.imports(simple);
} else {
builder.pkg(pkg);
builder.imports(pkg + '.' + simple);
}
builder.comment(this);
if (this.isA(OWL.DEPRECATEDPROPERTY)) {
builder.annotate(Deprecated.class);
}
builder.annotateEnum(Retention.class,"value",RetentionPolicy.class,"RUNTIME");
builder.annotateEnums(Target.class,ElementType.class,"TYPE","METHOD","ParaMETER","ANNOTATION_TYPE","PACKAGE");
builder.annotationName(simple);
builder.annotationProperties(this);
builder.annotateURI(Iri.class,builder.getType(this.getURI()));
if (this.isA(OWL.FUNCTIONALPROPERTY)) {
builder.method("value",true).returnType(builder.imports(String.class)).end();
} else {
builder.method("value",true).returnType(builder.imports(String.class) + "[]")
.end();
}
}
项目:asteroid
文件:LocalTransformation.java
private AnnotationNode getTargetAnnotation(final String resolvedTarget) {
final List<ElementType> types = resolveAnnotationTarget(resolvedTarget);
final ListExpression listExpr = resolveTargetfromElementType(types);
return A.NODES.annotation(Target.class)
.member(A.UTIL.ANNOTATION.ANNOTATION_VALUE,listExpr)
.build();
}
项目:annotation-tools
文件:IndexFileWriter.java
private Collection<Annotation> requiredMetaannotations(
Collection<Annotation> annos) {
Set<Annotation> results = new HashSet<Annotation>();
for (Annotation a : annos) {
String aName = a.def.name;
if (aName.equals(Retention.class.getCanonicalName())
|| aName.equals(Target.class.getCanonicalName())) {
results.add(a);
}
}
return results;
}
项目:Stdlib
文件:Annotations.java
/**
* Returns a set of Meta annotations associated with the given annotation
* bundle. This will suppress {@link java.lang.annotation.Retention} and
* {@link java.lang.annotation.Target}. The supplied annotation will be
* the first annotation included in the returned set.
*/
public static Set<Annotation> getMetaAnnotations(Annotation bundle)
{
Set<Annotation> result = Sets.newLinkedHashSet();
result.add(Objects.notNull(bundle));
for (Annotation a : bundle.annotationType().getDeclaredAnnotations()) {
// minor optimization: by-pass 2 common JDK Meta-annotations
if ((a instanceof Target) || (a instanceof Retention)) {
continue;
}
result.add(a);
}
return result;
}
项目:jadecy
文件:ClassDepsParserTest.java
public void test_computeDependencies_fromAno_public() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
// Extends Object.
addSlashedname(expected,Object.class);
// Implements Annotation.
addSlashedname(expected,Annotation.class);
//
addSlashedname(expected,Class.class);
addSlashedname(expected,Number.class);
addSlashedname(expected,Byte.class);
addSlashedname(expected,String.class);
addSlashedname(expected,RoundingMode.class);
addSlashedname(expected,Documented.class);
//
if (apiOnly) {
} else {
addSlashedname(expected,Retention.class);
addSlashedname(expected,RetentionPolicy.class);
addSlashedname(expected,Target.class);
addSlashedname(expected,ElementType.class);
//
addSlashedname(expected,ClassDepsParserTest.class);
}
computeDepsAndCheck(MyTestAnno2_public.class.getName(),apiOnly,expected);
}
}
项目:jadecy
文件:ClassDepsParserTest.java
public void test_computeDependencies_fromAno_private() {
for (boolean apiOnly : FALSE_TRUE) {
final SortedSet<String> expected = new TreeSet<String>();
//
if (apiOnly) {
} else {
addSlashedname(expected,ClassDepsParserTest.class);
//
addSlashedname(expected,Object.class);
addSlashedname(expected,Annotation.class);
//
addSlashedname(expected,Class.class);
addSlashedname(expected,Number.class);
addSlashedname(expected,Byte.class);
addSlashedname(expected,String.class);
addSlashedname(expected,RoundingMode.class);
addSlashedname(expected,Documented.class);
}
computeDepsAndCheck(MyTestAnno2_private.class.getName(),expected);
}
}
项目:picoservice
文件:AnnotationProcessorPico.java
private boolean _isValidElement(Element pElement)
{
Retention retention = pElement.getAnnotation(Retention.class);
if (retention == null || retention.value() != RetentionPolicy.RUNTIME)
{
processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING,"Retention should be RUNTIME",pElement);
return false;
}
Target target = pElement.getAnnotation(Target.class);
if (target == null || target.value() == null || target.value().length == 0)
{
processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING,"Target has to be defined",pElement);
return false;
}
else
{
for (ElementType elementType : target.value())
{
if (elementType != ElementType.TYPE)
{
processingEnv.getMessager().printMessage(Diagnostic.Kind.MANDATORY_WARNING,"Unsupported type: " + elementType,pElement);
return false;
}
}
}
return true;
}
@Test
public void Annotation_can_only_be_applied_to_fields() {
Target target = Fromlistof.class.getAnnotation(Target.class);
assertEquals(1,target.value().length);
ElementType type = target.value()[0];
assertTrue(type.equals(ElementType.FIELD));
}
项目:jfixture
文件:TestRange.java
@Test
public void Annotation_can_only_be_applied_to_fields() {
Target target = Range.class.getAnnotation(Target.class);
assertEquals(1,target.value().length);
ElementType type = target.value()[0];
assertTrue(type.equals(ElementType.FIELD));
}
项目:jfixture
文件:TestFixture.java
@Test
public void Annotation_can_only_be_applied_to_fields() {
Target target = Fixture.class.getAnnotation(Target.class);
assertEquals(1,target.value().length);
ElementType type = target.value()[0];
assertTrue(type.equals(ElementType.FIELD));
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。