add explicit this qualifier on all of java

This commit is contained in:
Erik Krogh Kristensen
2021-10-15 15:27:37 +02:00
parent b2e4276bc8
commit caeeebf572
104 changed files with 1269 additions and 1172 deletions

View File

@@ -3,24 +3,25 @@ import java
class ExternalData extends @externalDataElement { class ExternalData extends @externalDataElement {
string getDataPath() { externalData(this, result, _, _) } string getDataPath() { externalData(this, result, _, _) }
string getQueryPath() { result = getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql") } string getQueryPath() { result = this.getDataPath().regexpReplaceAll("\\.[^.]*$", ".ql") }
int getNumFields() { result = 1 + max(int i | externalData(this, _, i, _) | i) } int getNumFields() { result = 1 + max(int i | externalData(this, _, i, _) | i) }
string getField(int index) { externalData(this, _, index, result) } string getField(int index) { externalData(this, _, index, result) }
int getFieldAsInt(int index) { result = getField(index).toInt() } int getFieldAsInt(int index) { result = this.getField(index).toInt() }
float getFieldAsFloat(int index) { result = getField(index).toFloat() } float getFieldAsFloat(int index) { result = this.getField(index).toFloat() }
date getFieldAsDate(int index) { result = getField(index).toDate() } date getFieldAsDate(int index) { result = this.getField(index).toDate() }
string toString() { result = getQueryPath() + ": " + buildTupleString(0) } string toString() { result = this.getQueryPath() + ": " + this.buildTupleString(0) }
private string buildTupleString(int start) { private string buildTupleString(int start) {
start = getNumFields() - 1 and result = getField(start) start = this.getNumFields() - 1 and result = this.getField(start)
or or
start < getNumFields() - 1 and result = getField(start) + "," + buildTupleString(start + 1) start < this.getNumFields() - 1 and
result = this.getField(start) + "," + this.buildTupleString(start + 1)
} }
} }
@@ -33,7 +34,7 @@ class DefectExternalData extends ExternalData {
this.getNumFields() = 2 this.getNumFields() = 2
} }
string getURL() { result = getField(0) } string getURL() { result = this.getField(0) }
string getMessage() { result = getField(1) } string getMessage() { result = this.getField(1) }
} }

View File

@@ -47,7 +47,7 @@ class Container extends @container, Top {
*/ */
string getRelativePath() { string getRelativePath() {
exists(string absPath, string pref | exists(string absPath, string pref |
absPath = getAbsolutePath() and sourceLocationPrefix(pref) absPath = this.getAbsolutePath() and sourceLocationPrefix(pref)
| |
absPath = pref and result = "" absPath = pref and result = ""
or or
@@ -74,7 +74,7 @@ class Container extends @container, Top {
* </table> * </table>
*/ */
string getBaseName() { string getBaseName() {
result = getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1) result = this.getAbsolutePath().regexpCapture(".*/(([^/]*?)(?:\\.([^.]*))?)", 1)
} }
/** /**
@@ -100,7 +100,9 @@ class Container extends @container, Top {
* <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr> * <tr><td>"/tmp/x.tar.gz"</td><td>"gz"</td></tr>
* </table> * </table>
*/ */
string getExtension() { result = getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3) } string getExtension() {
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(\\.([^.]*))?", 3)
}
/** /**
* Gets the stem of this container, that is, the prefix of its base name up to * Gets the stem of this container, that is, the prefix of its base name up to
@@ -119,7 +121,9 @@ class Container extends @container, Top {
* <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr> * <tr><td>"/tmp/x.tar.gz"</td><td>"x.tar"</td></tr>
* </table> * </table>
*/ */
string getStem() { result = getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1) } string getStem() {
result = this.getAbsolutePath().regexpCapture(".*/([^/]*?)(?:\\.([^.]*))?", 1)
}
/** Gets the parent container of this file or folder, if any. */ /** Gets the parent container of this file or folder, if any. */
Container getParentContainer() { containerparent(result, this) } Container getParentContainer() { containerparent(result, this) }
@@ -128,20 +132,20 @@ class Container extends @container, Top {
Container getAChildContainer() { this = result.getParentContainer() } Container getAChildContainer() { this = result.getParentContainer() }
/** Gets a file in this container. */ /** Gets a file in this container. */
File getAFile() { result = getAChildContainer() } File getAFile() { result = this.getAChildContainer() }
/** Gets the file in this container that has the given `baseName`, if any. */ /** Gets the file in this container that has the given `baseName`, if any. */
File getFile(string baseName) { File getFile(string baseName) {
result = getAFile() and result = this.getAFile() and
result.getBaseName() = baseName result.getBaseName() = baseName
} }
/** Gets a sub-folder in this container. */ /** Gets a sub-folder in this container. */
Folder getAFolder() { result = getAChildContainer() } Folder getAFolder() { result = this.getAChildContainer() }
/** Gets the sub-folder in this container that has the given `baseName`, if any. */ /** Gets the sub-folder in this container that has the given `baseName`, if any. */
Folder getFolder(string baseName) { Folder getFolder(string baseName) {
result = getAFolder() and result = this.getAFolder() and
result.getBaseName() = baseName result.getBaseName() = baseName
} }
@@ -152,7 +156,7 @@ class Container extends @container, Top {
* to provide a different result. To get the absolute path of any `Container`, call * to provide a different result. To get the absolute path of any `Container`, call
* `Container.getAbsolutePath()` directly. * `Container.getAbsolutePath()` directly.
*/ */
override string toString() { result = getAbsolutePath() } override string toString() { result = this.getAbsolutePath() }
} }
/** A folder. */ /** A folder. */
@@ -160,7 +164,7 @@ class Folder extends Container, @folder {
override string getAbsolutePath() { folders(this, result) } override string getAbsolutePath() { folders(this, result) }
/** Gets the URL of this folder. */ /** Gets the URL of this folder. */
override string getURL() { result = "folder://" + getAbsolutePath() } override string getURL() { result = "folder://" + this.getAbsolutePath() }
override string getAPrimaryQlClass() { result = "Folder" } override string getAPrimaryQlClass() { result = "Folder" }
} }
@@ -183,7 +187,7 @@ class File extends Container, @file {
* A Java archive file with a ".jar" extension. * A Java archive file with a ".jar" extension.
*/ */
class JarFile extends File { class JarFile extends File {
JarFile() { getExtension() = "jar" } JarFile() { this.getExtension() = "jar" }
/** /**
* Gets the main attribute with the specified `key` * Gets the main attribute with the specified `key`
@@ -195,13 +199,17 @@ class JarFile extends File {
* Gets the "Specification-Version" main attribute * Gets the "Specification-Version" main attribute
* from this JAR file's manifest. * from this JAR file's manifest.
*/ */
string getSpecificationVersion() { result = getManifestMainAttribute("Specification-Version") } string getSpecificationVersion() {
result = this.getManifestMainAttribute("Specification-Version")
}
/** /**
* Gets the "Implementation-Version" main attribute * Gets the "Implementation-Version" main attribute
* from this JAR file's manifest. * from this JAR file's manifest.
*/ */
string getImplementationVersion() { result = getManifestMainAttribute("Implementation-Version") } string getImplementationVersion() {
result = this.getManifestMainAttribute("Implementation-Version")
}
/** /**
* Gets the per-entry attribute for the specified `entry` and `key` * Gets the per-entry attribute for the specified `entry` and `key`

View File

@@ -63,10 +63,10 @@ class Top extends @top {
predicate hasLocationInfo( predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
) { ) {
hasLocationInfoAux(filepath, startline, startcolumn, endline, endcolumn) this.hasLocationInfoAux(filepath, startline, startcolumn, endline, endcolumn)
or or
exists(string outFilepath, int outStartline, int outEndline | exists(string outFilepath, int outStartline, int outEndline |
hasLocationInfoAux(outFilepath, outStartline, _, outEndline, _) and this.hasLocationInfoAux(outFilepath, outStartline, _, outEndline, _) and
hasSmapLocationInfo(filepath, startline, startcolumn, endline, endcolumn, outFilepath, hasSmapLocationInfo(filepath, startline, startcolumn, endline, endcolumn, outFilepath,
outStartline, outEndline) outStartline, outEndline)
) )
@@ -103,7 +103,7 @@ class Top extends @top {
/** /**
* Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs. * Gets a comma-separated list of the names of the primary CodeQL classes to which this element belongs.
*/ */
final string getPrimaryQlClasses() { result = concat(getAPrimaryQlClass(), ",") } final string getPrimaryQlClasses() { result = concat(this.getAPrimaryQlClass(), ",") }
/** /**
* Gets the name of a primary CodeQL class to which this element belongs. * Gets the name of a primary CodeQL class to which this element belongs.

View File

@@ -51,7 +51,7 @@ class Annotation extends @annotation, Expr {
Expr getValue(string name) { filteredAnnotValue(this, this.getAnnotationElement(name), result) } Expr getValue(string name) { filteredAnnotValue(this, this.getAnnotationElement(name), result) }
/** Gets the element being annotated. */ /** Gets the element being annotated. */
Element getTarget() { result = getAnnotatedElement() } Element getTarget() { result = this.getAnnotatedElement() }
override string toString() { result = this.getType().getName() } override string toString() { result = this.getType().getName() }
@@ -67,8 +67,8 @@ class Annotation extends @annotation, Expr {
* expression defined for the value. * expression defined for the value.
*/ */
Expr getAValue(string name) { Expr getAValue(string name) {
getType().getAnnotationElement(name).getType() instanceof Array and this.getType().getAnnotationElement(name).getType() instanceof Array and
exists(Expr value | value = getValue(name) | exists(Expr value | value = this.getValue(name) |
if value instanceof ArrayInit then result = value.(ArrayInit).getAnInit() else result = value if value instanceof ArrayInit then result = value.(ArrayInit).getAnInit() else result = value
) )
} }
@@ -104,7 +104,7 @@ class Annotatable extends Element {
/** Holds if this element has the specified annotation. */ /** Holds if this element has the specified annotation. */
predicate hasAnnotation(string package, string name) { predicate hasAnnotation(string package, string name) {
exists(AnnotationType at | at = getAnAnnotation().getType() | exists(AnnotationType at | at = this.getAnAnnotation().getType() |
at.nestedName() = name and at.getPackage().getName() = package at.nestedName() = name and at.getPackage().getName() = package
) )
} }
@@ -118,7 +118,7 @@ class Annotatable extends Element {
* annotation attached to it for the specified `category`. * annotation attached to it for the specified `category`.
*/ */
predicate suppressesWarningsAbout(string category) { predicate suppressesWarningsAbout(string category) {
category = getAnAnnotation().(SuppressWarningsAnnotation).getASuppressedWarning() category = this.getAnAnnotation().(SuppressWarningsAnnotation).getASuppressedWarning()
or or
this.(Member).getDeclaringType().suppressesWarningsAbout(category) this.(Member).getDeclaringType().suppressesWarningsAbout(category)
or or

View File

@@ -528,13 +528,13 @@ private module ControlFlowGraphImpl {
/** Gets the first child node, if any. */ /** Gets the first child node, if any. */
ControlFlowNode firstChild() { ControlFlowNode firstChild() {
result = getChildNode(-1) result = this.getChildNode(-1)
or or
result = getChildNode(0) and not exists(getChildNode(-1)) result = this.getChildNode(0) and not exists(this.getChildNode(-1))
} }
/** Holds if this CFG node has any child nodes. */ /** Holds if this CFG node has any child nodes. */
predicate isLeafNode() { not exists(getChildNode(_)) } predicate isLeafNode() { not exists(this.getChildNode(_)) }
/** Holds if this node can finish with a `normalCompletion`. */ /** Holds if this node can finish with a `normalCompletion`. */
predicate mayCompleteNormally() { predicate mayCompleteNormally() {
@@ -1222,10 +1222,10 @@ class ConditionNode extends ControlFlowNode {
ControlFlowNode getABranchSuccessor(boolean branch) { result = branchSuccessor(this, branch) } ControlFlowNode getABranchSuccessor(boolean branch) { result = branchSuccessor(this, branch) }
/** Gets a true-successor of the `ConditionNode`. */ /** Gets a true-successor of the `ConditionNode`. */
ControlFlowNode getATrueSuccessor() { result = getABranchSuccessor(true) } ControlFlowNode getATrueSuccessor() { result = this.getABranchSuccessor(true) }
/** Gets a false-successor of the `ConditionNode`. */ /** Gets a false-successor of the `ConditionNode`. */
ControlFlowNode getAFalseSuccessor() { result = getABranchSuccessor(false) } ControlFlowNode getAFalseSuccessor() { result = this.getABranchSuccessor(false) }
/** Gets the condition of this `ConditionNode`. This is equal to the node itself. */ /** Gets the condition of this `ConditionNode`. This is equal to the node itself. */
Expr getCondition() { result = this } Expr getCondition() { result = this }

View File

@@ -27,7 +27,7 @@ abstract class ConversionSite extends Expr {
/** /**
* Whether this conversion site actually induces a conversion. * Whether this conversion site actually induces a conversion.
*/ */
predicate isTrivial() { getConversionTarget() = getConversionSource() } predicate isTrivial() { this.getConversionTarget() = this.getConversionSource() }
/** /**
* Whether this conversion is implicit. * Whether this conversion is implicit.

View File

@@ -34,10 +34,10 @@ class Element extends @element, Top {
* Elements pertaining to source files may include generated elements * Elements pertaining to source files may include generated elements
* not visible in source code, such as implicit default constructors. * not visible in source code, such as implicit default constructors.
*/ */
predicate fromSource() { getCompilationUnit().getExtension() = "java" } predicate fromSource() { this.getCompilationUnit().getExtension() = "java" }
/** Gets the compilation unit that this element belongs to. */ /** Gets the compilation unit that this element belongs to. */
CompilationUnit getCompilationUnit() { result = getFile() } CompilationUnit getCompilationUnit() { result = this.getFile() }
/** Cast this element to a `Documentable`. */ /** Cast this element to a `Documentable`. */
Documentable getDoc() { result = this } Documentable getDoc() { result = this }

View File

@@ -86,13 +86,15 @@ class Expr extends ExprParent, @expr {
* explicit constructor invocation statement. * explicit constructor invocation statement.
*/ */
getEnclosingCallable().isStatic() this.getEnclosingCallable().isStatic()
or or
getParent+() instanceof ThisConstructorInvocationStmt this.getParent+() instanceof ThisConstructorInvocationStmt
or or
getParent+() instanceof SuperConstructorInvocationStmt this.getParent+() instanceof SuperConstructorInvocationStmt
or or
exists(LambdaExpr lam | lam.asMethod() = getEnclosingCallable() and lam.isInStaticContext()) exists(LambdaExpr lam |
lam.asMethod() = this.getEnclosingCallable() and lam.isInStaticContext()
)
} }
/** Holds if this expression is parenthesized. */ /** Holds if this expression is parenthesized. */
@@ -116,7 +118,7 @@ private predicate primitiveOrString(Type t) {
*/ */
class CompileTimeConstantExpr extends Expr { class CompileTimeConstantExpr extends Expr {
CompileTimeConstantExpr() { CompileTimeConstantExpr() {
primitiveOrString(getType()) and primitiveOrString(this.getType()) and
( (
// Literals of primitive type and literals of type `String`. // Literals of primitive type and literals of type `String`.
this instanceof Literal this instanceof Literal
@@ -425,9 +427,9 @@ class ArrayCreationExpr extends Expr, @arraycreationexpr {
* Gets the size of the first dimension, if it can be statically determined. * Gets the size of the first dimension, if it can be statically determined.
*/ */
int getFirstDimensionSize() { int getFirstDimensionSize() {
if exists(getInit()) if exists(this.getInit())
then result = getInit().getSize() then result = this.getInit().getSize()
else result = getDimension(0).(CompileTimeConstantExpr).getIntValue() else result = this.getDimension(0).(CompileTimeConstantExpr).getIntValue()
} }
/** Gets a printable representation of this expression. */ /** Gets a printable representation of this expression. */
@@ -463,7 +465,7 @@ class ArrayInit extends Expr, @arrayinit {
* Gets the number of expressions in this initializer, that is, the size the * Gets the number of expressions in this initializer, that is, the size the
* created array will have. * created array will have.
*/ */
int getSize() { result = count(getAnInit()) } int getSize() { result = count(this.getAnInit()) }
/** Gets a printable representation of this expression. */ /** Gets a printable representation of this expression. */
override string toString() { result = "{...}" } override string toString() { result = "{...}" }
@@ -632,9 +634,9 @@ class Literal extends Expr, @literal {
class BooleanLiteral extends Literal, @booleanliteral { class BooleanLiteral extends Literal, @booleanliteral {
/** Gets the boolean representation of this literal. */ /** Gets the boolean representation of this literal. */
boolean getBooleanValue() { boolean getBooleanValue() {
result = true and getValue() = "true" result = true and this.getValue() = "true"
or or
result = false and getValue() = "false" result = false and this.getValue() = "false"
} }
override string getAPrimaryQlClass() { result = "BooleanLiteral" } override string getAPrimaryQlClass() { result = "BooleanLiteral" }
@@ -657,7 +659,7 @@ class BooleanLiteral extends Literal, @booleanliteral {
*/ */
class IntegerLiteral extends Literal, @integerliteral { class IntegerLiteral extends Literal, @integerliteral {
/** Gets the int representation of this literal. */ /** Gets the int representation of this literal. */
int getIntValue() { result = getValue().toInt() } int getIntValue() { result = this.getValue().toInt() }
override string getAPrimaryQlClass() { result = "IntegerLiteral" } override string getAPrimaryQlClass() { result = "IntegerLiteral" }
} }
@@ -693,7 +695,7 @@ class FloatingPointLiteral extends Literal, @floatingpointliteral {
* Gets the value of this literal as CodeQL 64-bit `float`. The value will * Gets the value of this literal as CodeQL 64-bit `float`. The value will
* be parsed as Java 32-bit `float` and then converted to a CodeQL `float`. * be parsed as Java 32-bit `float` and then converted to a CodeQL `float`.
*/ */
float getFloatValue() { result = getValue().toFloat() } float getFloatValue() { result = this.getValue().toFloat() }
override string getAPrimaryQlClass() { result = "FloatingPointLiteral" } override string getAPrimaryQlClass() { result = "FloatingPointLiteral" }
} }
@@ -709,7 +711,7 @@ class DoubleLiteral extends Literal, @doubleliteral {
* Gets the value of this literal as CodeQL 64-bit `float`. The result will * Gets the value of this literal as CodeQL 64-bit `float`. The result will
* have the same effective value as the Java `double` literal. * have the same effective value as the Java `double` literal.
*/ */
float getDoubleValue() { result = getValue().toFloat() } float getDoubleValue() { result = this.getValue().toFloat() }
override string getAPrimaryQlClass() { result = "DoubleLiteral" } override string getAPrimaryQlClass() { result = "DoubleLiteral" }
} }
@@ -732,10 +734,10 @@ class StringLiteral extends Literal, @stringliteral {
/** /**
* Gets the literal string without the quotes. * Gets the literal string without the quotes.
*/ */
string getRepresentedString() { result = getValue() } string getRepresentedString() { result = this.getValue() }
/** Holds if this string literal is a text block (`""" ... """`). */ /** Holds if this string literal is a text block (`""" ... """`). */
predicate isTextBlock() { getLiteral().matches("\"\"\"%") } predicate isTextBlock() { this.getLiteral().matches("\"\"\"%") }
override string getAPrimaryQlClass() { result = "StringLiteral" } override string getAPrimaryQlClass() { result = "StringLiteral" }
} }
@@ -1184,7 +1186,7 @@ class LambdaExpr extends FunctionalExpr, @lambdaexpr {
* Gets the implicit method corresponding to this lambda expression. * Gets the implicit method corresponding to this lambda expression.
* The parameters of the lambda expression are the parameters of this method. * The parameters of the lambda expression are the parameters of this method.
*/ */
override Method asMethod() { result = getAnonymousClass().getAMethod() } override Method asMethod() { result = this.getAnonymousClass().getAMethod() }
/** Holds if the body of this lambda is an expression. */ /** Holds if the body of this lambda is an expression. */
predicate hasExprBody() { lambdaKind(this, 0) } predicate hasExprBody() { lambdaKind(this, 0) }
@@ -1194,11 +1196,11 @@ class LambdaExpr extends FunctionalExpr, @lambdaexpr {
/** Gets the body of this lambda expression, if it is an expression. */ /** Gets the body of this lambda expression, if it is an expression. */
Expr getExprBody() { Expr getExprBody() {
hasExprBody() and result = asMethod().getBody().getAChild().(ReturnStmt).getResult() this.hasExprBody() and result = this.asMethod().getBody().getAChild().(ReturnStmt).getResult()
} }
/** Gets the body of this lambda expression, if it is a statement. */ /** Gets the body of this lambda expression, if it is a statement. */
BlockStmt getStmtBody() { hasStmtBody() and result = asMethod().getBody() } BlockStmt getStmtBody() { this.hasStmtBody() and result = this.asMethod().getBody() }
/** Gets a printable representation of this expression. */ /** Gets a printable representation of this expression. */
override string toString() { result = "...->..." } override string toString() { result = "...->..." }
@@ -1223,7 +1225,7 @@ class MemberRefExpr extends FunctionalExpr, @memberref {
* (if the reference is to a constructor) or an array creation expression (if the reference * (if the reference is to a constructor) or an array creation expression (if the reference
* is to an array constructor). * is to an array constructor).
*/ */
override Method asMethod() { result = getAnonymousClass().getAMethod() } override Method asMethod() { result = this.getAnonymousClass().getAMethod() }
/** /**
* Gets the method or constructor referenced by this member reference expression. * Gets the method or constructor referenced by this member reference expression.
@@ -1274,16 +1276,16 @@ class ConditionalExpr extends Expr, @conditionalexpr {
* it is `getFalseExpr()`. * it is `getFalseExpr()`.
*/ */
Expr getBranchExpr(boolean branch) { Expr getBranchExpr(boolean branch) {
branch = true and result = getTrueExpr() branch = true and result = this.getTrueExpr()
or or
branch = false and result = getFalseExpr() branch = false and result = this.getFalseExpr()
} }
/** /**
* Gets the expressions that is evaluated by one of the branches (`true` * Gets the expressions that is evaluated by one of the branches (`true`
* or `false` branch) of this conditional expression. * or `false` branch) of this conditional expression.
*/ */
Expr getABranchExpr() { result = getBranchExpr(_) } Expr getABranchExpr() { result = this.getBranchExpr(_) }
/** Gets a printable representation of this expression. */ /** Gets a printable representation of this expression. */
override string toString() { result = "...?...:..." } override string toString() { result = "...?...:..." }
@@ -1308,7 +1310,7 @@ class SwitchExpr extends Expr, StmtParent, @switchexpr {
* Gets a case of this `switch` expression, * Gets a case of this `switch` expression,
* which may be either a normal `case` or a `default`. * which may be either a normal `case` or a `default`.
*/ */
SwitchCase getACase() { result = getAConstCase() or result = getDefaultCase() } SwitchCase getACase() { result = this.getAConstCase() or result = this.getDefaultCase() }
/** Gets a (non-default) `case` of this `switch` expression. */ /** Gets a (non-default) `case` of this `switch` expression. */
ConstCase getAConstCase() { result.getParent() = this } ConstCase getAConstCase() { result.getParent() = this }
@@ -1321,7 +1323,7 @@ class SwitchExpr extends Expr, StmtParent, @switchexpr {
/** Gets a result expression of this `switch` expression. */ /** Gets a result expression of this `switch` expression. */
Expr getAResult() { Expr getAResult() {
result = getACase().getRuleExpression() result = this.getACase().getRuleExpression()
or or
exists(YieldStmt yield | yield.(JumpStmt).getTarget() = this and result = yield.getValue()) exists(YieldStmt yield | yield.(JumpStmt).getTarget() = this and result = yield.getValue())
} }
@@ -1336,8 +1338,8 @@ class SwitchExpr extends Expr, StmtParent, @switchexpr {
class InstanceOfExpr extends Expr, @instanceofexpr { class InstanceOfExpr extends Expr, @instanceofexpr {
/** Gets the expression on the left-hand side of the `instanceof` operator. */ /** Gets the expression on the left-hand side of the `instanceof` operator. */
Expr getExpr() { Expr getExpr() {
if isPattern() if this.isPattern()
then result = getLocalVariableDeclExpr().getInit() then result = this.getLocalVariableDeclExpr().getInit()
else result.isNthChildOf(this, 0) else result.isNthChildOf(this, 0)
} }
@@ -1346,7 +1348,7 @@ class InstanceOfExpr extends Expr, @instanceofexpr {
* *
* Holds if this `instanceof` expression uses pattern matching. * Holds if this `instanceof` expression uses pattern matching.
*/ */
predicate isPattern() { exists(getLocalVariableDeclExpr()) } predicate isPattern() { exists(this.getLocalVariableDeclExpr()) }
/** /**
* PREVIEW FEATURE in Java 14. Subject to removal in a future release. * PREVIEW FEATURE in Java 14. Subject to removal in a future release.
@@ -1359,7 +1361,7 @@ class InstanceOfExpr extends Expr, @instanceofexpr {
Expr getTypeName() { result.isNthChildOf(this, 1) } Expr getTypeName() { result.isNthChildOf(this, 1) }
/** Gets the type this `instanceof` expression checks for. */ /** Gets the type this `instanceof` expression checks for. */
RefType getCheckedType() { result = getTypeName().getType() } RefType getCheckedType() { result = this.getTypeName().getType() }
/** Gets a printable representation of this expression. */ /** Gets a printable representation of this expression. */
override string toString() { result = "...instanceof..." } override string toString() { result = "...instanceof..." }
@@ -1457,7 +1459,7 @@ class TypeLiteral extends Expr, @typeliteral {
* Gets the type this type literal refers to. For example for `String.class` the * Gets the type this type literal refers to. For example for `String.class` the
* result is the type representing `String`. * result is the type representing `String`.
*/ */
Type getReferencedType() { result = getTypeName().getType() } Type getReferencedType() { result = this.getTypeName().getType() }
/** Gets a printable representation of this expression. */ /** Gets a printable representation of this expression. */
override string toString() { result = this.getTypeName().toString() + ".class" } override string toString() { result = this.getTypeName().toString() + ".class" }
@@ -1482,15 +1484,15 @@ abstract class InstanceAccess extends Expr {
* This never holds for accesses in lambda expressions as they cannot access * This never holds for accesses in lambda expressions as they cannot access
* their own instance directly. * their own instance directly.
*/ */
predicate isOwnInstanceAccess() { not isEnclosingInstanceAccess(_) } predicate isOwnInstanceAccess() { not this.isEnclosingInstanceAccess(_) }
/** Holds if this instance access is to an enclosing instance of type `t`. */ /** Holds if this instance access is to an enclosing instance of type `t`. */
predicate isEnclosingInstanceAccess(RefType t) { predicate isEnclosingInstanceAccess(RefType t) {
t = getQualifier().getType().(RefType).getSourceDeclaration() and t = this.getQualifier().getType().(RefType).getSourceDeclaration() and
t != getEnclosingCallable().getDeclaringType() t != this.getEnclosingCallable().getDeclaringType()
or or
not exists(getQualifier()) and not exists(this.getQualifier()) and
exists(LambdaExpr lam | lam.asMethod() = getEnclosingCallable() | exists(LambdaExpr lam | lam.asMethod() = this.getEnclosingCallable() |
t = lam.getAnonymousClass().getEnclosingType() t = lam.getAnonymousClass().getEnclosingType()
) )
} }
@@ -1538,7 +1540,7 @@ class VarAccess extends Expr, @varaccess {
Expr getQualifier() { result.getParent() = this } Expr getQualifier() { result.getParent() = this }
/** Holds if this variable access has a qualifier. */ /** Holds if this variable access has a qualifier. */
predicate hasQualifier() { exists(getQualifier()) } predicate hasQualifier() { exists(this.getQualifier()) }
/** Gets the variable accessed by this variable access. */ /** Gets the variable accessed by this variable access. */
Variable getVariable() { variableBinding(this, result) } Variable getVariable() { variableBinding(this, result) }
@@ -1580,11 +1582,11 @@ class VarAccess extends Expr, @varaccess {
*/ */
predicate isLocal() { predicate isLocal() {
// The access has no qualifier, or... // The access has no qualifier, or...
not hasQualifier() not this.hasQualifier()
or or
// the qualifier is either `this` or `A.this`, where `A` is the enclosing type, or // the qualifier is either `this` or `A.this`, where `A` is the enclosing type, or
// the qualifier is either `super` or `A.super`, where `A` is the enclosing type. // the qualifier is either `super` or `A.super`, where `A` is the enclosing type.
getQualifier().(InstanceAccess).isOwnInstanceAccess() this.getQualifier().(InstanceAccess).isOwnInstanceAccess()
} }
override string getAPrimaryQlClass() { result = "VarAccess" } override string getAPrimaryQlClass() { result = "VarAccess" }
@@ -1626,7 +1628,7 @@ class MethodAccess extends Expr, Call, @methodaccess {
override Expr getQualifier() { result.isNthChildOf(this, -1) } override Expr getQualifier() { result.isNthChildOf(this, -1) }
/** Holds if this method access has a qualifier. */ /** Holds if this method access has a qualifier. */
predicate hasQualifier() { exists(getQualifier()) } predicate hasQualifier() { exists(this.getQualifier()) }
/** Gets an argument supplied to the method that is invoked using this method access. */ /** Gets an argument supplied to the method that is invoked using this method access. */
override Expr getAnArgument() { result.getIndex() >= 0 and result.getParent() = this } override Expr getAnArgument() { result.getIndex() >= 0 and result.getParent() = this }
@@ -1663,9 +1665,9 @@ class MethodAccess extends Expr, Call, @methodaccess {
* the enclosing type if there is no qualifier. * the enclosing type if there is no qualifier.
*/ */
RefType getReceiverType() { RefType getReceiverType() {
result = getQualifier().getType() result = this.getQualifier().getType()
or or
not hasQualifier() and result = getEnclosingCallable().getDeclaringType() not this.hasQualifier() and result = this.getEnclosingCallable().getDeclaringType()
} }
/** /**
@@ -1841,7 +1843,7 @@ class Call extends ExprParent, @caller {
Callable getCallee() { callableBinding(this, result) } Callable getCallee() { callableBinding(this, result) }
/** Gets the callable invoking this call. */ /** Gets the callable invoking this call. */
Callable getCaller() { result = getEnclosingCallable() } Callable getCaller() { result = this.getEnclosingCallable() }
} }
/** A polymorphic call to an instance method. */ /** A polymorphic call to an instance method. */
@@ -2042,14 +2044,14 @@ class Argument extends Expr {
} }
/** Holds if this argument is part of an implicit varargs array. */ /** Holds if this argument is part of an implicit varargs array. */
predicate isVararg() { isNthVararg(_) } predicate isVararg() { this.isNthVararg(_) }
/** /**
* Holds if this argument is part of an implicit varargs array at the * Holds if this argument is part of an implicit varargs array at the
* given array index. * given array index.
*/ */
predicate isNthVararg(int arrayindex) { predicate isNthVararg(int arrayindex) {
not isExplicitVarargsArray() and not this.isExplicitVarargsArray() and
exists(Callable tgt | exists(Callable tgt |
call.getCallee() = tgt and call.getCallee() = tgt and
tgt.isVarargs() and tgt.isVarargs() and

View File

@@ -69,12 +69,12 @@ class GenericType extends RefType {
/** /**
* Gets a type parameter of this generic type. * Gets a type parameter of this generic type.
*/ */
TypeVariable getATypeParameter() { result = getTypeParameter(_) } TypeVariable getATypeParameter() { result = this.getTypeParameter(_) }
/** /**
* Gets the number of type parameters of this generic type. * Gets the number of type parameters of this generic type.
*/ */
int getNumberOfTypeParameters() { result = strictcount(getATypeParameter()) } int getNumberOfTypeParameters() { result = strictcount(this.getATypeParameter()) }
override string getAPrimaryQlClass() { result = "GenericType" } override string getAPrimaryQlClass() { result = "GenericType" }
} }
@@ -107,7 +107,7 @@ abstract class BoundedType extends RefType, @boundedtype {
TypeBound getATypeBound() { result.getBoundedType() = this } TypeBound getATypeBound() { result.getBoundedType() = this }
/** Gets the first type bound for this type, if any. */ /** Gets the first type bound for this type, if any. */
TypeBound getFirstTypeBound() { result = getATypeBound() and result.getPosition() = 0 } TypeBound getFirstTypeBound() { result = this.getATypeBound() and result.getPosition() = 0 }
/** /**
* Gets an upper type bound of this type, or `Object` * Gets an upper type bound of this type, or `Object`
@@ -123,9 +123,9 @@ abstract class BoundedType extends RefType, @boundedtype {
/** Gets a transitive upper bound for this type that is not itself a bounded type. */ /** Gets a transitive upper bound for this type that is not itself a bounded type. */
RefType getAnUltimateUpperBoundType() { RefType getAnUltimateUpperBoundType() {
result = getUpperBoundType() and not result instanceof BoundedType result = this.getUpperBoundType() and not result instanceof BoundedType
or or
result = getUpperBoundType().(BoundedType).getAnUltimateUpperBoundType() result = this.getUpperBoundType().(BoundedType).getAnUltimateUpperBoundType()
} }
override string getAPrimaryQlClass() { result = "BoundedType" } override string getAPrimaryQlClass() { result = "BoundedType" }
@@ -168,8 +168,8 @@ class TypeVariable extends BoundedType, @typevariable {
/** Gets the lexically enclosing package of this type parameter, if any. */ /** Gets the lexically enclosing package of this type parameter, if any. */
override Package getPackage() { override Package getPackage() {
result = getGenericType().getPackage() or result = this.getGenericType().getPackage() or
result = getGenericCallable().getDeclaringType().getPackage() result = this.getGenericCallable().getDeclaringType().getPackage()
} }
/** Finds a type that was supplied for this parameter. */ /** Finds a type that was supplied for this parameter. */
@@ -190,9 +190,9 @@ class TypeVariable extends BoundedType, @typevariable {
/** Finds a non-typevariable type that was transitively supplied for this parameter. */ /** Finds a non-typevariable type that was transitively supplied for this parameter. */
RefType getAnUltimatelySuppliedType() { RefType getAnUltimatelySuppliedType() {
result = getASuppliedType() and not result instanceof TypeVariable result = this.getASuppliedType() and not result instanceof TypeVariable
or or
result = getASuppliedType().(TypeVariable).getAnUltimatelySuppliedType() result = this.getASuppliedType().(TypeVariable).getAnUltimatelySuppliedType()
} }
override string getAPrimaryQlClass() { result = "TypeVariable" } override string getAPrimaryQlClass() { result = "TypeVariable" }
@@ -261,7 +261,7 @@ class Wildcard extends BoundedType, @wildcard {
* Holds if this is the unconstrained wildcard `?`. * Holds if this is the unconstrained wildcard `?`.
*/ */
predicate isUnconstrained() { predicate isUnconstrained() {
not hasLowerBound() and not this.hasLowerBound() and
wildcards(this, "?", _) wildcards(this, "?", _)
} }
@@ -451,12 +451,12 @@ class GenericCallable extends Callable {
/** /**
* Gets a type parameter of this generic callable. * Gets a type parameter of this generic callable.
*/ */
TypeVariable getATypeParameter() { result = getTypeParameter(_) } TypeVariable getATypeParameter() { result = this.getTypeParameter(_) }
/** /**
* Gets the number of type parameters of this generic callable. * Gets the number of type parameters of this generic callable.
*/ */
int getNumberOfTypeParameters() { result = strictcount(getATypeParameter()) } int getNumberOfTypeParameters() { result = strictcount(this.getATypeParameter()) }
} }
/** /**
@@ -484,10 +484,10 @@ class GenericCall extends Call {
/** Gets a type argument of the call for the given `TypeVariable`. */ /** Gets a type argument of the call for the given `TypeVariable`. */
RefType getATypeArgument(TypeVariable v) { RefType getATypeArgument(TypeVariable v) {
result = getAnExplicitTypeArgument(v) result = this.getAnExplicitTypeArgument(v)
or or
not exists(getAnExplicitTypeArgument(v)) and not exists(this.getAnExplicitTypeArgument(v)) and
result = getAnInferredTypeArgument(v) result = this.getAnInferredTypeArgument(v)
} }
} }

View File

@@ -19,12 +19,12 @@ class TypeCloneable extends Interface {
/** The class `java.lang.ProcessBuilder`. */ /** The class `java.lang.ProcessBuilder`. */
class TypeProcessBuilder extends Class { class TypeProcessBuilder extends Class {
TypeProcessBuilder() { hasQualifiedName("java.lang", "ProcessBuilder") } TypeProcessBuilder() { this.hasQualifiedName("java.lang", "ProcessBuilder") }
} }
/** The class `java.lang.Runtime`. */ /** The class `java.lang.Runtime`. */
class TypeRuntime extends Class { class TypeRuntime extends Class {
TypeRuntime() { hasQualifiedName("java.lang", "Runtime") } TypeRuntime() { this.hasQualifiedName("java.lang", "Runtime") }
} }
/** The class `java.lang.String`. */ /** The class `java.lang.String`. */
@@ -143,22 +143,22 @@ class ImmutableType extends Type {
// --- Java IO --- // --- Java IO ---
/** The interface `java.io.Serializable`. */ /** The interface `java.io.Serializable`. */
class TypeSerializable extends Interface { class TypeSerializable extends Interface {
TypeSerializable() { hasQualifiedName("java.io", "Serializable") } TypeSerializable() { this.hasQualifiedName("java.io", "Serializable") }
} }
/** The interface `java.io.ObjectOutput`. */ /** The interface `java.io.ObjectOutput`. */
class TypeObjectOutput extends Interface { class TypeObjectOutput extends Interface {
TypeObjectOutput() { hasQualifiedName("java.io", "ObjectOutput") } TypeObjectOutput() { this.hasQualifiedName("java.io", "ObjectOutput") }
} }
/** The type `java.io.ObjectOutputStream`. */ /** The type `java.io.ObjectOutputStream`. */
class TypeObjectOutputStream extends RefType { class TypeObjectOutputStream extends RefType {
TypeObjectOutputStream() { hasQualifiedName("java.io", "ObjectOutputStream") } TypeObjectOutputStream() { this.hasQualifiedName("java.io", "ObjectOutputStream") }
} }
/** The type `java.io.ObjectInputStream`. */ /** The type `java.io.ObjectInputStream`. */
class TypeObjectInputStream extends RefType { class TypeObjectInputStream extends RefType {
TypeObjectInputStream() { hasQualifiedName("java.io", "ObjectInputStream") } TypeObjectInputStream() { this.hasQualifiedName("java.io", "ObjectInputStream") }
} }
/** The class `java.nio.file.Paths`. */ /** The class `java.nio.file.Paths`. */
@@ -196,8 +196,8 @@ class ProcessBuilderConstructor extends Constructor, ExecCallable {
*/ */
class MethodProcessBuilderCommand extends Method, ExecCallable { class MethodProcessBuilderCommand extends Method, ExecCallable {
MethodProcessBuilderCommand() { MethodProcessBuilderCommand() {
hasName("command") and this.hasName("command") and
getDeclaringType() instanceof TypeProcessBuilder this.getDeclaringType() instanceof TypeProcessBuilder
} }
override int getAnExecutedArgument() { result = 0 } override int getAnExecutedArgument() { result = 0 }
@@ -208,8 +208,8 @@ class MethodProcessBuilderCommand extends Method, ExecCallable {
*/ */
class MethodRuntimeExec extends Method, ExecCallable { class MethodRuntimeExec extends Method, ExecCallable {
MethodRuntimeExec() { MethodRuntimeExec() {
hasName("exec") and this.hasName("exec") and
getDeclaringType() instanceof TypeRuntime this.getDeclaringType() instanceof TypeRuntime
} }
override int getAnExecutedArgument() { result = 0 } override int getAnExecutedArgument() { result = 0 }
@@ -220,8 +220,8 @@ class MethodRuntimeExec extends Method, ExecCallable {
*/ */
class MethodSystemGetenv extends Method { class MethodSystemGetenv extends Method {
MethodSystemGetenv() { MethodSystemGetenv() {
hasName("getenv") and this.hasName("getenv") and
getDeclaringType() instanceof TypeSystem this.getDeclaringType() instanceof TypeSystem
} }
} }
@@ -230,8 +230,8 @@ class MethodSystemGetenv extends Method {
*/ */
class MethodSystemGetProperty extends Method { class MethodSystemGetProperty extends Method {
MethodSystemGetProperty() { MethodSystemGetProperty() {
hasName("getProperty") and this.hasName("getProperty") and
getDeclaringType() instanceof TypeSystem this.getDeclaringType() instanceof TypeSystem
} }
} }
@@ -239,7 +239,7 @@ class MethodSystemGetProperty extends Method {
* An access to a method named `getProperty` on class `java.lang.System`. * An access to a method named `getProperty` on class `java.lang.System`.
*/ */
class MethodAccessSystemGetProperty extends MethodAccess { class MethodAccessSystemGetProperty extends MethodAccess {
MethodAccessSystemGetProperty() { getMethod() instanceof MethodSystemGetProperty } MethodAccessSystemGetProperty() { this.getMethod() instanceof MethodSystemGetProperty }
/** /**
* Holds if this call has a compile-time constant first argument with the value `propertyName`. * Holds if this call has a compile-time constant first argument with the value `propertyName`.
@@ -255,8 +255,11 @@ class MethodAccessSystemGetProperty extends MethodAccess {
*/ */
class MethodExit extends Method { class MethodExit extends Method {
MethodExit() { MethodExit() {
hasName("exit") and this.hasName("exit") and
(getDeclaringType() instanceof TypeRuntime or getDeclaringType() instanceof TypeSystem) (
this.getDeclaringType() instanceof TypeRuntime or
this.getDeclaringType() instanceof TypeSystem
)
} }
} }
@@ -266,10 +269,10 @@ class MethodExit extends Method {
*/ */
class WriteObjectMethod extends Method { class WriteObjectMethod extends Method {
WriteObjectMethod() { WriteObjectMethod() {
hasName("writeObject") and this.hasName("writeObject") and
( (
getDeclaringType() instanceof TypeObjectOutputStream or this.getDeclaringType() instanceof TypeObjectOutputStream or
getDeclaringType() instanceof TypeObjectOutput this.getDeclaringType() instanceof TypeObjectOutput
) )
} }
} }
@@ -293,16 +296,16 @@ class ReadObjectMethod extends Method {
/** The method `Class.getName()`. */ /** The method `Class.getName()`. */
class ClassNameMethod extends Method { class ClassNameMethod extends Method {
ClassNameMethod() { ClassNameMethod() {
hasName("getName") and this.hasName("getName") and
getDeclaringType() instanceof TypeClass this.getDeclaringType() instanceof TypeClass
} }
} }
/** The method `Class.getSimpleName()`. */ /** The method `Class.getSimpleName()`. */
class ClassSimpleNameMethod extends Method { class ClassSimpleNameMethod extends Method {
ClassSimpleNameMethod() { ClassSimpleNameMethod() {
hasName("getSimpleName") and this.hasName("getSimpleName") and
getDeclaringType() instanceof TypeClass this.getDeclaringType() instanceof TypeClass
} }
} }
@@ -334,24 +337,24 @@ class MethodMathMax extends Method {
/** The field `System.in`. */ /** The field `System.in`. */
class SystemIn extends Field { class SystemIn extends Field {
SystemIn() { SystemIn() {
hasName("in") and this.hasName("in") and
getDeclaringType() instanceof TypeSystem this.getDeclaringType() instanceof TypeSystem
} }
} }
/** The field `System.out`. */ /** The field `System.out`. */
class SystemOut extends Field { class SystemOut extends Field {
SystemOut() { SystemOut() {
hasName("out") and this.hasName("out") and
getDeclaringType() instanceof TypeSystem this.getDeclaringType() instanceof TypeSystem
} }
} }
/** The field `System.err`. */ /** The field `System.err`. */
class SystemErr extends Field { class SystemErr extends Field {
SystemErr() { SystemErr() {
hasName("err") and this.hasName("err") and
getDeclaringType() instanceof TypeSystem this.getDeclaringType() instanceof TypeSystem
} }
} }

View File

@@ -25,7 +25,9 @@ class SuppressWarningsAnnotation extends Annotation {
} }
/** Gets the name of a warning suppressed by this annotation. */ /** Gets the name of a warning suppressed by this annotation. */
string getASuppressedWarning() { result = getASuppressedWarningLiteral().getRepresentedString() } string getASuppressedWarning() {
result = this.getASuppressedWarningLiteral().getRepresentedString()
}
} }
/** A `@Target` annotation. */ /** A `@Target` annotation. */

View File

@@ -26,27 +26,27 @@ class MXBean extends ManagedBean {
*/ */
class RegisteredManagedBeanImpl extends Class { class RegisteredManagedBeanImpl extends Class {
RegisteredManagedBeanImpl() { RegisteredManagedBeanImpl() {
getAnAncestor() instanceof ManagedBean and this.getAnAncestor() instanceof ManagedBean and
exists(JMXRegistrationCall registerCall | registerCall.getObjectArgument().getType() = this) exists(JMXRegistrationCall registerCall | registerCall.getObjectArgument().getType() = this)
} }
/** /**
* Gets a managed bean that this registered bean class implements. * Gets a managed bean that this registered bean class implements.
*/ */
ManagedBean getAnImplementedManagedBean() { result = getAnAncestor() } ManagedBean getAnImplementedManagedBean() { result = this.getAnAncestor() }
} }
/** /**
* A call that registers an object with the `MBeanServer`, directly or indirectly. * A call that registers an object with the `MBeanServer`, directly or indirectly.
*/ */
class JMXRegistrationCall extends MethodAccess { class JMXRegistrationCall extends MethodAccess {
JMXRegistrationCall() { getCallee() instanceof JMXRegistrationMethod } JMXRegistrationCall() { this.getCallee() instanceof JMXRegistrationMethod }
/** /**
* Gets the argument that represents the object in the registration call. * Gets the argument that represents the object in the registration call.
*/ */
Expr getObjectArgument() { Expr getObjectArgument() {
result = getArgument(getCallee().(JMXRegistrationMethod).getObjectPosition()) result = this.getArgument(this.getCallee().(JMXRegistrationMethod).getObjectPosition())
} }
} }
@@ -59,15 +59,15 @@ class JMXRegistrationCall extends MethodAccess {
class JMXRegistrationMethod extends Method { class JMXRegistrationMethod extends Method {
JMXRegistrationMethod() { JMXRegistrationMethod() {
// A direct registration with the `MBeanServer`. // A direct registration with the `MBeanServer`.
getDeclaringType().hasQualifiedName("javax.management", "MBeanServer") and this.getDeclaringType().hasQualifiedName("javax.management", "MBeanServer") and
getName() = "registerMBean" this.getName() = "registerMBean"
or or
// The `MBeanServer` is often wrapped by an application specific management class, so identify // The `MBeanServer` is often wrapped by an application specific management class, so identify
// methods that wrap a call to another `JMXRegistrationMethod`. // methods that wrap a call to another `JMXRegistrationMethod`.
exists(JMXRegistrationCall c | exists(JMXRegistrationCall c |
// This must be a call to another JMX registration method, where the object argument is an access // This must be a call to another JMX registration method, where the object argument is an access
// of one of the parameters of this method. // of one of the parameters of this method.
c.getObjectArgument().(VarAccess).getVariable() = getAParameter() c.getObjectArgument().(VarAccess).getVariable() = this.getAParameter()
) )
} }
@@ -76,13 +76,13 @@ class JMXRegistrationMethod extends Method {
*/ */
int getObjectPosition() { int getObjectPosition() {
// Passed as the first argument to `registerMBean`. // Passed as the first argument to `registerMBean`.
getDeclaringType().hasQualifiedName("javax.management", "MBeanServer") and this.getDeclaringType().hasQualifiedName("javax.management", "MBeanServer") and
getName() = "registerMBean" and this.getName() = "registerMBean" and
result = 0 result = 0
or or
// Identify the position in this method where the object parameter should be passed. // Identify the position in this method where the object parameter should be passed.
exists(JMXRegistrationCall c | exists(JMXRegistrationCall c |
c.getObjectArgument().(VarAccess).getVariable() = getParameter(result) c.getObjectArgument().(VarAccess).getVariable() = this.getParameter(result)
) )
} }
} }

View File

@@ -14,7 +14,7 @@ class JavadocParent extends @javadocParent, Top {
JavadocElement getChild(int index) { result = this.getAChild() and result.getIndex() = index } JavadocElement getChild(int index) { result = this.getAChild() and result.getIndex() = index }
/** Gets the number of documentation elements attached to this parent. */ /** Gets the number of documentation elements attached to this parent. */
int getNumChild() { result = count(getAChild()) } int getNumChild() { result = count(this.getAChild()) }
/** Gets a documentation element with the specified Javadoc tag name. */ /** Gets a documentation element with the specified Javadoc tag name. */
JavadocTag getATag(string name) { result = this.getAChild() and result.getTagName() = name } JavadocTag getATag(string name) { result = this.getAChild() and result.getTagName() = name }
@@ -33,7 +33,9 @@ class Javadoc extends JavadocParent, @javadoc {
/** Gets the value of the `@author` tag, if any. */ /** Gets the value of the `@author` tag, if any. */
string getAuthor() { result = this.getATag("@author").getChild(0).toString() } string getAuthor() { result = this.getATag("@author").getChild(0).toString() }
override string toString() { result = toStringPrefix() + getChild(0) + toStringPostfix() } override string toString() {
result = this.toStringPrefix() + this.getChild(0) + this.toStringPostfix()
}
private string toStringPrefix() { private string toStringPrefix() {
if isEolComment(this) if isEolComment(this)
@@ -47,7 +49,7 @@ class Javadoc extends JavadocParent, @javadoc {
if isEolComment(this) if isEolComment(this)
then result = "" then result = ""
else ( else (
if strictcount(getAChild()) = 1 then result = " */" else result = " ... */" if strictcount(this.getAChild()) = 1 then result = " */" else result = " ... */"
) )
} }
@@ -119,10 +121,10 @@ class ThrowsTag extends JavadocTag {
/** A Javadoc `@see` tag. */ /** A Javadoc `@see` tag. */
class SeeTag extends JavadocTag { class SeeTag extends JavadocTag {
SeeTag() { getTagName() = "@see" } SeeTag() { this.getTagName() = "@see" }
/** Gets the name of the entity referred to. */ /** Gets the name of the entity referred to. */
string getReference() { result = getChild(0).toString() } string getReference() { result = this.getChild(0).toString() }
} }
/** A Javadoc `@author` tag. */ /** A Javadoc `@author` tag. */

View File

@@ -76,11 +76,11 @@ class FreshMap extends ClassInstanceExpr {
* A call to `Map.put(key, value)`. * A call to `Map.put(key, value)`.
*/ */
class MapPutCall extends MethodAccess { class MapPutCall extends MethodAccess {
MapPutCall() { getCallee().(MapMethod).hasName("put") } MapPutCall() { this.getCallee().(MapMethod).hasName("put") }
/** Gets the key argument of this call. */ /** Gets the key argument of this call. */
Expr getKey() { result = getArgument(0) } Expr getKey() { result = this.getArgument(0) }
/** Gets the value argument of this call. */ /** Gets the value argument of this call. */
Expr getValue() { result = getArgument(1) } Expr getValue() { result = this.getArgument(1) }
} }

View File

@@ -21,7 +21,7 @@ class Member extends Element, Annotatable, Modifiable, @member {
RefType getDeclaringType() { declaresMember(result, this) } RefType getDeclaringType() { declaresMember(result, this) }
/** Gets the qualified name of this member. */ /** Gets the qualified name of this member. */
string getQualifiedName() { result = getDeclaringType().getName() + "." + getName() } string getQualifiedName() { result = this.getDeclaringType().getName() + "." + this.getName() }
/** /**
* Holds if this member has the specified name and is declared in the * Holds if this member has the specified name and is declared in the
@@ -33,9 +33,9 @@ class Member extends Element, Annotatable, Modifiable, @member {
/** Holds if this member is package protected, that is, neither public nor private nor protected. */ /** Holds if this member is package protected, that is, neither public nor private nor protected. */
predicate isPackageProtected() { predicate isPackageProtected() {
not isPrivate() and not this.isPrivate() and
not isProtected() and not this.isProtected() and
not isPublic() not this.isPublic()
} }
/** /**
@@ -78,7 +78,7 @@ class Callable extends StmtParent, Member, @callable {
*/ */
string getMethodDescriptor() { string getMethodDescriptor() {
exists(string return | return = this.getReturnType().getTypeDescriptor() | exists(string return | return = this.getReturnType().getTypeDescriptor() |
result = "(" + descriptorUpTo(this.getNumberOfParameters()) + ")" + return result = "(" + this.descriptorUpTo(this.getNumberOfParameters()) + ")" + return
) )
} }
@@ -86,19 +86,19 @@ class Callable extends StmtParent, Member, @callable {
n = 0 and result = "" n = 0 and result = ""
or or
exists(Parameter p | p = this.getParameter(n - 1) | exists(Parameter p | p = this.getParameter(n - 1) |
result = descriptorUpTo(n - 1) + p.getType().getTypeDescriptor() result = this.descriptorUpTo(n - 1) + p.getType().getTypeDescriptor()
) )
} }
/** Holds if this callable calls `target`. */ /** Holds if this callable calls `target`. */
predicate calls(Callable target) { exists(getACallSite(target)) } predicate calls(Callable target) { exists(this.getACallSite(target)) }
/** /**
* Holds if this callable calls `target` * Holds if this callable calls `target`
* using a `super(...)` constructor call. * using a `super(...)` constructor call.
*/ */
predicate callsSuperConstructor(Constructor target) { predicate callsSuperConstructor(Constructor target) {
getACallSite(target) instanceof SuperConstructorInvocationStmt this.getACallSite(target) instanceof SuperConstructorInvocationStmt
} }
/** /**
@@ -106,14 +106,14 @@ class Callable extends StmtParent, Member, @callable {
* using a `this(...)` constructor call. * using a `this(...)` constructor call.
*/ */
predicate callsThis(Constructor target) { predicate callsThis(Constructor target) {
getACallSite(target) instanceof ThisConstructorInvocationStmt this.getACallSite(target) instanceof ThisConstructorInvocationStmt
} }
/** /**
* Holds if this callable calls `target` * Holds if this callable calls `target`
* using a `super` method call. * using a `super` method call.
*/ */
predicate callsSuper(Method target) { getACallSite(target) instanceof SuperMethodAccess } predicate callsSuper(Method target) { this.getACallSite(target) instanceof SuperMethodAccess }
/** /**
* Holds if this callable calls `c` using * Holds if this callable calls `c` using
@@ -165,13 +165,13 @@ class Callable extends StmtParent, Member, @callable {
Field getAnAccessedField() { this.accesses(result) } Field getAnAccessedField() { this.accesses(result) }
/** Gets the type of a formal parameter of this callable. */ /** Gets the type of a formal parameter of this callable. */
Type getAParamType() { result = getParameterType(_) } Type getAParamType() { result = this.getParameterType(_) }
/** Holds if this callable does not have any formal parameters. */ /** Holds if this callable does not have any formal parameters. */
predicate hasNoParameters() { not exists(getAParameter()) } predicate hasNoParameters() { not exists(this.getAParameter()) }
/** Gets the number of formal parameters of this callable. */ /** Gets the number of formal parameters of this callable. */
int getNumberOfParameters() { result = count(getAParameter()) } int getNumberOfParameters() { result = count(this.getAParameter()) }
/** Gets a formal parameter of this callable. */ /** Gets a formal parameter of this callable. */
Parameter getAParameter() { result.getCallable() = this } Parameter getAParameter() { result.getCallable() = this }
@@ -205,7 +205,7 @@ class Callable extends StmtParent, Member, @callable {
*/ */
pragma[nomagic] pragma[nomagic]
string paramsString() { string paramsString() {
exists(int n | n = getNumberOfParameters() | exists(int n | n = this.getNumberOfParameters() |
n = 0 and result = "()" n = 0 and result = "()"
or or
n > 0 and result = "(" + this.paramUpTo(n - 1) + ")" n > 0 and result = "(" + this.paramUpTo(n - 1) + ")"
@@ -217,9 +217,9 @@ class Callable extends StmtParent, Member, @callable {
* from left to right, up to (and including) the `n`-th parameter. * from left to right, up to (and including) the `n`-th parameter.
*/ */
private string paramUpTo(int n) { private string paramUpTo(int n) {
n = 0 and result = getParameterType(0).toString() n = 0 and result = this.getParameterType(0).toString()
or or
n > 0 and result = paramUpTo(n - 1) + ", " + getParameterType(n) n > 0 and result = this.paramUpTo(n - 1) + ", " + this.getParameterType(n)
} }
/** /**
@@ -234,7 +234,7 @@ class Callable extends StmtParent, Member, @callable {
Exception getAnException() { exceptions(result, _, this) } Exception getAnException() { exceptions(result, _, this) }
/** Gets an exception type that occurs in the `throws` clause of this callable. */ /** Gets an exception type that occurs in the `throws` clause of this callable. */
RefType getAThrownExceptionType() { result = getAnException().getType() } RefType getAThrownExceptionType() { result = this.getAnException().getType() }
/** Gets a call site that references this callable. */ /** Gets a call site that references this callable. */
Call getAReference() { result.getCallee() = this } Call getAReference() { result.getCallee() = this }
@@ -392,7 +392,7 @@ class Method extends Callable, @method {
or or
// JLS 9.4: Every method declaration in the body of an interface without an // JLS 9.4: Every method declaration in the body of an interface without an
// access modifier is implicitly public. // access modifier is implicitly public.
getDeclaringType() instanceof Interface and this.getDeclaringType() instanceof Interface and
not this.isPrivate() not this.isPrivate()
or or
exists(FunctionalExpr func | func.asMethod() = this) exists(FunctionalExpr func | func.asMethod() = this)
@@ -413,7 +413,7 @@ class Method extends Callable, @method {
Callable.super.isStrictfp() Callable.super.isStrictfp()
or or
// JLS 8.1.1.3, JLS 9.1.1.2 // JLS 8.1.1.3, JLS 9.1.1.2
getDeclaringType().isStrictfp() this.getDeclaringType().isStrictfp()
} }
/** /**
@@ -421,8 +421,8 @@ class Method extends Callable, @method {
* nor an initializer method, and hence could be inherited. * nor an initializer method, and hence could be inherited.
*/ */
predicate isInheritable() { predicate isInheritable() {
not isPrivate() and not this.isPrivate() and
not (isStatic() and getDeclaringType() instanceof Interface) and not (this.isStatic() and this.getDeclaringType() instanceof Interface) and
not this instanceof InitializerMethod not this instanceof InitializerMethod
} }
@@ -430,13 +430,13 @@ class Method extends Callable, @method {
* Holds if this method is neither private nor static, and hence * Holds if this method is neither private nor static, and hence
* uses dynamic dispatch. * uses dynamic dispatch.
*/ */
predicate isVirtual() { not isPrivate() and not isStatic() } predicate isVirtual() { not this.isPrivate() and not this.isStatic() }
/** Holds if this method can be overridden. */ /** Holds if this method can be overridden. */
predicate isOverridable() { predicate isOverridable() {
isVirtual() and this.isVirtual() and
not isFinal() and not this.isFinal() and
not getDeclaringType().isFinal() not this.getDeclaringType().isFinal()
} }
override string getAPrimaryQlClass() { result = "Method" } override string getAPrimaryQlClass() { result = "Method" }
@@ -549,7 +549,7 @@ abstract class InitializerMethod extends Method { }
* field initializations and static initializer blocks. * field initializations and static initializer blocks.
*/ */
class StaticInitializer extends InitializerMethod { class StaticInitializer extends InitializerMethod {
StaticInitializer() { hasName("<clinit>") } StaticInitializer() { this.hasName("<clinit>") }
} }
/** /**
@@ -629,7 +629,7 @@ class Field extends Member, ExprParent, @field, Variable {
or or
// JLS 9.3: Every field declaration in the body of an interface is // JLS 9.3: Every field declaration in the body of an interface is
// implicitly public, static, and final // implicitly public, static, and final
getDeclaringType() instanceof Interface this.getDeclaringType() instanceof Interface
} }
override predicate isStatic() { override predicate isStatic() {

View File

@@ -25,7 +25,7 @@ abstract class Modifiable extends Element {
* abstract, so `isAbstract()` will hold for them even if `hasModifier("abstract")` * abstract, so `isAbstract()` will hold for them even if `hasModifier("abstract")`
* does not. * does not.
*/ */
predicate hasModifier(string m) { modifiers(getAModifier(), m) } predicate hasModifier(string m) { modifiers(this.getAModifier(), m) }
/** Holds if this element has no modifier. */ /** Holds if this element has no modifier. */
predicate hasNoModifier() { not hasModifier(this, _) } predicate hasNoModifier() { not hasModifier(this, _) }
@@ -34,31 +34,31 @@ abstract class Modifiable extends Element {
Modifier getAModifier() { this = result.getElement() } Modifier getAModifier() { this = result.getElement() }
/** Holds if this element has an `abstract` modifier or is implicitly abstract. */ /** Holds if this element has an `abstract` modifier or is implicitly abstract. */
predicate isAbstract() { hasModifier("abstract") } predicate isAbstract() { this.hasModifier("abstract") }
/** Holds if this element has a `static` modifier or is implicitly static. */ /** Holds if this element has a `static` modifier or is implicitly static. */
predicate isStatic() { hasModifier("static") } predicate isStatic() { this.hasModifier("static") }
/** Holds if this element has a `final` modifier or is implicitly final. */ /** Holds if this element has a `final` modifier or is implicitly final. */
predicate isFinal() { hasModifier("final") } predicate isFinal() { this.hasModifier("final") }
/** Holds if this element has a `public` modifier or is implicitly public. */ /** Holds if this element has a `public` modifier or is implicitly public. */
predicate isPublic() { hasModifier("public") } predicate isPublic() { this.hasModifier("public") }
/** Holds if this element has a `protected` modifier. */ /** Holds if this element has a `protected` modifier. */
predicate isProtected() { hasModifier("protected") } predicate isProtected() { this.hasModifier("protected") }
/** Holds if this element has a `private` modifier or is implicitly private. */ /** Holds if this element has a `private` modifier or is implicitly private. */
predicate isPrivate() { hasModifier("private") } predicate isPrivate() { this.hasModifier("private") }
/** Holds if this element has a `volatile` modifier. */ /** Holds if this element has a `volatile` modifier. */
predicate isVolatile() { hasModifier("volatile") } predicate isVolatile() { this.hasModifier("volatile") }
/** Holds if this element has a `synchronized` modifier. */ /** Holds if this element has a `synchronized` modifier. */
predicate isSynchronized() { hasModifier("synchronized") } predicate isSynchronized() { this.hasModifier("synchronized") }
/** Holds if this element has a `native` modifier. */ /** Holds if this element has a `native` modifier. */
predicate isNative() { hasModifier("native") } predicate isNative() { this.hasModifier("native") }
/** Holds if this element has a `default` modifier. */ /** Holds if this element has a `default` modifier. */
predicate isDefault() { this.hasModifier("default") } predicate isDefault() { this.hasModifier("default") }

View File

@@ -169,27 +169,27 @@ private class PpArrayCreationExpr extends PpAst, ArrayCreationExpr {
override string getPart(int i) { override string getPart(int i) {
i = 0 and result = "new " i = 0 and result = "new "
or or
i = 1 and result = baseType() i = 1 and result = this.baseType()
or or
i = 2 + 3 * dimensionIndex() and result = "[" i = 2 + 3 * this.dimensionIndex() and result = "["
or or
i = 4 + 3 * dimensionIndex() and result = "]" i = 4 + 3 * this.dimensionIndex() and result = "]"
or or
i = 4 + 3 * exprDims() + [1 .. nonExprDims()] and result = "[]" i = 4 + 3 * this.exprDims() + [1 .. this.nonExprDims()] and result = "[]"
} }
private string baseType() { result = this.getType().(Array).getElementType().toString() } private string baseType() { result = this.getType().(Array).getElementType().toString() }
private int dimensionIndex() { exists(this.getDimension(result)) } private int dimensionIndex() { exists(this.getDimension(result)) }
private int exprDims() { result = max(int j | j = 0 or j = 1 + dimensionIndex()) } private int exprDims() { result = max(int j | j = 0 or j = 1 + this.dimensionIndex()) }
private int nonExprDims() { result = this.getType().(Array).getDimension() - exprDims() } private int nonExprDims() { result = this.getType().(Array).getDimension() - this.exprDims() }
override PpAst getChild(int i) { override PpAst getChild(int i) {
exists(int j | result = this.getDimension(j) and i = 3 + 3 * j) exists(int j | result = this.getDimension(j) and i = 3 + 3 * j)
or or
i = 5 + 3 * exprDims() + nonExprDims() and result = this.getInit() i = 5 + 3 * this.exprDims() + this.nonExprDims() and result = this.getInit()
} }
} }
@@ -539,27 +539,27 @@ private class PpForStmt extends PpAst, ForStmt {
or or
exists(int j | j > 0 and exists(this.getInit(j)) and i = 2 + 2 * j and result = ", ") exists(int j | j > 0 and exists(this.getInit(j)) and i = 2 + 2 * j and result = ", ")
or or
i = 1 + lastInitIndex() and result = "; " i = 1 + this.lastInitIndex() and result = "; "
or or
i = 3 + lastInitIndex() and result = "; " i = 3 + this.lastInitIndex() and result = "; "
or or
exists(int j | exists(int j |
j > 0 and exists(this.getUpdate(j)) and i = 3 + lastInitIndex() + 2 * j and result = ", " j > 0 and exists(this.getUpdate(j)) and i = 3 + this.lastInitIndex() + 2 * j and result = ", "
) )
or or
i = 1 + lastUpdateIndex() and result = ")" i = 1 + this.lastUpdateIndex() and result = ")"
or or
i = 2 + lastUpdateIndex() and result = " " and this.getStmt() instanceof BlockStmt i = 2 + this.lastUpdateIndex() and result = " " and this.getStmt() instanceof BlockStmt
} }
private int lastInitIndex() { result = 3 + 2 * max(int j | exists(this.getInit(j))) } private int lastInitIndex() { result = 3 + 2 * max(int j | exists(this.getInit(j))) }
private int lastUpdateIndex() { private int lastUpdateIndex() {
result = 4 + lastInitIndex() + 2 * max(int j | exists(this.getUpdate(j))) result = 4 + this.lastInitIndex() + 2 * max(int j | exists(this.getUpdate(j)))
} }
override predicate newline(int i) { override predicate newline(int i) {
i = 2 + lastUpdateIndex() and not this.getStmt() instanceof BlockStmt i = 2 + this.lastUpdateIndex() and not this.getStmt() instanceof BlockStmt
} }
override PpAst getChild(int i) { override PpAst getChild(int i) {
@@ -567,15 +567,15 @@ private class PpForStmt extends PpAst, ForStmt {
or or
exists(int j | result = this.getInit(j) and i = 3 + 2 * j) exists(int j | result = this.getInit(j) and i = 3 + 2 * j)
or or
i = 2 + lastInitIndex() and result = this.getCondition() i = 2 + this.lastInitIndex() and result = this.getCondition()
or or
exists(int j | result = this.getUpdate(j) and i = 4 + lastInitIndex() + 2 * j) exists(int j | result = this.getUpdate(j) and i = 4 + this.lastInitIndex() + 2 * j)
or or
i = 3 + lastUpdateIndex() and result = this.getStmt() i = 3 + this.lastUpdateIndex() and result = this.getStmt()
} }
override predicate indents(int i) { override predicate indents(int i) {
i = 3 + lastUpdateIndex() and not this.getStmt() instanceof BlockStmt i = 3 + this.lastUpdateIndex() and not this.getStmt() instanceof BlockStmt
} }
} }
@@ -654,9 +654,9 @@ private class PpTryStmt extends PpAst, TryStmt {
or or
exists(int j | exists(this.getResourceExpr(j)) and i = 3 + 2 * j and result = ";") exists(int j | exists(this.getResourceExpr(j)) and i = 3 + 2 * j and result = ";")
or or
i = 2 + lastResourceIndex() and result = ") " and exists(this.getAResource()) i = 2 + this.lastResourceIndex() and result = ") " and exists(this.getAResource())
or or
i = 1 + lastCatchIndex() and result = " finally " and exists(this.getFinally()) i = 1 + this.lastCatchIndex() and result = " finally " and exists(this.getFinally())
} }
private int lastResourceIndex() { private int lastResourceIndex() {
@@ -664,17 +664,17 @@ private class PpTryStmt extends PpAst, TryStmt {
} }
private int lastCatchIndex() { private int lastCatchIndex() {
result = 4 + lastResourceIndex() + max(int j | exists(this.getCatchClause(j)) or j = 0) result = 4 + this.lastResourceIndex() + max(int j | exists(this.getCatchClause(j)) or j = 0)
} }
override PpAst getChild(int i) { override PpAst getChild(int i) {
exists(int j | i = 2 + 2 * j and result = this.getResource(j)) exists(int j | i = 2 + 2 * j and result = this.getResource(j))
or or
i = 3 + lastResourceIndex() and result = this.getBlock() i = 3 + this.lastResourceIndex() and result = this.getBlock()
or or
exists(int j | i = 4 + lastResourceIndex() + j and result = this.getCatchClause(j)) exists(int j | i = 4 + this.lastResourceIndex() + j and result = this.getCatchClause(j))
or or
i = 2 + lastCatchIndex() and result = this.getFinally() i = 2 + this.lastCatchIndex() and result = this.getFinally()
} }
} }
@@ -728,11 +728,11 @@ private class PpSwitchCase extends PpAst, SwitchCase {
or or
exists(int j | i = 2 * j and j != 0 and result = ", " and exists(this.(ConstCase).getValue(j))) exists(int j | i = 2 * j and j != 0 and result = ", " and exists(this.(ConstCase).getValue(j)))
or or
i = 1 + lastConstCaseValueIndex() and result = ":" and not this.isRule() i = 1 + this.lastConstCaseValueIndex() and result = ":" and not this.isRule()
or or
i = 1 + lastConstCaseValueIndex() and result = " -> " and this.isRule() i = 1 + this.lastConstCaseValueIndex() and result = " -> " and this.isRule()
or or
i = 3 + lastConstCaseValueIndex() and result = ";" and exists(this.getRuleExpression()) i = 3 + this.lastConstCaseValueIndex() and result = ";" and exists(this.getRuleExpression())
} }
private int lastConstCaseValueIndex() { private int lastConstCaseValueIndex() {
@@ -742,9 +742,9 @@ private class PpSwitchCase extends PpAst, SwitchCase {
override PpAst getChild(int i) { override PpAst getChild(int i) {
exists(int j | i = 1 + 2 * j and result = this.(ConstCase).getValue(j)) exists(int j | i = 1 + 2 * j and result = this.(ConstCase).getValue(j))
or or
i = 2 + lastConstCaseValueIndex() and result = this.getRuleExpression() i = 2 + this.lastConstCaseValueIndex() and result = this.getRuleExpression()
or or
i = 2 + lastConstCaseValueIndex() and result = this.getRuleStatement() i = 2 + this.lastConstCaseValueIndex() and result = this.getRuleStatement()
} }
} }

View File

@@ -151,7 +151,7 @@ class PrintAstNode extends TPrintAstNode {
/** /**
* Gets a child of this node. * Gets a child of this node.
*/ */
final PrintAstNode getAChild() { result = getChild(_) } final PrintAstNode getAChild() { result = this.getChild(_) }
/** /**
* Gets the parent of this node, if any. * Gets the parent of this node, if any.
@@ -169,7 +169,7 @@ class PrintAstNode extends TPrintAstNode {
*/ */
string getProperty(string key) { string getProperty(string key) {
key = "semmle.label" and key = "semmle.label" and
result = toString() result = this.toString()
} }
/** /**
@@ -178,7 +178,7 @@ class PrintAstNode extends TPrintAstNode {
* this. * this.
*/ */
string getChildEdgeLabel(int childIndex) { string getChildEdgeLabel(int childIndex) {
exists(getChild(childIndex)) and exists(this.getChild(childIndex)) and
result = childIndex.toString() result = childIndex.toString()
} }
} }
@@ -259,7 +259,7 @@ final class AnnotationPartNode extends ExprStmtNode {
override ElementNode getChild(int childIndex) { override ElementNode getChild(int childIndex) {
result.getElement() = result.getElement() =
rank[childIndex](Element ch, string file, int line, int column | rank[childIndex](Element ch, string file, int line, int column |
ch = getAnAnnotationChild() and locationSortKeys(ch, file, line, column) ch = this.getAnAnnotationChild() and locationSortKeys(ch, file, line, column)
| |
ch order by file, line, column ch order by file, line, column
) )
@@ -352,7 +352,7 @@ private class SingleLocalVarDeclParent extends ExprOrStmt {
LocalVariableDeclExpr getVariable() { result.getParent() = this } LocalVariableDeclExpr getVariable() { result.getParent() = this }
/** Gets the type access of the variable */ /** Gets the type access of the variable */
Expr getTypeAccess() { result = getVariable().getTypeAccess() } Expr getTypeAccess() { result = this.getVariable().getTypeAccess() }
} }
/** /**
@@ -460,7 +460,7 @@ final class ClassInterfaceNode extends ElementNode {
childIndex >= 0 and childIndex >= 0 and
result.(ElementNode).getElement() = result.(ElementNode).getElement() =
rank[childIndex](Element e, string file, int line, int column | rank[childIndex](Element e, string file, int line, int column |
e = getADeclaration() and locationSortKeys(e, file, line, column) e = this.getADeclaration() and locationSortKeys(e, file, line, column)
| |
e order by file, line, column e order by file, line, column
) )
@@ -507,7 +507,7 @@ final class CompilationUnitNode extends ElementNode {
childIndex >= 0 and childIndex >= 0 and
result.(ElementNode).getElement() = result.(ElementNode).getElement() =
rank[childIndex](Element e, string file, int line, int column | rank[childIndex](Element e, string file, int line, int column |
e = getADeclaration() and locationSortKeys(e, file, line, column) e = this.getADeclaration() and locationSortKeys(e, file, line, column)
| |
e order by file, line, column e order by file, line, column
) )

View File

@@ -55,7 +55,7 @@ abstract private class ReflectiveClassIdentifier extends Expr {
private class ReflectiveClassIdentifierLiteral extends ReflectiveClassIdentifier, TypeLiteral { private class ReflectiveClassIdentifierLiteral extends ReflectiveClassIdentifier, TypeLiteral {
override RefType getReflectivelyIdentifiedClass() { override RefType getReflectivelyIdentifiedClass() {
result = getReferencedType().(RefType).getSourceDeclaration() result = this.getReferencedType().(RefType).getSourceDeclaration()
} }
} }
@@ -65,21 +65,21 @@ private class ReflectiveClassIdentifierLiteral extends ReflectiveClassIdentifier
class ReflectiveClassIdentifierMethodAccess extends ReflectiveClassIdentifier, MethodAccess { class ReflectiveClassIdentifierMethodAccess extends ReflectiveClassIdentifier, MethodAccess {
ReflectiveClassIdentifierMethodAccess() { ReflectiveClassIdentifierMethodAccess() {
// A call to `Class.forName(...)`, from which we can infer `T` in the returned type `Class<T>`. // A call to `Class.forName(...)`, from which we can infer `T` in the returned type `Class<T>`.
getCallee().getDeclaringType() instanceof TypeClass and getCallee().hasName("forName") this.getCallee().getDeclaringType() instanceof TypeClass and this.getCallee().hasName("forName")
or or
// A call to `ClassLoader.loadClass(...)`, from which we can infer `T` in the returned type `Class<T>`. // A call to `ClassLoader.loadClass(...)`, from which we can infer `T` in the returned type `Class<T>`.
getCallee().getDeclaringType().hasQualifiedName("java.lang", "ClassLoader") and this.getCallee().getDeclaringType().hasQualifiedName("java.lang", "ClassLoader") and
getCallee().hasName("loadClass") this.getCallee().hasName("loadClass")
} }
/** /**
* If the argument to this call is a `StringLiteral`, then return that string. * If the argument to this call is a `StringLiteral`, then return that string.
*/ */
string getTypeName() { result = getArgument(0).(StringLiteral).getRepresentedString() } string getTypeName() { result = this.getArgument(0).(StringLiteral).getRepresentedString() }
override RefType getReflectivelyIdentifiedClass() { override RefType getReflectivelyIdentifiedClass() {
// We only handle cases where the class is specified as a string literal to this call. // We only handle cases where the class is specified as a string literal to this call.
result.getQualifiedName() = getTypeName() result.getQualifiedName() = this.getTypeName()
} }
} }
@@ -214,10 +214,10 @@ private predicate expectsEnclosingInstance(RefType r) {
class NewInstance extends MethodAccess { class NewInstance extends MethodAccess {
NewInstance() { NewInstance() {
( (
getCallee().getDeclaringType() instanceof TypeClass or this.getCallee().getDeclaringType() instanceof TypeClass or
getCallee().getDeclaringType() instanceof TypeConstructor this.getCallee().getDeclaringType() instanceof TypeConstructor
) and ) and
getCallee().hasName("newInstance") this.getCallee().hasName("newInstance")
} }
/** /**
@@ -225,26 +225,26 @@ class NewInstance extends MethodAccess {
* called. * called.
*/ */
Constructor getInferredConstructor() { Constructor getInferredConstructor() {
result = getInferredConstructedType().getAConstructor() and result = this.getInferredConstructedType().getAConstructor() and
if getCallee().getDeclaringType() instanceof TypeClass if this.getCallee().getDeclaringType() instanceof TypeClass
then result.getNumberOfParameters() = 0 then result.getNumberOfParameters() = 0
else else
if getNumArgument() = 1 and getArgument(0).getType() instanceof Array if this.getNumArgument() = 1 and this.getArgument(0).getType() instanceof Array
then then
// This is a var-args array argument. If array argument is initialized inline, then identify // This is a var-args array argument. If array argument is initialized inline, then identify
// the number of arguments specified in the array. // the number of arguments specified in the array.
if exists(getArgument(0).(ArrayCreationExpr).getInit()) if exists(this.getArgument(0).(ArrayCreationExpr).getInit())
then then
// Count the number of elements in the initializer, and find the matching constructors. // Count the number of elements in the initializer, and find the matching constructors.
matchConstructorArguments(result, this.matchConstructorArguments(result,
count(getArgument(0).(ArrayCreationExpr).getInit().getAnInit())) count(this.getArgument(0).(ArrayCreationExpr).getInit().getAnInit()))
else else
// Could be any of the constructors on this class. // Could be any of the constructors on this class.
any() any()
else else
// No var-args in play, just use the number of arguments to the `newInstance(..)` to determine // No var-args in play, just use the number of arguments to the `newInstance(..)` to determine
// which constructors may be called. // which constructors may be called.
matchConstructorArguments(result, getNumArgument()) this.matchConstructorArguments(result, this.getNumArgument())
} }
/** /**
@@ -273,13 +273,13 @@ class NewInstance extends MethodAccess {
not result instanceof TypeVariable and not result instanceof TypeVariable and
( (
// If this is called on a `Class<T>` instance, return the inferred type `T`. // If this is called on a `Class<T>` instance, return the inferred type `T`.
result = inferClassParameterType(getQualifier()) result = inferClassParameterType(this.getQualifier())
or or
// If this is called on a `Constructor<T>` instance, return the inferred type `T`. // If this is called on a `Constructor<T>` instance, return the inferred type `T`.
result = inferConstructorParameterType(getQualifier()) result = inferConstructorParameterType(this.getQualifier())
or or
// If the result of this is cast to a particular type, then use that type. // If the result of this is cast to a particular type, then use that type.
result = getCastInferredConstructedTypes() result = this.getCastInferredConstructedTypes()
) )
} }
@@ -313,7 +313,7 @@ class ClassMethodAccess extends MethodAccess {
// `TypeVariable`s do not have methods themselves. // `TypeVariable`s do not have methods themselves.
not result instanceof TypeVariable and not result instanceof TypeVariable and
// If this is called on a `Class<T>` instance, return the inferred type `T`. // If this is called on a `Class<T>` instance, return the inferred type `T`.
result = inferClassParameterType(getQualifier()) result = inferClassParameterType(this.getQualifier())
} }
} }
@@ -354,13 +354,13 @@ class ReflectiveMethodAccess extends ClassMethodAccess {
if this.getCallee().hasName("getDeclaredMethod") if this.getCallee().hasName("getDeclaredMethod")
then then
// The method must be declared on the type itself. // The method must be declared on the type itself.
result.getDeclaringType() = getInferredClassType() result.getDeclaringType() = this.getInferredClassType()
else else
// The method may be declared on an inferred type or a super-type. // The method may be declared on an inferred type or a super-type.
getInferredClassType().inherits(result) this.getInferredClassType().inherits(result)
) and ) and
// Only consider instances where the method name is provided as a `StringLiteral`. // Only consider instances where the method name is provided as a `StringLiteral`.
result.hasName(getArgument(0).(StringLiteral).getRepresentedString()) result.hasName(this.getArgument(0).(StringLiteral).getRepresentedString())
} }
} }
@@ -373,7 +373,9 @@ class ReflectiveAnnotationAccess extends ClassMethodAccess {
/** /**
* Gets a possible annotation type for this reflective annotation access. * Gets a possible annotation type for this reflective annotation access.
*/ */
AnnotationType getAPossibleAnnotationType() { result = inferClassParameterType(getArgument(0)) } AnnotationType getAPossibleAnnotationType() {
result = inferClassParameterType(this.getArgument(0))
}
} }
/** /**
@@ -391,13 +393,13 @@ class ReflectiveFieldAccess extends ClassMethodAccess {
if this.getCallee().hasName("getDeclaredField") if this.getCallee().hasName("getDeclaredField")
then then
// Declared fields must be on the type itself. // Declared fields must be on the type itself.
result.getDeclaringType() = getInferredClassType() result.getDeclaringType() = this.getInferredClassType()
else ( else (
// This field must be public, and be inherited by one of the inferred class types. // This field must be public, and be inherited by one of the inferred class types.
result.isPublic() and result.isPublic() and
getInferredClassType().inherits(result) this.getInferredClassType().inherits(result)
) )
) and ) and
result.hasName(getArgument(0).(StringLiteral).getRepresentedString()) result.hasName(this.getArgument(0).(StringLiteral).getRepresentedString())
} }
} }

View File

@@ -71,7 +71,7 @@ class BlockStmt extends Stmt, @block {
int getNumStmt() { result = count(this.getAStmt()) } int getNumStmt() { result = count(this.getAStmt()) }
/** Gets the last statement in this block. */ /** Gets the last statement in this block. */
Stmt getLastStmt() { result = getStmt(getNumStmt() - 1) } Stmt getLastStmt() { result = this.getStmt(this.getNumStmt() - 1) }
override string pp() { result = "{ ... }" } override string pp() { result = "{ ... }" }
@@ -93,7 +93,7 @@ class SingletonBlock extends BlockStmt {
SingletonBlock() { this.getNumStmt() = 1 } SingletonBlock() { this.getNumStmt() = 1 }
/** Gets the single statement in this block. */ /** Gets the single statement in this block. */
Stmt getStmt() { result = getStmt(0) } Stmt getStmt() { result = this.getStmt(0) }
} }
/** /**
@@ -125,7 +125,7 @@ class IfStmt extends ConditionalStmt, @ifstmt {
* Gets the statement that is executed whenever the condition * Gets the statement that is executed whenever the condition
* of this branch statement evaluates to `true`. * of this branch statement evaluates to `true`.
*/ */
deprecated override Stmt getTrueSuccessor() { result = getThen() } deprecated override Stmt getTrueSuccessor() { result = this.getThen() }
/** Gets the `else` branch of this `if` statement. */ /** Gets the `else` branch of this `if` statement. */
Stmt getElse() { result.isNthChildOf(this, 2) } Stmt getElse() { result.isNthChildOf(this, 2) }
@@ -155,7 +155,7 @@ class ForStmt extends ConditionalStmt, @forstmt {
/** Gets the initializer expression of the loop at the specified (zero-based) position. */ /** Gets the initializer expression of the loop at the specified (zero-based) position. */
Expr getInit(int index) { Expr getInit(int index) {
result = getAnInit() and result = this.getAnInit() and
index = -1 - result.getIndex() index = -1 - result.getIndex()
} }
@@ -167,7 +167,7 @@ class ForStmt extends ConditionalStmt, @forstmt {
/** Gets the update expression of this loop at the specified (zero-based) position. */ /** Gets the update expression of this loop at the specified (zero-based) position. */
Expr getUpdate(int index) { Expr getUpdate(int index) {
result = getAnUpdate() and result = this.getAnUpdate() and
index = result.getIndex() - 3 index = result.getIndex() - 3
} }
@@ -178,7 +178,7 @@ class ForStmt extends ConditionalStmt, @forstmt {
* Gets the statement that is executed whenever the condition * Gets the statement that is executed whenever the condition
* of this branch statement evaluates to true. * of this branch statement evaluates to true.
*/ */
deprecated override Stmt getTrueSuccessor() { result = getStmt() } deprecated override Stmt getTrueSuccessor() { result = this.getStmt() }
/** /**
* Gets a variable that is used as an iteration variable: it is defined, * Gets a variable that is used as an iteration variable: it is defined,
@@ -193,12 +193,12 @@ class ForStmt extends ConditionalStmt, @forstmt {
*/ */
Variable getAnIterationVariable() { Variable getAnIterationVariable() {
// Check that the variable is assigned to, incremented or decremented in the update expression, and... // Check that the variable is assigned to, incremented or decremented in the update expression, and...
exists(Expr update | update = getAnUpdate().getAChildExpr*() | exists(Expr update | update = this.getAnUpdate().getAChildExpr*() |
update.(UnaryAssignExpr).getExpr() = result.getAnAccess() or update.(UnaryAssignExpr).getExpr() = result.getAnAccess() or
update = result.getAnAssignedValue() update = result.getAnAssignedValue()
) and ) and
// ...that it is checked or used in the condition. // ...that it is checked or used in the condition.
getCondition().getAChildExpr*() = result.getAnAccess() this.getCondition().getAChildExpr*() = result.getAnAccess()
} }
override string pp() { result = "for (...;...;...) " + this.getStmt().pp() } override string pp() { result = "for (...;...;...) " + this.getStmt().pp() }
@@ -242,7 +242,7 @@ class WhileStmt extends ConditionalStmt, @whilestmt {
* Gets the statement that is executed whenever the condition * Gets the statement that is executed whenever the condition
* of this branch statement evaluates to true. * of this branch statement evaluates to true.
*/ */
deprecated override Stmt getTrueSuccessor() { result = getStmt() } deprecated override Stmt getTrueSuccessor() { result = this.getStmt() }
override string pp() { result = "while (...) " + this.getStmt().pp() } override string pp() { result = "while (...) " + this.getStmt().pp() }
@@ -265,7 +265,7 @@ class DoStmt extends ConditionalStmt, @dostmt {
* Gets the statement that is executed whenever the condition * Gets the statement that is executed whenever the condition
* of this branch statement evaluates to `true`. * of this branch statement evaluates to `true`.
*/ */
deprecated override Stmt getTrueSuccessor() { result = getStmt() } deprecated override Stmt getTrueSuccessor() { result = this.getStmt() }
override string pp() { result = "do " + this.getStmt().pp() + " while (...)" } override string pp() { result = "do " + this.getStmt().pp() + " while (...)" }
@@ -343,17 +343,17 @@ class TryStmt extends Stmt, @trystmt {
} }
/** Gets a resource in this `try` statement, if any. */ /** Gets a resource in this `try` statement, if any. */
ExprParent getAResource() { result = getAResourceDecl() or result = getAResourceExpr() } ExprParent getAResource() { result = this.getAResourceDecl() or result = this.getAResourceExpr() }
/** Gets the resource at the specified position in this `try` statement. */ /** Gets the resource at the specified position in this `try` statement. */
ExprParent getResource(int index) { ExprParent getResource(int index) {
result = getResourceDecl(index) or result = getResourceExpr(index) result = this.getResourceDecl(index) or result = this.getResourceExpr(index)
} }
/** Gets a resource variable, if any, either from a resource variable declaration or resource expression. */ /** Gets a resource variable, if any, either from a resource variable declaration or resource expression. */
Variable getAResourceVariable() { Variable getAResourceVariable() {
result = getAResourceDecl().getAVariable().getVariable() or result = this.getAResourceDecl().getAVariable().getVariable() or
result = getAResourceExpr().getVariable() result = this.getAResourceExpr().getVariable()
} }
override string pp() { result = "try " + this.getBlock().pp() + " catch (...)" } override string pp() { result = "try " + this.getBlock().pp() + " catch (...)" }
@@ -381,7 +381,7 @@ class CatchClause extends Stmt, @catchclause {
/** Gets a type caught by this `catch` clause. */ /** Gets a type caught by this `catch` clause. */
RefType getACaughtType() { RefType getACaughtType() {
exists(Expr ta | ta = getVariable().getTypeAccess() | exists(Expr ta | ta = this.getVariable().getTypeAccess() |
result = ta.(TypeAccess).getType() or result = ta.(TypeAccess).getType() or
result = ta.(UnionTypeAccess).getAnAlternative().getType() result = ta.(UnionTypeAccess).getAnAlternative().getType()
) )
@@ -411,7 +411,7 @@ class SwitchStmt extends Stmt, @switchstmt {
* Gets a case of this `switch` statement, * Gets a case of this `switch` statement,
* which may be either a normal `case` or a `default`. * which may be either a normal `case` or a `default`.
*/ */
SwitchCase getACase() { result = getAConstCase() or result = getDefaultCase() } SwitchCase getACase() { result = this.getAConstCase() or result = this.getDefaultCase() }
/** Gets a (non-default) `case` of this `switch` statement. */ /** Gets a (non-default) `case` of this `switch` statement. */
ConstCase getAConstCase() { result.getParent() = this } ConstCase getAConstCase() { result.getParent() = this }
@@ -550,7 +550,7 @@ class ThrowStmt extends Stmt, @throwstmt {
override string getHalsteadID() { result = "ThrowStmt" } override string getHalsteadID() { result = "ThrowStmt" }
/** Gets the type of the expression thrown by this `throw` statement. */ /** Gets the type of the expression thrown by this `throw` statement. */
RefType getThrownExceptionType() { result = getExpr().getType() } RefType getThrownExceptionType() { result = this.getExpr().getType() }
/** /**
* Gets the `catch` clause that catches the exception * Gets the `catch` clause that catches the exception
@@ -559,14 +559,14 @@ class ThrowStmt extends Stmt, @throwstmt {
* provided such a `catch` exists. * provided such a `catch` exists.
*/ */
CatchClause getLexicalCatchIfAny() { CatchClause getLexicalCatchIfAny() {
exists(TryStmt try | try = findEnclosing() and result = catchClauseForThis(try)) exists(TryStmt try | try = this.findEnclosing() and result = this.catchClauseForThis(try))
} }
private Stmt findEnclosing() { private Stmt findEnclosing() {
result = getEnclosingStmt() result = this.getEnclosingStmt()
or or
exists(Stmt mid | exists(Stmt mid |
mid = findEnclosing() and mid = this.findEnclosing() and
not exists(this.catchClauseForThis(mid.(TryStmt))) and not exists(this.catchClauseForThis(mid.(TryStmt))) and
result = mid.getEnclosingStmt() result = mid.getEnclosingStmt()
) )
@@ -575,7 +575,7 @@ class ThrowStmt extends Stmt, @throwstmt {
private CatchClause catchClauseForThis(TryStmt try) { private CatchClause catchClauseForThis(TryStmt try) {
result = try.getACatchClause() and result = try.getACatchClause() and
result.getEnclosingCallable() = this.getEnclosingCallable() and result.getEnclosingCallable() = this.getEnclosingCallable() and
getExpr().getType().(RefType).hasSupertype*(result.getVariable().getType().(RefType)) and this.getExpr().getType().(RefType).hasSupertype*(result.getVariable().getType().(RefType)) and
not this.getEnclosingStmt+() = result not this.getEnclosingStmt+() = result
} }
@@ -599,7 +599,7 @@ class JumpStmt extends Stmt {
namestrings(result.getLabel(), _, this) namestrings(result.getLabel(), _, this)
} }
private Stmt getLabelTarget() { result = getTargetLabel().getStmt() } private Stmt getLabelTarget() { result = this.getTargetLabel().getStmt() }
private Stmt getAPotentialTarget() { private Stmt getAPotentialTarget() {
this.getEnclosingStmt+() = result and this.getEnclosingStmt+() = result and
@@ -613,20 +613,20 @@ class JumpStmt extends Stmt {
private SwitchExpr getSwitchExprTarget() { result = this.(YieldStmt).getParent+() } private SwitchExpr getSwitchExprTarget() { result = this.(YieldStmt).getParent+() }
private StmtParent getEnclosingTarget() { private StmtParent getEnclosingTarget() {
result = getSwitchExprTarget() result = this.getSwitchExprTarget()
or or
not exists(getSwitchExprTarget()) and not exists(this.getSwitchExprTarget()) and
result = getAPotentialTarget() and result = this.getAPotentialTarget() and
not exists(Stmt other | other = getAPotentialTarget() | other.getEnclosingStmt+() = result) not exists(Stmt other | other = this.getAPotentialTarget() | other.getEnclosingStmt+() = result)
} }
/** /**
* Gets the statement or `switch` expression that this `break`, `yield` or `continue` jumps to. * Gets the statement or `switch` expression that this `break`, `yield` or `continue` jumps to.
*/ */
StmtParent getTarget() { StmtParent getTarget() {
result = getLabelTarget() result = this.getLabelTarget()
or or
not exists(getLabelTarget()) and result = getEnclosingTarget() not exists(this.getLabelTarget()) and result = this.getEnclosingTarget()
} }
} }
@@ -714,9 +714,9 @@ class ExprStmt extends Stmt, @exprstmt {
/** Holds if this statement represents a field declaration with an initializer. */ /** Holds if this statement represents a field declaration with an initializer. */
predicate isFieldDecl() { predicate isFieldDecl() {
getEnclosingCallable() instanceof InitializerMethod and this.getEnclosingCallable() instanceof InitializerMethod and
exists(FieldDeclaration fd, Location fdl, Location sl | exists(FieldDeclaration fd, Location fdl, Location sl |
fdl = fd.getLocation() and sl = getLocation() fdl = fd.getLocation() and sl = this.getLocation()
| |
fdl.getFile() = sl.getFile() and fdl.getFile() = sl.getFile() and
fdl.getStartLine() = sl.getStartLine() and fdl.getStartLine() = sl.getStartLine() and
@@ -775,7 +775,7 @@ class LocalVariableDeclStmt extends Stmt, @localvariabledeclstmt {
} }
/** Gets an index of a variable declared in this local variable declaration statement. */ /** Gets an index of a variable declared in this local variable declaration statement. */
int getAVariableIndex() { exists(getVariable(result)) } int getAVariableIndex() { exists(this.getVariable(result)) }
override string pp() { result = "var ...;" } override string pp() { result = "var ...;" }

View File

@@ -152,15 +152,15 @@ class FormattingCall extends Call {
private Expr getLastArg() { private Expr getLastArg() {
exists(Expr last | last = this.getArgument(this.getNumArgument() - 1) | exists(Expr last | last = this.getArgument(this.getNumArgument() - 1) |
if this.hasExplicitVarargsArray() if this.hasExplicitVarargsArray()
then result = last.(ArrayCreationExpr).getInit().getInit(getVarargsCount() - 1) then result = last.(ArrayCreationExpr).getInit().getInit(this.getVarargsCount() - 1)
else result = last else result = last
) )
} }
/** Holds if this uses the "logger ({})" format syntax and the last argument is a `Throwable`. */ /** Holds if this uses the "logger ({})" format syntax and the last argument is a `Throwable`. */
predicate hasTrailingThrowableArgument() { predicate hasTrailingThrowableArgument() {
getSyntax() = TFmtLogger() and this.getSyntax() = TFmtLogger() and
getLastArg().getType().(RefType).getASourceSupertype*() instanceof TypeThrowable this.getLastArg().getType().(RefType).getASourceSupertype*() instanceof TypeThrowable
} }
/** Gets the argument to this call in the position of the format string */ /** Gets the argument to this call in the position of the format string */
@@ -171,7 +171,7 @@ class FormattingCall extends Call {
exists(int i | exists(int i |
result = this.getArgument(i) and result = this.getArgument(i) and
i > this.getFormatStringIndex() and i > this.getFormatStringIndex() and
not hasExplicitVarargsArray() not this.hasExplicitVarargsArray()
) )
} }
@@ -433,15 +433,15 @@ private class PrintfFormatString extends FormatString {
override int getMaxFmtSpecIndex() { override int getMaxFmtSpecIndex() {
result = result =
max(int ix | max(int ix |
ix = fmtSpecRefersToSpecificIndex(_) or ix = this.fmtSpecRefersToSpecificIndex(_) or
ix = count(int i | fmtSpecRefersToSequentialIndex(i)) ix = count(int i | this.fmtSpecRefersToSequentialIndex(i))
) )
} }
override int getASkippedFmtSpecIndex() { override int getASkippedFmtSpecIndex() {
result in [1 .. getMaxFmtSpecIndex()] and result in [1 .. this.getMaxFmtSpecIndex()] and
result > count(int i | fmtSpecRefersToSequentialIndex(i)) and result > count(int i | this.fmtSpecRefersToSequentialIndex(i)) and
not result = fmtSpecRefersToSpecificIndex(_) not result = this.fmtSpecRefersToSpecificIndex(_)
} }
private int getFmtSpecRank(int specOffset) { private int getFmtSpecRank(int specOffset) {
@@ -449,14 +449,14 @@ private class PrintfFormatString extends FormatString {
} }
override int getAnArgUsageOffset(int argNo) { override int getAnArgUsageOffset(int argNo) {
argNo = fmtSpecRefersToSpecificIndex(result) argNo = this.fmtSpecRefersToSpecificIndex(result)
or or
result = rank[argNo](int i | fmtSpecRefersToSequentialIndex(i)) result = rank[argNo](int i | this.fmtSpecRefersToSequentialIndex(i))
or or
fmtSpecRefersToPrevious(result) and this.fmtSpecRefersToPrevious(result) and
exists(int previousOffset | exists(int previousOffset |
getFmtSpecRank(previousOffset) = getFmtSpecRank(result) - 1 and this.getFmtSpecRank(previousOffset) = this.getFmtSpecRank(result) - 1 and
previousOffset = getAnArgUsageOffset(argNo) previousOffset = this.getAnArgUsageOffset(argNo)
) )
} }
} }
@@ -479,10 +479,12 @@ private class LoggerFormatString extends FormatString {
private predicate fmtPlaceholder(int i) { private predicate fmtPlaceholder(int i) {
this.charAt(i) = "{" and this.charAt(i) = "{" and
this.charAt(i + 1) = "}" and this.charAt(i + 1) = "}" and
not true = isUnescapedBackslash(i - 1) not true = this.isUnescapedBackslash(i - 1)
} }
override int getMaxFmtSpecIndex() { result = count(int i | fmtPlaceholder(i)) } override int getMaxFmtSpecIndex() { result = count(int i | this.fmtPlaceholder(i)) }
override int getAnArgUsageOffset(int argNo) { result = rank[argNo](int i | fmtPlaceholder(i)) } override int getAnArgUsageOffset(int argNo) {
result = rank[argNo](int i | this.fmtPlaceholder(i))
}
} }

View File

@@ -379,7 +379,7 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
} }
/** Holds if this type declares any members. */ /** Holds if this type declares any members. */
predicate hasMember() { exists(getAMember()) } predicate hasMember() { exists(this.getAMember()) }
/** Gets a member declared in this type. */ /** Gets a member declared in this type. */
Member getAMember() { this = result.getDeclaringType() } Member getAMember() { this = result.getDeclaringType() }
@@ -545,8 +545,10 @@ class RefType extends Type, Annotatable, Modifiable, @reftype {
* `java.lang.Thread$State`. * `java.lang.Thread$State`.
*/ */
string getQualifiedName() { string getQualifiedName() {
exists(string pkgName | pkgName = getPackage().getName() | exists(string pkgName | pkgName = this.getPackage().getName() |
if pkgName = "" then result = nestedName() else result = pkgName + "." + nestedName() if pkgName = ""
then result = this.nestedName()
else result = pkgName + "." + this.nestedName()
) )
} }
@@ -656,7 +658,7 @@ class IntersectionType extends RefType, @class {
/** Gets a textual representation of this type that includes all the intersected types. */ /** Gets a textual representation of this type that includes all the intersected types. */
string getLongName() { string getLongName() {
result = superType().toString() + concat(" & " + superInterface().toString()) result = this.superType().toString() + concat(" & " + this.superInterface().toString())
} }
/** Gets the first bound of this intersection type. */ /** Gets the first bound of this intersection type. */
@@ -690,7 +692,8 @@ class AnonymousClass extends NestedClass {
override string getTypeDescriptor() { override string getTypeDescriptor() {
exists(RefType parent | parent = this.getEnclosingType() | exists(RefType parent | parent = this.getEnclosingType() |
exists(int num | exists(int num |
num = 1 + count(AnonymousClass other | other.rankInParent(parent) < rankInParent(parent)) num =
1 + count(AnonymousClass other | other.rankInParent(parent) < this.rankInParent(parent))
| |
exists(string parentWithSemi | parentWithSemi = parent.getTypeDescriptor() | exists(string parentWithSemi | parentWithSemi = parent.getTypeDescriptor() |
result = parentWithSemi.prefix(parentWithSemi.length() - 1) + "$" + num + ";" result = parentWithSemi.prefix(parentWithSemi.length() - 1) + "$" + num + ";"
@@ -760,8 +763,8 @@ class NestedType extends RefType {
/** Gets the nesting depth of this nested type. Top-level types have nesting depth 0. */ /** Gets the nesting depth of this nested type. Top-level types have nesting depth 0. */
int getNestingDepth() { int getNestingDepth() {
if getEnclosingType() instanceof NestedType if this.getEnclosingType() instanceof NestedType
then result = getEnclosingType().(NestedType).getNestingDepth() + 1 then result = this.getEnclosingType().(NestedType).getNestingDepth() + 1
else result = 1 else result = 1
} }
@@ -776,7 +779,7 @@ class NestedType extends RefType {
super.isStrictfp() super.isStrictfp()
or or
// JLS 8.1.1.3, JLS 9.1.1.2 // JLS 8.1.1.3, JLS 9.1.1.2
getEnclosingType().isStrictfp() this.getEnclosingType().isStrictfp()
} }
override predicate isStatic() { override predicate isStatic() {
@@ -860,9 +863,9 @@ class ClassOrInterface extends RefType, @classorinterface {
/** Holds if this class or interface is package protected, that is, neither public nor private nor protected. */ /** Holds if this class or interface is package protected, that is, neither public nor private nor protected. */
predicate isPackageProtected() { predicate isPackageProtected() {
not isPrivate() and not this.isPrivate() and
not isProtected() and not this.isProtected() and
not isPublic() not this.isPublic()
} }
} }
@@ -948,12 +951,12 @@ class PrimitiveType extends Type, @primitive {
* require an explicit cast. * require an explicit cast.
*/ */
Literal getADefaultValue() { Literal getADefaultValue() {
getName() = "boolean" and result.getLiteral() = "false" this.getName() = "boolean" and result.getLiteral() = "false"
or or
getName() = "char" and this.getName() = "char" and
(result.getLiteral() = "'\\0'" or result.getLiteral() = "'\\u0000'") (result.getLiteral() = "'\\0'" or result.getLiteral() = "'\\u0000'")
or or
getName().regexpMatch("(float|double|int|short|byte|long)") and this.getName().regexpMatch("(float|double|int|short|byte|long)") and
result.getLiteral().regexpMatch("0(\\.0)?+[lLfFdD]?+") result.getLiteral().regexpMatch("0(\\.0)?+[lLfFdD]?+")
} }
@@ -1047,7 +1050,7 @@ class EnumType extends Class {
override predicate isFinal() { override predicate isFinal() {
// JLS 8.9: An enum declaration is implicitly `final` unless it contains // JLS 8.9: An enum declaration is implicitly `final` unless it contains
// at least one enum constant that has a class body. // at least one enum constant that has a class body.
not getAnEnumConstant().getAnAssignedValue().getType() instanceof AnonymousClass not this.getAnEnumConstant().getAnAssignedValue().getType() instanceof AnonymousClass
} }
} }

View File

@@ -115,7 +115,7 @@ class JUnitJupiterTestMethod extends Method {
* A JUnit `@Ignore` annotation. * A JUnit `@Ignore` annotation.
*/ */
class JUnitIgnoreAnnotation extends Annotation { class JUnitIgnoreAnnotation extends Annotation {
JUnitIgnoreAnnotation() { getType().hasQualifiedName("org.junit", "Ignore") } JUnitIgnoreAnnotation() { this.getType().hasQualifiedName("org.junit", "Ignore") }
} }
/** /**
@@ -124,7 +124,7 @@ class JUnitIgnoreAnnotation extends Annotation {
*/ */
class JUnitIgnoredMethod extends Method { class JUnitIgnoredMethod extends Method {
JUnitIgnoredMethod() { JUnitIgnoredMethod() {
getAnAnnotation() instanceof JUnitIgnoreAnnotation this.getAnAnnotation() instanceof JUnitIgnoreAnnotation
or or
exists(Class c | c = this.getDeclaringType() | exists(Class c | c = this.getDeclaringType() |
c.getAnAnnotation() instanceof JUnitIgnoreAnnotation c.getAnAnnotation() instanceof JUnitIgnoreAnnotation
@@ -136,14 +136,14 @@ class JUnitIgnoredMethod extends Method {
* An annotation in TestNG. * An annotation in TestNG.
*/ */
class TestNGAnnotation extends Annotation { class TestNGAnnotation extends Annotation {
TestNGAnnotation() { getType().getPackage().hasName("org.testng.annotations") } TestNGAnnotation() { this.getType().getPackage().hasName("org.testng.annotations") }
} }
/** /**
* An annotation of type `org.test.ng.annotations.Test`. * An annotation of type `org.test.ng.annotations.Test`.
*/ */
class TestNGTestAnnotation extends TestNGAnnotation { class TestNGTestAnnotation extends TestNGAnnotation {
TestNGTestAnnotation() { getType().hasName("Test") } TestNGTestAnnotation() { this.getType().hasName("Test") }
} }
/** /**
@@ -158,13 +158,13 @@ class TestNGTestMethod extends Method {
*/ */
TestNGDataProviderMethod getADataProvider() { TestNGDataProviderMethod getADataProvider() {
exists(TestNGTestAnnotation testAnnotation | exists(TestNGTestAnnotation testAnnotation |
testAnnotation = getAnAnnotation() and testAnnotation = this.getAnAnnotation() and
// The data provider must have the same name as the referenced data provider // The data provider must have the same name as the referenced data provider
result.getDataProviderName() = result.getDataProviderName() =
testAnnotation.getValue("dataProvider").(StringLiteral).getRepresentedString() testAnnotation.getValue("dataProvider").(StringLiteral).getRepresentedString()
| |
// Either the data provider should be on the current class, or a supertype // Either the data provider should be on the current class, or a supertype
getDeclaringType().getAnAncestor() = result.getDeclaringType() this.getDeclaringType().getAnAncestor() = result.getDeclaringType()
or or
// Or the data provider class should be declared // Or the data provider class should be declared
result.getDeclaringType() = result.getDeclaringType() =
@@ -190,14 +190,14 @@ class TestMethod extends Method {
* A TestNG annotation used to mark a method that runs "before". * A TestNG annotation used to mark a method that runs "before".
*/ */
class TestNGBeforeAnnotation extends TestNGAnnotation { class TestNGBeforeAnnotation extends TestNGAnnotation {
TestNGBeforeAnnotation() { getType().getName().matches("Before%") } TestNGBeforeAnnotation() { this.getType().getName().matches("Before%") }
} }
/** /**
* A TestNG annotation used to mark a method that runs "after". * A TestNG annotation used to mark a method that runs "after".
*/ */
class TestNGAfterAnnotation extends TestNGAnnotation { class TestNGAfterAnnotation extends TestNGAnnotation {
TestNGAfterAnnotation() { getType().getName().matches("After%") } TestNGAfterAnnotation() { this.getType().getName().matches("After%") }
} }
/** /**
@@ -205,7 +205,7 @@ class TestNGAfterAnnotation extends TestNGAnnotation {
* them as data provider methods for TestNG. * them as data provider methods for TestNG.
*/ */
class TestNGDataProviderAnnotation extends TestNGAnnotation { class TestNGDataProviderAnnotation extends TestNGAnnotation {
TestNGDataProviderAnnotation() { getType().hasName("DataProvider") } TestNGDataProviderAnnotation() { this.getType().hasName("DataProvider") }
} }
/** /**
@@ -213,7 +213,7 @@ class TestNGDataProviderAnnotation extends TestNGAnnotation {
* them as factory methods for TestNG. * them as factory methods for TestNG.
*/ */
class TestNGFactoryAnnotation extends TestNGAnnotation { class TestNGFactoryAnnotation extends TestNGAnnotation {
TestNGFactoryAnnotation() { getType().hasName("Factory") } TestNGFactoryAnnotation() { this.getType().hasName("Factory") }
} }
/** /**
@@ -221,13 +221,13 @@ class TestNGFactoryAnnotation extends TestNGAnnotation {
* which listeners apply to them. * which listeners apply to them.
*/ */
class TestNGListenersAnnotation extends TestNGAnnotation { class TestNGListenersAnnotation extends TestNGAnnotation {
TestNGListenersAnnotation() { getType().hasName("Listeners") } TestNGListenersAnnotation() { this.getType().hasName("Listeners") }
/** /**
* Gets a listener defined in this annotation. * Gets a listener defined in this annotation.
*/ */
TestNGListenerImpl getAListener() { TestNGListenerImpl getAListener() {
result = getAValue("value").(TypeLiteral).getReferencedType() result = this.getAValue("value").(TypeLiteral).getReferencedType()
} }
} }
@@ -235,7 +235,7 @@ class TestNGListenersAnnotation extends TestNGAnnotation {
* A concrete implementation class of one or more of the TestNG listener interfaces. * A concrete implementation class of one or more of the TestNG listener interfaces.
*/ */
class TestNGListenerImpl extends Class { class TestNGListenerImpl extends Class {
TestNGListenerImpl() { getAnAncestor().hasQualifiedName("org.testng", "ITestNGListener") } TestNGListenerImpl() { this.getAnAncestor().hasQualifiedName("org.testng", "ITestNGListener") }
} }
/** /**
@@ -246,14 +246,14 @@ class TestNGListenerImpl extends Class {
* an instance of a particular value when running a test method. * an instance of a particular value when running a test method.
*/ */
class TestNGDataProviderMethod extends Method { class TestNGDataProviderMethod extends Method {
TestNGDataProviderMethod() { getAnAnnotation() instanceof TestNGDataProviderAnnotation } TestNGDataProviderMethod() { this.getAnAnnotation() instanceof TestNGDataProviderAnnotation }
/** /**
* Gets the name associated with this data provider. * Gets the name associated with this data provider.
*/ */
string getDataProviderName() { string getDataProviderName() {
result = result =
getAnAnnotation() this.getAnAnnotation()
.(TestNGDataProviderAnnotation) .(TestNGDataProviderAnnotation)
.getValue("name") .getValue("name")
.(StringLiteral) .(StringLiteral)
@@ -268,7 +268,7 @@ class TestNGDataProviderMethod extends Method {
* This factory callable is used to generate instances of parameterized test classes. * This factory callable is used to generate instances of parameterized test classes.
*/ */
class TestNGFactoryCallable extends Callable { class TestNGFactoryCallable extends Callable {
TestNGFactoryCallable() { getAnAnnotation() instanceof TestNGFactoryAnnotation } TestNGFactoryCallable() { this.getAnAnnotation() instanceof TestNGFactoryAnnotation }
} }
/** /**
@@ -276,7 +276,7 @@ class TestNGFactoryCallable extends Callable {
*/ */
class ParameterizedJUnitTest extends Class { class ParameterizedJUnitTest extends Class {
ParameterizedJUnitTest() { ParameterizedJUnitTest() {
getAnAnnotation() this.getAnAnnotation()
.(RunWithAnnotation) .(RunWithAnnotation)
.getRunner() .getRunner()
.(Class) .(Class)
@@ -289,7 +289,7 @@ class ParameterizedJUnitTest extends Class {
*/ */
class JUnitCategoryAnnotation extends Annotation { class JUnitCategoryAnnotation extends Annotation {
JUnitCategoryAnnotation() { JUnitCategoryAnnotation() {
getType().hasQualifiedName("org.junit.experimental.categories", "Category") this.getType().hasQualifiedName("org.junit.experimental.categories", "Category")
} }
/** /**
@@ -297,7 +297,7 @@ class JUnitCategoryAnnotation extends Annotation {
*/ */
Type getACategory() { Type getACategory() {
exists(TypeLiteral literal, Expr value | exists(TypeLiteral literal, Expr value |
value = getValue("value") and value = this.getValue("value") and
( (
literal = value or literal = value or
literal = value.(ArrayCreationExpr).getInit().getAnInit() literal = value.(ArrayCreationExpr).getInit().getAnInit()
@@ -313,7 +313,7 @@ class JUnitCategoryAnnotation extends Annotation {
*/ */
class JUnitTheoryTest extends Class { class JUnitTheoryTest extends Class {
JUnitTheoryTest() { JUnitTheoryTest() {
getAnAnnotation() this.getAnAnnotation()
.(RunWithAnnotation) .(RunWithAnnotation)
.getRunner() .getRunner()
.(Class) .(Class)

View File

@@ -47,12 +47,12 @@ class LocalVariableDecl extends @localvar, LocalScopeVariable {
override Callable getCallable() { result = this.getParent().getEnclosingCallable() } override Callable getCallable() { result = this.getParent().getEnclosingCallable() }
/** Gets the callable in which this declaration occurs. */ /** Gets the callable in which this declaration occurs. */
Callable getEnclosingCallable() { result = getCallable() } Callable getEnclosingCallable() { result = this.getCallable() }
override string toString() { result = this.getType().getName() + " " + this.getName() } override string toString() { result = this.getType().getName() + " " + this.getName() }
/** Gets the initializer expression of this local variable declaration. */ /** Gets the initializer expression of this local variable declaration. */
override Expr getInitializer() { result = getDeclExpr().getInit() } override Expr getInitializer() { result = this.getDeclExpr().getInit() }
override string getAPrimaryQlClass() { result = "LocalVariableDecl" } override string getAPrimaryQlClass() { result = "LocalVariableDecl" }
} }
@@ -63,7 +63,7 @@ class Parameter extends Element, @param, LocalScopeVariable {
override Type getType() { params(this, result, _, _, _) } override Type getType() { params(this, result, _, _, _) }
/** Holds if the parameter is never assigned a value in the body of the callable. */ /** Holds if the parameter is never assigned a value in the body of the callable. */
predicate isEffectivelyFinal() { not exists(getAnAssignedValue()) } predicate isEffectivelyFinal() { not exists(this.getAnAssignedValue()) }
/** Gets the (zero-based) index of this formal parameter. */ /** Gets the (zero-based) index of this formal parameter. */
int getPosition() { params(this, _, result, _, _) } int getPosition() { params(this, _, result, _, _) }
@@ -87,8 +87,8 @@ class Parameter extends Element, @param, LocalScopeVariable {
* Varargs parameters will have no results for this method. * Varargs parameters will have no results for this method.
*/ */
Expr getAnArgument() { Expr getAnArgument() {
not isVarargs() and not this.isVarargs() and
result = getACallArgument(getPosition()) result = this.getACallArgument(this.getPosition())
} }
pragma[noinline] pragma[noinline]

View File

@@ -2,9 +2,9 @@ import java
/** A subclass of `PrimitiveType` with width-based ordering methods. */ /** A subclass of `PrimitiveType` with width-based ordering methods. */
class OrdPrimitiveType extends PrimitiveType { class OrdPrimitiveType extends PrimitiveType {
predicate widerThan(OrdPrimitiveType that) { getWidthRank() > that.getWidthRank() } predicate widerThan(OrdPrimitiveType that) { this.getWidthRank() > that.getWidthRank() }
predicate widerThanOrEqualTo(OrdPrimitiveType that) { getWidthRank() >= that.getWidthRank() } predicate widerThanOrEqualTo(OrdPrimitiveType that) { this.getWidthRank() >= that.getWidthRank() }
OrdPrimitiveType maxType(OrdPrimitiveType that) { OrdPrimitiveType maxType(OrdPrimitiveType that) {
this.widerThan(that) and result = this this.widerThan(that) and result = this

View File

@@ -25,13 +25,13 @@ class BasicBlock extends ControlFlowNode {
/** Gets an immediate successor of this basic block. */ /** Gets an immediate successor of this basic block. */
cached cached
BasicBlock getABBSuccessor() { result = getLastNode().getASuccessor() } BasicBlock getABBSuccessor() { result = this.getLastNode().getASuccessor() }
/** Gets an immediate predecessor of this basic block. */ /** Gets an immediate predecessor of this basic block. */
BasicBlock getABBPredecessor() { result.getABBSuccessor() = this } BasicBlock getABBPredecessor() { result.getABBSuccessor() = this }
/** Gets a control-flow node contained in this basic block. */ /** Gets a control-flow node contained in this basic block. */
ControlFlowNode getANode() { result = getNode(_) } ControlFlowNode getANode() { result = this.getNode(_) }
/** Gets the control-flow node at a specific (zero-indexed) position in this basic block. */ /** Gets the control-flow node at a specific (zero-indexed) position in this basic block. */
cached cached
@@ -39,7 +39,7 @@ class BasicBlock extends ControlFlowNode {
result = this and pos = 0 result = this and pos = 0
or or
exists(ControlFlowNode mid, int mid_pos | pos = mid_pos + 1 | exists(ControlFlowNode mid, int mid_pos | pos = mid_pos + 1 |
getNode(mid_pos) = mid and this.getNode(mid_pos) = mid and
mid.getASuccessor() = result and mid.getASuccessor() = result and
not result instanceof BasicBlock not result instanceof BasicBlock
) )
@@ -49,11 +49,11 @@ class BasicBlock extends ControlFlowNode {
ControlFlowNode getFirstNode() { result = this } ControlFlowNode getFirstNode() { result = this }
/** Gets the last control-flow node in this basic block. */ /** Gets the last control-flow node in this basic block. */
ControlFlowNode getLastNode() { result = getNode(length() - 1) } ControlFlowNode getLastNode() { result = this.getNode(this.length() - 1) }
/** Gets the number of control-flow nodes contained in this basic block. */ /** Gets the number of control-flow nodes contained in this basic block. */
cached cached
int length() { result = strictcount(getANode()) } int length() { result = strictcount(this.getANode()) }
/** Holds if this basic block strictly dominates `node`. */ /** Holds if this basic block strictly dominates `node`. */
predicate bbStrictlyDominates(BasicBlock node) { bbStrictlyDominates(this, node) } predicate bbStrictlyDominates(BasicBlock node) { bbStrictlyDominates(this, node) }

View File

@@ -12,13 +12,13 @@ import semmle.code.java.controlflow.Guards
*/ */
class ConstantField extends Field { class ConstantField extends Field {
ConstantField() { ConstantField() {
getType() instanceof ImmutableType and this.getType() instanceof ImmutableType and
// Assigned once // Assigned once
count(getAnAssignedValue()) = 1 and count(this.getAnAssignedValue()) = 1 and
// And that assignment is either in the appropriate initializer, or, for instance fields on // And that assignment is either in the appropriate initializer, or, for instance fields on
// classes with one constructor, in the constructor. // classes with one constructor, in the constructor.
forall(FieldWrite fa | fa = getAnAccess() | forall(FieldWrite fa | fa = this.getAnAccess() |
if isStatic() if this.isStatic()
then fa.getEnclosingCallable() instanceof StaticInitializer then fa.getEnclosingCallable() instanceof StaticInitializer
else ( else (
// Defined in the instance initializer. // Defined in the instance initializer.
@@ -26,7 +26,7 @@ class ConstantField extends Field {
or or
// It can be defined in the constructor if there is only one constructor. // It can be defined in the constructor if there is only one constructor.
fa.getEnclosingCallable() instanceof Constructor and fa.getEnclosingCallable() instanceof Constructor and
count(getDeclaringType().getAConstructor()) = 1 count(this.getDeclaringType().getAConstructor()) = 1
) )
) )
} }
@@ -36,7 +36,7 @@ class ConstantField extends Field {
* *
* Note: although this value is constant, we may not be able to statically determine the value. * Note: although this value is constant, we may not be able to statically determine the value.
*/ */
ConstantExpr getConstantValue() { result = getAnAssignedValue() } ConstantExpr getConstantValue() { result = this.getAnAssignedValue() }
} }
/** /**
@@ -162,18 +162,18 @@ class ConstSwitchStmt extends SwitchStmt {
/** Gets the `ConstCase` that matches, if any. */ /** Gets the `ConstCase` that matches, if any. */
ConstCase getMatchingConstCase() { ConstCase getMatchingConstCase() {
result = getAConstCase() and result = this.getAConstCase() and
// Only handle the int case for now // Only handle the int case for now
result.getValue().(ConstantExpr).getIntValue() = getExpr().(ConstantExpr).getIntValue() result.getValue().(ConstantExpr).getIntValue() = this.getExpr().(ConstantExpr).getIntValue()
} }
/** Gets the matching case, if it can be deduced. */ /** Gets the matching case, if it can be deduced. */
SwitchCase getMatchingCase() { SwitchCase getMatchingCase() {
// Must be a value we can deduce // Must be a value we can deduce
exists(getExpr().(ConstantExpr).getIntValue()) and exists(this.getExpr().(ConstantExpr).getIntValue()) and
if exists(getMatchingConstCase()) if exists(this.getMatchingConstCase())
then result = getMatchingConstCase() then result = this.getMatchingConstCase()
else result = getDefaultCase() else result = this.getDefaultCase()
} }
/** /**
@@ -184,8 +184,8 @@ class ConstSwitchStmt extends SwitchStmt {
SwitchCase getAFailingCase() { SwitchCase getAFailingCase() {
exists(SwitchCase matchingCase | exists(SwitchCase matchingCase |
// We must have found the matching case, otherwise we can't deduce which cases are not matched // We must have found the matching case, otherwise we can't deduce which cases are not matched
matchingCase = getMatchingCase() and matchingCase = this.getMatchingCase() and
result = getACase() and result = this.getACase() and
result != matchingCase result != matchingCase
) )
} }
@@ -208,7 +208,7 @@ class UnreachableBasicBlock extends BasicBlock {
or or
// This block is not reachable in the CFG, and is not a callable, a body of a callable, an // This block is not reachable in the CFG, and is not a callable, a body of a callable, an
// expression in an annotation, an expression in an assert statement, or a catch clause. // expression in an annotation, an expression in an assert statement, or a catch clause.
forall(BasicBlock bb | bb = getABBPredecessor() | bb instanceof UnreachableBasicBlock) and forall(BasicBlock bb | bb = this.getABBPredecessor() | bb instanceof UnreachableBasicBlock) and
not exists(Callable c | c.getBody() = this) and not exists(Callable c | c.getBody() = this) and
not this instanceof Callable and not this instanceof Callable and
not exists(Annotation a | a.getAChildExpr*() = this) and not exists(Annotation a | a.getAChildExpr*() = this) and
@@ -231,12 +231,12 @@ class UnreachableBasicBlock extends BasicBlock {
* An unreachable expression is an expression contained in an `UnreachableBasicBlock`. * An unreachable expression is an expression contained in an `UnreachableBasicBlock`.
*/ */
class UnreachableExpr extends Expr { class UnreachableExpr extends Expr {
UnreachableExpr() { getBasicBlock() instanceof UnreachableBasicBlock } UnreachableExpr() { this.getBasicBlock() instanceof UnreachableBasicBlock }
} }
/** /**
* An unreachable statement is a statement contained in an `UnreachableBasicBlock`. * An unreachable statement is a statement contained in an `UnreachableBasicBlock`.
*/ */
class UnreachableStmt extends Stmt { class UnreachableStmt extends Stmt {
UnreachableStmt() { getBasicBlock() instanceof UnreachableBasicBlock } UnreachableStmt() { this.getBasicBlock() instanceof UnreachableBasicBlock }
} }

View File

@@ -45,8 +45,8 @@ private class RmiMethodParameterSource extends RemoteFlowSource {
exists(RemoteCallableMethod method | exists(RemoteCallableMethod method |
method.getAParameter() = this.asParameter() and method.getAParameter() = this.asParameter() and
( (
getType() instanceof PrimitiveType or this.getType() instanceof PrimitiveType or
getType() instanceof TypeString this.getType() instanceof TypeString
) )
) )
} }

View File

@@ -97,7 +97,7 @@ class SsaSourceVariable extends TSsaSourceVariable {
else result = c.getName() + "(..)." + v.getName() else result = c.getName() + "(..)." + v.getName()
) )
or or
result = this.(SsaSourceField).ppQualifier() + "." + getVariable().toString() result = this.(SsaSourceField).ppQualifier() + "." + this.getVariable().toString()
} }
/** /**
@@ -117,7 +117,7 @@ class SsaSourceVariable extends TSsaSourceVariable {
Location getLocation() { Location getLocation() {
exists(LocalScopeVariable v | this = TLocalVar(_, v) and result = v.getLocation()) exists(LocalScopeVariable v | this = TLocalVar(_, v) and result = v.getLocation())
or or
this instanceof SsaSourceField and result = getFirstAccess().getLocation() this instanceof SsaSourceField and result = this.getFirstAccess().getLocation()
} }
/** Gets the type of this variable. */ /** Gets the type of this variable. */
@@ -140,7 +140,7 @@ class SsaSourceField extends SsaSourceVariable {
} }
/** Gets the field corresponding to this named field. */ /** Gets the field corresponding to this named field. */
Field getField() { result = getVariable() } Field getField() { result = this.getVariable() }
/** Gets a string representation of the qualifier. */ /** Gets a string representation of the qualifier. */
string ppQualifier() { string ppQualifier() {
@@ -155,8 +155,8 @@ class SsaSourceField extends SsaSourceVariable {
/** Holds if the field itself or any of the fields part of the qualifier are volatile. */ /** Holds if the field itself or any of the fields part of the qualifier are volatile. */
predicate isVolatile() { predicate isVolatile() {
getField().isVolatile() or this.getField().isVolatile() or
getQualifier().(SsaSourceField).isVolatile() this.getQualifier().(SsaSourceField).isVolatile()
} }
} }
@@ -932,10 +932,10 @@ class SsaVariable extends TSsaVariable {
string toString() { none() } string toString() { none() }
/** Gets the source location for this element. */ /** Gets the source location for this element. */
Location getLocation() { result = getCFGNode().getLocation() } Location getLocation() { result = this.getCFGNode().getLocation() }
/** Gets the `BasicBlock` in which this SSA variable is defined. */ /** Gets the `BasicBlock` in which this SSA variable is defined. */
BasicBlock getBasicBlock() { result = getCFGNode().getBasicBlock() } BasicBlock getBasicBlock() { result = this.getCFGNode().getBasicBlock() }
/** Gets an access of this SSA variable. */ /** Gets an access of this SSA variable. */
RValue getAUse() { RValue getAUse() {
@@ -989,14 +989,16 @@ class SsaUpdate extends SsaVariable {
/** An SSA variable that is defined by a `VariableUpdate`. */ /** An SSA variable that is defined by a `VariableUpdate`. */
class SsaExplicitUpdate extends SsaUpdate, TSsaCertainUpdate { class SsaExplicitUpdate extends SsaUpdate, TSsaCertainUpdate {
SsaExplicitUpdate() { SsaExplicitUpdate() {
exists(VariableUpdate upd | upd = this.getCFGNode() and getDestVar(upd) = getSourceVariable()) exists(VariableUpdate upd |
upd = this.getCFGNode() and getDestVar(upd) = this.getSourceVariable()
)
} }
override string toString() { result = "SSA def(" + getSourceVariable() + ")" } override string toString() { result = "SSA def(" + this.getSourceVariable() + ")" }
/** Gets the `VariableUpdate` defining the SSA variable. */ /** Gets the `VariableUpdate` defining the SSA variable. */
VariableUpdate getDefiningExpr() { VariableUpdate getDefiningExpr() {
result = this.getCFGNode() and getDestVar(result) = getSourceVariable() result = this.getCFGNode() and getDestVar(result) = this.getSourceVariable()
} }
} }
@@ -1010,22 +1012,22 @@ class SsaImplicitUpdate extends SsaUpdate {
SsaImplicitUpdate() { not this instanceof SsaExplicitUpdate } SsaImplicitUpdate() { not this instanceof SsaExplicitUpdate }
override string toString() { override string toString() {
result = "SSA impl upd[" + getKind() + "](" + getSourceVariable() + ")" result = "SSA impl upd[" + this.getKind() + "](" + this.getSourceVariable() + ")"
} }
private string getKind() { private string getKind() {
this = TSsaUntracked(_, _) and result = "untracked" this = TSsaUntracked(_, _) and result = "untracked"
or or
certainVariableUpdate(getSourceVariable().getQualifier(), getCFGNode(), _, _) and certainVariableUpdate(this.getSourceVariable().getQualifier(), this.getCFGNode(), _, _) and
result = "explicit qualifier" result = "explicit qualifier"
or or
if uncertainVariableUpdate(getSourceVariable().getQualifier(), getCFGNode(), _, _) if uncertainVariableUpdate(this.getSourceVariable().getQualifier(), this.getCFGNode(), _, _)
then then
if exists(getANonLocalUpdate()) if exists(this.getANonLocalUpdate())
then result = "nonlocal + nonlocal qualifier" then result = "nonlocal + nonlocal qualifier"
else result = "nonlocal qualifier" else result = "nonlocal qualifier"
else ( else (
exists(getANonLocalUpdate()) and result = "nonlocal" exists(this.getANonLocalUpdate()) and result = "nonlocal"
) )
} }
@@ -1034,9 +1036,9 @@ class SsaImplicitUpdate extends SsaUpdate {
*/ */
FieldWrite getANonLocalUpdate() { FieldWrite getANonLocalUpdate() {
exists(SsaSourceField f, Callable setter | exists(SsaSourceField f, Callable setter |
f = getSourceVariable() and f = this.getSourceVariable() and
relevantFieldUpdate(setter, f.getField(), result) and relevantFieldUpdate(setter, f.getField(), result) and
updatesNamedField(getCFGNode(), f, setter) updatesNamedField(this.getCFGNode(), f, setter)
) )
} }
@@ -1049,8 +1051,8 @@ class SsaImplicitUpdate extends SsaUpdate {
*/ */
predicate assignsUnknownValue() { predicate assignsUnknownValue() {
this = TSsaUntracked(_, _) or this = TSsaUntracked(_, _) or
certainVariableUpdate(getSourceVariable().getQualifier(), getCFGNode(), _, _) or certainVariableUpdate(this.getSourceVariable().getQualifier(), this.getCFGNode(), _, _) or
uncertainVariableUpdate(getSourceVariable().getQualifier(), getCFGNode(), _, _) uncertainVariableUpdate(this.getSourceVariable().getQualifier(), this.getCFGNode(), _, _)
} }
} }
@@ -1072,30 +1074,31 @@ class SsaUncertainImplicitUpdate extends SsaImplicitUpdate, TSsaUncertainUpdate
* includes initial values of parameters, fields, and closure variables. * includes initial values of parameters, fields, and closure variables.
*/ */
class SsaImplicitInit extends SsaVariable, TSsaEntryDef { class SsaImplicitInit extends SsaVariable, TSsaEntryDef {
override string toString() { result = "SSA init(" + getSourceVariable() + ")" } override string toString() { result = "SSA init(" + this.getSourceVariable() + ")" }
/** Holds if this is a closure variable that captures the value of `capturedvar`. */ /** Holds if this is a closure variable that captures the value of `capturedvar`. */
predicate captures(SsaVariable capturedvar) { predicate captures(SsaVariable capturedvar) {
ssaDefReachesCapture(_, capturedvar, getSourceVariable()) ssaDefReachesCapture(_, capturedvar, this.getSourceVariable())
} }
/** /**
* Holds if the SSA variable is a parameter defined by its initial value in the callable. * Holds if the SSA variable is a parameter defined by its initial value in the callable.
*/ */
predicate isParameterDefinition(Parameter p) { predicate isParameterDefinition(Parameter p) {
getSourceVariable() = TLocalVar(p.getCallable(), p) and p.getCallable().getBody() = getCFGNode() this.getSourceVariable() = TLocalVar(p.getCallable(), p) and
p.getCallable().getBody() = this.getCFGNode()
} }
} }
/** An SSA phi node. */ /** An SSA phi node. */
class SsaPhiNode extends SsaVariable, TSsaPhiNode { class SsaPhiNode extends SsaVariable, TSsaPhiNode {
override string toString() { result = "SSA phi(" + getSourceVariable() + ")" } override string toString() { result = "SSA phi(" + this.getSourceVariable() + ")" }
/** Gets an input to the phi node defining the SSA variable. */ /** Gets an input to the phi node defining the SSA variable. */
SsaVariable getAPhiInput() { SsaVariable getAPhiInput() {
exists(BasicBlock phiPred, TrackedVar v | exists(BasicBlock phiPred, TrackedVar v |
v = getSourceVariable() and v = this.getSourceVariable() and
getCFGNode().(BasicBlock).getABBPredecessor() = phiPred and this.getCFGNode().(BasicBlock).getABBPredecessor() = phiPred and
ssaDefReachesEndOfBlock(v, result, phiPred) ssaDefReachesEndOfBlock(v, result, phiPred)
) )
} }

View File

@@ -484,10 +484,10 @@ class BaseSsaVariable extends TBaseSsaVariable {
string toString() { none() } string toString() { none() }
Location getLocation() { result = getCFGNode().getLocation() } Location getLocation() { result = this.getCFGNode().getLocation() }
/** Gets the `BasicBlock` in which this SSA variable is defined. */ /** Gets the `BasicBlock` in which this SSA variable is defined. */
BasicBlock getBasicBlock() { result = getCFGNode().getBasicBlock() } BasicBlock getBasicBlock() { result = this.getCFGNode().getBasicBlock() }
/** Gets an access of this SSA variable. */ /** Gets an access of this SSA variable. */
RValue getAUse() { ssaDefReachesUse(_, this, result) } RValue getAUse() { ssaDefReachesUse(_, this, result) }
@@ -532,14 +532,16 @@ class BaseSsaVariable extends TBaseSsaVariable {
/** An SSA variable that is defined by a `VariableUpdate`. */ /** An SSA variable that is defined by a `VariableUpdate`. */
class BaseSsaUpdate extends BaseSsaVariable, TSsaUpdate { class BaseSsaUpdate extends BaseSsaVariable, TSsaUpdate {
BaseSsaUpdate() { BaseSsaUpdate() {
exists(VariableUpdate upd | upd = this.getCFGNode() and getDestVar(upd) = getSourceVariable()) exists(VariableUpdate upd |
upd = this.getCFGNode() and getDestVar(upd) = this.getSourceVariable()
)
} }
override string toString() { result = "SSA def(" + getSourceVariable() + ")" } override string toString() { result = "SSA def(" + this.getSourceVariable() + ")" }
/** Gets the `VariableUpdate` defining the SSA variable. */ /** Gets the `VariableUpdate` defining the SSA variable. */
VariableUpdate getDefiningExpr() { VariableUpdate getDefiningExpr() {
result = this.getCFGNode() and getDestVar(result) = getSourceVariable() result = this.getCFGNode() and getDestVar(result) = this.getSourceVariable()
} }
} }
@@ -548,30 +550,31 @@ class BaseSsaUpdate extends BaseSsaVariable, TSsaUpdate {
* includes initial values of parameters, fields, and closure variables. * includes initial values of parameters, fields, and closure variables.
*/ */
class BaseSsaImplicitInit extends BaseSsaVariable, TSsaEntryDef { class BaseSsaImplicitInit extends BaseSsaVariable, TSsaEntryDef {
override string toString() { result = "SSA init(" + getSourceVariable() + ")" } override string toString() { result = "SSA init(" + this.getSourceVariable() + ")" }
/** Holds if this is a closure variable that captures the value of `capturedvar`. */ /** Holds if this is a closure variable that captures the value of `capturedvar`. */
predicate captures(BaseSsaVariable capturedvar) { predicate captures(BaseSsaVariable capturedvar) {
ssaDefReachesCapture(_, capturedvar, getSourceVariable()) ssaDefReachesCapture(_, capturedvar, this.getSourceVariable())
} }
/** /**
* Holds if the SSA variable is a parameter defined by its initial value in the callable. * Holds if the SSA variable is a parameter defined by its initial value in the callable.
*/ */
predicate isParameterDefinition(Parameter p) { predicate isParameterDefinition(Parameter p) {
getSourceVariable() = TLocalVar(p.getCallable(), p) and p.getCallable().getBody() = getCFGNode() this.getSourceVariable() = TLocalVar(p.getCallable(), p) and
p.getCallable().getBody() = this.getCFGNode()
} }
} }
/** An SSA phi node. */ /** An SSA phi node. */
class BaseSsaPhiNode extends BaseSsaVariable, TSsaPhiNode { class BaseSsaPhiNode extends BaseSsaVariable, TSsaPhiNode {
override string toString() { result = "SSA phi(" + getSourceVariable() + ")" } override string toString() { result = "SSA phi(" + this.getSourceVariable() + ")" }
/** Gets an input to the phi node defining the SSA variable. */ /** Gets an input to the phi node defining the SSA variable. */
BaseSsaVariable getAPhiInput() { BaseSsaVariable getAPhiInput() {
exists(BasicBlock phiPred, BaseSsaSourceVariable v | exists(BasicBlock phiPred, BaseSsaSourceVariable v |
v = getSourceVariable() and v = this.getSourceVariable() and
getCFGNode().(BasicBlock).getABBPredecessor() = phiPred and this.getCFGNode().(BasicBlock).getABBPredecessor() = phiPred and
ssaDefReachesEndOfBlock(v, result, phiPred) ssaDefReachesEndOfBlock(v, result, phiPred)
) )
} }

View File

@@ -110,12 +110,12 @@ abstract class Configuration extends string {
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowTo(Node sink) { hasFlow(_, sink) } predicate hasFlowTo(Node sink) { this.hasFlow(_, sink) }
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowToExpr(DataFlowExpr sink) { hasFlowTo(exprNode(sink)) } predicate hasFlowToExpr(DataFlowExpr sink) { this.hasFlowTo(exprNode(sink)) }
/** /**
* Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev` * Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev`
@@ -3170,7 +3170,7 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
} }
override string toString() { override string toString() {
result = "[" + this.toStringImpl(true) + length().toString() + ")]" result = "[" + this.toStringImpl(true) + this.length().toString() + ")]"
or or
result = "[" + this.toStringImpl(false) result = "[" + this.toStringImpl(false)
} }
@@ -3309,9 +3309,11 @@ abstract private class PathNodeImpl extends PathNode {
result = " <" + this.(PathNodeMid).getCallContext().toString() + ">" result = " <" + this.(PathNodeMid).getCallContext().toString() + ">"
} }
override string toString() { result = this.getNodeEx().toString() + ppAp() } override string toString() { result = this.getNodeEx().toString() + this.ppAp() }
override string toStringWithContext() { result = this.getNodeEx().toString() + ppAp() + ppCtx() } override string toStringWithContext() {
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
}
override predicate hasLocationInfo( override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -3379,11 +3381,11 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
override PathNodeImpl getASuccessorImpl() { override PathNodeImpl getASuccessorImpl() {
// an intermediate step to another intermediate node // an intermediate step to another intermediate node
result = getSuccMid() result = this.getSuccMid()
or or
// a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges // a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges
exists(PathNodeMid mid, PathNodeSink sink | exists(PathNodeMid mid, PathNodeSink sink |
mid = getSuccMid() and mid = this.getSuccMid() and
mid.getNodeEx() = sink.getNodeEx() and mid.getNodeEx() = sink.getNodeEx() and
mid.getAp() instanceof AccessPathNil and mid.getAp() instanceof AccessPathNil and
sink.getConfiguration() = unbindConf(mid.getConfiguration()) and sink.getConfiguration() = unbindConf(mid.getConfiguration()) and

View File

@@ -110,12 +110,12 @@ abstract class Configuration extends string {
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowTo(Node sink) { hasFlow(_, sink) } predicate hasFlowTo(Node sink) { this.hasFlow(_, sink) }
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowToExpr(DataFlowExpr sink) { hasFlowTo(exprNode(sink)) } predicate hasFlowToExpr(DataFlowExpr sink) { this.hasFlowTo(exprNode(sink)) }
/** /**
* Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev` * Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev`
@@ -3170,7 +3170,7 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
} }
override string toString() { override string toString() {
result = "[" + this.toStringImpl(true) + length().toString() + ")]" result = "[" + this.toStringImpl(true) + this.length().toString() + ")]"
or or
result = "[" + this.toStringImpl(false) result = "[" + this.toStringImpl(false)
} }
@@ -3309,9 +3309,11 @@ abstract private class PathNodeImpl extends PathNode {
result = " <" + this.(PathNodeMid).getCallContext().toString() + ">" result = " <" + this.(PathNodeMid).getCallContext().toString() + ">"
} }
override string toString() { result = this.getNodeEx().toString() + ppAp() } override string toString() { result = this.getNodeEx().toString() + this.ppAp() }
override string toStringWithContext() { result = this.getNodeEx().toString() + ppAp() + ppCtx() } override string toStringWithContext() {
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
}
override predicate hasLocationInfo( override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -3379,11 +3381,11 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
override PathNodeImpl getASuccessorImpl() { override PathNodeImpl getASuccessorImpl() {
// an intermediate step to another intermediate node // an intermediate step to another intermediate node
result = getSuccMid() result = this.getSuccMid()
or or
// a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges // a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges
exists(PathNodeMid mid, PathNodeSink sink | exists(PathNodeMid mid, PathNodeSink sink |
mid = getSuccMid() and mid = this.getSuccMid() and
mid.getNodeEx() = sink.getNodeEx() and mid.getNodeEx() = sink.getNodeEx() and
mid.getAp() instanceof AccessPathNil and mid.getAp() instanceof AccessPathNil and
sink.getConfiguration() = unbindConf(mid.getConfiguration()) and sink.getConfiguration() = unbindConf(mid.getConfiguration()) and

View File

@@ -110,12 +110,12 @@ abstract class Configuration extends string {
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowTo(Node sink) { hasFlow(_, sink) } predicate hasFlowTo(Node sink) { this.hasFlow(_, sink) }
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowToExpr(DataFlowExpr sink) { hasFlowTo(exprNode(sink)) } predicate hasFlowToExpr(DataFlowExpr sink) { this.hasFlowTo(exprNode(sink)) }
/** /**
* Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev` * Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev`
@@ -3170,7 +3170,7 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
} }
override string toString() { override string toString() {
result = "[" + this.toStringImpl(true) + length().toString() + ")]" result = "[" + this.toStringImpl(true) + this.length().toString() + ")]"
or or
result = "[" + this.toStringImpl(false) result = "[" + this.toStringImpl(false)
} }
@@ -3309,9 +3309,11 @@ abstract private class PathNodeImpl extends PathNode {
result = " <" + this.(PathNodeMid).getCallContext().toString() + ">" result = " <" + this.(PathNodeMid).getCallContext().toString() + ">"
} }
override string toString() { result = this.getNodeEx().toString() + ppAp() } override string toString() { result = this.getNodeEx().toString() + this.ppAp() }
override string toStringWithContext() { result = this.getNodeEx().toString() + ppAp() + ppCtx() } override string toStringWithContext() {
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
}
override predicate hasLocationInfo( override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -3379,11 +3381,11 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
override PathNodeImpl getASuccessorImpl() { override PathNodeImpl getASuccessorImpl() {
// an intermediate step to another intermediate node // an intermediate step to another intermediate node
result = getSuccMid() result = this.getSuccMid()
or or
// a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges // a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges
exists(PathNodeMid mid, PathNodeSink sink | exists(PathNodeMid mid, PathNodeSink sink |
mid = getSuccMid() and mid = this.getSuccMid() and
mid.getNodeEx() = sink.getNodeEx() and mid.getNodeEx() = sink.getNodeEx() and
mid.getAp() instanceof AccessPathNil and mid.getAp() instanceof AccessPathNil and
sink.getConfiguration() = unbindConf(mid.getConfiguration()) and sink.getConfiguration() = unbindConf(mid.getConfiguration()) and

View File

@@ -110,12 +110,12 @@ abstract class Configuration extends string {
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowTo(Node sink) { hasFlow(_, sink) } predicate hasFlowTo(Node sink) { this.hasFlow(_, sink) }
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowToExpr(DataFlowExpr sink) { hasFlowTo(exprNode(sink)) } predicate hasFlowToExpr(DataFlowExpr sink) { this.hasFlowTo(exprNode(sink)) }
/** /**
* Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev` * Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev`
@@ -3170,7 +3170,7 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
} }
override string toString() { override string toString() {
result = "[" + this.toStringImpl(true) + length().toString() + ")]" result = "[" + this.toStringImpl(true) + this.length().toString() + ")]"
or or
result = "[" + this.toStringImpl(false) result = "[" + this.toStringImpl(false)
} }
@@ -3309,9 +3309,11 @@ abstract private class PathNodeImpl extends PathNode {
result = " <" + this.(PathNodeMid).getCallContext().toString() + ">" result = " <" + this.(PathNodeMid).getCallContext().toString() + ">"
} }
override string toString() { result = this.getNodeEx().toString() + ppAp() } override string toString() { result = this.getNodeEx().toString() + this.ppAp() }
override string toStringWithContext() { result = this.getNodeEx().toString() + ppAp() + ppCtx() } override string toStringWithContext() {
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
}
override predicate hasLocationInfo( override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -3379,11 +3381,11 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
override PathNodeImpl getASuccessorImpl() { override PathNodeImpl getASuccessorImpl() {
// an intermediate step to another intermediate node // an intermediate step to another intermediate node
result = getSuccMid() result = this.getSuccMid()
or or
// a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges // a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges
exists(PathNodeMid mid, PathNodeSink sink | exists(PathNodeMid mid, PathNodeSink sink |
mid = getSuccMid() and mid = this.getSuccMid() and
mid.getNodeEx() = sink.getNodeEx() and mid.getNodeEx() = sink.getNodeEx() and
mid.getAp() instanceof AccessPathNil and mid.getAp() instanceof AccessPathNil and
sink.getConfiguration() = unbindConf(mid.getConfiguration()) and sink.getConfiguration() = unbindConf(mid.getConfiguration()) and

View File

@@ -110,12 +110,12 @@ abstract class Configuration extends string {
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowTo(Node sink) { hasFlow(_, sink) } predicate hasFlowTo(Node sink) { this.hasFlow(_, sink) }
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowToExpr(DataFlowExpr sink) { hasFlowTo(exprNode(sink)) } predicate hasFlowToExpr(DataFlowExpr sink) { this.hasFlowTo(exprNode(sink)) }
/** /**
* Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev` * Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev`
@@ -3170,7 +3170,7 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
} }
override string toString() { override string toString() {
result = "[" + this.toStringImpl(true) + length().toString() + ")]" result = "[" + this.toStringImpl(true) + this.length().toString() + ")]"
or or
result = "[" + this.toStringImpl(false) result = "[" + this.toStringImpl(false)
} }
@@ -3309,9 +3309,11 @@ abstract private class PathNodeImpl extends PathNode {
result = " <" + this.(PathNodeMid).getCallContext().toString() + ">" result = " <" + this.(PathNodeMid).getCallContext().toString() + ">"
} }
override string toString() { result = this.getNodeEx().toString() + ppAp() } override string toString() { result = this.getNodeEx().toString() + this.ppAp() }
override string toStringWithContext() { result = this.getNodeEx().toString() + ppAp() + ppCtx() } override string toStringWithContext() {
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
}
override predicate hasLocationInfo( override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -3379,11 +3381,11 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
override PathNodeImpl getASuccessorImpl() { override PathNodeImpl getASuccessorImpl() {
// an intermediate step to another intermediate node // an intermediate step to another intermediate node
result = getSuccMid() result = this.getSuccMid()
or or
// a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges // a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges
exists(PathNodeMid mid, PathNodeSink sink | exists(PathNodeMid mid, PathNodeSink sink |
mid = getSuccMid() and mid = this.getSuccMid() and
mid.getNodeEx() = sink.getNodeEx() and mid.getNodeEx() = sink.getNodeEx() and
mid.getAp() instanceof AccessPathNil and mid.getAp() instanceof AccessPathNil and
sink.getConfiguration() = unbindConf(mid.getConfiguration()) and sink.getConfiguration() = unbindConf(mid.getConfiguration()) and

View File

@@ -110,12 +110,12 @@ abstract class Configuration extends string {
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowTo(Node sink) { hasFlow(_, sink) } predicate hasFlowTo(Node sink) { this.hasFlow(_, sink) }
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowToExpr(DataFlowExpr sink) { hasFlowTo(exprNode(sink)) } predicate hasFlowToExpr(DataFlowExpr sink) { this.hasFlowTo(exprNode(sink)) }
/** /**
* Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev` * Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev`
@@ -3170,7 +3170,7 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
} }
override string toString() { override string toString() {
result = "[" + this.toStringImpl(true) + length().toString() + ")]" result = "[" + this.toStringImpl(true) + this.length().toString() + ")]"
or or
result = "[" + this.toStringImpl(false) result = "[" + this.toStringImpl(false)
} }
@@ -3309,9 +3309,11 @@ abstract private class PathNodeImpl extends PathNode {
result = " <" + this.(PathNodeMid).getCallContext().toString() + ">" result = " <" + this.(PathNodeMid).getCallContext().toString() + ">"
} }
override string toString() { result = this.getNodeEx().toString() + ppAp() } override string toString() { result = this.getNodeEx().toString() + this.ppAp() }
override string toStringWithContext() { result = this.getNodeEx().toString() + ppAp() + ppCtx() } override string toStringWithContext() {
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
}
override predicate hasLocationInfo( override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -3379,11 +3381,11 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
override PathNodeImpl getASuccessorImpl() { override PathNodeImpl getASuccessorImpl() {
// an intermediate step to another intermediate node // an intermediate step to another intermediate node
result = getSuccMid() result = this.getSuccMid()
or or
// a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges // a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges
exists(PathNodeMid mid, PathNodeSink sink | exists(PathNodeMid mid, PathNodeSink sink |
mid = getSuccMid() and mid = this.getSuccMid() and
mid.getNodeEx() = sink.getNodeEx() and mid.getNodeEx() = sink.getNodeEx() and
mid.getAp() instanceof AccessPathNil and mid.getAp() instanceof AccessPathNil and
sink.getConfiguration() = unbindConf(mid.getConfiguration()) and sink.getConfiguration() = unbindConf(mid.getConfiguration()) and

View File

@@ -110,12 +110,12 @@ abstract class Configuration extends string {
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowTo(Node sink) { hasFlow(_, sink) } predicate hasFlowTo(Node sink) { this.hasFlow(_, sink) }
/** /**
* Holds if data may flow from some source to `sink` for this configuration. * Holds if data may flow from some source to `sink` for this configuration.
*/ */
predicate hasFlowToExpr(DataFlowExpr sink) { hasFlowTo(exprNode(sink)) } predicate hasFlowToExpr(DataFlowExpr sink) { this.hasFlowTo(exprNode(sink)) }
/** /**
* Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev` * Gets the exploration limit for `hasPartialFlow` and `hasPartialFlowRev`
@@ -3170,7 +3170,7 @@ private class AccessPathCons extends AccessPath, TAccessPathCons {
} }
override string toString() { override string toString() {
result = "[" + this.toStringImpl(true) + length().toString() + ")]" result = "[" + this.toStringImpl(true) + this.length().toString() + ")]"
or or
result = "[" + this.toStringImpl(false) result = "[" + this.toStringImpl(false)
} }
@@ -3309,9 +3309,11 @@ abstract private class PathNodeImpl extends PathNode {
result = " <" + this.(PathNodeMid).getCallContext().toString() + ">" result = " <" + this.(PathNodeMid).getCallContext().toString() + ">"
} }
override string toString() { result = this.getNodeEx().toString() + ppAp() } override string toString() { result = this.getNodeEx().toString() + this.ppAp() }
override string toStringWithContext() { result = this.getNodeEx().toString() + ppAp() + ppCtx() } override string toStringWithContext() {
result = this.getNodeEx().toString() + this.ppAp() + this.ppCtx()
}
override predicate hasLocationInfo( override predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
@@ -3379,11 +3381,11 @@ private class PathNodeMid extends PathNodeImpl, TPathNodeMid {
override PathNodeImpl getASuccessorImpl() { override PathNodeImpl getASuccessorImpl() {
// an intermediate step to another intermediate node // an intermediate step to another intermediate node
result = getSuccMid() result = this.getSuccMid()
or or
// a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges // a final step to a sink via zero steps means we merge the last two steps to prevent trivial-looking edges
exists(PathNodeMid mid, PathNodeSink sink | exists(PathNodeMid mid, PathNodeSink sink |
mid = getSuccMid() and mid = this.getSuccMid() and
mid.getNodeEx() = sink.getNodeEx() and mid.getNodeEx() = sink.getNodeEx() and
mid.getAp() instanceof AccessPathNil and mid.getAp() instanceof AccessPathNil and
sink.getConfiguration() = unbindConf(mid.getConfiguration()) and sink.getConfiguration() = unbindConf(mid.getConfiguration()) and

View File

@@ -117,9 +117,9 @@ module Public {
* Gets an upper bound on the type of this node. * Gets an upper bound on the type of this node.
*/ */
Type getTypeBound() { Type getTypeBound() {
result = getImprovedTypeBound() result = this.getImprovedTypeBound()
or or
result = getType() and not exists(getImprovedTypeBound()) result = this.getType() and not exists(this.getImprovedTypeBound())
} }
/** /**
@@ -132,7 +132,7 @@ module Public {
predicate hasLocationInfo( predicate hasLocationInfo(
string filepath, int startline, int startcolumn, int endline, int endcolumn string filepath, int startline, int startcolumn, int endline, int endcolumn
) { ) {
getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn) this.getLocation().hasLocationInfo(filepath, startline, startcolumn, endline, endcolumn)
} }
} }
@@ -288,9 +288,9 @@ private class NewExpr extends PostUpdateNode, TExprNode {
* A `PostUpdateNode` that is not a `ClassInstanceExpr`. * A `PostUpdateNode` that is not a `ClassInstanceExpr`.
*/ */
abstract private class ImplicitPostUpdateNode extends PostUpdateNode { abstract private class ImplicitPostUpdateNode extends PostUpdateNode {
override Location getLocation() { result = getPreUpdateNode().getLocation() } override Location getLocation() { result = this.getPreUpdateNode().getLocation() }
override string toString() { result = getPreUpdateNode().toString() + " [post update]" } override string toString() { result = this.getPreUpdateNode().toString() + " [post update]" }
} }
private class ExplicitExprPostUpdate extends ImplicitPostUpdateNode, TExplicitExprPostUpdate { private class ExplicitExprPostUpdate extends ImplicitPostUpdateNode, TExplicitExprPostUpdate {

View File

@@ -285,11 +285,11 @@ private predicate taintPreservingQualifierToMethod(Method m) {
private class StringReplaceMethod extends TaintPreservingCallable { private class StringReplaceMethod extends TaintPreservingCallable {
StringReplaceMethod() { StringReplaceMethod() {
getDeclaringType() instanceof TypeString and this.getDeclaringType() instanceof TypeString and
( (
hasName("replace") or this.hasName("replace") or
hasName("replaceAll") or this.hasName("replaceAll") or
hasName("replaceFirst") this.hasName("replaceFirst")
) )
} }
@@ -443,7 +443,7 @@ class ObjectOutputStreamVar extends LocalVariableDecl {
} }
MethodAccess getAWriteObjectMethodAccess() { MethodAccess getAWriteObjectMethodAccess() {
result.getQualifier() = getAnAccess() and result.getQualifier() = this.getAnAccess() and
result.getMethod().hasName("writeObject") result.getMethod().hasName("writeObject")
} }
} }
@@ -488,7 +488,7 @@ private class FormatterVar extends LocalVariableDecl {
} }
MethodAccess getAFormatMethodAccess() { MethodAccess getAFormatMethodAccess() {
result.getQualifier() = getAnAccess() and result.getQualifier() = this.getAnAccess() and
result.getMethod().hasName("format") result.getMethod().hasName("format")
} }
} }
@@ -513,13 +513,13 @@ private class FormatterCallable extends TaintPreservingCallable {
} }
override predicate returnsTaintFrom(int arg) { override predicate returnsTaintFrom(int arg) {
if this instanceof Constructor then arg = 0 else arg = [-1 .. getNumberOfParameters()] if this instanceof Constructor then arg = 0 else arg = [-1 .. this.getNumberOfParameters()]
} }
override predicate transfersTaint(int src, int sink) { override predicate transfersTaint(int src, int sink) {
this.hasName("format") and this.hasName("format") and
sink = -1 and sink = -1 and
src = [0 .. getNumberOfParameters()] src = [0 .. this.getNumberOfParameters()]
} }
} }
@@ -532,13 +532,13 @@ module StringBuilderVarModule {
* build up a query using string concatenation. * build up a query using string concatenation.
*/ */
class StringBuilderVar extends LocalVariableDecl { class StringBuilderVar extends LocalVariableDecl {
StringBuilderVar() { getType() instanceof StringBuildingType } StringBuilderVar() { this.getType() instanceof StringBuildingType }
/** /**
* Gets a call that adds something to this string builder, from the argument at the given index. * Gets a call that adds something to this string builder, from the argument at the given index.
*/ */
MethodAccess getAnInput(int arg) { MethodAccess getAnInput(int arg) {
result.getQualifier() = getAChainedReference() and result.getQualifier() = this.getAChainedReference() and
( (
result.getMethod().getName() = "append" and arg = 0 result.getMethod().getName() = "append" and arg = 0
or or
@@ -552,20 +552,20 @@ module StringBuilderVarModule {
* Gets a call that appends something to this string builder. * Gets a call that appends something to this string builder.
*/ */
MethodAccess getAnAppend() { MethodAccess getAnAppend() {
result.getQualifier() = getAChainedReference() and result.getQualifier() = this.getAChainedReference() and
result.getMethod().getName() = "append" result.getMethod().getName() = "append"
} }
MethodAccess getNextAppend(MethodAccess append) { MethodAccess getNextAppend(MethodAccess append) {
result = getAnAppend() and result = this.getAnAppend() and
append = getAnAppend() and append = this.getAnAppend() and
( (
result.getQualifier() = append result.getQualifier() = append
or or
not exists(MethodAccess chainAccess | chainAccess.getQualifier() = append) and not exists(MethodAccess chainAccess | chainAccess.getQualifier() = append) and
exists(RValue sbva1, RValue sbva2 | exists(RValue sbva1, RValue sbva2 |
adjacentUseUse(sbva1, sbva2) and adjacentUseUse(sbva1, sbva2) and
append.getQualifier() = getAChainedReference(sbva1) and append.getQualifier() = this.getAChainedReference(sbva1) and
result.getQualifier() = sbva2 result.getQualifier() = sbva2
) )
) )
@@ -575,7 +575,7 @@ module StringBuilderVarModule {
* Gets a call that converts this string builder to a string. * Gets a call that converts this string builder to a string.
*/ */
MethodAccess getToStringCall() { MethodAccess getToStringCall() {
result.getQualifier() = getAChainedReference() and result.getQualifier() = this.getAChainedReference() and
result.getMethod().getName() = "toString" result.getMethod().getName() = "toString"
} }
@@ -590,7 +590,7 @@ module StringBuilderVarModule {
/** /**
* Gets an expression that refers to this `StringBuilder`, possibly after some chained calls. * Gets an expression that refers to this `StringBuilder`, possibly after some chained calls.
*/ */
Expr getAChainedReference() { result = getAChainedReference(_) } Expr getAChainedReference() { result = this.getAChainedReference(_) }
} }
} }

View File

@@ -82,19 +82,19 @@ class SuppressedConstructor extends Constructor {
SuppressedConstructor() { SuppressedConstructor() {
// Must be private or protected to suppress it. // Must be private or protected to suppress it.
( (
isPrivate() this.isPrivate()
or or
// A protected, suppressed constructor only makes sense in a non-abstract class. // A protected, suppressed constructor only makes sense in a non-abstract class.
isProtected() and not getDeclaringType().isAbstract() this.isProtected() and not this.getDeclaringType().isAbstract()
) and ) and
// Must be no-arg in order to replace the compiler generated default constructor. // Must be no-arg in order to replace the compiler generated default constructor.
getNumberOfParameters() = 0 and this.getNumberOfParameters() = 0 and
// Not the compiler-generated constructor itself. // Not the compiler-generated constructor itself.
not isDefaultConstructor() and not this.isDefaultConstructor() and
// Verify that there is only one statement, which is the `super()` call. This exists // Verify that there is only one statement, which is the `super()` call. This exists
// even for empty constructors. // even for empty constructors.
getBody().(BlockStmt).getNumStmt() = 1 and this.getBody().(BlockStmt).getNumStmt() = 1 and
getBody().(BlockStmt).getAStmt().(SuperConstructorInvocationStmt).getNumArgument() = 0 and this.getBody().(BlockStmt).getAStmt().(SuperConstructorInvocationStmt).getNumArgument() = 0 and
// A constructor that is called is not acting to suppress the default constructor. We permit // A constructor that is called is not acting to suppress the default constructor. We permit
// calls from suppressed and default constructors - in both cases, they can only come from // calls from suppressed and default constructors - in both cases, they can only come from
// sub-class constructors. // sub-class constructors.
@@ -105,7 +105,9 @@ class SuppressedConstructor extends Constructor {
) and ) and
// If other constructors are declared, then no compiler-generated constructor is added, so // If other constructors are declared, then no compiler-generated constructor is added, so
// this constructor is not acting to suppress the default compiler-generated constructor. // this constructor is not acting to suppress the default compiler-generated constructor.
not exists(Constructor other | other = getDeclaringType().getAConstructor() and other != this) not exists(Constructor other |
other = this.getDeclaringType().getAConstructor() and other != this
)
} }
} }
@@ -114,7 +116,7 @@ class SuppressedConstructor extends Constructor {
*/ */
class NamespaceClass extends RefType { class NamespaceClass extends RefType {
NamespaceClass() { NamespaceClass() {
fromSource() and this.fromSource() and
// All members, apart from the default constructor and, if present, a "suppressed" constructor // All members, apart from the default constructor and, if present, a "suppressed" constructor
// must be static. There must be at least one member apart from the permitted constructors. // must be static. There must be at least one member apart from the permitted constructors.
forex(Member m | forex(Member m |
@@ -125,7 +127,9 @@ class NamespaceClass extends RefType {
m.isStatic() m.isStatic()
) and ) and
// Must only extend other namespace classes, or `Object`. // Must only extend other namespace classes, or `Object`.
forall(RefType r | r = getASupertype() | r instanceof TypeObject or r instanceof NamespaceClass) forall(RefType r | r = this.getASupertype() |
r instanceof TypeObject or r instanceof NamespaceClass
)
} }
} }
@@ -197,7 +201,7 @@ class DeadClass extends SourceClassOrInterface {
/** /**
* Identify all the "dead" roots of this dead class. * Identify all the "dead" roots of this dead class.
*/ */
DeadRoot getADeadRoot() { result = getADeadRoot(getACallable()) } DeadRoot getADeadRoot() { result = getADeadRoot(this.getACallable()) }
/** /**
* Holds if this dead class is only used within the class itself. * Holds if this dead class is only used within the class itself.
@@ -206,8 +210,8 @@ class DeadClass extends SourceClassOrInterface {
// Accessed externally if any callable in the class has a possible liveness cause outside the // Accessed externally if any callable in the class has a possible liveness cause outside the
// class. Only one step is required. // class. Only one step is required.
not exists(Callable c | not exists(Callable c |
c = possibleLivenessCause(getACallable()) and c = possibleLivenessCause(this.getACallable()) and
not c = getACallable() not c = this.getACallable()
) )
} }
} }
@@ -229,7 +233,7 @@ abstract class WhitelistedLiveClass extends RefType { }
*/ */
class DeadMethod extends Callable { class DeadMethod extends Callable {
DeadMethod() { DeadMethod() {
fromSource() and this.fromSource() and
not isLive(this) and not isLive(this) and
not this.(Constructor).isDefaultConstructor() and not this.(Constructor).isDefaultConstructor() and
// Ignore `SuppressedConstructor`s in `NamespaceClass`es. There is no reason to use a suppressed // Ignore `SuppressedConstructor`s in `NamespaceClass`es. There is no reason to use a suppressed

View File

@@ -10,7 +10,7 @@ import semmle.code.java.frameworks.jackson.JacksonSerializability
* This defines the set of fields for which we will determine liveness. * This defines the set of fields for which we will determine liveness.
*/ */
library class SourceField extends Field { library class SourceField extends Field {
SourceField() { fromSource() } SourceField() { this.fromSource() }
} }
/** /**
@@ -26,7 +26,7 @@ class DeadField extends SourceField {
*/ */
predicate isInDeadScope() { predicate isInDeadScope() {
// `EnumConstant`s, and fields in dead classes, are reported in other queries. // `EnumConstant`s, and fields in dead classes, are reported in other queries.
getDeclaringType() instanceof DeadClass or this.getDeclaringType() instanceof DeadClass or
this instanceof EnumConstant this instanceof EnumConstant
} }
} }
@@ -37,7 +37,7 @@ class DeadField extends SourceField {
*/ */
class LiveField extends SourceField { class LiveField extends SourceField {
LiveField() { LiveField() {
exists(FieldRead access | access = getAnAccess() | exists(FieldRead access | access = this.getAnAccess() |
isLive(access.getEnclosingCallable()) isLive(access.getEnclosingCallable())
or or
exists(Annotation a | exists(Annotation a |
@@ -89,11 +89,11 @@ abstract class WhitelistedLiveField extends Field { }
*/ */
class SerialVersionUIDField extends ReflectivelyReadField { class SerialVersionUIDField extends ReflectivelyReadField {
SerialVersionUIDField() { SerialVersionUIDField() {
hasName("serialVersionUID") and this.hasName("serialVersionUID") and
isStatic() and this.isStatic() and
isFinal() and this.isFinal() and
getType().hasName("long") and this.getType().hasName("long") and
getDeclaringType().getASupertype*() instanceof TypeSerializable this.getDeclaringType().getASupertype*() instanceof TypeSerializable
} }
} }
@@ -104,7 +104,7 @@ class SerialVersionUIDField extends ReflectivelyReadField {
class LiveJaxbBoundField extends ReflectivelyReadField, JaxbBoundField { class LiveJaxbBoundField extends ReflectivelyReadField, JaxbBoundField {
LiveJaxbBoundField() { LiveJaxbBoundField() {
// If the class is considered live, it must have at least one live constructor. // If the class is considered live, it must have at least one live constructor.
exists(Constructor c | c = getDeclaringType().getAConstructor() | isLive(c)) exists(Constructor c | c = this.getDeclaringType().getAConstructor() | isLive(c))
} }
} }
@@ -114,11 +114,11 @@ class LiveJaxbBoundField extends ReflectivelyReadField, JaxbBoundField {
*/ */
class JUnitAnnotatedField extends ReflectivelyReadField { class JUnitAnnotatedField extends ReflectivelyReadField {
JUnitAnnotatedField() { JUnitAnnotatedField() {
hasAnnotation("org.junit.experimental.theories", "DataPoint") or this.hasAnnotation("org.junit.experimental.theories", "DataPoint") or
hasAnnotation("org.junit.experimental.theories", "DataPoints") or this.hasAnnotation("org.junit.experimental.theories", "DataPoints") or
hasAnnotation("org.junit.runners", "Parameterized$Parameter") or this.hasAnnotation("org.junit.runners", "Parameterized$Parameter") or
hasAnnotation("org.junit", "Rule") or this.hasAnnotation("org.junit", "Rule") or
hasAnnotation("org.junit", "ClassRule") this.hasAnnotation("org.junit", "ClassRule")
} }
} }
@@ -164,8 +164,8 @@ class JPAReadField extends ReflectivelyReadField {
) )
| |
not this.hasAnnotation("javax.persistence", "Transient") and not this.hasAnnotation("javax.persistence", "Transient") and
not isStatic() and not this.isStatic() and
not isFinal() not this.isFinal()
) )
} }
} }

View File

@@ -102,7 +102,7 @@ library class JacksonReflectivelyConstructedClass extends ReflectivelyConstructe
override Callable getALiveCallable() { override Callable getALiveCallable() {
// Constructors may be called by Jackson, if they are a no-arg, they have a suitable annotation, // Constructors may be called by Jackson, if they are a no-arg, they have a suitable annotation,
// or inherit a suitable annotation through a mixin. // or inherit a suitable annotation through a mixin.
result = getAConstructor() and result = this.getAConstructor() and
( (
result.getNumberOfParameters() = 0 or result.getNumberOfParameters() = 0 or
result.getAnAnnotation() instanceof JacksonAnnotation or result.getAnAnnotation() instanceof JacksonAnnotation or
@@ -153,7 +153,7 @@ class DeserializedClass extends ReflectivelyConstructedClass {
*/ */
class NewInstanceCall extends EntryPoint, NewInstance { class NewInstanceCall extends EntryPoint, NewInstance {
override Constructor getALiveCallable() { override Constructor getALiveCallable() {
result = getInferredConstructor() and result = this.getInferredConstructor() and
// The `newInstance(...)` call must be used in a live context. // The `newInstance(...)` call must be used in a live context.
isLive(this.getEnclosingCallable()) isLive(this.getEnclosingCallable())
} }
@@ -164,7 +164,7 @@ class NewInstanceCall extends EntryPoint, NewInstance {
*/ */
class ReflectiveMethodAccessEntryPoint extends EntryPoint, ReflectiveMethodAccess { class ReflectiveMethodAccessEntryPoint extends EntryPoint, ReflectiveMethodAccess {
override Method getALiveCallable() { override Method getALiveCallable() {
result = inferAccessedMethod() and result = this.inferAccessedMethod() and
// The `getMethod(...)` call must be used in a live context. // The `getMethod(...)` call must be used in a live context.
isLive(this.getEnclosingCallable()) isLive(this.getEnclosingCallable())
} }
@@ -210,8 +210,8 @@ class JaxbXmlEnum extends AnnotationEntryPoint {
class JaxbXmlType extends AnnotationEntryPoint, JaxbType { class JaxbXmlType extends AnnotationEntryPoint, JaxbType {
override Callable getALiveCallable() { override Callable getALiveCallable() {
// Must have a live no-arg constructor for JAXB to perform marshal/unmarshal. // Must have a live no-arg constructor for JAXB to perform marshal/unmarshal.
exists(Constructor c | c = getAConstructor() and c.getNumberOfParameters() = 0 | isLive(c)) and exists(Constructor c | c = this.getAConstructor() and c.getNumberOfParameters() = 0 | isLive(c)) and
result = getACallable() and result = this.getACallable() and
( (
// A bound getter or setter. // A bound getter or setter.
result instanceof JaxbBoundGetterSetter result instanceof JaxbBoundGetterSetter
@@ -262,7 +262,7 @@ class ManagedBeanImplEntryPoint extends EntryPoint, RegisteredManagedBeanImpl {
// Find the method that will be called for each method on each managed bean that this class // Find the method that will be called for each method on each managed bean that this class
// implements. // implements.
this.inherits(result) and this.inherits(result) and
result.(Method).overrides(getAnImplementedManagedBean().getAMethod()) result.(Method).overrides(this.getAnImplementedManagedBean().getAMethod())
} }
} }
@@ -377,7 +377,7 @@ class JavaxResourceAnnotatedMethod extends CallableEntryPointOnConstructedClass
*/ */
class JavaxManagedBeanReflectivelyConstructed extends ReflectivelyConstructedClass { class JavaxManagedBeanReflectivelyConstructed extends ReflectivelyConstructedClass {
JavaxManagedBeanReflectivelyConstructed() { JavaxManagedBeanReflectivelyConstructed() {
getAnAnnotation() instanceof JavaxManagedBeanAnnotation this.getAnAnnotation() instanceof JavaxManagedBeanAnnotation
} }
} }
@@ -413,13 +413,13 @@ class PersistencePropertyMethod extends CallableEntryPoint {
*/ */
class PersistenceCallbackMethod extends CallableEntryPoint { class PersistenceCallbackMethod extends CallableEntryPoint {
PersistenceCallbackMethod() { PersistenceCallbackMethod() {
getAnAnnotation() instanceof PrePersistAnnotation or this.getAnAnnotation() instanceof PrePersistAnnotation or
getAnAnnotation() instanceof PreRemoveAnnotation or this.getAnAnnotation() instanceof PreRemoveAnnotation or
getAnAnnotation() instanceof PreUpdateAnnotation or this.getAnAnnotation() instanceof PreUpdateAnnotation or
getAnAnnotation() instanceof PostPersistAnnotation or this.getAnAnnotation() instanceof PostPersistAnnotation or
getAnAnnotation() instanceof PostRemoveAnnotation or this.getAnAnnotation() instanceof PostRemoveAnnotation or
getAnAnnotation() instanceof PostUpdateAnnotation or this.getAnAnnotation() instanceof PostUpdateAnnotation or
getAnAnnotation() instanceof PostLoadAnnotation this.getAnAnnotation() instanceof PostLoadAnnotation
} }
} }
@@ -429,20 +429,20 @@ class PersistenceCallbackMethod extends CallableEntryPoint {
*/ */
class ArbitraryXMLEntryPoint extends ReflectivelyConstructedClass { class ArbitraryXMLEntryPoint extends ReflectivelyConstructedClass {
ArbitraryXMLEntryPoint() { ArbitraryXMLEntryPoint() {
fromSource() and this.fromSource() and
exists(XMLAttribute attribute | exists(XMLAttribute attribute |
attribute.getName() = "className" or attribute.getName() = "className" or
attribute.getName().matches("%ClassName") or attribute.getName().matches("%ClassName") or
attribute.getName() = "class" or attribute.getName() = "class" or
attribute.getName().matches("%Class") attribute.getName().matches("%Class")
| |
attribute.getValue() = getQualifiedName() attribute.getValue() = this.getQualifiedName()
) )
} }
override Callable getALiveCallable() { override Callable getALiveCallable() {
// Any constructor on these classes, as we don't know which may be called. // Any constructor on these classes, as we don't know which may be called.
result = getAConstructor() result = this.getAConstructor()
} }
} }

View File

@@ -18,7 +18,7 @@ class TestMethodEntry extends CallableEntryPoint {
or or
exists(AnnotationType a | a = this.getAnAnnotation().getType() | exists(AnnotationType a | a = this.getAnAnnotation().getType() |
a.hasQualifiedName("org.junit.runners", "Parameterized$Parameters") and a.hasQualifiedName("org.junit.runners", "Parameterized$Parameters") and
getDeclaringType() instanceof ParameterizedJUnitTest this.getDeclaringType() instanceof ParameterizedJUnitTest
) )
} }
} }
@@ -28,12 +28,12 @@ class TestMethodEntry extends CallableEntryPoint {
*/ */
class BeforeOrAfterEntry extends CallableEntryPoint { class BeforeOrAfterEntry extends CallableEntryPoint {
BeforeOrAfterEntry() { BeforeOrAfterEntry() {
getAnAnnotation() instanceof TestNGBeforeAnnotation or this.getAnAnnotation() instanceof TestNGBeforeAnnotation or
getAnAnnotation() instanceof TestNGAfterAnnotation or this.getAnAnnotation() instanceof TestNGAfterAnnotation or
getAnAnnotation() instanceof BeforeAnnotation or this.getAnAnnotation() instanceof BeforeAnnotation or
getAnAnnotation() instanceof BeforeClassAnnotation or this.getAnAnnotation() instanceof BeforeClassAnnotation or
getAnAnnotation() instanceof AfterAnnotation or this.getAnAnnotation() instanceof AfterAnnotation or
getAnAnnotation() instanceof AfterClassAnnotation this.getAnAnnotation() instanceof AfterClassAnnotation
} }
} }
@@ -44,7 +44,7 @@ class JUnitTheories extends CallableEntryPoint {
JUnitTheories() { JUnitTheories() {
exists(AnnotationType a | exists(AnnotationType a |
a = this.getAnAnnotation().getType() and a = this.getAnAnnotation().getType() and
getDeclaringType() instanceof JUnitTheoryTest this.getDeclaringType() instanceof JUnitTheoryTest
| |
a.hasQualifiedName("org.junit.experimental.theories", "Theory") or a.hasQualifiedName("org.junit.experimental.theories", "Theory") or
a.hasQualifiedName("org.junit.experimental.theories", "DataPoint") or a.hasQualifiedName("org.junit.experimental.theories", "DataPoint") or
@@ -63,7 +63,7 @@ class JUnitDataPointField extends ReflectivelyReadField {
a.hasQualifiedName("org.junit.experimental.theories", "DataPoint") or a.hasQualifiedName("org.junit.experimental.theories", "DataPoint") or
a.hasQualifiedName("org.junit.experimental.theories", "DataPoints") a.hasQualifiedName("org.junit.experimental.theories", "DataPoints")
) and ) and
getDeclaringType() instanceof JUnitTheoryTest this.getDeclaringType() instanceof JUnitTheoryTest
) )
} }
} }
@@ -152,7 +152,7 @@ class CucumberConstructedClass extends ReflectivelyConstructedClass {
// Consider any constructor to be live - Cucumber calls a runtime-specified dependency // Consider any constructor to be live - Cucumber calls a runtime-specified dependency
// injection framework (possibly an in-built one) to construct these instances, so any // injection framework (possibly an in-built one) to construct these instances, so any
// constructor could be called. // constructor could be called.
result = getAConstructor() result = this.getAConstructor()
} }
} }

View File

@@ -29,7 +29,7 @@ class ServletConstructedClass extends ReflectivelyConstructedClass {
*/ */
class ServletListenerClass extends ReflectivelyConstructedClass { class ServletListenerClass extends ReflectivelyConstructedClass {
ServletListenerClass() { ServletListenerClass() {
getAnAncestor() instanceof ServletWebXMLListenerType and this.getAnAncestor() instanceof ServletWebXMLListenerType and
// If we have seen any `web.xml` files, this listener will be considered to be live only if it is // If we have seen any `web.xml` files, this listener will be considered to be live only if it is
// referred to as a listener-class in at least one. If no `web.xml` files are found, we assume // referred to as a listener-class in at least one. If no `web.xml` files are found, we assume
// that XML extraction was not enabled, and therefore consider all listener classes as live. // that XML extraction was not enabled, and therefore consider all listener classes as live.
@@ -47,7 +47,7 @@ class ServletListenerClass extends ReflectivelyConstructedClass {
*/ */
class ServletFilterClass extends ReflectivelyConstructedClass { class ServletFilterClass extends ReflectivelyConstructedClass {
ServletFilterClass() { ServletFilterClass() {
getASupertype*().hasQualifiedName("javax.servlet", "Filter") and this.getASupertype*().hasQualifiedName("javax.servlet", "Filter") and
// If we have seen any `web.xml` files, this filter will be considered to be live only if it is // If we have seen any `web.xml` files, this filter will be considered to be live only if it is
// referred to as a filter-class in at least one. If no `web.xml` files are found, we assume // referred to as a filter-class in at least one. If no `web.xml` files are found, we assume
// that XML extraction was not enabled, and therefore consider all filter classes as live. // that XML extraction was not enabled, and therefore consider all filter classes as live.

View File

@@ -48,7 +48,7 @@ class CamelToBeanURI extends CamelToURI {
/** /**
* Gets the bean referenced by this URI. * Gets the bean referenced by this URI.
*/ */
SpringBean getRefBean() { result.getBeanIdentifier() = getBeanIdentifier() } SpringBean getRefBean() { result.getBeanIdentifier() = this.getBeanIdentifier() }
} }
/** /**

View File

@@ -31,7 +31,7 @@ class GuiceProvider extends Interface {
* A method that overrides the `get` method on the interface `com.google.inject.Provider`. * A method that overrides the `get` method on the interface `com.google.inject.Provider`.
*/ */
Method getAnOverridingGetMethod() { Method getAnOverridingGetMethod() {
exists(Method m | m.getSourceDeclaration() = getGetMethod() | result.overrides*(m)) exists(Method m | m.getSourceDeclaration() = this.getGetMethod() | result.overrides*(m))
} }
} }

View File

@@ -17,11 +17,11 @@ library class JAXBMarshalMethod extends Method {
} }
class JaxbAnnotationType extends AnnotationType { class JaxbAnnotationType extends AnnotationType {
JaxbAnnotationType() { getPackage().getName() = "javax.xml.bind.annotation" } JaxbAnnotationType() { this.getPackage().getName() = "javax.xml.bind.annotation" }
} }
class JaxbAnnotated extends Annotatable { class JaxbAnnotated extends Annotatable {
JaxbAnnotated() { getAnAnnotation().getType() instanceof JaxbAnnotationType } JaxbAnnotated() { this.getAnAnnotation().getType() instanceof JaxbAnnotationType }
predicate hasJaxbAnnotation(string name) { hasJaxbAnnotation(this, name) } predicate hasJaxbAnnotation(string name) { hasJaxbAnnotation(this, name) }
} }
@@ -62,8 +62,8 @@ class JaxbType extends Class {
* Gets the `XmlAccessType` associated with this class. * Gets the `XmlAccessType` associated with this class.
*/ */
XmlAccessType getXmlAccessType() { XmlAccessType getXmlAccessType() {
if exists(getDeclaredAccessType()) if exists(this.getDeclaredAccessType())
then result = getDeclaredAccessType() then result = this.getDeclaredAccessType()
else else
// Default access type, if not specified. // Default access type, if not specified.
result.isPublicMember() result.isPublicMember()
@@ -81,22 +81,22 @@ class XmlAccessType extends EnumConstant {
/** /**
* All public getter/setter pairs and public fields will be bound. * All public getter/setter pairs and public fields will be bound.
*/ */
predicate isPublicMember() { getName() = "PUBLIC_MEMBER" } predicate isPublicMember() { this.getName() = "PUBLIC_MEMBER" }
/** /**
* All non-static, non-transient fields will be bound. * All non-static, non-transient fields will be bound.
*/ */
predicate isField() { getName() = "FIELD" } predicate isField() { this.getName() = "FIELD" }
/** /**
* All getter/setter pairs will be bound. * All getter/setter pairs will be bound.
*/ */
predicate isProperty() { getName() = "PROPERTY" } predicate isProperty() { this.getName() = "PROPERTY" }
/** /**
* Nothing will be bound automatically. * Nothing will be bound automatically.
*/ */
predicate isNone() { getName() = "NONE" } predicate isNone() { this.getName() = "NONE" }
} }
/** /**
@@ -105,10 +105,10 @@ class XmlAccessType extends EnumConstant {
*/ */
class JaxbMemberAnnotation extends JaxbAnnotationType { class JaxbMemberAnnotation extends JaxbAnnotationType {
JaxbMemberAnnotation() { JaxbMemberAnnotation() {
hasName("XmlElement") or this.hasName("XmlElement") or
hasName("XmlAttribute") or this.hasName("XmlAttribute") or
hasName("XmlElementRefs") or this.hasName("XmlElementRefs") or
hasName("XmlElements") this.hasName("XmlElements")
} }
} }
@@ -121,14 +121,14 @@ private predicate isTransient(Member m) { hasJaxbAnnotation(m, "XmlTransient") }
class JaxbBoundField extends Field { class JaxbBoundField extends Field {
JaxbBoundField() { JaxbBoundField() {
// Fields cannot be static, because JAXB creates instances. // Fields cannot be static, because JAXB creates instances.
not isStatic() and not this.isStatic() and
// Fields cannot be final, because JAXB instantiates the object, then sets the properties. // Fields cannot be final, because JAXB instantiates the object, then sets the properties.
not isFinal() and not this.isFinal() and
// No transient fields are ever bound. // No transient fields are ever bound.
not isTransient(this) and not isTransient(this) and
( (
// Explicitly annotated to be bound. // Explicitly annotated to be bound.
exists(getAnAnnotation().getType().(JaxbMemberAnnotation)) exists(this.getAnAnnotation().getType().(JaxbMemberAnnotation))
or or
// Within a JAXB type which has an `XmlAcessType` that binds this field. // Within a JAXB type which has an `XmlAcessType` that binds this field.
exists(JaxbType type | this.getDeclaringType() = type | exists(JaxbType type | this.getDeclaringType() = type |
@@ -136,7 +136,7 @@ class JaxbBoundField extends Field {
type.getXmlAccessType().isField() type.getXmlAccessType().isField()
or or
// Only public fields are automatically bound in this access type. // Only public fields are automatically bound in this access type.
type.getXmlAccessType().isPublicMember() and isPublic() type.getXmlAccessType().isPublicMember() and this.isPublic()
) )
) )
} }
@@ -157,7 +157,7 @@ library class GetterOrSetterMethod extends Method {
* Holds if this method has a "pair"ed method, e.g. whether there is an equivalent getter if this * Holds if this method has a "pair"ed method, e.g. whether there is an equivalent getter if this
* is a setter, and vice versa. * is a setter, and vice versa.
*/ */
predicate isProperty() { exists(getPair()) } predicate isProperty() { exists(this.getPair()) }
/** /**
* Gets the "pair" method, if one exists; that is, the getter if this is a setter, and vice versa. * Gets the "pair" method, if one exists; that is, the getter if this is a setter, and vice versa.
@@ -183,16 +183,16 @@ class JaxbBoundGetterSetter extends GetterOrSetterMethod {
this.getField() instanceof JaxbBoundField this.getField() instanceof JaxbBoundField
or or
// An annotation on this method or the pair that indicate that it is a valid setter/getter. // An annotation on this method or the pair that indicate that it is a valid setter/getter.
getThisOrPair().getAnAnnotation().getType() instanceof JaxbMemberAnnotation this.getThisOrPair().getAnAnnotation().getType() instanceof JaxbMemberAnnotation
or or
// Within a JAXB type which has an `XmlAcessType` that binds this method. // Within a JAXB type which has an `XmlAcessType` that binds this method.
exists(JaxbType c | this.getDeclaringType() = c | exists(JaxbType c | this.getDeclaringType() = c |
// If this is a "property" - both a setter and getter present for the XML element or attribute // If this is a "property" - both a setter and getter present for the XML element or attribute
// - the `XmlAccessType` of the declaring type may cause this property to be bound. // - the `XmlAccessType` of the declaring type may cause this property to be bound.
isProperty() and this.isProperty() and
( (
// In the `PUBLIC_MEMBER` case all public properties are considered bound. // In the `PUBLIC_MEMBER` case all public properties are considered bound.
c.getXmlAccessType().isPublicMember() and isPublic() c.getXmlAccessType().isPublicMember() and this.isPublic()
or or
// In "property" all properties are considered bound. // In "property" all properties are considered bound.
c.getXmlAccessType().isProperty() c.getXmlAccessType().isProperty()

View File

@@ -64,5 +64,5 @@ class RunWithAnnotation extends Annotation {
/** /**
* Gets the runner that will be used. * Gets the runner that will be used.
*/ */
Type getRunner() { result = getValue("value").(TypeLiteral).getReferencedType() } Type getRunner() { result = this.getValue("value").(TypeLiteral).getReferencedType() }
} }

View File

@@ -7,31 +7,31 @@ private import semmle.code.java.dataflow.DataFlow
private class ObjectMapper extends RefType { private class ObjectMapper extends RefType {
ObjectMapper() { ObjectMapper() {
getASupertype*().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectMapper") this.getASupertype*().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectMapper")
} }
} }
/** A builder for building Jackson's `JsonMapper`. */ /** A builder for building Jackson's `JsonMapper`. */
class MapperBuilder extends RefType { class MapperBuilder extends RefType {
MapperBuilder() { MapperBuilder() {
hasQualifiedName("com.fasterxml.jackson.databind.cfg", "MapperBuilder<JsonMapper,Builder>") this.hasQualifiedName("com.fasterxml.jackson.databind.cfg", "MapperBuilder<JsonMapper,Builder>")
} }
} }
private class JsonFactory extends RefType { private class JsonFactory extends RefType {
JsonFactory() { hasQualifiedName("com.fasterxml.jackson.core", "JsonFactory") } JsonFactory() { this.hasQualifiedName("com.fasterxml.jackson.core", "JsonFactory") }
} }
private class JsonParser extends RefType { private class JsonParser extends RefType {
JsonParser() { hasQualifiedName("com.fasterxml.jackson.core", "JsonParser") } JsonParser() { this.hasQualifiedName("com.fasterxml.jackson.core", "JsonParser") }
} }
/** A type descriptor in Jackson libraries. For example, `java.lang.Class`. */ /** A type descriptor in Jackson libraries. For example, `java.lang.Class`. */
class JacksonTypeDescriptorType extends RefType { class JacksonTypeDescriptorType extends RefType {
JacksonTypeDescriptorType() { JacksonTypeDescriptorType() {
this instanceof TypeClass or this instanceof TypeClass or
hasQualifiedName("com.fasterxml.jackson.databind", "JavaType") or this.hasQualifiedName("com.fasterxml.jackson.databind", "JavaType") or
hasQualifiedName("com.fasterxml.jackson.core.type", "TypeReference") this.hasQualifiedName("com.fasterxml.jackson.core.type", "TypeReference")
} }
} }

View File

@@ -41,39 +41,39 @@ class TypeLdapName extends Class {
/** A method with the name `addAll` declared in `javax.naming.ldap.LdapName`. */ /** A method with the name `addAll` declared in `javax.naming.ldap.LdapName`. */
class MethodLdapNameAddAll extends Method { class MethodLdapNameAddAll extends Method {
MethodLdapNameAddAll() { MethodLdapNameAddAll() {
getDeclaringType() instanceof TypeLdapName and this.getDeclaringType() instanceof TypeLdapName and
hasName("addAll") this.hasName("addAll")
} }
} }
/** A method with the name `clone` declared in `javax.naming.ldap.LdapName`. */ /** A method with the name `clone` declared in `javax.naming.ldap.LdapName`. */
class MethodLdapNameClone extends Method { class MethodLdapNameClone extends Method {
MethodLdapNameClone() { MethodLdapNameClone() {
getDeclaringType() instanceof TypeLdapName and this.getDeclaringType() instanceof TypeLdapName and
hasName("clone") this.hasName("clone")
} }
} }
/** A method with the name `getAll` declared in `javax.naming.ldap.LdapName`. */ /** A method with the name `getAll` declared in `javax.naming.ldap.LdapName`. */
class MethodLdapNameGetAll extends Method { class MethodLdapNameGetAll extends Method {
MethodLdapNameGetAll() { MethodLdapNameGetAll() {
getDeclaringType() instanceof TypeLdapName and this.getDeclaringType() instanceof TypeLdapName and
hasName("getAll") this.hasName("getAll")
} }
} }
/** A method with the name `getRdns` declared in `javax.naming.ldap.LdapName`. */ /** A method with the name `getRdns` declared in `javax.naming.ldap.LdapName`. */
class MethodLdapNameGetRdns extends Method { class MethodLdapNameGetRdns extends Method {
MethodLdapNameGetRdns() { MethodLdapNameGetRdns() {
getDeclaringType() instanceof TypeLdapName and this.getDeclaringType() instanceof TypeLdapName and
hasName("getRdns") this.hasName("getRdns")
} }
} }
/** A method with the name `toString` declared in `javax.naming.ldap.LdapName`. */ /** A method with the name `toString` declared in `javax.naming.ldap.LdapName`. */
class MethodLdapNameToString extends Method { class MethodLdapNameToString extends Method {
MethodLdapNameToString() { MethodLdapNameToString() {
getDeclaringType() instanceof TypeLdapName and this.getDeclaringType() instanceof TypeLdapName and
hasName("toString") this.hasName("toString")
} }
} }

View File

@@ -11,8 +11,8 @@ private import semmle.code.java.dataflow.FlowSteps
*/ */
class Kryo extends RefType { class Kryo extends RefType {
Kryo() { Kryo() {
hasQualifiedName("com.esotericsoftware.kryo", "Kryo") or this.hasQualifiedName("com.esotericsoftware.kryo", "Kryo") or
hasQualifiedName("com.esotericsoftware.kryo5", "Kryo") this.hasQualifiedName("com.esotericsoftware.kryo5", "Kryo")
} }
} }
@@ -21,8 +21,8 @@ class Kryo extends RefType {
*/ */
class KryoInput extends RefType { class KryoInput extends RefType {
KryoInput() { KryoInput() {
hasQualifiedName("com.esotericsoftware.kryo.io", "Input") or this.hasQualifiedName("com.esotericsoftware.kryo.io", "Input") or
hasQualifiedName("com.esotericsoftware.kryo5.io", "Input") this.hasQualifiedName("com.esotericsoftware.kryo5.io", "Input")
} }
} }
@@ -31,8 +31,8 @@ class KryoInput extends RefType {
*/ */
class KryoPool extends RefType { class KryoPool extends RefType {
KryoPool() { KryoPool() {
hasQualifiedName("com.esotericsoftware.kryo.pool", "KryoPool") or this.hasQualifiedName("com.esotericsoftware.kryo.pool", "KryoPool") or
hasQualifiedName("com.esotericsoftware.kryo5.pool", "KryoPool") this.hasQualifiedName("com.esotericsoftware.kryo5.pool", "KryoPool")
} }
} }
@@ -41,8 +41,8 @@ class KryoPool extends RefType {
*/ */
class KryoPoolBuilder extends RefType { class KryoPoolBuilder extends RefType {
KryoPoolBuilder() { KryoPoolBuilder() {
hasQualifiedName("com.esotericsoftware.kryo.pool", "KryoPool$Builder") or this.hasQualifiedName("com.esotericsoftware.kryo.pool", "KryoPool$Builder") or
hasQualifiedName("com.esotericsoftware.kryo5.pool", "KryoPool$Builder") this.hasQualifiedName("com.esotericsoftware.kryo5.pool", "KryoPool$Builder")
} }
} }
@@ -51,10 +51,10 @@ class KryoPoolBuilder extends RefType {
*/ */
class KryoPoolBuilderMethod extends Method { class KryoPoolBuilderMethod extends Method {
KryoPoolBuilderMethod() { KryoPoolBuilderMethod() {
getDeclaringType() instanceof KryoPoolBuilder and this.getDeclaringType() instanceof KryoPoolBuilder and
( (
getReturnType() instanceof KryoPoolBuilder or this.getReturnType() instanceof KryoPoolBuilder or
getReturnType() instanceof KryoPool this.getReturnType() instanceof KryoPool
) )
} }
} }
@@ -92,7 +92,7 @@ class KryoEnableWhiteListing extends MethodAccess {
*/ */
class KryoPoolRunMethod extends Method { class KryoPoolRunMethod extends Method {
KryoPoolRunMethod() { KryoPoolRunMethod() {
getDeclaringType() instanceof KryoPool and this.getDeclaringType() instanceof KryoPool and
hasName("run") this.hasName("run")
} }
} }

View File

@@ -11,8 +11,8 @@ import java
*/ */
class MockitoVerifyMethod extends Method { class MockitoVerifyMethod extends Method {
MockitoVerifyMethod() { MockitoVerifyMethod() {
getDeclaringType().getPackage().getName().matches("org.mockito%") and this.getDeclaringType().getPackage().getName().matches("org.mockito%") and
hasName("verify") this.hasName("verify")
} }
} }
@@ -21,7 +21,7 @@ class MockitoVerifyMethod extends Method {
*/ */
class MockitoVerifiedMethodAccess extends MethodAccess { class MockitoVerifiedMethodAccess extends MethodAccess {
MockitoVerifiedMethodAccess() { MockitoVerifiedMethodAccess() {
getQualifier().(MethodAccess).getMethod() instanceof MockitoVerifyMethod this.getQualifier().(MethodAccess).getMethod() instanceof MockitoVerifyMethod
} }
} }
@@ -41,8 +41,8 @@ class MockitoMockableType extends ClassOrInterface {
*/ */
class MockitoInitMocks extends Method { class MockitoInitMocks extends Method {
MockitoInitMocks() { MockitoInitMocks() {
getDeclaringType().hasQualifiedName("org.mockito", "MockitoAnnotations") and this.getDeclaringType().hasQualifiedName("org.mockito", "MockitoAnnotations") and
hasName("initMocks") this.hasName("initMocks")
} }
} }
@@ -61,10 +61,10 @@ class MockitoInitedTest extends Class {
or or
// Call to `MockitoAnnotations.initMocks()`, either by the constructor or by a `@Before` method. // Call to `MockitoAnnotations.initMocks()`, either by the constructor or by a `@Before` method.
exists(MockitoInitMocks initMocks | exists(MockitoInitMocks initMocks |
getAConstructor().calls*(initMocks) this.getAConstructor().calls*(initMocks)
or or
exists(Method m | exists(Method m |
m = getAnAncestor().getAMethod() and m = this.getAnAncestor().getAMethod() and
( (
m.hasAnnotation("org.junit", "Before") or m.hasAnnotation("org.junit", "Before") or
m.hasAnnotation("org.testng.annotations", "BeforeMethod") m.hasAnnotation("org.testng.annotations", "BeforeMethod")
@@ -85,8 +85,8 @@ class MockitoInitedTest extends Class {
*/ */
class MockitoAnnotation extends Annotation { class MockitoAnnotation extends Annotation {
MockitoAnnotation() { MockitoAnnotation() {
getType().getPackage().getName().matches("org.mockito") or this.getType().getPackage().getName().matches("org.mockito") or
getType().getPackage().getName().matches("org.mockito.%") this.getType().getPackage().getName().matches("org.mockito.%")
} }
} }
@@ -95,11 +95,11 @@ class MockitoAnnotation extends Annotation {
*/ */
class MockitoExclusiveAnnotation extends MockitoAnnotation { class MockitoExclusiveAnnotation extends MockitoAnnotation {
MockitoExclusiveAnnotation() { MockitoExclusiveAnnotation() {
getType().hasQualifiedName("org.mockito", "Mock") or this.getType().hasQualifiedName("org.mockito", "Mock") or
getType().hasQualifiedName("org.mockito", "MockitoAnnotations$Mock") or this.getType().hasQualifiedName("org.mockito", "MockitoAnnotations$Mock") or
getType().hasQualifiedName("org.mockito", "InjectMocks") or this.getType().hasQualifiedName("org.mockito", "InjectMocks") or
getType().hasQualifiedName("org.mockito", "Spy") or this.getType().hasQualifiedName("org.mockito", "Spy") or
getType().hasQualifiedName("org.mockito", "Captor") this.getType().hasQualifiedName("org.mockito", "Captor")
} }
} }
@@ -107,16 +107,16 @@ class MockitoExclusiveAnnotation extends MockitoAnnotation {
* A field which has a Mockito annotation. * A field which has a Mockito annotation.
*/ */
class MockitoAnnotatedField extends Field { class MockitoAnnotatedField extends Field {
MockitoAnnotatedField() { getAnAnnotation() instanceof MockitoAnnotation } MockitoAnnotatedField() { this.getAnAnnotation() instanceof MockitoAnnotation }
/** /**
* Holds if this field will be processed by Mockito. * Holds if this field will be processed by Mockito.
*/ */
predicate isValid() { predicate isValid() {
// Mockito annotations are never parsed if the test isn't properly initialized. // Mockito annotations are never parsed if the test isn't properly initialized.
getDeclaringType() instanceof MockitoInitedTest and this.getDeclaringType() instanceof MockitoInitedTest and
// There should only be one "exclusive" mockito annotation per field. // There should only be one "exclusive" mockito annotation per field.
count(getAnAnnotation().(MockitoExclusiveAnnotation)) = 1 count(this.getAnAnnotation().(MockitoExclusiveAnnotation)) = 1
} }
} }
@@ -125,16 +125,16 @@ class MockitoAnnotatedField extends Field {
*/ */
class MockitoMockedField extends MockitoAnnotatedField { class MockitoMockedField extends MockitoAnnotatedField {
MockitoMockedField() { MockitoMockedField() {
hasAnnotation("org.mockito", "Mock") this.hasAnnotation("org.mockito", "Mock")
or or
// Deprecated style. // Deprecated style.
hasAnnotation("org.mockito", "MockitoAnnotations$Mock") this.hasAnnotation("org.mockito", "MockitoAnnotations$Mock")
} }
override predicate isValid() { override predicate isValid() {
super.isValid() and super.isValid() and
// The type must also be mockable, otherwise it will not be initialized. // The type must also be mockable, otherwise it will not be initialized.
getType() instanceof MockitoMockableType this.getType() instanceof MockitoMockableType
} }
/** /**
@@ -142,12 +142,13 @@ class MockitoMockedField extends MockitoAnnotatedField {
*/ */
predicate isReferencedByInjection() { predicate isReferencedByInjection() {
exists(MockitoInjectedField injectedField | exists(MockitoInjectedField injectedField |
injectedField.getDeclaringType() = getDeclaringType() injectedField.getDeclaringType() = this.getDeclaringType()
| |
// A `@Mock` is injected if it is used in one of the invoked callables (constructor or // A `@Mock` is injected if it is used in one of the invoked callables (constructor or
// setter), or injected directly onto a field. // setter), or injected directly onto a field.
getType().(RefType).getAnAncestor() = injectedField.getAnInvokedCallable().getAParamType() or this.getType().(RefType).getAnAncestor() =
getType().(RefType).getAnAncestor() = injectedField.getASetField().getType() injectedField.getAnInvokedCallable().getAParamType() or
this.getType().(RefType).getAnAncestor() = injectedField.getASetField().getType()
) )
} }
} }
@@ -156,25 +157,25 @@ class MockitoMockedField extends MockitoAnnotatedField {
* A field annotated with `@InjectMocks`. * A field annotated with `@InjectMocks`.
*/ */
class MockitoInjectedField extends MockitoAnnotatedField { class MockitoInjectedField extends MockitoAnnotatedField {
MockitoInjectedField() { hasAnnotation("org.mockito", "InjectMocks") } MockitoInjectedField() { this.hasAnnotation("org.mockito", "InjectMocks") }
override predicate isValid() { override predicate isValid() {
super.isValid() and super.isValid() and
( (
// If we need to initialize the field, it is only valid if the type is a `Class` that is not // If we need to initialize the field, it is only valid if the type is a `Class` that is not
// local, is static if it is a nested class, and is not abstract. // local, is static if it is a nested class, and is not abstract.
exists(getInitializer()) exists(this.getInitializer())
or or
exists(Class c | c = getType() | exists(Class c | c = this.getType() |
not c.isLocal() and not c.isLocal() and
(getType() instanceof NestedClass implies c.(NestedClass).isStatic()) and (this.getType() instanceof NestedClass implies c.(NestedClass).isStatic()) and
not c.isAbstract() not c.isAbstract()
) )
) and ) and
( (
// If neither of these is true, then mockito will fail to initialize this field. // If neither of these is true, then mockito will fail to initialize this field.
usingConstructorInjection() or this.usingConstructorInjection() or
usingPropertyInjection() this.usingPropertyInjection()
) )
} }
@@ -184,7 +185,8 @@ class MockitoInjectedField extends MockitoAnnotatedField {
* Note: this does not include the no-arg constructor. * Note: this does not include the no-arg constructor.
*/ */
predicate usingConstructorInjection() { predicate usingConstructorInjection() {
not exists(getInitializer()) and exists(getMockInjectedClass().getAMostMockableConstructor()) not exists(this.getInitializer()) and
exists(this.getMockInjectedClass().getAMostMockableConstructor())
} }
/** /**
@@ -194,10 +196,10 @@ class MockitoInjectedField extends MockitoAnnotatedField {
* constructor, in addition to any property. * constructor, in addition to any property.
*/ */
predicate usingPropertyInjection() { predicate usingPropertyInjection() {
not usingConstructorInjection() and not this.usingConstructorInjection() and
( (
exists(getInitializer()) or exists(this.getInitializer()) or
exists(getMockInjectedClass().getNoArgsConstructor()) exists(this.getMockInjectedClass().getNoArgsConstructor())
) )
} }
@@ -212,18 +214,18 @@ class MockitoInjectedField extends MockitoAnnotatedField {
Callable getAnInvokedCallable() { Callable getAnInvokedCallable() {
exists(MockitoMockInjectedClass mockInjectedClass | exists(MockitoMockInjectedClass mockInjectedClass |
// This is the type we are constructing/injecting. // This is the type we are constructing/injecting.
mockInjectedClass = getType() mockInjectedClass = this.getType()
| |
if usingConstructorInjection() if this.usingConstructorInjection()
then then
// If there is no initializer for this field, and there is a most mockable constructor, // If there is no initializer for this field, and there is a most mockable constructor,
// then we are doing a parameterized injection of mocks into a most mockable constructor. // then we are doing a parameterized injection of mocks into a most mockable constructor.
result = mockInjectedClass.getAMostMockableConstructor() result = mockInjectedClass.getAMostMockableConstructor()
else else
if usingPropertyInjection() if this.usingPropertyInjection()
then then
// We will call the no-arg constructor if the field wasn't initialized. // We will call the no-arg constructor if the field wasn't initialized.
not exists(getInitializer()) and not exists(this.getInitializer()) and
result = mockInjectedClass.getNoArgsConstructor() result = mockInjectedClass.getNoArgsConstructor()
or or
// Perform property injection into setter fields, but only where there exists a mock // Perform property injection into setter fields, but only where there exists a mock
@@ -249,9 +251,9 @@ class MockitoInjectedField extends MockitoAnnotatedField {
* Field injection only occurs if property injection and not constructor injection is used. * Field injection only occurs if property injection and not constructor injection is used.
*/ */
Field getASetField() { Field getASetField() {
if usingPropertyInjection() if this.usingPropertyInjection()
then then
result = getMockInjectedClass().getASetField() and result = this.getMockInjectedClass().getASetField() and
exists(MockitoMockedField mockedField | exists(MockitoMockedField mockedField |
mockedField.getDeclaringType() = this.getDeclaringType() and mockedField.getDeclaringType() = this.getDeclaringType() and
mockedField.isValid() mockedField.isValid()
@@ -268,15 +270,15 @@ class MockitoInjectedField extends MockitoAnnotatedField {
* A field annotated with the Mockito `@Spy` annotation. * A field annotated with the Mockito `@Spy` annotation.
*/ */
class MockitoSpiedField extends MockitoAnnotatedField { class MockitoSpiedField extends MockitoAnnotatedField {
MockitoSpiedField() { hasAnnotation("org.mockito", "Spy") } MockitoSpiedField() { this.hasAnnotation("org.mockito", "Spy") }
override predicate isValid() { override predicate isValid() {
super.isValid() and super.isValid() and
( (
exists(getInitializer()) exists(this.getInitializer())
or or
exists(Constructor c | exists(Constructor c |
c = getType().(RefType).getAConstructor() and c.getNumberOfParameters() = 0 c = this.getType().(RefType).getAConstructor() and c.getNumberOfParameters() = 0
) )
) )
} }
@@ -284,7 +286,7 @@ class MockitoSpiedField extends MockitoAnnotatedField {
/** /**
* Holds if construction ever occurs. * Holds if construction ever occurs.
*/ */
predicate isConstructed() { not exists(getInitializer()) } predicate isConstructed() { not exists(this.getInitializer()) }
} }
private int mockableParameterCount(Constructor constructor) { private int mockableParameterCount(Constructor constructor) {
@@ -312,8 +314,8 @@ library class MockitoMockInjectedClass extends Class {
* Mockito will call only one of them, but which one is dependent on the JVM... * Mockito will call only one of them, but which one is dependent on the JVM...
*/ */
Constructor getAMostMockableConstructor() { Constructor getAMostMockableConstructor() {
result = getAConstructor() and result = this.getAConstructor() and
mockableParameterCount(result) = max(mockableParameterCount(getAConstructor())) and mockableParameterCount(result) = max(mockableParameterCount(this.getAConstructor())) and
result.getNumberOfParameters() > 0 result.getNumberOfParameters() > 0
} }
@@ -331,7 +333,7 @@ library class MockitoMockInjectedClass extends Class {
* it sets. * it sets.
*/ */
Method getASetterMethod() { Method getASetterMethod() {
result = getAMethod() and result = this.getAMethod() and
exists(MockitoSettableField settableField | result = settableField.getSetterMethod()) exists(MockitoSettableField settableField | result = settableField.getSetterMethod())
} }
@@ -342,7 +344,7 @@ library class MockitoMockInjectedClass extends Class {
* setter method. * setter method.
*/ */
MockitoSettableField getASetField() { MockitoSettableField getASetField() {
result = getAField() and result = this.getAField() and
not exists(result.getSetterMethod()) not exists(result.getSetterMethod())
} }
} }
@@ -353,8 +355,8 @@ library class MockitoMockInjectedClass extends Class {
*/ */
class MockitoSettableField extends Field { class MockitoSettableField extends Field {
MockitoSettableField() { MockitoSettableField() {
not isFinal() and not this.isFinal() and
not isStatic() and not this.isStatic() and
exists(MockitoMockInjectedClass injectedClass | injectedClass = this.getDeclaringType()) exists(MockitoMockInjectedClass injectedClass | injectedClass = this.getDeclaringType())
} }

View File

@@ -6,39 +6,39 @@ import semmle.code.java.Type
/** The type `java.net.URLConnection`. */ /** The type `java.net.URLConnection`. */
class TypeUrlConnection extends RefType { class TypeUrlConnection extends RefType {
TypeUrlConnection() { hasQualifiedName("java.net", "URLConnection") } TypeUrlConnection() { this.hasQualifiedName("java.net", "URLConnection") }
} }
/** The type `java.net.Socket`. */ /** The type `java.net.Socket`. */
class TypeSocket extends RefType { class TypeSocket extends RefType {
TypeSocket() { hasQualifiedName("java.net", "Socket") } TypeSocket() { this.hasQualifiedName("java.net", "Socket") }
} }
/** The type `java.net.URL`. */ /** The type `java.net.URL`. */
class TypeUrl extends RefType { class TypeUrl extends RefType {
TypeUrl() { hasQualifiedName("java.net", "URL") } TypeUrl() { this.hasQualifiedName("java.net", "URL") }
} }
/** The type `java.net.URI`. */ /** The type `java.net.URI`. */
class TypeUri extends RefType { class TypeUri extends RefType {
TypeUri() { hasQualifiedName("java.net", "URI") } TypeUri() { this.hasQualifiedName("java.net", "URI") }
} }
/** The method `java.net.URLConnection::getInputStream`. */ /** The method `java.net.URLConnection::getInputStream`. */
class URLConnectionGetInputStreamMethod extends Method { class URLConnectionGetInputStreamMethod extends Method {
URLConnectionGetInputStreamMethod() { URLConnectionGetInputStreamMethod() {
getDeclaringType() instanceof TypeUrlConnection and this.getDeclaringType() instanceof TypeUrlConnection and
hasName("getInputStream") and this.hasName("getInputStream") and
hasNoParameters() this.hasNoParameters()
} }
} }
/** The method `java.net.Socket::getInputStream`. */ /** The method `java.net.Socket::getInputStream`. */
class SocketGetInputStreamMethod extends Method { class SocketGetInputStreamMethod extends Method {
SocketGetInputStreamMethod() { SocketGetInputStreamMethod() {
getDeclaringType() instanceof TypeSocket and this.getDeclaringType() instanceof TypeSocket and
hasName("getInputStream") and this.hasName("getInputStream") and
hasNoParameters() this.hasNoParameters()
} }
} }

View File

@@ -30,7 +30,7 @@ class ProtobufMessageLite extends Interface {
* Gets a static method named `parseFrom` (or similar) declared on a subtype of the `MessageLite` interface. * Gets a static method named `parseFrom` (or similar) declared on a subtype of the `MessageLite` interface.
*/ */
Method getAParseFromMethod() { Method getAParseFromMethod() {
result = getASubtype+().getAMethod() and result = this.getASubtype+().getAMethod() and
result.getName().matches("parse%From") and result.getName().matches("parse%From") and
result.isStatic() result.isStatic()
} }

View File

@@ -37,14 +37,14 @@ private class SafeYamlConstructionFlowConfig extends DataFlow2::Configuration {
src.asExpr() instanceof SafeSnakeYamlConstruction src.asExpr() instanceof SafeSnakeYamlConstruction
} }
override predicate isSink(DataFlow::Node sink) { sink = yamlClassInstanceExprArgument(_) } override predicate isSink(DataFlow::Node sink) { sink = this.yamlClassInstanceExprArgument(_) }
private DataFlow::ExprNode yamlClassInstanceExprArgument(ClassInstanceExpr cie) { private DataFlow::ExprNode yamlClassInstanceExprArgument(ClassInstanceExpr cie) {
cie.getConstructedType() instanceof Yaml and cie.getConstructedType() instanceof Yaml and
result.getExpr() = cie.getArgument(0) result.getExpr() = cie.getArgument(0)
} }
ClassInstanceExpr getSafeYaml() { hasFlowTo(yamlClassInstanceExprArgument(result)) } ClassInstanceExpr getSafeYaml() { this.hasFlowTo(this.yamlClassInstanceExprArgument(result)) }
} }
/** /**
@@ -70,13 +70,13 @@ private class SafeYamlFlowConfig extends DataFlow3::Configuration {
override predicate isSource(DataFlow::Node src) { src.asExpr() instanceof SafeYaml } override predicate isSource(DataFlow::Node src) { src.asExpr() instanceof SafeYaml }
override predicate isSink(DataFlow::Node sink) { sink = yamlParseQualifier(_) } override predicate isSink(DataFlow::Node sink) { sink = this.yamlParseQualifier(_) }
private DataFlow::ExprNode yamlParseQualifier(SnakeYamlParse syp) { private DataFlow::ExprNode yamlParseQualifier(SnakeYamlParse syp) {
result.getExpr() = syp.getQualifier() result.getExpr() = syp.getQualifier()
} }
SnakeYamlParse getASafeSnakeYamlParse() { hasFlowTo(yamlParseQualifier(result)) } SnakeYamlParse getASafeSnakeYamlParse() { this.hasFlowTo(this.yamlParseQualifier(result)) }
} }
/** /**

View File

@@ -77,8 +77,8 @@ class TypeLdapOperations extends Interface {
*/ */
class MethodSpringLdapTemplateAuthenticate extends Method { class MethodSpringLdapTemplateAuthenticate extends Method {
MethodSpringLdapTemplateAuthenticate() { MethodSpringLdapTemplateAuthenticate() {
getDeclaringType() instanceof TypeSpringLdapTemplate and this.getDeclaringType() instanceof TypeSpringLdapTemplate and
hasName("authenticate") this.hasName("authenticate")
} }
} }
@@ -88,8 +88,8 @@ class MethodSpringLdapTemplateAuthenticate extends Method {
*/ */
class MethodSpringLdapTemplateFind extends Method { class MethodSpringLdapTemplateFind extends Method {
MethodSpringLdapTemplateFind() { MethodSpringLdapTemplateFind() {
getDeclaringType() instanceof TypeSpringLdapTemplate and this.getDeclaringType() instanceof TypeSpringLdapTemplate and
hasName("find") this.hasName("find")
} }
} }
@@ -99,8 +99,8 @@ class MethodSpringLdapTemplateFind extends Method {
*/ */
class MethodSpringLdapTemplateFindOne extends Method { class MethodSpringLdapTemplateFindOne extends Method {
MethodSpringLdapTemplateFindOne() { MethodSpringLdapTemplateFindOne() {
getDeclaringType() instanceof TypeSpringLdapTemplate and this.getDeclaringType() instanceof TypeSpringLdapTemplate and
hasName("findOne") this.hasName("findOne")
} }
} }
@@ -110,8 +110,8 @@ class MethodSpringLdapTemplateFindOne extends Method {
*/ */
class MethodSpringLdapTemplateSearch extends Method { class MethodSpringLdapTemplateSearch extends Method {
MethodSpringLdapTemplateSearch() { MethodSpringLdapTemplateSearch() {
getDeclaringType() instanceof TypeSpringLdapTemplate and this.getDeclaringType() instanceof TypeSpringLdapTemplate and
hasName("search") this.hasName("search")
} }
} }
@@ -121,8 +121,8 @@ class MethodSpringLdapTemplateSearch extends Method {
*/ */
class MethodSpringLdapTemplateSearchForContext extends Method { class MethodSpringLdapTemplateSearchForContext extends Method {
MethodSpringLdapTemplateSearchForContext() { MethodSpringLdapTemplateSearchForContext() {
getDeclaringType() instanceof TypeSpringLdapTemplate and this.getDeclaringType() instanceof TypeSpringLdapTemplate and
hasName("searchForContext") this.hasName("searchForContext")
} }
} }
@@ -132,8 +132,8 @@ class MethodSpringLdapTemplateSearchForContext extends Method {
*/ */
class MethodSpringLdapTemplateSearchForObject extends Method { class MethodSpringLdapTemplateSearchForObject extends Method {
MethodSpringLdapTemplateSearchForObject() { MethodSpringLdapTemplateSearchForObject() {
getDeclaringType() instanceof TypeSpringLdapTemplate and this.getDeclaringType() instanceof TypeSpringLdapTemplate and
hasName("searchForObject") this.hasName("searchForObject")
} }
} }
@@ -143,8 +143,8 @@ class MethodSpringLdapTemplateSearchForObject extends Method {
*/ */
class MethodSpringLdapQueryBuilderFilter extends Method { class MethodSpringLdapQueryBuilderFilter extends Method {
MethodSpringLdapQueryBuilderFilter() { MethodSpringLdapQueryBuilderFilter() {
getDeclaringType() instanceof TypeSpringLdapQueryBuilder and this.getDeclaringType() instanceof TypeSpringLdapQueryBuilder and
hasName("filter") this.hasName("filter")
} }
} }
@@ -154,8 +154,8 @@ class MethodSpringLdapQueryBuilderFilter extends Method {
*/ */
class MethodSpringLdapQueryBuilderBase extends Method { class MethodSpringLdapQueryBuilderBase extends Method {
MethodSpringLdapQueryBuilderBase() { MethodSpringLdapQueryBuilderBase() {
getDeclaringType() instanceof TypeSpringLdapQueryBuilder and this.getDeclaringType() instanceof TypeSpringLdapQueryBuilder and
hasName("base") this.hasName("base")
} }
} }
@@ -165,8 +165,8 @@ class MethodSpringLdapQueryBuilderBase extends Method {
*/ */
class MethodSpringLdapNameBuilderNewInstance extends Method { class MethodSpringLdapNameBuilderNewInstance extends Method {
MethodSpringLdapNameBuilderNewInstance() { MethodSpringLdapNameBuilderNewInstance() {
getDeclaringType() instanceof TypeSpringLdapNameBuilder and this.getDeclaringType() instanceof TypeSpringLdapNameBuilder and
hasName("newInstance") this.hasName("newInstance")
} }
} }
@@ -176,8 +176,8 @@ class MethodSpringLdapNameBuilderNewInstance extends Method {
*/ */
class MethodSpringLdapNameBuilderAdd extends Method { class MethodSpringLdapNameBuilderAdd extends Method {
MethodSpringLdapNameBuilderAdd() { MethodSpringLdapNameBuilderAdd() {
getDeclaringType() instanceof TypeSpringLdapNameBuilder and this.getDeclaringType() instanceof TypeSpringLdapNameBuilder and
hasName("add") this.hasName("add")
} }
} }
@@ -187,8 +187,8 @@ class MethodSpringLdapNameBuilderAdd extends Method {
*/ */
class MethodSpringLdapNameBuilderBuild extends Method { class MethodSpringLdapNameBuilderBuild extends Method {
MethodSpringLdapNameBuilderBuild() { MethodSpringLdapNameBuilderBuild() {
getDeclaringType() instanceof TypeSpringLdapNameBuilder and this.getDeclaringType() instanceof TypeSpringLdapNameBuilder and
hasName("build") this.hasName("build")
} }
} }
@@ -198,7 +198,7 @@ class MethodSpringLdapNameBuilderBuild extends Method {
*/ */
class MethodSpringLdapUtilsNewLdapName extends Method { class MethodSpringLdapUtilsNewLdapName extends Method {
MethodSpringLdapUtilsNewLdapName() { MethodSpringLdapUtilsNewLdapName() {
getDeclaringType() instanceof TypeSpringLdapUtils and this.getDeclaringType() instanceof TypeSpringLdapUtils and
hasName("newLdapName") this.hasName("newLdapName")
} }
} }

View File

@@ -27,7 +27,7 @@ class ThriftIface extends Interface {
Method getAnImplementingMethod() { Method getAnImplementingMethod() {
result.getDeclaringType().(Class).getASupertype+() = this and result.getDeclaringType().(Class).getASupertype+() = this and
result.overrides(getAMethod()) and result.overrides(this.getAMethod()) and
not result.getFile() = this.getFile() not result.getFile() = this.getFile()
} }
} }

View File

@@ -35,79 +35,79 @@ class TypeUnboundIdLDAPConnection extends Class {
/** A method with the name `setBaseDN` declared in `com.unboundid.ldap.sdk.SearchRequest`. */ /** A method with the name `setBaseDN` declared in `com.unboundid.ldap.sdk.SearchRequest`. */
class MethodUnboundIdSearchRequestSetBaseDN extends Method { class MethodUnboundIdSearchRequestSetBaseDN extends Method {
MethodUnboundIdSearchRequestSetBaseDN() { MethodUnboundIdSearchRequestSetBaseDN() {
getDeclaringType() instanceof TypeUnboundIdSearchRequest and this.getDeclaringType() instanceof TypeUnboundIdSearchRequest and
hasName("setBaseDN") this.hasName("setBaseDN")
} }
} }
/** A method with the name `setFilter` declared in `com.unboundid.ldap.sdk.SearchRequest`. */ /** A method with the name `setFilter` declared in `com.unboundid.ldap.sdk.SearchRequest`. */
class MethodUnboundIdSearchRequestSetFilter extends Method { class MethodUnboundIdSearchRequestSetFilter extends Method {
MethodUnboundIdSearchRequestSetFilter() { MethodUnboundIdSearchRequestSetFilter() {
getDeclaringType() instanceof TypeUnboundIdSearchRequest and this.getDeclaringType() instanceof TypeUnboundIdSearchRequest and
hasName("setFilter") this.hasName("setFilter")
} }
} }
/** A method with the name `create` declared in `com.unboundid.ldap.sdk.Filter`. */ /** A method with the name `create` declared in `com.unboundid.ldap.sdk.Filter`. */
class MethodUnboundIdFilterCreate extends Method { class MethodUnboundIdFilterCreate extends Method {
MethodUnboundIdFilterCreate() { MethodUnboundIdFilterCreate() {
getDeclaringType() instanceof TypeUnboundIdLdapFilter and this.getDeclaringType() instanceof TypeUnboundIdLdapFilter and
hasName("create") this.hasName("create")
} }
} }
/** A method with the name `createANDFilter` declared in `com.unboundid.ldap.sdk.Filter`. */ /** A method with the name `createANDFilter` declared in `com.unboundid.ldap.sdk.Filter`. */
class MethodUnboundIdFilterCreateANDFilter extends Method { class MethodUnboundIdFilterCreateANDFilter extends Method {
MethodUnboundIdFilterCreateANDFilter() { MethodUnboundIdFilterCreateANDFilter() {
getDeclaringType() instanceof TypeUnboundIdLdapFilter and this.getDeclaringType() instanceof TypeUnboundIdLdapFilter and
hasName("createANDFilter") this.hasName("createANDFilter")
} }
} }
/** A method with the name `createORFilter` declared in `com.unboundid.ldap.sdk.Filter`. */ /** A method with the name `createORFilter` declared in `com.unboundid.ldap.sdk.Filter`. */
class MethodUnboundIdFilterCreateORFilter extends Method { class MethodUnboundIdFilterCreateORFilter extends Method {
MethodUnboundIdFilterCreateORFilter() { MethodUnboundIdFilterCreateORFilter() {
getDeclaringType() instanceof TypeUnboundIdLdapFilter and this.getDeclaringType() instanceof TypeUnboundIdLdapFilter and
hasName("createORFilter") this.hasName("createORFilter")
} }
} }
/** A method with the name `createNOTFilter` declared in `com.unboundid.ldap.sdk.Filter`. */ /** A method with the name `createNOTFilter` declared in `com.unboundid.ldap.sdk.Filter`. */
class MethodUnboundIdFilterCreateNOTFilter extends Method { class MethodUnboundIdFilterCreateNOTFilter extends Method {
MethodUnboundIdFilterCreateNOTFilter() { MethodUnboundIdFilterCreateNOTFilter() {
getDeclaringType() instanceof TypeUnboundIdLdapFilter and this.getDeclaringType() instanceof TypeUnboundIdLdapFilter and
hasName("createNOTFilter") this.hasName("createNOTFilter")
} }
} }
/** A method with the name `simplifyFilter` declared in `com.unboundid.ldap.sdk.Filter`. */ /** A method with the name `simplifyFilter` declared in `com.unboundid.ldap.sdk.Filter`. */
class MethodUnboundIdFilterSimplifyFilter extends Method { class MethodUnboundIdFilterSimplifyFilter extends Method {
MethodUnboundIdFilterSimplifyFilter() { MethodUnboundIdFilterSimplifyFilter() {
getDeclaringType() instanceof TypeUnboundIdLdapFilter and this.getDeclaringType() instanceof TypeUnboundIdLdapFilter and
hasName("simplifyFilter") this.hasName("simplifyFilter")
} }
} }
/** A method with the name `search` declared in `com.unboundid.ldap.sdk.LDAPConnection`. */ /** A method with the name `search` declared in `com.unboundid.ldap.sdk.LDAPConnection`. */
class MethodUnboundIdLDAPConnectionSearch extends Method { class MethodUnboundIdLDAPConnectionSearch extends Method {
MethodUnboundIdLDAPConnectionSearch() { MethodUnboundIdLDAPConnectionSearch() {
getDeclaringType() instanceof TypeUnboundIdLDAPConnection and this.getDeclaringType() instanceof TypeUnboundIdLDAPConnection and
hasName("search") this.hasName("search")
} }
} }
/** A method with the name `asyncSearch` declared in `com.unboundid.ldap.sdk.LDAPConnection`. */ /** A method with the name `asyncSearch` declared in `com.unboundid.ldap.sdk.LDAPConnection`. */
class MethodUnboundIdLDAPConnectionAsyncSearch extends Method { class MethodUnboundIdLDAPConnectionAsyncSearch extends Method {
MethodUnboundIdLDAPConnectionAsyncSearch() { MethodUnboundIdLDAPConnectionAsyncSearch() {
getDeclaringType() instanceof TypeUnboundIdLDAPConnection and this.getDeclaringType() instanceof TypeUnboundIdLDAPConnection and
hasName("asyncSearch") this.hasName("asyncSearch")
} }
} }
/** A method with the name `searchForEntry` declared in `com.unboundid.ldap.sdk.LDAPConnection`. */ /** A method with the name `searchForEntry` declared in `com.unboundid.ldap.sdk.LDAPConnection`. */
class MethodUnboundIdLDAPConnectionSearchForEntry extends Method { class MethodUnboundIdLDAPConnectionSearchForEntry extends Method {
MethodUnboundIdLDAPConnectionSearchForEntry() { MethodUnboundIdLDAPConnectionSearchForEntry() {
getDeclaringType() instanceof TypeUnboundIdLDAPConnection and this.getDeclaringType() instanceof TypeUnboundIdLDAPConnection and
hasName("searchForEntry") this.hasName("searchForEntry")
} }
} }

View File

@@ -37,10 +37,12 @@ class AndroidComponent extends Class {
} }
/** Holds if this Android component is configured as `exported` in an `AndroidManifest.xml` file. */ /** Holds if this Android component is configured as `exported` in an `AndroidManifest.xml` file. */
predicate isExported() { getAndroidComponentXmlElement().isExported() } predicate isExported() { this.getAndroidComponentXmlElement().isExported() }
/** Holds if this Android component has an intent filter configured in an `AndroidManifest.xml` file. */ /** Holds if this Android component has an intent filter configured in an `AndroidManifest.xml` file. */
predicate hasIntentFilter() { exists(getAndroidComponentXmlElement().getAnIntentFilterElement()) } predicate hasIntentFilter() {
exists(this.getAndroidComponentXmlElement().getAnIntentFilterElement())
}
} }
/** /**
@@ -53,10 +55,10 @@ class ExportableAndroidComponent extends AndroidComponent {
* `AndroidManifest.xml` file. * `AndroidManifest.xml` file.
*/ */
override predicate isExported() { override predicate isExported() {
getAndroidComponentXmlElement().isExported() this.getAndroidComponentXmlElement().isExported()
or or
hasIntentFilter() and this.hasIntentFilter() and
not getAndroidComponentXmlElement().isNotExported() not this.getAndroidComponentXmlElement().isNotExported()
} }
} }
@@ -88,7 +90,7 @@ class AndroidContentProvider extends ExportableAndroidComponent {
* in an `AndroidManifest.xml` file. * in an `AndroidManifest.xml` file.
*/ */
predicate requiresPermissions() { predicate requiresPermissions() {
getAndroidComponentXmlElement().(AndroidProviderXmlElement).requiresPermissions() this.getAndroidComponentXmlElement().(AndroidProviderXmlElement).requiresPermissions()
} }
} }

View File

@@ -7,35 +7,37 @@ import semmle.code.java.dataflow.ExternalFlow
* The class `android.content.Intent`. * The class `android.content.Intent`.
*/ */
class TypeIntent extends Class { class TypeIntent extends Class {
TypeIntent() { hasQualifiedName("android.content", "Intent") } TypeIntent() { this.hasQualifiedName("android.content", "Intent") }
} }
/** /**
* The class `android.app.Activity`. * The class `android.app.Activity`.
*/ */
class TypeActivity extends Class { class TypeActivity extends Class {
TypeActivity() { hasQualifiedName("android.app", "Activity") } TypeActivity() { this.hasQualifiedName("android.app", "Activity") }
} }
/** /**
* The class `android.content.Context`. * The class `android.content.Context`.
*/ */
class TypeContext extends RefType { class TypeContext extends RefType {
TypeContext() { hasQualifiedName("android.content", "Context") } TypeContext() { this.hasQualifiedName("android.content", "Context") }
} }
/** /**
* The class `android.content.BroadcastReceiver`. * The class `android.content.BroadcastReceiver`.
*/ */
class TypeBroadcastReceiver extends Class { class TypeBroadcastReceiver extends Class {
TypeBroadcastReceiver() { hasQualifiedName("android.content", "BroadcastReceiver") } TypeBroadcastReceiver() { this.hasQualifiedName("android.content", "BroadcastReceiver") }
} }
/** /**
* The method `Activity.getIntent` * The method `Activity.getIntent`
*/ */
class AndroidGetIntentMethod extends Method { class AndroidGetIntentMethod extends Method {
AndroidGetIntentMethod() { hasName("getIntent") and getDeclaringType() instanceof TypeActivity } AndroidGetIntentMethod() {
this.hasName("getIntent") and this.getDeclaringType() instanceof TypeActivity
}
} }
/** /**
@@ -43,7 +45,7 @@ class AndroidGetIntentMethod extends Method {
*/ */
class AndroidReceiveIntentMethod extends Method { class AndroidReceiveIntentMethod extends Method {
AndroidReceiveIntentMethod() { AndroidReceiveIntentMethod() {
hasName("onReceive") and getDeclaringType() instanceof TypeBroadcastReceiver this.hasName("onReceive") and this.getDeclaringType() instanceof TypeBroadcastReceiver
} }
} }
@@ -52,8 +54,8 @@ class AndroidReceiveIntentMethod extends Method {
*/ */
class ContextStartActivityMethod extends Method { class ContextStartActivityMethod extends Method {
ContextStartActivityMethod() { ContextStartActivityMethod() {
(hasName("startActivity") or hasName("startActivities")) and (this.hasName("startActivity") or this.hasName("startActivities")) and
getDeclaringType() instanceof TypeContext this.getDeclaringType() instanceof TypeContext
} }
} }
@@ -70,8 +72,8 @@ private class IntentFieldsInheritTaint extends DataFlow::SyntheticFieldContent,
*/ */
class IntentGetParcelableExtraMethod extends Method { class IntentGetParcelableExtraMethod extends Method {
IntentGetParcelableExtraMethod() { IntentGetParcelableExtraMethod() {
hasName("getParcelableExtra") and this.hasName("getParcelableExtra") and
getDeclaringType() instanceof TypeIntent this.getDeclaringType() instanceof TypeIntent
} }
} }

View File

@@ -1,15 +1,15 @@
import java import java
class TypeWebView extends Class { class TypeWebView extends Class {
TypeWebView() { hasQualifiedName("android.webkit", "WebView") } TypeWebView() { this.hasQualifiedName("android.webkit", "WebView") }
} }
class TypeWebViewClient extends Class { class TypeWebViewClient extends Class {
TypeWebViewClient() { hasQualifiedName("android.webkit", "WebViewClient") } TypeWebViewClient() { this.hasQualifiedName("android.webkit", "WebViewClient") }
} }
class TypeWebSettings extends Class { class TypeWebSettings extends Class {
TypeWebSettings() { hasQualifiedName("android.webkit", "WebSettings") } TypeWebSettings() { this.hasQualifiedName("android.webkit", "WebSettings") }
} }
class WebViewGetSettingsMethod extends Method { class WebViewGetSettingsMethod extends Method {

View File

@@ -25,14 +25,14 @@ private class TypeLiteralToParseAsFlowConfiguration extends DataFlowForSerializa
) )
} }
TypeLiteral getSourceWithFlowToParseAs() { hasFlow(DataFlow::exprNode(result), _) } TypeLiteral getSourceWithFlowToParseAs() { this.hasFlow(DataFlow::exprNode(result), _) }
} }
/** A field that is deserialized by `HttpResponse.parseAs`. */ /** A field that is deserialized by `HttpResponse.parseAs`. */
class HttpResponseParseAsDeserializableField extends DeserializableField { class HttpResponseParseAsDeserializableField extends DeserializableField {
HttpResponseParseAsDeserializableField() { HttpResponseParseAsDeserializableField() {
exists(RefType decltype, TypeLiteralToParseAsFlowConfiguration conf | exists(RefType decltype, TypeLiteralToParseAsFlowConfiguration conf |
decltype = getDeclaringType() and decltype = this.getDeclaringType() and
conf.getSourceWithFlowToParseAs().getReferencedType() = decltype and conf.getSourceWithFlowToParseAs().getReferencedType() = decltype and
decltype.fromSource() decltype.fromSource()
) )

View File

@@ -38,7 +38,7 @@ class GwtEntryPointClass extends Class {
isGwtXmlIncluded() isGwtXmlIncluded()
implies implies
// The entry point is live if it is specified in a `*.gwt.xml` file. // The entry point is live if it is specified in a `*.gwt.xml` file.
exists(getAGwtXmlFile()) exists(this.getAGwtXmlFile())
} }
} }
@@ -48,7 +48,7 @@ class GwtEntryPointClass extends Class {
*/ */
class GwtCompilationUnit extends CompilationUnit { class GwtCompilationUnit extends CompilationUnit {
GwtCompilationUnit() { GwtCompilationUnit() {
exists(GwtXmlFile f | getRelativePath().matches(f.getARelativeSourcePath() + "%")) exists(GwtXmlFile f | this.getRelativePath().matches(f.getARelativeSourcePath() + "%"))
} }
} }

View File

@@ -12,57 +12,62 @@ import GwtUiBinderXml
* An annotation in the package `com.google.gwt.uibinder.client`. * An annotation in the package `com.google.gwt.uibinder.client`.
*/ */
class GwtUiBinderClientAnnotation extends Annotation { class GwtUiBinderClientAnnotation extends Annotation {
GwtUiBinderClientAnnotation() { getType().getPackage().hasName("com.google.gwt.uibinder.client") } GwtUiBinderClientAnnotation() {
this.getType().getPackage().hasName("com.google.gwt.uibinder.client")
}
} }
/** /**
* A `@com.google.gwt.uibinder.client.UiHandler` annotation. * A `@com.google.gwt.uibinder.client.UiHandler` annotation.
*/ */
class GwtUiHandlerAnnotation extends GwtUiBinderClientAnnotation { class GwtUiHandlerAnnotation extends GwtUiBinderClientAnnotation {
GwtUiHandlerAnnotation() { getType().hasName("UiHandler") } GwtUiHandlerAnnotation() { this.getType().hasName("UiHandler") }
} }
/** /**
* A `@com.google.gwt.uibinder.client.UiField` annotation. * A `@com.google.gwt.uibinder.client.UiField` annotation.
*/ */
class GwtUiFieldAnnotation extends GwtUiBinderClientAnnotation { class GwtUiFieldAnnotation extends GwtUiBinderClientAnnotation {
GwtUiFieldAnnotation() { getType().hasName("UiField") } GwtUiFieldAnnotation() { this.getType().hasName("UiField") }
} }
/** /**
* A `@com.google.gwt.uibinder.client.UiTemplate` annotation. * A `@com.google.gwt.uibinder.client.UiTemplate` annotation.
*/ */
class GwtUiTemplateAnnotation extends GwtUiBinderClientAnnotation { class GwtUiTemplateAnnotation extends GwtUiBinderClientAnnotation {
GwtUiTemplateAnnotation() { getType().hasName("UiTemplate") } GwtUiTemplateAnnotation() { this.getType().hasName("UiTemplate") }
} }
/** /**
* A `@com.google.gwt.uibinder.client.UiFactory` annotation. * A `@com.google.gwt.uibinder.client.UiFactory` annotation.
*/ */
class GwtUiFactoryAnnotation extends GwtUiBinderClientAnnotation { class GwtUiFactoryAnnotation extends GwtUiBinderClientAnnotation {
GwtUiFactoryAnnotation() { getType().hasName("UiFactory") } GwtUiFactoryAnnotation() { this.getType().hasName("UiFactory") }
} }
/** /**
* A `@com.google.gwt.uibinder.client.UiConstructor` annotation. * A `@com.google.gwt.uibinder.client.UiConstructor` annotation.
*/ */
class GwtUiConstructorAnnotation extends GwtUiBinderClientAnnotation { class GwtUiConstructorAnnotation extends GwtUiBinderClientAnnotation {
GwtUiConstructorAnnotation() { getType().hasName("UiConstructor") } GwtUiConstructorAnnotation() { this.getType().hasName("UiConstructor") }
} }
/** /**
* A field that is reflectively written to, and read from, by the GWT UiBinder framework. * A field that is reflectively written to, and read from, by the GWT UiBinder framework.
*/ */
class GwtUiField extends Field { class GwtUiField extends Field {
GwtUiField() { getAnAnnotation() instanceof GwtUiFieldAnnotation } GwtUiField() { this.getAnAnnotation() instanceof GwtUiFieldAnnotation }
/** /**
* If true, the field must be filled before `UiBinder.createAndBindUi` is called. * If true, the field must be filled before `UiBinder.createAndBindUi` is called.
* If false, `UiBinder.createAndBindUi` will fill the field. * If false, `UiBinder.createAndBindUi` will fill the field.
*/ */
predicate isProvided() { predicate isProvided() {
getAnAnnotation().(GwtUiFieldAnnotation).getValue("provided").(BooleanLiteral).getBooleanValue() = this.getAnAnnotation()
true .(GwtUiFieldAnnotation)
.getValue("provided")
.(BooleanLiteral)
.getBooleanValue() = true
} }
} }
@@ -70,14 +75,14 @@ class GwtUiField extends Field {
* A method called as a handler for events thrown by GWT widgets. * A method called as a handler for events thrown by GWT widgets.
*/ */
class GwtUiHandler extends Method { class GwtUiHandler extends Method {
GwtUiHandler() { getAnAnnotation() instanceof GwtUiHandlerAnnotation } GwtUiHandler() { this.getAnAnnotation() instanceof GwtUiHandlerAnnotation }
/** /**
* Gets the name of the field for which this handler is registered. * Gets the name of the field for which this handler is registered.
*/ */
string getFieldName() { string getFieldName() {
result = result =
getAnAnnotation() this.getAnAnnotation()
.(GwtUiHandlerAnnotation) .(GwtUiHandlerAnnotation)
.getValue("value") .getValue("value")
.(CompileTimeConstantExpr) .(CompileTimeConstantExpr)
@@ -89,7 +94,7 @@ class GwtUiHandler extends Method {
*/ */
GwtUiField getField() { GwtUiField getField() {
result = this.getDeclaringType().getAField() and result = this.getDeclaringType().getAField() and
result.getName() = getFieldName() result.getName() = this.getFieldName()
} }
} }
@@ -98,12 +103,12 @@ class GwtUiHandler extends Method {
* construct an instance of a class specified in a UiBinder XML file. * construct an instance of a class specified in a UiBinder XML file.
*/ */
class GwtUiFactory extends Method { class GwtUiFactory extends Method {
GwtUiFactory() { getAnAnnotation() instanceof GwtUiFactoryAnnotation } GwtUiFactory() { this.getAnAnnotation() instanceof GwtUiFactoryAnnotation }
} }
/** /**
* A constructor that may be called by the UiBinder framework as a result of a `GWT.create()` call. * A constructor that may be called by the UiBinder framework as a result of a `GWT.create()` call.
*/ */
class GwtUiConstructor extends Constructor { class GwtUiConstructor extends Constructor {
GwtUiConstructor() { getAnAnnotation() instanceof GwtUiConstructorAnnotation } GwtUiConstructor() { this.getAnAnnotation() instanceof GwtUiConstructorAnnotation }
} }

View File

@@ -36,8 +36,8 @@ class GwtComponentTemplateElement extends XMLElement {
*/ */
Class getClass() { Class getClass() {
exists(string namespace | exists(string namespace |
namespace = getNamespace().getURI() and namespace = this.getNamespace().getURI() and
result.getQualifiedName() = namespace.substring(11, namespace.length()) + "." + getName() result.getQualifiedName() = namespace.substring(11, namespace.length()) + "." + this.getName()
) )
} }
} }

View File

@@ -16,24 +16,24 @@ class GwtXmlFile extends XMLFile {
/** Gets the name of an inherited GWT module, for example `com.google.gwt.user.User`. */ /** Gets the name of an inherited GWT module, for example `com.google.gwt.user.User`. */
string getAnInheritedModuleName() { string getAnInheritedModuleName() {
result = getModuleElement().getAnInheritsElement().getAnInheritedName() result = this.getModuleElement().getAnInheritsElement().getAnInheritedName()
} }
/** Gets a GWT module XML file (from source) inherited from this module. */ /** Gets a GWT module XML file (from source) inherited from this module. */
GwtXmlFile getAnInheritedXmlFile() { GwtXmlFile getAnInheritedXmlFile() {
exists(GwtXmlFile f, string name | exists(GwtXmlFile f, string name |
name = getAnInheritedModuleName() and name = this.getAnInheritedModuleName() and
f.getAbsolutePath().matches("%/" + name.replaceAll(".", "/") + ".gwt.xml") and f.getAbsolutePath().matches("%/" + name.replaceAll(".", "/") + ".gwt.xml") and
result = f result = f
) )
} }
/** Gets the relative path of the folder containing this GWT module XML file. */ /** Gets the relative path of the folder containing this GWT module XML file. */
string getRelativeRootFolderPath() { result = getParentContainer().getRelativePath() } string getRelativeRootFolderPath() { result = this.getParentContainer().getRelativePath() }
/** Gets a GWT-translatable source sub-folder explicitly defined in a `<source>` element. */ /** Gets a GWT-translatable source sub-folder explicitly defined in a `<source>` element. */
string getAnExplicitSourceSubPath() { string getAnExplicitSourceSubPath() {
result = getModuleElement().getASourceElement().getASourcePath() result = this.getModuleElement().getASourceElement().getASourcePath()
} }
/** /**
@@ -41,9 +41,9 @@ class GwtXmlFile extends XMLFile {
* Either the default `client` folder or as specified by `<source>` tags. * Either the default `client` folder or as specified by `<source>` tags.
*/ */
string getASourceSubPath() { string getASourceSubPath() {
result = "client" and not exists(getAnExplicitSourceSubPath()) result = "client" and not exists(this.getAnExplicitSourceSubPath())
or or
result = getAnExplicitSourceSubPath() result = this.getAnExplicitSourceSubPath()
} }
/** /**
@@ -52,7 +52,7 @@ class GwtXmlFile extends XMLFile {
* (Includes the full relative root folder path of the GWT module.) * (Includes the full relative root folder path of the GWT module.)
*/ */
string getARelativeSourcePath() { string getARelativeSourcePath() {
result = getRelativeRootFolderPath() + "/" + getASourceSubPath() result = this.getRelativeRootFolderPath() + "/" + this.getASourceSubPath()
} }
} }
@@ -81,7 +81,7 @@ class GwtInheritsElement extends XMLElement {
} }
/** Gets the name of an inherited GWT module, for example `com.google.gwt.user.User`. */ /** Gets the name of an inherited GWT module, for example `com.google.gwt.user.User`. */
string getAnInheritedName() { result = getAttribute("name").getValue() } string getAnInheritedName() { result = this.getAttribute("name").getValue() }
} }
/** An `<entry-point>` element within a GWT module XML file. */ /** An `<entry-point>` element within a GWT module XML file. */
@@ -92,7 +92,7 @@ class GwtEntryPointElement extends XMLElement {
} }
/** Gets the name of a class that serves as a GWT entry-point. */ /** Gets the name of a class that serves as a GWT entry-point. */
string getClassName() { result = getAttribute("class").getValue().trim() } string getClassName() { result = this.getAttribute("class").getValue().trim() }
} }
/** A `<source>` element within a GWT module XML file. */ /** A `<source>` element within a GWT module XML file. */
@@ -104,11 +104,11 @@ class GwtSourceElement extends XMLElement {
/** Gets a path specified to be GWT translatable source code. */ /** Gets a path specified to be GWT translatable source code. */
string getASourcePath() { string getASourcePath() {
result = getAttribute("path").getValue() and result = this.getAttribute("path").getValue() and
// Conservative approximation, ignoring Ant-style `FileSet` semantics. // Conservative approximation, ignoring Ant-style `FileSet` semantics.
not exists(getAChild()) and not exists(this.getAChild()) and
not exists(getAttribute("includes")) and not exists(this.getAttribute("includes")) and
not exists(getAttribute("excludes")) not exists(this.getAttribute("excludes"))
} }
} }
@@ -120,5 +120,5 @@ class GwtServletElement extends XMLElement {
} }
/** Gets the name of a class that is used as a servlet. */ /** Gets the name of a class that is used as a servlet. */
string getClassName() { result = getAttribute("class").getValue().trim() } string getClassName() { result = this.getAttribute("class").getValue().trim() }
} }

View File

@@ -10,9 +10,9 @@ import java
class OCNIComment extends Javadoc { class OCNIComment extends Javadoc {
OCNIComment() { OCNIComment() {
// The comment must start with `-[` ... // The comment must start with `-[` ...
getChild(0).getText().matches("-[%") and this.getChild(0).getText().matches("-[%") and
// ... and it must end with `]-`. // ... and it must end with `]-`.
getChild(getNumChild() - 1).getText().matches("%]-") this.getChild(this.getNumChild() - 1).getText().matches("%]-")
} }
} }
@@ -42,9 +42,9 @@ class OCNIMethodComment extends OCNIComment {
*/ */
class OCNIImport extends OCNIComment { class OCNIImport extends OCNIComment {
OCNIImport() { OCNIImport() {
getAChild().getText().regexpMatch(".*#(import|include).*") and this.getAChild().getText().regexpMatch(".*#(import|include).*") and
not exists(RefType rt | rt.getFile() = this.getFile() | not exists(RefType rt | rt.getFile() = this.getFile() |
rt.getLocation().getStartLine() < getLocation().getStartLine() rt.getLocation().getStartLine() < this.getLocation().getStartLine()
) )
} }
} }

View File

@@ -32,21 +32,21 @@ abstract class JacksonSerializableType extends Type { }
private class JacksonWriteValueMethod extends Method, TaintPreservingCallable { private class JacksonWriteValueMethod extends Method, TaintPreservingCallable {
JacksonWriteValueMethod() { JacksonWriteValueMethod() {
( (
getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectWriter") or this.getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectWriter") or
getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectMapper") this.getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectMapper")
) and ) and
getName().matches("writeValue%") and this.getName().matches("writeValue%") and
getParameter(getNumberOfParameters() - 1).getType() instanceof TypeObject this.getParameter(this.getNumberOfParameters() - 1).getType() instanceof TypeObject
} }
override predicate returnsTaintFrom(int arg) { override predicate returnsTaintFrom(int arg) {
getNumberOfParameters() = 1 and this.getNumberOfParameters() = 1 and
arg = 0 arg = 0
} }
override predicate transfersTaint(int src, int sink) { override predicate transfersTaint(int src, int sink) {
getNumberOfParameters() > 1 and this.getNumberOfParameters() > 1 and
src = getNumberOfParameters() - 1 and src = this.getNumberOfParameters() - 1 and
sink = 0 sink = 0
} }
} }
@@ -58,10 +58,10 @@ private class JacksonWriteValueMethod extends Method, TaintPreservingCallable {
private class JacksonReadValueMethod extends Method, TaintPreservingCallable { private class JacksonReadValueMethod extends Method, TaintPreservingCallable {
JacksonReadValueMethod() { JacksonReadValueMethod() {
( (
getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectReader") or this.getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectReader") or
getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectMapper") this.getDeclaringType().hasQualifiedName("com.fasterxml.jackson.databind", "ObjectMapper")
) and ) and
hasName(["readValue", "readValues"]) this.hasName(["readValue", "readValues"])
} }
override predicate returnsTaintFrom(int arg) { arg = 0 } override predicate returnsTaintFrom(int arg) { arg = 0 }
@@ -109,7 +109,7 @@ private class TypeLiteralToJacksonDatabindFlowConfiguration extends DataFlowForS
) )
} }
TypeLiteral getSourceWithFlowToJacksonDatabind() { hasFlow(DataFlow::exprNode(result), _) } TypeLiteral getSourceWithFlowToJacksonDatabind() { this.hasFlow(DataFlow::exprNode(result), _) }
} }
/** A type whose values are explicitly deserialized in a call to a Jackson method. */ /** A type whose values are explicitly deserialized in a call to a Jackson method. */
@@ -139,7 +139,7 @@ private class FieldReferencedJacksonDeserializableType extends JacksonDeserializ
class JacksonSerializableField extends SerializableField { class JacksonSerializableField extends SerializableField {
JacksonSerializableField() { JacksonSerializableField() {
exists(JacksonSerializableType superType | exists(JacksonSerializableType superType |
superType = getDeclaringType().getASupertype*() and superType = this.getDeclaringType().getASupertype*() and
not superType instanceof TypeObject and not superType instanceof TypeObject and
superType.fromSource() superType.fromSource()
) and ) and
@@ -151,7 +151,7 @@ class JacksonSerializableField extends SerializableField {
class JacksonDeserializableField extends DeserializableField { class JacksonDeserializableField extends DeserializableField {
JacksonDeserializableField() { JacksonDeserializableField() {
exists(JacksonDeserializableType superType | exists(JacksonDeserializableType superType |
superType = getDeclaringType().getASupertype*() and superType = this.getDeclaringType().getASupertype*() and
not superType instanceof TypeObject and not superType instanceof TypeObject and
superType.fromSource() superType.fromSource()
) and ) and
@@ -161,7 +161,7 @@ class JacksonDeserializableField extends DeserializableField {
/** A call to a field that may be deserialized using the Jackson JSON framework. */ /** A call to a field that may be deserialized using the Jackson JSON framework. */
private class JacksonDeserializableFieldAccess extends FieldAccess { private class JacksonDeserializableFieldAccess extends FieldAccess {
JacksonDeserializableFieldAccess() { getField() instanceof JacksonDeserializableField } JacksonDeserializableFieldAccess() { this.getField() instanceof JacksonDeserializableField }
} }
/** /**
@@ -194,19 +194,19 @@ class JacksonAddMixinCall extends MethodAccess {
/** /**
* Gets a possible type for the target of the mixing, if any can be deduced. * Gets a possible type for the target of the mixing, if any can be deduced.
*/ */
RefType getATarget() { result = inferClassParameterType(getArgument(0)) } RefType getATarget() { result = inferClassParameterType(this.getArgument(0)) }
/** /**
* Gets a possible type that will be mixed in, if any can be deduced. * Gets a possible type that will be mixed in, if any can be deduced.
*/ */
RefType getAMixedInType() { result = inferClassParameterType(getArgument(1)) } RefType getAMixedInType() { result = inferClassParameterType(this.getArgument(1)) }
} }
/** /**
* A Jackson annotation. * A Jackson annotation.
*/ */
class JacksonAnnotation extends Annotation { class JacksonAnnotation extends Annotation {
JacksonAnnotation() { getType().getPackage().hasName("com.fasterxml.jackson.annotation") } JacksonAnnotation() { this.getType().getPackage().hasName("com.fasterxml.jackson.annotation") }
} }
/** /**
@@ -228,7 +228,7 @@ class JacksonMixinType extends ClassOrInterface {
* Gets a callable from this type that is mixed in by Jackson. * Gets a callable from this type that is mixed in by Jackson.
*/ */
Callable getAMixedInCallable() { Callable getAMixedInCallable() {
result = getACallable() and result = this.getACallable() and
( (
result.(Constructor).isDefaultConstructor() or result.(Constructor).isDefaultConstructor() or
result.getAnAnnotation() instanceof JacksonAnnotation or result.getAnAnnotation() instanceof JacksonAnnotation or
@@ -240,7 +240,7 @@ class JacksonMixinType extends ClassOrInterface {
* Gets a field that is mixed in by Jackson. * Gets a field that is mixed in by Jackson.
*/ */
Field getAMixedInField() { Field getAMixedInField() {
result = getAField() and result = this.getAField() and
result.getAnAnnotation() instanceof JacksonAnnotation result.getAnAnnotation() instanceof JacksonAnnotation
} }
} }
@@ -264,17 +264,17 @@ class JacksonMixedInCallable extends Callable {
* Gets a callable on a possible target that this is mixed into. * Gets a callable on a possible target that this is mixed into.
*/ */
Callable getATargetCallable() { Callable getATargetCallable() {
exists(RefType targetType | targetType = getATargetType() | exists(RefType targetType | targetType = this.getATargetType() |
result = getATargetType().getACallable() and result = this.getATargetType().getACallable() and
if this instanceof Constructor if this instanceof Constructor
then then
// The mixed in type will have a different name to the target type, so just compare the // The mixed in type will have a different name to the target type, so just compare the
// parameters. // parameters.
result.getSignature().suffix(targetType.getName().length()) = result.getSignature().suffix(targetType.getName().length()) =
getSignature().suffix(getDeclaringType().getName().length()) this.getSignature().suffix(this.getDeclaringType().getName().length())
else else
// Signatures should match // Signatures should match
result.getSignature() = getSignature() result.getSignature() = this.getSignature()
) )
} }
} }

View File

@@ -10,8 +10,8 @@ import java
*/ */
class PersistentEntity extends RefType { class PersistentEntity extends RefType {
PersistentEntity() { PersistentEntity() {
getAnAnnotation() instanceof EntityAnnotation or this.getAnAnnotation() instanceof EntityAnnotation or
getAnAnnotation() instanceof EmbeddableAnnotation this.getAnAnnotation() instanceof EmbeddableAnnotation
} }
/** /**
@@ -22,12 +22,12 @@ class PersistentEntity extends RefType {
* instead. * instead.
*/ */
string getAccessType() { string getAccessType() {
if exists(getAccessTypeFromAnnotation()) if exists(this.getAccessTypeFromAnnotation())
then result = getAccessTypeFromAnnotation() then result = this.getAccessTypeFromAnnotation()
else else
// If the access type is not explicit, then the location of the `Id` annotation determines // If the access type is not explicit, then the location of the `Id` annotation determines
// which access type is used. // which access type is used.
if getAMethod().hasAnnotation("javax.persistence", "Id") if this.getAMethod().hasAnnotation("javax.persistence", "Id")
then result = "property" then result = "property"
else result = "field" else result = "field"
} }
@@ -36,7 +36,7 @@ class PersistentEntity extends RefType {
* Gets the access type for this entity as defined by a `@javax.persistence.Access` annotation, if any. * Gets the access type for this entity as defined by a `@javax.persistence.Access` annotation, if any.
*/ */
string getAccessTypeFromAnnotation() { string getAccessTypeFromAnnotation() {
exists(AccessAnnotation accessType | accessType = getAnAnnotation() | exists(AccessAnnotation accessType | accessType = this.getAnAnnotation() |
result = result =
accessType.getValue("value").(FieldRead).getField().(EnumConstant).getName().toLowerCase() accessType.getValue("value").(FieldRead).getField().(EnumConstant).getName().toLowerCase()
) )

View File

@@ -100,7 +100,7 @@ class PersistencePropertyElement extends XMLElement {
* disables the EclipseLink shared cache. * disables the EclipseLink shared cache.
*/ */
predicate disablesEclipseLinkSharedCache() { predicate disablesEclipseLinkSharedCache() {
getAttribute("name").getValue() = "eclipselink.cache.shared.default" and this.getAttribute("name").getValue() = "eclipselink.cache.shared.default" and
getAttribute("value").getValue() = "false" this.getAttribute("value").getValue() = "false"
} }
} }

View File

@@ -8,7 +8,7 @@ import EJBJarXML
*/ */
abstract class EJB extends Class { abstract class EJB extends Class {
/** Gets a `Callable` that is directly or indirectly called from within the EJB. */ /** Gets a `Callable` that is directly or indirectly called from within the EJB. */
Callable getAUsedCallable() { getACallable().polyCalls*(result) } Callable getAUsedCallable() { this.getACallable().polyCalls*(result) }
} }
/** /**
@@ -33,16 +33,16 @@ class SessionEJB extends EJB {
// Either the EJB does not declare any business interfaces explicitly // Either the EJB does not declare any business interfaces explicitly
// and implements a single interface candidate, // and implements a single interface candidate,
// which is then considered to be the business interface... // which is then considered to be the business interface...
count(getAnExplicitBusinessInterface()) = 0 and count(this.getAnExplicitBusinessInterface()) = 0 and
count(getAnImplementedBusinessInterfaceCandidate()) = 1 and count(this.getAnImplementedBusinessInterfaceCandidate()) = 1 and
result = getAnImplementedBusinessInterfaceCandidate() result = this.getAnImplementedBusinessInterfaceCandidate()
or or
// ...or each business interface needs to be declared explicitly. // ...or each business interface needs to be declared explicitly.
( (
count(getAnImplementedBusinessInterfaceCandidate()) != 1 or count(this.getAnImplementedBusinessInterfaceCandidate()) != 1 or
count(getAnExplicitBusinessInterface()) != 0 count(this.getAnExplicitBusinessInterface()) != 0
) and ) and
result = getAnExplicitBusinessInterface() result = this.getAnExplicitBusinessInterface()
} }
/** /**
@@ -198,7 +198,7 @@ abstract class EjbInterfaceAnnotation extends Annotation {
// Returns the type `Foo` of any type literal `Foo.class` occurring // Returns the type `Foo` of any type literal `Foo.class` occurring
// within the "value" element of this annotation. // within the "value" element of this annotation.
// Uses `getAChildExpr*()` since the "value" element can have type `Class` or `Class[]`. // Uses `getAChildExpr*()` since the "value" element can have type `Class` or `Class[]`.
exists(TypeLiteral tl | tl = getValue("value").getAChildExpr*() | exists(TypeLiteral tl | tl = this.getValue("value").getAChildExpr*() |
result = tl.getReferencedType() result = tl.getReferencedType()
) )
} }
@@ -447,7 +447,7 @@ class AnnotatedRemoteHomeInterface extends LegacyEjbRemoteHomeInterface {
SessionEJB getAnEJB() { result.getAnAnnotation().(RemoteHomeAnnotation).getANamedType() = this } SessionEJB getAnEJB() { result.getAnAnnotation().(RemoteHomeAnnotation).getANamedType() = this }
/** Gets a remote interface associated with this legacy remote home interface. */ /** Gets a remote interface associated with this legacy remote home interface. */
Interface getAnAssociatedRemoteInterface() { result = getACreateMethod().getReturnType() } Interface getAnAssociatedRemoteInterface() { result = this.getACreateMethod().getReturnType() }
} }
/** A legacy remote home interface specified within an XML deployment descriptor. */ /** A legacy remote home interface specified within an XML deployment descriptor. */
@@ -511,7 +511,7 @@ class AnnotatedLocalHomeInterface extends LegacyEjbLocalHomeInterface {
SessionEJB getAnEJB() { result.getAnAnnotation().(LocalHomeAnnotation).getANamedType() = this } SessionEJB getAnEJB() { result.getAnAnnotation().(LocalHomeAnnotation).getANamedType() = this }
/** Gets a local interface associated with this legacy local home interface. */ /** Gets a local interface associated with this legacy local home interface. */
Interface getAnAssociatedLocalInterface() { result = getACreateMethod().getReturnType() } Interface getAnAssociatedLocalInterface() { result = this.getACreateMethod().getReturnType() }
} }
/** A legacy local home interface specified within an XML deployment descriptor. */ /** A legacy local home interface specified within an XML deployment descriptor. */
@@ -562,8 +562,8 @@ class RemoteInterface extends Interface {
/** Gets a remote method implementation for this remote interface. */ /** Gets a remote method implementation for this remote interface. */
Method getARemoteMethodImplementation() { Method getARemoteMethodImplementation() {
result = getARemoteMethodImplementationChecked() or result = this.getARemoteMethodImplementationChecked() or
result = getARemoteMethodImplementationUnchecked() result = this.getARemoteMethodImplementationUnchecked()
} }
/** /**
@@ -572,7 +572,7 @@ class RemoteInterface extends Interface {
* abstract methods or overriding within an interface hierarchy. * abstract methods or overriding within an interface hierarchy.
*/ */
Method getARemoteMethodImplementationChecked() { Method getARemoteMethodImplementationChecked() {
result.overrides(getARemoteMethod()) and result.overrides(this.getARemoteMethod()) and
exists(result.getBody()) exists(result.getBody())
} }
@@ -586,9 +586,9 @@ class RemoteInterface extends Interface {
*/ */
Method getARemoteMethodImplementationUnchecked() { Method getARemoteMethodImplementationUnchecked() {
exists(SessionEJB ejb, Method rm | exists(SessionEJB ejb, Method rm |
ejb = getAnEJB() and ejb = this.getAnEJB() and
not ejb.getASupertype*() = this and not ejb.getASupertype*() = this and
rm = getARemoteMethod() and rm = this.getARemoteMethod() and
result = getAnInheritedMatchingMethodIgnoreThrows(ejb, rm.getSignature()) and result = getAnInheritedMatchingMethodIgnoreThrows(ejb, rm.getSignature()) and
not exists(inheritsMatchingMethodExceptThrows(ejb, rm)) not exists(inheritsMatchingMethodExceptThrows(ejb, rm))
) and ) and

View File

@@ -114,8 +114,8 @@ class EjbJarSessionElement extends EjbJarBeanTypeElement {
* This is either a `business-local` or `business-remote` element. * This is either a `business-local` or `business-remote` element.
*/ */
XMLElement getABusinessElement() { XMLElement getABusinessElement() {
result = getABusinessLocalElement() or result = this.getABusinessLocalElement() or
result = getABusinessRemoteElement() result = this.getABusinessRemoteElement()
} }
/** Gets a `remote` child XML element of this `session` XML element. */ /** Gets a `remote` child XML element of this `session` XML element. */
@@ -153,7 +153,7 @@ class EjbJarSessionElement extends EjbJarBeanTypeElement {
* XML element nested within this `session` XML element. * XML element nested within this `session` XML element.
*/ */
XMLElement getACreateMethodNameElement() { XMLElement getACreateMethodNameElement() {
result = getAnInitMethodElement().getACreateMethodElement().getAMethodNameElement() result = this.getAnInitMethodElement().getACreateMethodElement().getAMethodNameElement()
} }
/** /**
@@ -161,7 +161,7 @@ class EjbJarSessionElement extends EjbJarBeanTypeElement {
* XML element nested within this `session` XML element. * XML element nested within this `session` XML element.
*/ */
XMLElement getABeanMethodNameElement() { XMLElement getABeanMethodNameElement() {
result = getAnInitMethodElement().getABeanMethodElement().getAMethodNameElement() result = this.getAnInitMethodElement().getABeanMethodElement().getAMethodNameElement()
} }
} }

View File

@@ -25,14 +25,14 @@ class FacesConfigXMLElement extends XMLElement {
/** /**
* Gets the value for this element, with leading and trailing whitespace trimmed. * Gets the value for this element, with leading and trailing whitespace trimmed.
*/ */
string getValue() { result = allCharactersString().trim() } string getValue() { result = this.allCharactersString().trim() }
} }
/** /**
* An element in a JSF config file that declares a managed bean. * An element in a JSF config file that declares a managed bean.
*/ */
class FacesConfigManagedBean extends FacesConfigXMLElement { class FacesConfigManagedBean extends FacesConfigXMLElement {
FacesConfigManagedBean() { getName() = "managed-bean" } FacesConfigManagedBean() { this.getName() = "managed-bean" }
} }
/** /**
@@ -40,21 +40,21 @@ class FacesConfigManagedBean extends FacesConfigXMLElement {
*/ */
class FacesConfigManagedBeanClass extends FacesConfigXMLElement { class FacesConfigManagedBeanClass extends FacesConfigXMLElement {
FacesConfigManagedBeanClass() { FacesConfigManagedBeanClass() {
getName() = "managed-bean-class" and this.getName() = "managed-bean-class" and
getParent() instanceof FacesConfigManagedBean this.getParent() instanceof FacesConfigManagedBean
} }
/** /**
* Gets the `Class` of the managed bean. * Gets the `Class` of the managed bean.
*/ */
Class getManagedBeanClass() { result.getQualifiedName() = getValue() } Class getManagedBeanClass() { result.getQualifiedName() = this.getValue() }
} }
/** /**
* An element in a JSF config file that declares a custom component. * An element in a JSF config file that declares a custom component.
*/ */
class FacesConfigComponent extends FacesConfigXMLElement { class FacesConfigComponent extends FacesConfigXMLElement {
FacesConfigComponent() { getName() = "component" } FacesConfigComponent() { this.getName() = "component" }
} }
/** /**
@@ -62,12 +62,12 @@ class FacesConfigComponent extends FacesConfigXMLElement {
*/ */
class FacesConfigComponentClass extends FacesConfigXMLElement { class FacesConfigComponentClass extends FacesConfigXMLElement {
FacesConfigComponentClass() { FacesConfigComponentClass() {
getName() = "component-class" and this.getName() = "component-class" and
getParent() instanceof FacesConfigComponent this.getParent() instanceof FacesConfigComponent
} }
/** /**
* Gets the `Class` of the faces component. * Gets the `Class` of the faces component.
*/ */
Class getFacesComponentClass() { result.getQualifiedName() = getValue() } Class getFacesComponentClass() { result.getQualifiedName() = this.getValue() }
} }

View File

@@ -33,9 +33,9 @@ private class ExternalContextSource extends SourceModelCsv {
*/ */
class FacesGetResponseWriterMethod extends Method { class FacesGetResponseWriterMethod extends Method {
FacesGetResponseWriterMethod() { FacesGetResponseWriterMethod() {
getDeclaringType() instanceof FacesContext and this.getDeclaringType() instanceof FacesContext and
hasName("getResponseWriter") and this.hasName("getResponseWriter") and
getNumberOfParameters() = 0 this.getNumberOfParameters() = 0
} }
} }
@@ -44,9 +44,9 @@ class FacesGetResponseWriterMethod extends Method {
*/ */
class FacesGetResponseStreamMethod extends Method { class FacesGetResponseStreamMethod extends Method {
FacesGetResponseStreamMethod() { FacesGetResponseStreamMethod() {
getDeclaringType() instanceof FacesContext and this.getDeclaringType() instanceof FacesContext and
hasName("getResponseStream") and this.hasName("getResponseStream") and
getNumberOfParameters() = 0 this.getNumberOfParameters() = 0
} }
} }

View File

@@ -6,12 +6,12 @@ import java
/** The interface representing `HttpRequest.Builder`. */ /** The interface representing `HttpRequest.Builder`. */
class TypeHttpRequestBuilder extends Interface { class TypeHttpRequestBuilder extends Interface {
TypeHttpRequestBuilder() { hasQualifiedName("java.net.http", "HttpRequest$Builder") } TypeHttpRequestBuilder() { this.hasQualifiedName("java.net.http", "HttpRequest$Builder") }
} }
/** The interface representing `java.net.http.HttpRequest`. */ /** The interface representing `java.net.http.HttpRequest`. */
class TypeHttpRequest extends Interface { class TypeHttpRequest extends Interface {
TypeHttpRequest() { hasQualifiedName("java.net.http", "HttpRequest") } TypeHttpRequest() { this.hasQualifiedName("java.net.http", "HttpRequest") }
} }
/** The `uri` method on `java.net.http.HttpRequest.Builder`. */ /** The `uri` method on `java.net.http.HttpRequest.Builder`. */

View File

@@ -45,7 +45,7 @@ class PlayAddCsrfTokenAnnotation extends Annotation {
* The type `play.libs.F.Promise<Result>`. * The type `play.libs.F.Promise<Result>`.
*/ */
class PlayAsyncResultPromise extends MemberType { class PlayAsyncResultPromise extends MemberType {
PlayAsyncResultPromise() { hasQualifiedName("play.libs", "F$Promise<Result>") } PlayAsyncResultPromise() { this.hasQualifiedName("play.libs", "F$Promise<Result>") }
} }
/** /**

View File

@@ -24,7 +24,7 @@ predicate hasInjectAnnotation(Annotatable a) {
class SpringComponentConstructor extends Constructor { class SpringComponentConstructor extends Constructor {
SpringComponentConstructor() { SpringComponentConstructor() {
// Must be a live Spring component. // Must be a live Spring component.
getDeclaringType().(SpringComponent).isLive() and this.getDeclaringType().(SpringComponent).isLive() and
( (
this.getNumberOfParameters() = 0 or this.getNumberOfParameters() = 0 or
hasInjectAnnotation(this) hasInjectAnnotation(this)
@@ -93,8 +93,8 @@ class SpringBeanXMLAutowiredSetterMethod extends Method {
) )
) and ) and
// The resulting bean is of the right type. // The resulting bean is of the right type.
result.getClass().getAnAncestor() = getParameter(0).getType() and result.getClass().getAnAncestor() = this.getParameter(0).getType() and
getNumberOfParameters() = 1 and this.getNumberOfParameters() = 1 and
this.getName().matches("set%") this.getName().matches("set%")
) )
} }
@@ -110,7 +110,7 @@ class SpringBeanAutowiredCallable extends Callable {
// Marked as `@Autowired`. // Marked as `@Autowired`.
hasInjectAnnotation(this) and hasInjectAnnotation(this) and
// No autowiring occurs if there are no parameters // No autowiring occurs if there are no parameters
getNumberOfParameters() > 0 this.getNumberOfParameters() > 0
} }
/** /**
@@ -118,7 +118,7 @@ class SpringBeanAutowiredCallable extends Callable {
* defined in. * defined in.
*/ */
SpringBean getEnclosingSpringBean() { SpringBean getEnclosingSpringBean() {
result = getDeclaringType().(SpringBeanRefType).getSpringBean() result = this.getDeclaringType().(SpringBeanRefType).getSpringBean()
} }
/** /**
@@ -129,22 +129,24 @@ class SpringBeanAutowiredCallable extends Callable {
/** /**
* Gets the qualifier annotation for parameter at `pos`, if any. * Gets the qualifier annotation for parameter at `pos`, if any.
*/ */
SpringQualifierAnnotation getQualifier(int pos) { result = getParameter(pos).getAnAnnotation() } SpringQualifierAnnotation getQualifier(int pos) {
result = this.getParameter(pos).getAnAnnotation()
}
/** /**
* Gets the qualifier annotation for this method, if any. * Gets the qualifier annotation for this method, if any.
*/ */
SpringQualifierAnnotation getQualifier() { result = getAnAnnotation() } SpringQualifierAnnotation getQualifier() { result = this.getAnAnnotation() }
/** /**
* Gets the resource annotation for this method, if any. * Gets the resource annotation for this method, if any.
*/ */
SpringResourceAnnotation getResource() { result = getAnAnnotation() } SpringResourceAnnotation getResource() { result = this.getAnAnnotation() }
/** /**
* Gets a bean that will be injected into this callable. * Gets a bean that will be injected into this callable.
*/ */
SpringBean getAnInjectedBean() { result = getInjectedBean(_) } SpringBean getAnInjectedBean() { result = this.getInjectedBean(_) }
/** /**
* Gets the `SpringBean`, if any, that will be injected for the parameter at position `pos`, * Gets the `SpringBean`, if any, that will be injected for the parameter at position `pos`,
@@ -152,24 +154,24 @@ class SpringBeanAutowiredCallable extends Callable {
*/ */
SpringBean getInjectedBean(int pos) { SpringBean getInjectedBean(int pos) {
// Must be a sub-type of the parameter type // Must be a sub-type of the parameter type
result.getClass().getAnAncestor() = getParameterType(pos) and result.getClass().getAnAncestor() = this.getParameterType(pos) and
// Now look up bean // Now look up bean
if exists(getQualifier(pos)) if exists(this.getQualifier(pos))
then then
// Resolved by `@Qualifier("qualifier")` specified on the parameter // Resolved by `@Qualifier("qualifier")` specified on the parameter
result = getQualifier(pos).getSpringBean() result = this.getQualifier(pos).getSpringBean()
else else
if exists(getQualifier()) and getNumberOfParameters() = 1 if exists(this.getQualifier()) and this.getNumberOfParameters() = 1
then then
// Resolved by `@Qualifier("qualifier")` on the method // Resolved by `@Qualifier("qualifier")` on the method
pos = 0 and pos = 0 and
result = getQualifier().getSpringBean() result = this.getQualifier().getSpringBean()
else else
if exists(getResource().getNameValue()) and getNumberOfParameters() = 1 if exists(this.getResource().getNameValue()) and this.getNumberOfParameters() = 1
then then
// Resolved by looking at the name part of `@Resource(name="qualifier")` // Resolved by looking at the name part of `@Resource(name="qualifier")`
pos = 0 and pos = 0 and
result = getResource().getSpringBean() result = this.getResource().getSpringBean()
else else
// Otherwise no restrictions, just by type // Otherwise no restrictions, just by type
any() any()
@@ -181,24 +183,24 @@ class SpringBeanAutowiredCallable extends Callable {
*/ */
SpringComponent getInjectedComponent(int pos) { SpringComponent getInjectedComponent(int pos) {
// Must be a sub-type of the parameter type // Must be a sub-type of the parameter type
result.getAnAncestor() = getParameterType(pos) and result.getAnAncestor() = this.getParameterType(pos) and
// Now look up bean // Now look up bean
if exists(getQualifier(pos)) if exists(this.getQualifier(pos))
then then
// Resolved by `@Qualifier("qualifier")` specified on the parameter // Resolved by `@Qualifier("qualifier")` specified on the parameter
result = getQualifier(pos).getSpringComponent() result = this.getQualifier(pos).getSpringComponent()
else else
if exists(getQualifier()) and getNumberOfParameters() = 1 if exists(this.getQualifier()) and this.getNumberOfParameters() = 1
then then
// Resolved by `@Qualifier("qualifier")` on the method // Resolved by `@Qualifier("qualifier")` on the method
pos = 0 and pos = 0 and
result = getQualifier().getSpringComponent() result = this.getQualifier().getSpringComponent()
else else
if exists(getResource().getNameValue()) and getNumberOfParameters() = 1 if exists(this.getResource().getNameValue()) and this.getNumberOfParameters() = 1
then then
// Resolved by looking at the name part of `@Resource(name="qualifier")` // Resolved by looking at the name part of `@Resource(name="qualifier")`
pos = 0 and pos = 0 and
result = getResource().getSpringComponent() result = this.getResource().getSpringComponent()
else else
// Otherwise no restrictions, just by type // Otherwise no restrictions, just by type
any() any()
@@ -219,7 +221,7 @@ class SpringBeanAutowiredField extends Field {
* defined in. * defined in.
*/ */
SpringBean getEnclosingSpringBean() { SpringBean getEnclosingSpringBean() {
result = getDeclaringType().(SpringBeanRefType).getSpringBean() result = this.getDeclaringType().(SpringBeanRefType).getSpringBean()
} }
/** /**
@@ -230,12 +232,12 @@ class SpringBeanAutowiredField extends Field {
/** /**
* Gets the qualifier annotation for this method, if any. * Gets the qualifier annotation for this method, if any.
*/ */
SpringQualifierAnnotation getQualifier() { result = getAnAnnotation() } SpringQualifierAnnotation getQualifier() { result = this.getAnAnnotation() }
/** /**
* Gets the resource annotation for this method, if any. * Gets the resource annotation for this method, if any.
*/ */
SpringResourceAnnotation getResource() { result = getAnAnnotation() } SpringResourceAnnotation getResource() { result = this.getAnAnnotation() }
/** /**
* Gets the `SpringBean`, if any, that will be injected for this field, considering any `@Qualifier` * Gets the `SpringBean`, if any, that will be injected for this field, considering any `@Qualifier`
@@ -243,17 +245,17 @@ class SpringBeanAutowiredField extends Field {
*/ */
SpringBean getInjectedBean() { SpringBean getInjectedBean() {
// Must be a sub-type of the parameter type // Must be a sub-type of the parameter type
result.getClass().getAnAncestor() = getType() and result.getClass().getAnAncestor() = this.getType() and
// Now look up bean // Now look up bean
if exists(getQualifier()) if exists(this.getQualifier())
then then
// Resolved by `@Qualifier("qualifier")` specified on the field // Resolved by `@Qualifier("qualifier")` specified on the field
result = getQualifier().getSpringBean() result = this.getQualifier().getSpringBean()
else else
if exists(getResource().getNameValue()) if exists(this.getResource().getNameValue())
then then
// Resolved by looking at the name part of `@Resource(name="qualifier")` // Resolved by looking at the name part of `@Resource(name="qualifier")`
result = getResource().getSpringBean() result = this.getResource().getSpringBean()
else else
// Otherwise no restrictions, just by type // Otherwise no restrictions, just by type
any() any()
@@ -265,17 +267,17 @@ class SpringBeanAutowiredField extends Field {
*/ */
SpringComponent getInjectedComponent() { SpringComponent getInjectedComponent() {
// Must be a sub-type of the parameter type // Must be a sub-type of the parameter type
result.getAnAncestor() = getType() and result.getAnAncestor() = this.getType() and
// Now look up bean // Now look up bean
if exists(getQualifier()) if exists(this.getQualifier())
then then
// Resolved by `@Qualifier("qualifier")` specified on the field // Resolved by `@Qualifier("qualifier")` specified on the field
result = getQualifier().getSpringComponent() result = this.getQualifier().getSpringComponent()
else else
if exists(getResource().getNameValue()) if exists(this.getResource().getNameValue())
then then
// Resolved by looking at the name part of `@Resource(name="qualifier")` // Resolved by looking at the name part of `@Resource(name="qualifier")`
result = getResource().getSpringComponent() result = this.getResource().getSpringComponent()
else else
// Otherwise no restrictions, just by type // Otherwise no restrictions, just by type
any() any()
@@ -287,9 +289,9 @@ class SpringBeanAutowiredField extends Field {
*/ */
class SpringQualifierAnnotationType extends AnnotationType { class SpringQualifierAnnotationType extends AnnotationType {
SpringQualifierAnnotationType() { SpringQualifierAnnotationType() {
hasQualifiedName("org.springframework.beans.factory.annotation", "Qualifier") or this.hasQualifiedName("org.springframework.beans.factory.annotation", "Qualifier") or
hasQualifiedName("javax.inject", "Qualifier") or this.hasQualifiedName("javax.inject", "Qualifier") or
getAnAnnotation().getType() instanceof SpringQualifierAnnotationType this.getAnAnnotation().getType() instanceof SpringQualifierAnnotationType
} }
} }
@@ -299,15 +301,15 @@ class SpringQualifierAnnotationType extends AnnotationType {
*/ */
class SpringQualifierDefinitionAnnotation extends Annotation { class SpringQualifierDefinitionAnnotation extends Annotation {
SpringQualifierDefinitionAnnotation() { SpringQualifierDefinitionAnnotation() {
getType() instanceof SpringQualifierAnnotationType and this.getType() instanceof SpringQualifierAnnotationType and
getAnnotatedElement() instanceof SpringComponent this.getAnnotatedElement() instanceof SpringComponent
} }
/** /**
* Gets the value of the qualifier field for this qualifier. * Gets the value of the qualifier field for this qualifier.
*/ */
string getQualifierValue() { string getQualifierValue() {
result = getValue("value").(CompileTimeConstantExpr).getStringValue() result = this.getValue("value").(CompileTimeConstantExpr).getStringValue()
} }
} }
@@ -315,24 +317,24 @@ class SpringQualifierDefinitionAnnotation extends Annotation {
* A qualifier annotation on a method or field that is used to disambiguate which bean will be used. * A qualifier annotation on a method or field that is used to disambiguate which bean will be used.
*/ */
class SpringQualifierAnnotation extends Annotation { class SpringQualifierAnnotation extends Annotation {
SpringQualifierAnnotation() { getType() instanceof SpringQualifierAnnotationType } SpringQualifierAnnotation() { this.getType() instanceof SpringQualifierAnnotationType }
/** /**
* Gets the value of the qualifier field for this qualifier. * Gets the value of the qualifier field for this qualifier.
*/ */
string getQualifierValue() { string getQualifierValue() {
result = getValue("value").(CompileTimeConstantExpr).getStringValue() result = this.getValue("value").(CompileTimeConstantExpr).getStringValue()
} }
/** /**
* Gets the bean definition in an XML file that this qualifier resolves to, if any. * Gets the bean definition in an XML file that this qualifier resolves to, if any.
*/ */
SpringBean getSpringBean() { result.getQualifierValue() = getQualifierValue() } SpringBean getSpringBean() { result.getQualifierValue() = this.getQualifierValue() }
/** /**
* Gets the Spring component that this qualifier resolves to, if any. * Gets the Spring component that this qualifier resolves to, if any.
*/ */
SpringComponent getSpringComponent() { result.getQualifierValue() = getQualifierValue() } SpringComponent getSpringComponent() { result.getQualifierValue() = this.getQualifierValue() }
} }
/** /**
@@ -340,20 +342,22 @@ class SpringQualifierAnnotation extends Annotation {
* autowired by Spring, and can optionally specify a qualifier in the "name". * autowired by Spring, and can optionally specify a qualifier in the "name".
*/ */
class SpringResourceAnnotation extends Annotation { class SpringResourceAnnotation extends Annotation {
SpringResourceAnnotation() { getType().hasQualifiedName("javax.inject", "Resource") } SpringResourceAnnotation() { this.getType().hasQualifiedName("javax.inject", "Resource") }
/** /**
* Gets the specified name value, if any. * Gets the specified name value, if any.
*/ */
string getNameValue() { result = getValue("name").(CompileTimeConstantExpr).getStringValue() } string getNameValue() {
result = this.getValue("name").(CompileTimeConstantExpr).getStringValue()
}
/** /**
* Gets the bean definition in an XML file that the resource resolves to, if any. * Gets the bean definition in an XML file that the resource resolves to, if any.
*/ */
SpringBean getSpringBean() { result.getQualifierValue() = getNameValue() } SpringBean getSpringBean() { result.getQualifierValue() = this.getNameValue() }
/** /**
* Gets the Spring component that this qualifier resolves to, if any. * Gets the Spring component that this qualifier resolves to, if any.
*/ */
SpringComponent getSpringComponent() { result.getQualifierValue() = getNameValue() } SpringComponent getSpringComponent() { result.getQualifierValue() = this.getNameValue() }
} }

View File

@@ -16,7 +16,7 @@ class SpringBean extends SpringXMLElement {
SpringBean() { SpringBean() {
this.getName() = "bean" and this.getName() = "bean" and
// Do not capture Camel beans, which are different // Do not capture Camel beans, which are different
not getNamespace().getURI() = "http://camel.apache.org/schema/spring" not this.getNamespace().getURI() = "http://camel.apache.org/schema/spring"
} }
override string toString() { result = this.getBeanIdentifier() } override string toString() { result = this.getBeanIdentifier() }
@@ -383,7 +383,7 @@ class SpringBean extends SpringXMLElement {
// If a factory bean is specified, use that, otherwise use the current bean. // If a factory bean is specified, use that, otherwise use the current bean.
( (
if exists(this.getFactoryBeanName()) if exists(this.getFactoryBeanName())
then result.getDeclaringType() = getFactoryBean().getClass() then result.getDeclaringType() = this.getFactoryBean().getClass()
else ( else (
result.getDeclaringType() = this.getClass() and result.getDeclaringType() = this.getClass() and
// Must be static because we don't yet have an instance. // Must be static because we don't yet have an instance.
@@ -400,9 +400,9 @@ class SpringBean extends SpringXMLElement {
* the bean identifier if no qualifier is specified. * the bean identifier if no qualifier is specified.
*/ */
string getQualifierValue() { string getQualifierValue() {
if exists(getQualifier()) if exists(this.getQualifier())
then result = getQualifier().getQualifierValue() then result = this.getQualifier().getQualifierValue()
else result = getBeanIdentifier() else result = this.getBeanIdentifier()
} }
/** /**

View File

@@ -35,7 +35,12 @@ class SpringBeanFile extends XMLFile {
*/ */
string getAProfileExpr() { string getAProfileExpr() {
result = result =
getBeansElement().getAttribute("profile").getValue().splitAt(",").splitAt(" ").splitAt(";") and this.getBeansElement()
.getAttribute("profile")
.getValue()
.splitAt(",")
.splitAt(" ")
.splitAt(";") and
result.length() != 0 result.length() != 0
} }

View File

@@ -20,7 +20,7 @@ class SpringXMLComponentScan extends SpringXMLElement {
* Gets a profile expression for which this `component-scan` is enabled, or nothing if it is * Gets a profile expression for which this `component-scan` is enabled, or nothing if it is
* applicable to any profile. * applicable to any profile.
*/ */
string getAProfileExpr() { result = getSpringBeanFile().getAProfileExpr() } string getAProfileExpr() { result = this.getSpringBeanFile().getAProfileExpr() }
} }
/** /**
@@ -29,7 +29,7 @@ class SpringXMLComponentScan extends SpringXMLElement {
*/ */
class SpringComponentScan extends Annotation { class SpringComponentScan extends Annotation {
SpringComponentScan() { SpringComponentScan() {
getType().hasQualifiedName("org.springframework.context.annotation", "ComponentScan") this.getType().hasQualifiedName("org.springframework.context.annotation", "ComponentScan")
} }
/** /**
@@ -37,13 +37,13 @@ class SpringComponentScan extends Annotation {
*/ */
string getBasePackages() { string getBasePackages() {
// "value" and "basePackages" are synonymous, and are simple strings // "value" and "basePackages" are synonymous, and are simple strings
result = getAValue("basePackages").(StringLiteral).getRepresentedString() result = this.getAValue("basePackages").(StringLiteral).getRepresentedString()
or or
result = getAValue("value").(StringLiteral).getRepresentedString() result = this.getAValue("value").(StringLiteral).getRepresentedString()
or or
exists(TypeLiteral typeLiteral | exists(TypeLiteral typeLiteral |
// Base package classes are type literals whose package should be considered a base package. // Base package classes are type literals whose package should be considered a base package.
typeLiteral = getAValue("basePackageClasses") typeLiteral = this.getAValue("basePackageClasses")
| |
result = typeLiteral.getReferencedType().(RefType).getPackage().getName() result = typeLiteral.getReferencedType().(RefType).getPackage().getName()
) )
@@ -97,10 +97,10 @@ class SpringBasePackage extends string {
class SpringComponentAnnotation extends AnnotationType { class SpringComponentAnnotation extends AnnotationType {
SpringComponentAnnotation() { SpringComponentAnnotation() {
// Component used directly as an annotation. // Component used directly as an annotation.
hasQualifiedName("org.springframework.stereotype", "Component") this.hasQualifiedName("org.springframework.stereotype", "Component")
or or
// Component can be used as a meta-annotation on other annotation types. // Component can be used as a meta-annotation on other annotation types.
getAnAnnotation().getType() instanceof SpringComponentAnnotation this.getAnAnnotation().getType() instanceof SpringComponentAnnotation
} }
} }
@@ -117,20 +117,20 @@ private predicate isSpringXMLEnabled() { exists(SpringXMLElement springXMLElemen
*/ */
class SpringComponent extends RefType { class SpringComponent extends RefType {
SpringComponent() { SpringComponent() {
getAnAnnotation().getType() instanceof SpringComponentAnnotation and this.getAnAnnotation().getType() instanceof SpringComponentAnnotation and
not this instanceof AnnotationType not this instanceof AnnotationType
} }
/** /**
* Gets a qualifier used to distinguish when this class should be autowired into other classes. * Gets a qualifier used to distinguish when this class should be autowired into other classes.
*/ */
SpringQualifierDefinitionAnnotation getQualifier() { result = getAnAnnotation() } SpringQualifierDefinitionAnnotation getQualifier() { result = this.getAnAnnotation() }
/** /**
* Gets the `@Component` or equivalent annotation. * Gets the `@Component` or equivalent annotation.
*/ */
Annotation getComponentAnnotation() { Annotation getComponentAnnotation() {
result = getAnAnnotation() and result = this.getAnAnnotation() and
result.getType() instanceof SpringComponentAnnotation result.getType() instanceof SpringComponentAnnotation
} }
@@ -138,13 +138,14 @@ class SpringComponent extends RefType {
* Gets the bean identifier for this component. * Gets the bean identifier for this component.
*/ */
string getBeanIdentifier() { string getBeanIdentifier() {
if exists(getComponentAnnotation().getValue("value")) if exists(this.getComponentAnnotation().getValue("value"))
then then
// If the name has been specified in the component annotation, use that. // If the name has been specified in the component annotation, use that.
result = getComponentAnnotation().getValue("value").(CompileTimeConstantExpr).getStringValue() result =
this.getComponentAnnotation().getValue("value").(CompileTimeConstantExpr).getStringValue()
else else
// Otherwise use the name of the class, with the initial letter lower cased. // Otherwise use the name of the class, with the initial letter lower cased.
exists(string name | name = getName() | exists(string name | name = this.getName() |
result = name.charAt(0).toLowerCase() + name.suffix(1) result = name.charAt(0).toLowerCase() + name.suffix(1)
) )
} }
@@ -154,13 +155,13 @@ class SpringComponent extends RefType {
* resolving autowiring on other classes. * resolving autowiring on other classes.
*/ */
string getQualifierValue() { string getQualifierValue() {
if exists(getQualifier()) if exists(this.getQualifier())
then then
// If given a qualifier, use the value specified. // If given a qualifier, use the value specified.
result = getQualifier().getQualifierValue() result = this.getQualifier().getQualifierValue()
else else
// Otherwise, default to the bean identifier. // Otherwise, default to the bean identifier.
result = getBeanIdentifier() result = this.getBeanIdentifier()
} }
/** /**
@@ -184,8 +185,8 @@ class SpringComponent extends RefType {
this.getPackage().getName() = sbp this.getPackage().getName() = sbp
) and ) and
( (
not exists(getAProfileExpr()) or not exists(this.getAProfileExpr()) or
getAProfileExpr().(SpringProfileExpr).isActive() this.getAProfileExpr().(SpringProfileExpr).isActive()
) )
} }
@@ -195,7 +196,7 @@ class SpringComponent extends RefType {
*/ */
string getAProfileExpr() { string getAProfileExpr() {
exists(Annotation profileAnnotation | exists(Annotation profileAnnotation |
profileAnnotation = getAnAnnotation() and profileAnnotation = this.getAnAnnotation() and
profileAnnotation profileAnnotation
.getType() .getType()
.hasQualifiedName("org.springframework.context.annotation", "Profile") .hasQualifiedName("org.springframework.context.annotation", "Profile")

View File

@@ -9,10 +9,10 @@ import SpringWebClient
class SpringControllerAnnotation extends AnnotationType { class SpringControllerAnnotation extends AnnotationType {
SpringControllerAnnotation() { SpringControllerAnnotation() {
// `@Controller` used directly as an annotation. // `@Controller` used directly as an annotation.
hasQualifiedName("org.springframework.stereotype", "Controller") this.hasQualifiedName("org.springframework.stereotype", "Controller")
or or
// `@Controller` can be used as a meta-annotation on other annotation types. // `@Controller` can be used as a meta-annotation on other annotation types.
getAnAnnotation().getType() instanceof SpringControllerAnnotation this.getAnAnnotation().getType() instanceof SpringControllerAnnotation
} }
} }
@@ -22,28 +22,30 @@ class SpringControllerAnnotation extends AnnotationType {
* Rest controllers are the same as controllers, but imply the `@ResponseBody` annotation. * Rest controllers are the same as controllers, but imply the `@ResponseBody` annotation.
*/ */
class SpringRestControllerAnnotation extends SpringControllerAnnotation { class SpringRestControllerAnnotation extends SpringControllerAnnotation {
SpringRestControllerAnnotation() { hasName("RestController") } SpringRestControllerAnnotation() { this.hasName("RestController") }
} }
/** /**
* A class annotated, directly or indirectly, as a Spring `Controller`. * A class annotated, directly or indirectly, as a Spring `Controller`.
*/ */
class SpringController extends Class { class SpringController extends Class {
SpringController() { getAnAnnotation().getType() instanceof SpringControllerAnnotation } SpringController() { this.getAnAnnotation().getType() instanceof SpringControllerAnnotation }
} }
/** /**
* A class annotated, directly or indirectly, as a Spring `RestController`. * A class annotated, directly or indirectly, as a Spring `RestController`.
*/ */
class SpringRestController extends SpringController { class SpringRestController extends SpringController {
SpringRestController() { getAnAnnotation().getType() instanceof SpringRestControllerAnnotation } SpringRestController() {
this.getAnAnnotation().getType() instanceof SpringRestControllerAnnotation
}
} }
/** /**
* A method on a Spring controller which is accessed by the Spring MVC framework. * A method on a Spring controller which is accessed by the Spring MVC framework.
*/ */
abstract class SpringControllerMethod extends Method { abstract class SpringControllerMethod extends Method {
SpringControllerMethod() { getDeclaringType() instanceof SpringController } SpringControllerMethod() { this.getDeclaringType() instanceof SpringController }
} }
/** /**
@@ -83,10 +85,10 @@ class SpringInitBinderMethod extends SpringControllerMethod {
class SpringRequestMappingAnnotationType extends AnnotationType { class SpringRequestMappingAnnotationType extends AnnotationType {
SpringRequestMappingAnnotationType() { SpringRequestMappingAnnotationType() {
// `@RequestMapping` used directly as an annotation. // `@RequestMapping` used directly as an annotation.
hasQualifiedName("org.springframework.web.bind.annotation", "RequestMapping") this.hasQualifiedName("org.springframework.web.bind.annotation", "RequestMapping")
or or
// `@RequestMapping` can be used as a meta-annotation on other annotation types, e.g. GetMapping, PostMapping etc. // `@RequestMapping` can be used as a meta-annotation on other annotation types, e.g. GetMapping, PostMapping etc.
getAnAnnotation().getType() instanceof SpringRequestMappingAnnotationType this.getAnAnnotation().getType() instanceof SpringRequestMappingAnnotationType
} }
} }
@@ -96,7 +98,7 @@ class SpringRequestMappingAnnotationType extends AnnotationType {
class SpringResponseBodyAnnotationType extends AnnotationType { class SpringResponseBodyAnnotationType extends AnnotationType {
SpringResponseBodyAnnotationType() { SpringResponseBodyAnnotationType() {
// `@ResponseBody` used directly as an annotation. // `@ResponseBody` used directly as an annotation.
hasQualifiedName("org.springframework.web.bind.annotation", "ResponseBody") this.hasQualifiedName("org.springframework.web.bind.annotation", "ResponseBody")
} }
} }
@@ -129,7 +131,7 @@ class SpringRequestMappingMethod extends SpringControllerMethod {
} }
/** Gets a request mapping parameter. */ /** Gets a request mapping parameter. */
SpringRequestMappingParameter getARequestParameter() { result = getAParameter() } SpringRequestMappingParameter getARequestParameter() { result = this.getAParameter() }
/** Gets the "produces" @RequestMapping annotation value, if present. If an array is specified, gets the array. */ /** Gets the "produces" @RequestMapping annotation value, if present. If an array is specified, gets the array. */
Expr getProducesExpr() { Expr getProducesExpr() {
@@ -158,9 +160,9 @@ class SpringRequestMappingMethod extends SpringControllerMethod {
/** Holds if this is considered an `@ResponseBody` method. */ /** Holds if this is considered an `@ResponseBody` method. */
predicate isResponseBody() { predicate isResponseBody() {
getAnAnnotation().getType() instanceof SpringResponseBodyAnnotationType or this.getAnAnnotation().getType() instanceof SpringResponseBodyAnnotationType or
getDeclaringType().getAnAnnotation().getType() instanceof SpringResponseBodyAnnotationType or this.getDeclaringType().getAnAnnotation().getType() instanceof SpringResponseBodyAnnotationType or
getDeclaringType() instanceof SpringRestController this.getDeclaringType() instanceof SpringRestController
} }
} }
@@ -185,44 +187,50 @@ class SpringServletInputAnnotation extends Annotation {
/** An annotation of the type `org.springframework.web.bind.annotation.ModelAttribute`. */ /** An annotation of the type `org.springframework.web.bind.annotation.ModelAttribute`. */
class SpringModelAttributeAnnotation extends Annotation { class SpringModelAttributeAnnotation extends Annotation {
SpringModelAttributeAnnotation() { SpringModelAttributeAnnotation() {
getType().hasQualifiedName("org.springframework.web.bind.annotation", "ModelAttribute") this.getType().hasQualifiedName("org.springframework.web.bind.annotation", "ModelAttribute")
} }
} }
/** A parameter of a `SpringRequestMappingMethod`. */ /** A parameter of a `SpringRequestMappingMethod`. */
class SpringRequestMappingParameter extends Parameter { class SpringRequestMappingParameter extends Parameter {
SpringRequestMappingParameter() { getCallable() instanceof SpringRequestMappingMethod } SpringRequestMappingParameter() { this.getCallable() instanceof SpringRequestMappingMethod }
/** Holds if the parameter should not be consider a direct source of taint. */ /** Holds if the parameter should not be consider a direct source of taint. */
predicate isNotDirectlyTaintedInput() { predicate isNotDirectlyTaintedInput() {
getType().(RefType).getAnAncestor() instanceof SpringWebRequest or this.getType().(RefType).getAnAncestor() instanceof SpringWebRequest or
getType().(RefType).getAnAncestor() instanceof SpringNativeWebRequest or this.getType().(RefType).getAnAncestor() instanceof SpringNativeWebRequest or
getType().(RefType).getAnAncestor().hasQualifiedName("javax.servlet", "ServletRequest") or this.getType().(RefType).getAnAncestor().hasQualifiedName("javax.servlet", "ServletRequest") or
getType().(RefType).getAnAncestor().hasQualifiedName("javax.servlet", "ServletResponse") or this.getType().(RefType).getAnAncestor().hasQualifiedName("javax.servlet", "ServletResponse") or
getType().(RefType).getAnAncestor().hasQualifiedName("javax.servlet.http", "HttpSession") or this.getType().(RefType).getAnAncestor().hasQualifiedName("javax.servlet.http", "HttpSession") or
getType().(RefType).getAnAncestor().hasQualifiedName("javax.servlet.http", "PushBuilder") or this.getType().(RefType).getAnAncestor().hasQualifiedName("javax.servlet.http", "PushBuilder") or
getType().(RefType).getAnAncestor().hasQualifiedName("java.security", "Principal") or this.getType().(RefType).getAnAncestor().hasQualifiedName("java.security", "Principal") or
getType().(RefType).getAnAncestor().hasQualifiedName("org.springframework.http", "HttpMethod") or this.getType()
getType().(RefType).getAnAncestor().hasQualifiedName("java.util", "Locale") or .(RefType)
getType().(RefType).getAnAncestor().hasQualifiedName("java.util", "TimeZone") or .getAnAncestor()
getType().(RefType).getAnAncestor().hasQualifiedName("java.time", "ZoneId") or .hasQualifiedName("org.springframework.http", "HttpMethod") or
getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "OutputStream") or this.getType().(RefType).getAnAncestor().hasQualifiedName("java.util", "Locale") or
getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "Writer") or this.getType().(RefType).getAnAncestor().hasQualifiedName("java.util", "TimeZone") or
getType() this.getType().(RefType).getAnAncestor().hasQualifiedName("java.time", "ZoneId") or
this.getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "OutputStream") or
this.getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "Writer") or
this.getType()
.(RefType) .(RefType)
.getAnAncestor() .getAnAncestor()
.hasQualifiedName("org.springframework.web.servlet.mvc.support", "RedirectAttributes") or .hasQualifiedName("org.springframework.web.servlet.mvc.support", "RedirectAttributes") or
// Also covers BindingResult. Note, you can access the field value through this interface, which should be considered tainted // Also covers BindingResult. Note, you can access the field value through this interface, which should be considered tainted
getType().(RefType).getAnAncestor().hasQualifiedName("org.springframework.validation", "Errors") or this.getType()
getType() .(RefType)
.getAnAncestor()
.hasQualifiedName("org.springframework.validation", "Errors") or
this.getType()
.(RefType) .(RefType)
.getAnAncestor() .getAnAncestor()
.hasQualifiedName("org.springframework.web.bind.support", "SessionStatus") or .hasQualifiedName("org.springframework.web.bind.support", "SessionStatus") or
getType() this.getType()
.(RefType) .(RefType)
.getAnAncestor() .getAnAncestor()
.hasQualifiedName("org.springframework.web.util", "UriComponentsBuilder") or .hasQualifiedName("org.springframework.web.util", "UriComponentsBuilder") or
getType() this.getType()
.(RefType) .(RefType)
.getAnAncestor() .getAnAncestor()
.hasQualifiedName("org.springframework.data.domain", "Pageable") or .hasQualifiedName("org.springframework.data.domain", "Pageable") or
@@ -231,13 +239,13 @@ class SpringRequestMappingParameter extends Parameter {
private predicate isExplicitlyTaintedInput() { private predicate isExplicitlyTaintedInput() {
// InputStream or Reader parameters allow access to the body of a request // InputStream or Reader parameters allow access to the body of a request
getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "InputStream") or this.getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "InputStream") or
getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "Reader") or this.getType().(RefType).getAnAncestor().hasQualifiedName("java.io", "Reader") or
// The SpringServletInputAnnotations allow access to the URI, request parameters, cookie values and the body of the request // The SpringServletInputAnnotations allow access to the URI, request parameters, cookie values and the body of the request
this.getAnAnnotation() instanceof SpringServletInputAnnotation or this.getAnAnnotation() instanceof SpringServletInputAnnotation or
// HttpEntity is like @RequestBody, but with a wrapper including the headers // HttpEntity is like @RequestBody, but with a wrapper including the headers
// TODO model unwrapping aspects // TODO model unwrapping aspects
getType().(RefType).getASourceSupertype*() instanceof SpringHttpEntity or this.getType().(RefType).getASourceSupertype*() instanceof SpringHttpEntity or
this.getAnAnnotation() this.getAnAnnotation()
.getType() .getType()
.hasQualifiedName("org.springframework.web.bind.annotation", "RequestAttribute") or .hasQualifiedName("org.springframework.web.bind.annotation", "RequestAttribute") or
@@ -249,35 +257,35 @@ class SpringRequestMappingParameter extends Parameter {
private predicate isImplicitRequestParam() { private predicate isImplicitRequestParam() {
// Any parameter which is not explicitly handled, is consider to be an `@RequestParam`, if // Any parameter which is not explicitly handled, is consider to be an `@RequestParam`, if
// it is a simple bean property // it is a simple bean property
not isNotDirectlyTaintedInput() and not this.isNotDirectlyTaintedInput() and
not isExplicitlyTaintedInput() and not this.isExplicitlyTaintedInput() and
( (
getType() instanceof PrimitiveType or this.getType() instanceof PrimitiveType or
getType() instanceof TypeString this.getType() instanceof TypeString
) )
} }
private predicate isImplicitModelAttribute() { private predicate isImplicitModelAttribute() {
// Any parameter which is not explicitly handled, is consider to be an `@ModelAttribute`, if // Any parameter which is not explicitly handled, is consider to be an `@ModelAttribute`, if
// it is not an implicit request param // it is not an implicit request param
not isNotDirectlyTaintedInput() and not this.isNotDirectlyTaintedInput() and
not isExplicitlyTaintedInput() and not this.isExplicitlyTaintedInput() and
not isImplicitRequestParam() not this.isImplicitRequestParam()
} }
/** Holds if this is an explicit or implicit `@ModelAttribute` parameter. */ /** Holds if this is an explicit or implicit `@ModelAttribute` parameter. */
predicate isModelAttribute() { predicate isModelAttribute() {
isImplicitModelAttribute() or this.isImplicitModelAttribute() or
getAnAnnotation() instanceof SpringModelAttributeAnnotation this.getAnAnnotation() instanceof SpringModelAttributeAnnotation
} }
/** Holds if the input is tainted. */ /** Holds if the input is tainted. */
predicate isTaintedInput() { predicate isTaintedInput() {
isExplicitlyTaintedInput() this.isExplicitlyTaintedInput()
or or
// Any parameter which is not explicitly identified, is consider to be an `@RequestParam`, if // Any parameter which is not explicitly identified, is consider to be an `@RequestParam`, if
// it is a simple bean property) or a @ModelAttribute if not // it is a simple bean property) or a @ModelAttribute if not
not isNotDirectlyTaintedInput() not this.isNotDirectlyTaintedInput()
} }
} }
@@ -286,7 +294,7 @@ class SpringRequestMappingParameter extends Parameter {
* the method, which will be used to render the response e.g. as a JSP file. * the method, which will be used to render the response e.g. as a JSP file.
*/ */
abstract class SpringModel extends Parameter { abstract class SpringModel extends Parameter {
SpringModel() { getCallable() instanceof SpringRequestMappingMethod } SpringModel() { this.getCallable() instanceof SpringRequestMappingMethod }
/** /**
* Types for which instances are placed inside the model. * Types for which instances are placed inside the model.
@@ -298,11 +306,11 @@ abstract class SpringModel extends Parameter {
* A `java.util.Map` can be accepted as the model parameter for a Spring `RequestMapping` method. * A `java.util.Map` can be accepted as the model parameter for a Spring `RequestMapping` method.
*/ */
class SpringModelPlainMap extends SpringModel { class SpringModelPlainMap extends SpringModel {
SpringModelPlainMap() { getType() instanceof MapType } SpringModelPlainMap() { this.getType() instanceof MapType }
override RefType getATypeInModel() { override RefType getATypeInModel() {
exists(MethodAccess methodCall | exists(MethodAccess methodCall |
methodCall.getQualifier() = getAnAccess() and methodCall.getQualifier() = this.getAnAccess() and
methodCall.getCallee().hasName("put") methodCall.getCallee().hasName("put")
| |
result = methodCall.getArgument(1).getType() result = methodCall.getArgument(1).getType()
@@ -316,13 +324,13 @@ class SpringModelPlainMap extends SpringModel {
*/ */
class SpringModelModel extends SpringModel { class SpringModelModel extends SpringModel {
SpringModelModel() { SpringModelModel() {
getType().(RefType).hasQualifiedName("org.springframework.ui", "Model") or this.getType().(RefType).hasQualifiedName("org.springframework.ui", "Model") or
getType().(RefType).hasQualifiedName("org.springframework.ui", "ModelMap") this.getType().(RefType).hasQualifiedName("org.springframework.ui", "ModelMap")
} }
override RefType getATypeInModel() { override RefType getATypeInModel() {
exists(MethodAccess methodCall | exists(MethodAccess methodCall |
methodCall.getQualifier() = getAnAccess() and methodCall.getQualifier() = this.getAnAccess() and
methodCall.getCallee().hasName("addAttribute") methodCall.getCallee().hasName("addAttribute")
| |
result = methodCall.getArgument(methodCall.getNumArgument() - 1).getType() result = methodCall.getArgument(methodCall.getNumArgument() - 1).getType()

View File

@@ -18,7 +18,7 @@ class ExpressionEvaluationMethod extends Method {
* The class `org.springframework.expression.ExpressionParser`. * The class `org.springframework.expression.ExpressionParser`.
*/ */
class ExpressionParser extends RefType { class ExpressionParser extends RefType {
ExpressionParser() { hasQualifiedName("org.springframework.expression", "ExpressionParser") } ExpressionParser() { this.hasQualifiedName("org.springframework.expression", "ExpressionParser") }
} }
/** /**
@@ -26,7 +26,7 @@ class ExpressionParser extends RefType {
*/ */
class SimpleEvaluationContextBuilder extends RefType { class SimpleEvaluationContextBuilder extends RefType {
SimpleEvaluationContextBuilder() { SimpleEvaluationContextBuilder() {
hasQualifiedName("org.springframework.expression.spel.support", this.hasQualifiedName("org.springframework.expression.spel.support",
"SimpleEvaluationContext$Builder") "SimpleEvaluationContext$Builder")
} }
} }
@@ -35,7 +35,7 @@ class SimpleEvaluationContextBuilder extends RefType {
* The class `org.springframework.expression.Expression`. * The class `org.springframework.expression.Expression`.
*/ */
class Expression extends RefType { class Expression extends RefType {
Expression() { hasQualifiedName("org.springframework.expression", "Expression") } Expression() { this.hasQualifiedName("org.springframework.expression", "Expression") }
} }
/** /**
@@ -43,6 +43,6 @@ class Expression extends RefType {
*/ */
class SimpleEvaluationContext extends RefType { class SimpleEvaluationContext extends RefType {
SimpleEvaluationContext() { SimpleEvaluationContext() {
hasQualifiedName("org.springframework.expression.spel.support", "SimpleEvaluationContext") this.hasQualifiedName("org.springframework.expression.spel.support", "SimpleEvaluationContext")
} }
} }

View File

@@ -16,22 +16,22 @@ class SpringRemotingDestination extends SpringXMLElement {
* Gets the bean that this remoting destination refers to. * Gets the bean that this remoting destination refers to.
*/ */
SpringBean getSpringBean() { SpringBean getSpringBean() {
result = getParent() or result = this.getParent() or
result.getBeanIdentifier() = getAttribute("ref").getValue() result.getBeanIdentifier() = this.getAttribute("ref").getValue()
} }
/** /**
* Methods that are specifically included when the bean is exposed as a remote destination. * Methods that are specifically included when the bean is exposed as a remote destination.
*/ */
string getAnIncludeMethod() { string getAnIncludeMethod() {
result = getAttribute("include-methods").getValue().splitAt(",").trim() result = this.getAttribute("include-methods").getValue().splitAt(",").trim()
} }
/** /**
* Methods that are specifically excluded when the bean is exposed as a remote destination. * Methods that are specifically excluded when the bean is exposed as a remote destination.
*/ */
string getAnExcludeMethod() { string getAnExcludeMethod() {
result = getAttribute("exclude-methods").getValue().splitAt(",").trim() result = this.getAttribute("exclude-methods").getValue().splitAt(",").trim()
} }
} }
@@ -44,7 +44,7 @@ class SpringRemotingDestinationClass extends Class {
this = remotingDestination.getSpringBean().getClass() this = remotingDestination.getSpringBean().getClass()
) )
or or
hasAnnotation("org.springframework.flex.remoting", "RemotingDestination") and this.hasAnnotation("org.springframework.flex.remoting", "RemotingDestination") and
// Must either be a live bean, or a live component. // Must either be a live bean, or a live component.
( (
this.(SpringComponent).isLive() or this.(SpringComponent).isLive() or
@@ -66,11 +66,11 @@ class SpringRemotingDestinationClass extends Class {
* basis, only those methods that are not marked as excluded are exported. * basis, only those methods that are not marked as excluded are exported.
*/ */
predicate isIncluding() { predicate isIncluding() {
exists(Method m | m = getAMethod() | exists(Method m | m = this.getAMethod() |
m.hasAnnotation("org.springframework.flex.remoting", "RemotingInclude") m.hasAnnotation("org.springframework.flex.remoting", "RemotingInclude")
) )
or or
exists(getRemotingDestinationXML().getAnIncludeMethod()) exists(this.getRemotingDestinationXML().getAnIncludeMethod())
} }
/** /**
@@ -78,13 +78,13 @@ class SpringRemotingDestinationClass extends Class {
*/ */
Method getARemotingMethod() { Method getARemotingMethod() {
result = this.getAMethod() and result = this.getAMethod() and
if isIncluding() if this.isIncluding()
then then
result.hasAnnotation("org.springframework.flex.remoting", "RemotingInclude") or result.hasAnnotation("org.springframework.flex.remoting", "RemotingInclude") or
result.getName() = getRemotingDestinationXML().getAnIncludeMethod() result.getName() = this.getRemotingDestinationXML().getAnIncludeMethod()
else ( else (
not result.hasAnnotation("org.springframework.flex.remoting", "RemotingExclude") and not result.hasAnnotation("org.springframework.flex.remoting", "RemotingExclude") and
not result.getName() = getRemotingDestinationXML().getAnExcludeMethod() not result.getName() = this.getRemotingDestinationXML().getAnExcludeMethod()
) )
} }
} }

View File

@@ -26,10 +26,10 @@ class SpringProfileExpr extends string {
*/ */
predicate isActive() { predicate isActive() {
( (
getProfile() instanceof AlwaysEnabledSpringProfile or this.getProfile() instanceof AlwaysEnabledSpringProfile or
getProfile() instanceof SometimesEnabledSpringProfile this.getProfile() instanceof SometimesEnabledSpringProfile
) and ) and
not getProfile() instanceof NeverEnabledSpringProfile not this.getProfile() instanceof NeverEnabledSpringProfile
} }
} }
@@ -48,7 +48,7 @@ class NotSpringProfileExpr extends SpringProfileExpr {
* This profile expression is active if it can ever be evaluated to true, according to our * This profile expression is active if it can ever be evaluated to true, according to our
* knowledge of which profiles are sometimes/never/always enabled. * knowledge of which profiles are sometimes/never/always enabled.
*/ */
override predicate isActive() { not getProfile() instanceof AlwaysEnabledSpringProfile } override predicate isActive() { not this.getProfile() instanceof AlwaysEnabledSpringProfile }
} }
/** /**

View File

@@ -25,7 +25,7 @@ class SpringNativeWebRequest extends Class {
*/ */
class ModelAndView extends Class { class ModelAndView extends Class {
ModelAndView() { ModelAndView() {
hasQualifiedName(["org.springframework.web.servlet", "org.springframework.web.portlet"], this.hasQualifiedName(["org.springframework.web.servlet", "org.springframework.web.portlet"],
"ModelAndView") "ModelAndView")
} }
} }
@@ -33,7 +33,7 @@ class ModelAndView extends Class {
/** A call to the Spring `ModelAndView.setViewName` method. */ /** A call to the Spring `ModelAndView.setViewName` method. */
class SpringModelAndViewSetViewNameCall extends MethodAccess { class SpringModelAndViewSetViewNameCall extends MethodAccess {
SpringModelAndViewSetViewNameCall() { SpringModelAndViewSetViewNameCall() {
getMethod().getDeclaringType() instanceof ModelAndView and this.getMethod().getDeclaringType() instanceof ModelAndView and
getMethod().hasName("setViewName") this.getMethod().hasName("setViewName")
} }
} }

View File

@@ -86,7 +86,7 @@ class Struts2ActionClass extends Class {
* Holds if this action class extends the preparable interface. * Holds if this action class extends the preparable interface.
*/ */
predicate isPreparable() { predicate isPreparable() {
getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Preparable") this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Preparable")
} }
/** /**
@@ -96,10 +96,10 @@ class Struts2ActionClass extends Class {
* methods only exist if the class `isPreparable()`. * methods only exist if the class `isPreparable()`.
*/ */
Method getPrepareMethod() { Method getPrepareMethod() {
isPreparable() and this.isPreparable() and
exists(Struts2ActionMethod actionMethod | exists(Struts2ActionMethod actionMethod |
actionMethod = getActionMethod() and actionMethod = this.getActionMethod() and
inherits(result) and this.inherits(result) and
result result
.hasName("prepare" + actionMethod.getName().charAt(0).toUpperCase() + .hasName("prepare" + actionMethod.getName().charAt(0).toUpperCase() +
actionMethod.getName().suffix(1)) actionMethod.getName().suffix(1))

View File

@@ -16,7 +16,7 @@ class StrutsActionAnnotation extends StrutsAnnotation {
StrutsActionAnnotation() { this.getType().hasName("Action") } StrutsActionAnnotation() { this.getType().hasName("Action") }
Callable getActionCallable() { Callable getActionCallable() {
result = getAnnotatedElement() result = this.getAnnotatedElement()
or or
exists(StrutsActionsAnnotation actions | this = actions.getAnAction() | exists(StrutsActionsAnnotation actions | this = actions.getAnAction() |
result = actions.getAnnotatedElement() result = actions.getAnnotatedElement()

View File

@@ -8,8 +8,8 @@ import semmle.code.xml.MavenPom
*/ */
library class Struts2ConventionDependency extends Dependency { library class Struts2ConventionDependency extends Dependency {
Struts2ConventionDependency() { Struts2ConventionDependency() {
getGroup().getValue() = "org.apache.struts" and this.getGroup().getValue() = "org.apache.struts" and
getArtifact().getValue() = "struts2-convention-plugin" this.getArtifact().getValue() = "struts2-convention-plugin"
} }
} }
@@ -100,7 +100,7 @@ class Struts2ConventionActionClass extends Class {
isStrutsConventionPluginUsed(this) and isStrutsConventionPluginUsed(this) and
exists(string ancestorPackage | exists(string ancestorPackage |
// Has an ancestor package on the whitelist // Has an ancestor package on the whitelist
ancestorPackage = getPackage().getName().splitAt(".") and ancestorPackage = this.getPackage().getName().splitAt(".") and
( (
ancestorPackage = "struts" or ancestorPackage = "struts" or
ancestorPackage = "struts2" or ancestorPackage = "struts2" or
@@ -109,7 +109,7 @@ class Struts2ConventionActionClass extends Class {
) )
) and ) and
( (
getName().matches("%" + getConventionSuffix(this)) or this.getName().matches("%" + getConventionSuffix(this)) or
this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Action") this.getAnAncestor().hasQualifiedName("com.opensymphony.xwork2", "Action")
) )
} }

View File

@@ -31,18 +31,18 @@ abstract class StrutsXMLFile extends XMLFile {
/** /**
* Gets a transitively included file. * Gets a transitively included file.
*/ */
StrutsXMLFile getAnIncludedFile() { result = getADirectlyIncludedFile*() } StrutsXMLFile getAnIncludedFile() { result = this.getADirectlyIncludedFile*() }
/** /**
* Gets a `<constant>` defined in this file, or an included file. * Gets a `<constant>` defined in this file, or an included file.
*/ */
StrutsXMLConstant getAConstant() { result.getFile() = getAnIncludedFile() } StrutsXMLConstant getAConstant() { result.getFile() = this.getAnIncludedFile() }
/** /**
* Gets the value of the constant with the given `name`. * Gets the value of the constant with the given `name`.
*/ */
string getConstantValue(string name) { string getConstantValue(string name) {
exists(StrutsXMLConstant constant | constant = getAConstant() | exists(StrutsXMLConstant constant | constant = this.getAConstant() |
constant.getConstantName() = name and constant.getConstantName() = name and
result = constant.getConstantValue() result = constant.getConstantValue()
) )
@@ -56,8 +56,8 @@ abstract class StrutsXMLFile extends XMLFile {
*/ */
class StrutsRootXMLFile extends StrutsXMLFile { class StrutsRootXMLFile extends StrutsXMLFile {
StrutsRootXMLFile() { StrutsRootXMLFile() {
getBaseName() = "struts.xml" or this.getBaseName() = "struts.xml" or
getBaseName() = "struts-plugin.xml" this.getBaseName() = "struts-plugin.xml"
} }
} }
@@ -73,7 +73,7 @@ class StrutsIncludedXMLFile extends StrutsXMLFile {
*/ */
class StrutsFolder extends Folder { class StrutsFolder extends Folder {
StrutsFolder() { StrutsFolder() {
exists(Container c | c = getAChildContainer() | exists(Container c | c = this.getAChildContainer() |
c instanceof StrutsFolder or c instanceof StrutsFolder or
c instanceof StrutsXMLFile c instanceof StrutsXMLFile
) )
@@ -82,14 +82,14 @@ class StrutsFolder extends Folder {
/** /**
* Holds if this folder has a unique Struts root configuration file. * Holds if this folder has a unique Struts root configuration file.
*/ */
predicate isUnique() { count(getAStrutsRootFile()) = 1 } predicate isUnique() { count(this.getAStrutsRootFile()) = 1 }
/** /**
* Gets a struts root configuration that applies to this folder. * Gets a struts root configuration that applies to this folder.
*/ */
StrutsRootXMLFile getAStrutsRootFile() { StrutsRootXMLFile getAStrutsRootFile() {
result = getAChildContainer() or result = this.getAChildContainer() or
result = getAChildContainer().(StrutsFolder).getAStrutsRootFile() result = this.getAChildContainer().(StrutsFolder).getAStrutsRootFile()
} }
} }
@@ -102,7 +102,7 @@ class StrutsXMLElement extends XMLElement {
/** /**
* Gets the value for this element, with leading and trailing whitespace trimmed. * Gets the value for this element, with leading and trailing whitespace trimmed.
*/ */
string getValue() { result = allCharactersString().trim() } string getValue() { result = this.allCharactersString().trim() }
} }
/** /**
@@ -121,7 +121,7 @@ class StrutsXMLInclude extends StrutsXMLElement {
* potentially be included. * potentially be included.
*/ */
XMLFile getIncludedFile() { XMLFile getIncludedFile() {
exists(string file | file = getAttribute("file").getValue() | exists(string file | file = this.getAttribute("file").getValue() |
result.getAbsolutePath().matches("%" + escapeForMatch(file)) result.getAbsolutePath().matches("%" + escapeForMatch(file))
) )
} }
@@ -157,10 +157,10 @@ class StrutsXMLAction extends StrutsXMLElement {
* Gets the `Class` that is referenced by this Struts action. * Gets the `Class` that is referenced by this Struts action.
*/ */
Class getActionClass() { Class getActionClass() {
strutsWildcardMatching(result.getQualifiedName(), getAttribute("class").getValue()) strutsWildcardMatching(result.getQualifiedName(), this.getAttribute("class").getValue())
} }
string getMethodName() { result = getAttribute("method").getValue() } string getMethodName() { result = this.getAttribute("method").getValue() }
/** /**
* Gets the `Method` which is referenced by this action. * Gets the `Method` which is referenced by this action.
@@ -168,9 +168,9 @@ class StrutsXMLAction extends StrutsXMLElement {
* If no method is specified in the attributes of this element, a method named `execute` is chosen. * If no method is specified in the attributes of this element, a method named `execute` is chosen.
*/ */
Method getActionMethod() { Method getActionMethod() {
getActionClass().inherits(result) and this.getActionClass().inherits(result) and
if exists(getMethodName()) if exists(this.getMethodName())
then strutsWildcardMatching(result.getName(), getMethodName()) then strutsWildcardMatching(result.getName(), this.getMethodName())
else result.hasName("execute") else result.hasName("execute")
} }
} }
@@ -179,9 +179,9 @@ class StrutsXMLAction extends StrutsXMLElement {
* A `<constant>` property, representing a configuration parameter to struts. * A `<constant>` property, representing a configuration parameter to struts.
*/ */
class StrutsXMLConstant extends StrutsXMLElement { class StrutsXMLConstant extends StrutsXMLElement {
StrutsXMLConstant() { getName() = "constant" } StrutsXMLConstant() { this.getName() = "constant" }
string getConstantName() { result = getAttribute("name").getValue() } string getConstantName() { result = this.getAttribute("name").getValue() }
string getConstantValue() { result = getAttribute("value").getValue() } string getConstantValue() { result = this.getAttribute("value").getValue() }
} }

View File

@@ -137,7 +137,9 @@ class MetricRefType extends RefType, MetricElement {
/** Holds if the specified callable should be included in the CK cohesion computation. */ /** Holds if the specified callable should be included in the CK cohesion computation. */
predicate includeInLackOfCohesionCK(Callable c) { predicate includeInLackOfCohesionCK(Callable c) {
not c instanceof TestMethod and not c instanceof TestMethod and
exists(Field f | c.getDeclaringType() = this and c.accesses(f) and relevantFieldForCohesion(f)) exists(Field f |
c.getDeclaringType() = this and c.accesses(f) and this.relevantFieldForCohesion(f)
)
} }
pragma[noopt] pragma[noopt]
@@ -152,8 +154,8 @@ class MetricRefType extends RefType, MetricElement {
/** Holds if a (non-ignored) callable reads a field relevant for cohesion. */ /** Holds if a (non-ignored) callable reads a field relevant for cohesion. */
private predicate relevantCallableAndFieldCK(Callable m, Field f) { private predicate relevantCallableAndFieldCK(Callable m, Field f) {
includeInLackOfCohesionCK(m) and this.includeInLackOfCohesionCK(m) and
relevantFieldForCohesion(f) and this.relevantFieldForCohesion(f) and
m.accesses(f) and m.accesses(f) and
m.getDeclaringType() = this m.getDeclaringType() = this
} }
@@ -180,12 +182,12 @@ class MetricRefType extends RefType, MetricElement {
*/ */
float getLackOfCohesionCK() { float getLackOfCohesionCK() {
exists(int callables, int linked, float n | exists(int callables, int linked, float n |
callables = count(Callable m | includeInLackOfCohesionCK(m)) and callables = count(Callable m | this.includeInLackOfCohesionCK(m)) and
linked = linked =
count(Callable m1, Callable m2 | count(Callable m1, Callable m2 |
exists(Field f | exists(Field f |
relevantCallableAndFieldCK(m1, f) and this.relevantCallableAndFieldCK(m1, f) and
relevantCallableAndFieldCK(m2, f) and this.relevantCallableAndFieldCK(m2, f) and
m1 != m2 m1 != m2
) )
) and ) and
@@ -207,7 +209,7 @@ class MetricRefType extends RefType, MetricElement {
int getADepth() { int getADepth() {
this.hasQualifiedName("java.lang", "Object") and result = 0 this.hasQualifiedName("java.lang", "Object") and result = 0
or or
not cyclic() and result = this.getASupertype().(MetricRefType).getADepth() + 1 not this.cyclic() and result = this.getASupertype().(MetricRefType).getADepth() + 1
} }
/** /**
@@ -229,10 +231,10 @@ class MetricRefType extends RefType, MetricElement {
int getADepth(RefType reference) { int getADepth(RefType reference) {
this = reference and result = 0 this = reference and result = 0
or or
not cyclic() and result = this.getASupertype().(MetricRefType).getADepth(reference) + 1 not this.cyclic() and result = this.getASupertype().(MetricRefType).getADepth(reference) + 1
} }
private predicate cyclic() { getASupertype+() = this } private predicate cyclic() { this.getASupertype+() = this }
/** Gets the depth of inheritance metric relative to the specified reference type. */ /** Gets the depth of inheritance metric relative to the specified reference type. */
int getInheritanceDepth(RefType reference) { result = max(this.getADepth(reference)) } int getInheritanceDepth(RefType reference) { result = max(this.getADepth(reference)) }

View File

@@ -69,10 +69,10 @@ private class CommandArgumentList extends SsaExplicitUpdate {
/** Gets a use of the variable for which the list could be empty. */ /** Gets a use of the variable for which the list could be empty. */
private RValue getAUseBeforeFirstAdd() { private RValue getAUseBeforeFirstAdd() {
result = getAFirstUse() result = this.getAFirstUse()
or or
exists(RValue mid | exists(RValue mid |
mid = getAUseBeforeFirstAdd() and mid = this.getAUseBeforeFirstAdd() and
adjacentUseUse(mid, result) and adjacentUseUse(mid, result) and
not exists(MethodAccess ma | not exists(MethodAccess ma |
mid = ma.getQualifier() and mid = ma.getQualifier() and
@@ -85,25 +85,25 @@ private class CommandArgumentList extends SsaExplicitUpdate {
* Gets an addition to this list, i.e. a call to an `add` or `addAll` method. * Gets an addition to this list, i.e. a call to an `add` or `addAll` method.
*/ */
MethodAccess getAnAdd() { MethodAccess getAnAdd() {
result.getQualifier() = getAUse() and result.getQualifier() = this.getAUse() and
result.getMethod().getName().matches("add%") result.getMethod().getName().matches("add%")
} }
/** Gets an addition to this list which could be its first element. */ /** Gets an addition to this list which could be its first element. */
MethodAccess getAFirstAdd() { MethodAccess getAFirstAdd() {
result = getAnAdd() and result = this.getAnAdd() and
result.getQualifier() = getAUseBeforeFirstAdd() result.getQualifier() = this.getAUseBeforeFirstAdd()
} }
/** Gets an addition to this list which is not the first element. */ /** Gets an addition to this list which is not the first element. */
MethodAccess getASubsequentAdd() { MethodAccess getASubsequentAdd() {
result = getAnAdd() and result = this.getAnAdd() and
not result = getAFirstAdd() not result = this.getAFirstAdd()
} }
/** Holds if the first element of this list is a shell command. */ /** Holds if the first element of this list is a shell command. */
predicate isShell() { predicate isShell() {
exists(MethodAccess ma | ma = getAFirstAdd() and isShell(ma.getArgument(0))) exists(MethodAccess ma | ma = this.getAFirstAdd() and isShell(ma.getArgument(0)))
} }
} }
@@ -122,7 +122,7 @@ private predicate arrayLValue(ArrayAccess acc) { exists(Assignment a | a.getDest
private class CommandArgumentArray extends SsaExplicitUpdate { private class CommandArgumentArray extends SsaExplicitUpdate {
CommandArgumentArray() { CommandArgumentArray() {
this.getSourceVariable().getType() instanceof ArrayOfStringType and this.getSourceVariable().getType() instanceof ArrayOfStringType and
forall(ArrayAccess a | a.getArray() = getAUse() and arrayLValue(a) | forall(ArrayAccess a | a.getArray() = this.getAUse() and arrayLValue(a) |
a.getIndexExpr() instanceof CompileTimeConstantExpr a.getIndexExpr() instanceof CompileTimeConstantExpr
) )
} }
@@ -139,7 +139,7 @@ private class CommandArgumentArray extends SsaExplicitUpdate {
} }
/** Gets an expression that is written to the given index of this array. */ /** Gets an expression that is written to the given index of this array. */
Expr getAWrite(int index) { result = getAWrite(index, _) } Expr getAWrite(int index) { result = this.getAWrite(index, _) }
} }
/** /**
@@ -147,20 +147,20 @@ private class CommandArgumentArray extends SsaExplicitUpdate {
*/ */
private class CommandArgArrayImmutableFirst extends CommandArgumentArray { private class CommandArgArrayImmutableFirst extends CommandArgumentArray {
CommandArgArrayImmutableFirst() { CommandArgArrayImmutableFirst() {
(exists(getAWrite(0)) or exists(firstElementOf(this.getDefiningExpr()))) and (exists(this.getAWrite(0)) or exists(firstElementOf(this.getDefiningExpr()))) and
forall(RValue use | exists(this.getAWrite(0, use)) | use = this.getAFirstUse()) forall(RValue use | exists(this.getAWrite(0, use)) | use = this.getAFirstUse())
} }
/** Gets the first element of this array. */ /** Gets the first element of this array. */
Expr getFirstElement() { Expr getFirstElement() {
result = getAWrite(0) result = this.getAWrite(0)
or or
not exists(getAWrite(0)) and not exists(this.getAWrite(0)) and
result = firstElementOf(getDefiningExpr()) result = firstElementOf(this.getDefiningExpr())
} }
/** Holds if the first element of this array is a shell command. */ /** Holds if the first element of this array is a shell command. */
predicate isShell() { isShell(getFirstElement()) } predicate isShell() { isShell(this.getFirstElement()) }
} }
/** Gets the first element of an imutable array of strings */ /** Gets the first element of an imutable array of strings */

View File

@@ -18,7 +18,7 @@ class X509TrustManager extends RefType {
} }
class HttpsURLConnection extends RefType { class HttpsURLConnection extends RefType {
HttpsURLConnection() { hasQualifiedName("javax.net.ssl", "HttpsURLConnection") } HttpsURLConnection() { this.hasQualifiedName("javax.net.ssl", "HttpsURLConnection") }
} }
class SSLSocketFactory extends RefType { class SSLSocketFactory extends RefType {
@@ -26,16 +26,16 @@ class SSLSocketFactory extends RefType {
} }
class SSLContext extends RefType { class SSLContext extends RefType {
SSLContext() { hasQualifiedName("javax.net.ssl", "SSLContext") } SSLContext() { this.hasQualifiedName("javax.net.ssl", "SSLContext") }
} }
/** The `javax.net.ssl.SSLSession` class. */ /** The `javax.net.ssl.SSLSession` class. */
class SSLSession extends RefType { class SSLSession extends RefType {
SSLSession() { hasQualifiedName("javax.net.ssl", "SSLSession") } SSLSession() { this.hasQualifiedName("javax.net.ssl", "SSLSession") }
} }
class HostnameVerifier extends RefType { class HostnameVerifier extends RefType {
HostnameVerifier() { hasQualifiedName("javax.net.ssl", "HostnameVerifier") } HostnameVerifier() { this.hasQualifiedName("javax.net.ssl", "HostnameVerifier") }
} }
/** The Java class `javax.crypto.KeyGenerator`. */ /** The Java class `javax.crypto.KeyGenerator`. */
@@ -51,10 +51,10 @@ class KeyPairGenerator extends RefType {
/** The `verify` method of the class `javax.net.ssl.HostnameVerifier`. */ /** The `verify` method of the class `javax.net.ssl.HostnameVerifier`. */
class HostnameVerifierVerify extends Method { class HostnameVerifierVerify extends Method {
HostnameVerifierVerify() { HostnameVerifierVerify() {
hasName("verify") and this.hasName("verify") and
getDeclaringType().getASupertype*() instanceof HostnameVerifier and this.getDeclaringType().getASupertype*() instanceof HostnameVerifier and
getParameterType(0) instanceof TypeString and this.getParameterType(0) instanceof TypeString and
getParameterType(1) instanceof SSLSession this.getParameterType(1) instanceof SSLSession
} }
} }
@@ -67,37 +67,37 @@ class TrustManagerCheckMethod extends Method {
class CreateSocket extends Method { class CreateSocket extends Method {
CreateSocket() { CreateSocket() {
hasName("createSocket") and this.hasName("createSocket") and
getDeclaringType() instanceof SSLSocketFactory this.getDeclaringType() instanceof SSLSocketFactory
} }
} }
class GetSocketFactory extends Method { class GetSocketFactory extends Method {
GetSocketFactory() { GetSocketFactory() {
hasName("getSocketFactory") and this.hasName("getSocketFactory") and
getDeclaringType() instanceof SSLContext this.getDeclaringType() instanceof SSLContext
} }
} }
class SetConnectionFactoryMethod extends Method { class SetConnectionFactoryMethod extends Method {
SetConnectionFactoryMethod() { SetConnectionFactoryMethod() {
hasName("setSSLSocketFactory") and this.hasName("setSSLSocketFactory") and
getDeclaringType().getASupertype*() instanceof HttpsURLConnection this.getDeclaringType().getASupertype*() instanceof HttpsURLConnection
} }
} }
class SetHostnameVerifierMethod extends Method { class SetHostnameVerifierMethod extends Method {
SetHostnameVerifierMethod() { SetHostnameVerifierMethod() {
hasName("setHostnameVerifier") and this.hasName("setHostnameVerifier") and
getDeclaringType().getASupertype*() instanceof HttpsURLConnection this.getDeclaringType().getASupertype*() instanceof HttpsURLConnection
} }
} }
/** The `setDefaultHostnameVerifier` method of the class `javax.net.ssl.HttpsURLConnection`. */ /** The `setDefaultHostnameVerifier` method of the class `javax.net.ssl.HttpsURLConnection`. */
class SetDefaultHostnameVerifierMethod extends Method { class SetDefaultHostnameVerifierMethod extends Method {
SetDefaultHostnameVerifierMethod() { SetDefaultHostnameVerifierMethod() {
hasName("setDefaultHostnameVerifier") and this.hasName("setDefaultHostnameVerifier") and
getDeclaringType().getASupertype*() instanceof HttpsURLConnection this.getDeclaringType().getASupertype*() instanceof HttpsURLConnection
} }
} }

View File

@@ -17,38 +17,38 @@ private class DefaultSafeExternalAPIMethod extends SafeExternalAPIMethod {
DefaultSafeExternalAPIMethod() { DefaultSafeExternalAPIMethod() {
this instanceof EqualsMethod this instanceof EqualsMethod
or or
getName().regexpMatch("size|length|compareTo|getClass|lastIndexOf") this.getName().regexpMatch("size|length|compareTo|getClass|lastIndexOf")
or or
this.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "Validate") this.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "Validate")
or or
getQualifiedName() = "Objects.equals" this.getQualifiedName() = "Objects.equals"
or or
getDeclaringType() instanceof TypeString and getName() = "equals" this.getDeclaringType() instanceof TypeString and this.getName() = "equals"
or or
getDeclaringType().hasQualifiedName("com.google.common.base", "Preconditions") this.getDeclaringType().hasQualifiedName("com.google.common.base", "Preconditions")
or or
getDeclaringType().getPackage().getName().matches("org.junit%") this.getDeclaringType().getPackage().getName().matches("org.junit%")
or or
getDeclaringType().hasQualifiedName("com.google.common.base", "Strings") and this.getDeclaringType().hasQualifiedName("com.google.common.base", "Strings") and
getName() = "isNullOrEmpty" this.getName() = "isNullOrEmpty"
or or
getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "StringUtils") and this.getDeclaringType().hasQualifiedName("org.apache.commons.lang3", "StringUtils") and
getName() = "isNotEmpty" this.getName() = "isNotEmpty"
or or
getDeclaringType().hasQualifiedName("java.lang", "Character") and this.getDeclaringType().hasQualifiedName("java.lang", "Character") and
getName() = "isDigit" this.getName() = "isDigit"
or or
getDeclaringType().hasQualifiedName("java.lang", "String") and this.getDeclaringType().hasQualifiedName("java.lang", "String") and
getName().regexpMatch("equalsIgnoreCase|regionMatches") this.getName().regexpMatch("equalsIgnoreCase|regionMatches")
or or
getDeclaringType().hasQualifiedName("java.lang", "Boolean") and this.getDeclaringType().hasQualifiedName("java.lang", "Boolean") and
getName() = "parseBoolean" this.getName() = "parseBoolean"
or or
getDeclaringType().hasQualifiedName("org.apache.commons.io", "IOUtils") and this.getDeclaringType().hasQualifiedName("org.apache.commons.io", "IOUtils") and
getName() = "closeQuietly" this.getName() = "closeQuietly"
or or
getDeclaringType().hasQualifiedName("org.springframework.util", "StringUtils") and this.getDeclaringType().hasQualifiedName("org.springframework.util", "StringUtils") and
getName().regexpMatch("hasText|isEmpty") this.getName().regexpMatch("hasText|isEmpty")
} }
} }
@@ -90,7 +90,8 @@ class ExternalAPIDataNode extends DataFlow::Node {
/** Gets the description of the method being called. */ /** Gets the description of the method being called. */
string getMethodDescription() { string getMethodDescription() {
result = getMethod().getDeclaringType().getPackage() + "." + getMethod().getQualifiedName() result =
this.getMethod().getDeclaringType().getPackage() + "." + this.getMethod().getQualifiedName()
} }
} }
@@ -130,7 +131,7 @@ class ExternalAPIUsedWithUntrustedData extends TExternalAPI {
/** Gets the number of untrusted sources used with this external API. */ /** Gets the number of untrusted sources used with this external API. */
int getNumberOfUntrustedSources() { int getNumberOfUntrustedSources() {
result = count(getUntrustedDataNode().getAnUntrustedSource()) result = count(this.getUntrustedDataNode().getAnUntrustedSource())
} }
/** Gets a textual representation of this element. */ /** Gets a textual representation of this element. */

View File

@@ -168,7 +168,9 @@ private predicate createJexlEngineStep(DataFlow::Node fromNode, DataFlow::Node t
* A method that creates a JEXL script. * A method that creates a JEXL script.
*/ */
private class CreateJexlScriptMethod extends Method { private class CreateJexlScriptMethod extends Method {
CreateJexlScriptMethod() { getDeclaringType() instanceof JexlEngine and hasName("createScript") } CreateJexlScriptMethod() {
this.getDeclaringType() instanceof JexlEngine and this.hasName("createScript")
}
} }
/** /**
@@ -176,8 +178,11 @@ private class CreateJexlScriptMethod extends Method {
*/ */
private class CreateJexlTemplateMethod extends Method { private class CreateJexlTemplateMethod extends Method {
CreateJexlTemplateMethod() { CreateJexlTemplateMethod() {
(getDeclaringType() instanceof JxltEngine or getDeclaringType() instanceof UnifiedJexl) and (
hasName("createTemplate") this.getDeclaringType() instanceof JxltEngine or
this.getDeclaringType() instanceof UnifiedJexl
) and
this.hasName("createTemplate")
} }
} }
@@ -186,40 +191,42 @@ private class CreateJexlTemplateMethod extends Method {
*/ */
private class CreateJexlExpressionMethod extends Method { private class CreateJexlExpressionMethod extends Method {
CreateJexlExpressionMethod() { CreateJexlExpressionMethod() {
(getDeclaringType() instanceof JexlEngine or getDeclaringType() instanceof JxltEngine) and (this.getDeclaringType() instanceof JexlEngine or this.getDeclaringType() instanceof JxltEngine) and
hasName("createExpression") this.hasName("createExpression")
or or
getDeclaringType() instanceof UnifiedJexl and hasName("parse") this.getDeclaringType() instanceof UnifiedJexl and this.hasName("parse")
} }
} }
private class JexlRefType extends RefType { private class JexlRefType extends RefType {
JexlRefType() { getPackage().hasName(["org.apache.commons.jexl2", "org.apache.commons.jexl3"]) } JexlRefType() {
this.getPackage().hasName(["org.apache.commons.jexl2", "org.apache.commons.jexl3"])
}
} }
private class JexlBuilder extends JexlRefType { private class JexlBuilder extends JexlRefType {
JexlBuilder() { hasName("JexlBuilder") } JexlBuilder() { this.hasName("JexlBuilder") }
} }
private class JexlEngine extends JexlRefType { private class JexlEngine extends JexlRefType {
JexlEngine() { hasName("JexlEngine") } JexlEngine() { this.hasName("JexlEngine") }
} }
private class JxltEngine extends JexlRefType { private class JxltEngine extends JexlRefType {
JxltEngine() { hasName("JxltEngine") } JxltEngine() { this.hasName("JxltEngine") }
} }
private class UnifiedJexl extends JexlRefType { private class UnifiedJexl extends JexlRefType {
UnifiedJexl() { hasName("UnifiedJEXL") } UnifiedJexl() { this.hasName("UnifiedJEXL") }
} }
private class JexlUberspect extends Interface { private class JexlUberspect extends Interface {
JexlUberspect() { JexlUberspect() {
hasQualifiedName("org.apache.commons.jexl2.introspection", "Uberspect") or this.hasQualifiedName("org.apache.commons.jexl2.introspection", "Uberspect") or
hasQualifiedName("org.apache.commons.jexl3.introspection", "JexlUberspect") this.hasQualifiedName("org.apache.commons.jexl3.introspection", "JexlUberspect")
} }
} }
private class Reader extends RefType { private class Reader extends RefType {
Reader() { hasQualifiedName("java.io", "Reader") } Reader() { this.hasQualifiedName("java.io", "Reader") }
} }

View File

@@ -183,8 +183,8 @@ private predicate templateCompileStep(DataFlow::Node node1, DataFlow::Node node2
*/ */
private class MvelScriptEngineCompilationMethod extends Method { private class MvelScriptEngineCompilationMethod extends Method {
MvelScriptEngineCompilationMethod() { MvelScriptEngineCompilationMethod() {
getDeclaringType() instanceof MvelScriptEngine and this.getDeclaringType() instanceof MvelScriptEngine and
hasName(["compile", "compiledScript"]) this.hasName(["compile", "compiledScript"])
} }
} }
@@ -193,8 +193,8 @@ private class MvelScriptEngineCompilationMethod extends Method {
*/ */
private class TemplateCompilerCompileMethod extends Method { private class TemplateCompilerCompileMethod extends Method {
TemplateCompilerCompileMethod() { TemplateCompilerCompileMethod() {
getDeclaringType() instanceof TemplateCompiler and this.getDeclaringType() instanceof TemplateCompiler and
hasName("compile") this.hasName("compile")
} }
} }
@@ -203,31 +203,31 @@ private class TemplateCompilerCompileMethod extends Method {
*/ */
private class TemplateCompilerCompileTemplateMethod extends Method { private class TemplateCompilerCompileTemplateMethod extends Method {
TemplateCompilerCompileTemplateMethod() { TemplateCompilerCompileTemplateMethod() {
getDeclaringType() instanceof TemplateCompiler and this.getDeclaringType() instanceof TemplateCompiler and
hasName("compileTemplate") this.hasName("compileTemplate")
} }
} }
private class MVEL extends RefType { private class MVEL extends RefType {
MVEL() { hasQualifiedName("org.mvel2", "MVEL") } MVEL() { this.hasQualifiedName("org.mvel2", "MVEL") }
} }
private class ExpressionCompiler extends RefType { private class ExpressionCompiler extends RefType {
ExpressionCompiler() { hasQualifiedName("org.mvel2.compiler", "ExpressionCompiler") } ExpressionCompiler() { this.hasQualifiedName("org.mvel2.compiler", "ExpressionCompiler") }
} }
private class CompiledAccExpression extends RefType { private class CompiledAccExpression extends RefType {
CompiledAccExpression() { hasQualifiedName("org.mvel2.compiler", "CompiledAccExpression") } CompiledAccExpression() { this.hasQualifiedName("org.mvel2.compiler", "CompiledAccExpression") }
} }
private class MvelScriptEngine extends RefType { private class MvelScriptEngine extends RefType {
MvelScriptEngine() { hasQualifiedName("org.mvel2.jsr223", "MvelScriptEngine") } MvelScriptEngine() { this.hasQualifiedName("org.mvel2.jsr223", "MvelScriptEngine") }
} }
private class MvelCompiledScript extends RefType { private class MvelCompiledScript extends RefType {
MvelCompiledScript() { hasQualifiedName("org.mvel2.jsr223", "MvelCompiledScript") } MvelCompiledScript() { this.hasQualifiedName("org.mvel2.jsr223", "MvelCompiledScript") }
} }
private class TemplateCompiler extends RefType { private class TemplateCompiler extends RefType {
TemplateCompiler() { hasQualifiedName("org.mvel2.templates", "TemplateCompiler") } TemplateCompiler() { this.hasQualifiedName("org.mvel2.templates", "TemplateCompiler") }
} }

View File

@@ -138,7 +138,7 @@ private class StringBuilderVarExt extends StringBuilderVar {
private StringBuilderAppend getNextAppendIncludingAssignmentChains( private StringBuilderAppend getNextAppendIncludingAssignmentChains(
StringBuilderConstructorOrAppend prev StringBuilderConstructorOrAppend prev
) { ) {
result = getNextAssignmentChainedAppend(prev) result = this.getNextAssignmentChainedAppend(prev)
or or
prev = this.getAnAssignedValue() and prev = this.getAnAssignedValue() and
result = this.getAFirstAppendAfterAssignment() result = this.getAFirstAppendAfterAssignment()

View File

@@ -58,8 +58,8 @@ private class SafeEvaluationContextFlowConfig extends DataFlow2::Configuration {
*/ */
private class SafeContextSource extends DataFlow::ExprNode { private class SafeContextSource extends DataFlow::ExprNode {
SafeContextSource() { SafeContextSource() {
isSimpleEvaluationContextConstructorCall(getExpr()) or isSimpleEvaluationContextConstructorCall(this.getExpr()) or
isSimpleEvaluationContextBuilderCall(getExpr()) isSimpleEvaluationContextBuilderCall(this.getExpr())
} }
} }

View File

@@ -67,10 +67,10 @@ private class SafeKryo extends DataFlow2::Configuration {
} }
override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) { override predicate isAdditionalFlowStep(DataFlow::Node node1, DataFlow::Node node2) {
stepKryoPoolBuilderFactoryArgToConstructor(node1, node2) or this.stepKryoPoolBuilderFactoryArgToConstructor(node1, node2) or
stepKryoPoolRunMethodAccessQualifierToFunctionalArgument(node1, node2) or this.stepKryoPoolRunMethodAccessQualifierToFunctionalArgument(node1, node2) or
stepKryoPoolBuilderChainMethod(node1, node2) or this.stepKryoPoolBuilderChainMethod(node1, node2) or
stepKryoPoolBorrowMethod(node1, node2) this.stepKryoPoolBorrowMethod(node1, node2)
} }
/** /**

View File

@@ -79,7 +79,7 @@ private class XssVulnerableWriterSourceToWritingMethodFlowConfig extends TaintTr
/** A method that can be used to output data to an output stream or writer. */ /** A method that can be used to output data to an output stream or writer. */
private class WritingMethod extends Method { private class WritingMethod extends Method {
WritingMethod() { WritingMethod() {
getDeclaringType().getASupertype*().hasQualifiedName("java.io", _) and this.getDeclaringType().getASupertype*().hasQualifiedName("java.io", _) and
( (
this.getName().matches("print%") or this.getName().matches("print%") or
this.getName() = "append" or this.getName() = "append" or

View File

@@ -36,7 +36,7 @@ class AndroidManifestXmlElement extends XMLElement {
/** /**
* Gets the value of the `package` attribute of this `<manifest>` element. * Gets the value of the `package` attribute of this `<manifest>` element.
*/ */
string getPackageAttributeValue() { result = getAttributeValue("package") } string getPackageAttributeValue() { result = this.getAttributeValue("package") }
} }
/** /**
@@ -141,7 +141,7 @@ class AndroidComponentXmlElement extends XMLElement {
*/ */
string getComponentName() { string getComponentName() {
exists(XMLAttribute attr | exists(XMLAttribute attr |
attr = getAnAttribute() and attr = this.getAnAttribute() and
attr.getNamespace().getPrefix() = "android" and attr.getNamespace().getPrefix() = "android" and
attr.getName() = "name" attr.getName() = "name"
| |
@@ -153,12 +153,15 @@ class AndroidComponentXmlElement extends XMLElement {
* Gets the resolved value of the `android:name` attribute of this component element. * Gets the resolved value of the `android:name` attribute of this component element.
*/ */
string getResolvedComponentName() { string getResolvedComponentName() {
if getComponentName().matches(".%") if this.getComponentName().matches(".%")
then then
result = result =
getParent().(XMLElement).getParent().(AndroidManifestXmlElement).getPackageAttributeValue() + this.getParent()
getComponentName() .(XMLElement)
else result = getComponentName() .getParent()
.(AndroidManifestXmlElement)
.getPackageAttributeValue() + this.getComponentName()
else result = this.getComponentName()
} }
/** /**
@@ -166,7 +169,7 @@ class AndroidComponentXmlElement extends XMLElement {
*/ */
string getExportedAttributeValue() { string getExportedAttributeValue() {
exists(XMLAttribute attr | exists(XMLAttribute attr |
attr = getAnAttribute() and attr = this.getAnAttribute() and
attr.getNamespace().getPrefix() = "android" and attr.getNamespace().getPrefix() = "android" and
attr.getName() = "exported" attr.getName() = "exported"
| |
@@ -177,12 +180,12 @@ class AndroidComponentXmlElement extends XMLElement {
/** /**
* Holds if the `android:exported` attribute of this component element is `true`. * Holds if the `android:exported` attribute of this component element is `true`.
*/ */
predicate isExported() { getExportedAttributeValue() = "true" } predicate isExported() { this.getExportedAttributeValue() = "true" }
/** /**
* Holds if the `android:exported` attribute of this component element is explicitly set to `false`. * Holds if the `android:exported` attribute of this component element is explicitly set to `false`.
*/ */
predicate isNotExported() { getExportedAttributeValue() = "false" } predicate isNotExported() { this.getExportedAttributeValue() = "false" }
} }
/** /**
@@ -212,7 +215,7 @@ class AndroidActionXmlElement extends XMLElement {
*/ */
string getActionName() { string getActionName() {
exists(XMLAttribute attr | exists(XMLAttribute attr |
attr = getAnAttribute() and attr = this.getAnAttribute() and
attr.getNamespace().getPrefix() = "android" and attr.getNamespace().getPrefix() = "android" and
attr.getName() = "name" attr.getName() = "name"
| |

Some files were not shown because too many files have changed in this diff Show More