use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class JavaElementDifferenceAnalyzer method appendUses.
private void appendUses(ProbingEnvironment env, Element element, final StringBuilder bld) {
LOG.trace("Reporting uses of {}", element);
if (element == null) {
bld.append("<null>");
return;
}
while (element != null && !(element instanceof JavaTypeElement)) {
element = element.getParent();
}
if (element == null) {
return;
}
JavaTypeElement usedType = (JavaTypeElement) element;
if (usedType.isInAPI() && !usedType.isInApiThroughUse()) {
String message = MessageFormat.format(messages.getString("revapi.java.uses.partOfApi"), usedType.getFullHumanReadableString());
bld.append(message);
return;
}
usedType.visitUseSites(new UseSite.Visitor<Object, Void>() {
@Nullable
@Override
public Object visit(@Nonnull DeclaredType type, @Nonnull UseSite use, @Nullable Void parameter) {
if (appendUse(env, usedType, bld, type, use)) {
// just a non-null values
return Boolean.TRUE;
}
return null;
}
@Nullable
@Override
public Object end(DeclaredType type, @Nullable Void parameter) {
return null;
}
}, null);
}
use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class JavaElementDifferenceAnalyzer method appendUseType.
private boolean appendUseType(ProbingEnvironment env, JavaTypeElement ut, List<TypeAndUseSite> path, JavaTypeElement usedType, DeclaredType type, UseSite currentUse, Set<javax.lang.model.element.TypeElement> visitedTypes) {
javax.lang.model.element.TypeElement useType = ut.getDeclaringElement();
if (visitedTypes.contains(useType)) {
return false;
}
visitedTypes.add(useType);
if (ut.isInAPI() && !ut.isInApiThroughUse() && !ut.equals(usedType)) {
// the class is in the primary API
path.add(0, new TypeAndUseSite(type, currentUse));
return true;
} else {
Boolean ret = ut.visitUseSites(new UseSite.Visitor<Boolean, Void>() {
@Nullable
@Override
public Boolean visit(@Nonnull DeclaredType visitedType, @Nonnull UseSite use, @Nullable Void parameter) {
if (traverseToApi(env, usedType, visitedType, use, path, visitedTypes)) {
path.add(0, new TypeAndUseSite(type, currentUse));
return true;
}
return null;
}
@Nullable
@Override
public Boolean end(DeclaredType type, @Nullable Void parameter) {
return null;
}
}, null);
if (ret == null) {
Set<javax.lang.model.element.TypeElement> derivedUseTypes = env.getDerivedTypes(useType);
for (javax.lang.model.element.TypeElement dut : derivedUseTypes) {
TypeElement model = env.getTypeMap().get(dut);
if (model == null) {
continue;
}
JavaModelElement derivedUseElement = findSameDeclarationUnder(currentUse.getSite(), model);
if (derivedUseElement == null) {
continue;
}
UseSite derivedUse = new UseSite(currentUse.getUseType(), derivedUseElement);
if (appendUseType(env, model, path, usedType, type, derivedUse, visitedTypes)) {
ret = true;
break;
}
}
}
return ret == null ? false : ret;
}
}
use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class JavaElementDifferenceAnalyzer method isCheckedElsewhere.
private boolean isCheckedElsewhere(JavaModelElement element, ProbingEnvironment env) {
if (element == null) {
// the other element will not be null and therefore we will determine the fact with the other element...
return true;
}
if (!element.isInherited()) {
return false;
}
String elementSig = Util.toUniqueString(element.getModelRepresentation());
String declSig = Util.toUniqueString(element.getDeclaringElement().asType());
if (!Objects.equals(elementSig, declSig)) {
return false;
}
javax.lang.model.element.TypeElement declaringType = findTypeOf(element.getDeclaringElement());
JavaTypeElement declaringClass = env.getTypeMap().get(declaringType);
return declaringClass != null && declaringClass.isInAPI();
}
use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class InheritanceChainChanged method doVisitClass.
@Override
protected void doVisitClass(JavaTypeElement oldEl, JavaTypeElement newEl) {
if (!isBothAccessible(oldEl, newEl)) {
return;
}
TypeElement oldType = oldEl.getDeclaringElement();
TypeElement newType = newEl.getDeclaringElement();
List<TypeMirror> oldSuperTypes = Util.getAllSuperClasses(getOldTypeEnvironment().getTypeUtils(), oldType.asType());
List<TypeMirror> newSuperTypes = Util.getAllSuperClasses(getNewTypeEnvironment().getTypeUtils(), newType.asType());
if (oldSuperTypes.size() != newSuperTypes.size()) {
pushActive(oldEl, newEl, oldSuperTypes, newSuperTypes);
} else {
Types oldTypes = getOldTypeEnvironment().getTypeUtils();
Types newTypes = getNewTypeEnvironment().getTypeUtils();
for (int i = 0; i < oldSuperTypes.size(); ++i) {
// need to erase them all so that we get only true type changes. formal type parameter changes
// are captured by SuperTypeParametersChanged check
TypeMirror oldSuperClass = oldTypes.erasure(oldSuperTypes.get(i));
TypeMirror newSuperClass = newTypes.erasure(newSuperTypes.get(i));
if (!Util.isSameType(oldSuperClass, newSuperClass)) {
pushActive(oldEl, newEl, oldSuperTypes, newSuperTypes);
break;
}
}
}
}
use of org.revapi.java.spi.JavaTypeElement in project revapi by revapi.
the class Added method doEnd.
@Override
protected List<Difference> doEnd() {
ActiveElements<JavaTypeElement> types = popIfActive();
if (types != null) {
TypeElement typeInOld = getOldTypeEnvironment().getElementUtils().getTypeElement(types.newElement.getDeclaringElement().getQualifiedName());
String[] attachments = Code.attachmentsFor(types.oldElement, types.newElement);
Difference difference = typeInOld == null ? createDifference(Code.CLASS_ADDED, attachments) : createDifference(Code.CLASS_EXTERNAL_CLASS_EXPOSED_IN_API, attachments);
return Collections.singletonList(difference);
}
return null;
}
Aggregations