use of javax.lang.model.element.AnnotationMirror in project checker-framework by typetools.
the class ContractsUtils method makeArgumentMap.
/**
* Makes a map from element names of a contract annotation to qualifier argument names, as
* defined by {@link QualifierArgument}.
*
* <p>Each element of {@code contractAnnoElement} that is annotated by {@link QualifierArgument}
* is mapped to the name specified by the value of {@link QualifierArgument}. If the value is
* not specified or is an empty string, then the element is mapped to an argument of the same
* name.
*
* @param contractAnnoElement the declaration of the contract annotation containing the elements
* @return map from the names of elements of {@code sourceArgumentNames} to the corresponding
* qualifier argument names
* @see QualifierArgument
*/
private Map<String, String> makeArgumentMap(Element contractAnnoElement) {
HashMap<String, String> argumentMap = new HashMap<>();
for (ExecutableElement meth : ElementFilter.methodsIn(contractAnnoElement.getEnclosedElements())) {
AnnotationMirror argumentAnnotation = factory.getDeclAnnotationNoAliases(meth, QualifierArgument.class);
if (argumentAnnotation != null) {
String sourceName = meth.getSimpleName().toString();
String targetName = AnnotationUtils.getElementValue(argumentAnnotation, "value", String.class, false);
if (targetName == null || targetName.isEmpty()) {
targetName = sourceName;
}
argumentMap.put(sourceName, targetName);
}
}
return argumentMap;
}
use of javax.lang.model.element.AnnotationMirror in project checker-framework by typetools.
the class ContractsUtils method getPreconditions.
/**
* Returns the set of preconditions on the element {@code element}.
*/
public Set<Precondition> getPreconditions(Element element) {
Set<Precondition> result = new LinkedHashSet<>();
// Check for a single contract.
AnnotationMirror requiresAnnotation = factory.getDeclAnnotation(element, RequiresQualifier.class);
result.addAll(getPrecondition(requiresAnnotation));
// Check for multiple contracts.
AnnotationMirror requiresAnnotations = factory.getDeclAnnotation(element, 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(element, 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);
AnnotationMirror precondtionAnno = getAnnotationMirrorOfMetaAnnotation(metaAnno, anno);
if (precondtionAnno == null) {
continue;
}
for (String expr : expressions) {
result.add(new Precondition(expr, precondtionAnno));
}
}
return result;
}
use of javax.lang.model.element.AnnotationMirror in project checker-framework by typetools.
the class GraphQualifierHierarchy method finish.
// private final AnnotationMirror bottom;
@Override
protected void finish(QualifierHierarchy qualHierarchy, Map<AnnotationMirror, Set<AnnotationMirror>> fullMap, Map<AnnotationMirror, AnnotationMirror> polyQualifiers, Set<AnnotationMirror> tops, Set<AnnotationMirror> bottoms, Object... args) {
// Careful, when this method is called, a field this.bottom would not be set yet.
if (args != null && args[0] != null) {
AnnotationMirror thebottom = (AnnotationMirror) args[0];
// A special bottom qualifier was provided; go through the existing
// bottom qualifiers and tie them all to this bottom qualifier.
// Set<AnnotationMirror> bottoms = findBottoms(supertypes);
Set<AnnotationMirror> allQuals = AnnotationUtils.createAnnotationSet();
allQuals.addAll(fullMap.keySet());
allQuals.remove(thebottom);
AnnotationUtils.updateMappingToImmutableSet(fullMap, thebottom, allQuals);
// thebottom is initially a top qualifier
tops.remove(thebottom);
// thebottom is now the single bottom qualifier
bottoms.clear();
bottoms.add(thebottom);
}
}
use of javax.lang.model.element.AnnotationMirror in project checker-framework by typetools.
the class GraphQualifierHierarchy method isSubtype.
@Override
public boolean isSubtype(Collection<? extends AnnotationMirror> rhs, Collection<? extends AnnotationMirror> lhs) {
rhs = replacePolyAll(rhs);
lhs = replacePolyAll(lhs);
if (lhs.isEmpty() || rhs.isEmpty()) {
ErrorReporter.errorAbort("GraphQualifierHierarchy: Empty annotations in lhs: " + lhs + " or rhs: " + rhs);
}
if (lhs.size() > 1) {
ErrorReporter.errorAbort("GraphQualifierHierarchy: Type with more than one annotation found: " + lhs);
}
if (rhs.size() > 1) {
ErrorReporter.errorAbort("GraphQualifierHierarchy: Type with more than one annotation found: " + rhs);
}
for (AnnotationMirror lhsAnno : lhs) {
for (AnnotationMirror rhsAnno : rhs) {
if (isSubtype(rhsAnno, lhsAnno)) {
return true;
}
}
}
return false;
}
use of javax.lang.model.element.AnnotationMirror in project checker-framework by typetools.
the class MultiGraphQualifierHierarchy method calculateLubs.
private Map<AnnotationPair, AnnotationMirror> calculateLubs() {
Map<AnnotationPair, AnnotationMirror> newlubs = new HashMap<>();
for (AnnotationMirror a1 : typeQualifiers) {
for (AnnotationMirror a2 : typeQualifiers) {
if (AnnotationUtils.areSameIgnoringValues(a1, a2)) {
continue;
}
if (!AnnotationUtils.areSame(getTopAnnotation(a1), getTopAnnotation(a2))) {
continue;
}
AnnotationPair pair = new AnnotationPair(a1, a2);
if (newlubs.containsKey(pair)) {
continue;
}
AnnotationMirror lub = findLub(a1, a2);
newlubs.put(pair, lub);
}
}
return newlubs;
}
Aggregations