1 package com.github.javaparser.symbolsolver.resolution.typeinference; 2 3 import com.github.javaparser.resolution.declarations.ResolvedTypeParameterDeclaration; 4 import com.github.javaparser.resolution.types.ResolvedType; 5 6 import java.util.LinkedList; 7 import java.util.List; 8 9 /** 10 * @author Federico Tomassetti 11 */ 12 public class Substitution { 13 14 private List<ResolvedTypeParameterDeclaration> typeParameterDeclarations; 15 private List<ResolvedType> types; 16 17 private final static Substitution EMPTY = new Substitution(); 18 empty()19 public static Substitution empty() { 20 return EMPTY; 21 } 22 withPair(ResolvedTypeParameterDeclaration typeParameterDeclaration, ResolvedType type)23 public Substitution withPair(ResolvedTypeParameterDeclaration typeParameterDeclaration, ResolvedType type) { 24 Substitution newInstance = new Substitution(); 25 newInstance.typeParameterDeclarations.addAll(this.typeParameterDeclarations); 26 newInstance.types.addAll(this.types); 27 newInstance.typeParameterDeclarations.add(typeParameterDeclaration); 28 newInstance.types.add(type); 29 return newInstance; 30 31 } 32 Substitution()33 private Substitution() { 34 this.typeParameterDeclarations = new LinkedList<>(); 35 this.types = new LinkedList<>(); 36 } 37 apply(ResolvedType originalType)38 public ResolvedType apply(ResolvedType originalType) { 39 ResolvedType result = originalType; 40 for (int i=0;i<typeParameterDeclarations.size();i++) { 41 result = result.replaceTypeVariables(typeParameterDeclarations.get(i), types.get(i)); 42 } 43 return result; 44 } 45 } 46