Skip to content

Commit 5f0ab52

Browse files
authored
Merge pull request #7988 from Marcono1234/marcono1234/sealed-types-predicates
Java: Add predicates for sealed classes
2 parents cfcb06c + 2f82a46 commit 5f0ab52

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 `ClassOrInterface.getAPermittedSubtype` and `isSealed` exposing information about 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)