Package org.sonar.java.model
Class DefaultJavaFileScannerContext
- java.lang.Object
-
- org.sonar.java.model.DefaultJavaFileScannerContext
-
- All Implemented Interfaces:
JavaFileScannerContext
- Direct Known Subclasses:
VisitorsBridgeForTests.TestJavaFileScannerContext
public class DefaultJavaFileScannerContext extends Object implements JavaFileScannerContext
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.sonar.plugins.java.api.JavaFileScannerContext
JavaFileScannerContext.Location
-
-
Constructor Summary
Constructors Constructor Description DefaultJavaFileScannerContext(CompilationUnitTree tree, org.sonar.api.batch.fs.InputFile inputFile, SemanticModel semanticModel, SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddIssue(int line, JavaCheck javaCheck, String message)Report an issue on a specific line.voidaddIssue(int line, JavaCheck javaCheck, String message, Integer cost)Report an issue on a specific line.voidaddIssue(File file, JavaCheck check, int line, String message)Deprecated.since SonarJava 5.12 - Use 'reportIssue' instead, or dedicated method to report issue directly on file or projectvoidaddIssueOnFile(JavaCheck javaCheck, String message)Report an issue at file level.voidaddIssueOnProject(JavaCheck check, String message)Report an issue at at the project level.protected static AnalyzerMessagecreateAnalyzerMessage(org.sonar.api.batch.fs.InputFile inputFile, JavaCheck javaCheck, Tree startTree, Tree endTree, String message, Iterable<List<JavaFileScannerContext.Location>> flows, Integer cost)AnalyzerMessagecreateAnalyzerMessage(JavaCheck javaCheck, Tree startTree, String message)booleanfileParsed()Checks if file has been parsed correctly.FilegetBaseDirectory()List<Tree>getComplexityNodes(Tree tree)Computes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.FilegetFile()Deprecated.since SonarJava 5.12 - Rely ongetInputFile()insteadStringgetFileContent()Content of the currently analyzed file.StringgetFileKey()Deprecated.since SonarJava 5.12 - Use key of InputFile instead, usinggetInputFile().List<String>getFileLines()Lines of the currently analyzed file.org.sonar.api.batch.fs.InputFilegetInputFile()InputFile under analysis.JavaVersiongetJavaVersion()Java version defined for the analysis usingsonar.java.versionparameter.org.sonar.api.batch.fs.InputComponentgetProject()InputComponentrepresenting the project being analyzedObjectgetSemanticModel()Get semantic analysis.CompilationUnitTreegetTree()Parsed tree of the current file.FilegetWorkingDirectory()The working directory used by the analysis.voidreportIssue(AnalyzerMessage message)voidreportIssue(JavaCheck javaCheck, Tree tree, String message)Report an issue.voidreportIssue(JavaCheck javaCheck, Tree syntaxNode, String message, List<JavaFileScannerContext.Location> secondary, 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> secondary, Integer cost)Report an issue.voidreportIssueWithFlow(JavaCheck javaCheck, Tree syntaxNode, String message, Iterable<List<JavaFileScannerContext.Location>> flows, Integer cost)Report an issue.
-
-
-
Constructor Detail
-
DefaultJavaFileScannerContext
public DefaultJavaFileScannerContext(CompilationUnitTree tree, org.sonar.api.batch.fs.InputFile inputFile, SemanticModel semanticModel, @Nullable SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed)
-
-
Method Detail
-
getTree
public CompilationUnitTree getTree()
Description copied from interface:JavaFileScannerContextParsed tree of the current file.- Specified by:
getTreein interfaceJavaFileScannerContext- Returns:
- CompilationUnitTree ready for scan by checks.
-
addIssueOnFile
public void addIssueOnFile(JavaCheck javaCheck, String message)
Description copied from interface:JavaFileScannerContextReport an issue at file level.- Specified by:
addIssueOnFilein interfaceJavaFileScannerContext- Parameters:
javaCheck- The check raising the issue.message- Message to display to the user
-
addIssueOnProject
public void addIssueOnProject(JavaCheck check, String message)
Description copied from interface:JavaFileScannerContextReport an issue at at the project level.- Specified by:
addIssueOnProjectin interfaceJavaFileScannerContext- Parameters:
check- The check raising the issue.message- Message to display to the user
-
addIssue
public void addIssue(int line, JavaCheck javaCheck, String message)Description copied from interface:JavaFileScannerContextReport an issue on a specific line. PreferJavaFileScannerContext.reportIssue(JavaCheck, Tree, String)for more precise reporting.- Specified by:
addIssuein interfaceJavaFileScannerContext- Parameters:
line- line on which to report the issuejavaCheck- The check raising the issue.message- Message to display to the user
-
addIssue
public void addIssue(int line, JavaCheck javaCheck, String message, @Nullable Integer cost)Description copied from interface:JavaFileScannerContextReport an issue on a specific line. PreferJavaFileScannerContext.reportIssue(JavaCheck, Tree, String, List, Integer)for more precise reporting.- Specified by:
addIssuein interfaceJavaFileScannerContext- Parameters:
line- line on which to report the issuejavaCheck- The check raising the issue.message- Message to display to the usercost- computed remediation cost if applicable, null if not.
-
getSemanticModel
@Nullable public Object getSemanticModel()
Description copied from interface:JavaFileScannerContextGet semantic analysis.- Specified by:
getSemanticModelin interfaceJavaFileScannerContext- Returns:
- SemanticModel if semantic analysis was successful, null otherwise.
-
getJavaVersion
public JavaVersion getJavaVersion()
Description copied from interface:JavaFileScannerContextJava version defined for the analysis usingsonar.java.versionparameter.- Specified by:
getJavaVersionin interfaceJavaFileScannerContext- Returns:
- JavaVersion object with API to act on it.
-
fileParsed
public boolean fileParsed()
Description copied from interface:JavaFileScannerContextChecks if file has been parsed correctly.- Specified by:
fileParsedin interfaceJavaFileScannerContext- Returns:
- true if parsing was successful
-
getFileKey
@Deprecated public String getFileKey()
Deprecated.since SonarJava 5.12 - Use key of InputFile instead, usinggetInputFile().Description copied from interface:JavaFileScannerContextFileKey of currently analyzed file.- Specified by:
getFileKeyin interfaceJavaFileScannerContext- Returns:
- the fileKey of the file currently analyzed.
-
addIssue
@Deprecated public void addIssue(File file, JavaCheck check, int line, String message)
Deprecated.since SonarJava 5.12 - Use 'reportIssue' instead, or dedicated method to report issue directly on file or projectDescription copied from interface:JavaFileScannerContextReport an issue at a specific line of a given file. This method is used for one- Specified by:
addIssuein interfaceJavaFileScannerContext- 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
-
reportIssue
public void reportIssue(JavaCheck javaCheck, Tree tree, String message)
Description copied from interface:JavaFileScannerContextReport an issue.- Specified by:
reportIssuein interfaceJavaFileScannerContext- Parameters:
javaCheck- check raising the issuetree- syntax node on which to raise the issue.message- Message to display to the user.
-
reportIssue
public void reportIssue(JavaCheck javaCheck, Tree syntaxNode, String message, List<JavaFileScannerContext.Location> secondary, @Nullable Integer cost)
Description copied from interface:JavaFileScannerContextReport an issue.- Specified by:
reportIssuein interfaceJavaFileScannerContext- Parameters:
javaCheck- check raising the issuesyntaxNode- syntax node on which to raise the issue.message- Message to display to the user.secondary- List ofJavaFileScannerContext.Locationto display secondary location for the issue.cost- computed remediation cost if applicable, null if not.
-
reportIssueWithFlow
public void reportIssueWithFlow(JavaCheck javaCheck, Tree syntaxNode, String message, Iterable<List<JavaFileScannerContext.Location>> flows, @Nullable Integer cost)
Description copied from interface:JavaFileScannerContextReport an issue.- Specified by:
reportIssueWithFlowin interfaceJavaFileScannerContext- Parameters:
javaCheck- check raising the issuesyntaxNode- 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
public void reportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message)
Description copied from interface:JavaFileScannerContextReport an issue.- Specified by:
reportIssuein interfaceJavaFileScannerContext- 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
public void reportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message, List<JavaFileScannerContext.Location> secondary, @Nullable Integer cost)
Description copied from interface:JavaFileScannerContextReport an issue.- Specified by:
reportIssuein interfaceJavaFileScannerContext- 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.secondary- List ofJavaFileScannerContext.Locationto display secondary location for the issue.cost- computed remediation cost if applicable, null if not.
-
getFileLines
public List<String> getFileLines()
Description copied from interface:JavaFileScannerContextLines of the currently analyzed file.- Specified by:
getFileLinesin interfaceJavaFileScannerContext- Returns:
- list of file lines.
-
getFileContent
public String getFileContent()
Description copied from interface:JavaFileScannerContextContent of the currently analyzed file.- Specified by:
getFileContentin interfaceJavaFileScannerContext- Returns:
- the file content as a String.
-
reportIssue
public void reportIssue(AnalyzerMessage message)
-
createAnalyzerMessage
public AnalyzerMessage createAnalyzerMessage(JavaCheck javaCheck, Tree startTree, String message)
-
createAnalyzerMessage
protected static AnalyzerMessage createAnalyzerMessage(org.sonar.api.batch.fs.InputFile inputFile, JavaCheck javaCheck, Tree startTree, @Nullable Tree endTree, String message, Iterable<List<JavaFileScannerContext.Location>> flows, @Nullable Integer cost)
-
getFile
@Deprecated public File getFile()
Deprecated.since SonarJava 5.12 - Rely ongetInputFile()insteadDescription copied from interface:JavaFileScannerContextFile under analysis.- Specified by:
getFilein interfaceJavaFileScannerContext- Returns:
- the currently analyzed file.
-
getInputFile
public org.sonar.api.batch.fs.InputFile getInputFile()
Description copied from interface:JavaFileScannerContextInputFile under analysis.- Specified by:
getInputFilein interfaceJavaFileScannerContext- Returns:
- the currently analyzed
InputFile.
-
getProject
public org.sonar.api.batch.fs.InputComponent getProject()
Description copied from interface:JavaFileScannerContextInputComponentrepresenting the project being analyzed- Specified by:
getProjectin interfaceJavaFileScannerContext- Returns:
- the project component
-
getWorkingDirectory
public File getWorkingDirectory()
Description copied from interface:JavaFileScannerContextThe working directory used by the analysis.- Specified by:
getWorkingDirectoryin interfaceJavaFileScannerContext- Returns:
- the current working directory.
-
getBaseDirectory
public File getBaseDirectory()
-
getComplexityNodes
public List<Tree> getComplexityNodes(Tree tree)
Description copied from interface:JavaFileScannerContextComputes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.- Specified by:
getComplexityNodesin interfaceJavaFileScannerContext- Parameters:
tree- the tree to compute the complexity.- Returns:
- the list of syntax nodes incrementing the complexity.
-
-