mirror of
https://github.com/github/codeql.git
synced 2026-05-04 05:05:12 +02:00
Java: Replace incorrect usage of Literal.getLiteral()
This commit is contained in:
committed by
Chris Smowton
parent
1c1c46591e
commit
58d2d5d14e
@@ -118,11 +118,7 @@ class Annotatable extends Element {
|
||||
* annotation attached to it for the specified `category`.
|
||||
*/
|
||||
predicate suppressesWarningsAbout(string category) {
|
||||
exists(string withQuotes |
|
||||
withQuotes = getAnAnnotation().(SuppressWarningsAnnotation).getASuppressedWarning()
|
||||
|
|
||||
category = withQuotes.substring(1, withQuotes.length() - 1)
|
||||
)
|
||||
category = getAnAnnotation().(SuppressWarningsAnnotation).getASuppressedWarning()
|
||||
or
|
||||
this.(Member).getDeclaringType().suppressesWarningsAbout(category)
|
||||
or
|
||||
|
||||
@@ -599,10 +599,23 @@ class AssignURShiftExpr extends AssignOp, @assignurshiftexpr {
|
||||
|
||||
/** A common super-class to represent constant literals. */
|
||||
class Literal extends Expr, @literal {
|
||||
/** Gets a string representation of this literal. */
|
||||
/**
|
||||
* Gets a string representation of this literal as it appeared
|
||||
* in the source code.
|
||||
*
|
||||
* **Important:** Unless a query explicitly wants to check how
|
||||
* a literal was written in the source code, the predicate
|
||||
* `getValue()` (or value predicates of subclasses) should be
|
||||
* used instead. For example for the integer literal `0x7fff_ffff`
|
||||
* the result of `getLiteral()` would be `0x7fff_ffff`, while
|
||||
* the result of `getValue()` would be `2147483647`.
|
||||
*/
|
||||
string getLiteral() { namestrings(result, _, this) }
|
||||
|
||||
/** Gets a string representation of the value of this literal. */
|
||||
/**
|
||||
* Gets a string representation of the value this literal
|
||||
* represents.
|
||||
*/
|
||||
string getValue() { namestrings(_, result, this) }
|
||||
|
||||
/** Gets a printable representation of this expression. */
|
||||
@@ -619,9 +632,9 @@ class Literal extends Expr, @literal {
|
||||
class BooleanLiteral extends Literal, @booleanliteral {
|
||||
/** Gets the boolean representation of this literal. */
|
||||
boolean getBooleanValue() {
|
||||
result = true and getLiteral() = "true"
|
||||
result = true and getValue() = "true"
|
||||
or
|
||||
result = false and getLiteral() = "false"
|
||||
result = false and getValue() = "false"
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "BooleanLiteral" }
|
||||
|
||||
@@ -25,10 +25,7 @@ class SuppressWarningsAnnotation extends Annotation {
|
||||
}
|
||||
|
||||
/** Gets the name of a warning suppressed by this annotation. */
|
||||
string getASuppressedWarning() {
|
||||
result = this.getAValue().(StringLiteral).getLiteral() or
|
||||
result = this.getAValue().(ArrayInit).getAnInit().(StringLiteral).getLiteral()
|
||||
}
|
||||
string getASuppressedWarning() { result = getASuppressedWarningLiteral().getRepresentedString() }
|
||||
}
|
||||
|
||||
/** A `@Target` annotation. */
|
||||
|
||||
@@ -5,7 +5,7 @@ import java
|
||||
* An element that starts with a relative path.
|
||||
*/
|
||||
predicate relativePath(Element tree, string command) {
|
||||
exists(StringLiteral lit, string text | tree = lit and text = lit.getLiteral() |
|
||||
exists(StringLiteral lit, string text | tree = lit and text = lit.getRepresentedString() |
|
||||
text != "" and
|
||||
(
|
||||
text.regexpMatch("[^/\\\\ \t]*") or
|
||||
|
||||
Reference in New Issue
Block a user