private static boolean hasErrors(Symbol root, Symbol[] symbols, Set<Symbol> visited) { if(null != symbols) { for(Symbol s: symbols) { if (s == root) { continue; } if (hasErrors(s, visited)) { return true; } } } return false; }
private static boolean hasErrors(Symbol root, Symbol[] symbols) { if(null != symbols) { for(Symbol s: symbols) { if (s == root) { continue; } if (hasErrors(s)) { return true; } } } return false; }
/** * Returns true if the Parser contains any Error symbol, indicating that it may fail * for some inputs. */ public static boolean hasErrors(Symbol symbol) { return hasErrors(symbol, new HashSet<Symbol>()); }
/** * Returns true if the Parser contains any Error symbol, indicating that it may fail * for some inputs. */ public static boolean hasErrors(Symbol symbol) { switch(symbol.kind) { case ALTERNATIVE: return hasErrors(symbol, ((Alternative) symbol).symbols); case EXPLICIT_ACTION: return false; case IMPLICIT_ACTION: if (symbol instanceof ErrorAction) { return true; } if (symbol instanceof UnionAdjustAction) { return hasErrors(((UnionAdjustAction) symbol).symToParse); } return false; case REPEATER: Repeater r = (Repeater) symbol; return hasErrors(r.end) || hasErrors(symbol, r.production); case ROOT: case SEQUENCE: return hasErrors(symbol, symbol.production); case TERMINAL: return false; default: throw new RuntimeException("unknown symbol kind: " + symbol.kind); } }
return hasErrors(symbol, ((Alternative) symbol).symbols, visited); case EXPLICIT_ACTION: return false; return hasErrors(((UnionAdjustAction) symbol).symToParse, visited); case REPEATER: Repeater r = (Repeater) symbol; return hasErrors(r.end, visited) || hasErrors(symbol, r.production, visited); case ROOT: case SEQUENCE: return hasErrors(symbol, symbol.production, visited); case TERMINAL: return false;
/** * Validates that data written with one schema can be read using another, * based on the default Avro schema resolution rules. * * @param writtenWith * The "writer's" schema, representing data to be read. * @param readUsing * The "reader's" schema, representing how the reader will interpret * data. * @throws SchemaValidationException * if the schema <b>readUsing<b/> cannot be used to read data * written with <b>writtenWith<b/> */ static void canRead(Schema writtenWith, Schema readUsing) throws SchemaValidationException { boolean error; try { error = Symbol.hasErrors(new ResolvingGrammarGenerator().generate( writtenWith, readUsing)); } catch (IOException e) { throw new SchemaValidationException(readUsing, writtenWith, e); } if (error) { throw new SchemaValidationException(readUsing, writtenWith); } }
/** * Validates that data written with one schema can be read using another, * based on the default Avro schema resolution rules. * * @param writtenWith * The "writer's" schema, representing data to be read. * @param readUsing * The "reader's" schema, representing how the reader will interpret * data. * @throws SchemaValidationException * if the schema <b>readUsing<b/> cannot be used to read data * written with <b>writtenWith<b/> */ static void canRead(Schema writtenWith, Schema readUsing) throws SchemaValidationException { boolean error; try { error = Symbol.hasErrors(new ResolvingGrammarGenerator().generate( writtenWith, readUsing)); } catch (IOException e) { throw new SchemaValidationException(readUsing, writtenWith, e); } if (error) { throw new SchemaValidationException(readUsing, writtenWith); } }
private static boolean hasErrors(Symbol root, Symbol[] symbols) { if(null != symbols) { for(Symbol s: symbols) { if (s == root) { continue; } if (hasErrors(s)) { return true; } } } return false; }
/** * Returns true if the Parser contains any Error symbol, indicating that it may fail * for some inputs. */ public static boolean hasErrors(Symbol symbol) { switch(symbol.kind) { case ALTERNATIVE: return hasErrors(symbol, ((Alternative) symbol).symbols); case EXPLICIT_ACTION: return false; case IMPLICIT_ACTION: if (symbol instanceof ErrorAction) { return true; } if (symbol instanceof UnionAdjustAction) { return hasErrors(((UnionAdjustAction) symbol).symToParse); } return false; case REPEATER: Repeater r = (Repeater) symbol; return hasErrors(r.end) || hasErrors(symbol, r.production); case ROOT: case SEQUENCE: return hasErrors(symbol, symbol.production); case TERMINAL: return false; default: throw new RuntimeException("unknown symbol kind: " + symbol.kind); } }
/** * Validates that data written with one schema can be read using another, * based on the default Avro schema resolution rules. * * @param writtenWith * The "writer's" schema, representing data to be read. * @param readUsing * The "reader's" schema, representing how the reader will interpret * data. * @throws SchemaValidationException * if the schema <b>readUsing<b/> cannot be used to read data * written with <b>writtenWith<b/> */ static void canRead(Schema writtenWith, Schema readUsing) throws SchemaValidationException { boolean error; try { error = Symbol.hasErrors(new ResolvingGrammarGenerator().generate( writtenWith, readUsing)); } catch (IOException e) { throw new SchemaValidationException(readUsing, writtenWith, e); } if (error) { throw new SchemaValidationException(readUsing, writtenWith); } }