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


Java Target类代码示例

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


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

示例1: annotationMatchesTarget

import java.lang.annotation.Target; //导入依赖的package包/类
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;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:20,代码来源:Annotations.java

示例2: buildTemplateConstraint

import java.lang.annotation.Target; //导入依赖的package包/类
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);
    }
}
 
开发者ID:hibernate,项目名称:beanvalidation-benchmark,代码行数:19,代码来源:Jsr303Annotator.java

示例3: isDeclarationAnnotation

import java.lang.annotation.Target; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:campolake,项目名称:openjdk9,代码行数:27,代码来源:Utils.java

示例4: getAnnotationTargets

import java.lang.annotation.Target; //导入依赖的package包/类
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();
}
 
开发者ID:eclipse,项目名称:xtext-extras,代码行数:19,代码来源:XAnnotationUtil.java

示例5: rootAnnotation

import java.lang.annotation.Target; //导入依赖的package包/类
@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());
}
 
开发者ID:sormuras,项目名称:listing,代码行数:21,代码来源:JavaMirrorsTest.java

示例6: loadAndCheckAnnotatedAnnotation

import java.lang.annotation.Target; //导入依赖的package包/类
@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));
    });
}
 
开发者ID:aalmiray,项目名称:naum,代码行数:23,代码来源:ClassTest.java

示例7: annotationTypeAnnotation

import java.lang.annotation.Target; //导入依赖的package包/类
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();
    }


}
 
开发者ID:luhaoaimama1,项目名称:JavaZone,代码行数:17,代码来源:TestMain.java

示例8: getAllReflectionClasses

import java.lang.annotation.Target; //导入依赖的package包/类
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
	}
 
开发者ID:liraz,项目名称:gwt-backbone,代码行数:26,代码来源:ReflectAllInOneCreator.java

示例9: getMethod

import java.lang.annotation.Target; //导入依赖的package包/类
/**
 * 获得 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.");
}
 
开发者ID:venusdrogon,项目名称:feilong-spring,代码行数:34,代码来源:JoinPointUtilTest.java

示例10: isAnnotationPresent

import java.lang.annotation.Target; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:venusdrogon,项目名称:feilong-spring,代码行数:34,代码来源:JoinPointUtilTest.java

示例11: getDeclaredAnnotationClass

import java.lang.annotation.Target; //导入依赖的package包/类
@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());
}
 
开发者ID:evant,项目名称:autodata,代码行数:21,代码来源:AutoDataAnnotationProcessor.java

示例12: matchClass

import java.lang.annotation.Target; //导入依赖的package包/类
@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;
}
 
开发者ID:google,项目名称:error-prone,代码行数:18,代码来源:InvalidTargetingOnScopingAnnotation.java

示例13: testMethodAnnotations

import java.lang.annotation.Target; //导入依赖的package包/类
@MyRuntimeAnnotation(
    intValue = 456,
    strValue = "test",
    enumValue = ElementType.METHOD,
    classValue = String.class,
    annotationValue = @Target({ElementType.METHOD}),
    arrayValue = {"X", "Y", "Z"}
)
@MyClassAnnotation(
    intValue = 456,
    strValue = "test",
    enumValue = ElementType.METHOD,
    classValue = String.class,
    annotationValue = @Target({}),
    arrayValue = {"X", "Y", "Z"}
)
public void testMethodAnnotations() {
    
}
 
开发者ID:zxh0,项目名称:classpy,代码行数:20,代码来源:AnnotatedClass.java

示例14: testParameterAnnotations

import java.lang.annotation.Target; //导入依赖的package包/类
public void testParameterAnnotations(
    @MyRuntimeAnnotation(
        intValue = 456,
        strValue = "test",
        enumValue = ElementType.METHOD,
        classValue = String.class,
        annotationValue = @Target({ElementType.METHOD}),
        arrayValue = {"X", "Y", "Z"}
    )
    @MyClassAnnotation(
        intValue = 456,
        strValue = "test",
        enumValue = ElementType.METHOD,
        classValue = String.class,
        annotationValue = @Target({}),
        arrayValue = {"X", "Y", "Z"}
    )   
    int param1
) {
    // ...
}
 
开发者ID:zxh0,项目名称:classpy,代码行数:22,代码来源:AnnotatedClass.java

示例15: test_isAnnotationPresent_Cla

import java.lang.annotation.Target; //导入依赖的package包/类
/**
 *  
 */
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));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:20,代码来源:Class1_5Test.java


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