public int getErrorCount() { return diag.getErrorCount(); }
public void appendAllDiags(DiagCollector diagCollector) { diags.addAll(diagCollector.getDiags()); errorCount += diagCollector.getErrorCount(); }
public void appendAllDiags(DiagCollector diagCollector) { diags.addAll(diagCollector.getDiags()); errorCount += diagCollector.getErrorCount(); }
private String normalize(String source, LocationContext location, Element element) { Preconditions.checkNotNull(source, "source should not be null."); Preconditions.checkNotNull(location, "location should not be null."); this.element = element; int errorCount = diagResolver.getDiagCollector().getErrorCount(); SourceParser parser = new SourceParser(source, location, diagResolver, docPath); SourceRoot root = parser.parse(); LocationContext savedLocation = this.location; this.location = location; visit(root); this.location = savedLocation; return diagResolver.getDiagCollector().getErrorCount() > errorCount ? source : builder.toString(); }
@Override public int getErrorCount() { return model.getDiagReporter().getDiagCollector().getErrorCount(); }
@Override public int getErrorCount() { return model.getDiagReporter().getDiagCollector().getErrorCount(); }
private String normalize(String source, LocationContext location, Element element) { Preconditions.checkNotNull(source, "source should not be null."); Preconditions.checkNotNull(location, "location should not be null."); this.element = element; int errorCount = diagResolver.getDiagCollector().getErrorCount(); SourceParser parser = new SourceParser(source, location, diagResolver, docPath); SourceRoot root = parser.parse(); LocationContext savedLocation = this.location; this.location = location; visit(root); this.location = savedLocation; return diagResolver.getDiagCollector().getErrorCount() > errorCount ? source : builder.toString(); }
@Override public Map<String, GeneratedResult<Doc>> generate() { // Establish required stage for generation. model.establishStage(Merged.KEY); if (model.getDiagReporter().getDiagCollector().getErrorCount() > 0) { return null; } List<ViewModel> surfaceDocs = modelToViewTransformer.transform(new ProtoApiModel(model), productConfig); if (model.getDiagReporter().getDiagCollector().getErrorCount() > 0) { return null; } Map<String, GeneratedResult<Doc>> results = new TreeMap<>(); for (ViewModel surfaceDoc : surfaceDocs) { results.putAll(snippetSetRunner.generate(surfaceDoc)); } return results; }
@Test public void loadDefaultLicenseLines() throws IOException { String actualLicenseFilePath = String.format("src/main/resources/com/google/api/codegen/%s", DEFAULT_LICENSE_FILE); BufferedReader actualLicenseReader = new BufferedReader(new FileReader(actualLicenseFilePath)); String firstLicenseLine = actualLicenseReader.readLine(); List<String> defaultLicenseLines = defaultHeaderUtil.loadLicenseLines(); List<String> explicitLicenseLines = explicitHeaderUtil.loadLicenseLines(); assertThat(explicitLicenseLines).isEqualTo(defaultLicenseLines); assertThat(firstLicenseLine).isEqualTo(defaultLicenseLines.get(0)); assertThat(defaultHeaderUtil.getDiagCollector().getErrorCount()).isEqualTo(0); assertThat(explicitHeaderUtil.getDiagCollector().getErrorCount()).isEqualTo(0); }
@Test public void loadDefaultCopyrightLines() throws IOException { String actualCopyrightFilePath = String.format("src/main/resources/com/google/api/codegen/%s", DEFAULT_COPYRIGHT_FILE); BufferedReader actualCopyrightReader = new BufferedReader(new FileReader(actualCopyrightFilePath)); String firstCopyrightLine = actualCopyrightReader.readLine(); List<String> defaultCopyrightLines = defaultHeaderUtil.loadCopyrightLines(); List<String> explicitCopyrightLines = explicitHeaderUtil.loadCopyrightLines(); assertThat(explicitCopyrightLines).isEqualTo(defaultCopyrightLines); assertThat(firstCopyrightLine).isEqualTo(defaultCopyrightLines.get(0)); assertThat(defaultHeaderUtil.getDiagCollector().getErrorCount()).isEqualTo(0); assertThat(explicitHeaderUtil.getDiagCollector().getErrorCount()).isEqualTo(0); }
@Override public boolean run(Model model) { int oldErrorCount = model.getDiagReporter().getDiagCollector().getErrorCount(); SymbolTable symbolTable = new SymbolTableBuilder(model).run(); model.setSymbolTable(symbolTable); new ReferenceResolver(model, symbolTable).run(); if (oldErrorCount == model.getDiagReporter().getDiagCollector().getErrorCount()) { // No new errors produced -- success. model.putAttribute(Resolved.KEY, new Resolved()); return true; } return false; } }
@Override public boolean run(Model model) { int oldErrorCount = model.getDiagReporter().getDiagCollector().getErrorCount(); SymbolTable symbolTable = new SymbolTableBuilder(model).run(); model.setSymbolTable(symbolTable); new ReferenceResolver(model, symbolTable).run(); if (oldErrorCount == model.getDiagReporter().getDiagCollector().getErrorCount()) { // No new errors produced -- success. model.putAttribute(Resolved.KEY, new Resolved()); return true; } return false; } }
private ConfigSource loadConfigFromFiles(List<String> configFileNames) { List<File> configFiles = pathsToFiles(configFileNames); if (model.getDiagReporter().getDiagCollector().getErrorCount() > 0) { return null; } ImmutableMap<String, Message> supportedConfigTypes = ImmutableMap.of( ConfigProto.getDescriptor().getFullName(), ConfigProto.getDefaultInstance()); return MultiYamlReader.read( model.getDiagReporter().getDiagCollector(), configFiles, supportedConfigTypes); }
@Override protected void process() throws Exception { model.establishStage(Merged.KEY); if (model.getDiagReporter().getDiagCollector().getErrorCount() > 0) { for (Diag diag : model.getDiagReporter().getDiagCollector().getDiags()) { System.err.println(diag.toString()); } return; } String outputPath = options.get(OUTPUT_FILE); Map<String, String> outputFiles = generateConfig(outputPath); ToolUtil.writeFiles(outputFiles, ""); }
private void expectError(String message) { if (diagReporter.getDiagCollector().getErrorCount() == 0) { Truth.assertWithMessage("No error found.").fail("Expected error message %s", message); } else if (diagReporter.getDiagCollector().getErrorCount() > 1) { Truth.assert_().fail("Found more than one error: \n%s", NEWLINE_JOINER.join(getErrors())); } else { Truth.assertThat(Iterables.getOnlyElement(getErrors()).toString()).isEqualTo(message); } }
@Override protected void process() throws Exception { model.establishStage(Merged.KEY); if (model.getDiagReporter().getDiagCollector().getErrorCount() > 0) { for (Diag diag : model.getDiagReporter().getDiagCollector().getDiags()) { System.err.println(diag.toString()); } return; } Map<String, GeneratedResult<Doc>> results = generate(model); ToolUtil.writeFiles(GeneratedResult.extractBodies(results), options.get(OUTPUT_DIR)); }
@Test public void testCreateLROWithNonLROMethod() { DiagCollector diagCollector = new BoundedDiagCollector(); LongRunningConfig longRunningConfig = LongRunningConfig.createLongRunningConfig( simpleMethod, diagCollector, LongRunningConfigProto.getDefaultInstance(), protoParser); assertThat(diagCollector.getErrorCount()).isEqualTo(0); assertThat(longRunningConfig).isNull(); } }
@Override public boolean run(final Model model) { int oldErrorCount = model.getDiagReporter().getDiagCollector().getErrorCount(); for (ConfigAspect aspect : model.getConfigAspects()) { aspect.startLinting(); } new Visitor(model.getScoper()) { @VisitsBefore void validate(ProtoElement element) { for (ConfigAspect aspect : model.getConfigAspects()) { aspect.lint(element); } } }.visit(model); for (ConfigAspect aspect : model.getConfigAspects()) { aspect.endLinting(); } if (oldErrorCount == model.getDiagReporter().getDiagCollector().getErrorCount()) { // No new errors produced -- success. model.putAttribute(Linted.KEY, new Linted()); return true; } return false; } }
/** * Asserts if filtered result equals expected string. Asserts failure if there are errors detected * during the filtering. */ private void assertResult(String expected, String result) { if (diagReporter.getDiagCollector().getErrorCount() > 0) { Truth.assertWithMessage("Errors detected while filtering comment") .fail(NEWLINE_JOINER.join(diagReporter.getDiagCollector().getDiags())); } else { Truth.assertThat(result).isEqualTo(expected); } }
@Test public void testLanguageSettingsOverride() { try { langOverrideHeaderUtil.loadLicenseLines(); } catch (RuntimeException e) { // This is supposed to happen because IMAGINARY_FILE doesn't exist. assertThat(langOverrideHeaderUtil.getDiagCollector().getErrorCount()).isGreaterThan(0); return; } fail(); } }