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

Commit 7a3a7da

Browse files
committed
Allow imported methods to route correctly
1 parent 1a60c07 commit 7a3a7da

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ attribute node_symbol = node => symbol = (source-text node), source_n
4040
(program)@prog {
4141
node @prog.defs
4242
node @prog.lexical_scope
43-
node @prog.exports
44-
node @prog.globals
4543
edge @prog.lexical_scope -> ROOT_NODE
4644
edge @prog.lexical_scope -> @prog.defs
4745
}
@@ -87,6 +85,7 @@ attribute node_symbol = node => symbol = (source-text node), source_n
8785
edge @import.defs -> @name.value
8886
}
8987

88+
; Import rules lifted mostly from typescript
9089
(program [(import_declaration)]* @import) @prog {
9190
var proj_scope = ROOT_NODE
9291

@@ -103,9 +102,6 @@ attribute node_symbol = node => symbol = (source-text node), source_n
103102
set proj_scope = proj_def
104103
}
105104

106-
; expose globals
107-
edge proj_scope -> @prog.globals
108-
109105
var mod_scope = proj_scope
110106
if (not (is-empty @import)) {
111107
; module definition
@@ -130,8 +126,6 @@ attribute node_symbol = node => symbol = (source-text node), source_n
130126
}
131127
; make the last one a definition
132128
attr (mod_scope) is_definition, source_node = @prog, empty_source_span
133-
; expose exports via module definition
134-
edge mod_scope -> @prog.exports
135129
} else {
136130
; expose definitions via project scope
137131
edge mod_scope -> @prog.defs
@@ -1299,6 +1293,16 @@ attribute node_symbol = node => symbol = (source-text node), source_n
12991293
edge @this.type -> @this.lexical_scope
13001294
}
13011295

1296+
(scoped_type_identifier
1297+
(type_identifier) @imported_class_name (type_identifier) @method_name) {
1298+
1299+
node member
1300+
attr (member) push_symbol = "."
1301+
1302+
edge @method_name.type -> member
1303+
edge member -> @imported_class_name.type
1304+
}
1305+
13021306
;; ==========
13031307
;; Comments
13041308
;; ==========

languages/tree-sitter-stack-graphs-java/test/imports_and_exports/import_method.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
/*--- path: a.java ---*/
22
import Foo;
33

4-
54
public class Importer {
65
public static void main(String[] args) {
76
x = new Foo.bar();
8-
// ^ defined: 17
9-
// ^ defined: 2, 16
7+
// ^ defined: 16
8+
// ^ defined: 2, 15
109

1110
}
1211
}

0 commit comments

Comments
 (0)