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

fix: parser removing more than generics #746

Closed
wants to merge 1 commit into from

Conversation

Jydett
Copy link

@Jydett Jydett commented Nov 30, 2023

Hello, firstly, thank you for this great tool !

I encounter an issue the other day similar to [this one](#584) where the comparison in this pseudo-class would be matched as a generic declaration and removed before being parsed as java code, thus resulting in java parsing errors.

decompiled code

class Clazz {
   public boolean test(int x) {
      int a = 0, b = 0;
      if (a < x && x > b) {
          return false;
      }
      return true;
   }
}

after generic type erasing

class Clazz {
   public boolean test(int x) {
      int a = 0, b = 0;
      if (a            b) {
          return false;
      }
      return true;
   }
}

I tried to fix the regular expression, but it would become massive, hard to understand and inefficient, so I rewrote the function as a simple syntax parser and added some tests.

@Jydett
Copy link
Author

Jydett commented Dec 1, 2023

I'll switch this PR to draft as I discovered some a new edge case that will be hard to fix:

    public static void main(String[] args) {
        int a = 0, b = 0, c = 0, d = 0;
        boolean x = a < b & c > d;
    }

@meiMingle
Copy link

@Jydett Hi, do you think this PR can solve the edge case you mentioned? #748

@Jydett
Copy link
Author

Jydett commented Dec 10, 2023

@meiMingle Hi, i don't think so. If you want to check you can copy the test class to your PR and run it to validate its behaviour

@meiMingle
Copy link

@Jydett I just used my newly created regular expression to run your test class and the only thing that failed was the following method, <T extends EntityLivingBase<X> | Foo> are you sure this syntax is correct? What environment (JDK version/language level) does it come from?

@Test
void removeGenericMethodDeclaration() {
String code = "<T extends EntityLivingBase<X> | Foo> foo() {}";
var res = filterGeneric(code);
assertEquals(" foo() {}", res);
}
```assertEquals(" foo() {}", res);
}

@Jydett
Copy link
Author

Jydett commented Dec 11, 2023

@meiMingle You're right the correct syntax is <T extends EntityLivingBase<X> & Foo>

@Col-E
Copy link
Owner

Col-E commented Jun 4, 2024

Closing out as we're focusing on 4.x now, and its not using JavaParser as a backend.

@Col-E Col-E closed this Jun 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants