Interface JavaFileScannerContext

    • Method Detail

      • getTree

        CompilationUnitTree getTree()
        Parsed tree of the current file.
        Returns:
        CompilationUnitTree ready for scan by checks.
      • addIssueOnFile

        void addIssueOnFile​(JavaCheck check,
                            String message)
        Report an issue at file level.
        Parameters:
        check - The check raising the issue.
        message - Message to display to the user
      • addIssueOnProject

        void addIssueOnProject​(JavaCheck check,
                               String message)
        Report an issue at at the project level.
        Parameters:
        check - The check raising the issue.
        message - Message to display to the user
        Since:
        SonarJava 5.12: Dropping support of file-related methods
      • addIssue

        void addIssue​(int line,
                      JavaCheck check,
                      String message)
        Report an issue on a specific line. Prefer reportIssue(JavaCheck, Tree, String) for more precise reporting.
        Parameters:
        line - line on which to report the issue
        check - The check raising the issue.
        message - Message to display to the user
      • addIssue

        void addIssue​(int line,
                      JavaCheck check,
                      String message,
                      @Nullable
                      Integer cost)
        Report an issue on a specific line. Prefer reportIssue(JavaCheck, Tree, String, List, Integer) for more precise reporting.
        Parameters:
        line - line on which to report the issue
        check - The check raising the issue.
        message - Message to display to the user
        cost - computed remediation cost if applicable, null if not.
      • getSemanticModel

        @Nullable
        Object getSemanticModel()
        Get semantic analysis.
        Returns:
        SemanticModel if semantic analysis was successful, null otherwise.
      • getFileKey

        @Deprecated
        String getFileKey()
        Deprecated.
        since SonarJava 5.12: Rely on the InputFile key instead, using getInputFile().
        FileKey of currently analyzed file.
        Returns:
        the fileKey of the file currently analyzed.
      • getInputFile

        org.sonar.api.batch.fs.InputFile getInputFile()
        InputFile under analysis.
        Returns:
        the currently analyzed InputFile.
        Since:
        SonarJava 5.12: Dropping support of file-related methods
      • getProject

        org.sonar.api.batch.fs.InputComponent getProject()
        InputComponent representing the project being analyzed
        Returns:
        the project component
        Since:
        SonarJava 5.12: Dropping support of file-related methods
      • getWorkingDirectory

        File getWorkingDirectory()
        The working directory used by the analysis.
        Returns:
        the current working directory.
      • getJavaVersion

        JavaVersion getJavaVersion()
        Java version defined for the analysis using sonar.java.version parameter.
        Returns:
        JavaVersion object with API to act on it.
      • fileParsed

        boolean fileParsed()
        Checks if file has been parsed correctly.
        Returns:
        true if parsing was successful
      • getComplexityNodes

        List<Tree> getComplexityNodes​(Tree tree)
        Computes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.
        Parameters:
        tree - the tree to compute the complexity.
        Returns:
        the list of syntax nodes incrementing the complexity.
      • reportIssue

        void reportIssue​(JavaCheck javaCheck,
                         Tree tree,
                         String message)
        Report an issue.
        Parameters:
        javaCheck - check raising the issue
        tree - syntax node on which to raise the issue.
        message - Message to display to the user.
      • reportIssue

        void reportIssue​(JavaCheck javaCheck,
                         Tree startTree,
                         Tree endTree,
                         String message)
        Report an issue.
        Parameters:
        javaCheck - check raising the issue
        startTree - syntax node on which to start the highlighting of the issue.
        endTree - syntax node on which to end the highlighting of the issue.
        message - Message to display to the user.
      • reportIssue

        void reportIssue​(JavaCheck javaCheck,
                         Tree startTree,
                         Tree endTree,
                         String message,
                         List<JavaFileScannerContext.Location> secondaryLocations,
                         @Nullable
                         Integer cost)
        Report an issue.
        Parameters:
        javaCheck - check raising the issue
        startTree - syntax node on which to start the highlighting of the issue.
        endTree - syntax node on which to end the highlighting of the issue.
        message - Message to display to the user.
        secondaryLocations - List of JavaFileScannerContext.Location to display secondary location for the issue.
        cost - computed remediation cost if applicable, null if not.
      • getFileLines

        List<String> getFileLines()
        Lines of the currently analyzed file.
        Returns:
        list of file lines.
      • getFileContent

        String getFileContent()
        Content of the currently analyzed file.
        Returns:
        the file content as a String.
      • sourceMap

        default Optional<SourceMap> sourceMap()
        Return JSR 45 source map for current input file
        Returns:
        source map if available