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

Tentative fix for missing "//" operator on XPathMatcher #3707

Merged
merged 3 commits into from
Nov 22, 2023

Conversation

ammachado
Copy link
Contributor

What's changed?

Changes XPathMatcher to allow // syntax.

What's your motivation?

openrewrite/rewrite-migrate-java#353

Anything in particular you'd like reviewers to focus on?

This is just enough to fix the before mentioned issue, definitely needs more testing and a better implementation.

Anyone you would like to review specifically?

Have you considered any alternatives or workarounds?

Any additional context

Checklist

  • I've added unit tests to cover both positive and negative cases
  • I've added the license header to any new files through ./gradlew licenseFormat
  • I've used the IntelliJ IDEA auto-formatter on affected files

@timtebeek timtebeek self-requested a review November 20, 2023 17:35
@timtebeek timtebeek added bug Something isn't working enhancement New feature or request labels Nov 20, 2023
@@ -78,6 +88,33 @@ public boolean matches(Cursor cursor) {
Collections.reverse(path);
String[] parts = expression.substring(1).split("/");

// Deal with the two forward slashes in the expression; works, but I'm not proud of it.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -78,6 +88,31 @@ public boolean matches(Cursor cursor) {
Collections.reverse(path);
String[] parts = expression.substring(1).split("/");

// Deal with the two forward slashes in the expression; works, but I'm not proud of it.
if (expression.contains("//") && Arrays.stream(parts).anyMatch(StringUtils::isBlank)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the second part of the conditional meant to match? Since it seems as though we only reach here when Arrays.stream(parts).anyMatch(StringUtils::isBlank) would be true, given that the expression contains //, does not start with /, and is then split on /. Is it to skip cases that end in // which would not produce empty elements?

Copy link
Contributor

@timtebeek timtebeek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite sure what else you'd want to test still; approved as is, and ready to merge if you are.

@timtebeek timtebeek merged commit 775c2d5 into openrewrite:main Nov 22, 2023
1 check passed
@timtebeek
Copy link
Contributor

Decided to merge as is to not keep this open; since we specifically look at cases where the expression contains // I don't expect any adverse effects. Thanks for identifying the problem and providing the fix!

timtebeek added a commit to openrewrite/rewrite-migrate-java that referenced this pull request Nov 22, 2023
timtebeek added a commit to openrewrite/rewrite-migrate-java that referenced this pull request Nov 28, 2023
* Update maven-compiler-plugin in pluginManagement

Following on from openrewrite/rewrite#3707
Fixes #353

* Simplify test case to not use property
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

2 participants