Package org.sonar.java.model
Class DefaultJavaFileScannerContext
java.lang.Object
org.sonar.java.model.DefaultJavaFileScannerContext
- All Implemented Interfaces:
RegexScannerContext
,FluentReporting
,JavaFileScannerContext
- Direct Known Subclasses:
JavaFileScannerContextForTests
public class DefaultJavaFileScannerContext
extends Object
implements JavaFileScannerContext, RegexScannerContext, FluentReporting
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.sonar.java.reporting.FluentReporting
FluentReporting.JavaIssueBuilder
Nested classes/interfaces inherited from interface org.sonar.plugins.java.api.JavaFileScannerContext
JavaFileScannerContext.Location
-
Constructor Summary
ConstructorsConstructorDescriptionDefaultJavaFileScannerContext(CompilationUnitTree tree, org.sonar.api.batch.fs.InputFile inputFile, Sema semanticModel, SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed, boolean inAndroidContext)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Report an issue on a specific line.void
Report an issue on a specific line.void
addIssueOnFile(JavaCheck javaCheck, String message)
Report an issue at file level.void
addIssueOnProject(JavaCheck check, String message)
Report an issue at at the project level.protected static AnalyzerMessage
createAnalyzerMessage(org.sonar.api.batch.fs.InputFile inputFile, JavaCheck javaCheck, Tree startTree, Tree endTree, String message, Iterable<List<JavaFileScannerContext.Location>> flows, Integer cost)
createAnalyzerMessage(JavaCheck javaCheck, Tree startTree, String message)
boolean
Checks 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.InputFile
InputFile under analysis.Java version defined for the analysis usingsonar.java.version
parameter.org.sonar.api.batch.fs.InputComponent
InputComponent
representing the project being analyzedGet semantic analysis.getTree()
Parsed tree of the current file.The working directory used by the analysis.boolean
To be used to know if the current file is in an android context or not.newIssue()
org.sonarsource.analyzer.commons.regex.RegexParseResult
regexForLiterals(org.sonarsource.analyzer.commons.regex.ast.FlagSet initialFlags, LiteralTree... stringLiterals)
void
reportIssue(RegexCheck regexCheck, Tree javaSyntaxElement, String message, Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)
void
reportIssue(RegexCheck regexCheck, org.sonarsource.analyzer.commons.regex.ast.RegexSyntaxElement regexTree, String message, Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)
void
reportIssue(AnalyzerMessage message)
void
reportIssue(JavaCheck javaCheck, Tree tree, String message)
Report an issue.void
reportIssue(JavaCheck javaCheck, Tree syntaxNode, String message, List<JavaFileScannerContext.Location> secondary, 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> secondary, Integer cost)
Report an issue.void
reportIssueWithFlow(JavaCheck javaCheck, Tree syntaxNode, String message, Iterable<List<JavaFileScannerContext.Location>> flows, Integer cost)
Report an issue.Return JSR 45 source map for current input fileprotected static void
throwIfEndOfAnalysisCheck(JavaCheck javaCheck)
-
Constructor Details
-
DefaultJavaFileScannerContext
public DefaultJavaFileScannerContext(CompilationUnitTree tree, org.sonar.api.batch.fs.InputFile inputFile, Sema semanticModel, @Nullable SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed, boolean inAndroidContext)
-
-
Method Details
-
getTree
Description copied from interface:JavaFileScannerContext
Parsed tree of the current file.- Specified by:
getTree
in interfaceJavaFileScannerContext
- Returns:
- CompilationUnitTree ready for scan by checks.
-
addIssueOnFile
Description copied from interface:JavaFileScannerContext
Report an issue at file level.- Specified by:
addIssueOnFile
in interfaceJavaFileScannerContext
- Parameters:
javaCheck
- The check raising the issue.message
- Message to display to the user
-
addIssueOnProject
Description copied from interface:JavaFileScannerContext
Report an issue at at the project level.- Specified by:
addIssueOnProject
in interfaceJavaFileScannerContext
- Parameters:
check
- The check raising the issue.message
- Message to display to the user
-
addIssue
Description copied from interface:JavaFileScannerContext
Report an issue on a specific line. PreferJavaFileScannerContext.reportIssue(JavaCheck, Tree, String)
for more precise reporting.- Specified by:
addIssue
in interfaceJavaFileScannerContext
- Parameters:
line
- line on which to report the issuejavaCheck
- The check raising the issue.message
- Message to display to the user
-
addIssue
Description copied from interface:JavaFileScannerContext
Report an issue on a specific line. PreferJavaFileScannerContext.reportIssue(JavaCheck, Tree, String, List, Integer)
for more precise reporting.- Specified by:
addIssue
in 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
Description copied from interface:JavaFileScannerContext
Get semantic analysis.- Specified by:
getSemanticModel
in interfaceJavaFileScannerContext
- Returns:
- SemanticModel if semantic analysis was successful, null otherwise.
-
getJavaVersion
Description copied from interface:JavaFileScannerContext
Java version defined for the analysis usingsonar.java.version
parameter.- Specified by:
getJavaVersion
in interfaceJavaFileScannerContext
- Returns:
- JavaVersion object with API to act on it.
-
inAndroidContext
public boolean inAndroidContext()Description copied from interface:JavaFileScannerContext
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.- Specified by:
inAndroidContext
in interfaceJavaFileScannerContext
- Returns:
- true if the current file is in an android context.
-
fileParsed
public boolean fileParsed()Description copied from interface:JavaFileScannerContext
Checks if file has been parsed correctly.- Specified by:
fileParsed
in interfaceJavaFileScannerContext
- Returns:
- true if parsing was successful
-
reportIssue
Description copied from interface:JavaFileScannerContext
Report an issue.- Specified by:
reportIssue
in 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(RegexCheck regexCheck, org.sonarsource.analyzer.commons.regex.ast.RegexSyntaxElement regexTree, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)- Specified by:
reportIssue
in interfaceRegexScannerContext
-
reportIssue
public void reportIssue(RegexCheck regexCheck, Tree javaSyntaxElement, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries)- Specified by:
reportIssue
in interfaceRegexScannerContext
-
regexForLiterals
public org.sonarsource.analyzer.commons.regex.RegexParseResult regexForLiterals(org.sonarsource.analyzer.commons.regex.ast.FlagSet initialFlags, LiteralTree... stringLiterals)- Specified by:
regexForLiterals
in interfaceRegexScannerContext
-
reportIssue
public void reportIssue(JavaCheck javaCheck, Tree syntaxNode, String message, List<JavaFileScannerContext.Location> secondary, @Nullable Integer cost)Description copied from interface:JavaFileScannerContext
Report an issue.- Specified by:
reportIssue
in 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.Location
to 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:JavaFileScannerContext
Report an issue.- Specified by:
reportIssueWithFlow
in 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.Location
to display flows for the issue.cost
- computed remediation cost if applicable, null if not.
-
reportIssue
Description copied from interface:JavaFileScannerContext
Report an issue.- Specified by:
reportIssue
in 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:JavaFileScannerContext
Report an issue.- Specified by:
reportIssue
in 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.Location
to display secondary location for the issue.cost
- computed remediation cost if applicable, null if not.
-
getFileLines
Description copied from interface:JavaFileScannerContext
Lines of the currently analyzed file.- Specified by:
getFileLines
in interfaceJavaFileScannerContext
- Returns:
- list of file lines.
-
getFileContent
Description copied from interface:JavaFileScannerContext
Content of the currently analyzed file.- Specified by:
getFileContent
in interfaceJavaFileScannerContext
- Returns:
- the file content as a String.
-
reportIssue
-
createAnalyzerMessage
-
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) -
getInputFile
public org.sonar.api.batch.fs.InputFile getInputFile()Description copied from interface:JavaFileScannerContext
InputFile under analysis.- Specified by:
getInputFile
in interfaceJavaFileScannerContext
- Returns:
- the currently analyzed
InputFile
.
-
getProject
public org.sonar.api.batch.fs.InputComponent getProject()Description copied from interface:JavaFileScannerContext
InputComponent
representing the project being analyzed- Specified by:
getProject
in interfaceJavaFileScannerContext
- Returns:
- the project component
-
getWorkingDirectory
Description copied from interface:JavaFileScannerContext
The working directory used by the analysis.- Specified by:
getWorkingDirectory
in interfaceJavaFileScannerContext
- Returns:
- the current working directory.
-
getComplexityNodes
Description copied from interface:JavaFileScannerContext
Computes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.- Specified by:
getComplexityNodes
in interfaceJavaFileScannerContext
- Parameters:
tree
- the tree to compute the complexity.- Returns:
- the list of syntax nodes incrementing the complexity.
-
throwIfEndOfAnalysisCheck
-
sourceMap
Description copied from interface:JavaFileScannerContext
Return JSR 45 source map for current input file- Specified by:
sourceMap
in interfaceJavaFileScannerContext
- Returns:
- source map if available
-
newIssue
- Specified by:
newIssue
in interfaceFluentReporting
-