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, File file, SemanticModel semanticModel, SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addIssue(int line, JavaCheck javaCheck, String message)
Report an issue on a specific line.void
addIssue(int line, JavaCheck javaCheck, String message, Integer cost)
Report an issue on a specific line.void
addIssue(File file, JavaCheck check, int line, String message)
Report an issue at a specific line of a given file.void
addIssueOnFile(JavaCheck javaCheck, String message)
Report an issue at file level.protected static AnalyzerMessage
createAnalyzerMessage(File file, JavaCheck javaCheck, Tree startTree, Tree endTree, String message, Iterable<List<JavaFileScannerContext.Location>> flows, Integer cost)
AnalyzerMessage
createAnalyzerMessage(JavaCheck javaCheck, Tree startTree, String message)
boolean
fileParsed()
Checks if file has been parsed correctly.File
getBaseDirectory()
List<Tree>
getComplexityNodes(Tree tree)
Computes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.File
getFile()
File under analysis.String
getFileContent()
Content of the currently analyzed file.String
getFileKey()
FileKey of currently analyzed file.List<String>
getFileLines()
Lines of the currently analyzed file.JavaVersion
getJavaVersion()
Java version defined for the analysis using sonar.java.version parameter.List<Tree>
getMethodComplexityNodes(ClassTree enclosingClass, MethodTree methodTree)
Computes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.Object
getSemanticModel()
Get semantic analysis.CompilationUnitTree
getTree()
Parsed tree of the current file.File
getWorkingDirectory()
The working directory used by the analysis.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.
-
-
-
Constructor Detail
-
DefaultJavaFileScannerContext
public DefaultJavaFileScannerContext(CompilationUnitTree tree, File file, SemanticModel semanticModel, @Nullable SonarComponents sonarComponents, JavaVersion javaVersion, boolean fileParsed)
-
-
Method Detail
-
getTree
public CompilationUnitTree 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
public void addIssueOnFile(JavaCheck javaCheck, String message)
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
-
addIssue
public void addIssue(int line, JavaCheck javaCheck, String message)
Description copied from interface:JavaFileScannerContext
Report an issue on a specific line.- 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
public void addIssue(int line, JavaCheck javaCheck, String message, @Nullable Integer cost)
Description copied from interface:JavaFileScannerContext
Report an issue on a specific line.- 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
@Nullable public Object getSemanticModel()
Description copied from interface:JavaFileScannerContext
Get semantic analysis.- Specified by:
getSemanticModel
in interfaceJavaFileScannerContext
- Returns:
- SemanticModel if semantic analysis was successful, null otherwise.
-
getJavaVersion
public JavaVersion getJavaVersion()
Description copied from interface:JavaFileScannerContext
Java version defined for the analysis using sonar.java.version parameter.- Specified by:
getJavaVersion
in interfaceJavaFileScannerContext
- Returns:
- JavaVersion object with API to act on it.
-
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
-
getFileKey
public String getFileKey()
Description copied from interface:JavaFileScannerContext
FileKey of currently analyzed file.- Specified by:
getFileKey
in interfaceJavaFileScannerContext
- Returns:
- the fileKey of the file currently analyzed.
-
addIssue
public void addIssue(File file, JavaCheck check, int line, String message)
Description copied from interface:JavaFileScannerContext
Report an issue at a specific line of a given file. This method is used for one- Specified by:
addIssue
in 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: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(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
public void reportIssue(JavaCheck javaCheck, Tree startTree, Tree endTree, String message)
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
public List<String> getFileLines()
Description copied from interface:JavaFileScannerContext
Lines of the currently analyzed file.- Specified by:
getFileLines
in interfaceJavaFileScannerContext
- Returns:
- list of file lines.
-
getFileContent
public String 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
public void reportIssue(AnalyzerMessage message)
-
createAnalyzerMessage
public AnalyzerMessage createAnalyzerMessage(JavaCheck javaCheck, Tree startTree, String message)
-
createAnalyzerMessage
protected static AnalyzerMessage createAnalyzerMessage(File file, JavaCheck javaCheck, Tree startTree, @Nullable Tree endTree, String message, Iterable<List<JavaFileScannerContext.Location>> flows, @Nullable Integer cost)
-
getFile
public File getFile()
Description copied from interface:JavaFileScannerContext
File under analysis.- Specified by:
getFile
in interfaceJavaFileScannerContext
- Returns:
- the currently analysed file.
-
getWorkingDirectory
public File getWorkingDirectory()
Description copied from interface:JavaFileScannerContext
The working directory used by the analysis.- Specified by:
getWorkingDirectory
in interfaceJavaFileScannerContext
- Returns:
- the current working directory.
-
getBaseDirectory
public File getBaseDirectory()
-
getComplexityNodes
public List<Tree> getComplexityNodes(Tree tree)
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.
-
getMethodComplexityNodes
public List<Tree> getMethodComplexityNodes(ClassTree enclosingClass, MethodTree methodTree)
Description copied from interface:JavaFileScannerContext
Computes the list of syntax nodes which are contributing to increase the complexity for the given methodTree.- Specified by:
getMethodComplexityNodes
in interfaceJavaFileScannerContext
- Parameters:
enclosingClass
- not used.methodTree
- the methodTree to compute the complexity.- Returns:
- the list of syntax nodes incrementing the complexity.
-
-