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

Optimize filterGenerics() #748

Closed
wants to merge 5 commits into from
Closed

Conversation

meiMingle
Copy link
Contributor

@meiMingle meiMingle commented Dec 6, 2023

What's new

What's fixed

For the optimization of code like the following, code processed by the old filterGenerics method will cause it to be damaged, causing JavaParser to not parse correctly.

   static <T> Collection<T> a(Iterable<T> var0) {
      return (Collection<T>)var0;
   }

Then

   static                                 var0) {
      return (Collection   )var0;
   }

Now

   static  Collection  a(Iterable  var0) {
      return (Collection )var0;
   }

@meiMingle meiMingle marked this pull request as draft December 10, 2023 17:50
@meiMingle
Copy link
Contributor Author

<(,?(((\?\s+(extends|super)\s+)?[^<>+\-*/%=&|!~^:(){}?'"]*)))+>|<\s*\?\s*>

@Col-E Hello, I created a new regular expression that should work for most situations so far. But maybe the expression is a little complicated, which will cause OOM when using the classes provided by jregex. This problem does not occur when using java.util.regex. I'm wondering if I should replace the jregex library. Should it be replaced by java.util.regex or RegExodus like the one used in 4x? What are the advantages of RegExodus?

@meiMingle meiMingle marked this pull request as ready for review December 11, 2023 10:19
@meiMingle
Copy link
Contributor Author

@Col-E Currently I only run the regular expressions here using java.util.regex to avoid large-scale changes and avoid OOM caused by Jregex. I think it's probably a relatively good compromise.

@Jydett
Copy link
Contributor

Jydett commented Dec 11, 2023

@meiMingle I've added this test that fails with this PR:

	@Test
	void dontRemoveGenericInString() {
		String code = "String x = \"Foo<X>\";";
		var res = filterGeneric(code);
		assertEquals(code, res);
	}

The expression is here in a string and should not be filtered out; but it is. Do you think you can fix it ?

@meiMingle
Copy link
Contributor Author

@Jydett You are right, I thought about it for a while but didn't find a reliable way to handle this situation.

@meiMingle
Copy link
Contributor Author

I realize this may not be a good solution

@meiMingle meiMingle closed this Mar 29, 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.

3 participants