Skip to content

Conversation

@zbynek
Copy link
Collaborator

@zbynek zbynek commented Mar 12, 2025

Fixes #9872
Fixes #10091
Fixes #9991

@zbynek zbynek marked this pull request as draft March 12, 2025 01:37
@zbynek zbynek changed the title wip Java 12-17API additions Mar 12, 2025
@zbynek zbynek force-pushed the java17-emul branch 2 times, most recently from 42c7d0a to ec22afe Compare March 12, 2025 08:42
Copy link
Member

@niloc132 niloc132 left a comment

Choose a reason for hiding this comment

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

Nice work on the draft - some quick feedback

assertEquals(3, hideFromCompiler("foo").transform(String::length));
}

public void testIndent() {
Copy link
Member

Choose a reason for hiding this comment

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

please also include a set of these tests that does not do a hideFromCompiler, so we can make sure that if the compiler is able to constant-fold these method calls, that it does so correctly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I did not implement any tests without hideFromCompiler yet since I wasn't sure which methods need them. It seems that tests either hide all inputs from compiler (like the ones from https://github.com/gwtproject/gwt/pull/9975/files#diff-79013db0b72ddfb9522327d93e6c5804f44c160025590e971ddfc7fd4eb7c045R26 ) or hide nothing (https://github.com/zbynek/gwt/blob/f0c1486a46018aec9de93458136cfc161f569e81/user/test/com/google/gwt/emultest/java/lang/StringTest.java#L542 ). Also I'm not sure if it wouldn't be better to test the constant-folding optimization and verify that these are actually folded rather than make assertions where we don't know if we're testing folding or emulation.

Copy link
Member

Choose a reason for hiding this comment

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

Using hideFromCompiler ensures that the emulated sources provided can be called and function the way that the test expects. Passing a constant and allowing constant folding means that the operation will be performed by the compiler itself, using the JRE's own implementation, which does two things for us: we know that constant folding doesn't somehow break with this call, and that the JRE implementation doesn't behave in a way that fails the test.

This isn't a guarantee - the constant folding mechanism is pretty specific (I've been meaning to file a bug about that) and won't always kick in, but it does let us get a little more coverage.

@zbynek zbynek force-pushed the java17-emul branch 3 times, most recently from 077dfea to 55d86e0 Compare March 13, 2025 01:39
@zbynek zbynek force-pushed the java17-emul branch 4 times, most recently from 033deb4 to b6adb5d Compare March 18, 2025 06:02
@zbynek zbynek force-pushed the java17-emul branch 6 times, most recently from 0257e71 to b8996b5 Compare April 2, 2025 21:53
@zbynek zbynek marked this pull request as ready for review April 2, 2025 22:38
@zbynek zbynek force-pushed the java17-emul branch 3 times, most recently from ec661eb to a8e31dc Compare April 5, 2025 14:31
@zbynek
Copy link
Collaborator Author

zbynek commented May 1, 2025

@zbynek zbynek mentioned this pull request May 7, 2025
assertEquals("x\n y", hideFromCompiler(" x\n y").stripIndent());
assertEquals("x\n\ny", hideFromCompiler(" x\n \n y").stripIndent());
assertEquals(" x\ny", hideFromCompiler("\t x\r\n y").stripIndent());
}
Copy link
Member

Choose a reason for hiding this comment

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

I think this should have a handful of more tests too:

  • " x\n. " to confirm that the second line is entirely removed
  • " x\n\n y" to confirm blank lines do not have their indent counted
  • ...except the last line, where a blank line's indent is meaningful. Combining the above two notes, something like " x\n " should yield " x\n" (and " x\n " should have the same result)

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/String.html#stripIndent()

zbynek and others added 13 commits October 29, 2025 02:09
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
Co-authored-by: Colin Alworth <[email protected]>
@niloc132 niloc132 added the ready This PR has been reviewed by a maintainer and is ready for a CI run. label Oct 29, 2025
Co-authored-by: Colin Alworth <[email protected]>
@zbynek zbynek merged commit 552c72e into gwtproject:main Oct 30, 2025
8 checks passed
@niloc132 niloc132 added this to the 2.13 milestone Oct 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Category-JRE ready This PR has been reviewed by a maintainer and is ready for a CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CharSequence isEmpty method is missing Implement (or document) missing CharSequence methods New API emulation from Java version 12 - 17

3 participants