Skip to content

Java: Add support to Compact Source Files #20116

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,240 changes: 1,240 additions & 0 deletions java/downgrades/9f6026c400996c13842974b24f076a486ad1f69c/old.dbscheme

Large diffs are not rendered by default.

1,236 changes: 1,236 additions & 0 deletions java/downgrades/9f6026c400996c13842974b24f076a486ad1f69c/semmlecode.dbscheme

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
description: Remove Java 25 compact source files support by removing `isImplicitClass` table
compatibility: partial
isImplicitClass.rel: delete
4 changes: 4 additions & 0 deletions java/ql/lib/change-notes/2025-07-23-compact-source-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: feature
---
* Added support for Java 25 compact source files (JEP 512). The new predicate `Class.isImplicit()` identifies classes that are implicitly declared when using compact source files, and the new predicate `CompilationUnit.isCompactSourceFile()` identifies compilation units that contain compact source files.
4 changes: 4 additions & 0 deletions java/ql/lib/config/semmlecode.dbscheme
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,10 @@ isLocalClassOrInterface(
int parent: @localtypedeclstmt ref
);

isImplicitClass(
unique int classid: @classorinterface ref
);

isDefConstr(
int constructorid: @constructor ref
);
Expand Down
8 changes: 8 additions & 0 deletions java/ql/lib/semmle/code/java/CompilationUnit.qll
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@ class CompilationUnit extends Element, File {
*/
Module getModule() { cumodule(this, result) }

/**
* Holds if this compilation unit represents a compact source file.
* A compact source file contains an implicitly declared top-level class.
*/
predicate isCompactSourceFile() {
exists(Class c | c.getCompilationUnit() = this and c.isImplicit())
}

override string getAPrimaryQlClass() { result = "CompilationUnit" }
}
6 changes: 6 additions & 0 deletions java/ql/lib/semmle/code/java/Diagnostics.qll
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,9 @@ class Diagnostic extends @diagnostic {
/** Gets a textual representation of this diagnostic. */
string toString() { result = this.getMessage() }
}

/**
* Holds for extraction information keys that should be skipped from telemetry reports.
* This predicate can be extended by other packs to filter out specific telemetry keys.
*/
extensible predicate extractorInformationSkipKey(string key);
3 changes: 3 additions & 0 deletions java/ql/lib/semmle/code/java/Type.qll
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,9 @@ class Class extends ClassOrInterface {
/** Holds if this class is an anonymous class. */
predicate isAnonymous() { isAnonymClass(this.getSourceDeclaration(), _) }

/** Holds if this class is an implicit class (compact source file). */
predicate isImplicit() { isImplicitClass(this.getSourceDeclaration()) }

/**
* Gets an annotation that applies to this class.
*
Expand Down
Loading