Search in sources :

Example 6 with JavaModelElement

use of org.revapi.java.spi.JavaModelElement in project revapi by revapi.

the class VisibilityChanged method doEnd.

@Override
protected final List<Difference> doEnd() {
    CheckBase.ActiveElements<JavaModelElement> elements = popIfActive();
    if (elements != null) {
        Modifier oldVisibility = getVisibility(elements.oldElement.getDeclaringElement());
        Modifier newVisibility = getVisibility(elements.newElement.getDeclaringElement());
        // public == 0, private == 3
        if (isProblem(getModifierRank(oldVisibility), getModifierRank(newVisibility))) {
            return Collections.singletonList(report(elements, oldVisibility, newVisibility));
        }
    }
    return null;
}
Also used : CheckBase(org.revapi.java.spi.CheckBase) JavaModelElement(org.revapi.java.spi.JavaModelElement) Modifier(javax.lang.model.element.Modifier)

Example 7 with JavaModelElement

use of org.revapi.java.spi.JavaModelElement in project revapi by revapi.

the class FormalTypeParametersChanged method doEnd.

@Nullable
@Override
protected List<Difference> doEnd() {
    ActiveElements<JavaModelElement> els = popIfActive();
    if (els == null) {
        return null;
    }
    @SuppressWarnings("unchecked") List<TypeParameterElement> added = (List<TypeParameterElement>) els.context[0];
    @SuppressWarnings("unchecked") List<TypeParameterElement> removed = (List<TypeParameterElement>) els.context[1];
    @SuppressWarnings("unchecked") Map<TypeParameterElement, TypeParameterElement> changed = (Map<TypeParameterElement, TypeParameterElement>) els.context[2];
    Parameterizable oldT = (Parameterizable) els.oldElement.getDeclaringElement();
    List<Difference> diffs = new ArrayList<>();
    if (oldT.getTypeParameters().isEmpty()) {
        diffs.add(createDifference(Code.GENERICS_ELEMENT_NOW_PARAMETERIZED, Code.attachmentsFor(els.oldElement, els.newElement)));
    }
    for (TypeParameterElement e : added) {
        diffs.add(createDifferenceWithExplicitParams(Code.GENERICS_FORMAL_TYPE_PARAMETER_ADDED, Code.attachmentsFor(els.oldElement, els.newElement), Util.toHumanReadableString(e)));
    }
    for (TypeParameterElement e : removed) {
        diffs.add(createDifferenceWithExplicitParams(Code.GENERICS_FORMAL_TYPE_PARAMETER_REMOVED, Code.attachmentsFor(els.oldElement, els.newElement), Util.toHumanReadableString(e)));
    }
    for (Map.Entry<TypeParameterElement, TypeParameterElement> e : changed.entrySet()) {
        String oldP = Util.toHumanReadableString(e.getKey());
        String newP = Util.toHumanReadableString(e.getValue());
        diffs.add(createDifferenceWithExplicitParams(Code.GENERICS_FORMAL_TYPE_PARAMETER_CHANGED, Code.attachmentsFor(els.oldElement, els.newElement, "oldTypeParameter", oldP, "newTypeParameter", newP), oldP, newP));
    }
    return diffs;
}
Also used : JavaModelElement(org.revapi.java.spi.JavaModelElement) ArrayList(java.util.ArrayList) Difference(org.revapi.Difference) TypeParameterElement(javax.lang.model.element.TypeParameterElement) Parameterizable(javax.lang.model.element.Parameterizable) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Nullable(javax.annotation.Nullable)

Example 8 with JavaModelElement

use of org.revapi.java.spi.JavaModelElement in project revapi by revapi.

the class MovedInHierarchy method doEnd.

@Nullable
@Override
protected List<Difference> doEnd() {
    ActiveElements<JavaModelElement> els = popIfActive();
    if (els == null) {
        return null;
    }
    String oldType = Util.toHumanReadableString(els.oldElement.getDeclaringElement().getEnclosingElement().asType());
    String newType = Util.toHumanReadableString(els.newElement.getDeclaringElement().getEnclosingElement().asType());
    // we know that oldEl.isInherited() != newEl.isInherited(), so it's enough to just check for the old
    Code code = els.oldElement.isInherited() ? moveDown : moveUp;
    return Collections.singletonList(createDifference(code, Code.attachmentsFor(els.oldElement, els.newElement, "oldClass", oldType, "newClass", newType)));
}
Also used : JavaModelElement(org.revapi.java.spi.JavaModelElement) Code(org.revapi.java.spi.Code) Nullable(javax.annotation.Nullable)

Aggregations

JavaModelElement (org.revapi.java.spi.JavaModelElement)8 List (java.util.List)3 Nullable (javax.annotation.Nullable)3 ArrayList (java.util.ArrayList)2 DeclaredType (javax.lang.model.type.DeclaredType)2 API (org.revapi.API)2 AnalysisContext (org.revapi.AnalysisContext)2 Element (org.revapi.Element)2 Revapi (org.revapi.Revapi)2 Code (org.revapi.java.spi.Code)2 JavaTypeElement (org.revapi.java.spi.JavaTypeElement)2 UseSite (org.revapi.java.spi.UseSite)2 Collections (java.util.Collections)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 Nonnull (javax.annotation.Nonnull)1 Element (javax.lang.model.element.Element)1