Class DefaultJavaFileScannerContext
java.lang.Object
org.sonar.java.model.DefaultModuleScannerContext
org.sonar.java.model.DefaultInputFileScannerContext
org.sonar.java.model.DefaultJavaFileScannerContext
- All Implemented Interfaces:
MetricsScannerContext, RegexScannerContext, FluentReporting, InputFileScannerContext, JavaFileScannerContext, ModuleScannerContext
- Direct Known Subclasses:
JavaFileScannerContextForTests
public class DefaultJavaFileScannerContext
extends DefaultInputFileScannerContext
implements JavaFileScannerContext, RegexScannerContext, FluentReporting, MetricsScannerContext
-
Nested Class Summary
Nested classes/interfaces inherited from interface FluentReporting
FluentReporting.JavaIssueBuilderNested classes/interfaces inherited from interface JavaFileScannerContext
JavaFileScannerContext.LocationModifier and TypeInterfaceDescriptionstatic classMessage and syntaxNode for a secondary location. -
Field Summary
Fields inherited from class DefaultInputFileScannerContext
inputFileFields inherited from class DefaultModuleScannerContext
cacheContext, inAndroidContext, javaVersion, sonarComponentsModifier and TypeFieldDescriptionprotected final CacheContextprotected final booleanprotected final JavaVersionprotected final SonarComponents -
Constructor Summary
ConstructorsConstructorDescriptionDefaultJavaFileScannerContext(CompilationUnitTree tree, org.sonar.api.batch.fs.InputFile inputFile, Sema semanticModel, SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed, boolean inAndroidContext) DefaultJavaFileScannerContext(CompilationUnitTree tree, org.sonar.api.batch.fs.InputFile inputFile, Sema semanticModel, SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed, boolean inAndroidContext, CacheContext cacheContext) -
Method Summary
Modifier and TypeMethodDescriptionprotected static AnalyzerMessagecreateAnalyzerMessage(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) 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.Get semantic analysis.getTree()Parsed tree of the current file.newIssue()org.sonarsource.analyzer.commons.regex.RegexParseResultregexForLiterals(org.sonarsource.analyzer.commons.regex.ast.FlagSet initialFlags, LiteralTree... stringLiterals) voidreportIssue(RegexCheck regexCheck, Tree javaSyntaxElement, String message, Integer cost, List<RegexCheck.RegexIssueLocation> secondaries) voidreportIssue(RegexCheck regexCheck, org.sonarsource.analyzer.commons.regex.ast.RegexSyntaxElement regexTree, String message, Integer cost, List<RegexCheck.RegexIssueLocation> secondaries) 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.Return JSR 45 source map for current input fileprotected static voidthrowIfEndOfAnalysisCheck(JavaCheck javaCheck) Methods inherited from class DefaultInputFileScannerContext
addIssue, addIssue, addIssueOnFile, getInputFileModifier and TypeMethodDescriptionvoidReport an issue on a specific line.voidReport an issue on a specific line.voidaddIssueOnFile(JavaCheck javaCheck, String message) Report an issue at file level.org.sonar.api.batch.fs.InputFileInputFile under analysis.Methods inherited from class DefaultModuleScannerContext
addIssueOnProject, getCacheContext, getConfiguration, getFullyQualifiedModuleKey, getJavaVersion, getModuleKey, getProject, getRootProjectWorkingDirectory, getWorkingDirectory, inAndroidContext, reportIssue, sonarProductModifier and TypeMethodDescriptionvoidaddIssueOnProject(JavaCheck check, String message) Report an issue at the project level.org.sonar.api.config.ConfigurationJava version defined for the analysis usingsonar.java.versionparameter.org.sonar.api.batch.fs.InputComponentInputComponentrepresenting the project being analyzedThe working directory used by the analysis.booleanTo be used to know if the current file is in an android context or not.voidreportIssue(AnalyzerMessage message) org.sonar.api.SonarProduct
-
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, @Nullable CacheContext cacheContext) -
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:JavaFileScannerContextParsed tree of the current file.- Specified by:
getTreein interfaceJavaFileScannerContext- Returns:
- CompilationUnitTree ready for scan by checks.
-
getSemanticModel
Description copied from interface:JavaFileScannerContextGet semantic analysis.- Specified by:
getSemanticModelin interfaceJavaFileScannerContext- Returns:
- SemanticModel if semantic analysis was successful, null otherwise.
-
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
-
reportIssue
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(RegexCheck regexCheck, org.sonarsource.analyzer.commons.regex.ast.RegexSyntaxElement regexTree, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries) - Specified by:
reportIssuein interfaceRegexScannerContext
-
reportIssue
public void reportIssue(RegexCheck regexCheck, Tree javaSyntaxElement, String message, @Nullable Integer cost, List<RegexCheck.RegexIssueLocation> secondaries) - Specified by:
reportIssuein interfaceRegexScannerContext
-
regexForLiterals
public org.sonarsource.analyzer.commons.regex.RegexParseResult regexForLiterals(org.sonarsource.analyzer.commons.regex.ast.FlagSet initialFlags, LiteralTree... stringLiterals) - Specified by:
regexForLiteralsin interfaceRegexScannerContext
-
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
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
Description copied from interface:JavaFileScannerContextLines of the currently analyzed file.- Specified by:
getFileLinesin interfaceJavaFileScannerContext- Returns:
- list of file lines.
-
getFileContent
Description copied from interface:JavaFileScannerContextContent of the currently analyzed file.- Specified by:
getFileContentin interfaceJavaFileScannerContext- Returns:
- the file content as a String.
-
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) -
getComplexityNodes
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.
-
throwIfEndOfAnalysisCheck
-
sourceMap
Description copied from interface:JavaFileScannerContextReturn JSR 45 source map for current input file- Specified by:
sourceMapin interfaceJavaFileScannerContext- Returns:
- source map if available
-
newIssue
- Specified by:
newIssuein interfaceFluentReporting
-
getMetricsComputer
- Specified by:
getMetricsComputerin interfaceMetricsScannerContext
-