Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 59f650f

Browse files
committed
Add support for implicit switch statement types
1 parent 817cda2 commit 59f650f

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

languages/tree-sitter-stack-graphs-java/src/stack-graphs.tsg

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,41 @@ attribute node_symbol = node => symbol = (source-text node), source_n
620620
edge @stmt.after_scope -> @stmt.before_scope
621621
}
622622

623+
(method_declaration
624+
parameters:
625+
(formal_parameters
626+
(formal_parameter
627+
type: (generic_type
628+
(type_arguments
629+
(type_identifier) @type))))
630+
body:
631+
(block
632+
(switch_expression
633+
condition: (_)
634+
body: (switch_block
635+
(switch_block_statement_group
636+
(switch_label
637+
(identifier))
638+
@label))
639+
)) @stmt) {
640+
641+
node ident
642+
attr (ident) node_reference = @type
643+
644+
node ref__typeof
645+
attr(ref__typeof) push_symbol = "."
646+
node implicit_this__typeof
647+
attr(implicit_this__typeof) push_symbol = ":"
648+
649+
edge implicit_this__typeof -> @label.lexical_scope
650+
edge @label.lexical_scope -> ref__typeof
651+
edge ref__typeof -> implicit_this__typeof
652+
edge implicit_this__typeof -> ident
653+
654+
edge ident -> @stmt.after_scope
655+
}
656+
657+
623658
(switch_block) @this {
624659
node @this.lexical_scope
625660
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
enum Level {
2+
LOW,
3+
MEDIUM,
4+
HIGH
5+
}
6+
7+
class Supplier<T> {
8+
T get() {}
9+
}
10+
11+
class App {
12+
boolean isSufficient(Supplier<Level> level_supplier) {
13+
switch (level_supplier.get()) {
14+
case LOW: return false;
15+
// ^ defined: 2
16+
case MEDIUM: return false;
17+
// ^ defined: 3
18+
case Level.HIGH: return true;
19+
// ^ defined: 1
20+
// ^ defined: 4
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)