DefaultJavaFileScannerContext implements JavaFileScannerContext, RegexScannerContext { @Override public Optional<SourceMap> sourceMap() { if (inputFile instanceof GeneratedFile) { return Optional.of(((GeneratedFile) inputFile).sourceMap()); } return Optional.empty(); } DefaultJavaFileScannerContext(CompilationUnitTree tree, InputFile inputFile, Sema semanticModel,
                                       @Nullable SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed); @Override CompilationUnitTree getTree(); @Override void addIssueOnFile(JavaCheck javaCheck, String message); @Override void addIssueOnProject(JavaCheck check, String message); @Override void addIssue(int line, JavaCheck javaCheck, String message); @Override void addIssue(int line, JavaCheck javaCheck, String message, @Nullable Integer cost); @Override @Nullable Object getSemanticModel(); @Override JavaVersion getJavaVersion(); @Override boolean fileParsed(); @Deprecated @Override String getFileKey(); @Override void reportIssue(JavaCheck javaCheck, Tree tree, String message); @Override void reportIssue(RegexCheck regexCheck, RegexSyntaxElement regexTree, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries); @Override void reportIssue(RegexCheck regexCheck, Tree javaSyntaxElement, String message, @Nullable Integer cost, List<RegexIssueLocation> secondaries); @Override RegexParseResult regexForLiterals(FlagSet initialFlags, LiteralTree... stringLiterals); @Override void reportIssue(JavaCheck javaCheck, Tree syntaxNode, String message, List<Location> secondary, @Nullable Integer cost); @Override void reportIssueWithFlow(JavaCheck javaCheck, Tree syntaxNode, String message, Iterable<List<Location>> flows, @Nullable Integer cost); @Override void reportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message); @Override void reportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message, List<Location> secondary, @Nullable Integer cost); @Override List<String> getFileLines(); @Override String getFileContent(); void reportIssue(AnalyzerMessage message); AnalyzerMessage createAnalyzerMessage(JavaCheck javaCheck, Tree startTree, String message); @Override InputFile getInputFile(); @Override InputComponent getProject(); @Override File getWorkingDirectory(); @Override List<Tree> getComplexityNodes(Tree tree); @Override Optional<SourceMap> sourceMap();  }
@Test void test_source_map() { GeneratedFile file = mock(GeneratedFile.class); SourceMap sourceMap = mock(SourceMap.class); when(file.sourceMap()).thenReturn(sourceMap); DefaultJavaFileScannerContext ctx = new DefaultJavaFileScannerContext(compilationUnitTree, file, null, sonarComponents, new JavaVersionImpl(), true); assertThat(ctx.sourceMap()).containsSame(sourceMap); ctx = new DefaultJavaFileScannerContext(compilationUnitTree, JAVA_INPUT_FILE, null, sonarComponents, new JavaVersionImpl(), true); assertThat(ctx.sourceMap()).isEmpty(); }