static TypeName withoutMissingTypeVariables()

in dataenum-processor/src/main/java/com/spotify/dataenum/processor/generator/match/TypeVariableUtils.java [31:64]


  static TypeName withoutMissingTypeVariables(
      TypeName typeName, Iterable<TypeVariableName> availableTypeVariables) throws ParserException {
    if (!(typeName instanceof ParameterizedTypeName) || availableTypeVariables == null) {
      return typeName;
    }

    ParameterizedTypeName parameterizedTypeName = (ParameterizedTypeName) typeName;

    List<TypeName> adjustedArguments = new ArrayList<>();
    for (TypeName argument : parameterizedTypeName.typeArguments) {
      if (argument instanceof ParameterizedTypeName) {
        // Recursive call
        adjustedArguments.add(withoutMissingTypeVariables(argument, availableTypeVariables));
      } else if (argument instanceof TypeVariableName) {
        TypeVariableName variable = (TypeVariableName) argument;
        if (Iterables.contains(availableTypeVariables, variable)) {
          adjustedArguments.add(variable);
        } else {
          if (variable.bounds.size() == 0) {
            adjustedArguments.add(TypeName.OBJECT);
          } else if (variable.bounds.size() == 1) {
            adjustedArguments.add(variable.bounds.get(0));
          } else {
            throw new ParserException("More than one generic type bound is not supported");
          }
        }
      } else {
        adjustedArguments.add(argument);
      }
    }

    TypeName[] adjustedArgumentsArr = adjustedArguments.toArray(new TypeName[] {});
    return ParameterizedTypeName.get(parameterizedTypeName.rawType, adjustedArgumentsArr);
  }