Merge pull request #5273 from intrigus-lgtm/java/unify-main-method-check

Java: Remove duplicate code.
This commit is contained in:
Anders Schack-Mulligen
2021-03-01 09:05:28 +01:00
committed by GitHub
3 changed files with 5 additions and 15 deletions

View File

@@ -9,13 +9,13 @@
import java
import semmle.code.java.J2EE
import MainLib
import TestLib
/** The `main` method in an Enterprise Java Bean. */
class EnterpriseBeanMainMethod extends Method {
EnterpriseBeanMainMethod() {
this.getDeclaringType() instanceof EnterpriseBean and
isMainMethod(this) and
this instanceof MainMethod and
not isTestMethod(this)
}
}

View File

@@ -1,17 +1,7 @@
/** Definitions related to the main method in a test program. */
/** Definitions related to test methods. */
import java
/** Holds if `m` is the main method of a Java class with the signature `public static void main(String[] args)`. */
predicate isMainMethod(Method m) {
m.hasName("main") and
m.isStatic() and
m.getReturnType() instanceof VoidType and
m.isPublic() and
m.getNumberOfParameters() = 1 and
m.getParameter(0).getType() instanceof Array
}
/**
* Holds if `m` is a test method indicated by:
* a) in a test directory such as `src/test/java`

View File

@@ -9,7 +9,7 @@
import java
import semmle.code.java.frameworks.Servlets
import MainLib
import TestLib
/** The java type `javax.servlet.Filter`. */
class ServletFilterClass extends Class {
@@ -48,7 +48,7 @@ class WebComponentMainMethod extends Method {
.getASupertype+()
.hasQualifiedName("org.springframework.webflow.execution", "Action") // Spring actions
) and
isMainMethod(this) and
this instanceof MainMethod and
not isTestMethod(this)
}
}