本文整理汇总了Java中java.lang.annotation.RetentionPolicy.values方法的典型用法代码示例。如果您正苦于以下问题:Java RetentionPolicy.values方法的具体用法?Java RetentionPolicy.values怎么用?Java RetentionPolicy.values使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.lang.annotation.RetentionPolicy
的用法示例。
在下文中一共展示了RetentionPolicy.values方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import java.lang.annotation.RetentionPolicy; //导入方法依赖的package包/类
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();
}
}
示例2: annotationTest
import java.lang.annotation.RetentionPolicy; //导入方法依赖的package包/类
@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);
}
}
示例3: retentionPolicyTestCaseGenerator
import java.lang.annotation.RetentionPolicy; //导入方法依赖的package包/类
@DataProvider(name = "retentionPolicyTestCase")
public Object[][] retentionPolicyTestCaseGenerator() {
List<Object[]> list = new ArrayList<>();
for (RetentionPolicy policy : RetentionPolicy.values()) {
list.add(new Object[]{policy});
}
return list.toArray(new Object[list.size()][]);
}
示例4: test_values
import java.lang.annotation.RetentionPolicy; //导入方法依赖的package包/类
/**
* @throws Exception
* @tests java.lang.annotation.RetentionPolicy#values()
*/
@SuppressWarnings("nls")
public void test_values() throws Exception {
RetentionPolicy[] values = RetentionPolicy.values();
assertTrue(values.length > 1);
Arrays.sort(values);
assertTrue(Arrays.binarySearch(values, RetentionPolicy.RUNTIME) >= 0);
}