-
Notifications
You must be signed in to change notification settings - Fork 8
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
Provide option for explicit toString calls in the generated interpolation code #14
Provide option for explicit toString calls in the generated interpolation code #14
Conversation
@@ -71,9 +74,4 @@ private boolean isClassOrEnum(Element codeElement) { | |||
public SourceVersion getSupportedSourceVersion() { | |||
return SourceVersion.latestSupported(); | |||
} | |||
|
|||
private void printBanner() { | |||
String banner = "v0.3 String Interpolation Java Plugin, by Anatoliy Korovin"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Resolving #13 btw ;)
|
||
public FakeJavaFileWrapper(String text) { | ||
super(URI.create("myfake:/Test.java"), JavaFileObject.Kind.SOURCE); | ||
this.text = "class Test { Object value = String.valueOf(" + text + "); }"; | ||
if (callToStringExplicitlyInInterpolations) { | ||
this.text = "class Test { Object value = java.util.Objects.nonNull(" + text + ") ? java.util.Objects.requireNonNull(" + text + ").toString() : \"null\"; }"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the best I've come up with so far, it performs boxing for primitive types, but unfortunately requires double evaluation of the expression :/
Hi @PawelLipski , I will find time to cover this by unit tests and fix build errors, |
Ok! let me know if you agree with the general design, I can also provide docs for this as well |
Codecov Report
@@ Coverage Diff @@
## master #14 +/- ##
============================================
+ Coverage 91.89% 92.10% +0.21%
+ Complexity 54 52 -2
============================================
Files 6 6
Lines 148 152 +4
Branches 16 16
============================================
+ Hits 136 140 +4
Misses 7 7
Partials 5 5
Continue to review full report at Codecov.
|
Also, I fixed the build (see the latest commit), apparently |
@antkorwin added tests for the newly-added option; they depends on jupiter-tools/compile-test#1 getting released as v0.2 first, however (that's why Travis isn't passing as for now) |
... and docs as well :) I'd appreciate your feedback since one of our projects would greatly benefit from this feature getting released |
Hey @antkorwin 😄 how does the work go? when can we get it merged? |
@@ -147,7 +147,7 @@ | |||
<dependency> | |||
<groupId>com.jupiter-tools</groupId> | |||
<artifactId>compile-test</artifactId> | |||
<version>0.1</version> | |||
<version>0.2</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@antkorwin so now that compile-test v0.2 is on Maven Central (:tada:), could you re-run the most recent test? I apparently can't trigger a test re-run on Travis for this project myself. Or I can just amend & force-push the most recent commit.
@antkorwin long time no hear... how's going? |
Hi, @PawelLipski It looks great! |
I will check it today and deploy the next version to maven central... @PawelLipski @mkondratek thanks a lot for your contribution! |
"Result: " | ||
+ String.valueOf(obj) | ||
+ ".method() = " | ||
= String.valueOf(obj.method()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of =
it should be +
here... to be fixed with the next release
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wow, I read this text but didn't notice a typo =)
I have fixed it now.
the next release already published to the maven central |
I found it pretty useful e.g. for static code analyzers to make sure that an explicit
toString
call is always present. E.g. in our project we'd like to forbidtoString
calls on certain classes (likeOption(al)
), since it's usually not intended (and in case ofOption
, it can result in a literalSome(...)
being rendered in user-facing strings in the UI).Plus also resolve a bug related to reported positions of compilation errors within interpolated strings & improve code style in a few places.
Depends on jupiter-tools/compile-test#1