Package org.sonar.javascript.se
Class SeCheck
- java.lang.Object
-
- org.sonar.javascript.se.SeCheck
-
- All Implemented Interfaces:
JavaScriptCheck
public class SeCheck extends Object implements JavaScriptCheck
Extend this class to implement a new check based on symbolic execution.
-
-
Constructor Summary
Constructors Constructor Description SeCheck()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description PreciseIssueaddIssue(Tree tree, String message)Returns new issue which is instance ofPreciseIssue.<T extends Issue>
TaddIssue(T issue)Use this method only to add specific kind of issue.LineIssueaddLineIssue(Tree tree, String message)Deprecated.voidafterBlockElement(ProgramState currentState, Tree element)Override this method to perform actions after executingelement.voidbeforeBlockElement(ProgramState currentState, Tree element, ProgramPoint programPoint)Override this method to perform actions before executingelement.voidcheckConditions(Map<Tree,Collection<Constraint>> conditions)Override this method to check the constraints on conditions (TRUTHY or FALSY) in current execution (aka function scope).voidcleanupAndStartFileAnalysis(ScriptTree scriptTree)voidendOfExecution(Scope functionScope)Override this method to perform actions when the execution is finished.voidendOfFile(ScriptTree scriptTree)TreeVisitorContextgetContext()List<Issue>scanFile(TreeVisitorContext context)voidsetContext(TreeVisitorContext context)voidstartOfExecution(Scope functionScope)Override this method to perform actions before the start of execution.protected voidstartOfFile(ScriptTree scriptTree)Override this method to perform actions before any analysis is performedStringtoString()
-
-
-
Method Detail
-
checkConditions
public void checkConditions(Map<Tree,Collection<Constraint>> conditions)
Override this method to check the constraints on conditions (TRUTHY or FALSY) in current execution (aka function scope). This method is called after end of execution. Note that it's not called if execution was not finished due reaching the execution limit.
-
beforeBlockElement
public void beforeBlockElement(ProgramState currentState, Tree element, ProgramPoint programPoint)
Override this method to perform actions before executingelement. This method is called before each element until end of execution or reaching the execution limit.- Parameters:
currentState- current state at the program point precedingelementelement- syntax tree to be executed nextprogramPoint- current programPoint associated to the element
-
afterBlockElement
public void afterBlockElement(ProgramState currentState, Tree element)
Override this method to perform actions after executingelement. This method is called after each element until end of execution or reaching the execution limit.- Parameters:
currentState- current state at the program point followingelementelement- last executed syntax tree
-
cleanupAndStartFileAnalysis
public void cleanupAndStartFileAnalysis(ScriptTree scriptTree)
-
startOfFile
protected void startOfFile(ScriptTree scriptTree)
Override this method to perform actions before any analysis is performed- Parameters:
scriptTree- the scriptTree that is going to be analyzed
-
endOfFile
public void endOfFile(ScriptTree scriptTree)
-
endOfExecution
public void endOfExecution(Scope functionScope)
Override this method to perform actions when the execution is finished. This method is called for each execution, i.e. for each function in the file. Note this method is not called if the execution limit was reached.- Parameters:
functionScope- scope corresponding to the function which was executed
-
startOfExecution
public void startOfExecution(Scope functionScope)
Override this method to perform actions before the start of execution. This method is called for each execution, i.e. for each function in the file. Note this method is called even if the execution limit was reached later.- Parameters:
functionScope- scope corresponding to the function which will be executed
-
addLineIssue
@Deprecated public LineIssue addLineIssue(Tree tree, String message)
Deprecated.Description copied from interface:JavaScriptCheckReturns new issue which is located on first line oftree- Specified by:
addLineIssuein interfaceJavaScriptCheck
-
addIssue
public PreciseIssue addIssue(Tree tree, String message)
Description copied from interface:JavaScriptCheckReturns new issue which is instance ofPreciseIssue. Then you can chain this method with following method calls to provide more information about issue:PreciseIssue.secondary(Tree, String),PreciseIssue.secondary(Tree)(without message) orPreciseIssue.secondary(IssueLocation)to add secondary locationPreciseIssue.cost(double)to add cost
See example
To create new issue you also can usenewIssue(functionDeclaration, "Remove this function declaration") .secondary(call, "Function call") .secondary(redefinition, "Function redefinition") .cost(functionDeclaration.parameters().parameters().size());JavaScriptCheck.addIssue(Issue):getContext().addIssue(new FileIssue(this, "Some message"))
- Specified by:
addIssuein interfaceJavaScriptCheck- Parameters:
tree- primary location of issuemessage- primary message- Returns:
- new issue
-
addIssue
public <T extends Issue> T addIssue(T issue)
Description copied from interface:JavaScriptCheckUse this method only to add specific kind of issue. E.g. you can use this method to add issue on file level, line issue or precise issue with sophisticated primary location.Otherwise please use
JavaScriptCheck.addIssue(Tree, String)- Specified by:
addIssuein interfaceJavaScriptCheck
-
scanFile
public List<Issue> scanFile(TreeVisitorContext context)
- Specified by:
scanFilein interfaceJavaScriptCheck
-
setContext
public void setContext(TreeVisitorContext context)
-
getContext
public TreeVisitorContext getContext()
-
-