private static void checkTreeForExceptions(String input, CommonTree tree) { TreeVisitor visitor = new TreeVisitor(); ErrorNodesFinder errorNodesFinder = new ErrorNodesFinder(); visitor.visit(tree, errorNodesFinder); List<ErrorRec> errors = errorNodesFinder.getErrorNodes().stream() .map(node -> new ErrorRec(node, "CommonErrorNode")) .collect(Collectors.toList()); if (!errors.isEmpty()) { throw new JpqlSyntaxException(String.format("Errors found for input jpql:[%s]", StringUtils.strip(input)), errors); } } }
StringBuilder stringBuilder = new StringBuilder(); for (ErrorRec rec : e.getErrorRecs()) { stringBuilder.append(rec.toString()).append("<br>");
String variableName = getVariableName(); if (variableName == null) { invalidNodes.add(new ErrorRec(this, "No variable name found")); return; invalidNodes.add(new ErrorRec(this, "No children found")); return; invalidNodes.add(new ErrorRec(this, "Child 0 is an error node")); return; Pointer pointer = pathNode.resolvePointer(model, variableContext); 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) { variableContext.addEntityVariable(variableName, ((EntityPointer) pointer).getEntity()); variableContext.addEntityVariable(variableName, ((CollectionPointer) pointer).getEntity()); } else { invalidNodes.add(new ErrorRec(this, "Unexpected pointer variable type: " + pointer.getClass()) ); variableContext.addEntityVariable(variableName, model.getEntityByName(child0.getText())); } catch (UnknownEntityNameException e) { invalidNodes.add(new ErrorRec(this, "Could not find entity for name " + child0.getText())
invalidIdVarNodes.add(new ErrorRec(this, "No entity variable name")); return; invalidIdVarNodes.add(new ErrorRec(this, "Null children")); return; invalidIdVarNodes.add(new ErrorRec(this, "Number of children not equals 1")); return; invalidIdVarNodes.add(new ErrorRec(this, "Child 0 is an error node")); return;
@Override public CommonTree treeToQueryPre(QueryBuilder sb, List<ErrorRec> invalidNodes) { int childCount = getChildCount(); if (childCount == 0) { invalidNodes.add(new ErrorRec(this, "No children found")); return null; } sb.appendSpace(); sb.appendString(joinSpec); sb.appendSpace(); sb.appendString(toQuery(getChild(0))); sb.appendSpace(); sb.appendString(variableName); if (childCount > 1) { sb.appendSpace(); sb.appendString("on"); for (int idx = 1; idx < childCount; idx++) { sb.appendSpace(); sb.appendString(toQuery(getChild(idx))); } } return null; }
invalidNodes.add(new ErrorRec((CommonErrorNode) t, "Error node")); return t;