ParsingErrorCheck implements PythonCheck { @Override public void scanFile(PythonVisitorContext context) { RecognitionException parsingException = context.parsingException(); if (parsingException != null) { context.addIssue(new PreciseIssue(this, IssueLocation.atLineLevel(parsingException.getMessage(), parsingException.getLine()))); } }  @Override void scanFile(PythonVisitorContext context);  }
@Test public void test() throws Exception { File file = new File("src/test/resources/checks/parsingError.py"); PythonParser parser = PythonParser.create(); PythonVisitorContext context; try { String fileContent = new String(Files.readAllBytes(file.toPath()), StandardCharsets.UTF_8); parser.parse(fileContent); throw new IllegalStateException("Expected RecognitionException"); } catch (RecognitionException e) { context = new PythonVisitorContext(null, e); } ParsingErrorCheck check = new ParsingErrorCheck(); check.scanFile(context); List<PreciseIssue> issues = context.getIssues(); assertThat(issues).hasSize(1); assertThat(issues.get(0).primaryLocation().startLine()).isEqualTo(1); }