Skip to content

Commit 4f3765a

Browse files
committed
Добавлен детектор модулей от Android-версии
1 parent 2d0b49b commit 4f3765a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
}

0 commit comments

Comments
 (0)