當前位置: 首頁>>代碼示例>>Java>>正文


Java RetentionPolicy.valueOf方法代碼示例

本文整理匯總了Java中java.lang.annotation.RetentionPolicy.valueOf方法的典型用法代碼示例。如果您正苦於以下問題:Java RetentionPolicy.valueOf方法的具體用法?Java RetentionPolicy.valueOf怎麽用?Java RetentionPolicy.valueOf使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.lang.annotation.RetentionPolicy的用法示例。


在下文中一共展示了RetentionPolicy.valueOf方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: visitType

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
@Override
protected void visitType(TypeDefinition td) {
    if (!td.isAnnotation())
        return;
    DeclaredAnnotation da = getOrCreate(td);
    for (CustomAnnotation ca : td.getAnnotations()) {
        if (Types.is(ca.getAnnotationType(), Retention.class)) {
            for (AnnotationParameter ap : ca.getParameters()) {
                if (ap.getMember().equals("value")) {
                    AnnotationElement value = ap.getValue();
                    if (value instanceof EnumAnnotationElement) {
                        EnumAnnotationElement enumValue = (EnumAnnotationElement) value;
                        if (Types.is(enumValue.getEnumType(), RetentionPolicy.class)) {
                            da.policy = RetentionPolicy.valueOf(enumValue.getEnumConstantName());
                        }
                    }
                }
            }
        }
    }
}
 
開發者ID:amaembo,項目名稱:huntbugs,代碼行數:22,代碼來源:DeclaredAnnotations.java

示例2: ClassRepr

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
public ClassRepr(final DependencyContext context, final DataInput in) {
  super(in);
  try {
    this.myContext = context;
    myFileName = DataInputOutputUtil.readINT(in);
    mySuperClass = (TypeRepr.ClassType)TypeRepr.externalizer(context).read(in);
    myInterfaces = (Set<TypeRepr.AbstractType>)RW.read(TypeRepr.externalizer(context), new THashSet<TypeRepr.AbstractType>(1), in);
    myFields = (Set<FieldRepr>)RW.read(FieldRepr.externalizer(context), new THashSet<FieldRepr>(), in);
    myMethods = (Set<MethodRepr>)RW.read(MethodRepr.externalizer(context), new THashSet<MethodRepr>(), in);
    myAnnotationTargets = (Set<ElemType>)RW.read(UsageRepr.AnnotationUsage.elementTypeExternalizer, EnumSet.noneOf(ElemType.class), in);

    final String s = RW.readUTF(in);

    myRetentionPolicy = s.length() == 0 ? null : RetentionPolicy.valueOf(s);

    myOuterClassName = DataInputOutputUtil.readINT(in);
    int flags = DataInputOutputUtil.readINT(in);
    myIsLocal = (flags & LOCAL_MASK) != 0;
    myIsAnonymous = (flags & ANONYMOUS_MASK) != 0;
    myUsages =(Set<UsageRepr.Usage>)RW.read(UsageRepr.externalizer(context), new THashSet<UsageRepr.Usage>(), in);
  }
  catch (IOException e) {
    throw new BuildDataCorruptedException(e);
  }
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:26,代碼來源:ClassRepr.java

示例3: test_valueOfLjava_lang_String

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
/**
 * @throws Exception
 * @tests java.lang.annotation.RetentionPolicy#valueOf(String)
 */
@SuppressWarnings("nls")
public void test_valueOfLjava_lang_String() throws Exception {
    assertSame(RetentionPolicy.CLASS, RetentionPolicy
            .valueOf("CLASS"));
    assertSame(RetentionPolicy.RUNTIME, RetentionPolicy
            .valueOf("RUNTIME"));
    assertSame(RetentionPolicy.SOURCE, RetentionPolicy
            .valueOf("SOURCE"));
    try {
        RetentionPolicy.valueOf("OTHER");
        fail("Should throw an IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // expected
    }
}
 
開發者ID:keplersj,項目名稱:In-the-Box-Fork,代碼行數:20,代碼來源:RetentionPolicyTest.java

示例4: ClassRepr

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
public ClassRepr(final DependencyContext context, final DataInput in) {
  super(in);
  try {
    this.myContext = context;
    myFileName = in.readInt();
    mySuperClass = (TypeRepr.ClassType)TypeRepr.externalizer(context).read(in);
    myInterfaces = (Set<TypeRepr.AbstractType>)RW.read(TypeRepr.externalizer(context), new HashSet<TypeRepr.AbstractType>(), in);
    myFields = (Set<FieldRepr>)RW.read(FieldRepr.externalizer(context), new HashSet<FieldRepr>(), in);
    myMethods = (Set<MethodRepr>)RW.read(MethodRepr.externalizer(context), new HashSet<MethodRepr>(), in);
    myAnnotationTargets = (Set<ElemType>)RW.read(UsageRepr.AnnotationUsage.elementTypeExternalizer, EnumSet.noneOf(ElemType.class), in);

    final String s = in.readUTF();

    myRetentionPolicy = s.length() == 0 ? null : RetentionPolicy.valueOf(s);

    myOuterClassName = in.readInt();
    myIsLocal = in.readBoolean();
    myIsAnonymous = in.readBoolean();
    myUsages =(Set<UsageRepr.Usage>)RW.read(UsageRepr.externalizer(context), new HashSet<UsageRepr.Usage>(), in);
  }
  catch (IOException e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:25,代碼來源:ClassRepr.java

示例5: getRetentionPolicy

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
@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,代碼行數:25,代碼來源:AnnotationsHighlightUtil.java

示例6: readRetention

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
private void readRetention()
{
	final Annotation retention = this.theClass.getAnnotation(Annotation.LazyFields.RETENTION_CLASS);
	if (retention == null)
	{
		return;
	}

	final IValue value = retention.getArguments().get(0, Names.value);
	if (!(value instanceof EnumValue))
	{
		return;
	}

	try
	{
		final String name = ((EnumValue) value).getName().qualified;
		this.retention = RetentionPolicy.valueOf(name);
	}
	catch (IllegalArgumentException ignored)
	{
		// Problematic RetentionPolicy annotation - do not handle this
	}
}
 
開發者ID:Dyvil,項目名稱:Dyvil,代碼行數:25,代碼來源:AnnotationMetadata.java

示例7: bindRetention

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
private static RetentionPolicy bindRetention(AnnoInfo annotation) {
  Const value = annotation.values().get("value");
  if (value.kind() != Kind.ENUM_CONSTANT) {
    return null;
  }
  EnumConstantValue enumValue = (EnumConstantValue) value;
  if (!enumValue.sym().owner().toString().equals("java/lang/annotation/RetentionPolicy")) {
    return null;
  }
  return RetentionPolicy.valueOf(enumValue.sym().name());
}
 
開發者ID:google,項目名稱:turbine,代碼行數:12,代碼來源:ConstBinder.java

示例8: bindRetention

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
private RetentionPolicy bindRetention(AnnotationInfo annotation) {
  ElementValue val = annotation.elementValuePairs().get("value");
  if (val.kind() != Kind.ENUM) {
    return null;
  }
  EnumConstValue enumVal = (EnumConstValue) val;
  if (!enumVal.typeName().equals("Ljava/lang/annotation/RetentionPolicy;")) {
    return null;
  }
  return RetentionPolicy.valueOf(enumVal.constName());
}
 
開發者ID:google,項目名稱:turbine,代碼行數:12,代碼來源:BytecodeBoundClass.java

示例9: visitEnum

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
@Override
public void visitEnum(String name, String desc, String value) {
  myRetentionPolicy = RetentionPolicy.valueOf(value);
}
 
開發者ID:jskierbi,項目名稱:intellij-ce-playground,代碼行數:5,代碼來源:ClassfileAnalyzer.java

示例10: visitEnum

import java.lang.annotation.RetentionPolicy; //導入方法依賴的package包/類
public void visitEnum(String name, String desc, String value) {
  myRetentionPolicy = RetentionPolicy.valueOf(value);
}
 
開發者ID:lshain-android-source,項目名稱:tools-idea,代碼行數:4,代碼來源:ClassfileAnalyzer.java


注:本文中的java.lang.annotation.RetentionPolicy.valueOf方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。