mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
Add Interface.isLocal and use it where appropriate
Some EJB logic regrettably needs to be renamed out of the way. Hopefully the churn caused by this is less than would be caused if Interface's isLocal needed to be named differently from Class.isLocal.
This commit is contained in:
@@ -45,7 +45,7 @@ class Member extends Element, Annotatable, Modifiable, @member {
|
||||
Callable getEnclosingCallable() {
|
||||
exists(NestedClass nc | this.getDeclaringType() = nc |
|
||||
nc.(AnonymousClass).getClassInstanceExpr().getEnclosingCallable() = result or
|
||||
nc.(LocalClass).getLocalClassDeclStmt().getEnclosingCallable() = result
|
||||
nc.(LocalClassOrInterface).getLocalClassDeclStmt().getEnclosingCallable() = result
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -786,14 +786,20 @@ class LocalVariableDeclStmt extends Stmt, @localvariabledeclstmt {
|
||||
override string getAPrimaryQlClass() { result = "LocalVariableDeclStmt" }
|
||||
}
|
||||
|
||||
/** A statement that declares a local class. */
|
||||
/** A statement that declares a local class or interface. */
|
||||
class LocalClassDeclStmt extends Stmt, @localclassdeclstmt {
|
||||
/** Gets the local class declared by this statement. */
|
||||
LocalClass getLocalClass() { isLocalClass(result, this) }
|
||||
LocalClassOrInterface getLocalClass() { isLocalClass(result, this) }
|
||||
|
||||
override string pp() { result = "class " + this.getLocalClass().toString() }
|
||||
private string getDeclKeyword() {
|
||||
result = "class" and this.getLocalClass() instanceof Class
|
||||
or
|
||||
result = "interface" and this.getLocalClass() instanceof Interface
|
||||
}
|
||||
|
||||
override string toString() { result = "class ..." }
|
||||
override string pp() { result = this.getDeclKeyword() + " " + this.getLocalClass().toString() }
|
||||
|
||||
override string toString() { result = this.getDeclKeyword() + " ..." }
|
||||
|
||||
override string getHalsteadID() { result = "LocalClassDeclStmt" }
|
||||
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
* (`Interface`).
|
||||
*
|
||||
* Reference types can be at the top level (`TopLevelType`) or nested (`NestedType`).
|
||||
* Classes can also be local (`LocalClass`) or anonymous (`AnonymousClass`).
|
||||
* Enumerated types (`EnumType`) are a special kind of class.
|
||||
* Classes and interfaces can also be local (`LocalClassOrInterface`, `LocalClass`) or anonymous (`AnonymousClass`).
|
||||
* Enumerated types (`EnumType`) and records (`Record`) are a special kinds of class.
|
||||
*/
|
||||
|
||||
import Member
|
||||
@@ -269,7 +269,7 @@ predicate declaresMember(Type t, @member m) {
|
||||
// Since the type `@member` in the dbscheme includes all `@reftype`s,
|
||||
// anonymous and local classes need to be excluded here.
|
||||
not m instanceof AnonymousClass and
|
||||
not m instanceof LocalClass
|
||||
not m instanceof LocalClassOrInterface
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -608,20 +608,10 @@ class SrcRefType extends RefType {
|
||||
}
|
||||
|
||||
/** A class declaration. */
|
||||
class Class extends RefType, @class {
|
||||
class Class extends ClassOrInterface, @class {
|
||||
/** Holds if this class is an anonymous class. */
|
||||
predicate isAnonymous() { isAnonymClass(this, _) }
|
||||
|
||||
/** Holds if this class is a local class. */
|
||||
predicate isLocal() { isLocalClass(this, _) }
|
||||
|
||||
/** Holds if this class is package protected, that is, neither public nor private nor protected. */
|
||||
predicate isPackageProtected() {
|
||||
not isPrivate() and
|
||||
not isProtected() and
|
||||
not isPublic()
|
||||
}
|
||||
|
||||
override RefType getSourceDeclaration() { classes(this, _, _, result) }
|
||||
|
||||
/**
|
||||
@@ -630,11 +620,13 @@ class Class extends RefType, @class {
|
||||
* Note that a class may inherit annotations from super-classes.
|
||||
*/
|
||||
override Annotation getAnAnnotation() {
|
||||
result = RefType.super.getAnAnnotation()
|
||||
result = ClassOrInterface.super.getAnAnnotation()
|
||||
or
|
||||
exists(AnnotationType tp | tp = result.getType() |
|
||||
tp.isInherited() and
|
||||
not exists(Annotation ann | ann = RefType.super.getAnAnnotation() | ann.getType() = tp) and
|
||||
not exists(Annotation ann | ann = ClassOrInterface.super.getAnAnnotation() |
|
||||
ann.getType() = tp
|
||||
) and
|
||||
result = this.getASupertype().(Class).getAnAnnotation()
|
||||
)
|
||||
}
|
||||
@@ -643,8 +635,6 @@ class Class extends RefType, @class {
|
||||
}
|
||||
|
||||
/**
|
||||
* PREVIEW FEATURE in Java 14. Subject to removal in a future release.
|
||||
*
|
||||
* A record declaration.
|
||||
*/
|
||||
class Record extends Class {
|
||||
@@ -727,13 +717,20 @@ class AnonymousClass extends NestedClass {
|
||||
override string getAPrimaryQlClass() { result = "AnonymousClass" }
|
||||
}
|
||||
|
||||
/** A local class. */
|
||||
class LocalClass extends NestedClass {
|
||||
LocalClass() { this.isLocal() }
|
||||
/** A local class or interface. */
|
||||
class LocalClassOrInterface extends NestedType, ClassOrInterface {
|
||||
LocalClassOrInterface() { this.isLocal() }
|
||||
|
||||
/** Gets the statement that declares this local class. */
|
||||
LocalClassDeclStmt getLocalClassDeclStmt() { isLocalClass(this, result) }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "LocalClassOrInterface" }
|
||||
}
|
||||
|
||||
/** A local class. */
|
||||
class LocalClass extends LocalClassOrInterface, NestedClass {
|
||||
LocalClass() { this.isLocal() }
|
||||
|
||||
override string getAPrimaryQlClass() { result = "LocalClass" }
|
||||
}
|
||||
|
||||
@@ -847,7 +844,7 @@ class InnerClass extends NestedClass {
|
||||
}
|
||||
|
||||
/** An interface. */
|
||||
class Interface extends RefType, @interface {
|
||||
class Interface extends ClassOrInterface, @interface {
|
||||
override RefType getSourceDeclaration() { interfaces(this, _, _, result) }
|
||||
|
||||
override predicate isAbstract() {
|
||||
@@ -855,21 +852,24 @@ class Interface extends RefType, @interface {
|
||||
any()
|
||||
}
|
||||
|
||||
/** Holds if this interface is package protected, that is, neither public nor private nor protected. */
|
||||
predicate isPackageProtected() {
|
||||
not isPrivate() and
|
||||
not isProtected() and
|
||||
not isPublic()
|
||||
}
|
||||
|
||||
override string getAPrimaryQlClass() { result = "Interface" }
|
||||
}
|
||||
|
||||
/** A class or interface. */
|
||||
class ClassOrInterface extends RefType {
|
||||
ClassOrInterface() {
|
||||
this instanceof Class or
|
||||
this instanceof Interface
|
||||
this instanceof @class or
|
||||
this instanceof @interface
|
||||
}
|
||||
|
||||
/** Holds if this class or interface is local. */
|
||||
predicate isLocal() { isLocalClass(this, _) }
|
||||
|
||||
/** Holds if this class or interface is package protected, that is, neither public nor private nor protected. */
|
||||
predicate isPackageProtected() {
|
||||
not isPrivate() and
|
||||
not isProtected() and
|
||||
not isPublic()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -234,10 +234,10 @@ abstract class BusinessInterface extends Interface {
|
||||
abstract SessionEJB getAnEJB();
|
||||
|
||||
/** Holds if this business interface is declared local. */
|
||||
abstract predicate isLocal();
|
||||
abstract predicate isDeclaredLocal();
|
||||
|
||||
/** Holds if this business interface is declared remote. */
|
||||
abstract predicate isRemote();
|
||||
abstract predicate isDeclaredRemote();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -259,14 +259,14 @@ class XmlSpecifiedBusinessInterface extends BusinessInterface {
|
||||
)
|
||||
}
|
||||
|
||||
override predicate isLocal() {
|
||||
override predicate isDeclaredLocal() {
|
||||
exists(EjbJarXMLFile f |
|
||||
this.getQualifiedName() =
|
||||
f.getASessionElement().getABusinessLocalElement().getACharactersSet().getCharacters()
|
||||
)
|
||||
}
|
||||
|
||||
override predicate isRemote() {
|
||||
override predicate isDeclaredRemote() {
|
||||
exists(EjbJarXMLFile f |
|
||||
this.getQualifiedName() =
|
||||
f.getASessionElement().getABusinessRemoteElement().getACharactersSet().getCharacters()
|
||||
@@ -295,9 +295,9 @@ class AnnotatedBusinessInterface extends BusinessInterface {
|
||||
result.getAnAnnotation().(BusinessInterfaceAnnotation).getANamedType() = this
|
||||
}
|
||||
|
||||
override predicate isLocal() { this instanceof LocalAnnotatedBusinessInterface }
|
||||
override predicate isDeclaredLocal() { this instanceof LocalAnnotatedBusinessInterface }
|
||||
|
||||
override predicate isRemote() { this instanceof RemoteAnnotatedBusinessInterface }
|
||||
override predicate isDeclaredRemote() { this instanceof RemoteAnnotatedBusinessInterface }
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -540,7 +540,7 @@ class XmlSpecifiedLocalHomeInterface extends LegacyEjbLocalHomeInterface {
|
||||
class RemoteInterface extends Interface {
|
||||
RemoteInterface() {
|
||||
this instanceof RemoteAnnotatedBusinessInterface or
|
||||
this.(XmlSpecifiedBusinessInterface).isRemote() or
|
||||
this.(XmlSpecifiedBusinessInterface).isDeclaredRemote() or
|
||||
exists(SessionEJB ejb | this = ejb.getARemoteInterface())
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ where
|
||||
// Remove local classes defined in the dead method - they are reported separately as a dead
|
||||
// class. We keep anonymous class counts, because anonymous classes are not reported
|
||||
// separately.
|
||||
sum(LocalClass localClass |
|
||||
sum(LocalClassOrInterface localClass |
|
||||
localClass.getLocalClassDeclStmt().getEnclosingCallable() = deadMethod
|
||||
|
|
||||
localClass.getNumberOfLinesOfCode()
|
||||
|
||||
@@ -8,15 +8,10 @@
|
||||
import java
|
||||
|
||||
/** A type that should be in the generated code. */
|
||||
abstract private class GeneratedType extends RefType {
|
||||
abstract private class GeneratedType extends ClassOrInterface {
|
||||
GeneratedType() {
|
||||
(
|
||||
this instanceof Interface
|
||||
or
|
||||
this instanceof Class
|
||||
) and
|
||||
not this instanceof AnonymousClass and
|
||||
not this instanceof LocalClass and
|
||||
not this.isLocal() and
|
||||
not this.getPackage() instanceof ExcludedPackage
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user