-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: Add CharacterLiteral.getCodePointValue()
#6614
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
Java: Add CharacterLiteral.getCodePointValue()
#6614
Conversation
CharacterLiteral.getCodePointValue()
| not this instanceof CharacterLiteral and | ||
| result = lit.toInt() | ||
| ) | ||
| or | ||
| result = this.(CharacterLiteral).getCodePointValue() |
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.
We probably don't want to surprise users by exposing this change through an existing API
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.
I am not sure if this is really a surprise. If you perform an arithmetic operation with a char literal in Java then it actually uses its code point, e.g. 'a' + 1 is 98.
If a new predicate was added for this, then a lot of the logic for the arithmetic operations of CompileTimeConstantExpr would have to be duplicated.
Additionally getIntValue() already covers a cast to char, so there is not a big difference then.
| * Gets a string which consists of the single character represented by | ||
| * this literal. | ||
| */ | ||
| string getStringValue() { result = getValue() } |
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.
Why add this alias?
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.
Mostly because getValue() just happens to represent the same result (but not necessarily on purpose) and this separate predicate makes the intention and behavior clearer.
Though maybe it indeed does not add much value, should I remove it?
However, should it then (in a separate issue?) also be discussed if StringLiteral.getRepresentedString() is really needed? Because there getValue() would be even more obvious to use.
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.
We should probably just get rid of getRepresentedString through a proper deprecation cycle. The reason for its existence dates back to before we had proper extraction of literal values, when this would simply remove the leading and trailing " chars in a naive attempt to calculate the value from the literal in QL.
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.
Have removed getStringValue() and instead added an override for getValue() with that QLDoc.
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.
Have created #7004 for deprecating getRepresentedString().
The changed code previously also only covered IntegerLiteral: - Restricted to Literal - Integral type - != "long" - != "char" So the only class left which matches all of these is IntegerLiteral.
b104332 to
4f59886
Compare
Resolves #3635
Adds
CharacterLiteral.getCodePointValue()and adjustsCompileTimeConstantExpr.getIntValue()to work forCharacterLiteral.Tests for
CompileTimeConstantExprhave not been extended, hopefully the existing test code suffices.