use of com.github.javaparser.resolution.declarations.HasAccessSpecifier in project javaparser by javaparser.
the class JavaParserTypeDeclarationAdapter method checkAncestorsForType.
/**
* Recursively checks the ancestors of the {@param declaration} if an internal type is declared with a name equal
* to {@param name}.
* TODO: Edit to remove return of null (favouring a return of optional)
* @return A ResolvedTypeDeclaration matching the {@param name}, null otherwise
*/
private ResolvedTypeDeclaration checkAncestorsForType(String name, ResolvedReferenceTypeDeclaration declaration) {
for (ResolvedReferenceType ancestor : declaration.getAncestors(true)) {
try {
// TODO: Figure out if it is appropriate to remove the orElseThrow() -- if so, how...
ResolvedReferenceTypeDeclaration ancestorReferenceTypeDeclaration = ancestor.getTypeDeclaration().orElseThrow(() -> new RuntimeException("TypeDeclaration unexpectedly empty."));
for (ResolvedTypeDeclaration internalTypeDeclaration : ancestorReferenceTypeDeclaration.internalTypes()) {
boolean visible = true;
if (internalTypeDeclaration instanceof ResolvedReferenceTypeDeclaration) {
ResolvedReferenceTypeDeclaration resolvedReferenceTypeDeclaration = internalTypeDeclaration.asReferenceType();
if (resolvedReferenceTypeDeclaration instanceof HasAccessSpecifier) {
visible = ((HasAccessSpecifier) resolvedReferenceTypeDeclaration).accessSpecifier() != AccessSpecifier.PRIVATE;
}
}
if (internalTypeDeclaration.getName().equals(name)) {
if (visible) {
return internalTypeDeclaration;
} else {
// FIXME -- Avoid returning null.
return null;
}
}
}
// check recursively the ancestors of this ancestor
ResolvedTypeDeclaration ancestorTypeDeclaration = checkAncestorsForType(name, ancestorReferenceTypeDeclaration);
if (ancestorTypeDeclaration != null) {
return ancestorTypeDeclaration;
}
} catch (UnsupportedOperationException e) {
// just continue using the next ancestor
}
}
// FIXME -- Avoid returning null.
return null;
}
Aggregations