Skip to content

Commit

Permalink
Merge pull request javaparser#1676 from daanschipper/issue-1675
Browse files Browse the repository at this point in the history
Recursive checking ancestors for TypeDeclaration with provided name
  • Loading branch information
matozoid authored Jul 16, 2018
2 parents c2b2a12 + f272b49 commit 25c50c9
Showing 1 changed file with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,33 @@ public SymbolReference<ResolvedTypeDeclaration> solveType(String name, TypeSolve
}

// Look into extended classes and implemented interfaces
for (ResolvedReferenceType ancestor : this.typeDeclaration.getAncestors()) {
try {
for (ResolvedTypeDeclaration internalTypeDeclaration : ancestor.getTypeDeclaration().internalTypes()) {
if (internalTypeDeclaration.getName().equals(name)) {
return SymbolReference.solved(internalTypeDeclaration);
}
}
} catch (UnsupportedOperationException e) {
// just continue using the next ancestor
ResolvedTypeDeclaration type = checkAncestorsForType(name, this.typeDeclaration);
return ((type != null) ? SymbolReference.solved(type) : context.getParent().solveType(name, typeSolver));
}

/**
* Recursively checks the ancestors of the {@param declaration} if an internal type is declared with a name equal
* to {@param name}.
* @return A ResolvedTypeDeclaration matching the {@param name}, null otherwise
*/
private ResolvedTypeDeclaration checkAncestorsForType(String name, ResolvedReferenceTypeDeclaration declaration) {
for (ResolvedReferenceType ancestor : declaration.getAncestors()) {
try {
for (ResolvedTypeDeclaration internalTypeDeclaration : ancestor.getTypeDeclaration().internalTypes()) {
if (internalTypeDeclaration.getName().equals(name)) {
return internalTypeDeclaration;
}
}
// check recursively the ancestors of this ancestor
ResolvedTypeDeclaration ancestorDeclaration = checkAncestorsForType(name, ancestor.getTypeDeclaration());
if (ancestorDeclaration != null) {
return ancestorDeclaration;
}
} catch (UnsupportedOperationException e) {
// just continue using the next ancestor
}
}

return context.getParent().solveType(name, typeSolver);
return null;
}

public SymbolReference<ResolvedMethodDeclaration> solveMethod(String name, List<ResolvedType> argumentsTypes, boolean staticOnly, TypeSolver typeSolver) {
Expand Down

0 comments on commit 25c50c9

Please sign in to comment.