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


Java Target.value方法代码示例

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


在下文中一共展示了Target.value方法的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: 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

示例3: 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

示例4: 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

示例5: 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

示例6: matchClass

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

示例7: _isValidElement

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

示例8: Annotation_can_only_be_applied_to_fields

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

示例9: Annotation_can_only_be_applied_to_fields

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

示例10: Annotation_can_only_be_applied_to_fields

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

示例11: validTarget

import java.lang.annotation.Target; //导入方法依赖的package包/类
private static boolean validTarget(Class<? extends Annotation> type) {
	final Target target = type.getAnnotation(Target.class);

	if(target==null) {
		return false;
	}

	final ElementType[] targets=target.value();

	return 
		targets.length == 1 && 
		targets[0] == ElementType.ANNOTATION_TYPE;
}
 
开发者ID:ldp4j,项目名称:ldp4j,代码行数:14,代码来源:MetaAnnotationHelper.java

示例12: copyAnnotationTarget

import java.lang.annotation.Target; //导入方法依赖的package包/类
public static void copyAnnotationTarget(Class annotationClass, AnnotationDefinition annotationDefinition) {
    if (annotationClass.isAnnotationPresent(Target.class)) {
        Target targetAnnotation = (Target) annotationClass.getAnnotation(Target.class);
        java.lang.annotation.ElementType[] targets = targetAnnotation.value();
        if (targets != null && targets.length > 0) {
            for (int i = 0; i < targets.length; i++) {
                annotationDefinition.addTarget(buildElementType(targets[i]));
            }
        } else {
            //added to avoid an errai unmarshalling error in broser side, when an annotation has no targets, e.g.
            //javax.persistence.UniqueConstraint
            annotationDefinition.addTarget(ElementType.UNDEFINED);
        }
    }
}
 
开发者ID:kiegroup,项目名称:kie-wb-common,代码行数:16,代码来源:DriverUtils.java

示例13: process

import java.lang.annotation.Target; //导入方法依赖的package包/类
public void process() {
    for (Entry<Class<?>, SimpleDeclarationVisitor> av_pair : _annotationVisitors.entrySet()) {

        Class<?> annotation = av_pair.getKey();
        String annotName = annotation.getName();

        AnnotationTypeDeclaration annotDeclaration = _annotationDefinitions.get(annotName);
        if (annotDeclaration == null) {
            _messager.printError("Cannot load class definition of annotation @" + annotName +
                ". This annotation will NOT be processed");
            continue;
        }

        Target applicableOn = annotDeclaration.getAnnotation(Target.class);

        SimpleDeclarationVisitor visitor = av_pair.getValue();
        if (visitor == null) {
            _messager.printError("Cannot find the visitor for annotation @" + annotName +
                ". This annotation will NOT be processed");
            continue;
        }

        for (Declaration typeDeclaration : _annotatedElements.get(annotDeclaration)) {

            if (applicableOn != null && applicableOn.value() != null)
                if (!testSuitableDeclaration(typeDeclaration, applicableOn)) {
                    _messager.printError(typeDeclaration.getPosition(), "[ERROR] The @" +
                        annotation.getSimpleName() +
                        "annotation is not applicable for this type of Java construct.");
                }

            // check using the visitor
            typeDeclaration.accept(visitor);
        }
    }
}
 
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:37,代码来源:ProActiveProcessorAPT.java

示例14: testSuitableDeclaration

import java.lang.annotation.Target; //导入方法依赖的package包/类
private boolean testSuitableDeclaration(Declaration typeDeclaration, Target applicableOn) {

        for (ElementType applicableType : applicableOn.value()) {
            if (UtilsAPT.applicableOnDeclaration(applicableType, typeDeclaration))
                return true;
        }
        return false;
    }
 
开发者ID:mnip91,项目名称:proactive-component-monitoring,代码行数:9,代码来源:ProActiveProcessorAPT.java

示例15: canPresentOn

import java.lang.annotation.Target; //导入方法依赖的package包/类
public boolean canPresentOn(ElementType type) throws SyntaxException {
        String name = fullName();
        try {
                Class<?> cls = Class.forName(name);
                Annotation[] annotations = cls.getAnnotations();
                for (Annotation a : annotations) {
                        if (a instanceof Target) {
                                Target target = (Target) a;
                                ElementType[] types = target.value();
                                for (ElementType t : types) {
                                        if (t.equals(type)) return true;
                                }
                                return false;
                        }
                }
                return true;
        } catch (ClassNotFoundException e) {
                // annotation not compiled yet
                // check manually
                SAnno targetAnno = null;
                for (SAnno anno : annos()) {
                        if (anno.type().fullName().equals(Target.class.getName())) {
                                targetAnno = anno;
                                break;
                        }
                }
                if (null == targetAnno) return true;
                SAnnoField valueAnnoF = null;
                for (SAnnoField f : targetAnno.type().annoFields()) {
                        if (f.name().equals("value")) {
                                valueAnnoF = f;
                                break;
                        }
                }
                if (valueAnnoF == null) throw new LtBug("it should not be null");
                SArrayValue arrV = (SArrayValue) targetAnno.values().get(valueAnnoF);
                for (Value v : arrV.values()) {
                        if (v instanceof EnumValue && v.type().fullName().equals(ElementType.class.getName())) {
                                if (type.name().equals(((EnumValue) v).enumStr())) return true;
                        }
                }
                return false;
        }
}
 
开发者ID:wkgcass,项目名称:Latte-lang,代码行数:45,代码来源:SAnnoDef.java


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