From c098a0a1b09d66b390ae38d6509a5b78a8c93abe Mon Sep 17 00:00:00 2001 From: Till Schnell Date: Sun, 25 Apr 2021 11:34:25 +0200 Subject: [PATCH] extract duplicate code to a separate method --- .../ReplaceTypeparamVisitor.java | 35 +++++++++++++------ 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/inferWildcards/ReplaceTypeparamVisitor.java b/src/main/java/de/dhbwstuttgart/inferWildcards/ReplaceTypeparamVisitor.java index eb8ae531..74619e07 100644 --- a/src/main/java/de/dhbwstuttgart/inferWildcards/ReplaceTypeparamVisitor.java +++ b/src/main/java/de/dhbwstuttgart/inferWildcards/ReplaceTypeparamVisitor.java @@ -116,20 +116,14 @@ public class ReplaceTypeparamVisitor // parent TPH mapping this.visit(nextRefType); - // Generate TPH - TypePlaceholder tph = generateTypePlaceholder(nextRefType); - - // Replace in AST - listIterator.set(tph); + generateTphAndReplaceInTree(listIterator, next); } else if (next instanceof GenericRefType) { - GenericRefType nextGenericRefType = (GenericRefType) next; - // Generate TPH - TypePlaceholder tph = generateTypePlaceholder(nextGenericRefType); + // Visit of nested type arguments not necessary as Generic Types cannot contain + // type parameters - // Replace in AST - listIterator.set(tph); + generateTphAndReplaceInTree(listIterator, next); } } @@ -152,5 +146,26 @@ public class ReplaceTypeparamVisitor tphMap.put(tph, t); return tph; } + + /** + * Generate the TPH for a {@link RefTypeOrTPHOrWildcardOrGeneric}, saves the + * mapping and replaces the type by the type placeholder in the tree. + * + * @param listIterator {@link ListIterator} over + * {@link RefTypeOrTPHOrWildcardOrGeneric} representing the + * tree to replace in + * @param refType {@link RefTypeOrTPHOrWildcardOrGeneric} to generate type + * placeholder for and replace + */ + private void generateTphAndReplaceInTree (ListIterator listIterator, + RefTypeOrTPHOrWildcardOrGeneric refType) { + // Generate TPH + TypePlaceholder tph = generateTypePlaceholder(refType); + + // Replace in AST + listIterator.set(tph); + } + } + }