Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: ReferenceBuilder.getTypeReference() cannot handle complex type parameters #6068

Open
josple opened this issue Nov 12, 2024 · 0 comments
Labels

Comments

@josple
Copy link

josple commented Nov 12, 2024

Describe the bug

Complex type arguments that involve multiple types and nested parameterized types are not currently handled correctly. The issue that happens is that the type params are split on ',' which doesn't respect nested type params.

I have fixed this locally by replacing:

  final String[] split = m.group(2).split(",");

With:

  final List<String> split = getStringTypes(m.group(2));

-------


  private List<String> getStringTypes(String concatTypeArgs) {
    if (!concatTypeArgs.contains("<")) {
      return Arrays.asList(concatTypeArgs.split(","));
    }

    List<String> types = new ArrayList<>();

    int bracketDepth = 0;
    int startPos = 0;

    for (int i = 0; i < concatTypeArgs.length(); i++) {
      char c = concatTypeArgs.charAt(i);
      if (c == ',' && bracketDepth == 0) {
        types.add(concatTypeArgs.substring(startPos, i));
        startPos = i + 1;
      } else if (c == '<') {
        bracketDepth++;
      } else if (c == '>') {
        bracketDepth--;
      }
    }

    // Add final type if possible
    if (startPos < concatTypeArgs.length()) {
      types.add(concatTypeArgs.substring(startPos));
    }

    return types;
  }

Source code you are trying to analyze/transform

SomeType<Integer,Double,MyType<Integer,Double>>

Source code for your Spoon processing

No response

Actual output

Integer
Double
MyType<Integer
Double>

Expected output

Integer
Double
MyType<Integer,Double>

Spoon Version

11.1.0

JVM Version

17

What operating system are you using?

Windows

@josple josple added the bug label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant