use of scenelib.annotations.Annotation in project checker-framework by typetools.
the class ToIndexFileConverter method visit.
@Override
public Void visit(MethodDeclaration decl, AElement elem) {
Type type = decl.getType();
List<Parameter> params = decl.getParameters();
List<TypeParameter> typeParams = decl.getTypeParameters();
Optional<ReceiverParameter> rcvrParam = decl.getReceiverParameter();
BlockStmt body = decl.getBody().orElse(null);
StringBuilder sb = new StringBuilder(decl.getNameAsString()).append('(');
AClass clazz = (AClass) elem;
AMethod method;
if (params != null) {
for (Parameter param : params) {
Type ptype = param.getType();
sb.append(getJVML(ptype));
}
}
sb.append(')').append(getJVML(type));
method = clazz.methods.vivify(sb.toString());
visitDecl(decl, method);
visitType(type, method.returnType);
if (params != null) {
for (int i = 0; i < params.size(); i++) {
Parameter param = params.get(i);
AField field = method.parameters.vivify(i);
visitType(param.getType(), field.type);
}
}
if (rcvrParam.isPresent()) {
for (AnnotationExpr expr : rcvrParam.get().getAnnotations()) {
Annotation anno = extractAnnotation(expr);
method.receiver.type.tlAnnotationsHere.add(anno);
}
}
if (typeParams != null) {
for (int i = 0; i < typeParams.size(); i++) {
TypeParameter typeParam = typeParams.get(i);
List<ClassOrInterfaceType> bounds = typeParam.getTypeBound();
if (bounds != null) {
for (int j = 0; j < bounds.size(); j++) {
ClassOrInterfaceType bound = bounds.get(j);
BoundLocation loc = new BoundLocation(i, j);
bound.accept(this, method.bounds.vivify(loc));
}
}
}
}
return body == null ? null : body.accept(this, method);
}
use of scenelib.annotations.Annotation in project checker-framework by typetools.
the class WholeProgramInferenceScenesHelper method removeIgnoredAnnosFromATypeElement.
/**
* Removes all annotations that should be ignored from an ATypeElement. (See {@link
* #shouldIgnore}).
*/
private void removeIgnoredAnnosFromATypeElement(ATypeElement typeEl, TypeUseLocation loc) {
String firstKey = typeEl.description.toString() + typeEl.tlAnnotationsHere.toString();
Set<String> annosToIgnoreForLocation = annosToIgnore.get(Pair.of(firstKey, loc));
if (annosToIgnoreForLocation != null) {
Set<Annotation> annosToRemove = new HashSet<>();
for (Annotation anno : typeEl.tlAnnotationsHere) {
if (annosToIgnoreForLocation.contains(anno.def().toString())) {
annosToRemove.add(anno);
}
}
typeEl.tlAnnotationsHere.removeAll(annosToRemove);
}
// Recursively remove ignored annotations from inner types
if (typeEl.innerTypes.size() != 0) {
for (ATypeElement innerType : typeEl.innerTypes.values()) {
removeIgnoredAnnosFromATypeElement(innerType, loc);
}
}
}
use of scenelib.annotations.Annotation in project checker-framework by typetools.
the class WholeProgramInferenceScenesHelper method typeElementToATM.
/**
* Updates an {@link org.checkerframework.framework.type.AnnotatedTypeMirror} to contain the
* {@link scenelib.annotations.Annotation}s of an {@link scenelib.annotations.el.ATypeElement}.
*
* @param atm the AnnotatedTypeMirror to be modified
* @param type the {@link scenelib.annotations.el.ATypeElement}
* @param atf the annotated type factory of a given type system, whose type hierarchy will be
* used
*/
private void typeElementToATM(AnnotatedTypeMirror atm, ATypeElement type, AnnotatedTypeFactory atf) {
Set<Annotation> annos = getSupportedAnnosInSet(type.tlAnnotationsHere, atf);
for (Annotation anno : annos) {
AnnotationMirror am = AnnotationConverter.annotationToAnnotationMirror(anno, atf.getProcessingEnv());
atm.addAnnotation(am);
}
if (atm.getKind() == TypeKind.ARRAY) {
AnnotatedArrayType aat = (AnnotatedArrayType) atm;
for (ATypeElement innerType : type.innerTypes.values()) {
typeElementToATM(aat.getComponentType(), innerType, atf);
}
}
if (atm.getKind() == TypeKind.TYPEVAR) {
AnnotatedTypeVariable atv = (AnnotatedTypeVariable) atm;
for (ATypeElement innerType : type.innerTypes.values()) {
typeElementToATM(atv.getUpperBound(), innerType, atf);
}
}
}
use of scenelib.annotations.Annotation in project checker-framework by typetools.
the class WholeProgramInferenceScenesHelper method addAnnotationsToATypeElement.
private void addAnnotationsToATypeElement(AnnotatedTypeMirror newATM, AnnotatedTypeFactory atf, ATypeElement typeToUpdate, TypeUseLocation defLoc, AnnotationMirror am, boolean isEffectiveAnnotation) {
Annotation anno = AnnotationConverter.annotationMirrorToAnnotation(am);
if (anno != null) {
typeToUpdate.tlAnnotationsHere.add(anno);
if (isEffectiveAnnotation || shouldIgnore(am, defLoc, atf, newATM)) {
// firstKey works as a unique identifier for each annotation
// that should not be inserted in source code
String firstKey = typeToUpdate.description.toString() + typeToUpdate.tlAnnotationsHere.toString();
Pair<String, TypeUseLocation> key = Pair.of(firstKey, defLoc);
Set<String> annosIgnored = annosToIgnore.get(key);
if (annosIgnored == null) {
annosIgnored = new HashSet<>();
annosToIgnore.put(key, annosIgnored);
}
annosIgnored.add(anno.def().toString());
}
}
}
use of scenelib.annotations.Annotation in project checker-framework by typetools.
the class WholeProgramInferenceScenesHelper method getSupportedAnnosInSet.
/**
* Returns a subset of annosSet, consisting of the annotations supported by atf.
*/
private Set<Annotation> getSupportedAnnosInSet(Set<Annotation> annosSet, AnnotatedTypeFactory atf) {
Set<Annotation> output = new HashSet<>();
Set<Class<? extends java.lang.annotation.Annotation>> supportedAnnos = atf.getSupportedTypeQualifiers();
for (Annotation anno : annosSet) {
for (Class<? extends java.lang.annotation.Annotation> clazz : supportedAnnos) {
// TODO: Remove comparison by name, and make this routine more efficient.
if (clazz.getName().equals(anno.def.name)) {
output.add(anno);
}
}
}
return output;
}
Aggregations