Skip to content

Commit a496b1d

Browse files
committed
Java: Add predicates for sealed classes
1 parent 9b4dbb9 commit a496b1d

22 files changed

+68
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Added predicates for sealed classes.

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,12 @@ class ClassOrInterface extends RefType, @classorinterface {
913913
not this.isProtected() and
914914
not this.isPublic()
915915
}
916+
917+
/** Gets a permitted subtype in case this class or interface is a sealed class (Java 17 feature). */
918+
ClassOrInterface getAPermittedSubtype() { permits(this, result) }
919+
920+
/** Holds if this class or interface is explicitly or implicitly a sealed class (Java 17 feature). */
921+
predicate isSealed() { exists(this.getAPermittedSubtype()) }
916922
}
917923

918924
private string getAPublicObjectMethodSignature() {

0 commit comments

Comments
 (0)