@Test public void should_report_analysis_error_in_sonarLint_context_withSQ_6_0() throws Exception { JavaAstScanner scanner = defaultJavaAstScanner(); FakeAuditListener listener = spy(new FakeAuditListener()); SonarComponents sonarComponents = mock(SonarComponents.class); when(sonarComponents.reportAnalysisError(any(RecognitionException.class), any(File.class))) .thenReturn(true); scanner.setVisitorBridge( new VisitorsBridge( Lists.newArrayList(listener), Lists.newArrayList(), sonarComponents, false)); scanner.scan(ImmutableList.of(new File("src/test/resources/AstScannerParseError.txt"))); verify(sonarComponents).reportAnalysisError(any(RecognitionException.class), any(File.class)); verifyZeroInteractions(listener); }
@Override public void reportIssue( JavaCheck javaCheck, Tree syntaxNode, String message, List<Location> secondary, @Nullable Integer cost) { AnalyzerMessage analyzerMessage = new AnalyzerMessage( javaCheck, file, AnalyzerMessage.textSpanFor(syntaxNode), message, cost != null ? cost : 0); for (Location location : secondary) { AnalyzerMessage secondaryLocation = new AnalyzerMessage( javaCheck, file, AnalyzerMessage.textSpanFor(location.syntaxNode), location.msg, 0); analyzerMessage.secondaryLocations.add(secondaryLocation); } sonarComponents.reportIssue(analyzerMessage); }
@Override public void addIssue(File file, JavaCheck check, int line, String message) { if (sonarComponents != null) { sonarComponents.addIssue(file, check, line, message, null); } }
@Override public void addIssue(int line, JavaCheck javaCheck, String message, @Nullable Double cost) { sonarComponents.addIssue(file, javaCheck, line, message, cost); }