use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable in project checker-framework by typetools.
the class WholeProgramInferenceScenesHelper method updateAnnotationSetInScene.
/**
* Updates the set of annotations in a location of a Scene.
*
* <ul>
* <li>If there was no previous annotation for that location, then the updated set will be the
* annotations in newATM.
* <li>If there was a previous annotation, the updated set will be the LUB between the
* previous annotation and newATM.
* </ul>
*
* <p>
*
* @param type ATypeElement of the Scene which will be modified
* @param atf the annotated type factory of a given type system, whose type hierarchy will be
* used
* @param jaifPath used to identify a Scene
* @param rhsATM the RHS of the annotated type on the source code
* @param lhsATM the LHS of the annotated type on the source code
* @param defLoc the location where the annotation will be added
*/
protected void updateAnnotationSetInScene(ATypeElement type, AnnotatedTypeFactory atf, String jaifPath, AnnotatedTypeMirror rhsATM, AnnotatedTypeMirror lhsATM, TypeUseLocation defLoc) {
if (rhsATM instanceof AnnotatedNullType && ignoreNullAssignments) {
return;
}
AnnotatedTypeMirror atmFromJaif = AnnotatedTypeMirror.createType(rhsATM.getUnderlyingType(), atf, false);
typeElementToATM(atmFromJaif, type, atf);
updatesATMWithLUB(atf, rhsATM, atmFromJaif);
if (lhsATM instanceof AnnotatedTypeVariable) {
Set<AnnotationMirror> upperAnnos = ((AnnotatedTypeVariable) lhsATM).getUpperBound().getEffectiveAnnotations();
// current type on the source code, halt.
if (upperAnnos.size() == rhsATM.getAnnotations().size() && atf.getQualifierHierarchy().isSubtype(rhsATM.getAnnotations(), upperAnnos)) {
return;
}
}
updateTypeElementFromATM(rhsATM, lhsATM, atf, type, 1, defLoc);
modifiedScenes.add(jaifPath);
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable 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 org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable in project checker-framework by typetools.
the class CFAbstractValue method getEffectTypeVar.
/**
* Returns the AnnotatedTypeVariable associated with the given TypeMirror or null.
*
* <p>If TypeMirror is a type variable, then the AnnotatedTypeVariable return is the declaration
* of that TypeMirror. If the TypeMirror is a wildcard that extends a type variable, the
* AnnotatedTypeVariable return is the declaration of that type variable. Otherwise, null is
* returned.
*/
private AnnotatedTypeVariable getEffectTypeVar(TypeMirror typeMirror) {
if (typeMirror == null) {
return null;
} else if (typeMirror.getKind() == TypeKind.WILDCARD) {
return getEffectTypeVar(((WildcardType) typeMirror).getExtendsBound());
} else if (typeMirror.getKind() == TypeKind.TYPEVAR) {
TypeVariable typevar = ((TypeVariable) typeMirror);
AnnotatedTypeMirror atm = analysis.getTypeFactory().getAnnotatedType(typevar.asElement());
return (AnnotatedTypeVariable) atm;
} else {
return null;
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable in project checker-framework by typetools.
the class StubParser method annotateTypeParameters.
private void annotateTypeParameters(// for debugging
BodyDeclaration<?> decl, // for debugging; TypeElement or ExecutableElement
Object elt, Map<Element, AnnotatedTypeMirror> atypes, List<? extends AnnotatedTypeMirror> typeArguments, List<TypeParameter> typeParameters) {
if (typeParameters == null) {
return;
}
if (typeParameters.size() != typeArguments.size()) {
String msg = String.format("annotateTypeParameters: mismatched sizes: typeParameters (size %d)=%s; typeArguments (size %d)=%s; decl=%s; elt=%s (%s).", typeParameters.size(), typeParameters, typeArguments.size(), typeArguments, decl.toString().replace(LINE_SEPARATOR, " "), elt.toString().replace(LINE_SEPARATOR, " "), elt.getClass());
if (!debugStubParser) {
msg = msg + "%n For more details, run with -AstubDebug";
}
stubWarn(msg);
}
for (int i = 0; i < typeParameters.size(); ++i) {
TypeParameter param = typeParameters.get(i);
AnnotatedTypeVariable paramType = (AnnotatedTypeVariable) typeArguments.get(i);
if (param.getTypeBound() == null || param.getTypeBound().isEmpty()) {
// No bound so annotations are both lower and upper bounds
annotate(paramType, param.getAnnotations());
} else if (param.getTypeBound() != null && param.getTypeBound().size() > 0) {
annotate(paramType.getLowerBound(), param.getAnnotations());
annotate(paramType.getUpperBound(), param.getTypeBound().get(0), null);
if (param.getTypeBound().size() > 1) {
// TODO: add support for intersection types
stubWarnNotFound("Annotations on intersection types are not yet supported");
}
}
putNew(atypes, paramType.getUnderlyingType().asElement(), paramType);
}
}
use of org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable in project checker-framework by typetools.
the class StubParser method processType.
/**
* @return list of AnnotatedTypeVariable of the type's type parameter declarations
*/
private List<AnnotatedTypeVariable> processType(ClassOrInterfaceDeclaration decl, TypeElement elt) {
annotateDecl(declAnnos, elt, decl.getAnnotations());
AnnotatedDeclaredType type = atypeFactory.fromElement(elt);
annotate(type, decl.getAnnotations());
final List<? extends AnnotatedTypeMirror> typeArguments = type.getTypeArguments();
final List<TypeParameter> typeParameters = decl.getTypeParameters();
if (debugStubParser) {
int numParams = (typeParameters == null ? 0 : typeParameters.size());
int numArgs = (typeArguments == null ? 0 : typeArguments.size());
if (numParams != numArgs) {
stubDebug(String.format("parseType: mismatched sizes for typeParameters=%s (size %d) and typeArguments=%s (size %d); decl=%s; elt=%s (%s); type=%s (%s); parseState=%s", typeParameters, numParams, typeArguments, numArgs, decl.toString().replace(LINE_SEPARATOR, " "), elt.toString().replace(LINE_SEPARATOR, " "), elt.getClass(), type, type.getClass(), parseState));
stubDebug("Proceeding despite mismatched sizes");
}
}
annotateTypeParameters(decl, elt, atypes, typeArguments, typeParameters);
annotateSupertypes(decl, type);
putNew(atypes, elt, type);
List<AnnotatedTypeVariable> typeVariables = new ArrayList<>();
for (AnnotatedTypeMirror typeV : type.getTypeArguments()) {
if (typeV.getKind() != TypeKind.TYPEVAR) {
stubWarn("expected an AnnotatedTypeVariable but found type kind " + typeV.getKind() + ": " + typeV);
} else {
typeVariables.add((AnnotatedTypeVariable) typeV);
}
}
return typeVariables;
}
Aggregations