本文整理汇总了Java中org.antlr.v4.runtime.tree.TerminalNodeImpl类的典型用法代码示例。如果您正苦于以下问题:Java TerminalNodeImpl类的具体用法?Java TerminalNodeImpl怎么用?Java TerminalNodeImpl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
TerminalNodeImpl类属于org.antlr.v4.runtime.tree包,在下文中一共展示了TerminalNodeImpl类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: enterPattern_matcher
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
@Override
public void enterPattern_matcher(SQLParser.Pattern_matcherContext ctx) {
super.enterPattern_matcher(ctx);
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof TerminalNodeImpl) {
if (isNot(child.getText())) {
currentPredicate.negate();
}
break;
}
}
if (currentPredicate.isNegated()) {
currentPredicate.setOperator("not like");
} else {
currentPredicate.setOperator("like");
}
skipNextTerminal = true;
}
示例2: cloneExprContext
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
/**
* Cloning expression to create new same expression.
*/
public static ExprContext cloneExprContext(final ExprContext expr) {
final ExprContext clone = createContextType(expr);
clone.copyFrom(expr);
for (final ParseTree child : expr.children) {
if (child instanceof TerminalNode) {
clone.addChild(new TerminalNodeImpl(((TerminalNode) child).getSymbol()));
} else if (child instanceof ExprContext) {
final ExprContext cloneChild = cloneExprContext((ExprContext) child);
clone.addChild(cloneChild);
setLeftRight(clone, cloneChild);
} else if (child instanceof Token) {
clone.addChild(new CommonToken((Token) child));
}
}
return clone;
}
示例3: createConjunctionContext
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
/**
* Creating conjunction expression.
*/
public static ConjunctionContext createConjunctionContext(final ExprContext leftContext,
final ExprContext rightContext) {
final ConjunctionContext conjunctionContext = new ConjunctionContext(new ExprContext());
final TerminalNodeImpl andNode = new TerminalNodeImpl(new CommonToken(10, "and"));
// Setting context parents.
leftContext.parent = conjunctionContext;
andNode.parent = conjunctionContext;
rightContext.parent = conjunctionContext;
conjunctionContext.left = leftContext;
conjunctionContext.right = rightContext;
// Adding conjunction expression's children.
conjunctionContext.addChild(leftContext);
conjunctionContext.addChild(andNode);
conjunctionContext.addChild(rightContext);
return conjunctionContext;
}
示例4: createDisjunctionContext
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
/**
* Creating disjunction expression.
*/
public static DisjunctionContext createDisjunctionContext(final ExprContext leftContext,
final ExprContext rightContext) {
final DisjunctionContext disjunctionContext = new DisjunctionContext(new ExprContext());
final TerminalNodeImpl orNode = new TerminalNodeImpl(new CommonToken(12, "or"));
// Setting context parents.
leftContext.parent = disjunctionContext;
rightContext.parent = disjunctionContext;
orNode.parent = disjunctionContext;
disjunctionContext.left = leftContext;
disjunctionContext.right = rightContext;
// Adding disjunction expression's children.
disjunctionContext.addChild(leftContext);
disjunctionContext.addChild(orNode);
disjunctionContext.addChild(rightContext);
return disjunctionContext;
}
示例5: createNegationContext
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
/**
* Creating negation expression.
*/
public static NegationContext createNegationContext(final ExprContext expr) {
final NegationContext negationContext = new NegationContext(new ExprContext());
final TerminalNodeImpl notNode = new TerminalNodeImpl(new CommonToken(FOLParser.NOT, "not"));
// Setting context parents.
notNode.parent = negationContext;
expr.parent = negationContext;
// Adding negation expression's children.
negationContext.addChild(notNode);
negationContext.addChild(expr);
return negationContext;
}
示例6: createParenthesesContext
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
/**
* Creating parentheses expression.
*/
public static ParenthesesContext createParenthesesContext(final ExprContext expr) {
final ParenthesesContext parenthesesContext = new ParenthesesContext(new ExprContext());
final TerminalNodeImpl leftParenthes = new TerminalNodeImpl(new CommonToken(FOLParser.LP, "("));
final TerminalNodeImpl rightParenthes =
new TerminalNodeImpl(new CommonToken(FOLParser.RP, ")"));
// Setting context parents.
leftParenthes.parent = parenthesesContext;
rightParenthes.parent = parenthesesContext;
expr.parent = parenthesesContext;
// Adding parentheses expression's children.
parenthesesContext.addChild(leftParenthes);
parenthesesContext.addChild(expr);
parenthesesContext.addChild(rightParenthes);
return parenthesesContext;
}
示例7: getChildContextText
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
/**
* Searches the children of the given context for a context of the given clazz
* type and returns its Text Value. If there are multiple relevant child nodes,
* we will return the text value for one of them at random.
*/
public String getChildContextText(RuleContext ctx) {
if (ctx == null) {
return "";
}
if (ctx instanceof TypeNameContext) {
return ctx.getText();
}
String s = "";
for (int i = 0; i < ctx.getChildCount(); i++) {
if (!(ctx.getChild(i) instanceof TerminalNodeImpl)) {
try {
String t = getChildContextText((RuleContext) ctx.getChild(i));
if (!t.isEmpty()) {
s += t + ",";
}
} catch (Exception e) {
// do nothing
}
}
}
return s.replaceAll(",$", "");
}
示例8: testCheckEndingWIthSemicolon2
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
@Test
public void testCheckEndingWIthSemicolon2() {
Rule r = new Rule();
RuleImplementation rImpl = new RuleImplementation();
rImpl.getNames().getTextItem().add(Select_statementContext.class.getSimpleName());
rImpl.setRuleMatchType(RuleMatchType.CLASS_ONLY);
r.setRuleImplementation(rImpl);
RuleImplementation child = new RuleImplementation();
child.setDistance(1);
child.setIndex(-1);
child.setDistanceCheckType(RuleDistanceIndexMatchType.EQUALS);
child.setIndexCheckType(RuleDistanceIndexMatchType.EQUALS);
child.getTextToFind().getTextItem().add(";");
child.setTextCheckType(TextCheckType.STRICT);
child.setRuleMatchType(RuleMatchType.CLASS_ONLY);
child.setRuleResultType(RuleResultType.FAIL_IF_NOT_FOUND);
child.getNames().getTextItem().add(TerminalNodeImpl.class.getSimpleName());
rImpl.getChildrenRules().getRuleImplementation().add(child);
String s = "SELECT * from dbo.test where name like '%test%'";
TsqlIssue[] issues = Antlr4Utils.verify2(r, s);
Assert.assertEquals(1, issues.length);
}
示例9: fromAntlrNode
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
public static TypeRef fromAntlrNode(Java8Parser.UnannArrayTypeContext antlrNode) {
if (antlrNode.unannPrimitiveType() != null){
long nDims = antlrNode.dims().children.stream().filter((c)->c instanceof TerminalNodeImpl).map((c) -> (TerminalNodeImpl)c)
.filter((c)->c.getText().equals("[")).count();
// TODO consider annotations
// TODO consider multiple dimensions
if (antlrNode.dims().annotation() != null && !antlrNode.dims().annotation().isEmpty()){
throw new UnsupportedOperationException();
}
return fromAntlrNode(PrimitiveTypeRef.fromAntlrNode(antlrNode.unannPrimitiveType()), nDims);
} else {
throw new UnsupportedOperationException();
}
}
示例10: verifyInitializerBraceStyle
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
private void verifyInitializerBraceStyle(SwiftParser.InitializerDeclarationContext ctx) {
// Check if there is an element between the parameter clause and open brace (i.e. 'throws' or 'rethrows')
// (Issue #405)
ParseTree leftSibling = ParseTreeUtil.getLeftSibling(ctx.initializerBody());
if (leftSibling instanceof TerminalNodeImpl) {
verifyCodeBlockOpenBraceStyle(
ctx.initializerBody().codeBlock(),
((TerminalNodeImpl) leftSibling).getSymbol(),
Messages.INITIALIZER_BODY);
} else {
verifyCodeBlockOpenBraceStyle(ctx.initializerBody().codeBlock(), ctx.parameterClause().getStop(),
Messages.INITIALIZER_BODY);
}
verifyBodyCloseBraceStyle(ctx.initializerBody().codeBlock(), Messages.INITIALIZER_BODY);
}
示例11: verifyEnumBraceStyle
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
private void verifyEnumBraceStyle(ParserRuleContext ctx) {
for (ParseTree child : ctx.children) {
if (child instanceof TerminalNodeImpl && child.getText().equals("{")) {
Token openBrace = ((TerminalNodeImpl) child).getSymbol();
Location openBraceLocation = ListenerUtil.getTokenLocation(openBrace);
ParserRuleContext leftSibling = (ParserRuleContext) ParseTreeUtil.getLeftSibling(child);
Location leftSiblingLocation = ListenerUtil.getContextStopLocation(leftSibling);
if (openBraceLocation.line != leftSiblingLocation.line) {
printer.warn(Rules.BRACE_STYLE, Messages.ENUM + Messages.OPEN_BRACE_STYLE, openBraceLocation);
} else if (checkLeftSpaces(leftSibling.getStop(), openBrace, 1)) {
printer.error(Rules.BRACE_STYLE, Messages.OPEN_BRACE + Messages.SPACE_BEFORE, openBraceLocation);
}
break;
}
}
ParseTree lastChild = ParseTreeUtil.getLastChild(ctx);
verifyCloseBraceStyle(lastChild, ParseTreeUtil.getLeftSibling(lastChild), Messages.ENUM);
}
示例12: verifyCloseBraceStyle
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
private void verifyCloseBraceStyle(ParseTree closeBrace, ParseTree closeBraceLeftSibling, String constructName) {
Token closeBraceToken = ((TerminalNodeImpl)closeBrace).getSymbol();
Location closeBraceLocation = ListenerUtil.getTokenLocation(closeBraceToken);
if (commentLeftOfCloseBrace(closeBraceToken)) {
this.printer.warn(Rules.BRACE_STYLE, constructName + Messages.CLOSE_BRACE_STYLE, closeBraceLocation);
return;
}
Location closeBraceLeftSiblingLocation = ListenerUtil.getParseTreeStopLocation(closeBraceLeftSibling);
if (closeBraceLocation.line == closeBraceLeftSiblingLocation.line) {
if (!closeBraceLeftSibling.getText().equals("{")) {
this.printer.warn(Rules.BRACE_STYLE, constructName + Messages.CLOSE_BRACE_STYLE, closeBraceLocation);
} else if (closeBraceLocation.column - closeBraceLeftSiblingLocation.column != 1) {
this.printer.warn(Rules.BRACE_STYLE, Messages.EMPTY_BODY, closeBraceLeftSiblingLocation);
}
}
}
示例13: verifyClosureCloseBraceStyle
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
private void verifyClosureCloseBraceStyle(SwiftParser.ClosureExpressionContext ctx) {
ParseTree closeBrace = ParseTreeUtil.getLastChild(ctx);
Token closeBraceToken = ((TerminalNodeImpl) closeBrace).getSymbol();
Location closeBraceLocation = ListenerUtil.getTokenLocation(closeBraceToken);
Location openBraceLocation = ListenerUtil.getLocationOfChildToken(ctx, 0);
if (openBraceLocation.line != closeBraceLocation.line && commentLeftOfCloseBrace(closeBraceToken)) {
this.printer.warn(Rules.BRACE_STYLE, Messages.CLOSURE + Messages.CLOSE_BRACE_STYLE, closeBraceLocation);
return;
}
Location leftSiblingLocation = ListenerUtil.getParseTreeStopLocation(ParseTreeUtil.getLeftSibling(closeBrace));
if (leftSiblingLocation.line == closeBraceLocation.line && openBraceLocation.line != closeBraceLocation.line) {
this.printer.warn(Rules.BRACE_STYLE, Messages.CLOSURE + Messages.CLOSE_BRACE_STYLE, closeBraceLocation);
}
}
示例14: removeCallSeparator
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
/**
* Remove the separator (,) between arguments.
*
* @param file Source file to edit.
* @param context ExpressionList context.
* @param index Parameter index of the argument ("a", "b") "a" = 0, "b" = 1
*/
private void removeCallSeparator(SourceFile file,
ExpressionListContext context, int index) {
ParseTree item = null;
// Remove separator after argument.
if (index == 0 && context.getChildCount() >= index + 1) {
item = context.getChild(index + 1);
} else if (context.getChildCount() >= index - 1) {
item = context.getChild(index - 1);
}
if (item instanceof TerminalNodeImpl &&
item.getText().equals(",")) {
file.getRewriter().delete(((TerminalNodeImpl)item).getPayload());
}
}
示例15: enterIn_predicate
import org.antlr.v4.runtime.tree.TerminalNodeImpl; //导入依赖的package包/类
@Override
public void enterIn_predicate(SQLParser.In_predicateContext ctx) {
super.enterIn_predicate(ctx);
enterInClause();
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree child = ctx.getChild(i);
if (child instanceof TerminalNodeImpl) {
if (isNot(child.getText())) {
currentPredicate.negate();
}
break;
}
}
currentPredicate.inOperator();
}