File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
src/main/java/com/annimon/ownlang/parser/visitors Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ package com .annimon .ownlang .parser .visitors ;
2+
3+ import com .annimon .ownlang .lib .ArrayValue ;
4+ import com .annimon .ownlang .lib .Types ;
5+ import com .annimon .ownlang .lib .Value ;
6+ import com .annimon .ownlang .parser .ast .Statement ;
7+ import com .annimon .ownlang .parser .ast .UseStatement ;
8+ import com .annimon .ownlang .parser .ast .ValueExpression ;
9+ import java .util .HashSet ;
10+ import java .util .Set ;
11+
12+ public class ModuleDetector extends AbstractVisitor {
13+
14+ private Set <String > modules ;
15+
16+ public ModuleDetector () {
17+ modules = new HashSet <>();
18+ }
19+
20+ public Set <String > detect (Statement s ) {
21+ s .accept (this );
22+ return modules ;
23+ }
24+
25+ @ Override
26+ public void visit (UseStatement st ) {
27+ if (st .expression instanceof ValueExpression ) {
28+ ValueExpression ve = (ValueExpression ) st .expression ;
29+ if (ve .value .type () == Types .ARRAY ) {
30+ for (Value module : ((ArrayValue ) ve .value )) {
31+ modules .add (module .asString ());
32+ }
33+ } else {
34+ modules .add (ve .value .asString ());
35+ }
36+ }
37+ super .visit (st );
38+ }
39+ }
You can’t perform that action at this time.
0 commit comments