本文整理汇总了Java中java.lang.annotation.RetentionPolicy.CLASS属性的典型用法代码示例。如果您正苦于以下问题:Java RetentionPolicy.CLASS属性的具体用法?Java RetentionPolicy.CLASS怎么用?Java RetentionPolicy.CLASS使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类java.lang.annotation.RetentionPolicy
的用法示例。
在下文中一共展示了RetentionPolicy.CLASS属性的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRetentionPolicy
@Nullable
public static RetentionPolicy getRetentionPolicy(@NotNull PsiClass annotation) {
PsiModifierList modifierList = annotation.getModifierList();
if (modifierList != null) {
PsiAnnotation retentionAnno = modifierList.findAnnotation(CommonClassNames.JAVA_LANG_ANNOTATION_RETENTION);
if (retentionAnno == null) return RetentionPolicy.CLASS;
PsiAnnotationMemberValue policyRef = PsiImplUtil.findAttributeValue(retentionAnno, null);
if (policyRef instanceof PsiReference) {
PsiElement field = ((PsiReference)policyRef).resolve();
if (field instanceof PsiEnumConstant) {
String name = ((PsiEnumConstant)field).getName();
try {
return Enum.valueOf(RetentionPolicy.class, name);
}
catch (Exception e) {
LOG.warn("Unknown policy: " + name);
}
}
}
}
return null;
}
示例2: getRetentionPolicy
@Nullable
private static RetentionPolicy getRetentionPolicy(PsiClass annotation) {
PsiModifierList modifierList = annotation.getModifierList();
if (modifierList != null) {
PsiAnnotation retentionAnno = modifierList.findAnnotation(CommonClassNames.JAVA_LANG_ANNOTATION_RETENTION);
if (retentionAnno == null) return RetentionPolicy.CLASS;
PsiAnnotationMemberValue policyRef = PsiImplUtil.findAttributeValue(retentionAnno, null);
if (policyRef instanceof PsiReference) {
PsiElement field = ((PsiReference)policyRef).resolve();
if (field instanceof PsiEnumConstant) {
String name = ((PsiEnumConstant)field).getName();
try {
return RetentionPolicy.valueOf(name);
}
catch (Exception e) {
LOG.warn("Unknown policy: " + name);
}
}
}
}
return null;
}
示例3:
@GetterAnnotation(policy = RetentionPolicy.CLASS,
string = "\n\"",
type = Object.class,
value = {@InnerAnnotation, @InnerAnnotation},
bval = Byte.MIN_VALUE, dval = Double.POSITIVE_INFINITY,
ival = Integer.MAX_VALUE,
fval = Float.NaN,
blval = true,
cval = 'j')
@Path("/ef")
@Value.Auxiliary
boolean ef();
示例4: getRetentionPolicy
protected RetentionPolicy getRetentionPolicy(String name) {
if (name.contains("Visible")) {
return RetentionPolicy.RUNTIME;
} else if (name.contains("Invisible")) {
return RetentionPolicy.CLASS;
}
throw new IllegalArgumentException(name);
}
示例5: retention
/**
* The retention policy for annotations of this type.
* If non-null, this is called a "top-level" annotation definition.
* It may be null for annotations that are used only as a field of other
* annotations.
*/
public /*@Nullable*/ RetentionPolicy retention() {
if (tlAnnotationsHere.contains(Annotations.aRetentionClass)) {
return RetentionPolicy.CLASS;
} else if (tlAnnotationsHere.contains(Annotations.aRetentionRuntime)) {
return RetentionPolicy.RUNTIME;
} else if (tlAnnotationsHere.contains(Annotations.aRetentionSource)) {
return RetentionPolicy.SOURCE;
} else {
return null;
}
}
示例6: AnnotationType
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);
}
示例7: effectiveRetentionPolicy
private static RetentionPolicy effectiveRetentionPolicy(Element element) {
RetentionPolicy retentionPolicy = RetentionPolicy.CLASS;
Retention retentionAnnotation = element.getAnnotation(Retention.class);
if (retentionAnnotation != null) {
retentionPolicy = retentionAnnotation.value();
}
return retentionPolicy;
}
示例8: AnnotationUsageCache
/**
* 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;
}
示例9: advice
@Advice.OnMethodEnter
@Advice.OnMethodExit
private static void advice(@Custom Object value) {
if (value != Object.class && value != RetentionPolicy.CLASS && value != null) {
throw new AssertionError();
}
}
示例10: isCompile
@Override
public boolean isCompile() {
IsAnnotation retention = retentionAnno.get();
if (retention == null) {
return true;
}
IsMethod value = retention.getMethod("value");
IsAnnotationValue val = retention.getValue(value);
return RetentionPolicy.CLASS == val.getRawValue();
}
示例11: getRetentionPolicy
@Nullable
public static RetentionPolicy getRetentionPolicy(@NotNull PsiClass annotation)
{
PsiModifierList modifierList = annotation.getModifierList();
if(modifierList != null)
{
PsiAnnotation retentionAnno = modifierList.findAnnotation(CommonClassNames.JAVA_LANG_ANNOTATION_RETENTION);
if(retentionAnno == null)
{
return RetentionPolicy.CLASS;
}
PsiAnnotationMemberValue policyRef = PsiImplUtil.findAttributeValue(retentionAnno, null);
if(policyRef instanceof PsiReference)
{
PsiElement field = ((PsiReference) policyRef).resolve();
if(field instanceof PsiEnumConstant)
{
String name = ((PsiEnumConstant) field).getName();
try
{
//noinspection ConstantConditions
return Enum.valueOf(RetentionPolicy.class, name);
}
catch(Exception e)
{
LOG.warn("Unknown policy: " + name);
}
}
}
}
return null;
}
示例12: getAnnotations
/**
* 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();
}