public abstract class HardCodedLiteralsCheckBase extends CheckImplementationBase
getLiteralRegex()
(if specified) and which
occur in context with an identifier (e.g. assignment, comparison). The
identifier is checked with isMatchingIdentifier(IToken)
.
findAllMatchingLiteral()
can be overwritten if all literals matching
getLiteralRegex()
should produce a finding, regardless of the
context where these occur.
The checks works on pre-processed tokens, thus implementing checks must have
the parameter ECheckParameter.ABSTRACT_SYNTAX_TREE
enabled.Modifier and Type | Field and Description |
---|---|
protected java.util.List<IToken> |
preprocessedTokens
Tokens of the current element, but without comments
|
context
Constructor and Description |
---|
HardCodedLiteralsCheckBase() |
Modifier and Type | Method and Description |
---|---|
void |
execute()
Executes the custom check with the given context.
|
protected boolean |
findAllMatchingLiteral()
Indicates if any literal matching
getLiteralRegex() should be
reported. |
protected abstract java.lang.String |
getFindingsMessageText() |
protected abstract java.lang.String |
getLiteralRegex()
Gets the regular expression against which literals must match.
|
protected abstract boolean |
isMatchingIdentifier(IToken identifier)
Checks if the given identifier matches
|
protected boolean |
isMatchingLiteral(IToken literal) |
protected java.util.Optional<IToken> |
lookupIdentifierIfInCaseWhen(IToken literal)
ABAP Specific function
Performs a lookup for the identifier if the given literal occurs as an WHEN
option inside a CASE/WHEN structure.
|
protected java.util.Optional<IToken> |
lookupIdentifierIfInDefinition(IToken literal)
ABAP Specific function
Performs a lookup for identifier when a literal is assigned with the VALUE
addition.
|
protected java.util.Optional<IToken> |
lookupIdentifierIfInNewStatement(IToken literal)
CLike Specific function
Performs a lookup for the identifier if the given literal occurs as in a NEW
statement.
|
protected java.util.Optional<IToken> |
lookupIdentifierIfInOperation(IToken literal,
boolean leftHandLookup)
Performs a lookup for the identifier, if the given literal is stated within
an operation where on the other side of the operator an identifier is stated
|
protected java.util.Optional<IToken> |
lookupIdentifierIfInProperty(IToken literal)
C# Specific function
Performs a lookup for the identifier if the given literal occurs as an
PROPERTY.
|
createFinding, createFinding, createFinding, createFinding, createFinding, createFinding, createFinding, createFindingForSiblingEntities, createFindingForSiblings, createFindingOnFirstLine, createFindingOnUnfilteredCode, createFindingOnUnfilteredCode, createFindingOnUnfilteredCode, createInstance, createSelectionPattern, getCodeViewOption, initialize, isCpp, select, select, selectUnfilteredPreProcessed, setContext
protected java.util.List<IToken> preprocessedTokens
public HardCodedLiteralsCheckBase()
public void execute() throws CheckException
execute
in class CheckImplementationBase
CheckException
protected boolean isMatchingLiteral(IToken literal)
true
if the literal matches and should be checkedprotected boolean findAllMatchingLiteral()
getLiteralRegex()
should be
reported. Default implementation is false
.protected java.util.Optional<IToken> lookupIdentifierIfInOperation(IToken literal, boolean leftHandLookup)
leftHandLookup
- determines if identifier should be search on the left side,
otherwise it is expected on the right side of the operator.protected java.util.Optional<IToken> lookupIdentifierIfInCaseWhen(IToken literal)
protected java.util.Optional<IToken> lookupIdentifierIfInDefinition(IToken literal)
protected java.util.Optional<IToken> lookupIdentifierIfInProperty(IToken literal)
protected java.util.Optional<IToken> lookupIdentifierIfInNewStatement(IToken literal)
protected abstract java.lang.String getLiteralRegex()
null
any literal matches.protected abstract boolean isMatchingIdentifier(IToken identifier)
protected abstract java.lang.String getFindingsMessageText()