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 014bac8
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 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,19 @@ 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;
parentType = (CtType<?>) declarer;

Check warning on line 651 in src/main/java/spoon/support/adaption/TypeAdaptor.java

View workflow job for this annotation

GitHub Actions / code-quality qodana

Assignment to method parameter

Assignment to method parameter `parentType`
} else {
parentType = declarer.getDeclaringType();

Check warning on line 653 in src/main/java/spoon/support/adaption/TypeAdaptor.java

View workflow job for this annotation

GitHub Actions / code-quality qodana

Assignment to method parameter

Assignment to method parameter `parentType`
}
return declarer.getDeclaringType();
}
return type;
return parentType;
}

private DeclarationNode buildDeclarationHierarchyFrom(
Expand Down

0 comments on commit 014bac8

Please sign in to comment.