Package org.sonar.plugins.java.api
Interface JavaFileScannerContext
- All Known Implementing Classes:
DefaultJavaFileScannerContext,JavaFileScannerContextForTests
Context injected in check classes and used to report issues.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic classMessage and syntaxNode for a secondary location. -
Method Summary
Modifier and TypeMethodDescriptionvoidReport an issue on a specific line.voidReport an issue on a specific line.voidaddIssueOnFile(JavaCheck check, String message) Report an issue at file level.voidaddIssueOnProject(JavaCheck check, String message) Report an issue at at the project level.booleanChecks if file has been parsed correctly.getComplexityNodes(Tree tree) Computes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.Content of the currently analyzed file.Lines of the currently analyzed file.org.sonar.api.batch.fs.InputFileInputFile under analysis.Java version defined for the analysis usingsonar.java.versionparameter.org.sonar.api.batch.fs.InputComponentInputComponentrepresenting the project being analyzedGet semantic analysis.getTree()Parsed tree of the current file.The working directory used by the analysis.booleanTo be used to know if the current file is in an android context or not.voidreportIssue(JavaCheck javaCheck, Tree tree, String message) Report an issue.voidreportIssue(JavaCheck javaCheck, Tree tree, String message, List<JavaFileScannerContext.Location> secondaryLocations, Integer cost) Report an issue.voidreportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message) Report an issue.voidreportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message, List<JavaFileScannerContext.Location> secondaryLocations, Integer cost) Report an issue.voidreportIssueWithFlow(JavaCheck javaCheck, Tree tree, String message, Iterable<List<JavaFileScannerContext.Location>> flows, Integer cost) Report an issue.Return JSR 45 source map for current input file
-
Method Details
-
getTree
CompilationUnitTree getTree()Parsed tree of the current file.- Returns:
- CompilationUnitTree ready for scan by checks.
-
addIssueOnFile
Report an issue at file level.- Parameters:
check- The check raising the issue.message- Message to display to the user
-
addIssueOnProject
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
Report an issue on a specific line. PreferreportIssue(JavaCheck, Tree, String)for more precise reporting.- Parameters:
line- line on which to report the issuecheck- The check raising the issue.message- Message to display to the user
-
addIssue
Report an issue on a specific line. PreferreportIssue(JavaCheck, Tree, String, List, Integer)for more precise reporting.- Parameters:
line- line on which to report the issuecheck- The check raising the issue.message- Message to display to the usercost- computed remediation cost if applicable, null if not.
-
getSemanticModel
Get semantic analysis.- Returns:
- SemanticModel if semantic analysis was successful, null otherwise.
-
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()InputComponentrepresenting 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 usingsonar.java.versionparameter.- Returns:
- JavaVersion object with API to act on it.
-
inAndroidContext
boolean inAndroidContext()To be used to know if the current file is in an android context or not. This value is determined thanks to the presence of android classes in the classpath.- Returns:
- true if the current file is in an android context.
-
fileParsed
boolean fileParsed()Checks if file has been parsed correctly.- Returns:
- true if parsing was successful
-
getComplexityNodes
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
Report an issue.- Parameters:
javaCheck- check raising the issuetree- syntax node on which to raise the issue.message- Message to display to the user.
-
reportIssue
void reportIssue(JavaCheck javaCheck, Tree tree, String message, List<JavaFileScannerContext.Location> secondaryLocations, @Nullable Integer cost) Report an issue.- Parameters:
javaCheck- check raising the issuetree- syntax node on which to raise the issue.message- Message to display to the user.secondaryLocations- List ofJavaFileScannerContext.Locationto display secondary location for the issue.cost- computed remediation cost if applicable, null if not.
-
reportIssueWithFlow
void reportIssueWithFlow(JavaCheck javaCheck, Tree tree, String message, Iterable<List<JavaFileScannerContext.Location>> flows, @Nullable Integer cost) Report an issue.- Parameters:
javaCheck- check raising the issuetree- syntax node on which to raise the issue.message- Message to display to the user.flows- List of list ofJavaFileScannerContext.Locationto display flows for the issue.cost- computed remediation cost if applicable, null if not.
-
reportIssue
Report an issue.- Parameters:
javaCheck- check raising the issuestartTree- 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 issuestartTree- 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 ofJavaFileScannerContext.Locationto display secondary location for the issue.cost- computed remediation cost if applicable, null if not.
-
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
Return JSR 45 source map for current input file- Returns:
- source map if available
-