forked from jasder/antlr
rm unneeded getChildren
This commit is contained in:
parent
004f47174b
commit
6b1cef745c
|
@ -35,7 +35,6 @@ import org.antlr.v4.runtime.RuleContext;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/** An interface to access the tree of {@link RuleContext} objects created
|
/** An interface to access the tree of {@link RuleContext} objects created
|
||||||
* during a parse that makes the data structure look like a simple parse tree.
|
* during a parse that makes the data structure look like a simple parse tree.
|
||||||
|
@ -51,11 +50,6 @@ public interface ParseTree extends SyntaxTree {
|
||||||
@Override
|
@Override
|
||||||
ParseTree getChild(int i);
|
ParseTree getChild(int i);
|
||||||
|
|
||||||
/** Return ordered list of all children of this node; redefine to
|
|
||||||
* refine type.
|
|
||||||
*/
|
|
||||||
List<ParseTree> getChildren();
|
|
||||||
|
|
||||||
/** The {@link ParseTreeVisitor} needs a double dispatch method. */
|
/** The {@link ParseTreeVisitor} needs a double dispatch method. */
|
||||||
<T> T accept(ParseTreeVisitor<? extends T> visitor);
|
<T> T accept(ParseTreeVisitor<? extends T> visitor);
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.antlr.v4.runtime.tree.xpath;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.ParserRuleContext;
|
import org.antlr.v4.runtime.ParserRuleContext;
|
||||||
import org.antlr.v4.runtime.tree.ParseTree;
|
import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
|
import org.antlr.v4.runtime.tree.Tree;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -18,13 +19,13 @@ public class XPathRuleElement extends XPathElement {
|
||||||
public Collection<ParseTree> evaluate(ParseTree t) {
|
public Collection<ParseTree> evaluate(ParseTree t) {
|
||||||
// return all children of t that match nodeName
|
// return all children of t that match nodeName
|
||||||
List<ParseTree> nodes = new ArrayList<ParseTree>();
|
List<ParseTree> nodes = new ArrayList<ParseTree>();
|
||||||
for (ParseTree c : t.getChildren()) {
|
for (Tree c : t.getChildren()) {
|
||||||
if ( c instanceof ParserRuleContext ) {
|
if ( c instanceof ParserRuleContext ) {
|
||||||
ParserRuleContext ctx = (ParserRuleContext)c;
|
ParserRuleContext ctx = (ParserRuleContext)c;
|
||||||
if ( (ctx.getRuleIndex() == ruleIndex && !invert) ||
|
if ( (ctx.getRuleIndex() == ruleIndex && !invert) ||
|
||||||
(ctx.getRuleIndex() != ruleIndex && invert) )
|
(ctx.getRuleIndex() != ruleIndex && invert) )
|
||||||
{
|
{
|
||||||
nodes.add(c);
|
nodes.add(ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.antlr.v4.runtime.tree.xpath;
|
||||||
|
|
||||||
import org.antlr.v4.runtime.tree.ParseTree;
|
import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
import org.antlr.v4.runtime.tree.TerminalNode;
|
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||||
|
import org.antlr.v4.runtime.tree.Tree;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
@ -18,13 +19,13 @@ public class XPathTokenElement extends XPathElement {
|
||||||
public Collection<ParseTree> evaluate(ParseTree t) {
|
public Collection<ParseTree> evaluate(ParseTree t) {
|
||||||
// return all children of t that match nodeName
|
// return all children of t that match nodeName
|
||||||
List<ParseTree> nodes = new ArrayList<ParseTree>();
|
List<ParseTree> nodes = new ArrayList<ParseTree>();
|
||||||
for (ParseTree c : t.getChildren()) {
|
for (Tree c : t.getChildren()) {
|
||||||
if ( c instanceof TerminalNode ) {
|
if ( c instanceof TerminalNode ) {
|
||||||
TerminalNode tnode = (TerminalNode)c;
|
TerminalNode tnode = (TerminalNode)c;
|
||||||
if ( (tnode.getSymbol().getType() == tokenType && !invert) ||
|
if ( (tnode.getSymbol().getType() == tokenType && !invert) ||
|
||||||
(tnode.getSymbol().getType() != tokenType && invert) )
|
(tnode.getSymbol().getType() != tokenType && invert) )
|
||||||
{
|
{
|
||||||
nodes.add(c);
|
nodes.add(tnode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import org.antlr.v4.runtime.tree.ParseTree;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class XPathWildcardElement extends XPathElement {
|
public class XPathWildcardElement extends XPathElement {
|
||||||
public XPathWildcardElement() {
|
public XPathWildcardElement() {
|
||||||
|
@ -13,6 +14,6 @@ public class XPathWildcardElement extends XPathElement {
|
||||||
@Override
|
@Override
|
||||||
public Collection<ParseTree> evaluate(final ParseTree t) {
|
public Collection<ParseTree> evaluate(final ParseTree t) {
|
||||||
if ( invert ) return new ArrayList<ParseTree>(); // !* is weird but valid (empty)
|
if ( invert ) return new ArrayList<ParseTree>(); // !* is weird but valid (empty)
|
||||||
return new ArrayList<ParseTree>() {{addAll(t.getChildren());}};
|
return new ArrayList<ParseTree>() {{addAll((List<ParseTree>)t.getChildren());}};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue