Skip to content

Commit c8b9ba6

Browse files
committed
Java: Add isImplict predicate to CompilationUnit and Class
1 parent a1b697d commit c8b9ba6

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,13 @@ class CompilationUnit extends Element, File {
3333
*/
3434
Module getModule() { cumodule(this, result) }
3535

36+
/**
37+
* Holds if this compilation unit represents a compact source file.
38+
* A compact source file contains an implicitly declared top-level class.
39+
*/
40+
predicate isCompactSourceFile() {
41+
exists(Class c | c.getCompilationUnit() = this and c.isImplicit())
42+
}
43+
3644
override string getAPrimaryQlClass() { result = "CompilationUnit" }
3745
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,9 @@ class Class extends ClassOrInterface {
699699
/** Holds if this class is an anonymous class. */
700700
predicate isAnonymous() { isAnonymClass(this.getSourceDeclaration(), _) }
701701

702+
/** Holds if this class is an implicit class (compact source file). */
703+
predicate isImplicit() { isImplicitClass(this.getSourceDeclaration()) }
704+
702705
/**
703706
* Gets an annotation that applies to this class.
704707
*

0 commit comments

Comments
 (0)