當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。