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

@@ -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()
}
}