void use() {
// this immutable type (package style used)
ImIncludeTypes.builder().build();
// included on this type (package style used)
ImSerializable.builder().build();
// included on package (package style used)
ImTicker.builder().read(1).build();
// included in IncludeNestedTypes
ImmutableIncludeNestedTypes.Retention retention =
ImmutableIncludeNestedTypes.Retention.builder()
.value(RetentionPolicy.CLASS)
.build();
// included in IncludeNestedTypes
ImmutableIncludeNestedTypes.Target target =
ImmutableIncludeNestedTypes.Target.builder()
.value(ElementType.CONSTRUCTOR, ElementType.ANNOTATION_TYPE)
.build();
// package applied style "copyWith*" test
// see PackageStyle
retention.copyWithValue(RetentionPolicy.RUNTIME);
target.copyWithValue(ElementType.CONSTRUCTOR, ElementType.LOCAL_VARIABLE);
}
java类java.lang.annotation.RetentionPolicy的实例源码
IncludeTypes.java 文件源码
项目:GitHub
阅读 33
收藏 0
点赞 0
评论 0
UseImmutableCollections.java 文件源码
项目:GitHub
阅读 34
收藏 0
点赞 0
评论 0
default void use() {
ImmutableUseImmutableCollections.builder()
.addList("a", "b")
.addSet(1, 2)
.addEnumSet(RetentionPolicy.CLASS)
.addSortedSet(RetentionPolicy.RUNTIME)
.addMultiset("c", "c")
.putMap("d", 1)
.putEnumMap(RetentionPolicy.RUNTIME, 2)
.putSortedMap(RetentionPolicy.SOURCE, 3)
.putMultimap("e", 2)
.putSetMultimap("f", 5)
.putListMultimap("g", 6)
.build();
}
JdkOnlyTest.java 文件源码
项目:GitHub
阅读 34
收藏 0
点赞 0
评论 0
@Test
public void collections() {
ImmutableJdkColl coll = ImmutableJdkColl.builder()
.addInts(1)
.addInts(2, 3)
.addAllInts(Arrays.asList(4, 5, 6))
.addNavs(1, 2, 3)
.addOrds(4, 6, 5)
.addAllOrds(Arrays.asList(8, 7, 9))
.addPols(RetentionPolicy.RUNTIME, RetentionPolicy.RUNTIME)
.build();
check(coll.ints()).isOf(1, 2, 3, 4, 5, 6);
check(coll.navs()).isOf(3, 2, 1);
check(coll.ords()).isOf(4, 5, 6, 7, 8, 9);
check(coll.pols()).isOf(RetentionPolicy.RUNTIME);
}
FactoryParametersAndSwitcherTest.java 文件源码
项目:GitHub
阅读 36
收藏 0
点赞 0
评论 0
@Test
public void switcher() {
check(Factory4Builder.newBuilder(4)
.runtimePolicy()
.sourcePolicy()
.classPolicy()
.build()).is("" + RetentionPolicy.CLASS + 4);
check(Factory4Builder.newBuilder(42)
.sourcePolicy()
.runtimePolicy()
.build()).is("" + RetentionPolicy.RUNTIME + 42);
try {
Factory4Builder.newBuilder(44).build();
check(false);
} catch (IllegalStateException ex) {
}
}
Jsr303Annotator.java 文件源码
项目:beanvalidation-benchmark
阅读 38
收藏 0
点赞 0
评论 0
private JDefinedClass buildTemplateConstraint(String name) {
try {
JDefinedClass tplConstraint = codeModel._class(Config.CFG.getBasePackageName() + ".annot."+name, ClassType.ANNOTATION_TYPE_DECL);
tplConstraint.annotate(Documented.class);
tplConstraint.annotate(Retention.class).param("value", RetentionPolicy.RUNTIME);
tplConstraint.annotate(Target.class).paramArray("value").param(ElementType.TYPE).param(ElementType.ANNOTATION_TYPE).param(ElementType.FIELD).param(ElementType.METHOD);
// Using direct as I don't know how to build default { } with code model
tplConstraint.direct("\n" + " Class<?>[] groups() default {};\n" + " String message() default \"Invalid value\";\n" + " Class<? extends Payload>[] payload() default {};\n");
// Hack to force the import of javax.validation.Payload
tplConstraint.javadoc().addThrows((JClass) codeModel._ref(Payload.class)).add("Force import");
return tplConstraint;
} catch (JClassAlreadyExistsException e) {
throw new RuntimeException("Tried to create an already existing class: " + name, e);
}
}
ArchitectureTest.java 文件源码
项目:russian-requisites-validator
阅读 29
收藏 0
点赞 0
评论 0
private static ArchCondition<JavaClass> retention(final RetentionPolicy expected) {
return new ArchCondition<JavaClass>("retention " + expected.name()) {
@Override
public void check(JavaClass item, ConditionEvents events) {
Optional<Retention> annotation = item.tryGetAnnotationOfType(Retention.class);
if (annotation.isPresent()) {
RetentionPolicy actual = annotation.get().value();
boolean equals = expected.equals(actual);
String message = String.format("class %s is annotated with %s with value = '%s' which %s with required '%s'",
item.getName(), Retention.class.getSimpleName(), actual.name(), equals ? "equals" : "not equals", expected.name()
);
events.add(equals ? SimpleConditionEvent.satisfied(item, message) : SimpleConditionEvent.violated(item, message));
}
}
};
}
ClassMembersTest.java 文件源码
项目:openjdk-jdk10
阅读 36
收藏 0
点赞 0
评论 0
@Test(dataProvider = "retentionPolicyTestCase")
public void annotationTest(RetentionPolicy policy) {
assertEval("import java.lang.annotation.*;");
String annotationSource =
"@Retention(RetentionPolicy." + policy.toString() + ")\n" +
"@interface A {}";
assertEval(annotationSource);
String classSource =
"@A class C {\n" +
" @A C() {}\n" +
" @A void f() {}\n" +
" @A int f;\n" +
" @A class Inner {}\n" +
"}";
assertEval(classSource);
String isRuntimeVisible = policy == RetentionPolicy.RUNTIME ? "true" : "false";
assertEval("C.class.getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredConstructor().getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredMethod(\"f\").getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredField(\"f\").getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.Inner.class.getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
}
AnnotationDefaultTest.java 文件源码
项目:openjdk-jdk10
阅读 35
收藏 0
点赞 0
评论 0
public void test() throws TestFailedException {
try {
String template = getSource(getSourceFile(templateFileName));
for (int i = 0; i < 2; ++i) {
for (String repeatable : new String[] {"", "@Repeatable(Container.class)"}) {
for (RetentionPolicy policy : RetentionPolicy.values()) {
final int finalI = i;
Map<String, String> replacements = new HashMap<String, String>(){{
put("%POLICY%", policy.toString());
if (finalI != 0) {
put("default.*\n", ";\n");
}
put("%REPEATABLE%", repeatable);
}};
test(template, replacements, i == 0);
}
}
}
} catch (Throwable e) {
addFailure(e);
} finally {
checkStatus();
}
}
ClassMembersTest.java 文件源码
项目:openjdk9
阅读 28
收藏 0
点赞 0
评论 0
@Test(enabled = false) // TODO 8080354
public void annotationTest() {
assertEval("import java.lang.annotation.*;");
for (RetentionPolicy policy : RetentionPolicy.values()) {
String annotationSource =
"@Retention(RetentionPolicy." + policy.toString() + ")\n" +
"@interface A {}";
assertEval(annotationSource);
String classSource =
"@A class C {\n" +
" @A C() {}\n" +
" @A void f() {}\n" +
" @A int f;\n" +
" @A class Inner {}\n" +
"}";
assertEval(classSource);
String isRuntimeVisible = policy == RetentionPolicy.RUNTIME ? "true" : "false";
assertEval("C.class.getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredConstructor().getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredMethod(\"f\").getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.class.getDeclaredField(\"f\").getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
assertEval("C.Inner.class.getAnnotationsByType(A.class).length > 0;", isRuntimeVisible);
}
}
AnnotationDefaultTest.java 文件源码
项目:openjdk9
阅读 32
收藏 0
点赞 0
评论 0
public void test() throws TestFailedException {
try {
String template = getSource(getSourceFile(templateFileName));
for (int i = 0; i < 2; ++i) {
for (String repeatable : new String[] {"", "@Repeatable(Container.class)"}) {
for (RetentionPolicy policy : RetentionPolicy.values()) {
final int finalI = i;
Map<String, String> replacements = new HashMap<String, String>(){{
put("%POLICY%", policy.toString());
if (finalI != 0) {
put("default.*\n", ";\n");
}
put("%REPEATABLE%", repeatable);
}};
test(template, replacements, i == 0);
}
}
}
} catch (Throwable e) {
addFailure(e);
} finally {
checkStatus();
}
}
NoRuntimeRetention.java 文件源码
项目:huntbugs
阅读 33
收藏 0
点赞 0
评论 0
@AstVisitor(nodes = AstNodes.EXPRESSIONS)
public void visit(Expression expr, MethodContext mc, DeclaredAnnotations da) {
if (expr.getCode() == AstCode.InvokeVirtual && expr.getArguments().size() == 2) {
MethodReference mr = (MethodReference) expr.getOperand();
if ((mr.getDeclaringType().getInternalName().startsWith("java/lang/reflect/") || mr.getDeclaringType()
.getInternalName().equals("java/lang/Class")) && mr.getName().contains("Annotation")) {
Object constant = Nodes.getConstant(expr.getArguments().get(1));
if (constant instanceof TypeReference) {
TypeReference tr = (TypeReference) constant;
DeclaredAnnotation annot = da.get(tr);
if (annot != null && annot.getPolicy() != RetentionPolicy.RUNTIME) {
mc.report("AnnotationNoRuntimeRetention", 0, expr, ANNOTATION.create(tr));
}
}
}
}
}
DeclaredAnnotations.java 文件源码
项目:huntbugs
阅读 29
收藏 0
点赞 0
评论 0
@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());
}
}
}
}
}
}
}
ConstBinder.java 文件源码
项目:turbine
阅读 31
收藏 0
点赞 0
评论 0
static AnnotationMetadata bindAnnotationMetadata(
TurbineTyKind kind, Iterable<AnnoInfo> annotations) {
if (kind != TurbineTyKind.ANNOTATION) {
return null;
}
RetentionPolicy retention = null;
ImmutableSet<ElementType> target = null;
ClassSymbol repeatable = null;
for (AnnoInfo annotation : annotations) {
switch (annotation.sym().binaryName()) {
case "java/lang/annotation/Retention":
retention = bindRetention(annotation);
break;
case "java/lang/annotation/Target":
target = bindTarget(annotation);
break;
case "java/lang/annotation/Repeatable":
repeatable = bindRepeatable(annotation);
break;
default:
break;
}
}
return new AnnotationMetadata(retention, target, repeatable);
}
BytecodeBoundClass.java 文件源码
项目:turbine
阅读 42
收藏 0
点赞 0
评论 0
@Override
public AnnotationMetadata get() {
if ((access() & TurbineFlag.ACC_ANNOTATION) != TurbineFlag.ACC_ANNOTATION) {
return null;
}
RetentionPolicy retention = null;
ImmutableSet<ElementType> target = null;
ClassSymbol repeatable = null;
for (ClassFile.AnnotationInfo annotation : classFile.get().annotations()) {
switch (annotation.typeName()) {
case "Ljava/lang/annotation/Retention;":
retention = bindRetention(annotation);
break;
case "Ljava/lang/annotation/Target;":
target = bindTarget(annotation);
break;
case "Ljava/lang/annotation/Repeatable;":
repeatable = bindRepeatable(annotation);
break;
default:
break;
}
}
return new AnnotationMetadata(retention, target, repeatable);
}
TypeModel.java 文件源码
项目:Lyrics
阅读 40
收藏 0
点赞 0
评论 0
public TypeModel(Type type, Modifier[] modifiers, VariableModel extendsType, Set<VariableModel> interfaces, List<GenericVariableModel> genericVariables, List<AnnotationModel> annotations, Map<String, FieldModel> fields, Map<String, MethodModel> methods, InclusionType inclusion, List<String> values, Map<String, Object[]> valuesWithFields, List<String> fieldOrder, SubTypeModel subTypes, RetentionPolicy retention, ElementType[] elementTypes, List<String> customConstructorFields) {
this.type = type;
this.modifiers = modifiers;
this.extendsType = extendsType;
this.interfaces = interfaces;
this.genericVariables = genericVariables;
this.annotations = annotations;
this.fields = fields;
this.methods = methods;
this.inclusion = inclusion;
this.values = values;
this.valuesWithFields = valuesWithFields;
this.fieldOrder = fieldOrder;
this.subTypes = subTypes;
this.retention = retention;
this.elementTypes = elementTypes;
this.customConstructorFields = customConstructorFields;
}
StringDefValuesHandler.java 文件源码
项目:Lyrics
阅读 32
收藏 0
点赞 0
评论 0
@Override
public void process(TypeSpec.Builder typeBuilder, TypeModel typeModel) {
String valuesStr = "";
for (String key : getEnumValues(typeModel)) {
valuesStr += key + ", ";
typeBuilder.addField(FieldSpec.builder(ClassName.get(String.class), key)
.addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
.initializer("$S", key)
.build());
}
AnnotationSpec.Builder retentionAnnotation = AnnotationSpec.builder(ClassName.get(Retention.class)).
addMember("value", "$T.SOURCE", ClassName.get(RetentionPolicy.class));
AnnotationSpec.Builder intDefAnnotation = AnnotationSpec.builder(ClassName.get("android.support.annotation", "StringDef"))
.addMember("value", "{ $L }", valuesStr.substring(0, valuesStr.length() - 2));
typeBuilder.addType(TypeSpec.annotationBuilder(metaInfo.getClassName() + "Def").
addModifiers(Modifier.PUBLIC).
addAnnotation(retentionAnnotation.build()).
addAnnotation(intDefAnnotation.build()).
build());
}
ClassTest.java 文件源码
项目:naum
阅读 36
收藏 0
点赞 0
评论 0
@Test
public void loadAndCheckAnnotatedAnnotation() throws Exception {
ClassInfo classInfo = ClassInfo.newAnnotation()
.name("org.kordamp.naum.processor.klass.AnnotatedAnnotation")
.iface(Annotation.class.getName())
.build();
classInfo.addToAnnotations(annotationInfo()
.name(Retention.class.getName())
.annotationValue("value", new EnumValue(RetentionPolicy.class.getName(), "SOURCE"))
.build());
classInfo.addToAnnotations(annotationInfo()
.name(Target.class.getName())
.annotationValue("value", newArrayValue(asList(
newEnumValue(ElementType.class.getName(), ElementType.TYPE.name()),
newEnumValue(ElementType.class.getName(), ElementType.FIELD.name()))
))
.build());
loadAndCheck("org/kordamp/naum/processor/klass/AnnotatedAnnotation.class", (klass) -> {
assertThat(klass.getContentHash(), equalTo(classInfo.getContentHash()));
assertThat(klass, equalTo(classInfo));
});
}
ClassRepr.java 文件源码
项目:intellij-ce-playground
阅读 37
收藏 0
点赞 0
评论 0
public ClassRepr(final DependencyContext context, final int a, final int fn, final int n, final int sig,
final int sup,
final String[] i,
final Set<FieldRepr> f,
final Set<MethodRepr> m,
final Set<ElemType> targets,
final RetentionPolicy policy,
final int outerClassName,
final boolean localClassFlag,
final boolean anonymousClassFlag,
final Set<UsageRepr.Usage> usages) {
super(a, sig, n);
this.myContext = context;
myFileName = fn;
mySuperClass = TypeRepr.createClassType(context, sup);
myInterfaces = (Set<TypeRepr.AbstractType>)TypeRepr.createClassType(context, i, new THashSet<TypeRepr.AbstractType>(1));
myFields = f;
myMethods = m;
this.myAnnotationTargets = targets;
this.myRetentionPolicy = policy;
this.myOuterClassName = outerClassName;
this.myIsLocal = localClassFlag;
this.myIsAnonymous = anonymousClassFlag;
this.myUsages = usages;
}
ClassRepr.java 文件源码
项目:intellij-ce-playground
阅读 45
收藏 0
点赞 0
评论 0
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);
}
}
AnonymousCanBeLambdaInspection.java 文件源码
项目:intellij-ce-playground
阅读 32
收藏 0
点赞 0
评论 0
private static boolean hasRuntimeAnnotations(PsiMethod method) {
PsiAnnotation[] annotations = method.getModifierList().getAnnotations();
for (PsiAnnotation annotation : annotations) {
PsiJavaCodeReferenceElement ref = annotation.getNameReferenceElement();
PsiElement target = ref != null ? ref.resolve() : null;
if (target instanceof PsiClass) {
final PsiAnnotation retentionAnno = AnnotationUtil.findAnnotation((PsiClass)target, Retention.class.getName());
if (retentionAnno != null) {
PsiAnnotationMemberValue value = retentionAnno.findAttributeValue("value");
if (value instanceof PsiReferenceExpression) {
final PsiElement resolved = ((PsiReferenceExpression)value).resolve();
if (resolved instanceof PsiField && RetentionPolicy.RUNTIME.name().equals(((PsiField)resolved).getName())) {
final PsiClass containingClass = ((PsiField)resolved).getContainingClass();
if (containingClass != null && RetentionPolicy.class.getName().equals(containingClass.getQualifiedName())) {
return true;
}
}
}
}
}
}
return false;
}
AnnotationsHighlightUtil.java 文件源码
项目:intellij-ce-playground
阅读 33
收藏 0
点赞 0
评论 0
@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;
}
Controller.java 文件源码
项目:Diorite
阅读 39
收藏 0
点赞 0
评论 0
@Override
protected Map<Class<? extends Annotation>, ? extends Annotation> extractRawScopeAnnotations(AnnotatedCodeElement element)
{
Annotation[] annotations = AsmUtils.getAnnotations(element, RetentionPolicy.RUNTIME);
Map<Class<? extends Annotation>, Annotation> resultMap = new HashMap<>(annotations.length + 1);
for (Annotation annotation : annotations)
{
Class<? extends Annotation> annotationType = annotation.annotationType();
if (annotationType.isAnnotationPresent(Scope.class))
{
if (resultMap.containsKey(annotationType))
{
throw new IllegalStateException("Duplicated scope! Found: " + annotation + ", others: " + resultMap);
}
resultMap.put(annotationType, annotation);
}
}
return resultMap;
}
BindingUtil.java 文件源码
项目:j2objc
阅读 38
收藏 0
点赞 0
评论 0
/**
* Returns true if the specified binding is of an annotation that has
* a runtime retention policy.
*/
public static boolean isRuntimeAnnotation(ITypeBinding binding) {
if (binding != null && binding.isAnnotation()) {
for (IAnnotationBinding ann : binding.getAnnotations()) {
if (ann.getName().equals("Retention")) {
IVariableBinding retentionBinding =
(IVariableBinding) ann.getDeclaredMemberValuePairs()[0].getValue();
return retentionBinding.getName().equals(RetentionPolicy.RUNTIME.name());
}
}
if (binding.isNested()) {
return BindingUtil.isRuntimeAnnotation(binding.getDeclaringClass());
}
}
return false;
}
JavapParser.java 文件源码
项目:annotation-tools
阅读 28
收藏 0
点赞 0
评论 0
private void parseAnnotationSection(AElement member, AnnotationSection sec) throws IOException, ParseException {
// FILL
while (inData()) {
String annoTypeName = parseAnnotationHead();
RetentionPolicy retention = sec.retention;
AnnotationBuilder ab = AnnotationFactory.saf.beginAnnotation(annoTypeName, Annotations.getRetentionPolicyMetaAnnotationSet(retention));
if (ab == null) {
// don't care about the result
// but need to skip over it anyway
parseAnnotationBody(
AnnotationFactory.saf.beginAnnotation(annoTypeName, Annotations.noAnnotations),
SECTION_DATA_PREFIX);
} else {
// Wrap it in a TLA with the appropriate retention policy
Annotation a = parseAnnotationBody(ab, SECTION_DATA_PREFIX);
// Now we need to parse the location information to determine
// which element gets the annotation.
AElement annoMember = chooseSubElement(member, sec);
annoMember.tlAnnotationsHere.add(a);
}
}
}
AutoDataAnnotationProcessor.java 文件源码
项目:autodata
阅读 35
收藏 0
点赞 0
评论 0
@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());
}
RetentionPolicyTest.java 文件源码
项目:In-the-Box-Fork
阅读 31
收藏 0
点赞 0
评论 0
/**
* @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
}
}
RetentionPolicyTest.java 文件源码
项目:cn1
阅读 33
收藏 0
点赞 0
评论 0
/**
* @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
}
}
CustomReferenceNameProviderTest.java 文件源码
项目:JSONschema4-mapper
阅读 29
收藏 0
点赞 0
评论 0
@Test
public void enumReferenceTest() throws Exception {
//given
final String prefix = "c>";
mapper.setReferenceNameProvider(new DefaultReferenceNameProvider() {
@Override
protected String getPrefix() {
return prefix;
}
});
//when
final JSONObject schema = mapper.toJsonSchema4(Empty.class);
//then
final String enumRef = schema.getJSONObject("properties").getJSONObject("policy").getString("$ref");
assertThat(enumRef, equalTo(prefix + RetentionPolicy.class.getSimpleName()));
}
ClassRepr.java 文件源码
项目:tools-idea
阅读 43
收藏 0
点赞 0
评论 0
public ClassRepr(final DependencyContext context, final int a, final int fn, final int n, final int sig,
final int sup,
final String[] i,
final Set<FieldRepr> f,
final Set<MethodRepr> m,
final Set<ElemType> targets,
final RetentionPolicy policy,
final int outerClassName,
final boolean localClassFlag,
final boolean anonymousClassFlag,
final Set<UsageRepr.Usage> usages) {
super(a, sig, n);
this.myContext = context;
myFileName = fn;
mySuperClass = TypeRepr.createClassType(context, sup);
myInterfaces = (Set<TypeRepr.AbstractType>)TypeRepr.createClassType(context, i, new HashSet<TypeRepr.AbstractType>());
myFields = f;
myMethods = m;
this.myAnnotationTargets = targets;
this.myRetentionPolicy = policy;
this.myOuterClassName = outerClassName;
this.myIsLocal = localClassFlag;
this.myIsAnonymous = anonymousClassFlag;
this.myUsages = usages;
}
ClassRepr.java 文件源码
项目:tools-idea
阅读 48
收藏 0
点赞 0
评论 0
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);
}
}