use of org.revapi.java.spi.UseSite 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.UseSite 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;
}
}
Aggregations