use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class KindChanged method doEnd.
@Override
protected List<Difference> doEnd() {
ActiveElements<JavaTypeElement> types = popIfActive();
if (types != null) {
TypeElement o = types.oldElement.getDeclaringElement();
TypeElement n = types.newElement.getDeclaringElement();
if (o.getKind() != n.getKind()) {
Difference p = createDifference(Code.CLASS_KIND_CHANGED, Code.attachmentsFor(types.oldElement, types.newElement, "oldKind", kind(o), "newKind", kind(n)));
return Collections.singletonList(p);
}
}
return null;
}
use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class JavaElementBase method createFullHumanReadableString.
protected String createFullHumanReadableString() {
String decl = Util.toHumanReadableString(getDeclaringElement());
if (isInherited()) {
org.revapi.Element parent = getParent();
while (parent != null && !(parent instanceof JavaTypeElement)) {
parent = parent.getParent();
}
JavaTypeElement parentType = (JavaTypeElement) parent;
if (parentType != null) {
decl += " @ " + Util.toHumanReadableString(parentType.getDeclaringElement());
}
}
return getHumanReadableElementType() + " " + decl;
}
use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class NowImplementsInterface method doEnd.
@Override
protected List<Difference> doEnd() {
CheckBase.ActiveElements<JavaTypeElement> types = popIfActive();
if (types == null) {
return null;
}
List<Difference> result = new ArrayList<>();
List<? extends TypeMirror> newInterfaces = types.newElement.getDeclaringElement().getInterfaces();
List<? extends TypeMirror> oldInterfaces = types.oldElement.getDeclaringElement().getInterfaces();
for (TypeMirror newIface : newInterfaces) {
if (!Util.isSubtype(newIface, oldInterfaces, getNewTypeEnvironment().getTypeUtils())) {
result.add(createDifference(Code.CLASS_NOW_IMPLEMENTS_INTERFACE, Code.attachmentsFor(types.oldElement, types.newElement, "interface", Util.toHumanReadableString(newIface))));
}
}
return result;
}
use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class InheritanceChainChanged method doEnd.
@Override
protected List<Difference> doEnd() {
ActiveElements<JavaTypeElement> types = popIfActive();
if (types != null) {
List<Difference> ret = new ArrayList<>();
@SuppressWarnings("unchecked") List<TypeMirror> oldSuperClasses = (List<TypeMirror>) types.context[0];
@SuppressWarnings("unchecked") List<TypeMirror> newSuperClasses = (List<TypeMirror>) types.context[1];
Comparator<TypeMirror> typeNameComparator = Comparator.comparing(Util::toUniqueString);
List<TypeMirror> removedSuperClasses = new ArrayList<>();
List<TypeMirror> addedSuperClasses = new ArrayList<>();
oldSuperClasses.sort(typeNameComparator);
newSuperClasses.sort(typeNameComparator);
CoIterator<TypeMirror> iterator = new CoIterator<>(oldSuperClasses.iterator(), newSuperClasses.iterator(), typeNameComparator);
while (iterator.hasNext()) {
iterator.next();
TypeMirror oldType = iterator.getLeft();
TypeMirror newType = iterator.getRight();
if (oldType == null) {
addedSuperClasses.add(newType);
} else if (newType == null) {
removedSuperClasses.add(oldType);
}
}
// this will give us the equivalent of removed/added superclasses but ordered by the inheritance chain
// not by name
removedSuperClasses = retainInCopy(oldSuperClasses, removedSuperClasses);
addedSuperClasses = retainInCopy(newSuperClasses, addedSuperClasses);
Iterator<TypeMirror> removedIt = removedSuperClasses.iterator();
Iterator<TypeMirror> addedIt = addedSuperClasses.iterator();
// always report the most concrete classes
if (removedIt.hasNext()) {
removedIt.next();
}
if (addedIt.hasNext()) {
addedIt.next();
}
// ok, now we only have super types left of the most concrete removed/added super class.
// we are only going to report those that changed their inheritance hierarchy in the other version of the API.
removeClassesWithEquivalentSuperClassChain(removedIt, getOldTypeEnvironment(), getNewTypeEnvironment());
removeClassesWithEquivalentSuperClassChain(addedIt, getNewTypeEnvironment(), getOldTypeEnvironment());
for (TypeMirror t : removedSuperClasses) {
String str = Util.toHumanReadableString(t);
ret.add(createDifference(Code.CLASS_NO_LONGER_INHERITS_FROM_CLASS, Code.attachmentsFor(types.oldElement, types.newElement, "superClass", str)));
}
for (TypeMirror t : addedSuperClasses) {
String str = Util.toHumanReadableString(t);
Code code = types.oldElement.getDeclaringElement().getModifiers().contains(Modifier.FINAL) ? Code.CLASS_FINAL_CLASS_INHERITS_FROM_NEW_CLASS : Code.CLASS_NON_FINAL_CLASS_INHERITS_FROM_NEW_CLASS;
ret.add(createDifference(code, Code.attachmentsFor(types.oldElement, types.newElement, "superClass", str)));
// additionally add a difference about checked exceptions
if (changedToCheckedException(getNewTypeEnvironment().getTypeUtils(), t, oldSuperClasses)) {
ret.add(createDifference(Code.CLASS_NOW_CHECKED_EXCEPTION, Code.attachmentsFor(types.oldElement, types.newElement)));
}
}
return ret;
}
return null;
}
use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class NoLongerImplementsInterface method doEnd.
@Override
protected List<Difference> doEnd() {
ActiveElements<JavaTypeElement> types = popIfActive();
if (types == null) {
return null;
}
List<Difference> result = new ArrayList<>();
@SuppressWarnings("unchecked") List<TypeMirror> oldInterfaces = (List<TypeMirror>) types.context[0];
@SuppressWarnings("unchecked") List<TypeMirror> newInterfaces = (List<TypeMirror>) types.context[1];
for (TypeMirror oldIface : oldInterfaces) {
if (!Util.isSubtype(oldIface, newInterfaces, getOldTypeEnvironment().getTypeUtils())) {
result.add(createDifference(Code.CLASS_NO_LONGER_IMPLEMENTS_INTERFACE, Code.attachmentsFor(types.oldElement, types.newElement, "interface", Util.toHumanReadableString(oldIface))));
}
}
return result;
}
Aggregations