本文整理汇总了Java中org.checkerframework.javacutil.AnnotationUtils类的典型用法代码示例。如果您正苦于以下问题:Java AnnotationUtils类的具体用法?Java AnnotationUtils怎么用?Java AnnotationUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AnnotationUtils类属于org.checkerframework.javacutil包,在下文中一共展示了AnnotationUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDatatypesUsed
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
private Collection<String> getDatatypesUsed(Collection<Slot> slots) {
Set<String> types = new TreeSet<>();
for (Slot slot : slots) {
if (slot instanceof ConstantSlot) {
ConstantSlot constantSlot = (ConstantSlot) slot;
AnnotationMirror anno = constantSlot.getValue();
if (AnnotationUtils.areSameIgnoringValues(anno, DATAFLOW)) {
String[] dataflowValues = DataflowUtils.getTypeNames(anno);
for (String dataflowValue : dataflowValues) {
types.add(dataflowValue);
}
}
}
}
return types;
}
示例2: isSubtypeWithRoots
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
private boolean isSubtypeWithRoots(AnnotationMirror rhs, AnnotationMirror lhs) {
Set<String> rTypeNamesSet = new HashSet<String>(Arrays.asList(DataflowUtils.getTypeNames(rhs)));
Set<String> lTypeNamesSet = new HashSet<String>(Arrays.asList(DataflowUtils.getTypeNames(lhs)));
Set<String> rRootsSet = new HashSet<String>(Arrays.asList(DataflowUtils.getTypeNameRoots(rhs)));
Set<String> lRootsSet = new HashSet<String>(Arrays.asList(DataflowUtils.getTypeNameRoots(lhs)));
Set<String> combinedTypeNames = new HashSet<String>();
combinedTypeNames.addAll(rTypeNamesSet);
combinedTypeNames.addAll(lTypeNamesSet);
Set<String> combinedRoots = new HashSet<String>();
combinedRoots.addAll(rRootsSet);
combinedRoots.addAll(lRootsSet);
AnnotationMirror combinedAnno = DataflowUtils.createDataflowAnnotationWithRoots(
combinedTypeNames, combinedRoots, processingEnv);
AnnotationMirror refinedCombinedAnno = refineDataflow(combinedAnno);
AnnotationMirror refinedLhs = refineDataflow(lhs);
if (AnnotationUtils.areSame(refinedCombinedAnno, refinedLhs)) {
return true;
} else {
return false;
}
}
示例3: isSubtype
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
@Override
public boolean isSubtype(AnnotationMirror rhs, AnnotationMirror lhs) {
if (AnnotationUtils.areSameIgnoringValues(rhs, DATAFLOW)
&& AnnotationUtils.areSameIgnoringValues(lhs, DATAFLOW)) {
return isSubtypeWithRoots(rhs, lhs);
// return isSubtypeWithoutRoots(rhs, lhs);
} else {
//if (rhs != null && lhs != null)
if (AnnotationUtils.areSameIgnoringValues(rhs, DATAFLOW)) {
rhs = DATAFLOW;
} else if (AnnotationUtils.areSameIgnoringValues(lhs, DATAFLOW)) {
lhs = DATAFLOW;
}
return super.isSubtype(rhs, lhs);
}
}
示例4: solve
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
@Override
protected InferenceSolution solve() {
Elements elements = processingEnvironment.getElementUtils();
DATAFLOW = AnnotationUtils.fromClass(elements, DataFlow.class);
Collection<String> datatypesUsed = getDatatypesUsed(slots);
List<DataflowImpliesLogic> dataflowLogics = new ArrayList<>();
for (String datatype : datatypesUsed) {
Set<String> datatypeSet = new HashSet<String>();
datatypeSet.add(datatype);
AnnotationMirror dataflowAnnotation= DataflowUtils.createDataflowAnnotation(datatypeSet, processingEnvironment);
LatticeGenerator lattice = new LatticeGenerator(dataflowAnnotation,processingEnvironment);
DataflowGeneralSerializer serializer = new DataflowGeneralSerializer(
slotManager, lattice);
DataflowImpliesLogic logic = new DataflowImpliesLogic(lattice, constraints, serializer);
dataflowLogics.add(logic);
}
List<DatatypeSolution> datatypeSolutions = solveImpliesLogic(dataflowLogics);
return getMergedSolution(processingEnvironment, datatypeSolutions);
}
示例5: getDatatypesUsed
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
private Collection<String> getDatatypesUsed(Collection<Slot> solts) {
Set<String> types = new TreeSet<>();
for (Slot slot : solts) {
if (slot instanceof ConstantSlot) {
ConstantSlot constantSlot = (ConstantSlot) slot;
AnnotationMirror anno = constantSlot.getValue();
if (AnnotationUtils.areSameIgnoringValues(anno, DATAFLOW)) {
String[] dataflowValues = DataflowUtils.getTypeNames(anno);
for (String dataflowValue : dataflowValues) {
types.add(dataflowValue);
}
}
}
}
return types;
}
示例6: getSubSupertypeFor2
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
private void getSubSupertypeFor2() {
int num = 1;
for (AnnotationMirror i : allTypes) {
Set<AnnotationMirror> subtypeSet = new HashSet<AnnotationMirror>();
Set<AnnotationMirror> supertypeSet = new HashSet<AnnotationMirror>();
if (AnnotationUtils.areSame(i, this.top)) {
subtypeSet.add(this.top);
subtypeSet.add(this.bottom);
supertypeSet.add(this.top);
} else if (AnnotationUtils.areSame(i, this.bottom)) {
subtypeSet.add(this.bottom);
supertypeSet.add(this.bottom);
supertypeSet.add(this.top);
}
this.subType.put(i, subtypeSet);
this.superType.put(i, supertypeSet);
this.modifierInt.put(i, num);
this.IntModifier.put(num, i);
num++;
}
}
示例7: calculateGlbs
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
private Map<AnnotationPair, AnnotationMirror> calculateGlbs() {
Map<AnnotationPair, AnnotationMirror> newglbs = new HashMap<AnnotationPair, AnnotationMirror>();
for (AnnotationMirror a1 : supertypesGraph.keySet()) {
for (AnnotationMirror a2 : supertypesGraph.keySet()) {
if (AnnotationUtils.areSameIgnoringValues(a1, a2))
continue;
if (!AnnotationUtils.areSame(getTopAnnotation(a1), getTopAnnotation(a2)))
continue;
AnnotationPair pair = new AnnotationPair(a1, a2);
if (newglbs.containsKey(pair))
continue;
AnnotationMirror glb = findGlb(a1, a2);
newglbs.put(pair, glb);
}
}
return newglbs;
}
示例8: greatestLowerBoundsTypeVariable
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
/**
* Returns the type qualifiers that are the greatest lower bound of
* the qualifiers in annos1 and annos2.
*
* The two qualifiers have to be from the same qualifier hierarchy. Otherwise,
* null will be returned.
*
* <p>
* This method works even if the underlying Java type is a type variable.
* In that case, a 'null' AnnnotationMirror and the empty set represent a meaningful
* value (namely, no annotation).
*
* @param annos1 First collection of qualifiers
* @param annos2 Second collection of qualifiers
* @return Greatest lower bound of the two collections of qualifiers
*/
public Set<? extends AnnotationMirror>
greatestLowerBoundsTypeVariable(Collection<? extends AnnotationMirror> annos1, Collection<? extends AnnotationMirror> annos2) {
Set<AnnotationMirror> result = AnnotationUtils.createAnnotationSet();
for (AnnotationMirror top : getTopAnnotations()) {
AnnotationMirror anno1ForTop = null;
for (AnnotationMirror anno1 : annos1) {
if (isSubtypeTypeVariable(anno1, top)) {
anno1ForTop = anno1;
}
}
AnnotationMirror anno2ForTop = null;
for (AnnotationMirror anno2 : annos2) {
if (isSubtypeTypeVariable(anno2, top)) {
anno2ForTop = anno2;
}
}
AnnotationMirror t = greatestLowerBoundTypeVariable(anno1ForTop, anno2ForTop);
if (t != null) {
result.add(t);
}
}
return result;
}
示例9: bottomsOnly
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
private static boolean bottomsOnly(Elements elements, AnnotatedTypeFactory atypeFactory,
Set<AnnotationMirror> annotations) {
Set<AnnotationMirror> bots = AnnotationUtils.createAnnotationSet();
bots.addAll(atypeFactory.getQualifierHierarchy().getBottomAnnotations());
// Return true if all the qualifiers that are present are
// bottom qualifiers. Allow fewer qualifiers to be present,
// which can happen for type variables and wildcards.
boolean allbot = true;
for (AnnotationMirror am : annotations) {
if (!bots.remove(am)) {
allbot = false;
}
}
return allbot;
}
示例10: 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;
}
示例11: visitMethod
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
@Override
public Void visitMethod(MethodTree node, Void p) {
if (TreeUtils.isConstructor(node)) {
Collection<? extends AnnotationMirror> returnTypeAnnotations = getExplicitReturnTypeAnnotations(node);
// check for invalid constructor return type
for (Class<? extends Annotation> c : atypeFactory.getInvalidConstructorReturnTypeAnnotations()) {
for (AnnotationMirror a : returnTypeAnnotations) {
if (AnnotationUtils.areSameByClass(a, c)) {
checker.report(Result.failure(
COMMITMENT_INVALID_CONSTRUCTOR_RETURN_TYPE,
node), node);
break;
}
}
}
// Check that all fields have been initialized at the end of the
// constructor.
boolean isStatic = false;
Store store = atypeFactory.getRegularExitStore(node);
List<? extends AnnotationMirror> receiverAnnotations = getAllReceiverAnnotations(node);
checkFieldsInitialized(node, isStatic, store, receiverAnnotations);
}
return super.visitMethod(node, p);
}
示例12: isUnused
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
/**
* Returns whether the field {@code f} is unused, given the annotations on
* the receiver.
*/
private boolean isUnused(VariableTree field,
Collection<? extends AnnotationMirror> receiverAnnos) {
if (receiverAnnos.isEmpty()) {
return false;
}
AnnotationMirror unused = getDeclAnnotation(
TreeUtils.elementFromDeclaration(field), Unused.class);
if (unused == null)
return false;
Name when = AnnotationUtils.getElementValueClassName(unused, "when",
false);
for (AnnotationMirror anno : receiverAnnos) {
Name annoName = ((TypeElement) anno.getAnnotationType().asElement())
.getQualifiedName();
if (annoName.contentEquals(when)) {
return true;
}
}
return false;
}
示例13: findAllSupers
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
/**
* Finds all the super qualifiers for a qualifier.
*
* @param anno
* @param supertypesMap
* @return
*/
private static Set<AnnotationMirror>
findAllSupers(AnnotationMirror anno,
Map<AnnotationMirror, Set<AnnotationMirror>> supertypes,
Map<AnnotationMirror, Set<AnnotationMirror>> allSupersSoFar) {
Set<AnnotationMirror> supers = AnnotationUtils.createAnnotationSet();
if (allSupersSoFar.containsKey(anno))
return Collections.unmodifiableSet(allSupersSoFar.get(anno));
// Updating the visited list before and after helps avoid
// infinite loops. TODO: cleaner way?
allSupersSoFar.put(anno, supers);
for (AnnotationMirror superAnno : supertypes.get(anno)) {
supers.add(superAnno);
supers.addAll(findAllSupers(superAnno, supertypes, allSupersSoFar));
}
allSupersSoFar.put(anno, Collections.unmodifiableSet(supers));
return supers;
}
示例14: 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;
}
示例15: RegexAnnotatedTypeFactory
import org.checkerframework.javacutil.AnnotationUtils; //导入依赖的package包/类
public RegexAnnotatedTypeFactory(BaseTypeChecker checker) {
super(checker);
patternCompile = TreeUtils.getMethod("java.util.regex.Pattern", "compile", 1, processingEnv);
partialRegexValue = TreeUtils.getMethod("org.checkerframework.checker.regex.qual.PartialRegex", "value", 0, processingEnv);
REGEX = AnnotationUtils.fromClass(elements, Regex.class);
REGEXBOTTOM = AnnotationUtils.fromClass(elements, RegexBottom.class);
PARTIALREGEX = AnnotationUtils.fromClass(elements, PartialRegex.class);
regexValueElement = TreeUtils.getMethod("org.checkerframework.checker.regex.qual.Regex", "value", 0, processingEnv);
/*
legalReferenceTypes = new TypeMirror[] {
getTypeMirror("java.lang.CharSequence"),
getTypeMirror("java.lang.Character"),
getTypeMirror("java.util.regex.Pattern"),
getTypeMirror("java.util.regex.MatchResult") };
*/
this.postInit();
}