本文整理汇总了Java中org.antlr.runtime.tree.CommonErrorNode类的典型用法代码示例。如果您正苦于以下问题:Java CommonErrorNode类的具体用法?Java CommonErrorNode怎么用?Java CommonErrorNode使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CommonErrorNode类属于org.antlr.runtime.tree包,在下文中一共展示了CommonErrorNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: pre
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
@Override
public Object pre(Object t) {
if (!(t instanceof CommonTree))
return t;
if (t instanceof CommonErrorNode) {
return t;
}
CommonTree node = (CommonTree) t;
if (node instanceof QueryNode) {
QueryVariableContext newCurrent = new QueryVariableContext(model, (QueryNode) node);
if (root == null) {
root = newCurrent;
}
QueryVariableContext last = stack.peekLast();
if (last != null) {
last.addChild(newCurrent);
}
stack.addLast(newCurrent);
}
return t;
}
示例2: getTheSonOf
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
private String getTheSonOf(Object... params) {
String sonsStr = "";
String sep = "";
for(Object son : params) {
String paramTxt = "";
if (son instanceof CommonErrorNode) {
paramTxt = ((CommonErrorNode) son).getText();
} else if (son instanceof CommonTree) {
CommonTree cTree = ((CommonTree)son);
paramTxt = ((CommonTree) son).getText();
if (paramTxt.equals("Number") || paramTxt.equals("MAType") || paramTxt.equals("String")) {
paramTxt = cTree.getChild(0).getText();
} else if (paramTxt.equals("StockOperation")) {
paramTxt = cTree.getChild(0).getChild(0).getText();
} else {
paramTxt = cTree.getText() + ((cTree.getChildren()!= null)?"("+getTheSonOf(cTree.getChildren().toArray(new Object[] {}))+")":"");
}
}
sonsStr = sonsStr + sep + paramTxt;
sep = ",";
}
return sonsStr;
}
示例3: whereIsThatSonOf
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
private int[] whereIsThatSonOf(Object son) {
int[] location = new int[2];
if (son instanceof CommonToken) {
location[0] = ((CommonToken) son).getLine();
location[1] = ((CommonToken) son).getCharPositionInLine();
} else if (son instanceof CommonErrorNode) {
location[0] = ((CommonErrorNode) son).start.getLine();
location[1] = ((CommonErrorNode) son).start.getCharPositionInLine();
} else if (son instanceof CommonTree) {
CommonTree cTree = ((CommonTree)son);
if (cTree.getText().equals("Number") || cTree.getText().equals("MAType") || cTree.getText().equals("String") ) {
location[0] = cTree.getChild(0).getLine();
location[1] = cTree.getChild(0).getCharPositionInLine();
} else if (cTree.getText().equals("StockOperation")) {
location[0] = cTree.getChild(0).getChild(0).getLine();
location[1] = cTree.getChild(0).getChild(0).getCharPositionInLine();
} else {
location[0] = cTree.getLine();
location[1] = cTree.getCharPositionInLine();
}
}
return location;
}
示例4: getWhereClause
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
/**
* Takes the "where" parameter and turns it into a Java Object that can be used for querying
*
* @param whereParam String
* @return Query a parsed version of the where clause, represented in Java
*/
default Query getWhereClause(String whereParam) throws InvalidQueryException
{
if (whereParam == null)
return QueryImpl.EMPTY;
try
{
CommonTree whereTree = WhereCompiler.compileWhereClause(whereParam);
if (whereTree instanceof CommonErrorNode)
{
rpeLogger().debug("Error parsing the WHERE clause " + whereTree);
throw new InvalidQueryException(whereTree);
}
return new QueryImpl(whereTree);
}
catch (RewriteCardinalityException re)
{ //Catch any error so it doesn't get thrown up the stack
rpeLogger().info("Unhandled Error parsing the WHERE clause: " + re);
}
catch (RecognitionException e)
{
whereParam += ", " + WhereCompiler.resolveMessage(e);
rpeLogger().info("Error parsing the WHERE clause: " + whereParam);
}
//Default to throw out an invalid query
throw new InvalidQueryException(whereParam);
}
示例5: pre
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
@Override
public Object pre(Object t) {
if (t instanceof CommonErrorNode) {
errorNodes.add((CommonErrorNode) t);
return t;
}
return t;
}
示例6: post
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
@Override
public Object post(Object t) {
if (!(t instanceof CommonTree))
return t;
if (t instanceof CommonErrorNode) {
return t;
}
CommonTree node = (CommonTree) t;
if (node.token == null)
return t;
if (node.getType() == JPA2Lexer.DISTINCT ||
node.getType() == JPA2Lexer.FETCH ||
node.parent != null && node.parent.getType() == JPA2Lexer.T_SELECTED_ITEM && node.getType() == JPA2Lexer.AS) {
sb.appendSpace();
}
if (node instanceof TreeToQueryCapable) {
return ((TreeToQueryCapable) t).treeToQueryPost(sb, invalidNodes);
}
return t;
}
示例7: isValid
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
protected boolean isValid(CommonTree tree) {
TreeVisitor visitor = new TreeVisitor();
ErrorNodesFinder errorNodesFinder = new ErrorNodesFinder();
visitor.visit(tree, errorNodesFinder);
List<CommonErrorNode> errorNodes = errorNodesFinder.getErrorNodes();
if (!errorNodes.isEmpty()) {
System.err.println(errorNodes);
}
return errorNodes.isEmpty();
}
示例8: setErrorNode
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
/** Changes this tree node into an error node. */
void setErrorNode(Token start, Token stop, RecognitionException e) {
this.delegate = new CommonErrorNode(this.tokenStream, start, stop, e);
}
示例9: getDelegate
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
private CommonErrorNode getDelegate() {
return this.delegate;
}
示例10: getClause
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
/**
* Gets the clause specificed in paramName
*
* @param param
* @param paramName
* @return bean property names potentially using JSON Pointer syntax
*/
default List<String> getClause(String param, String paramName)
{
if (param == null)
return Collections.emptyList();
try
{
CommonTree selectedPropsTree = WhereCompiler.compileSelectClause(param);
if (selectedPropsTree instanceof CommonErrorNode)
{
rpeLogger().debug("Error parsing the " + paramName + " clause " + selectedPropsTree);
throw new InvalidSelectException(paramName, selectedPropsTree);
}
if (selectedPropsTree.getChildCount() == 0 && !selectedPropsTree.getText().isEmpty())
{
return Arrays.asList(selectedPropsTree.getText());
}
List<Tree> children = (List<Tree>) selectedPropsTree.getChildren();
if (children != null && !children.isEmpty())
{
List<String> properties = new ArrayList<String>(children.size());
for (Tree child : children)
{
properties.add(child.getText());
}
return properties;
}
}
catch (RewriteCardinalityException re)
{
//Catch any error so it doesn't get thrown up the stack
rpeLogger().debug("Unhandled Error parsing the " + paramName + " clause: " + re);
}
catch (RecognitionException e)
{
rpeLogger().debug("Error parsing the \"+paramName+\" clause: " + param);
}
catch (InvalidQueryException iqe)
{
throw new InvalidSelectException(paramName, iqe.getQueryParam());
}
//Default to throw out an invalid query
throw new InvalidSelectException(paramName, param);
}
示例11: GrammarASTErrorNode
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
public GrammarASTErrorNode(TokenStream input, Token start, Token stop,
org.antlr.runtime.RecognitionException e)
{
delegate = new CommonErrorNode(input,start,stop,e);
}
示例12: identifyVariableEntity
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
public void identifyVariableEntity(DomainModel model,
Deque<QueryVariableContext> stack,
List<ErrorRec> invalidNodes) {
String variableName = getVariableName();
if (variableName == null) {
invalidNodes.add(new ErrorRec(this, "No variable name found"));
return;
}
List children = getChildren();
if (children == null || children.size() == 0) {
invalidNodes.add(new ErrorRec(this, "No children found"));
return;
}
CommonTree child0 = (CommonTree) children.get(0);
if (child0 instanceof CommonErrorNode) {
invalidNodes.add(new ErrorRec(this, "Child 0 is an error node"));
return;
}
QueryVariableContext queryVC = stack.peekLast();
if (child0 instanceof PathNode) {
PathNode pathNode = (PathNode) child0;
Pointer pointer = pathNode.resolvePointer(model, queryVC);
if (pointer instanceof NoPointer) {
invalidNodes.add(new ErrorRec(this, "Cannot resolve joined entity"));
} else if (pointer instanceof SimpleAttributePointer) {
invalidNodes.add(new ErrorRec(this, "Joined entity resolved to a non-entity attribute"));
} else if (pointer instanceof EntityPointer) {
queryVC.addEntityVariable(variableName, ((EntityPointer) pointer).getEntity());
} else if (pointer instanceof CollectionPointer) {
queryVC.addEntityVariable(variableName, ((CollectionPointer) pointer).getEntity());
} else {
invalidNodes.add(new ErrorRec(this,
"Unexpected pointer variable type: " + pointer.getClass())
);
}
} else {//this special case is for "join X on X.a = Y.b" query. Entity name would be just text in the child node
try {
queryVC.addEntityVariable(variableName, model.getEntityByName(child0.getText()));
} catch (UnknownEntityNameException e) {
invalidNodes.add(new ErrorRec(this,
"Could not find entity for name " + child0.getText())
);
}
}
}
示例13: getErrorNodes
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
public List<CommonErrorNode> getErrorNodes() {
return Collections.unmodifiableList(errorNodes);
}
示例14: pre
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
@Override
public Object pre(Object t) {
if (!(t instanceof CommonTree)) {
return t;
}
if (t instanceof CommonErrorNode) {
invalidNodes.add(new ErrorRec((CommonErrorNode) t, "Error node"));
return t;
}
CommonTree node = (CommonTree) t;
if (node.token == null)
return t;
if (node.getType() == JPA2Lexer.HAVING ||
node.parent != null && node.parent.getType() == JPA2Lexer.T_SIMPLE_CONDITION
&& !parentNodeHasPreviousLparen(node) ||
node.parent != null && node.parent.getType() == JPA2Lexer.T_GROUP_BY ||
node.parent != null && node.parent.getType() == JPA2Lexer.T_ORDER_BY && node.getType() != JPA2Lexer.T_ORDER_BY_FIELD ||
node.parent != null && node.parent.getType() == JPA2Lexer.T_CONDITION && node.getType() == JPA2Lexer.LPAREN && (node.childIndex == 0 || node.parent.getChild(node.childIndex - 1).getType() != JPA2Lexer.LPAREN) ||
node.getType() == JPA2Lexer.AND ||
node.parent != null && node.parent.getType() == JPA2Lexer.T_ORDER_BY_FIELD ||
node.parent != null && node.parent.getType() == JPA2Lexer.T_SELECTED_ITEM && node.getType() == JPA2Lexer.AS ||
node.getType() == JPA2Lexer.OR ||
node.getType() == JPA2Lexer.NOT ||
node.getType() == JPA2Lexer.DISTINCT && node.childIndex == 0 ||
node.getType() == JPA2Lexer.JOIN ||
node.getType() == JPA2Lexer.LEFT ||
node.getType() == JPA2Lexer.OUTER ||
node.getType() == JPA2Lexer.INNER ||
node.getType() == JPA2Lexer.FETCH
) {
sb.appendSpace();
}
if (node.getType() == JPA2Lexer.T_ORDER_BY_FIELD && node.childIndex > 0 && node.parent.getChild(node.childIndex - 1).getType() == JPA2Lexer.T_ORDER_BY_FIELD) {
sb.appendString(", ");
}
if (isGroupByItem(node)) {
if (node.childIndex > 0 && isGroupByItem((CommonTree) node.parent.getChild(node.childIndex - 1))) {
sb.appendString(", ");
}
}
if (node instanceof TreeToQueryCapable) {
return ((TreeToQueryCapable) t).treeToQueryPre(sb, invalidNodes);
}
if (node.getType() == JPA2Lexer.T_SELECTED_ITEMS) {
return t;
}
if (node.getType() == JPA2Lexer.T_SOURCES) {
sb.appendString("from ");
return t;
}
sb.appendString(node.toString());
return t;
}
示例15: ASTErrorNode
import org.antlr.runtime.tree.CommonErrorNode; //导入依赖的package包/类
public ASTErrorNode(TokenStream input, Token start, Token stop,
RecognitionException e) {
delegate = new CommonErrorNode(input, start, stop, e);
}