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


Java Retention.value方法代码示例

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


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

示例1: getDeclaredAnnotationClass

import java.lang.annotation.Retention; //导入方法依赖的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

示例2: includeNotInheritedAnnotations

import java.lang.annotation.Retention; //导入方法依赖的package包/类
private void includeNotInheritedAnnotations() {
    for (Annotation annotation : type.getDeclaredAnnotations()) {
        if (annotation.annotationType().getAnnotation(Inherited.class) != null) {
            continue;
        }
        Retention retention = annotation.annotationType().getAnnotation(Retention.class);
        boolean visible = retention != null && retention.value() == RetentionPolicy.RUNTIME;
        AnnotationVisitor annotationVisitor = visitor.visitAnnotation(Type.getType(annotation.annotationType()).getDescriptor(), visible);
        visitAnnotationValues(annotation, annotationVisitor);
        annotationVisitor.visitEnd();
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:13,代码来源:AsmBackedClassGenerator.java

示例3: checkForRuntimeRetention

import java.lang.annotation.Retention; //导入方法依赖的package包/类
private static void checkForRuntimeRetention(
        Class<? extends Annotation> annotationType) {
    Retention retention = annotationType.getAnnotation(Retention.class);
    if (retention == null || retention.value() != RetentionPolicy.RUNTIME) {
        throw new IllegalArgumentException("Annotation " + annotationType.getSimpleName() + " is missing RUNTIME retention");
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:Matchers.java

示例4: checkScopeAnnotationValidity

import java.lang.annotation.Retention; //导入方法依赖的package包/类
private void checkScopeAnnotationValidity(TypeElement annotation) {
  if (annotation.getAnnotation(Scope.class) == null) {
    error(annotation, "Scope Annotation %s does not contain Scope annotation.", annotation.getQualifiedName());
    return;
  }

  Retention retention = annotation.getAnnotation(Retention.class);
  if (retention == null || retention.value() != RetentionPolicy.RUNTIME) {
    error(annotation, "Scope Annotation %s does not have RUNTIME retention policy.", annotation.getQualifiedName());
  }
}
 
开发者ID:stephanenicolas,项目名称:toothpick,代码行数:12,代码来源:FactoryProcessor.java

示例5: isRetainedAtRuntime

import java.lang.annotation.Retention; //导入方法依赖的package包/类
/**
 * Returns true if the given annotation is retained at runtime.
 */
public static boolean isRetainedAtRuntime(
        Class<? extends Annotation> annotationType) {
    Retention retention = annotationType.getAnnotation(Retention.class);
    return retention != null
            && retention.value() == RetentionPolicy.RUNTIME;
}
 
开发者ID:ruediste,项目名称:salta,代码行数:10,代码来源:Annotations.java

示例6: annotatedWith

import java.lang.annotation.Retention; //导入方法依赖的package包/类
@Override
public Builder annotatedWith(final Class<? extends Annotation> annotation) {
	Retention retention = annotation.getAnnotation(Retention.class);
	if (retention == null || retention.value() != RetentionPolicy.RUNTIME) {
		throw new IllegalStateException("Cannot filter annotated with annotation without retention policy"
				+ " set to RUNTIME: " + annotation.getName());
	}
	return satisfying(new Predicate() {
		@Override
		public boolean matches(Class<?> klass) {
			return klass.isAnnotationPresent(annotation);
		}
	});
}
 
开发者ID:soklet,项目名称:soklet,代码行数:15,代码来源:ClassFilter.java

示例7: _isValidElement

import java.lang.annotation.Retention; //导入方法依赖的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: AnnotationType

import java.lang.annotation.Retention; //导入方法依赖的package包/类
private AnnotationType(final Class<?> annoCls) {
  if (!annoCls.isAnnotation()) {
    throw new IllegalArgumentException("Not an annotation type");
  }

  Method[] methods = annoCls.getDeclaredMethods();

  for (Method m : methods) {
    if (m.getParameterTypes().length == 0) {
      // cache name -> method assoc
      String mname = m.getName();
      members.put(mname, m);

      // cache member type
      Class<?> type = m.getReturnType();
      memberTypes.put(mname, invocationHandlerReturnType(type));

      // cache member default val (if any)
      Object val = m.getDefaultValue();
      if (val != null) {
        memberDefaults.put(mname, val);
      }
    } else {
      // probably an exception
    }
  }

  if ((annoCls != Retention.class) && (annoCls != Inherited.class)) { // don't get recursive
    inherited = annoCls.isAnnotationPresent(Inherited.class);

    Retention r = annoCls.getAnnotation(Retention.class);
    if (r == null) {
      retention = RetentionPolicy.CLASS;
    } else {
      retention = r.value();
    }
  }

  SharedSecrets.getJavaLangAccess().setAnnotationType(annoCls, this);
}
 
开发者ID:grzesuav,项目名称:gjpf-core,代码行数:41,代码来源:AnnotationType.java

示例9: effectiveRetentionPolicy

import java.lang.annotation.Retention; //导入方法依赖的package包/类
private static RetentionPolicy effectiveRetentionPolicy(Element element) {
  RetentionPolicy retentionPolicy = RetentionPolicy.CLASS;
  Retention retentionAnnotation = element.getAnnotation(Retention.class);
  if (retentionAnnotation != null) {
    retentionPolicy = retentionAnnotation.value();
  }
  return retentionPolicy;
}
 
开发者ID:google,项目名称:error-prone,代码行数:9,代码来源:ElementPredicates.java

示例10: AnnotationUsageCache

import java.lang.annotation.Retention; //导入方法依赖的package包/类
/**
 * Constructor
 *
 * @param aAnnotationClass
 *        The annotation class to store the existence of. It must have the
 *        {@link RetentionPolicy#RUNTIME} to be usable within this class!
 */
public AnnotationUsageCache (@Nonnull final Class <? extends Annotation> aAnnotationClass)
{
  ValueEnforcer.notNull (aAnnotationClass, "AnnotationClass");

  // Check retention policy
  final Retention aRetention = aAnnotationClass.getAnnotation (Retention.class);
  final RetentionPolicy eRetentionPolicy = aRetention == null ? RetentionPolicy.CLASS : aRetention.value ();
  if (eRetentionPolicy != RetentionPolicy.RUNTIME)
    throw new IllegalArgumentException ("RetentionPolicy must be of type RUNTIME to be used within this cache. The current value ist " +
                                        eRetentionPolicy);

  // Save to members
  m_aAnnotationClass = aAnnotationClass;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:22,代码来源:AnnotationUsageCache.java

示例11: AnnotationRef

import java.lang.annotation.Retention; //导入方法依赖的package包/类
private AnnotationRef(Class<T> annType) {
  this.annType = annType;
  Retention retention = annType.getAnnotation(Retention.class);
  this.isRuntimeVisible = retention != null && retention.value() == RetentionPolicy.RUNTIME;
  this.typeDescriptor = Type.getDescriptor(annType);
  // we need to ensure that our writers are in a consistent ordering.  Otherwise we will generate
  // bytecode non deterministically.  getDeclaredMethods() internally uses a hashMap for storing
  // objects so the order of methods returned from it is non deterministic
  ImmutableMap.Builder<Method, FieldWriter> writersBuilder = ImmutableMap.builder();
  for (Method method : METHOD_ORDERING.sortedCopy(Arrays.asList(annType.getDeclaredMethods()))) {
    if (method.getParameterTypes().length == 0 && !Modifier.isStatic(method.getModifiers())) {
      Class<?> returnType = method.getReturnType();
      if (returnType.isArray()) {
        if (returnType.getComponentType().isAnnotation()) {
          // These could be supported, but we don't have a usecase yet.
          throw new UnsupportedOperationException("Arrays of annotations are not supported");
        }
        writersBuilder.put(method, arrayFieldWriter(method.getName()));
      } else if (returnType.isAnnotation()) {
        // N.B. this is recursive and will fail if we encounter recursive annotations
        // (StackOverflowError).  This could be resolved when we have a usecase, but the failure
        // will be obvious if it every pops up.
        @SuppressWarnings("unchecked") // we just checked above
        AnnotationRef<?> forType = forType((Class<? extends Annotation>) returnType);
        writersBuilder.put(method, annotationFieldWriter(method.getName(), forType));
      } else {
        // simple primitive
        writersBuilder.put(method, simpleFieldWriter(method.getName()));
      }
    }
  }
  this.writers = writersBuilder.build();
}
 
开发者ID:google,项目名称:closure-templates,代码行数:34,代码来源:AnnotationRef.java

示例12: getAnnotations

import java.lang.annotation.Retention; //导入方法依赖的package包/类
/**
 * Returns the invisible or visible annotations list, depending on the RetentionPolicy of the client
 * annotation.
 **/
private List<AnnotationNode> getAnnotations(MethodNode mn) {
    Retention retAnnot = args.annotationClass.getAnnotation(Retention.class);
    RetentionPolicy policy = retAnnot == null ? RetentionPolicy.CLASS : retAnnot.value();
    List<AnnotationNode> list = policy == RetentionPolicy.CLASS ?
            mn.invisibleAnnotations : mn.visibleAnnotations;
    return list != null ? list : Collections.<AnnotationNode>emptyList();
}
 
开发者ID:inesc-id-esw,项目名称:advice,代码行数:12,代码来源:ProcessAnnotations.java

示例13: isRetainedAtRuntime

import java.lang.annotation.Retention; //导入方法依赖的package包/类
/**
 * Returns true if the given annotation is retained at runtime.
 */
public static boolean isRetainedAtRuntime(Class<? extends Annotation> annotationType) {
    Retention retention = annotationType.getAnnotation(Retention.class);
    return retention != null && retention.value() == RetentionPolicy.RUNTIME;
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:Annotations.java

示例14: isRetainedAtRuntime

import java.lang.annotation.Retention; //导入方法依赖的package包/类
/**
 * Returns true if the given annotation is retained at runtime.
 */
public static boolean isRetainedAtRuntime(Class<? extends Annotation> annotationType) {
  Retention retention = annotationType.getAnnotation(Retention.class);
  return retention != null && retention.value() == RetentionPolicy.RUNTIME;
}
 
开发者ID:maetrive,项目名称:businessworks,代码行数:8,代码来源:Annotations.java

示例15: annotate

import java.lang.annotation.Retention; //导入方法依赖的package包/类
/**
 * Applies a Java 1.5-style annotation to a given Host. The Host must be of type {@link SootClass}, {@link SootMethod}
 * or {@link SootField}.
 * 
 * @param h a method, field, or class
 * @param klass the class of the annotation to apply to <code>h</code>
 * @param elems a (possibly empty) sequence of AnnotationElem objects corresponding to the elements that should be contained in this annotation
 */
public void annotate(Host h, Class<? extends Annotation> klass, List<AnnotationElem> elems) {
	//error-checking -- is this annotation appropriate for the target Host?
	Target t = klass.getAnnotation(Target.class);
	Collection<ElementType> elementTypes = Arrays.asList(t.value());		
	final String ERR = "Annotation class "+klass+" not applicable to host of type "+h.getClass()+".";
	if(h instanceof SootClass) {
		if(!elementTypes.contains(ElementType.TYPE)) {
			throw new RuntimeException(ERR);
		}
	} else if(h instanceof SootMethod) {
		if(!elementTypes.contains(ElementType.METHOD)) {
			throw new RuntimeException(ERR);
		}
	} else if(h instanceof SootField) {
		if(!elementTypes.contains(ElementType.FIELD)) {
			throw new RuntimeException(ERR);
		}
	} else {
		throw new RuntimeException("Tried to attach annotation to host of type "+h.getClass()+".");
	}
	
	//get the retention type of the class
	Retention r = klass.getAnnotation(Retention.class);
	
	// CLASS (runtime invisible) retention is the default
	int retPolicy = AnnotationConstants.RUNTIME_INVISIBLE;
	if(r!=null) {
		//TODO why actually do we have AnnotationConstants at all and don't use
		//     RetentionPolicy directly? (Eric Bodden 20/05/2008)
		switch(r.value()) {
		case CLASS:
			retPolicy = AnnotationConstants.RUNTIME_INVISIBLE;
			break;
		case RUNTIME:
			retPolicy = AnnotationConstants.RUNTIME_VISIBLE;
			break;
		default:
			throw new RuntimeException("Unexpected retention policy: "+retPolicy);
		}
	} 

	annotate(h, klass.getCanonicalName(), retPolicy , elems);	
}
 
开发者ID:flankerhqd,项目名称:JAADAS,代码行数:52,代码来源:AnnotationGenerator.java


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