Java Code Examples for java.lang.annotation.RetentionPolicy#SOURCE
The following examples show how to use
java.lang.annotation.RetentionPolicy#SOURCE .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PsiAnnotationExtractor.java From litho with Apache License 2.0 | 6 votes |
/** * We consider an annotation to be valid for extraction if it's not an internal annotation (i.e. * is in the <code>com.facebook.litho</code> package and is not a source-only annotation. * * @return Whether or not to extract the given annotation. */ private static boolean isValidAnnotation(Project project, PsiAnnotation psiAnnotation) { final String text = psiAnnotation.getQualifiedName(); if (text.startsWith("com.facebook.")) { return false; } PsiClass annotationClass = PsiSearchUtils.findClass(project, psiAnnotation.getQualifiedName()); if (annotationClass == null) { throw new RuntimeException("Annotation class not found, text is: " + text); } final Retention retention = PsiAnnotationProxyUtils.findAnnotationInHierarchy(annotationClass, Retention.class); return retention == null || retention.value() != RetentionPolicy.SOURCE; }
Example 2
Source File: AnnotationCreatorImpl.java From gizmo with Apache License 2.0 | 5 votes |
AnnotationCreatorImpl(String annotationType, RetentionPolicy retentionPolicy) { this.annotationType = annotationType; if (retentionPolicy == RetentionPolicy.SOURCE) { throw new IllegalArgumentException("Unsupported retention policy SOURCE"); } this.retentionPolicy = retentionPolicy; }
Example 3
Source File: AnnotationExtractor.java From litho with Apache License 2.0 | 5 votes |
/** * We consider an annotation to be valid for extraction if it's not an internal annotation (i.e. * is in the <code>com.facebook.litho</code> package and is not a source-only annotation. * * <p>We also do not consider the kotlin.Metadata annotation to be valid as it represents the * metadata of the Spec class and not of the class that we are generating. * * @return Whether or not to extract the given annotation. */ private static boolean isValidAnnotation(AnnotationMirror annotation) { final Retention retention = annotation.getAnnotationType().asElement().getAnnotation(Retention.class); if (retention != null && retention.value() == RetentionPolicy.SOURCE) { return false; } String annotationName = annotation.getAnnotationType().toString(); return !annotationName.startsWith("com.facebook.") && !annotationName.equals("kotlin.Metadata"); }
Example 4
Source File: RuntimeAnnotationsTestBase.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
private void testAttributes( TestCase.TestMemberInfo member, ClassFile classFile, Supplier<Attributes> attributes) throws ConstantPoolException { Map<String, Annotation> actualInvisible = collectAnnotations( classFile, member, attributes.get(), Attribute.RuntimeInvisibleAnnotations); Map<String, Annotation> actualVisible = collectAnnotations( classFile, member, attributes.get(), Attribute.RuntimeVisibleAnnotations); checkEquals(actualInvisible.keySet(), member.getRuntimeInvisibleAnnotations(), "RuntimeInvisibleAnnotations"); checkEquals(actualVisible.keySet(), member.getRuntimeVisibleAnnotations(), "RuntimeVisibleAnnotations"); for (TestAnnotationInfo expectedAnnotation : member.annotations.values()) { RetentionPolicy policy = getRetentionPolicy(expectedAnnotation.annotationName); if (policy == RetentionPolicy.SOURCE) { continue; } printf("Testing: isVisible: %s %s%n", policy.toString(), expectedAnnotation.annotationName); Annotation actualAnnotation = (policy == RetentionPolicy.RUNTIME ? actualVisible : actualInvisible) .get(expectedAnnotation.annotationName); if (checkNotNull(actualAnnotation, "Annotation is found : " + expectedAnnotation.annotationName)) { expectedAnnotation.testAnnotation(this, classFile, actualAnnotation); } } }
Example 5
Source File: AnnotationDef.java From annotation-tools with MIT License | 5 votes |
/** * 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. * * @return the retention policy for annotations of this type */ 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; } }
Example 6
Source File: CanBeAnnotated.java From ArchUnit with Apache License 2.0 | 4 votes |
private static boolean isRetentionSource(Class<? extends Annotation> annotationType) { return annotationType.getAnnotation(Retention.class) != null && (annotationType.getAnnotation(Retention.class).value() == RetentionPolicy.SOURCE); }
Example 7
Source File: SillySubstructure.java From immutables with Apache License 2.0 | 4 votes |
@Value.Default @SerializedName("e1") public RetentionPolicy enum1() { return RetentionPolicy.SOURCE; }