Search in sources :

Example 1 with ATypeElement

use of scenelib.annotations.el.ATypeElement in project checker-framework by typetools.

the class SceneToStubWriter method formatArrayTypeImpl.

/**
 * Formats the type of an array to be printable in Java source code, with the annotations from the
 * scenelib representation added. This method formats only the "array" parts of an array type; it
 * does not format (or attempt to format) the ultimate component type (that is, the non-array part
 * of the array type).
 *
 * @param scenelibRep the scene-lib representation
 * @param javacRep the javac representation of the array type
 * @return the type formatted to be written to Java source code, followed by a space character
 */
private static String formatArrayTypeImpl(ATypeElement scenelibRep, ArrayType javacRep) {
    TypeMirror javacComponent = javacRep.getComponentType();
    ATypeElement scenelibComponent = getNextArrayLevel(scenelibRep);
    String result = "";
    List<? extends AnnotationMirror> explicitAnnos = javacRep.getAnnotationMirrors();
    for (AnnotationMirror explicitAnno : explicitAnnos) {
        result += explicitAnno.toString();
        result += " ";
    }
    if (result.isEmpty() && scenelibRep != null) {
        result += formatAnnotations(scenelibRep.tlAnnotationsHere);
    }
    result += "[] ";
    if (javacComponent.getKind() == TypeKind.ARRAY) {
        return result + formatArrayTypeImpl(scenelibComponent, (ArrayType) javacComponent);
    } else {
        return result;
    }
}
Also used : ArrayType(javax.lang.model.type.ArrayType) AnnotationMirror(javax.lang.model.element.AnnotationMirror) TypeMirror(javax.lang.model.type.TypeMirror) ATypeElement(scenelib.annotations.el.ATypeElement)

Example 2 with ATypeElement

use of scenelib.annotations.el.ATypeElement in project checker-framework by typetools.

the class ASceneWrapper method removeAnnosFromATypeElement.

/**
 * Removes the specified annotations from an ATypeElement.
 *
 * @param typeElt the type element from which to remove annotations
 * @param loc the location where typeElt is used
 * @param annosToRemove annotations that should not be added to .jaif or stub files
 */
private void removeAnnosFromATypeElement(ATypeElement typeElt, TypeUseLocation loc, AnnotationsInContexts annosToRemove) {
    String annosToRemoveKey = WholeProgramInferenceScenesStorage.aTypeElementToString(typeElt);
    Set<String> annosToRemoveForLocation = annosToRemove.get(Pair.of(annosToRemoveKey, loc));
    if (annosToRemoveForLocation != null) {
        Set<Annotation> annosToRemoveHere = new HashSet<>();
        for (Annotation anno : typeElt.tlAnnotationsHere) {
            if (annosToRemoveForLocation.contains(anno.def().toString())) {
                annosToRemoveHere.add(anno);
            }
        }
        typeElt.tlAnnotationsHere.removeAll(annosToRemoveHere);
    }
    // Recursively remove annotations from inner types
    for (ATypeElement innerType : typeElt.innerTypes.values()) {
        removeAnnosFromATypeElement(innerType, loc, annosToRemove);
    }
}
Also used : Annotation(scenelib.annotations.Annotation) ATypeElement(scenelib.annotations.el.ATypeElement) HashSet(java.util.HashSet)

Example 3 with ATypeElement

use of scenelib.annotations.el.ATypeElement 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);
        }
    }
}
Also used : Annotation(scenelib.annotations.Annotation) ATypeElement(scenelib.annotations.el.ATypeElement) HashSet(java.util.HashSet)

Example 4 with ATypeElement

use of scenelib.annotations.el.ATypeElement 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);
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotatedArrayType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType) AnnotatedTypeVariable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable) Annotation(scenelib.annotations.Annotation) ATypeElement(scenelib.annotations.el.ATypeElement)

Example 5 with ATypeElement

use of scenelib.annotations.el.ATypeElement in project checker-framework by typetools.

the class WholeProgramInferenceScenesStorage method updateAtmFromATypeElement.

/**
 * Updates an {@link org.checkerframework.framework.type.AnnotatedTypeMirror} to contain the
 * {@link scenelib.annotations.Annotation}s of an {@link scenelib.annotations.el.ATypeElement}.
 *
 * @param result the AnnotatedTypeMirror to be modified
 * @param storageLocation the {@link scenelib.annotations.el.ATypeElement} used
 */
private void updateAtmFromATypeElement(AnnotatedTypeMirror result, ATypeElement storageLocation) {
    Set<Annotation> annos = getSupportedAnnosInSet(storageLocation.tlAnnotationsHere);
    for (Annotation anno : annos) {
        AnnotationMirror am = AnnotationConverter.annotationToAnnotationMirror(anno, atypeFactory.getProcessingEnv());
        result.addAnnotation(am);
    }
    if (result.getKind() == TypeKind.ARRAY) {
        AnnotatedArrayType aat = (AnnotatedArrayType) result;
        for (ATypeElement innerType : storageLocation.innerTypes.values()) {
            updateAtmFromATypeElement(aat.getComponentType(), innerType);
        }
    }
    if (result.getKind() == TypeKind.TYPEVAR) {
        AnnotatedTypeVariable atv = (AnnotatedTypeVariable) result;
        for (ATypeElement innerType : storageLocation.innerTypes.values()) {
            updateAtmFromATypeElement(atv.getUpperBound(), innerType);
        }
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotatedArrayType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType) AnnotatedTypeVariable(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable) Annotation(scenelib.annotations.Annotation) ATypeElement(scenelib.annotations.el.ATypeElement)

Aggregations

ATypeElement (scenelib.annotations.el.ATypeElement)6 Annotation (scenelib.annotations.Annotation)4 AnnotationMirror (javax.lang.model.element.AnnotationMirror)3 HashSet (java.util.HashSet)2 TypeMirror (javax.lang.model.type.TypeMirror)2 AnnotatedArrayType (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedArrayType)2 AnnotatedTypeVariable (org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedTypeVariable)2 ArrayType (javax.lang.model.type.ArrayType)1