Java: Make implicit this receivers explicit

This commit is contained in:
Kasper Svendsen
2023-05-03 10:08:04 +02:00
parent 733a00039e
commit 081085e128
46 changed files with 309 additions and 292 deletions

View File

@@ -17,33 +17,33 @@ import IDEContextual
*/
private class LocationOverridingMethodAccess extends MethodAccess {
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
exists(MemberRefExpr e | e.getReferencedCallable() = getMethod() |
exists(MemberRefExpr e | e.getReferencedCallable() = this.getMethod() |
exists(int elRef, int ecRef | e.hasLocationInfo(path, _, _, elRef, ecRef) |
sl = elRef and
sc = ecRef - getMethod().getName().length() + 1 and
sc = ecRef - this.getMethod().getName().length() + 1 and
el = elRef and
ec = ecRef
)
)
or
not exists(MemberRefExpr e | e.getReferencedCallable() = getMethod()) and
not exists(MemberRefExpr e | e.getReferencedCallable() = this.getMethod()) and
exists(int slSuper, int scSuper, int elSuper, int ecSuper |
super.hasLocationInfo(path, slSuper, scSuper, elSuper, ecSuper)
|
(
if exists(getTypeArgument(_))
if exists(this.getTypeArgument(_))
then
exists(Location locTypeArg |
locTypeArg = getTypeArgument(count(getTypeArgument(_)) - 1).getLocation()
locTypeArg = this.getTypeArgument(count(this.getTypeArgument(_)) - 1).getLocation()
|
sl = locTypeArg.getEndLine() and
sc = locTypeArg.getEndColumn() + 2
)
else (
if exists(getQualifier())
if exists(this.getQualifier())
then
// Note: this needs to be the original (full) location of the qualifier, not the modified one.
exists(Location locQual | locQual = getQualifier().getLocation() |
exists(Location locQual | locQual = this.getQualifier().getLocation() |
sl = locQual.getEndLine() and
sc = locQual.getEndColumn() + 2
)
@@ -54,10 +54,10 @@ private class LocationOverridingMethodAccess extends MethodAccess {
)
) and
(
if getNumArgument() > 0
if this.getNumArgument() > 0
then
// Note: this needs to be the original (full) location of the first argument, not the modified one.
exists(Location locArg | locArg = getArgument(0).getLocation() |
exists(Location locArg | locArg = this.getArgument(0).getLocation() |
el = locArg.getStartLine() and
ec = locArg.getStartColumn() - 2
)
@@ -80,10 +80,10 @@ private class LocationOverridingTypeAccess extends TypeAccess {
super.hasLocationInfo(path, slSuper, scSuper, elSuper, ecSuper)
|
(
if exists(getQualifier())
if exists(this.getQualifier())
then
// Note: this needs to be the original (full) location of the qualifier, not the modified one.
exists(Location locQual | locQual = getQualifier().getLocation() |
exists(Location locQual | locQual = this.getQualifier().getLocation() |
sl = locQual.getEndLine() and
sc = locQual.getEndColumn() + 2
)
@@ -93,10 +93,10 @@ private class LocationOverridingTypeAccess extends TypeAccess {
)
) and
(
if exists(getTypeArgument(_))
if exists(this.getTypeArgument(_))
then
// Note: this needs to be the original (full) location of the first type argument, not the modified one.
exists(Location locArg | locArg = getTypeArgument(0).getLocation() |
exists(Location locArg | locArg = this.getTypeArgument(0).getLocation() |
el = locArg.getStartLine() and
ec = locArg.getStartColumn() - 2
)
@@ -117,7 +117,7 @@ private class LocationOverridingFieldAccess extends FieldAccess {
override predicate hasLocationInfo(string path, int sl, int sc, int el, int ec) {
super.hasLocationInfo(path, _, _, el, ec) and
sl = el and
sc = ec - getField().getName().length() + 1
sc = ec - this.getField().getName().length() + 1
}
}
@@ -131,7 +131,7 @@ private class LocationOverridingImportType extends ImportType {
el = elSuper and
ec = ecSuper - 1 and
sl = el and
sc = ecSuper - getImportedType().getName().length()
sc = ecSuper - this.getImportedType().getName().length()
)
}
}
@@ -146,7 +146,7 @@ private class LocationOverridingImportStaticTypeMember extends ImportStaticTypeM
el = elSuper and
ec = ecSuper - 1 and
sl = el and
sc = ecSuper - getName().length()
sc = ecSuper - this.getName().length()
)
}
}

View File

@@ -11,7 +11,7 @@ abstract class ConfigLocatable extends @configLocatable {
Location getLocation() { configLocations(this, result) }
/** Gets the file associated with this element. */
File getFile() { result = getLocation().getFile() }
File getFile() { result = this.getLocation().getFile() }
/** Gets a textual representation of this element. */
abstract string toString();
@@ -33,7 +33,7 @@ class ConfigPair extends @config, ConfigLocatable {
* it exists and the empty string if it doesn't.
*/
string getEffectiveName() {
if exists(getNameElement()) then result = getNameElement().getName() else result = ""
if exists(this.getNameElement()) then result = this.getNameElement().getName() else result = ""
}
/**
@@ -41,11 +41,13 @@ class ConfigPair extends @config, ConfigLocatable {
* it exists and the empty string if it doesn't.
*/
string getEffectiveValue() {
if exists(getValueElement()) then result = getValueElement().getValue() else result = ""
if exists(this.getValueElement())
then result = this.getValueElement().getValue()
else result = ""
}
/** Gets a printable representation of this `ConfigPair`. */
override string toString() { result = getEffectiveName() + "=" + getEffectiveValue() }
override string toString() { result = this.getEffectiveName() + "=" + this.getEffectiveValue() }
}
/** The name element of a `ConfigPair`. */
@@ -54,7 +56,7 @@ class ConfigName extends @configName, ConfigLocatable {
string getName() { configNames(this, _, result) }
/** Gets a printable representation of this `ConfigName`. */
override string toString() { result = getName() }
override string toString() { result = this.getName() }
}
/** The value element of a `ConfigPair`. */
@@ -63,10 +65,10 @@ class ConfigValue extends @configValue, ConfigLocatable {
string getValue() { configValues(this, _, result) }
/** Gets a printable representation of this `ConfigValue`. */
override string toString() { result = getValue() }
override string toString() { result = this.getValue() }
}
/** A Java property is a name-value pair in a `.properties` file. */
class JavaProperty extends ConfigPair {
JavaProperty() { getFile().getExtension() = "properties" }
JavaProperty() { this.getFile().getExtension() = "properties" }
}

View File

@@ -31,7 +31,7 @@ class Compilation extends @compilation {
}
/** Gets a file compiled during this invocation. */
File getAFileCompiled() { result = getFileCompiled(_) }
File getAFileCompiled() { result = this.getFileCompiled(_) }
/** Gets the `i`th file compiled during this invocation. */
File getFileCompiled(int i) { compilation_compiling_files(this, i, result) }
@@ -76,7 +76,7 @@ class Compilation extends @compilation {
/**
* Gets an argument passed to the extractor on this invocation.
*/
string getAnArgument() { result = getArgument(_) }
string getAnArgument() { result = this.getArgument(_) }
/**
* Gets the `i`th argument passed to the extractor on this invocation.
@@ -86,7 +86,7 @@ class Compilation extends @compilation {
/**
* Gets an expanded argument passed to the extractor on this invocation.
*/
string getAnExpandedArgument() { result = getExpandedArgument(_) }
string getAnExpandedArgument() { result = this.getExpandedArgument(_) }
/**
* Gets the `i`th expanded argument passed to the extractor on this invocation.

View File

@@ -73,10 +73,10 @@ class RequiresDirective extends Directive, @requires {
override string toString() {
exists(string transitive, string static |
(if isTransitive() then transitive = "transitive " else transitive = "") and
(if isStatic() then static = "static " else static = "")
(if this.isTransitive() then transitive = "transitive " else transitive = "") and
(if this.isStatic() then static = "static " else static = "")
|
result = "requires " + transitive + static + getTargetModule() + ";"
result = "requires " + transitive + static + this.getTargetModule() + ";"
)
}
}
@@ -111,11 +111,11 @@ class ExportsDirective extends Directive, @exports {
override string toString() {
exists(string toClause |
if isQualified()
then toClause = (" to " + concat(getATargetModule().getName(), ", "))
if this.isQualified()
then toClause = (" to " + concat(this.getATargetModule().getName(), ", "))
else toClause = ""
|
result = "exports " + getExportedPackage() + toClause + ";"
result = "exports " + this.getExportedPackage() + toClause + ";"
)
}
}
@@ -150,11 +150,11 @@ class OpensDirective extends Directive, @opens {
override string toString() {
exists(string toClause |
if isQualified()
then toClause = (" to " + concat(getATargetModule().getName(), ", "))
if this.isQualified()
then toClause = (" to " + concat(this.getATargetModule().getName(), ", "))
else toClause = ""
|
result = "opens " + getOpenedPackage() + toClause + ";"
result = "opens " + this.getOpenedPackage() + toClause + ";"
)
}
}
@@ -170,7 +170,7 @@ class UsesDirective extends Directive, @uses {
*/
string getServiceInterfaceName() { uses(this, result) }
override string toString() { result = "uses " + getServiceInterfaceName() + ";" }
override string toString() { result = "uses " + this.getServiceInterfaceName() + ";" }
}
/**
@@ -191,7 +191,7 @@ class ProvidesDirective extends Directive, @provides {
override string toString() {
result =
"provides " + getServiceInterfaceName() + " with " +
concat(getServiceImplementationName(), ", ") + ";"
"provides " + this.getServiceInterfaceName() + " with " +
concat(this.getServiceImplementationName(), ", ") + ";"
}
}

View File

@@ -23,12 +23,12 @@ class ExcludeDebuggingProfilingLogging extends ExcludedConstantField {
"log"
]
|
getName().regexpMatch(".*(?i)" + validFieldName + ".*")
this.getName().regexpMatch(".*(?i)" + validFieldName + ".*")
) and
// Boolean type
(
getType().hasName("boolean") or
getType().(BoxedType).hasQualifiedName("java.lang", "Boolean")
this.getType().hasName("boolean") or
this.getType().(BoxedType).hasQualifiedName("java.lang", "Boolean")
)
}
}

View File

@@ -132,28 +132,28 @@ class InstanceAccessExt extends TInstanceAccessExt {
result = enc.getQualifier().toString() + "(" + enc.getType() + ")enclosing"
)
or
isOwnInstanceAccess() and result = "this"
this.isOwnInstanceAccess() and result = "this"
}
private string ppKind() {
isExplicit(_) and result = " <" + getAssociatedExprOrStmt().toString() + ">"
this.isExplicit(_) and result = " <" + this.getAssociatedExprOrStmt().toString() + ">"
or
isImplicitFieldQualifier(_) and result = " <.field>"
this.isImplicitFieldQualifier(_) and result = " <.field>"
or
isImplicitMethodQualifier(_) and result = " <.method>"
this.isImplicitMethodQualifier(_) and result = " <.method>"
or
isImplicitThisConstructorArgument(_) and result = " <constr(this)>"
this.isImplicitThisConstructorArgument(_) and result = " <constr(this)>"
or
isImplicitEnclosingInstanceCapture(_) and result = " <.new>"
this.isImplicitEnclosingInstanceCapture(_) and result = " <.new>"
or
isImplicitEnclosingInstanceQualifier(_) and result = "."
this.isImplicitEnclosingInstanceQualifier(_) and result = "."
}
/** Gets a textual representation of this element. */
string toString() { result = ppBase() + ppKind() }
string toString() { result = this.ppBase() + this.ppKind() }
/** Gets the source location for this element. */
Location getLocation() { result = getAssociatedExprOrStmt().getLocation() }
Location getLocation() { result = this.getAssociatedExprOrStmt().getLocation() }
private ExprParent getAssociatedExprOrStmt() {
this = TExplicitInstanceAccess(result) or
@@ -166,8 +166,8 @@ class InstanceAccessExt extends TInstanceAccessExt {
/** Gets the callable in which this instance access occurs. */
Callable getEnclosingCallable() {
result = getAssociatedExprOrStmt().(Expr).getEnclosingCallable() or
result = getAssociatedExprOrStmt().(Stmt).getEnclosingCallable()
result = this.getAssociatedExprOrStmt().(Expr).getEnclosingCallable() or
result = this.getAssociatedExprOrStmt().(Stmt).getEnclosingCallable()
}
/** Holds if this is the explicit instance access `ia`. */
@@ -206,7 +206,7 @@ class InstanceAccessExt extends TInstanceAccessExt {
}
/** Holds if this is an access to an object's own instance. */
predicate isOwnInstanceAccess() { not isEnclosingInstanceAccess(_) }
predicate isOwnInstanceAccess() { not this.isEnclosingInstanceAccess(_) }
/** Holds if this is an access to an enclosing instance. */
predicate isEnclosingInstanceAccess(RefType t) {
@@ -221,14 +221,14 @@ class InstanceAccessExt extends TInstanceAccessExt {
/** Gets the type of this instance access. */
RefType getType() {
isEnclosingInstanceAccess(result)
this.isEnclosingInstanceAccess(result)
or
isOwnInstanceAccess() and result = getEnclosingCallable().getDeclaringType()
this.isOwnInstanceAccess() and result = this.getEnclosingCallable().getDeclaringType()
}
/** Gets the control flow node associated with this instance access. */
ControlFlowNode getCfgNode() {
exists(ExprParent e | e = getAssociatedExprOrStmt() |
exists(ExprParent e | e = this.getAssociatedExprOrStmt() |
e instanceof Call and result = e
or
e instanceof InstanceAccess and result = e
@@ -244,14 +244,14 @@ class InstanceAccessExt extends TInstanceAccessExt {
* An access to an object's own instance.
*/
class OwnInstanceAccess extends InstanceAccessExt {
OwnInstanceAccess() { isOwnInstanceAccess() }
OwnInstanceAccess() { this.isOwnInstanceAccess() }
}
/**
* An access to an enclosing instance.
*/
class EnclosingInstanceAccess extends InstanceAccessExt {
EnclosingInstanceAccess() { isEnclosingInstanceAccess(_) }
EnclosingInstanceAccess() { this.isEnclosingInstanceAccess(_) }
/** Gets the implicit qualifier of this in the desugared representation. */
InstanceAccessExt getQualifier() {

View File

@@ -292,7 +292,7 @@ class CondReason extends Reason, TCondReason {
/** Gets the condition that is the reason for the bound. */
Guard getCond() { this = TCondReason(result) }
override string toString() { result = getCond().toString() }
override string toString() { result = this.getCond().toString() }
}
/**
@@ -362,7 +362,7 @@ private predicate safeCast(Type fromtyp, Type totyp) {
*/
private class RangeAnalysisSafeCastingExpr extends CastingExpr {
RangeAnalysisSafeCastingExpr() {
safeCast(getExpr().getType(), getType()) or
safeCast(this.getExpr().getType(), this.getType()) or
this instanceof ImplicitCastExpr or
this instanceof ImplicitNotNullExpr or
this instanceof ImplicitCoercionToUnitExpr
@@ -388,14 +388,14 @@ private predicate typeBound(Type typ, int lowerbound, int upperbound) {
private class NarrowingCastingExpr extends CastingExpr {
NarrowingCastingExpr() {
not this instanceof RangeAnalysisSafeCastingExpr and
typeBound(getType(), _, _)
typeBound(this.getType(), _, _)
}
/** Gets the lower bound of the resulting type. */
int getLowerBound() { typeBound(getType(), result, _) }
int getLowerBound() { typeBound(this.getType(), result, _) }
/** Gets the upper bound of the resulting type. */
int getUpperBound() { typeBound(getType(), _, result) }
int getUpperBound() { typeBound(this.getType(), _, result) }
}
/** Holds if `e >= 1` as determined by sign analysis. */

View File

@@ -24,17 +24,17 @@ private newtype TTypeFlowNode =
*/
private class TypeFlowNode extends TTypeFlowNode {
string toString() {
result = asField().toString() or
result = asSsa().toString() or
result = asExpr().toString() or
result = asMethod().toString()
result = this.asField().toString() or
result = this.asSsa().toString() or
result = this.asExpr().toString() or
result = this.asMethod().toString()
}
Location getLocation() {
result = asField().getLocation() or
result = asSsa().getLocation() or
result = asExpr().getLocation() or
result = asMethod().getLocation()
result = this.asField().getLocation() or
result = this.asSsa().getLocation() or
result = this.asExpr().getLocation() or
result = this.asMethod().getLocation()
}
Field asField() { this = TField(result) }
@@ -46,10 +46,10 @@ private class TypeFlowNode extends TTypeFlowNode {
Method asMethod() { this = TMethod(result) }
RefType getType() {
result = asField().getType() or
result = asSsa().getSourceVariable().getType() or
result = boxIfNeeded(asExpr().getType()) or
result = asMethod().getReturnType()
result = this.asField().getType() or
result = this.asSsa().getSourceVariable().getType() or
result = boxIfNeeded(this.asExpr().getType()) or
result = this.asMethod().getReturnType()
}
}

View File

@@ -42,8 +42,8 @@ class SpringFactoryMethod extends CallableEntryPoint {
*/
class SpringBeanAnnotatedMethod extends CallableEntryPoint {
SpringBeanAnnotatedMethod() {
hasAnnotation("org.springframework.context.annotation", "Bean") and
getDeclaringType().(SpringComponent).isLive()
this.hasAnnotation("org.springframework.context.annotation", "Bean") and
this.getDeclaringType().(SpringComponent).isLive()
}
}
@@ -59,9 +59,9 @@ class SpringControllerEntryPoint extends CallableEntryPoint instanceof SpringCon
class SpringResponseAccessibleMethod extends CallableEntryPoint {
SpringResponseAccessibleMethod() {
// Must be on a type used in a Model response.
getDeclaringType() instanceof SpringModelResponseType and
this.getDeclaringType() instanceof SpringModelResponseType and
// Must be public.
isPublic()
this.isPublic()
}
}
@@ -72,10 +72,11 @@ class SpringResponseAccessibleMethod extends CallableEntryPoint {
class SpringManagedResource extends CallableEntryPoint {
SpringManagedResource() {
(
hasAnnotation("org.springframework.jmx.export.annotation", "ManagedAttribute") or
hasAnnotation("org.springframework.jmx.export.annotation", "ManagedOperation")
this.hasAnnotation("org.springframework.jmx.export.annotation", "ManagedAttribute") or
this.hasAnnotation("org.springframework.jmx.export.annotation", "ManagedOperation")
) and
getDeclaringType().hasAnnotation("org.springframework.jmx.export.annotation", "ManagedResource")
this.getDeclaringType()
.hasAnnotation("org.springframework.jmx.export.annotation", "ManagedResource")
}
}
@@ -84,18 +85,18 @@ class SpringManagedResource extends CallableEntryPoint {
*/
class SpringPersistenceConstructor extends CallableEntryPoint {
SpringPersistenceConstructor() {
hasAnnotation("org.springframework.data.annotation", "PersistenceConstructor") and
getDeclaringType() instanceof PersistentEntity
this.hasAnnotation("org.springframework.data.annotation", "PersistenceConstructor") and
this.getDeclaringType() instanceof PersistentEntity
}
}
class SpringAspect extends CallableEntryPoint {
SpringAspect() {
(
hasAnnotation("org.aspectj.lang.annotation", "Around") or
hasAnnotation("org.aspectj.lang.annotation", "Before")
this.hasAnnotation("org.aspectj.lang.annotation", "Around") or
this.hasAnnotation("org.aspectj.lang.annotation", "Before")
) and
getDeclaringType().hasAnnotation("org.aspectj.lang.annotation", "Aspect")
this.getDeclaringType().hasAnnotation("org.aspectj.lang.annotation", "Aspect")
}
}
@@ -105,10 +106,10 @@ class SpringAspect extends CallableEntryPoint {
class SpringCli extends CallableEntryPoint {
SpringCli() {
(
hasAnnotation("org.springframework.shell.core.annotation", "CliCommand") or
hasAnnotation("org.springframework.shell.core.annotation", "CliAvailabilityIndicator")
this.hasAnnotation("org.springframework.shell.core.annotation", "CliCommand") or
this.hasAnnotation("org.springframework.shell.core.annotation", "CliAvailabilityIndicator")
) and
getDeclaringType()
this.getDeclaringType()
.getAnAncestor()
.hasQualifiedName("org.springframework.shell.core", "CommandMarker")
}

View File

@@ -6,14 +6,16 @@ import external.ExternalArtifact
* A method in a FIT fixture class, typically used in the fitnesse framework.
*/
class FitFixtureEntryPoint extends CallableEntryPoint {
FitFixtureEntryPoint() { getDeclaringType().getAnAncestor().hasQualifiedName("fit", "Fixture") }
FitFixtureEntryPoint() {
this.getDeclaringType().getAnAncestor().hasQualifiedName("fit", "Fixture")
}
}
/**
* FitNesse entry points externally defined.
*/
class FitNesseSlimEntryPointData extends ExternalData {
FitNesseSlimEntryPointData() { getDataPath() = "fitnesse.csv" }
FitNesseSlimEntryPointData() { this.getDataPath() = "fitnesse.csv" }
/**
* Gets the class name.
@@ -21,34 +23,34 @@ class FitNesseSlimEntryPointData extends ExternalData {
* This may be a fully qualified name, or just the name of the class. It may also be, or
* include, a FitNesse symbol, in which case it can be ignored.
*/
string getClassName() { result = getField(0) }
string getClassName() { result = this.getField(0) }
/**
* Gets a Class that either has `getClassName()` as the fully qualified name, or as the class name.
*/
Class getACandidateClass() {
result.getQualifiedName().matches(getClassName()) or
result.getName() = getClassName()
result.getQualifiedName().matches(this.getClassName()) or
result.getName() = this.getClassName()
}
/**
* Gets the name of the callable that will be called.
*/
string getCallableName() { result = getField(1) }
string getCallableName() { result = this.getField(1) }
/**
* Gets the number of parameters for the callable that will be called.
*/
int getNumParameters() { result = getField(2).toInt() }
int getNumParameters() { result = this.getField(2).toInt() }
/**
* Gets a callable on one of the candidate classes that matches the criteria for the method name
* and number of arguments.
*/
Callable getACandidateCallable() {
result.getDeclaringType() = getACandidateClass() and
result.getName() = getCallableName() and
result.getNumberOfParameters() = getNumParameters()
result.getDeclaringType() = this.getACandidateClass() and
result.getName() = this.getCallableName() and
result.getNumberOfParameters() = this.getNumParameters()
}
}

View File

@@ -64,7 +64,7 @@ class AssertionMethod extends Method {
/** Gets a call to the assertion method with `checkedArg` as argument. */
MethodAccess getACheck(Expr checkedArg) {
result = getACheck() and checkedArg = result.getAnArgument()
result = this.getACheck() and checkedArg = result.getAnArgument()
}
}

View File

@@ -8,7 +8,7 @@ import java
* An annotation defined in the Cucumber library.
*/
class CucumberAnnotation extends Annotation {
CucumberAnnotation() { getType().getPackage().getName().matches("cucumber.api.java%") }
CucumberAnnotation() { this.getType().getPackage().getName().matches("cucumber.api.java%") }
}
/**
@@ -16,7 +16,9 @@ class CucumberAnnotation extends Annotation {
*/
class CucumberJava8Language extends Interface {
CucumberJava8Language() {
getASupertype().getAnAncestor().hasQualifiedName("cucumber.runtime.java8", "LambdaGlueBase")
this.getASupertype()
.getAnAncestor()
.hasQualifiedName("cucumber.runtime.java8", "LambdaGlueBase")
}
}
@@ -24,12 +26,12 @@ class CucumberJava8Language extends Interface {
* A step definition for Cucumber.
*/
class CucumberStepDefinition extends Method {
CucumberStepDefinition() { getAnAnnotation() instanceof CucumberAnnotation }
CucumberStepDefinition() { this.getAnAnnotation() instanceof CucumberAnnotation }
}
/**
* A class containing Cucumber step definitions.
*/
class CucumberStepDefinitionClass extends Class {
CucumberStepDefinitionClass() { getAMember() instanceof CucumberStepDefinition }
CucumberStepDefinitionClass() { this.getAMember() instanceof CucumberStepDefinition }
}

View File

@@ -7,30 +7,30 @@ import java
/*--- Types ---*/
/** The interface `java.sql.Connection`. */
class TypeConnection extends Interface {
TypeConnection() { hasQualifiedName("java.sql", "Connection") }
TypeConnection() { this.hasQualifiedName("java.sql", "Connection") }
}
/** The interface `java.sql.PreparedStatement`. */
class TypePreparedStatement extends Interface {
TypePreparedStatement() { hasQualifiedName("java.sql", "PreparedStatement") }
TypePreparedStatement() { this.hasQualifiedName("java.sql", "PreparedStatement") }
}
/** The interface `java.sql.ResultSet`. */
class TypeResultSet extends Interface {
TypeResultSet() { hasQualifiedName("java.sql", "ResultSet") }
TypeResultSet() { this.hasQualifiedName("java.sql", "ResultSet") }
}
/** The interface `java.sql.Statement`. */
class TypeStatement extends Interface {
TypeStatement() { hasQualifiedName("java.sql", "Statement") }
TypeStatement() { this.hasQualifiedName("java.sql", "Statement") }
}
/*--- Methods ---*/
/** A method with the name `getString` declared in `java.sql.ResultSet`. */
class ResultSetGetStringMethod extends Method {
ResultSetGetStringMethod() {
getDeclaringType() instanceof TypeResultSet and
hasName("getString") and
getReturnType() instanceof TypeString
this.getDeclaringType() instanceof TypeResultSet and
this.hasName("getString") and
this.getReturnType() instanceof TypeString
}
}

View File

@@ -13,8 +13,8 @@ import java
*/
class LombokAnnotation extends Annotation {
LombokAnnotation() {
getType().getPackage().hasName("lombok") or
getType().getPackage().getName().matches("lombok.%")
this.getType().getPackage().hasName("lombok") or
this.getType().getPackage().getName().matches("lombok.%")
}
}
@@ -22,7 +22,7 @@ class LombokAnnotation extends Annotation {
* A Lombok `@NonNull` annotation.
*/
class LombokNonNullAnnotation extends LombokAnnotation {
LombokNonNullAnnotation() { getType().hasName("NonNull") }
LombokNonNullAnnotation() { this.getType().hasName("NonNull") }
}
/**
@@ -32,7 +32,7 @@ class LombokNonNullAnnotation extends LombokAnnotation {
* automatically closed by Lombok in a generated try-finally block.
*/
class LombokCleanupAnnotation extends LombokAnnotation {
LombokCleanupAnnotation() { getType().hasName("Cleanup") }
LombokCleanupAnnotation() { this.getType().hasName("Cleanup") }
}
/**
@@ -47,7 +47,7 @@ class LombokCleanupAnnotation extends LombokAnnotation {
* overridden by specifying `AccessLevel.NONE` for a field.
*/
class LombokGetterAnnotation extends LombokAnnotation {
LombokGetterAnnotation() { getType().hasName("Getter") }
LombokGetterAnnotation() { this.getType().hasName("Getter") }
}
/**
@@ -62,7 +62,7 @@ class LombokGetterAnnotation extends LombokAnnotation {
* overridden by specifying `AccessLevel.NONE` for a field.
*/
class LombokSetterAnnotation extends LombokAnnotation {
LombokSetterAnnotation() { getType().hasName("Setter") }
LombokSetterAnnotation() { this.getType().hasName("Setter") }
}
/**
@@ -72,7 +72,7 @@ class LombokSetterAnnotation extends LombokAnnotation {
* generates a `toString()` method.
*/
class LombokToStringAnnotation extends LombokAnnotation {
LombokToStringAnnotation() { getType().hasName("ToString") }
LombokToStringAnnotation() { this.getType().hasName("ToString") }
}
/**
@@ -82,7 +82,7 @@ class LombokToStringAnnotation extends LombokAnnotation {
* generates suitable `equals` and `hashCode` methods.
*/
class LombokEqualsAndHashCodeAnnotation extends LombokAnnotation {
LombokEqualsAndHashCodeAnnotation() { getType().hasName("EqualsAndHashCode") }
LombokEqualsAndHashCodeAnnotation() { this.getType().hasName("EqualsAndHashCode") }
}
/**
@@ -92,7 +92,7 @@ class LombokEqualsAndHashCodeAnnotation extends LombokAnnotation {
* generates a constructor with no parameters.
*/
class LombokNoArgsConstructorAnnotation extends LombokAnnotation {
LombokNoArgsConstructorAnnotation() { getType().hasName("NoArgsConstructor") }
LombokNoArgsConstructorAnnotation() { this.getType().hasName("NoArgsConstructor") }
}
/**
@@ -104,7 +104,7 @@ class LombokNoArgsConstructorAnnotation extends LombokAnnotation {
* where it is declared.
*/
class LombokRequiredArgsConstructorAnnotation extends LombokAnnotation {
LombokRequiredArgsConstructorAnnotation() { getType().hasName("RequiredArgsConstructor") }
LombokRequiredArgsConstructorAnnotation() { this.getType().hasName("RequiredArgsConstructor") }
}
/**
@@ -114,7 +114,7 @@ class LombokRequiredArgsConstructorAnnotation extends LombokAnnotation {
* generates a constructor with a parameter for each field in the class.
*/
class LombokAllArgsConstructorAnnotation extends LombokAnnotation {
LombokAllArgsConstructorAnnotation() { getType().hasName("AllArgsConstructor") }
LombokAllArgsConstructorAnnotation() { this.getType().hasName("AllArgsConstructor") }
}
/**
@@ -124,7 +124,7 @@ class LombokAllArgsConstructorAnnotation extends LombokAnnotation {
* fields, `@Setter` on all non-final fields, and `@RequiredArgsConstructor`.
*/
class LombokDataAnnotation extends LombokAnnotation {
LombokDataAnnotation() { getType().hasName("Data") }
LombokDataAnnotation() { this.getType().hasName("Data") }
}
/**
@@ -138,7 +138,7 @@ class LombokDataAnnotation extends LombokAnnotation {
* ```
*/
class LombokValueAnnotation extends LombokAnnotation {
LombokValueAnnotation() { getType().hasName("Value") }
LombokValueAnnotation() { this.getType().hasName("Value") }
}
/**
@@ -148,7 +148,7 @@ class LombokValueAnnotation extends LombokAnnotation {
* generates complex builder APIs for the class.
*/
class LombokBuilderAnnotation extends LombokAnnotation {
LombokBuilderAnnotation() { getType().hasName("Builder") }
LombokBuilderAnnotation() { this.getType().hasName("Builder") }
}
/**
@@ -158,7 +158,7 @@ class LombokBuilderAnnotation extends LombokAnnotation {
* without declaring them in a `throws` clause.
*/
class LombokSneakyThrowsAnnotation extends LombokAnnotation {
LombokSneakyThrowsAnnotation() { getType().hasName("SneakyThrows") }
LombokSneakyThrowsAnnotation() { this.getType().hasName("SneakyThrows") }
}
/**
@@ -170,7 +170,7 @@ class LombokSneakyThrowsAnnotation extends LombokAnnotation {
* methods annotated with `@Synchronized`.
*/
class LombokSynchronizedAnnotation extends LombokAnnotation {
LombokSynchronizedAnnotation() { getType().hasName("Synchronized") }
LombokSynchronizedAnnotation() { this.getType().hasName("Synchronized") }
}
/**
@@ -180,7 +180,7 @@ class LombokSynchronizedAnnotation extends LombokAnnotation {
* generates a logger field named `log` with a specified type.
*/
class LombokLogAnnotation extends LombokAnnotation {
LombokLogAnnotation() { getType().hasName("Log") }
LombokLogAnnotation() { this.getType().hasName("Log") }
}
/*
@@ -196,14 +196,14 @@ class LombokLogAnnotation extends LombokAnnotation {
*/
class LombokGetterAnnotatedField extends Field {
LombokGetterAnnotatedField() {
getAnAnnotation() instanceof LombokGetterAnnotation
this.getAnAnnotation() instanceof LombokGetterAnnotation
or
exists(LombokAnnotation a |
a instanceof LombokGetterAnnotation or
a instanceof LombokDataAnnotation or
a instanceof LombokValueAnnotation
|
a = getDeclaringType().getSourceDeclaration().getAnAnnotation()
a = this.getDeclaringType().getSourceDeclaration().getAnAnnotation()
)
}
}
@@ -217,8 +217,8 @@ class LombokGetterAnnotatedField extends Field {
*/
class LombokEqualsAndHashCodeGeneratedClass extends Class {
LombokEqualsAndHashCodeGeneratedClass() {
getAnAnnotation() instanceof LombokEqualsAndHashCodeAnnotation or
getAnAnnotation() instanceof LombokDataAnnotation or
getAnAnnotation() instanceof LombokValueAnnotation
this.getAnAnnotation() instanceof LombokEqualsAndHashCodeAnnotation or
this.getAnAnnotation() instanceof LombokDataAnnotation or
this.getAnAnnotation() instanceof LombokValueAnnotation
}
}

View File

@@ -7,30 +7,30 @@ private import semmle.code.java.dataflow.FlowSteps
* The `java.util.Properties` class.
*/
class TypeProperty extends Class {
TypeProperty() { hasQualifiedName("java.util", "Properties") }
TypeProperty() { this.hasQualifiedName("java.util", "Properties") }
}
/** The `getProperty` method of the class `java.util.Properties`. */
class PropertiesGetPropertyMethod extends Method {
PropertiesGetPropertyMethod() {
getDeclaringType() instanceof TypeProperty and
hasName("getProperty")
this.getDeclaringType() instanceof TypeProperty and
this.hasName("getProperty")
}
}
/** The `get` method of the class `java.util.Properties`. */
class PropertiesGetMethod extends Method {
PropertiesGetMethod() {
getDeclaringType() instanceof TypeProperty and
hasName("get")
this.getDeclaringType() instanceof TypeProperty and
this.hasName("get")
}
}
/** The `setProperty` method of the class `java.util.Properties`. */
class PropertiesSetPropertyMethod extends Method {
PropertiesSetPropertyMethod() {
getDeclaringType() instanceof TypeProperty and
hasName("setProperty")
this.getDeclaringType() instanceof TypeProperty and
this.hasName("setProperty")
}
}
@@ -39,7 +39,7 @@ class PropertiesSetPropertyMethod extends Method {
*/
class PropertiesStoreMethod extends Method {
PropertiesStoreMethod() {
getDeclaringType() instanceof TypeProperty and
(getName().matches("store%") or getName() = "save")
this.getDeclaringType() instanceof TypeProperty and
(this.getName().matches("store%") or this.getName() = "save")
}
}

View File

@@ -4,7 +4,7 @@ import java
/** The interface `java.rmi.Remote`. */
class TypeRemote extends RefType {
TypeRemote() { hasQualifiedName("java.rmi", "Remote") }
TypeRemote() { this.hasQualifiedName("java.rmi", "Remote") }
}
/** A method that is intended to be called via RMI. */

View File

@@ -10,7 +10,7 @@ import semmle.code.java.Reflection
* The Selenium `PageFactory` class used to create page objects
*/
class SeleniumPageFactory extends Class {
SeleniumPageFactory() { hasQualifiedName("org.openqa.selenium.support", "PageFactory") }
SeleniumPageFactory() { this.hasQualifiedName("org.openqa.selenium.support", "PageFactory") }
}
/**
@@ -18,14 +18,14 @@ class SeleniumPageFactory extends Class {
*/
class SeleniumInitElementsAccess extends MethodAccess {
SeleniumInitElementsAccess() {
getMethod().getDeclaringType() instanceof SeleniumPageFactory and
getMethod().hasName("initElements")
this.getMethod().getDeclaringType() instanceof SeleniumPageFactory and
this.getMethod().hasName("initElements")
}
/**
* Gets the class that is initialized by this call..
*/
Class getInitClass() { result = inferClassParameterType(getArgument(1)) }
Class getInitClass() { result = inferClassParameterType(this.getArgument(1)) }
}
/**

View File

@@ -5,14 +5,14 @@ import semmle.code.java.security.ExternalProcess
/** The class `org.apache.commons.exec.CommandLine`. */
private class TypeCommandLine extends Class {
TypeCommandLine() { hasQualifiedName("org.apache.commons.exec", "CommandLine") }
TypeCommandLine() { this.hasQualifiedName("org.apache.commons.exec", "CommandLine") }
}
/** The `parse()` method of the class `org.apache.commons.exec.CommandLine`. */
private class MethodCommandLineParse extends Method, ExecCallable {
MethodCommandLineParse() {
getDeclaringType() instanceof TypeCommandLine and
hasName("parse")
this.getDeclaringType() instanceof TypeCommandLine and
this.hasName("parse")
}
override int getAnExecutedArgument() { result = 0 }
@@ -21,8 +21,8 @@ private class MethodCommandLineParse extends Method, ExecCallable {
/** The `addArguments()` method of the class `org.apache.commons.exec.CommandLine`. */
private class MethodCommandLineAddArguments extends Method, ExecCallable {
MethodCommandLineAddArguments() {
getDeclaringType() instanceof TypeCommandLine and
hasName("addArguments")
this.getDeclaringType() instanceof TypeCommandLine and
this.hasName("addArguments")
}
override int getAnExecutedArgument() { result = 0 }

View File

@@ -20,19 +20,19 @@ import semmle.code.java.Reflection
import semmle.code.java.frameworks.spring.Spring
library class CamelAnnotation extends Annotation {
CamelAnnotation() { getType().getPackage().hasName("org.apache.camel") }
CamelAnnotation() { this.getType().getPackage().hasName("org.apache.camel") }
}
/**
* An annotation indicating that the annotated method is called by Apache Camel.
*/
class CamelConsumeAnnotation extends CamelAnnotation {
CamelConsumeAnnotation() { getType().hasName("Consume") }
CamelConsumeAnnotation() { this.getType().hasName("Consume") }
}
/**
* A method that may be called by Apache Camel in response to a message.
*/
class CamelConsumeMethod extends Method {
CamelConsumeMethod() { getAnAnnotation() instanceof CamelConsumeAnnotation }
CamelConsumeMethod() { this.getAnAnnotation() instanceof CamelConsumeAnnotation }
}

View File

@@ -23,7 +23,7 @@ import semmle.code.java.frameworks.spring.Spring
*/
library class ProcessorDefinitionElement extends MethodAccess {
ProcessorDefinitionElement() {
getMethod()
this.getMethod()
.getDeclaringType()
.getSourceDeclaration()
.hasQualifiedName("org.apache.camel.model", "ProcessorDefinition")
@@ -36,15 +36,15 @@ library class ProcessorDefinitionElement extends MethodAccess {
* This declares a "target" for this route, described by the URI given as the first argument.
*/
class CamelJavaDslToDecl extends ProcessorDefinitionElement {
CamelJavaDslToDecl() { getMethod().hasName("to") }
CamelJavaDslToDecl() { this.getMethod().hasName("to") }
/**
* Gets the URI specified by this `to` declaration.
*/
string getUri() { result = getArgument(0).(CompileTimeConstantExpr).getStringValue() }
string getUri() { result = this.getArgument(0).(CompileTimeConstantExpr).getStringValue() }
/** DEPRECATED: Alias for getUri */
deprecated string getURI() { result = getUri() }
deprecated string getURI() { result = this.getUri() }
}
/** DEPRECATED: Alias for CamelJavaDslToDecl */
@@ -57,20 +57,20 @@ deprecated class CamelJavaDSLToDecl = CamelJavaDslToDecl;
* or the bean object itself.
*/
class CamelJavaDslBeanDecl extends ProcessorDefinitionElement {
CamelJavaDslBeanDecl() { getMethod().hasName("bean") }
CamelJavaDslBeanDecl() { this.getMethod().hasName("bean") }
/**
* Gets a bean class that may be registered as a target by this `bean()` declaration.
*/
RefType getABeanClass() {
if getArgument(0).getType() instanceof TypeClass
if this.getArgument(0).getType() instanceof TypeClass
then
// In this case, we've been given a Class<?>, which implies a Spring Bean of this type
// should be loaded. Infer the type of type parameter.
result = inferClassParameterType(getArgument(0))
result = inferClassParameterType(this.getArgument(0))
else
// In this case, the object itself is used as the target for the Apache Camel messages.
result = getArgument(0).getType()
result = this.getArgument(0).getType()
}
}
@@ -85,22 +85,24 @@ deprecated class CamelJavaDSLBeanDecl = CamelJavaDslBeanDecl;
* assumption that it either represetns a qualified name, or a Srping bean identifier.
*/
class CamelJavaDslBeanRefDecl extends ProcessorDefinitionElement {
CamelJavaDslBeanRefDecl() { getMethod().hasName("beanRef") }
CamelJavaDslBeanRefDecl() { this.getMethod().hasName("beanRef") }
/**
* Gets the string describing the bean referred to.
*/
string getBeanRefString() { result = getArgument(0).(CompileTimeConstantExpr).getStringValue() }
string getBeanRefString() {
result = this.getArgument(0).(CompileTimeConstantExpr).getStringValue()
}
/**
* Gets a class that may be referred to by this bean reference.
*/
RefType getABeanClass() {
exists(SpringBean bean | bean.getBeanIdentifier() = getBeanRefString() |
exists(SpringBean bean | bean.getBeanIdentifier() = this.getBeanRefString() |
result = bean.getClass()
)
or
result.getQualifiedName() = getBeanRefString()
result.getQualifiedName() = this.getBeanRefString()
}
}
@@ -114,28 +116,28 @@ deprecated class CamelJavaDSLBeanRefDecl = CamelJavaDslBeanRefDecl;
*/
class CamelJavaDslMethodDecl extends MethodAccess {
CamelJavaDslMethodDecl() {
getMethod()
this.getMethod()
.getDeclaringType()
.getSourceDeclaration()
.hasQualifiedName("org.apache.camel.builder", "ExpressionClause") and
getMethod().hasName("method")
this.getMethod().hasName("method")
}
/**
* Gets a possible bean that this "method" expression represents.
*/
RefType getABean() {
if getArgument(0).getType() instanceof TypeString
if this.getArgument(0).getType() instanceof TypeString
then
exists(SpringBean bean |
bean.getBeanIdentifier() = getArgument(0).(CompileTimeConstantExpr).getStringValue()
bean.getBeanIdentifier() = this.getArgument(0).(CompileTimeConstantExpr).getStringValue()
|
result = bean.getClass()
)
else
if getArgument(0).getType() instanceof TypeClass
then result = inferClassParameterType(getArgument(0))
else result = getArgument(0).getType()
if this.getArgument(0).getType() instanceof TypeClass
then result = inferClassParameterType(this.getArgument(0))
else result = this.getArgument(0).getType()
}
}

View File

@@ -36,8 +36,8 @@ predicate isGigaSpacesEventMethod(Method eventMethod) {
*/
class GigaSpacesSpaceIdGetterMethod extends Method {
GigaSpacesSpaceIdGetterMethod() {
getAnAnnotation().getType().hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceId") and
getName().matches("get%")
this.getAnAnnotation().getType().hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceId") and
this.getName().matches("get%")
}
}
@@ -47,10 +47,10 @@ class GigaSpacesSpaceIdGetterMethod extends Method {
class GigaSpacesSpaceIdSetterMethod extends Method {
GigaSpacesSpaceIdSetterMethod() {
exists(GigaSpacesSpaceIdGetterMethod getterMethod |
getterMethod.getDeclaringType() = getDeclaringType() and
getName().matches("set%")
getterMethod.getDeclaringType() = this.getDeclaringType() and
this.getName().matches("set%")
|
getterMethod.getName().suffix(3) = getName().suffix(3)
getterMethod.getName().suffix(3) = this.getName().suffix(3)
)
}
}
@@ -61,7 +61,9 @@ class GigaSpacesSpaceIdSetterMethod extends Method {
*/
class GigaSpacesSpaceRoutingMethod extends Method {
GigaSpacesSpaceRoutingMethod() {
getAnAnnotation().getType().hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceRouting") and
getName().matches("get%")
this.getAnAnnotation()
.getType()
.hasQualifiedName("com.gigaspaces.annotation.pojo", "SpaceRouting") and
this.getName().matches("get%")
}
}

View File

@@ -8,7 +8,7 @@ import semmle.code.java.frameworks.javaee.jsf.JSFFacesContextXML
* A method that is visible to faces, if the instance type is visible to faces.
*/
library class FacesVisibleMethod extends Method {
FacesVisibleMethod() { isPublic() and not isStatic() }
FacesVisibleMethod() { this.isPublic() and not this.isStatic() }
}
/**
@@ -45,7 +45,7 @@ class FacesAccessibleType extends RefType {
}
/** Gets a method declared on this type that is visible to JSF. */
FacesVisibleMethod getAnAccessibleMethod() { result = getAMethod() }
FacesVisibleMethod getAnAccessibleMethod() { result = this.getAMethod() }
}
/**
@@ -59,7 +59,7 @@ class FacesAccessibleType extends RefType {
class FacesComponent extends Class {
FacesComponent() {
// Must extend UIComponent for it to be a valid component.
getAnAncestor().hasQualifiedName("javax.faces.component", "UIComponent") and
this.getAnAncestor().hasQualifiedName("javax.faces.component", "UIComponent") and
(
// Must be registered using either an annotation
exists(FacesComponentAnnotation componentAnnotation |

View File

@@ -6,12 +6,14 @@ import default
* A Java Server Faces `ManagedBean` annotation on a class.
*/
class FacesManagedBeanAnnotation extends Annotation {
FacesManagedBeanAnnotation() { getType().hasQualifiedName("javax.faces.bean", "ManagedBean") }
FacesManagedBeanAnnotation() {
this.getType().hasQualifiedName("javax.faces.bean", "ManagedBean")
}
/**
* Gets the `Class` of the managed bean.
*/
Class getManagedBeanClass() { result = getAnnotatedElement() }
Class getManagedBeanClass() { result = this.getAnnotatedElement() }
}
/**
@@ -21,11 +23,11 @@ class FacesManagedBeanAnnotation extends Annotation {
*/
class FacesComponentAnnotation extends Annotation {
FacesComponentAnnotation() {
getType().hasQualifiedName("javax.faces.component", "FacesComponent")
this.getType().hasQualifiedName("javax.faces.component", "FacesComponent")
}
/**
* Gets the `Class` of the FacesComponent, if this annotation is valid.
*/
Class getFacesComponentClass() { result = getAnnotatedElement() }
Class getFacesComponentClass() { result = this.getAnnotatedElement() }
}

View File

@@ -10,7 +10,7 @@ import semmle.code.java.frameworks.spring.SpringBean
* An Apache Camel element in a Spring Beans file.
*/
class SpringCamelXmlElement extends SpringXmlElement {
SpringCamelXmlElement() { getNamespace().getUri() = "http://camel.apache.org/schema/spring" }
SpringCamelXmlElement() { this.getNamespace().getUri() = "http://camel.apache.org/schema/spring" }
}
/** DEPRECATED: Alias for SpringCamelXmlElement */
@@ -22,7 +22,7 @@ deprecated class SpringCamelXMLElement = SpringCamelXmlElement;
* All Apache Camel Spring elements are nested within a `<camelContext>` or a `<routeContext>`.
*/
class SpringCamelXmlContext extends SpringCamelXmlElement {
SpringCamelXmlContext() { getName() = "camelContext" }
SpringCamelXmlContext() { this.getName() = "camelContext" }
}
/** DEPRECATED: Alias for SpringCamelXmlContext */
@@ -35,7 +35,7 @@ deprecated class SpringCamelXMLContext = SpringCamelXmlContext;
* `<camelContext>`.
*/
class SpringCamelXmlRouteContext extends SpringCamelXmlElement {
SpringCamelXmlRouteContext() { getName() = "routeContext" }
SpringCamelXmlRouteContext() { this.getName() = "routeContext" }
}
/** DEPRECATED: Alias for SpringCamelXmlRouteContext */
@@ -51,10 +51,10 @@ class SpringCamelXmlRoute extends SpringCamelXmlElement {
SpringCamelXmlRoute() {
// A route must either be in a `<routeContext>` or a `<camelContext>`.
(
getParent() instanceof SpringCamelXmlRouteContext or
getParent() instanceof SpringCamelXmlContext
this.getParent() instanceof SpringCamelXmlRouteContext or
this.getParent() instanceof SpringCamelXmlContext
) and
getName() = "route"
this.getName() = "route"
}
}
@@ -66,8 +66,8 @@ deprecated class SpringCamelXMLRoute = SpringCamelXmlRoute;
*/
class SpringCamelXmlRouteElement extends SpringCamelXmlElement {
SpringCamelXmlRouteElement() {
getParent() instanceof SpringCamelXmlRoute or
getParent() instanceof SpringCamelXmlRouteElement
this.getParent() instanceof SpringCamelXmlRoute or
this.getParent() instanceof SpringCamelXmlRouteElement
}
}
@@ -82,12 +82,12 @@ deprecated class SpringCamelXMLRouteElement = SpringCamelXmlRouteElement;
* route.
*/
class SpringCamelXmlBeanRef extends SpringCamelXmlRouteElement {
SpringCamelXmlBeanRef() { getName() = "bean" }
SpringCamelXmlBeanRef() { this.getName() = "bean" }
/**
* Gets the Spring bean that is referenced by this route bean definition, if any.
*/
SpringBean getRefBean() { result.getBeanIdentifier() = getAttribute("ref").getValue() }
SpringBean getRefBean() { result.getBeanIdentifier() = this.getAttribute("ref").getValue() }
/**
* Gets the RefType referred to by `beanType` attribute, if any.
@@ -95,7 +95,7 @@ class SpringCamelXmlBeanRef extends SpringCamelXmlRouteElement {
* This defines the bean that should be created by Apache Camel as a target of this route. In
* this case, no pre-existing bean is required.
*/
RefType getBeanType() { result.getQualifiedName() = getAttribute("beanType").getValue() }
RefType getBeanType() { result.getQualifiedName() = this.getAttribute("beanType").getValue() }
}
/** DEPRECATED: Alias for SpringCamelXmlBeanRef */
@@ -109,15 +109,15 @@ deprecated class SpringCamelXMLBeanRef = SpringCamelXmlBeanRef;
* consists of a bean name and optional method name.
*/
class SpringCamelXmlToElement extends SpringCamelXmlRouteElement {
SpringCamelXmlToElement() { getName() = "to" }
SpringCamelXmlToElement() { this.getName() = "to" }
/**
* Gets the URI attribute for this `<to>` element.
*/
string getUri() { result = getAttribute("uri").getValue() }
string getUri() { result = this.getAttribute("uri").getValue() }
/** DEPRECATED: Alias for getUri */
deprecated string getURI() { result = getUri() }
deprecated string getURI() { result = this.getUri() }
}
/** DEPRECATED: Alias for SpringCamelXmlToElement */
@@ -132,20 +132,20 @@ deprecated class SpringCamelXMLToElement = SpringCamelXmlToElement;
* (if "beanType" is used.
*/
class SpringCamelXmlMethodElement extends SpringCamelXmlElement {
SpringCamelXmlMethodElement() { getName() = "method" }
SpringCamelXmlMethodElement() { this.getName() = "method" }
/**
* Gets the `SpringBean` that this method expression refers to.
*/
SpringBean getRefBean() {
result.getBeanIdentifier() = getAttribute("ref").getValue() or
result.getBeanIdentifier() = getAttribute("bean").getValue()
result.getBeanIdentifier() = this.getAttribute("ref").getValue() or
result.getBeanIdentifier() = this.getAttribute("bean").getValue()
}
/**
* Gets the class based on the `beanType` attribute.
*/
RefType getBeanType() { result.getQualifiedName() = getAttribute("beanType").getValue() }
RefType getBeanType() { result.getQualifiedName() = this.getAttribute("beanType").getValue() }
}
/** DEPRECATED: Alias for SpringCamelXmlMethodElement */

View File

@@ -8,14 +8,14 @@ import java
*/
class InitializingBeanClass extends Class {
InitializingBeanClass() {
getAnAncestor().hasQualifiedName("org.springframework.beans.factory", "InitializingBean")
this.getAnAncestor().hasQualifiedName("org.springframework.beans.factory", "InitializingBean")
}
/**
* Gets the `afterPropertiesSet()` method, which is called after the bean has been initialized.
*/
Method getAfterPropertiesSet() {
inherits(result) and
this.inherits(result) and
result.hasName("afterPropertiesSet")
}
}

View File

@@ -155,7 +155,7 @@ private class CommandArgArrayImmutableFirst extends CommandArgumentArray {
Expr getFirstElement() {
result = this.getAWrite(0)
or
not exists(getAWrite(0)) and
not exists(this.getAWrite(0)) and
result = firstElementOf(this.getDefiningExpr())
}

View File

@@ -5,8 +5,8 @@ import java
*/
class SetWritable extends Method {
SetWritable() {
getDeclaringType() instanceof TypeFile and
hasName("setWritable")
this.getDeclaringType() instanceof TypeFile and
this.hasName("setWritable")
}
}

View File

@@ -12,8 +12,10 @@ import SensitiveApi
*/
private class HardcodedByteArray extends ArrayCreationExpr {
HardcodedByteArray() {
getType().(Array).getElementType().(PrimitiveType).getName() = "byte" and
forex(Expr elem | elem = getInit().getAChildExpr() | elem instanceof CompileTimeConstantExpr)
this.getType().(Array).getElementType().(PrimitiveType).getName() = "byte" and
forex(Expr elem | elem = this.getInit().getAChildExpr() |
elem instanceof CompileTimeConstantExpr
)
}
}
@@ -24,8 +26,10 @@ private class HardcodedByteArray extends ArrayCreationExpr {
*/
private class HardcodedCharArray extends ArrayCreationExpr {
HardcodedCharArray() {
getType().(Array).getElementType().(PrimitiveType).getName() = "char" and
forex(Expr elem | elem = getInit().getAChildExpr() | elem instanceof CompileTimeConstantExpr)
this.getType().(Array).getElementType().(PrimitiveType).getName() = "char" and
forex(Expr elem | elem = this.getInit().getAChildExpr() |
elem instanceof CompileTimeConstantExpr
)
}
}
@@ -72,7 +76,7 @@ class CredentialsApiSink extends CredentialsSink {
*/
class PasswordVariable extends Variable {
PasswordVariable() {
getName().regexpMatch("(?i)(encrypted|old|new)?pass(wd|word|code|phrase)(chars|value)?")
this.getName().regexpMatch("(?i)(encrypted|old|new)?pass(wd|word|code|phrase)(chars|value)?")
}
}
@@ -80,7 +84,7 @@ class PasswordVariable extends Variable {
* A variable whose name indicates that it may hold a user name.
*/
class UsernameVariable extends Variable {
UsernameVariable() { getName().regexpMatch("(?i)(user|username)") }
UsernameVariable() { this.getName().regexpMatch("(?i)(user|username)") }
}
/**

View File

@@ -9,7 +9,7 @@ import HardcodedCredentials
* A call to a method that is or overrides `java.lang.Object.equals`.
*/
class EqualsAccess extends MethodAccess {
EqualsAccess() { getMethod() instanceof EqualsMethod }
EqualsAccess() { this.getMethod() instanceof EqualsMethod }
}
/**

View File

@@ -22,22 +22,22 @@ abstract class FlagKind extends string {
private predicate flagFlowStepTC(DataFlow::Node node1, DataFlow::Node node2) {
node2 = node1 and
isFlagWithName(node1)
this.isFlagWithName(node1)
or
exists(DataFlow::Node nodeMid |
flagFlowStep(nodeMid, node2) and
flagFlowStepTC(node1, nodeMid)
this.flagFlowStepTC(node1, nodeMid)
)
}
private predicate isFlagWithName(DataFlow::Node flag) {
exists(VarAccess v | v.getVariable().getName() = getAFlagName() |
exists(VarAccess v | v.getVariable().getName() = this.getAFlagName() |
flag.asExpr() = v and v.getType() instanceof FlagType
)
or
exists(StringLiteral s | s.getValue() = getAFlagName() | flag.asExpr() = s)
exists(StringLiteral s | s.getValue() = this.getAFlagName() | flag.asExpr() = s)
or
exists(MethodAccess ma | ma.getMethod().getName() = getAFlagName() |
exists(MethodAccess ma | ma.getMethod().getName() = this.getAFlagName() |
flag.asExpr() = ma and
ma.getType() instanceof FlagType
)
@@ -46,8 +46,8 @@ abstract class FlagKind extends string {
/** Gets a node representing a (likely) security flag. */
DataFlow::Node getAFlag() {
exists(DataFlow::Node flag |
isFlagWithName(flag) and
flagFlowStepTC(flag, result)
this.isFlagWithName(flag) and
this.flagFlowStepTC(flag, result)
)
}
}

View File

@@ -18,10 +18,10 @@ import semmle.code.java.frameworks.spring.Spring
class InstanceFieldWrite extends FieldWrite {
InstanceFieldWrite() {
// Must be in an instance callable
not getEnclosingCallable().isStatic() and
not this.getEnclosingCallable().isStatic() and
// Must be declared in this type or a supertype.
getEnclosingCallable().getDeclaringType().inherits(getField()) and
isOwnFieldAccess()
this.getEnclosingCallable().getDeclaringType().inherits(this.getField()) and
this.isOwnFieldAccess()
}
}
@@ -62,7 +62,7 @@ class SpringPureClass extends Class {
SpringPureClass() {
// The only permitted statement in static initializers is the initialization of a static
// final or effectively final logger fields, or effectively immutable types.
forall(Stmt s | s = getANestedStmt(getAMember().(StaticInitializer).getBody()) |
forall(Stmt s | s = getANestedStmt(this.getAMember().(StaticInitializer).getBody()) |
exists(Field f | f = s.(ExprStmt).getExpr().(AssignExpr).getDest().(FieldWrite).getField() |
(
// A logger field
@@ -79,8 +79,8 @@ class SpringPureClass extends Class {
// No constructor, instance initializer or Spring bean init or setter method that is impure.
not exists(Callable c, ImpureStmt impureStmt |
(
inherits(c.(Method)) or
c = getAMember()
this.inherits(c.(Method)) or
c = this.getAMember()
) and
impureStmt.getEnclosingCallable() = c
|
@@ -110,7 +110,7 @@ class SpringPureClass extends Class {
*/
class SpringBeanFactory extends ClassOrInterface {
SpringBeanFactory() {
getAnAncestor().hasQualifiedName("org.springframework.beans.factory", "BeanFactory")
this.getAnAncestor().hasQualifiedName("org.springframework.beans.factory", "BeanFactory")
}
/**
@@ -136,20 +136,20 @@ class LiveSpringBean extends SpringBean {
LiveSpringBean() {
// Must not be needed for side effects due to construction
// Only loaded by the container when required, so construction cannot have any useful side-effects
not isLazyInit() and
not this.isLazyInit() and
// or has no side-effects when constructed
not getClass() instanceof SpringPureClass
not this.getClass() instanceof SpringPureClass
or
(
// If the class does not exist for this bean, or the class is not a source bean, then this is
// likely to be a definition using a library class, in which case we should consider it to be
// live.
not exists(getClass())
not exists(this.getClass())
or
not getClass().fromSource()
not this.getClass().fromSource()
or
// In alfresco, "webscript" beans should be considered live
getBeanParent*().getBeanParentName() = "webscript"
this.getBeanParent*().getBeanParentName() = "webscript"
or
// A live child bean implies this bean is live
exists(LiveSpringBean child | this = child.getBeanParent())

View File

@@ -3,8 +3,8 @@ import java
/** A class that implements `java.lang.Iterable`. */
class Iterable extends Class {
Iterable() {
isSourceDeclaration() and
getASourceSupertype+().hasQualifiedName("java.lang", "Iterable")
this.isSourceDeclaration() and
this.getASourceSupertype+().hasQualifiedName("java.lang", "Iterable")
}
/** The return value of a one-statement `iterator()` method. */

View File

@@ -16,7 +16,7 @@ import IterableClass
/** An `Iterable` that is also its own `Iterator`. */
class IterableIterator extends Iterable {
IterableIterator() { simpleIterator() instanceof ThisAccess }
IterableIterator() { this.simpleIterator() instanceof ThisAccess }
}
/** An `IterableIterator` that never returns any elements. */

View File

@@ -17,9 +17,9 @@ library class BoundKind extends string {
predicate isUpper() { this = "<=" }
predicate providesLowerBound() { isEqual() or isLower() }
predicate providesLowerBound() { this.isEqual() or this.isLower() }
predicate providesUpperBound() { isEqual() or isUpper() }
predicate providesUpperBound() { this.isEqual() or this.isUpper() }
}
/**

View File

@@ -19,19 +19,19 @@ import java
*/
class ArrayCast extends CastExpr {
ArrayCast() {
getExpr() instanceof ArrayCreationExpr and
getType() instanceof Array
this.getExpr() instanceof ArrayCreationExpr and
this.getType() instanceof Array
}
/** The type of the operand expression of this cast. */
Array getSourceType() { result = getExpr().getType() }
Array getSourceType() { result = this.getExpr().getType() }
/** The result type of this cast. */
Array getTargetType() { result = getType() }
Array getTargetType() { result = this.getType() }
Type getSourceComponentType() { result = getSourceType().getComponentType() }
Type getSourceComponentType() { result = this.getSourceType().getComponentType() }
Type getTargetComponentType() { result = getTargetType().getComponentType() }
Type getTargetComponentType() { result = this.getTargetType().getComponentType() }
}
predicate uncheckedCastType(RefType t) {

View File

@@ -32,9 +32,9 @@ class LTWideningComparison extends WideningComparison {
leftWidth(this) < rightWidth(this)
}
override Expr getNarrower() { result = getLeftOperand() }
override Expr getNarrower() { result = this.getLeftOperand() }
override Expr getWider() { result = getRightOperand() }
override Expr getWider() { result = this.getRightOperand() }
}
class GTWideningComparison extends WideningComparison {
@@ -43,9 +43,9 @@ class GTWideningComparison extends WideningComparison {
leftWidth(this) > rightWidth(this)
}
override Expr getNarrower() { result = getRightOperand() }
override Expr getNarrower() { result = this.getRightOperand() }
override Expr getWider() { result = getLeftOperand() }
override Expr getWider() { result = this.getLeftOperand() }
}
from WideningComparison c, LoopStmt l

View File

@@ -17,14 +17,14 @@ import semmle.code.java.dataflow.TaintTracking
import DataFlow
private class ShortStringLiteral extends StringLiteral {
ShortStringLiteral() { getValue().length() < 100 }
ShortStringLiteral() { this.getValue().length() < 100 }
}
class BrokenAlgoLiteral extends ShortStringLiteral {
BrokenAlgoLiteral() {
getValue().regexpMatch(getInsecureAlgorithmRegex()) and
this.getValue().regexpMatch(getInsecureAlgorithmRegex()) and
// Exclude German and French sentences.
not getValue().regexpMatch(".*\\p{IsLowercase} des \\p{IsLetter}.*")
not this.getValue().regexpMatch(".*\\p{IsLowercase} des \\p{IsLetter}.*")
}
}

View File

@@ -7,7 +7,7 @@ import semmle.code.java.dataflow.RangeAnalysis
class NumericNarrowingCastExpr extends CastExpr {
NumericNarrowingCastExpr() {
exists(NumericType sourceType, NumericType targetType |
sourceType = getExpr().getType() and targetType = getType()
sourceType = this.getExpr().getType() and targetType = this.getType()
|
not targetType.(NumType).widerThanOrEqualTo(sourceType)
)
@@ -28,8 +28,8 @@ class RightShiftOp extends Expr {
}
Variable getShiftedVariable() {
getLhs() = result.getAnAccess() or
getLhs().(AndBitwiseExpr).getAnOperand() = result.getAnAccess()
this.getLhs() = result.getAnAccess() or
this.getLhs().(AndBitwiseExpr).getAnOperand() = result.getAnAccess()
}
}

View File

@@ -17,11 +17,11 @@ class WebRequestSource extends DataFlow::Node {
m.hasName("getParameterNames") or
m.hasName("getParameterMap")
) and
ma = asExpr()
ma = this.asExpr()
)
}
}
class WebRequest extends RefType {
WebRequest() { hasQualifiedName("org.springframework.web.context.request", "WebRequest") }
WebRequest() { this.hasQualifiedName("org.springframework.web.context.request", "WebRequest") }
}

View File

@@ -24,7 +24,7 @@ class SetRevocationEnabledSink extends DataFlow::ExprNode {
SetRevocationEnabledSink() {
exists(MethodAccess setRevocationEnabledCall |
setRevocationEnabledCall.getMethod() instanceof SetRevocationEnabledMethod and
setRevocationEnabledCall.getArgument(0) = getExpr() and
setRevocationEnabledCall.getArgument(0) = this.getExpr() and
not exists(MethodAccess ma, Method m | m = ma.getMethod() |
(m instanceof AddCertPathCheckerMethod or m instanceof SetCertPathCheckersMethod) and
ma.getQualifier().(VarAccess).getVariable() =
@@ -36,25 +36,25 @@ class SetRevocationEnabledSink extends DataFlow::ExprNode {
class SetRevocationEnabledMethod extends Method {
SetRevocationEnabledMethod() {
getDeclaringType() instanceof PKIXParameters and
hasName("setRevocationEnabled")
this.getDeclaringType() instanceof PKIXParameters and
this.hasName("setRevocationEnabled")
}
}
class AddCertPathCheckerMethod extends Method {
AddCertPathCheckerMethod() {
getDeclaringType() instanceof PKIXParameters and
hasName("addCertPathChecker")
this.getDeclaringType() instanceof PKIXParameters and
this.hasName("addCertPathChecker")
}
}
class SetCertPathCheckersMethod extends Method {
SetCertPathCheckersMethod() {
getDeclaringType() instanceof PKIXParameters and
hasName("setCertPathCheckers")
this.getDeclaringType() instanceof PKIXParameters and
this.hasName("setCertPathCheckers")
}
}
class PKIXParameters extends RefType {
PKIXParameters() { hasQualifiedName("java.security.cert", "PKIXParameters") }
PKIXParameters() { this.hasQualifiedName("java.security.cert", "PKIXParameters") }
}

View File

@@ -27,7 +27,7 @@ class SslContextGetInstanceSink extends DataFlow::ExprNode {
exists(StaticMethodAccess ma, Method m | m = ma.getMethod() |
m.getDeclaringType() instanceof SslContext and
m.hasName("getInstance") and
ma.getArgument(0) = asExpr()
ma.getArgument(0) = this.asExpr()
)
}
}
@@ -39,7 +39,7 @@ class SslContextGetInstanceSink extends DataFlow::ExprNode {
class CreateSslParametersSink extends DataFlow::ExprNode {
CreateSslParametersSink() {
exists(ConstructorCall cc | cc.getConstructedType() instanceof SslParameters |
cc.getArgument(1) = asExpr()
cc.getArgument(1) = this.asExpr()
)
}
}
@@ -53,7 +53,7 @@ class SslParametersSetProtocolsSink extends DataFlow::ExprNode {
exists(MethodAccess ma, Method m | m = ma.getMethod() |
m.getDeclaringType() instanceof SslParameters and
m.hasName("setProtocols") and
ma.getArgument(0) = asExpr()
ma.getArgument(0) = this.asExpr()
)
}
}
@@ -73,7 +73,7 @@ class SetEnabledProtocolsSink extends DataFlow::ExprNode {
type instanceof SslEngine
) and
m.hasName("setEnabledProtocols") and
ma.getArgument(0) = asExpr()
ma.getArgument(0) = this.asExpr()
)
}
}
@@ -83,15 +83,15 @@ class SetEnabledProtocolsSink extends DataFlow::ExprNode {
*/
class UnsafeTlsVersion extends StringLiteral {
UnsafeTlsVersion() {
getValue() = "SSL" or
getValue() = "SSLv2" or
getValue() = "SSLv3" or
getValue() = "TLS" or
getValue() = "TLSv1" or
getValue() = "TLSv1.1"
this.getValue() = "SSL" or
this.getValue() = "SSLv2" or
this.getValue() = "SSLv3" or
this.getValue() = "TLS" or
this.getValue() = "TLSv1" or
this.getValue() = "TLSv1.1"
}
}
class SslServerSocket extends RefType {
SslServerSocket() { hasQualifiedName("javax.net.ssl", "SSLServerSocket") }
SslServerSocket() { this.hasQualifiedName("javax.net.ssl", "SSLServerSocket") }
}

View File

@@ -31,14 +31,14 @@ private predicate setsAllowCredentials(MethodAccess header) {
private class CorsProbableCheckAccess extends MethodAccess {
CorsProbableCheckAccess() {
getMethod().hasName("contains") and
getMethod().getDeclaringType().getASourceSupertype*() instanceof CollectionType
this.getMethod().hasName("contains") and
this.getMethod().getDeclaringType().getASourceSupertype*() instanceof CollectionType
or
getMethod().hasName("containsKey") and
getMethod().getDeclaringType().getASourceSupertype*() instanceof MapType
this.getMethod().hasName("containsKey") and
this.getMethod().getDeclaringType().getASourceSupertype*() instanceof MapType
or
getMethod().hasName("equals") and
getQualifier().getType() instanceof TypeString
this.getMethod().hasName("equals") and
this.getQualifier().getType() instanceof TypeString
}
}

View File

@@ -24,10 +24,10 @@ import BindingUnsafeRemoteObjectFlow::PathGraph
private class BindMethod extends Method {
BindMethod() {
(
getDeclaringType().hasQualifiedName("java.rmi", "Naming") or
getDeclaringType().hasQualifiedName("java.rmi.registry", "Registry")
this.getDeclaringType().hasQualifiedName("java.rmi", "Naming") or
this.getDeclaringType().hasQualifiedName("java.rmi.registry", "Registry")
) and
hasName(["bind", "rebind"])
this.hasName(["bind", "rebind"])
}
}

View File

@@ -2,7 +2,7 @@ import java
class RelevantAnnotatable extends Annotatable {
RelevantAnnotatable() {
getCompilationUnit().hasName("Annotatable") and getCompilationUnit().fromSource()
this.getCompilationUnit().hasName("Annotatable") and this.getCompilationUnit().fromSource()
}
}

View File

@@ -2,7 +2,7 @@ import java
class RelevantAnnotation extends Annotation {
RelevantAnnotation() {
getCompilationUnit().hasName("AnnotationValues") and getCompilationUnit().fromSource()
this.getCompilationUnit().hasName("AnnotationValues") and this.getCompilationUnit().fromSource()
}
}

View File

@@ -1,7 +1,7 @@
import java
class RelevantAnnotationType extends AnnotationType {
RelevantAnnotationType() { getCompilationUnit().hasName("AnnotationType") }
RelevantAnnotationType() { this.getCompilationUnit().hasName("AnnotationType") }
}
query predicate annotationType(