mirror of
https://github.com/AppleCommander/bastools.git
synced 2025-01-18 23:29:41 +00:00
Adding VariableCollectorVisitor.
This commit is contained in:
parent
d17aa69d8c
commit
edb91e9f96
api/src/main/java/io/github/applecommander/bastokenizer/api
@ -10,6 +10,7 @@ import io.github.applecommander.bastokenizer.api.visitors.LineNumberTargetCollec
|
||||
import io.github.applecommander.bastokenizer.api.visitors.PrettyPrintVisitor;
|
||||
import io.github.applecommander.bastokenizer.api.visitors.PrintVisitor;
|
||||
import io.github.applecommander.bastokenizer.api.visitors.ReassignmentVisitor;
|
||||
import io.github.applecommander.bastokenizer.api.visitors.VariableCollectorVisitor;
|
||||
import io.github.applecommander.bastokenizer.api.visitors.VariableReportVisitor;
|
||||
|
||||
/**
|
||||
@ -67,6 +68,10 @@ public class Visitors {
|
||||
return new LineNumberTargetCollector();
|
||||
}
|
||||
|
||||
public static VariableCollectorVisitor variableCollectorVisitor() {
|
||||
return new VariableCollectorVisitor();
|
||||
}
|
||||
|
||||
public static Visitor variableReportVisitor() {
|
||||
return new VariableReportVisitor();
|
||||
}
|
||||
|
24
api/src/main/java/io/github/applecommander/bastokenizer/api/visitors/VariableCollectorVisitor.java
Normal file
24
api/src/main/java/io/github/applecommander/bastokenizer/api/visitors/VariableCollectorVisitor.java
Normal file
@ -0,0 +1,24 @@
|
||||
package io.github.applecommander.bastokenizer.api.visitors;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import io.github.applecommander.bastokenizer.api.Visitor;
|
||||
import io.github.applecommander.bastokenizer.api.model.Token;
|
||||
import io.github.applecommander.bastokenizer.api.model.Token.Type;
|
||||
|
||||
public class VariableCollectorVisitor implements Visitor {
|
||||
private Set<String> variableNames = new HashSet<>();
|
||||
|
||||
public Set<String> getVariableNames() {
|
||||
return this.variableNames;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token visit(Token token) {
|
||||
if (token.type == Type.IDENT) {
|
||||
variableNames.add(token.text);
|
||||
}
|
||||
return Visitor.super.visit(token);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user