-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Merged
aschackmull
merged 4 commits into
github:main
from
Marcono1234:marcono1234/char-literal-codepoint
Nov 1, 2021
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
9730021
Java: Add `CharacterLiteral.getCodePointValue()`
Marcono1234 4f59886
Java: Simplify CompileTimeConstantExpr.getIntValue()
Marcono1234 fe51151
Java: Describe `CharacterLiteral.getValue()` behavior for surrogates
Marcono1234 301a907
Update java/ql/lib/semmle/code/java/Expr.qll
aschackmull File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 20 additions & 20 deletions
40
java/ql/test/library-tests/literals/charLiterals/charLiterals.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,20 +1,20 @@ | ||
| | CharLiterals.java:5:3:5:5 | 'a' | a | | ||
| | CharLiterals.java:6:3:6:10 | '\\u0061' | a | | ||
| | CharLiterals.java:7:3:7:10 | '\\u0000' | \u0000 | | ||
| | CharLiterals.java:8:3:8:10 | '\\uFFFF' | \uffff | | ||
| | CharLiterals.java:9:3:9:10 | '\\ufFfF' | \uffff | | ||
| | CharLiterals.java:10:3:10:6 | '\\0' | \u0000 | | ||
| | CharLiterals.java:11:3:11:6 | '\\n' | \n | | ||
| | CharLiterals.java:12:3:12:5 | '"' | " | | ||
| | CharLiterals.java:13:3:13:6 | '\\\\' | \\ | | ||
| | CharLiterals.java:14:3:14:6 | '\\'' | ' | | ||
| | CharLiterals.java:15:3:15:8 | '\\123' | S | | ||
| | CharLiterals.java:16:3:16:10 | '\\uD800' | \ufffd | | ||
| | CharLiterals.java:17:3:17:10 | '\\uDC00' | \ufffd | | ||
| | CharLiterals.java:19:3:19:16 | '\\u005C\\u005C' | \\ | | ||
| | CharLiterals.java:20:3:20:16 | '\\u005C\\u0027' | ' | | ||
| | CharLiterals.java:21:8:21:15 | 7a\\u0027 | a | | ||
| | CharLiterals.java:26:4:26:6 | 'a' | a | | ||
| | CharLiterals.java:27:4:27:6 | 'a' | a | | ||
| | CharLiterals.java:32:3:32:5 | 'a' | a | | ||
| | CharLiterals.java:32:9:32:11 | 'b' | b | | ||
| | CharLiterals.java:5:3:5:5 | 'a' | a | 97 | | ||
| | CharLiterals.java:6:3:6:10 | '\\u0061' | a | 97 | | ||
| | CharLiterals.java:7:3:7:10 | '\\u0000' | \u0000 | 0 | | ||
| | CharLiterals.java:8:3:8:10 | '\\uFFFF' | \uffff | 65535 | | ||
| | CharLiterals.java:9:3:9:10 | '\\ufFfF' | \uffff | 65535 | | ||
| | CharLiterals.java:10:3:10:6 | '\\0' | \u0000 | 0 | | ||
| | CharLiterals.java:11:3:11:6 | '\\n' | \n | 10 | | ||
| | CharLiterals.java:12:3:12:5 | '"' | " | 34 | | ||
| | CharLiterals.java:13:3:13:6 | '\\\\' | \\ | 92 | | ||
| | CharLiterals.java:14:3:14:6 | '\\'' | ' | 39 | | ||
| | CharLiterals.java:15:3:15:8 | '\\123' | S | 83 | | ||
| | CharLiterals.java:17:3:17:10 | '\\uD800' | \ufffd | 65533 | | ||
| | CharLiterals.java:18:3:18:10 | '\\uDC00' | \ufffd | 65533 | | ||
| | CharLiterals.java:20:3:20:16 | '\\u005C\\u005C' | \\ | 92 | | ||
| | CharLiterals.java:21:3:21:16 | '\\u005C\\u0027' | ' | 39 | | ||
| | CharLiterals.java:22:8:22:15 | 7a\\u0027 | a | 97 | | ||
| | CharLiterals.java:27:4:27:6 | 'a' | a | 97 | | ||
| | CharLiterals.java:28:4:28:6 | 'a' | a | 97 | | ||
| | CharLiterals.java:33:3:33:5 | 'a' | a | 97 | | ||
| | CharLiterals.java:33:9:33:11 | 'b' | b | 98 | |
2 changes: 1 addition & 1 deletion
2
java/ql/test/library-tests/literals/charLiterals/charLiterals.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import semmle.code.java.Expr | ||
|
|
||
| from CharacterLiteral lit | ||
| select lit, lit.getValue() | ||
| select lit, lit.getValue(), lit.getCodePointValue() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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' + 1is 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 tochar, so there is not a big difference then.