use of org.antlr.runtime.tree.CommonErrorNode in project cuba by cuba-platform.
the class IdVarSelector method pre.
@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;
}
use of org.antlr.runtime.tree.CommonErrorNode in project cuba by cuba-platform.
the class IdVarSelector method post.
@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 instanceof QueryNode) && node.getParent() != null && "T_CONDITION".equals(((CommonTree) node.getParent()).token.getText())) {
stack.peekLast().setPropagateVariablesUp(false);
return t;
}
if (node instanceof IdentificationVariableNode) {
IdentificationVariableNode vnode = (IdentificationVariableNode) node;
vnode.identifyVariableEntity(model, stack, invalidIdVarNodes);
return t;
}
if (node instanceof JoinVariableNode) {
JoinVariableNode vnode = (JoinVariableNode) node;
vnode.identifyVariableEntity(model, stack, invalidIdVarNodes);
return t;
}
return t;
}
use of org.antlr.runtime.tree.CommonErrorNode in project cuba by cuba-platform.
the class TreeToQuery method pre.
@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 || node.getType() == JPA2Lexer.CASE || node.getType() == JPA2Lexer.WHEN || node.getType() == JPA2Lexer.THEN || node.getType() == JPA2Lexer.ELSE || node.getType() == JPA2Lexer.END) {
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;
}
use of org.antlr.runtime.tree.CommonErrorNode in project alfresco-remote-api by Alfresco.
the class RecognizedParamsExtractor method getClause.
/**
* 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);
}
use of org.antlr.runtime.tree.CommonErrorNode in project cuba by cuba-platform.
the class Jpa2GrammarTest method isValid.
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();
}
Aggregations