From 014bac8d2bd69dcec64de5ea73425a69010612cc Mon Sep 17 00:00:00 2001 From: I-Al-Istannen Date: Tue, 23 May 2023 22:58:05 +0200 Subject: [PATCH] refactor: Extract common type parameter declarer extraction logic --- .../spoon/support/adaption/TypeAdaptor.java | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/main/java/spoon/support/adaption/TypeAdaptor.java b/src/main/java/spoon/support/adaption/TypeAdaptor.java index 74e45256926..df20572e351 100644 --- a/src/main/java/spoon/support/adaption/TypeAdaptor.java +++ b/src/main/java/spoon/support/adaption/TypeAdaptor.java @@ -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()); } @@ -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; + } else { + parentType = declarer.getDeclaringType(); } - return declarer.getDeclaringType(); } - return type; + return parentType; } private DeclarationNode buildDeclarationHierarchyFrom(