use of org.checkerframework.framework.qual.ImplicitFor in project checker-framework by typetools.
the class WholeProgramInferenceScenesHelper method shouldIgnore.
/**
* Returns true if {@code am} should not be inserted in source code, for example {@link
* org.checkerframework.common.value.qual.BottomVal}. This happens when {@code am} cannot be
* inserted in source code or is the default for the location passed as argument.
*
* <p>Invisible qualifiers, which are annotations that contain the {@link
* org.checkerframework.framework.qual.InvisibleQualifier} meta-annotation, also return true.
*
* <p>TODO: Merge functionality somewhere else with {@link
* org.checkerframework.framework.type.GenericAnnotatedTypeFactory#createQualifierDefaults}.
* Look into the createQualifierDefaults method before changing anything here. See Issue 683
* https://github.com/typetools/checker-framework/issues/683
*/
private boolean shouldIgnore(AnnotationMirror am, TypeUseLocation location, AnnotatedTypeFactory atf, AnnotatedTypeMirror atm) {
Element elt = am.getAnnotationType().asElement();
// Checks if am is an implementation detail (a type qualifier used
// internally by the type system and not meant to be seen by the user.)
Target target = elt.getAnnotation(Target.class);
if (target != null && target.value().length == 0)
return true;
if (elt.getAnnotation(InvisibleQualifier.class) != null)
return true;
// Checks if am is default
if (elt.getAnnotation(DefaultQualifierInHierarchy.class) != null) {
return true;
}
DefaultQualifier defaultQual = elt.getAnnotation(DefaultQualifier.class);
if (defaultQual != null) {
for (TypeUseLocation loc : defaultQual.locations()) {
if (loc == TypeUseLocation.ALL || loc == location) {
return true;
}
}
}
DefaultFor defaultQualForLocation = elt.getAnnotation(DefaultFor.class);
if (defaultQualForLocation != null) {
for (TypeUseLocation loc : defaultQualForLocation.value()) {
if (loc == TypeUseLocation.ALL || loc == location) {
return true;
}
}
}
// Checks if am is an implicit annotation.
// This case checks if it is meta-annotated with @ImplicitFor.
// TODO: Handle cases of implicit annotations added via an
// org.checkerframework.framework.type.treeannotator.ImplicitsTreeAnnotator.
ImplicitFor implicitFor = elt.getAnnotation(ImplicitFor.class);
if (implicitFor != null) {
org.checkerframework.framework.qual.TypeKind[] types = implicitFor.types();
TypeKind atmKind = atm.getUnderlyingType().getKind();
if (hasMatchingTypeKind(atmKind, types)) {
return true;
}
try {
Class<?>[] names = implicitFor.typeNames();
for (Class<?> c : names) {
TypeMirror underlyingtype = atm.getUnderlyingType();
while (underlyingtype instanceof javax.lang.model.type.ArrayType) {
underlyingtype = ((javax.lang.model.type.ArrayType) underlyingtype).getComponentType();
}
if (c.getCanonicalName().equals(atm.getUnderlyingType().toString())) {
return true;
}
}
} catch (MirroredTypesException e) {
}
}
return false;
}
Aggregations