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

8241187: ToolBox::grep should allow for negative filtering #1934

Closed
wants to merge 6 commits into from

Conversation

lgxbslgx
Copy link
Member

@lgxbslgx lgxbslgx commented Jan 4, 2021

Hi all,

This patch adds two methods in ToolBox to do the negative filtering. Although the label noreg-self was added, I write a test for this enhancement to verify the code. And the method name grepNotMatch may need to be improved. Any idea is appreciated.

Thank you for taking the time to review.

Best Regards.


Progress

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8241187: ToolBox::grep should allow for negative filtering

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/1934/head:pull/1934
$ git checkout pull/1934

Update a local copy of the PR:
$ git checkout pull/1934
$ git pull https://git.openjdk.java.net/jdk pull/1934/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 1934

View PR using the GUI difftool:
$ git pr show -t 1934

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/1934.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Jan 4, 2021

👋 Welcome back lgxbslgx! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Jan 4, 2021
@openjdk
Copy link

openjdk bot commented Jan 4, 2021

@lgxbslgx The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler compiler-dev@openjdk.org label Jan 4, 2021
@mlbridge
Copy link

mlbridge bot commented Jan 4, 2021

Webrevs

* @param lines the strings to be filtered
* @return the strings not matching the regular expression
*/
public List<String> grepNotMatch(Pattern pattern, List<String> lines) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of new methods named grepNotMatch I suggest adding new overloads of grep that take an additional boolean invert parameter that is conceptually equivalent to the grep -v option. The existing grep methods can be updated to delegate to the new methods, passing false for the new parameter.

Copy link
Member Author

Choose a reason for hiding this comment

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

@jonathan-gibbons Thank you for your suggestion. The code is updated now.

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 2, 2021

@lgxbslgx This pull request has been inactive for more than 4 weeks and will be automatically closed if another 4 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration!

@bridgekeeper
Copy link

bridgekeeper bot commented Mar 2, 2021

@lgxbslgx This pull request has been inactive for more than 8 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it!

@bridgekeeper bridgekeeper bot closed this Mar 2, 2021
@lgxbslgx
Copy link
Member Author

/open

@openjdk openjdk bot reopened this Apr 22, 2021
@openjdk
Copy link

openjdk bot commented Apr 22, 2021

@lgxbslgx @HostUserDetails{id=13688759, username='lgxbslgx', fullName='null'} this pull request is now open

@lgxbslgx
Copy link
Member Author

Ping. Could I ask your help to review this patch? Thanks a lot.

Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle left a comment

Choose a reason for hiding this comment

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

looks good to me with minor suggestion

* false: positive filtering, return the matched strings
* @return the strings matching(or not matching) the regular expression
*/
public List<String> grep(Pattern pattern, List<String> lines, boolean invert) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what about?

    public List<String> grep(Pattern pattern, List<String> lines, boolean invert) {
        return lines.stream()
                .filter(s -> invert ? !pattern.matcher(s).find() : pattern.matcher(s).find())
                .collect(Collectors.toList());
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

Putting the invert into method filter may cause a little performance influence. Is it similar to loop?
Because this is the test code, I adopt your suggestion.

@openjdk
Copy link

openjdk bot commented May 11, 2021

@lgxbslgx This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8241187: ToolBox::grep should allow for negative filtering

Reviewed-by: vromero

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 311 new commits pushed to the master branch:

  • 271a0c7: 8047218: [TEST_BUG] java/awt/FullScreen/AltTabCrashTest/AltTabCrashTest.java fails with exception
  • 1a0ff28: 8255035: Update BCEL to Version 6.5.0
  • 57c6ba6: 8266822: Rename MetaspaceShared::is_old_class to be more explicit about what "old" means
  • 616244f: 8266937: Remove Compile::reshape_address
  • 974b9f7: 8266773: Release VM is broken with GCC 9 after 8214237
  • f6c5a6b: 8266784: java/text/Collator/RuleBasedCollatorTest.java fails with jtreg 6
  • 1356116: 8266456: Replace direct TKit.run() calls with jdk.jpackage.test.Annotations.Test annotation
  • dfe8833: 8266783: java/lang/reflect/Proxy/DefaultMethods.java fails with jtreg 6
  • 995e956: 8266225: jarsigner is using incorrect security property to show weakness of certs
  • 0a12605: 8265448: (zipfs): Reduce read contention in ZipFileSystem
  • ... and 301 more: https://git.openjdk.java.net/jdk/compare/191f1fc46c30f7e92ba09d04bc000256442e64ed...master

As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@vicente-romero-oracle, @jonathan-gibbons) but any other Committer may sponsor as well.

➡️ To flag this PR as ready for integration with the above commit message, type /integrate in a new comment. (Afterwards, your sponsor types /sponsor in a new comment to perform the integration).

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 11, 2021
* @param invert identify positive or negative filtering
* true: negative filtering, return the unmatched strings
* false: positive filtering, return the matched strings
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not a particularly well-formed javadoc comment. Imagine the output if you were to run the file through javadoc.

Suggest:

Filters a list of strings according to the given regular expression,
returning either the strings that match or the strings that do not match.
@param regex the regular expression
@param lines the strings to be filtered
@param invert if true, return the lines that do not match; otherwise if false, return the lines that do match.

The invert parameter feels "inverted" leading to a "double negative".

Maybe it would be better to call the parameter "match" and invert the sense, so the doc comment reads:

Filters a list of strings according to the given regular expression,
returning either the strings that match or the strings that do not match.
@param regex the regular expression
@param lines the strings to be filtered
@param match if true, return the lines that match; otherwise if false, return the lines that do not match.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed.

@lgxbslgx
Copy link
Member Author

@vicente-romero-oracle @jonathan-gibbons Thanks for your review. I revised the code according to your suggestion.

return lines.stream()
.filter(s -> pattern.matcher(s).find())
.filter(s -> match ? pattern.matcher(s).find() : !pattern.matcher(s).find())
Copy link

Choose a reason for hiding this comment

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

s -> pattern.matcher(s).find() ^ !match would avoid repeating the expression

Copy link

Choose a reason for hiding this comment

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

Or probably even simpler s -> pattern.matcher(s).find() == match

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Fixed.

Copy link
Contributor

Choose a reason for hiding this comment

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

The first form is too cryptic. The second form is OK.

@lgxbslgx
Copy link
Member Author

/integrate

@openjdk openjdk bot added the sponsor Pull request is ready to be sponsored label May 12, 2021
@openjdk
Copy link

openjdk bot commented May 12, 2021

@lgxbslgx
Your change (at version cffa239) is now ready to be sponsored by a Committer.

@jonathan-gibbons
Copy link
Contributor

/sponsor

@openjdk openjdk bot closed this May 12, 2021
@openjdk openjdk bot added integrated Pull request has been integrated and removed sponsor Pull request is ready to be sponsored ready Pull request is ready to be integrated rfr Pull request is ready for review labels May 12, 2021
@openjdk
Copy link

openjdk bot commented May 12, 2021

@jonathan-gibbons @lgxbslgx Since your change was applied there have been 312 commits pushed to the master branch:

  • cc03734: 8266925: Add a test to verify that hidden class's members are not statically invocable
  • 271a0c7: 8047218: [TEST_BUG] java/awt/FullScreen/AltTabCrashTest/AltTabCrashTest.java fails with exception
  • 1a0ff28: 8255035: Update BCEL to Version 6.5.0
  • 57c6ba6: 8266822: Rename MetaspaceShared::is_old_class to be more explicit about what "old" means
  • 616244f: 8266937: Remove Compile::reshape_address
  • 974b9f7: 8266773: Release VM is broken with GCC 9 after 8214237
  • f6c5a6b: 8266784: java/text/Collator/RuleBasedCollatorTest.java fails with jtreg 6
  • 1356116: 8266456: Replace direct TKit.run() calls with jdk.jpackage.test.Annotations.Test annotation
  • dfe8833: 8266783: java/lang/reflect/Proxy/DefaultMethods.java fails with jtreg 6
  • 995e956: 8266225: jarsigner is using incorrect security property to show weakness of certs
  • ... and 302 more: https://git.openjdk.java.net/jdk/compare/191f1fc46c30f7e92ba09d04bc000256442e64ed...master

Your commit was automatically rebased without conflicts.

Pushed as commit ed32e02.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@lgxbslgx lgxbslgx deleted the JDK-8241187 branch May 12, 2021 01:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler compiler-dev@openjdk.org integrated Pull request has been integrated
4 participants