Skip to content

Commit

Permalink
refactor: Extract common type parameter declarer extraction logic
Browse files Browse the repository at this point in the history
  • Loading branch information
I-Al-Istannen committed May 23, 2023
1 parent 9f1cfa7 commit 53c3eb7
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/main/java/spoon/support/adaption/TypeAdaptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -596,14 +596,7 @@ private boolean needToMoveStartTypeToEnclosingClass(CtTypeReference<?> end, CtTy
// Declaring type is not the same as the inner type (i.e. the type parameter was declared on an
// enclosing type)
CtType<?> parentType = end.getParent(CtType.class);
if (parentType instanceof CtTypeParameter) {
CtFormalTypeDeclarer declarer = ((CtTypeParameter) parentType).getTypeParameterDeclarer();
if (declarer instanceof CtType) {
parentType = (CtType<?>) declarer;
} else {
parentType = declarer.getDeclaringType();
}
}
parentType = resolveTypeParameterToDeclarer(parentType);

return !parentType.getQualifiedName().equals(endType.getQualifiedName());
}
Expand Down Expand Up @@ -648,14 +641,21 @@ private CtType<?> findDeclaringType(CtTypeReference<?> reference) {
type = reference.getTypeDeclaration();
}

if (type instanceof CtTypeParameter) {
CtFormalTypeDeclarer declarer = ((CtTypeParameter) type).getTypeParameterDeclarer();
return resolveTypeParameterToDeclarer(type);
}

private static CtType<?> resolveTypeParameterToDeclarer(CtType<?> parentType) {
if (parentType instanceof CtTypeParameter) {
CtFormalTypeDeclarer declarer = ((CtTypeParameter) parentType).getTypeParameterDeclarer();
if (declarer instanceof CtType) {
return (CtType<?>) declarer;
} else {
return declarer.getDeclaringType();
}
return declarer.getDeclaringType();
}
return type;
// Could not resolve type parameter declarer (no class path mode?).
// Type adaption results will not be accurate, this is just a wild (and probably wrong) guess.
return parentType;
}

private DeclarationNode buildDeclarationHierarchyFrom(
Expand Down

0 comments on commit 53c3eb7

Please sign in to comment.