-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Open
IdrissRio
wants to merge
6
commits into
main
Choose a base branch
from
idrissrio/compact-soruce-file
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8648bf9
Java: Add `isImplicitClass` table to keep track of compact source files
IdrissRio ad9dc54
Java: Add `isImplict` predicate to CompilationUnit and Class
IdrissRio ab2cf13
Java: Add compact source file tests
IdrissRio 3603128
Java: Add upgrade and downgrade script
IdrissRio 618b0c0
Java: Add change note
IdrissRio 5a80595
Java: Update stats file
IdrissRio File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Java: Add compact source file tests
- Loading branch information
commit ab2cf131185bf0cdd86ff67ce7a29e9fe1f5fc50
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
java/ql/test/library-tests/compact-source-files/CompactSourceAnalysis.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| Test.java:0:0:0:0 | Test | Test.java:1:1:1:1 | Test | Compact source file 'Test' contains implicit class 'Test' | |
9 changes: 9 additions & 0 deletions
9
java/ql/test/library-tests/compact-source-files/CompactSourceAnalysis.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import java | ||
|
||
from CompilationUnit cu, Class c | ||
where | ||
cu.isCompactSourceFile() and | ||
c.getCompilationUnit() = cu and | ||
c.isImplicit() | ||
select cu, c, | ||
"Compact source file '" + cu.getName() + "' contains implicit class '" + c.getName() + "'" |
1 change: 1 addition & 0 deletions
1
java/ql/test/library-tests/compact-source-files/CompactSourceDetection.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| Test.java:0:0:0:0 | Test | |
5 changes: 5 additions & 0 deletions
5
java/ql/test/library-tests/compact-source-files/CompactSourceDetection.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import java | ||
|
||
from CompilationUnit cu | ||
where cu.isCompactSourceFile() | ||
select cu |
2 changes: 2 additions & 0 deletions
2
java/ql/test/library-tests/compact-source-files/ImplicitClassDetection.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| Test.java:1:1:1:1 | Test | implicit | | ||
| Test.java:25:7:25:16 | NotCompact | not implicit | |
7 changes: 7 additions & 0 deletions
7
java/ql/test/library-tests/compact-source-files/ImplicitClassDetection.ql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import java | ||
|
||
from Class c, string res | ||
where | ||
exists(c.getCompilationUnit().getRelativePath()) and | ||
if c.isImplicit() then res = "implicit" else res = "not implicit" | ||
select c, res |
42 changes: 42 additions & 0 deletions
42
java/ql/test/library-tests/compact-source-files/PrintAst.expected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
Test.java: | ||
# 0| [CompilationUnit] Test | ||
# 1| 1: [Class] Test | ||
# 1| 4: [FieldDeclaration] int instanceField; | ||
# 1| -1: [TypeAccess] int | ||
# 1| 0: [IntegerLiteral] 10 | ||
# 2| 5: [FieldDeclaration] int STATIC_CONSTANT; | ||
# 2| -1: [TypeAccess] int | ||
# 2| 0: [IntegerLiteral] 42 | ||
# 3| 6: [FieldDeclaration] String privateField; | ||
# 3| -1: [TypeAccess] String | ||
# 3| 0: [StringLiteral] "data" | ||
# 5| 7: [Method] main | ||
# 5| 3: [TypeAccess] void | ||
# 5| 5: [BlockStmt] { ... } | ||
# 6| 0: [ExprStmt] <Expr>; | ||
# 6| 0: [MethodCall] processData(...) | ||
# 7| 1: [ExprStmt] <Expr>; | ||
# 7| 0: [MethodCall] testStaticAccess(...) | ||
# 11| 8: [Method] processData | ||
# 11| 3: [TypeAccess] void | ||
# 11| 5: [BlockStmt] { ... } | ||
# 12| 0: [ExprStmt] <Expr>; | ||
# 12| 0: [PostIncExpr] ...++ | ||
# 12| 0: [VarAccess] instanceField | ||
# 13| 1: [ExprStmt] <Expr>; | ||
# 13| 0: [MethodCall] updatePrivateField(...) | ||
# 16| 9: [Method] updatePrivateField | ||
# 16| 3: [TypeAccess] void | ||
# 16| 5: [BlockStmt] { ... } | ||
# 17| 0: [ExprStmt] <Expr>; | ||
# 17| 0: [AssignExpr] ...=... | ||
# 17| 0: [VarAccess] privateField | ||
# 17| 1: [StringLiteral] "updated" | ||
# 21| 10: [Method] testStaticAccess | ||
# 21| 3: [TypeAccess] void | ||
# 21| 5: [BlockStmt] { ... } | ||
# 22| 0: [ExprStmt] <Expr>; | ||
# 22| 0: [MethodCall] println(...) | ||
# 22| -1: [TypeAccess] IO | ||
# 22| 0: [StringLiteral] "Static access test" | ||
# 25| 11: [Class] NotCompact |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
semmle/code/java/PrintAst.ql |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
int instanceField = 10; | ||
static final int STATIC_CONSTANT = 42; | ||
private String privateField = "data"; | ||
|
||
void main() { | ||
processData(); | ||
testStaticAccess(); | ||
} | ||
|
||
// Test instance methods | ||
void processData() { | ||
instanceField++; | ||
updatePrivateField(); | ||
} | ||
|
||
private void updatePrivateField() { | ||
privateField = "updated"; | ||
} | ||
|
||
// Test static method access | ||
static void testStaticAccess() { | ||
IO.println("Static access test"); | ||
} | ||
|
||
class NotCompact { | ||
//Test explict class | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//semmle-extractor-options: --javac-args --release 25 --enable-preview |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a spelling error in the comment: 'explict' should be 'explicit'.
Copilot uses AI. Check for mistakes.