-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Description
In some cases it might be useful to differentiate between regular string literals and Text Blocks (""" ... """
).
CodeQL already seems to support Text Blocks and models them as StringLiteral
.
Based on the JLS Text Blocks are not string literals (e.g. it says "Unlike in a string literal ..."), however for simplicity it probably makes sense to keep modelling them as StringLiteral
anyways. But it would be good to adjust the StringLiteral
documentation then.
It would therefore be useful to either have a predicate (e.g. StringLiteral.isTextBlock()
) or a separate class TextBlock
which extends StringLiteral
.
Detection is already possible by checking if StringLiteral.getLiteral()
starts with (or ends with) """
(or checking if the literal contains line breaks, which is not possible for regular string literals). However, that is slightly error-prone because (despite being unlikely) the Java source code could use Unicode escapes (which are replaced during pre-processing) for the "
and then the getLiteral()
check would fail:
// Unicode escapes for """
String s = \u0022\uuuu0022\u0022
test
""";
So the sanest solution might be to introduce a database type or predicate eventually.
What do you think?