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