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


Java RetentionPolicy.CLASS属性代码示例

本文整理汇总了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;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:24,代码来源:AnnotationsHighlightUtil.java

示例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;
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:24,代码来源:AnnotationsHighlightUtil.java

示例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();
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:GetterEncloser.java

示例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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:8,代码来源:AnnotationsTestBase.java

示例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;
    }
}
 
开发者ID:typetools,项目名称:annotation-tools,代码行数:17,代码来源:AnnotationDef.java

示例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);
}
 
开发者ID:grzesuav,项目名称:gjpf-core,代码行数:40,代码来源:AnnotationType.java

示例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;
}
 
开发者ID:google,项目名称:error-prone,代码行数:8,代码来源:ElementPredicates.java

示例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;
}
 
开发者ID:phax,项目名称:ph-commons,代码行数:21,代码来源:AnnotationUsageCache.java

示例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();
    }
}
 
开发者ID:raphw,项目名称:byte-buddy,代码行数:7,代码来源:AdviceTest.java

示例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();
}
 
开发者ID:WeTheInternet,项目名称:xapi,代码行数:10,代码来源:BytecodeAdapterService.java

示例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;
}
 
开发者ID:consulo,项目名称:consulo-java,代码行数:34,代码来源:AnnotationsHighlightUtil.java

示例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();
}
 
开发者ID:inesc-id-esw,项目名称:advice,代码行数:11,代码来源:ProcessAnnotations.java


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