mirror of
https://github.com/github/codeql.git
synced 2026-04-24 00:05:14 +02:00
Merge pull request #5273 from intrigus-lgtm/java/unify-main-method-check
Java: Remove duplicate code.
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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`
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user