本文整理汇总了Java中org.antlr.v4.runtime.tree.xpath.XPath类的典型用法代码示例。如果您正苦于以下问题:Java XPath类的具体用法?Java XPath怎么用?Java XPath使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XPath类属于org.antlr.v4.runtime.tree.xpath包,在下文中一共展示了XPath类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAlterTableIdentifiers
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
public ResolvedTableNames getAlterTableIdentifiers() {
Check.isTrue(statementType == StatementType.ALTER);
FusionTablesSqlParser parser = getParser();
VerboseErrorListener errorListener = Util.addVerboseErrorListener(parser);
String xpath = "//alter_table_stmt//string_literal";
Iterator<ParseTree> names = XPath.findAll(parser.fusionTablesSql(), xpath, parser).iterator();
String nameFrom = null;
String nameTo = null;
nameFrom = StringUtil.stripQuotes(getNextTerminal(names, parser));
nameTo = StringUtil.stripQuotes(getNextTerminal(names, parser));
return resolveTableNames(nameFrom, nameTo, errorListener.getErrors());
}
示例2: add_new_AST_node
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
@Test
public void add_new_AST_node()
throws Exception
{
Java8Parser parser = buildParser();
ParseTree tree = buildAST(parser);
Assert.assertNotNull(tree);
String myType = ASTHelperTest.class.getName();
ASTHelper astHelper = new ASTHelper(tree);
astHelper.addImport(myType);
Collection<ParseTree> imports = XPath.findAll(tree, "//importDeclaration", parser);
Assert.assertNotNull(imports);
boolean found = false;
for (ParseTree node : imports) {
if (("import" + myType + ";").equals(node.getText())) {
found = true;
break;
}
}
Assert.assertTrue(found);
}
示例3: testUnicode
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
@Test
public void testUnicode() throws Exception {
QueryParser parser = getParser("törmÈ ዩኒኮድ ምንድን ነው? ดินสอ 铅笔 قلم עפרון");
Collection<ParseTree> trees = XPath.findAll(parser.query(), "//termQuery", parser);
assertThat(trees, hasSize(8));
assertThat(trees, hasItem(text("törmÈ")));
assertThat(trees, hasItem(text("ዩኒኮድ")));
assertThat(trees, hasItem(text("ምንድን")));
assertThat(trees, hasItem(text("ነው?")));
assertThat(trees, hasItem(text("ดินสอ")));
assertThat(trees, hasItem(text("铅笔")));
assertThat(trees, hasItem(text("עפרון")));
assertThat(trees, hasItem(text("قلم")));
}
示例4: getRuleDefNameNode
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
public static TerminalNode getRuleDefNameNode(Parser parser, ParseTree tree, String ruleName) {
Collection<ParseTree> ruleDefRuleNodes;
if ( Grammar.isTokenName(ruleName) ) {
ruleDefRuleNodes = XPath.findAll(tree, "//lexerRule/TOKEN_REF", parser);
}
else {
ruleDefRuleNodes = XPath.findAll(tree, "//parserRuleSpec/RULE_REF", parser);
}
for (ParseTree node : ruleDefRuleNodes) {
String r = node.getText(); // always a TerminalNode; just get rule name of this def
if ( r.equals(ruleName) ) {
return (TerminalNode)node;
}
}
return null;
}
示例5: getAllRuleRefNodes
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
public static List<TerminalNode> getAllRuleRefNodes(Parser parser, ParseTree tree, String ruleName) {
List<TerminalNode> nodes = new ArrayList<TerminalNode>();
Collection<ParseTree> ruleRefs;
if ( Grammar.isTokenName(ruleName) ) {
ruleRefs = XPath.findAll(tree, "//lexerRuleBlock//TOKEN_REF", parser);
}
else {
ruleRefs = XPath.findAll(tree, "//ruleBlock//RULE_REF", parser);
}
for (ParseTree node : ruleRefs) {
TerminalNode terminal = (TerminalNode)node;
Token rrefToken = terminal.getSymbol();
String r = rrefToken.getText();
if ( r.equals(ruleName) ) {
nodes.add(terminal);
}
}
if ( nodes.size()==0 ) return null;
return nodes;
}
示例6: treeXpath
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
public void treeXpath() {
FusionTablesSqlParser parser = getParserStuff().parser;
String xpath = "//sql_stmt";
for (ParseTree t : XPath.findAll(parser.fusionTablesSql(), xpath, parser))
System.out.println(Util.getSqlStatementType(t, parser).name());
}
示例7: getStatementType
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
@SuppressWarnings("unused")
private StatementType getStatementType(FusionTablesSqlParser parser) {
String xpath = "//" + Const.rulename_sql_stmt;
Collection<ParseTree> s = XPath.findAll(parser.fusionTablesSql(), xpath, parser);
if (s.size() == 0)
return StatementType.UNKNOWN;
else
return Util.getSqlStatementType(s.iterator().next(), parser);
}
示例8: getTableAliases
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
public DiggedAliases getTableAliases() {
Map<String, String> result = new HashMap<String, String>();
FusionTablesSqlParser parser = getParser();
VerboseErrorListener errorListener = Util.addVerboseErrorListener(parser);
String xpath = "//table_name_with_alias";
Iterator<ParseTree> trees = XPath.findAll(parser.fusionTablesSql(), xpath, parser).iterator();
while (trees.hasNext()) {
ParseTree parseTree = trees.next();
addAlias(result, parseTree);
}
return new DiggedAliases(result, errorListener.getErrors());
}
示例9: retrieveReturnTypesOfMethods
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
public List<String> retrieveReturnTypesOfMethods(ParseTree tree, Java8Parser parser)
{
List<String> result = new ArrayList<>();
for (ParseTree node : XPath.findAll(tree, "//methodHeader", parser))
{
ParseTreeWalker walker = new ParseTreeWalker();
ReturnTypesOfMethodsListener listener = new ReturnTypesOfMethodsListener();
walker.walk(listener, node.getChild(0));
result.addAll(listener.getReturnTypesOfMethods());
}
return result;
}
示例10: retrieveReturnTypesOfMethodsXpath
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
public List<String> retrieveReturnTypesOfMethodsXpath(ParseTree tree, Java8Parser parser)
{
List<String> result = new ArrayList<>();
for (ParseTree node : XPath.findAll(tree, "//methodHeader/result//*/!typeArguments", parser)) {
if (node instanceof TerminalNode) {
result.add(((TerminalNode) node).getText());
} else {
result.add(node.getText());
}
}
return result;
}
示例11: initialize
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
protected void initialize(String input)
{
StringTemplateCSSLexer lexer = new StringTemplateCSSLexer(new ANTLRInputStream(input));
CommonTokenStream tokens = new CommonTokenStream(lexer);
StringTemplateCSSParser parser = new StringTemplateCSSParser(tokens);
parser.setErrorHandler(new BailErrorStrategy());
ParseTree tree = parser.css();
Collection<ParseTree> selectorCombinations = XPath.findAll(tree, "//selectorCombination", parser);
final StringUtils stringUtils = StringUtils.getInstance();
this.selectors = new ArrayList<List<String>>(selectorCombinations.size());
this.properties = new HashMap<List<String>, Map<String, String>>();
for (ParseTree selectorCombination : selectorCombinations) {
List<String> currentSelectors = new ArrayList<String>(selectorCombination.getChildCount());
this.selectors.add(currentSelectors);
for (int index = 0; index < selectorCombination.getChildCount(); index++) {
String text = selectorCombination.getChild(index).getText();
currentSelectors.add(text);
}
Map<String, String> block = retrieveProperties(selectorCombination, stringUtils);
this.properties.put(currentSelectors, block);
}
}
示例12: compares_selectors_correctly
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
@Test
public void compares_selectors_correctly() {
String javaInput = "package com.foo.bar;";
Java8Lexer lexer = new Java8Lexer(new ANTLRInputStream(javaInput));
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
ParseTree ast = parser.compilationUnit();
Collection<ParseTree> matches = XPath.findAll(ast, "//';'", parser);
Assert.assertNotNull(matches);
Assert.assertEquals(1, matches.size());
ParseTree semiColon = matches.toArray(new ParseTree[1])[0];
Assert.assertNotNull(semiColon);
matches = XPath.findAll(ast, "//'package'", parser);
Assert.assertNotNull(matches);
Assert.assertEquals(1, matches.size());
ParseTree packageNode = matches.toArray(new ParseTree[1])[0];
Assert.assertNotNull(packageNode);
List<String> selectors = Arrays.asList(".packageDeclaration", "\";\"::before");
SelectorMatchVisitor visitor = new SelectorMatchVisitor(selectors, ast);
Assert.assertTrue(visitor.matches(ast.getChild(0), ".packageDeclaration"));
Assert.assertTrue(visitor.matches(semiColon, "\";\"::before"));
}
示例13: selector_found
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
@Test
public void selector_found(){
String javaInput = "package com.foo.bar;";
String cssInput =
".packageDeclaration \";\"::before {\n"
+ " content: \" \";\n"
+ "}\n";
StringTemplateCSSHelper helper = new StringTemplateCSSHelper(cssInput);
Java8Lexer lexer = new Java8Lexer(new ANTLRInputStream(javaInput));
CommonTokenStream tokens = new CommonTokenStream(lexer);
Java8Parser parser = new Java8Parser(tokens);
ParseTree ast = parser.compilationUnit();
Collection<ParseTree> matches = XPath.findAll(ast, "//';'", parser);
Assert.assertNotNull(matches);
Assert.assertEquals(1, matches.size());
ParseTree semiColon = matches.toArray(new ParseTree[1])[0];
Assert.assertNotNull(semiColon);
matches = XPath.findAll(ast, "//'package'", parser);
Assert.assertNotNull(matches);
Assert.assertEquals(1, matches.size());
ParseTree packageNode = matches.toArray(new ParseTree[1])[0];
Assert.assertNotNull(packageNode);
List<String> selectors = Arrays.asList(".packageDeclaration", "\";\"::before");
Assert.assertTrue(helper.match(selectors, semiColon, ast));
Assert.assertFalse(helper.match(selectors, packageNode, ast));
}
示例14: justTestIt
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
@Test
public void justTestIt() throws Exception {
HqlParser parser = HqlParseTreeBuilder.INSTANCE.parseHql( "select a.b from Something a where a.c = '1'" );
Collection<ParseTree> fromClauses = XPath.findAll( parser.statement(), "//fromClause", parser );
assertEquals( 1, fromClauses.size() );
}
示例15: testIndexAccess
import org.antlr.v4.runtime.tree.xpath.XPath; //导入依赖的package包/类
@Test
public void testIndexAccess() throws Exception {
final String qry = "select o from Order o where o.items[0].id = 1234";
HqlParser parser = HqlParseTreeBuilder.INSTANCE.parseHql( qry );
Collection<ParseTree> fromClauses = XPath.findAll( parser.statement(), "//fromClause", parser );
assertEquals( 1, fromClauses.size() );
}