private static String formatMessage(String formatString, Node node, Object[] args) { if (node.getLocation().isPresent()) { NodeLocation nodeLocation = node.getLocation().get(); return format("line %s:%s: %s", nodeLocation.getLineNumber(), nodeLocation.getColumnNumber(), format(formatString, args)); } return format(formatString, args); } }
public R process(Node node, @Nullable C context) { return node.accept(this, context); }
@Override protected Boolean visitNode(Node node, Void context) { for (Node child : node.getChildren()) { if (process(child, context)) { return true; } } return false; }
//Assume that the member variables in SparseMatrix and Node are fully defined. class SparseMatrix { ArrayList filled_data_ = new ArrayList(); //Constructor, setter (both work) // The problem is that I seem to not be allowed to use the operator[] on // this type of array. int get (int row, int column) { for (int i = 0; i < filled_data_.size(); i++){ Node node = (Node)filled_data.get(i); if (row * max_row + column == node.getLocation()) { return node.getSize(); } } return defualt_value_; }
private static void assertParsed(String input, Node expected, Node parsed) { if (!parsed.equals(expected)) { fail(format("expected\n\n%s\n\nto parse as\n\n%s\n\nbut was\n\n%s\n", indent(input), indent(formatSql(expected, Optional.empty())), indent(formatSql(parsed, Optional.empty())))); } }
private static void assertParsed(String input, Node expected, Node parsed) { if (!parsed.equals(expected)) { fail(format("expected\n\n%s\n\nto parse as\n\n%s\n\nbut was\n\n%s\n", indent(input), indent(formatSql(expected, Optional.empty())), indent(formatSql(parsed, Optional.empty())))); } }
@Nullable private static ErrorLocation getErrorLocation(Throwable throwable) { // TODO: this is a big hack if (throwable instanceof ParsingException) { ParsingException e = (ParsingException) throwable; return new ErrorLocation(e.getLineNumber(), e.getColumnNumber()); } else if (throwable instanceof SemanticException) { SemanticException e = (SemanticException) throwable; if (e.getNode().getLocation().isPresent()) { NodeLocation nodeLocation = e.getNode().getLocation().get(); return new ErrorLocation(nodeLocation.getLineNumber(), nodeLocation.getColumnNumber()); } } return null; }
public R process(Node node, StackableAstVisitorContext<C> context) { context.push(node); try { return node.accept(this, context); } finally { context.pop(); } }
private static void assertParsed(String input, Node expected, Node parsed) { if (!parsed.equals(expected)) { fail(format("expected\n\n%s\n\nto parse as\n\n%s\n\nbut was\n\n%s\n", indent(input), indent(formatSql(expected)), indent(formatSql(parsed)))); } }
private void assertFails(Session session, SemanticErrorCode error, Optional<NodeLocation> location, @Language("SQL") String query) { try { analyze(session, query); fail(format("Expected error %s, but analysis succeeded", error)); } catch (SemanticException e) { if (e.getCode() != error) { fail(format("Expected error %s, but found %s: %s", error, e.getCode(), e.getMessage()), e); } if (location.isPresent()) { NodeLocation expected = location.get(); NodeLocation actual = e.getNode().getLocation().get(); if (expected.getLineNumber() != actual.getLineNumber() || expected.getColumnNumber() != actual.getColumnNumber()) { fail(format( "Expected error '%s' to occur at line %s, offset %s, but was: line %s, offset %s", e.getCode(), expected.getLineNumber(), expected.getColumnNumber(), actual.getLineNumber(), actual.getColumnNumber())); } } } }
public R process(Node node, @Nullable C context) { return node.accept(this, context); }
private static String formatMessage(String formatString, Node node, Object[] args) { if (node.getLocation().isPresent()) { NodeLocation nodeLocation = node.getLocation().get(); return format("line %s:%s: %s", nodeLocation.getLineNumber(), nodeLocation.getColumnNumber(), format(formatString, args)); } return format(formatString, args); } }
public R process(Node node, @Nullable C context) { return node.accept(this, context); }
@Nullable private static ErrorLocation getErrorLocation(Throwable throwable) { // TODO: this is a big hack if (throwable instanceof ParsingException) { ParsingException e = (ParsingException) throwable; return new ErrorLocation(e.getLineNumber(), e.getColumnNumber()); } else if (throwable instanceof SemanticException) { SemanticException e = (SemanticException) throwable; if (e.getNode().getLocation().isPresent()) { NodeLocation nodeLocation = e.getNode().getLocation().get(); return new ErrorLocation(nodeLocation.getLineNumber(), nodeLocation.getColumnNumber()); } } return null; }
public R process(Node node, StackableAstVisitorContext<C> context) { context.push(node); try { return node.accept(this, context); } finally { context.pop(); } }
public R process(Node node, StackableAstVisitorContext<C> context) { context.push(node); try { return node.accept(this, context); } finally { context.pop(); } }