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

Commit 5601ed8

Browse files
rnkaufmanrobrix
andcommitted
Wire up static method imports correctly
Co-authored-by: Rob Rix <[email protected]>
1 parent 7a3a7da commit 5601ed8

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ attribute node_symbol = node => symbol = (source-text node), source_n
165165
attr (@class_body.lexical_scope -> @class_body.defs) precedence = 1
166166
edge @class.defs -> def
167167
edge def -> @class_body.defs
168+
edge def -> @class_body.static_defs
168169

169170
node this__expr_def
170171
node @class.type
@@ -176,6 +177,11 @@ attribute node_symbol = node => symbol = (source-text node), source_n
176177

177178
attr (@class.type) pop_symbol = ":"
178179

180+
node def__typeof
181+
attr (def__typeof) pop_symbol = ":"
182+
edge def -> def__typeof
183+
edge def__typeof -> @class_body.static_defs
184+
179185
edge @class.type -> ref
180186
attr (@class.type -> ref) precedence = 1
181187
}
@@ -238,15 +244,18 @@ attribute node_symbol = node => symbol = (source-text node), source_n
238244
(class_body) @class_body {
239245
node @class_body.lexical_scope
240246
node @class_body.defs
247+
node @class_body.static_defs
241248
}
242249

243250
(class_body (_)@declaration)@class_body {
244251
edge @class_body.defs -> @declaration.defs
252+
edge @class_body.static_defs -> @declaration.static_defs
245253
edge @declaration.lexical_scope -> @class_body.lexical_scope
246254
}
247255

248256
(class_body (block) @block) {
249257
node @block.defs
258+
node @block.static_defs
250259
node @block.lexical_scope
251260
edge @block.lexical_scope -> @block.before_scope
252261
}
@@ -272,6 +281,7 @@ attribute node_symbol = node => symbol = (source-text node), source_n
272281
; FIXME: can we get away with defining one and only one thing for each of these, and therefore having a `.def` node instead of `.defs`?
273282
node @decl.defs
274283
node @decl.lexical_scope
284+
node @decl.static_defs
275285
}
276286

277287
(annotation_type_declaration
@@ -434,14 +444,20 @@ attribute node_symbol = node => symbol = (source-text node), source_n
434444
}
435445

436446
(method_declaration
447+
(modifiers "static"?@is_static)?
437448
type: (_) @type
438449
name: (identifier) @name
439450
body: (block) @block) @method
440451
{
441452
edge @type.lexical_scope -> @method.lexical_scope
442453

443454
node member
444-
edge @method.defs -> member
455+
456+
if none @is_static {
457+
edge @method.defs -> member
458+
} else {
459+
edge @method.static_defs -> member
460+
}
445461

446462
attr (member) pop_symbol = "."
447463

@@ -1313,6 +1329,8 @@ attribute node_symbol = node => symbol = (source-text node), source_n
13131329
node @line_comment.lexical_defs
13141330
node @line_comment.lexical_scope
13151331
node @line_comment.defs
1332+
node @line_comment.ref
1333+
node @line_comment.static_defs
13161334

13171335
edge @line_comment.after_scope -> @line_comment.before_scope
13181336
}
@@ -1321,6 +1339,8 @@ attribute node_symbol = node => symbol = (source-text node), source_n
13211339
node @block_comment.before_scope
13221340
node @block_comment.after_scope
13231341
node @block_comment.defs
1342+
node @block_comment.ref
1343+
node @block_comment.static_defs
13241344
node @block_comment.lexical_scope
13251345

13261346
edge @block_comment.after_scope -> @block_comment.before_scope

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
/*--- path: a.java ---*/
2-
import Foo;
1+
/*--- path: Importer.java ---*/
2+
import foo.Foo;
33

44
public class Importer {
55
public static void main(String[] args) {
6-
x = new Foo.bar();
7-
// ^ defined: 16
8-
// ^ defined: 2, 15
6+
Foo.bar();
7+
// ^ defined: 2,15
8+
// ^ defined: 16
99

1010
}
1111
}
1212

13-
/* --- path: foo.java ---*/
13+
/* --- path: foo/Foo.java ---*/
1414

1515
public class Foo {
1616
public static void bar() {

0 commit comments

Comments
 (0)