Skip to content

Commit 608d24f

Browse files
committed
Rename QL elements that refer to local classes
1 parent 0a5410c commit 608d24f

File tree

11 files changed

+48
-24
lines changed

11 files changed

+48
-24
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
lgtm,codescanning
2-
* `Class.isLocal` has been replaced with `ClassOrInterface.isLocal`. This is because as of Java 16, interfaces can be declared method-local. Accordingly, `LocalClassDeclStmt.getLocalClass` now returns a `ClassOrInterface`. `BusinessInterface`, declared in `EJB.qll`, has had its `isRemote` and `isLocal` methods renamed `isDeclaredLocal` and `isDeclaredRemote` to avoid a name clash.
2+
* `Class.isLocal` has been replaced with `ClassOrInterface.isLocal`. This is because as of Java 16, interfaces can be declared method-local. Accordingly, `LocalClassDeclStmt.getLocalClass` is renamed `LocalTypeDeclStmt.getLocalType` and now returns a `ClassOrInterface`. `BusinessInterface`, declared in `EJB.qll`, has had its `isRemote` and `isLocal` methods renamed `isDeclaredLocal` and `isDeclaredRemote` to avoid a name clash.

java/ql/lib/semmle/code/java/ControlFlowGraph.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ private module ControlFlowGraphImpl {
456456
or
457457
this instanceof EmptyStmt
458458
or
459-
this instanceof LocalClassDeclStmt
459+
this instanceof LocalTypeDeclStmt
460460
or
461461
this instanceof AssertStmt
462462
}

java/ql/lib/semmle/code/java/Member.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Member extends Element, Annotatable, Modifiable, @member {
4545
Callable getEnclosingCallable() {
4646
exists(NestedClass nc | this.getDeclaringType() = nc |
4747
nc.(AnonymousClass).getClassInstanceExpr().getEnclosingCallable() = result or
48-
nc.(LocalClassOrInterface).getLocalClassDeclStmt().getEnclosingCallable() = result
48+
nc.(LocalClassOrInterface).getLocalTypeDeclStmt().getEnclosingCallable() = result
4949
)
5050
}
5151
}

java/ql/lib/semmle/code/java/PrettyPrintAst.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -877,8 +877,8 @@ private class PpLocalVariableDeclStmt extends PpAst, LocalVariableDeclStmt {
877877
}
878878
}
879879

880-
private class PpLocalClassDeclStmt extends PpAst, LocalClassDeclStmt {
881-
override PpAst getChild(int i) { i = 0 and result = this.getLocalClass() }
880+
private class PpLocalTypeDeclStmt extends PpAst, LocalTypeDeclStmt {
881+
override PpAst getChild(int i) { i = 0 and result = this.getLocalType() }
882882
}
883883

884884
/*

java/ql/lib/semmle/code/java/PrintAst.qll

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,25 @@ final class ClassInstanceExprNode extends ExprStmtNode {
303303
}
304304

305305
/**
306-
* A node representing a `LocalClassDeclStmt`.
306+
* A node representing a `LocalTypeDeclStmt`.
307307
*/
308-
final class LocalClassDeclStmtNode extends ExprStmtNode {
309-
LocalClassDeclStmtNode() { element instanceof LocalClassDeclStmt }
308+
final class LocalTypeDeclStmtNode extends ExprStmtNode {
309+
LocalTypeDeclStmtNode() { element instanceof LocalTypeDeclStmt }
310310

311311
override ElementNode getChild(int childIndex) {
312312
result = super.getChild(childIndex)
313313
or
314314
childIndex = 0 and
315-
result.getElement() = element.(LocalClassDeclStmt).getLocalClass()
315+
result.getElement() = element.(LocalTypeDeclStmt).getLocalType()
316316
}
317317
}
318318

319+
/**
320+
* DEPRECATED: Renamed `LocalTypeDeclStmtNode` to reflect the fact that
321+
* as of Java 16 interfaces can also be declared locally, not just classes.
322+
*/
323+
deprecated class LocalClassDeclStmtNode = LocalTypeDeclStmtNode;
324+
319325
/**
320326
* A node representing a `ForStmt`.
321327
*/

java/ql/lib/semmle/code/java/Statement.qll

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -787,25 +787,37 @@ class LocalVariableDeclStmt extends Stmt, @localvariabledeclstmt {
787787
}
788788

789789
/** A statement that declares a local class or interface. */
790-
class LocalClassDeclStmt extends Stmt, @localclassdeclstmt {
791-
/** Gets the local class declared by this statement. */
792-
LocalClassOrInterface getLocalClass() { isLocalClass(result, this) }
790+
class LocalTypeDeclStmt extends Stmt, @localclassdeclstmt {
791+
/** Gets the local type declared by this statement. */
792+
LocalClassOrInterface getLocalType() { isLocalClass(result, this) }
793+
794+
/**
795+
* DEPRECATED: Renamed `getLocalType` to reflect the fact that
796+
* as of Java 16 interfaces can also be declared locally, not just classes.
797+
*/
798+
deprecated LocalClassOrInterface getLocalClass() { result = this.getLocalType() }
793799

794800
private string getDeclKeyword() {
795-
result = "class" and this.getLocalClass() instanceof Class
801+
result = "class" and this.getLocalType() instanceof Class
796802
or
797-
result = "interface" and this.getLocalClass() instanceof Interface
803+
result = "interface" and this.getLocalType() instanceof Interface
798804
}
799805

800-
override string pp() { result = this.getDeclKeyword() + " " + this.getLocalClass().toString() }
806+
override string pp() { result = this.getDeclKeyword() + " " + this.getLocalType().toString() }
801807

802808
override string toString() { result = this.getDeclKeyword() + " ..." }
803809

804-
override string getHalsteadID() { result = "LocalClassDeclStmt" }
810+
override string getHalsteadID() { result = "LocalTypeDeclStmt" }
805811

806-
override string getAPrimaryQlClass() { result = "LocalClassDeclStmt" }
812+
override string getAPrimaryQlClass() { result = "LocalTypeDeclStmt" }
807813
}
808814

815+
/**
816+
* DEPRECATED: Renamed `LocalTypeDeclStmt` to reflect the fact that
817+
* as of Java 16 interfaces can also be declared locally, not just classes.
818+
*/
819+
deprecated class LocalClassDeclStmt = LocalTypeDeclStmt;
820+
809821
/** An explicit `this(...)` constructor invocation. */
810822
class ThisConstructorInvocationStmt extends Stmt, ConstructorCall, @constructorinvocationstmt {
811823
/** Gets an argument of this constructor invocation. */

java/ql/lib/semmle/code/java/Type.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -722,7 +722,13 @@ class LocalClassOrInterface extends NestedType, ClassOrInterface {
722722
LocalClassOrInterface() { this.isLocal() }
723723

724724
/** Gets the statement that declares this local class. */
725-
LocalClassDeclStmt getLocalClassDeclStmt() { isLocalClass(this, result) }
725+
LocalTypeDeclStmt getLocalTypeDeclStmt() { isLocalClass(this, result) }
726+
727+
/**
728+
* DEPRECATED: renamed `getLocalTypeDeclStmt` to reflect the fact that
729+
* as of Java 16 interfaces can also be declared locally.
730+
*/
731+
deprecated LocalTypeDeclStmt getLocalClassDeclStmt() { result = this.getLocalTypeDeclStmt() }
726732

727733
override string getAPrimaryQlClass() { result = "LocalClassOrInterface" }
728734
}
@@ -839,7 +845,7 @@ class InnerClass extends NestedClass {
839845
predicate hasEnclosingInstance() {
840846
// JLS 15.9.2. Determining Enclosing Instances
841847
not this.(AnonymousClass).getClassInstanceExpr().isInStaticContext() and
842-
not this.(LocalClass).getLocalClassDeclStmt().getEnclosingCallable().isStatic()
848+
not this.(LocalClass).getLocalTypeDeclStmt().getEnclosingCallable().isStatic()
843849
}
844850
}
845851

java/ql/lib/semmle/code/java/dataflow/SSA.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ private module SsaImpl {
238238
/** Gets the definition point of a nested class in the parent scope. */
239239
private ControlFlowNode parentDef(NestedClass nc) {
240240
nc.(AnonymousClass).getClassInstanceExpr() = result or
241-
nc.(LocalClass).getLocalClassDeclStmt() = result
241+
nc.(LocalClass).getLocalTypeDeclStmt() = result
242242
}
243243

244244
/**

java/ql/lib/semmle/code/java/dataflow/internal/BaseSSA.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ private module SsaImpl {
7979
/** Gets the definition point of a nested class in the parent scope. */
8080
private ControlFlowNode parentDef(NestedClass nc) {
8181
nc.(AnonymousClass).getClassInstanceExpr() = result or
82-
nc.(LocalClass).getLocalClassDeclStmt() = result
82+
nc.(LocalClass).getLocalTypeDeclStmt() = result
8383
}
8484

8585
/**

java/ql/src/DeadCode/FLinesOfDeadCode.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ where
3838
// class. We keep anonymous class counts, because anonymous classes are not reported
3939
// separately.
4040
sum(LocalClassOrInterface localClass |
41-
localClass.getLocalClassDeclStmt().getEnclosingCallable() = deadMethod
41+
localClass.getLocalTypeDeclStmt().getEnclosingCallable() = deadMethod
4242
|
4343
localClass.getNumberOfLinesOfCode()
4444
)

0 commit comments

Comments
 (0)