本文整理汇总了Java中org.checkerframework.javacutil.AnnotationUtils.getElementValueArray方法的典型用法代码示例。如果您正苦于以下问题:Java AnnotationUtils.getElementValueArray方法的具体用法?Java AnnotationUtils.getElementValueArray怎么用?Java AnnotationUtils.getElementValueArray使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.checkerframework.javacutil.AnnotationUtils
的用法示例。
在下文中一共展示了AnnotationUtils.getElementValueArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: keyForInMap
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
private boolean keyForInMap(ExpressionTree key,
Element mapElement, TreePath path) {
AnnotatedTypeMirror keyForType = keyForFactory.getAnnotatedType(key);
AnnotationMirror anno = keyForType.getAnnotation(KeyFor.class);
if (anno == null)
return false;
List<String> maps = AnnotationUtils.getElementValueArray(anno, "value", String.class, false);
for (String map: maps) {
Element elt = resolver.findVariable(map, path);
if (elt.equals(mapElement) &&
!isSiteRequired(TreeUtils.getReceiverTree((ExpressionTree)path.getLeaf()), elt)) {
return true;
}
}
return false;
}
示例2: methodHolding
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
protected List<String> methodHolding(ExecutableElement element) {
AnnotationMirror holding = atypeFactory.getDeclAnnotation(element, Holding.class);
AnnotationMirror guardedBy
= atypeFactory.getDeclAnnotation(element, net.jcip.annotations.GuardedBy.class);
if (holding == null && guardedBy == null)
return Collections.emptyList();
List<String> locks = new ArrayList<String>();
if (holding != null) {
List<String> holdingValue = AnnotationUtils.getElementValueArray(holding, "value", String.class, false);
locks.addAll(holdingValue);
}
if (guardedBy != null) {
String guardedByValue = AnnotationUtils.getElementValue(guardedBy, "value", String.class, false);
locks.add(guardedByValue);
}
return locks;
}
示例3: handleDimensions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Recursive method to handle array initializations. Recursively
* descends the initializer to find each dimension's size and create the
* appropriate annotation for it.
*
* @param dimensions
* a list of ExpressionTrees where each ExpressionTree is a
* specifier of the size of that dimension (should be an
* IntVal).
* @param type
* the AnnotatedTypeMirror of the array
*/
private void handleDimensions(
List<? extends ExpressionTree> dimensions,
AnnotatedArrayType type) {
if (dimensions.size() > 1) {
handleDimensions(dimensions.subList(1, dimensions.size()),
(AnnotatedArrayType) type.getComponentType());
}
AnnotationMirror dimType = getAnnotatedType(dimensions.get(0))
.getAnnotationInHierarchy(INTVAL);
if (AnnotationUtils.areSameIgnoringValues(dimType, INTVAL)) {
HashSet<Integer> lengths = new HashSet<Integer>(
AnnotationUtils.getElementValueArray(dimType, "value",
Integer.class, true));
AnnotationMirror newQual = createAnnotation(
"org.checkerframework.common.value.qual.ArrayLen", lengths);
type.replaceAnnotation(newQual);
} else {
type.replaceAnnotation(UNKNOWNVAL);
}
}
示例4: evaluateUnaryOperator
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
private AnnotationMirror evaluateUnaryOperator(
AnnotationMirror argAnno, String operation, Class<?> argClass,
UnaryTree tree) {
try {
Class<?>[] argClasses = new Class<?>[] { argClass };
Method m = Operators.class.getMethod(operation, argClasses);
List<?> annoValues = AnnotationUtils.getElementValueArray(
argAnno, "value", argClass, true);
ArrayList<Object> results = new ArrayList<Object>(
annoValues.size());
for (Object val : annoValues) {
results.add(m.invoke(null, new Object[] { val }));
}
return resultAnnotationHandler(m.getReturnType(), results);
} catch (ReflectiveOperationException e) {
checker.report(Result
.warning("operator.unary.evaluation.failed", operation,
argClass), tree);
return null;
}
}
示例5: handleArrayLength
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* If the receiverType object has an ArrayLen annotation it returns an
* IntVal with all the ArrayLen annotation's values as its possible
* values.
*
* @param receiverType
*/
private AnnotationMirror handleArrayLength(
AnnotatedTypeMirror receiverType) {
AnnotationMirror recAnno = getValueAnnotation(receiverType);
if (AnnotationUtils.areSameIgnoringValues(recAnno, ARRAYLEN)) {
HashSet<Integer> lengthValues = new HashSet<Integer>(
AnnotationUtils.getElementValueArray(recAnno, "value",
Integer.class, true));
return createAnnotation("org.checkerframework.common.value.qual.IntVal",
lengthValues);
} else {
return UNKNOWNVAL;
}
}
示例6: getPrecondition
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Returns a set of pairs {@code (expr, annotation)} of preconditions
* according to the given {@link RequiresQualifier}.
*/
private Set<Pair<String, String>> getPrecondition(
AnnotationMirror requiresAnnotation) {
if (requiresAnnotation == null) {
return Collections.emptySet();
}
Set<Pair<String, String>> result = new HashSet<>();
List<String> expressions = AnnotationUtils.getElementValueArray(
requiresAnnotation, "expression", String.class, false);
String annotation = AnnotationUtils.getElementValueClassName(
requiresAnnotation, "qualifier", false).toString();
for (String expr : expressions) {
result.add(Pair.of(expr, annotation));
}
return result;
}
示例7: getPostcondition
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Returns a set of pairs {@code (expr, annotation)} of postconditions
* according to the given {@link EnsuresQualifier}.
*/
private Set<Pair<String, String>> getPostcondition(
AnnotationMirror ensuresAnnotation) {
if (ensuresAnnotation == null) {
return Collections.emptySet();
}
Set<Pair<String, String>> result = new HashSet<>();
List<String> expressions = AnnotationUtils.getElementValueArray(
ensuresAnnotation, "expression", String.class, false);
String annotation = AnnotationUtils.getElementValueClassName(
ensuresAnnotation, "qualifier", false).toString();
for (String expr : expressions) {
result.add(Pair.of(expr, annotation));
}
return result;
}
示例8: getConditionalPostcondition
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Returns a set of triples {@code (expr, (result, annotation))} of
* conditional postconditions according to the given
* {@link EnsuresQualifierIf}.
*/
private Set<Pair<String, Pair<Boolean, String>>> getConditionalPostcondition(
AnnotationMirror ensuresAnnotationIf) {
if (ensuresAnnotationIf == null) {
return Collections.emptySet();
}
Set<Pair<String, Pair<Boolean, String>>> result = new HashSet<>();
List<String> expressions = AnnotationUtils.getElementValueArray(
ensuresAnnotationIf, "expression", String.class, false);
String annotation = AnnotationUtils.getElementValueClassName(
ensuresAnnotationIf, "qualifier", false).toString();
boolean annoResult = AnnotationUtils.getElementValue(ensuresAnnotationIf,
"result", Boolean.class, false);
for (String expr : expressions) {
result.add(Pair.of(expr, Pair.of(annoResult, annotation)));
}
return result;
}
示例9: getDataflowValue
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
private static String[] getDataflowValue(AnnotationMirror type, String valueName) {
List<String> allTypesList = AnnotationUtils.getElementValueArray(type,valueName, String.class, true);
//types in this list is org.checkerframework.framework.util.AnnotationBuilder.
String[] allTypesInArray = new String[allTypesList.size()];
int i = 0;
for (Object o : allTypesList) {
allTypesInArray[i] = o.toString();
i++;
}
return allTypesInArray;
}
示例10: getMethodNames
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
private List<String> getMethodNames(ExpressionTree arg) {
// *** HANDLE METHOD NAME ***
List<String> methodNames = new ArrayList<>();
AnnotationMirror annotation = annotationProvider
.getAnnotationMirror(arg, StringVal.class);
if (annotation != null) {
methodNames = AnnotationUtils.getElementValueArray(annotation,
"value", String.class, true);
} else {
methodNames.add("Unannotated Method: " + arg.toString());
}
return methodNames;
}
示例11: evaluateBinaryOperator
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* This method resolves a binary operator by converting it to a
* reflective call to one of the operators defined in
* BinaryOperators.java. This method's arguments need to be correct
* (such as annotations not being UnknownVal or being of different value
* annotation types) so be careful you are going to call this.
*
* @param lhsAnno
* the value annotation of the LHS argument (Not UnknownVal)
* @param rhsAnno
* the value annotation of the RHS argument (Not UnknownVal)
* @param operation
* the String name of the operation
* @param argClass
* the Class of the operations arguments (used for reflective
* code)
*
* @return
*/
private AnnotationMirror evaluateBinaryOperator(
AnnotationMirror lhsAnno, AnnotationMirror rhsAnno,
String operation, Class<?> argClass, BinaryTree tree) {
try {
Class<?>[] argClasses = new Class<?>[] { argClass, argClass };
Method m = Operators.class.getMethod(operation, argClasses);
List<?> lhsAnnoValues = AnnotationUtils.getElementValueArray(
lhsAnno, "value", argClass, true);
List<?> rhsAnnoValues = AnnotationUtils.getElementValueArray(
rhsAnno, "value", argClass, true);
ArrayList<Object> results = new ArrayList<Object>(
lhsAnnoValues.size() * rhsAnnoValues.size());
for (Object lhsO : lhsAnnoValues) {
for (Object rhsO : rhsAnnoValues) {
results.add(m.invoke(null, new Object[] { lhsO, rhsO }));
}
}
return resultAnnotationHandler(m.getReturnType(), results);
} catch (ReflectiveOperationException e) {
checker.report(Result.warning(
"operator.binary.evaluation.failed", operation,
argClass), tree);
return null;
}
}
示例12: getCastedValues
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Extracts the list of values on an annotation as a List of Object
* while ensuring the actual type of each element is the same type as
* the underlyingType of the typeMirror input (so an Integer returns a
* list of Integer, not Long)
*
* @param typeMirror
* the AnnotatedTypeMirror to pull values from and use to
* determine what type to cast the values to
*
* @return List of Object where each element is the same type as the
* underlyingType of typeMirror
*/
private List<Object> getCastedValues(AnnotatedTypeMirror typeMirror,
Tree tree) {
if (!nonValueAnno(typeMirror)) {
// Class<?> annoValueClass =
// getTypeValueClass(typeMirror.getUnderlyingType().toString());
Class<?> annoValueClass = getAnnotationValueClass(getValueAnnotation(typeMirror));
@SuppressWarnings("unchecked")
// We know any type of value array
// from an annotation is a
// subtype of Object, so we are
// casting it to that
List<Object> tempValues = (List<Object>) AnnotationUtils
.getElementValueArray(
getValueAnnotation(typeMirror),
"value", annoValueClass, true);
// Since we will be reflectively invoking the method with these
// values, it will matter that they are the proper type (Integer
// and not Long for an int argument), so fix them if necessary
fixAnnotationValueObjectType(
tempValues,
annoValueClass,
getClass(typeMirror.getUnderlyingType().toString(),
tree));
return tempValues;
} else {
return null;
}
}
示例13: getPreconditions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Returns a set of pairs {@code (expr, annotation)} of preconditions on the
* method {@code methodElement}.
*/
public Set<Pair<String, String>> getPreconditions(
ExecutableElement methodElement) {
Set<Pair<String, String>> result = new HashSet<>();
// Check for a single contract.
AnnotationMirror requiresAnnotation = factory.getDeclAnnotation(
methodElement, RequiresQualifier.class);
result.addAll(getPrecondition(requiresAnnotation));
// Check for multiple contracts.
AnnotationMirror requiresAnnotations = factory.getDeclAnnotation(
methodElement, RequiresQualifiers.class);
if (requiresAnnotations != null) {
List<AnnotationMirror> annotations = AnnotationUtils
.getElementValueArray(requiresAnnotations, "value", AnnotationMirror.class, false);
for (AnnotationMirror a : annotations) {
result.addAll(getPrecondition(a));
}
}
// Check type-system specific annotations.
Class<PreconditionAnnotation> metaAnnotation = PreconditionAnnotation.class;
List<Pair<AnnotationMirror, AnnotationMirror>> declAnnotations = factory
.getDeclAnnotationWithMetaAnnotation(methodElement,
metaAnnotation);
for (Pair<AnnotationMirror, AnnotationMirror> r : declAnnotations) {
AnnotationMirror anno = r.first;
AnnotationMirror metaAnno = r.second;
List<String> expressions = AnnotationUtils.getElementValueArray(anno,
"value", String.class, false);
String annotationString = AnnotationUtils.getElementValueClassName(
metaAnno, "qualifier", false).toString();
for (String expr : expressions) {
result.add(Pair.of(expr, annotationString));
}
}
return result;
}
示例14: getPostconditions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Returns a set of pairs {@code (expr, annotation)} of postconditions on
* the method {@code methodElement}.
*/
public Set<Pair<String, String>> getPostconditions(
ExecutableElement methodElement) {
Set<Pair<String, String>> result = new HashSet<>();
// Check for a single contract.
AnnotationMirror ensuresAnnotation = factory.getDeclAnnotation(
methodElement, EnsuresQualifier.class);
result.addAll(getPostcondition(ensuresAnnotation));
// Check for multiple contracts.
AnnotationMirror ensuresAnnotations = factory.getDeclAnnotation(
methodElement, EnsuresQualifiers.class);
if (ensuresAnnotations != null) {
List<AnnotationMirror> annotations = AnnotationUtils
.getElementValueArray(ensuresAnnotations, "value", AnnotationMirror.class, false);
for (AnnotationMirror a : annotations) {
result.addAll(getPostcondition(a));
}
}
// Check type-system specific annotations.
Class<PostconditionAnnotation> metaAnnotation = PostconditionAnnotation.class;
List<Pair<AnnotationMirror, AnnotationMirror>> declAnnotations = factory
.getDeclAnnotationWithMetaAnnotation(methodElement,
metaAnnotation);
for (Pair<AnnotationMirror, AnnotationMirror> r : declAnnotations) {
AnnotationMirror anno = r.first;
AnnotationMirror metaAnno = r.second;
List<String> expressions = AnnotationUtils.getElementValueArray(anno,
"value", String.class, false);
String annotationString = AnnotationUtils.getElementValueClassName(
metaAnno, "qualifier", false).toString();
for (String expr : expressions) {
result.add(Pair.of(expr, annotationString));
}
}
return result;
}
示例15: getConditionalPostconditions
import org.checkerframework.javacutil.AnnotationUtils; //导入方法依赖的package包/类
/**
* Returns a set of triples {@code (expr, (result, annotation))} of
* conditional postconditions on the method {@code methodElement}.
*/
public Set<Pair<String, Pair<Boolean, String>>> getConditionalPostconditions(
ExecutableElement methodElement) {
Set<Pair<String, Pair<Boolean, String>>> result = new HashSet<>();
// Check for a single contract.
AnnotationMirror ensuresAnnotationIf = factory.getDeclAnnotation(
methodElement, EnsuresQualifierIf.class);
result.addAll(getConditionalPostcondition(ensuresAnnotationIf));
// Check for multiple contracts.
AnnotationMirror ensuresAnnotationsIf = factory.getDeclAnnotation(
methodElement, EnsuresQualifiersIf.class);
if (ensuresAnnotationsIf != null) {
List<AnnotationMirror> annotations = AnnotationUtils
.getElementValueArray(ensuresAnnotationsIf, "value", AnnotationMirror.class, false);
for (AnnotationMirror a : annotations) {
result.addAll(getConditionalPostcondition(a));
}
}
// Check type-system specific annotations.
Class<ConditionalPostconditionAnnotation> metaAnnotation = ConditionalPostconditionAnnotation.class;
List<Pair<AnnotationMirror, AnnotationMirror>> declAnnotations = factory
.getDeclAnnotationWithMetaAnnotation(methodElement,
metaAnnotation);
for (Pair<AnnotationMirror, AnnotationMirror> r : declAnnotations) {
AnnotationMirror anno = r.first;
AnnotationMirror metaAnno = r.second;
List<String> expressions = AnnotationUtils.getElementValueArray(anno,
"expression", String.class, false);
String annotationString = AnnotationUtils.getElementValueClassName(
metaAnno, "qualifier", false).toString();
boolean annoResult = AnnotationUtils.getElementValue(anno,
"result", Boolean.class, false);
for (String expr : expressions) {
result.add(Pair.of(expr, Pair.of(annoResult, annotationString)));
}
}
return result;
}