本文整理匯總了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());
}
示例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();
}
}
示例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");
}
}
示例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());
}
}
示例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;
}
示例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);
}
});
}
示例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;
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}