use of java.lang.annotation.RetentionPolicy in project groovy by apache.
the class Java5 method configureAnnotationFromDefinition.
public static void configureAnnotationFromDefinition(AnnotationNode definition, AnnotationNode root) {
ClassNode type = definition.getClassNode();
if ("java.lang.annotation.Retention".equals(type.getName())) {
Expression exp = definition.getMember("value");
if (!(exp instanceof PropertyExpression))
return;
PropertyExpression pe = (PropertyExpression) exp;
String name = pe.getPropertyAsString();
RetentionPolicy policy = RetentionPolicy.valueOf(name);
setRetentionPolicy(policy, root);
} else if ("java.lang.annotation.Target".equals(type.getName())) {
Expression exp = definition.getMember("value");
if (!(exp instanceof ListExpression))
return;
ListExpression le = (ListExpression) exp;
int bitmap = 0;
for (Expression e : le.getExpressions()) {
if (!(e instanceof PropertyExpression))
return;
PropertyExpression element = (PropertyExpression) e;
String name = element.getPropertyAsString();
ElementType value = ElementType.valueOf(name);
bitmap |= getElementCode(value);
}
root.setAllowedTargets(bitmap);
}
}
use of java.lang.annotation.RetentionPolicy in project intellij-plugins by JetBrains.
the class PackageAccessibilityInspection method checkAccessibility.
// OSGi Core Spec 3.5 "Class Loading Architecture"
private static Problem checkAccessibility(PsiClass targetClass, OsmorcFacet facet) {
// ignores annotations invisible at runtime
if (targetClass.isAnnotationType()) {
RetentionPolicy retention = AnnotationsHighlightUtil.getRetentionPolicy(targetClass);
if (retention == RetentionPolicy.SOURCE || retention == RetentionPolicy.CLASS) {
return null;
}
}
// ignores files of unsupported type
PsiFile targetFile = targetClass.getContainingFile();
if (!(targetFile instanceof PsiClassOwner)) {
return null;
}
// accepts classes from the parent class loader (normally java.* packages from the boot class path)
String packageName = ((PsiClassOwner) targetFile).getPackageName();
if (packageName.isEmpty() || packageName.startsWith("java.")) {
return null;
}
// accepts classes from the bundle's class path (private packages)
Module requestorModule = facet.getModule();
Module targetModule = ModuleUtilCore.findModuleForPsiElement(targetClass);
if (targetModule == requestorModule) {
return null;
}
BundleManifest importer = BundleManifestCache.getInstance(targetClass.getProject()).getManifest(requestorModule);
if (importer != null && (importer.isPrivatePackage(packageName) || importer.getExportedPackage(packageName) != null)) {
return null;
}
// rejects non-exported classes (manifest missing, or a package isn't listed as exported)
BundleManifest exporter = BundleManifestCache.getInstance(targetClass.getProject()).getManifest(targetClass);
if (exporter == null || exporter.getBundleSymbolicName() == null) {
return Problem.weak(message("PackageAccessibilityInspection.non.osgi", packageName));
}
String exportedPackage = exporter.getExportedPackage(packageName);
if (exportedPackage == null) {
return Problem.error(message("PackageAccessibilityInspection.not.exported", packageName));
}
// ignores facets other than manually-edited manifests (most probably, they will have their import list correctly generated)
if (!facet.getConfiguration().isManifestManuallyEdited()) {
return null;
}
// accepts packages listed as imported or required
if (importer != null) {
if (importer.isPackageImported(packageName)) {
return null;
}
if (importer.isBundleRequired(exporter.getBundleSymbolicName())) {
return null;
}
// Attached fragments [AFAIK these should not be linked statically - r.sh]
}
return Problem.error(message("PackageAccessibilityInspection.not.imported", packageName), new ImportPackageFix(exportedPackage));
}
Aggregations