getContextNamestring getContextName()
Returns context name. Dictionaries: C,C++ and C++Text Return type: string Example: Code Block |
---|
def test(node, context):
enforcercontext = context.getParentContext()
context.report(enforcercontext.getContextName())
return 1 |
executeRuleint executeRule(string textRuleName, NodeProvider node)
Returns 1 if the called text rule returns true. Return type: int Parameters: string textRuleName | Path and name of text rule |
---|
NodeProvider node | Node determines the point where text rule will be invoked |
---|
Example: Code Block |
---|
def test(node, context):
ruleenforcercontext = node.getEnforcer()
#call text rule in the line from node and in default: first column
ret = ruleenforcercontext.executeRule("./my_text_rule.rule", node)
return ret |
executeRuleEx int executeRuleEx(string textRuleName, NodeProvider node, string fileName, int line, int column)
Returns 1 if the called text rule returns true. Dictionaries: C,C++ and C++Text Return type: int Parameters: string textRuleName | Path and name of text rule |
---|
NodeProvider node | Node determines the point where text rule will be invoked |
---|
string fileName | Name of source file |
---|
int line | Starting line number from which the text rule will be invoked. If -1 , the call child rule will be skipped. |
---|
int column | Starting column number from which the text rule will be invoked. If -1 , the call child rule will be skipped. |
---|
Example: Code Block |
---|
def test(node, context):
ruleenforcercontext = node.getEnforcer()
file = node.getProperty("pathname")
line = node.getLine()
colum = node.getColumn()
ret = ruleenforcercontext.executeRuleEx("./txt.rule", node, filename, line, colum)
return ret |
executeRegexpint executeRegexp(string regExp, NodeProvider node)
Calls a regExp on the current source file in the line specified in the node. Dictionaries: C,C++ and C++Text Return type: int Parameters: string regExp | Regular expression string |
---|
NodeProvider node | Node is used to determine the line for which the regExp is called |
---|
Example: Code Block |
---|
def test(node, context):
ruleenforcercontext = node.getEnforcer()
#return 1 if there is cpp style comment in the line from node
ret = ruleenforcercontext.executeRegexp("\/\/",node)
return ret |
executeRegexpExint executeRegexpEx(string regExp, string filename, int start_line, int op_start_column, int op_end_line, int op_end_column)
Calls a regExp on source file $filename in the region defined by $start_line $op_start_column $op_end_lin $op_end_column Dictionaries: C,C++ and C++Text Return type: int Parameters: string regExp | Regular expression string |
---|
string fileName | Name of source file |
---|
int start_line | Starting line number. |
---|
int op_start_column | Starting column number (optional). Available value(s): - "each column number in the given line; default value '-1' means first column in line" ( c++ dictionary , applies to: )
- "each column number in the given line; default value '-1' means first column in line" ( c++text dictionary , applies to: )
|
---|
int op_end_line | Defined end line (optional). Available value(s): - "each line number for the given source file; default value '-1' means the same value like start line" ( c++ dictionary , applies to: )
- "each line number for the given source file; default value '-1' means the same value like start line" ( c++text dictionary , applies to: )
|
---|
int op_end_column | Defined end column (optional). Available value(s): - "each column number in the given line; default value '-1' means last column in line" ( c++ dictionary , applies to: )
- "each column number in the given line; default value '-1' means last column in line" ( c++text dictionary , applies to: )
|
---|
Example: Code Block |
---|
def test(node, context):
ruleenforcercontext = node.getEnforcer()
line = node.getLine()
file = node.getProperty("pathname")
#return 1 if there is cpp style comment in next line given from node
ret = ruleenforcercontext.executeRegexpEx("\/\/", file, line+1)
return ret |
putput(string key, string value)
Saves the key value inside the context. Dictionaries: C,C++ and C++Text Return type: none Parameters: string key | name of the key |
---|
string value | value of the key |
---|
Example: Code Block |
---|
| def test(node, context):
ruleenforcercontext = context.getParentContext()
ruleenforcercontext.put("color","red")
return 1 |
getstring get(string key)
Gets the key value from the context. Dictionaries: C,C++ and C++Text Return type: string Parameters: string key | name of the key |
---|
Example: Code Block |
---|
| def test(node, context):
ruleenforcercontext = context.getParentContext()
ruleenforcercontext.put("color","red")
context.report(ruleenforcercontext.get("color"))
return 1 |
getKeysList getKeys()
Gets a list of keys stored in the context. Dictionaries: C,C++ and C++Text Return type: list Example: Code Block |
---|
| def test(node, context):
ruleenforcercontext = context.getParentContext()
ruleenforcercontext.put("color","red")
ruleenforcercontext.put("size","big")
context.report(ruleenforcercontext.getKeys())
return 1 |
clearclear ()
Removes all keys stored in the context. Dictionaries: C,C++ and C++Text Return type: none Example: Code Block |
---|
| def test(node, context):
ruleenforcercontext = context.getParentContext()
ruleenforcercontext.put("color","red")
txt1 = ruleenforcercontext.get("color")
ruleenforcercontext.clear()
txt2 = ruleenforcercontext.get("color")
context.report("Before clear: " + txt1 + " After clear: " + str(txt2))
return 1 |
|