Package org.sonar.plugins.java.api
Interface JavaFileScannerContext
-
- All Known Implementing Classes:
DefaultJavaFileScannerContext,VisitorsBridgeForTests.TestJavaFileScannerContext
@Beta public interface JavaFileScannerContextContext injected in check classes and used to report issues.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classJavaFileScannerContext.LocationMessage and syntaxNode for a secondary location.
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods Modifier and Type Method Description voidaddIssue(int line, JavaCheck check, String message)Report an issue on a specific line.voidaddIssue(int line, JavaCheck check, String message, Integer cost)Report an issue on a specific line.voidaddIssue(File file, JavaCheck check, int line, String message)Report an issue at a specific line of a given file.voidaddIssueOnFile(JavaCheck check, String message)Report an issue at file level.booleanfileParsed()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.FilegetFile()File under analysis.StringgetFileContent()Content of the currently analyzed file.StringgetFileKey()FileKey of currently analyzed file.List<String>getFileLines()Lines of the currently analyzed file.JavaVersiongetJavaVersion()Java version defined for the analysis using sonar.java.version parameter.List<Tree>getMethodComplexityNodes(ClassTree enclosingClass, MethodTree methodTree)Deprecated.usegetComplexityNodes(Tree)insteadObjectgetSemanticModel()Get semantic analysis.CompilationUnitTreegetTree()Parsed tree of the current file.FilegetWorkingDirectory()The working directory used by the analysis.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.
-
-
-
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
-
addIssue
void addIssue(int line, JavaCheck check, String message)Report an issue on a specific line.- 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.- 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.
-
addIssue
void addIssue(File file, JavaCheck check, int line, String message)
Report an issue at a specific line of a given file. This method is used for one- Parameters:
file- File on which to reportcheck- The check raising the issue.line- line on which to report the issuemessage- Message to display to the user
-
getSemanticModel
@Nullable Object getSemanticModel()
Get semantic analysis.- Returns:
- SemanticModel if semantic analysis was successful, null otherwise.
-
getFileKey
String getFileKey()
FileKey of currently analyzed file.- Returns:
- the fileKey of the file currently analyzed.
-
getFile
File getFile()
File under analysis.- Returns:
- the currently analysed file.
-
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.
-
getMethodComplexityNodes
@Deprecated List<Tree> getMethodComplexityNodes(ClassTree enclosingClass, MethodTree methodTree)
Deprecated.usegetComplexityNodes(Tree)insteadComputes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.- Parameters:
enclosingClass- not used.methodTree- the methodTree 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.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
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.Locationto 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.
-
-