extract duplicate code to a separate method

This commit is contained in:
Till Schnell 2021-04-25 11:34:25 +02:00
parent cfce2f55ac
commit c098a0a1b0

View File

@ -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<RefTypeOrTPHOrWildcardOrGeneric> listIterator,
RefTypeOrTPHOrWildcardOrGeneric refType) {
// Generate TPH
TypePlaceholder tph = generateTypePlaceholder(refType);
// Replace in AST
listIterator.set(tph);
}
}
}