use of org.checkerframework.checker.mustcall.qual.CreatesMustCallFor in project checker-framework by typetools.
the class CreatesMustCallForElementSupplier method getCreatesMustCallForExpressions.
/**
* Returns the elements of the @CreatesMustCallFor annotation on the invoked method, as
* JavaExpressions. Returns the empty set if the given method has no @CreatesMustCallFor
* annotation.
*
* <p>If any expression is unparseable, this method reports an error and returns the empty set.
*
* @param n a method invocation
* @param atypeFactory the type factory to report errors and parse the expression string
* @param supplier a type factory that can supply the executable elements for CreatesMustCallFor
* and CreatesMustCallFor.List's value elements. Usually, you should just pass atypeFactory
* again. The arguments are different so that the given type factory's adherence to both
* protocols are checked by the type system.
* @return the arguments of the method's @CreatesMustCallFor annotation, or an empty list
*/
static List<JavaExpression> getCreatesMustCallForExpressions(MethodInvocationNode n, GenericAnnotatedTypeFactory<?, ?, ?, ?> atypeFactory, CreatesMustCallForElementSupplier supplier) {
AnnotationMirror createsMustCallForList = atypeFactory.getDeclAnnotation(n.getTarget().getMethod(), CreatesMustCallFor.List.class);
List<JavaExpression> results = new ArrayList<>(1);
if (createsMustCallForList != null) {
// Handle a set of CreatesMustCallFor annotations.
List<AnnotationMirror> createsMustCallForAnnos = AnnotationUtils.getElementValueArray(createsMustCallForList, supplier.getCreatesMustCallForListValueElement(), AnnotationMirror.class);
for (AnnotationMirror createsMustCallFor : createsMustCallForAnnos) {
JavaExpression expr = getCreatesMustCallForExpression(createsMustCallFor, n, atypeFactory, supplier);
if (expr != null && !results.contains(expr)) {
results.add(expr);
}
}
}
AnnotationMirror createsMustCallFor = atypeFactory.getDeclAnnotation(n.getTarget().getMethod(), CreatesMustCallFor.class);
if (createsMustCallFor != null) {
JavaExpression expr = getCreatesMustCallForExpression(createsMustCallFor, n, atypeFactory, supplier);
if (expr != null && !results.contains(expr)) {
results.add(expr);
}
}
return results;
}
use of org.checkerframework.checker.mustcall.qual.CreatesMustCallFor in project checker-framework by typetools.
the class ResourceLeakVisitor method getCreatesMustCallForValues.
/**
* Returns all the {@link CreatesMustCallFor#value} elements/arguments of all @CreatesMustCallFor
* annotations on the given element.
*
* <p>Does no viewpoint-adaptation, unlike {@link
* CreatesMustCallForElementSupplier#getCreatesMustCallForExpressions} which does.
*
* @param elt an executable element
* @param mcAtf a MustCallAnnotatedTypeFactory, to source the value element
* @param atypeFactory a ResourceLeakAnnotatedTypeFactory
* @return the literal strings present in the @CreatesMustCallFor annotation(s) of that element,
* substituting the default "this" for empty annotations. This method returns the empty list
* iff there are no @CreatesMustCallFor annotations on elt. The returned list is always
* modifiable if it is non-empty.
*/
/*package-private*/
static List<String> getCreatesMustCallForValues(ExecutableElement elt, MustCallAnnotatedTypeFactory mcAtf, ResourceLeakAnnotatedTypeFactory atypeFactory) {
AnnotationMirror createsMustCallForList = atypeFactory.getDeclAnnotation(elt, CreatesMustCallFor.List.class);
List<String> result = new ArrayList<>(4);
if (createsMustCallForList != null) {
List<AnnotationMirror> createsMustCallFors = AnnotationUtils.getElementValueArray(createsMustCallForList, mcAtf.getCreatesMustCallForListValueElement(), AnnotationMirror.class);
for (AnnotationMirror cmcf : createsMustCallFors) {
result.add(getCreatesMustCallForValue(cmcf, mcAtf));
}
}
AnnotationMirror createsMustCallFor = atypeFactory.getDeclAnnotation(elt, CreatesMustCallFor.class);
if (createsMustCallFor != null) {
result.add(getCreatesMustCallForValue(createsMustCallFor, mcAtf));
}
return result;
}
Aggregations