Package org.sonar.plugins.java.api
Interface JavaFileScannerContext
-
- All Known Implementing Classes:
DefaultJavaFileScannerContext
,VisitorsBridgeForTests.TestJavaFileScannerContext
@Beta public interface JavaFileScannerContext
Context injected in check classes and used to report issues.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
JavaFileScannerContext.Location
Message and syntaxNode for a secondary location.
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Deprecated Methods Modifier and Type Method Description void
addIssue(int line, JavaCheck check, String message)
Report an issue on a specific line.void
addIssue(int line, JavaCheck check, String message, Integer cost)
Report an issue on a specific line.void
addIssueOnFile(JavaCheck check, String message)
Report an issue at file level.void
addIssueOnProject(JavaCheck check, String message)
Report an issue at at the project level.boolean
fileParsed()
Checks if file has been parsed correctly.List<Tree>
getComplexityNodes(Tree tree)
Computes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.String
getFileContent()
Content of the currently analyzed file.String
getFileKey()
Deprecated.since SonarJava 5.12: Rely on the InputFile key instead, usinggetInputFile()
.List<String>
getFileLines()
Lines of the currently analyzed file.org.sonar.api.batch.fs.InputFile
getInputFile()
InputFile under analysis.JavaVersion
getJavaVersion()
Java version defined for the analysis usingsonar.java.version
parameter.org.sonar.api.batch.fs.InputComponent
getProject()
InputComponent
representing the project being analyzedObject
getSemanticModel()
Get semantic analysis.CompilationUnitTree
getTree()
Parsed tree of the current file.File
getWorkingDirectory()
The working directory used by the analysis.void
reportIssue(JavaCheck javaCheck, Tree tree, String message)
Report an issue.void
reportIssue(JavaCheck javaCheck, Tree tree, String message, List<JavaFileScannerContext.Location> secondaryLocations, Integer cost)
Report an issue.void
reportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message)
Report an issue.void
reportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message, List<JavaFileScannerContext.Location> secondaryLocations, Integer cost)
Report an issue.void
reportIssueWithFlow(JavaCheck javaCheck, Tree tree, String message, Iterable<List<JavaFileScannerContext.Location>> flows, Integer cost)
Report an issue.default Optional<SourceMap>
sourceMap()
Return JSR 45 source map for current input file
-
-
-
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. 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
void addIssue(int line, JavaCheck check, String message, @Nullable Integer cost)
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
@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, usinggetInputFile()
.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 usingsonar.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 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.Location
to 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.Location
to display flows for the issue.cost
- computed remediation cost if applicable, null if not.
-
reportIssue
void reportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message)
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.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.
-
-