Package edu.umd.cs.findbugs.ba.bcp
Class PatternElement
java.lang.Object
edu.umd.cs.findbugs.ba.bcp.PatternElement
- Direct Known Subclasses:
Invoke
,MatchAny
,Opcode
,SingleInstruction
,Wild
A PatternElement is an element of a ByteCodePattern. It potentially matches
some number of bytecode instructions.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract boolean
acceptBranch
(Edge edge, org.apache.bcel.generic.InstructionHandle source) Return whether or not it is acceptable to take the given branch.protected static BindingSet
addOrCheckDefinition
(String varName, Variable variable, BindingSet bindingSet) Add a variable definition to the given BindingSet, or if there is an existing definition, make sure it is consistent with the new definition.boolean
Return whether or not this PatternElement may match trailing edges.dominatedBy
(String dominatedBy) Set the label of another pattern element whose first matched instruction must dominate the instruction(s) matched by this element.Get the label of the pattern element whose first matched instruction must dominate the instruction(s) matched by this element.getLabel()
Get the label of this PatternElement.getNext()
Get the next PatternElement.Set a label for this PatternElement.static Variable
lookup
(String varName, BindingSet bindingSet) Look up a variable definition in given BindingSet.abstract MatchResult
match
(org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) Return whether or not this element matches the given instruction with the given Bindings in effect.abstract int
maxOccur()
Return the maximum number of instructions this PatternElement must match in the ByteCodePattern.abstract int
minOccur()
Return the minimum number of instructions this PatternElement must match in the ByteCodePattern.setAllowTrailingEdges
(boolean allowTrailingEdges) Set whether or not this PatternElement allows trailing edges to be matched.void
setIndex
(int index) Set the index.void
setNext
(PatternElement patternElement) Set the next PatternElement.toString()
-
Constructor Details
-
PatternElement
public PatternElement()
-
-
Method Details
-
getNext
Get the next PatternElement. -
setNext
Set the next PatternElement. -
label
Set a label for this PatternElement.- Parameters:
label
- the label- Returns:
- this object
-
getLabel
Get the label of this PatternElement.- Returns:
- the label, or null if the PatternElement is not labeled
-
dominatedBy
Set the label of another pattern element whose first matched instruction must dominate the instruction(s) matched by this element. -
getDominatedBy
Get the label of the pattern element whose first matched instruction must dominate the instruction(s) matched by this element. -
setIndex
public void setIndex(int index) Set the index. This is just for debugging. -
setAllowTrailingEdges
Set whether or not this PatternElement allows trailing edges to be matched. By default, trailing edges may be matched. When this value is set to false, it ensures that the successor instruction must be in the same basic block.- Parameters:
allowTrailingEdges
- true if trailing edges may be matched, false if trailing edges will never be matched
-
allowTrailingEdges
public boolean allowTrailingEdges()Return whether or not this PatternElement may match trailing edges. -
lookup
Look up a variable definition in given BindingSet.- Parameters:
varName
- the name of the variablebindingSet
- the BindingSet to look in- Returns:
- the Variable, or null if no Variable is bound to the name
-
match
@CheckForNull public abstract MatchResult match(org.apache.bcel.generic.InstructionHandle handle, org.apache.bcel.generic.ConstantPoolGen cpg, ValueNumberFrame before, ValueNumberFrame after, BindingSet bindingSet) throws DataflowAnalysisException Return whether or not this element matches the given instruction with the given Bindings in effect.- Parameters:
handle
- the instructioncpg
- the ConstantPoolGen from the methodbefore
- the ValueNumberFrame representing values in the Java stack frame just before the execution of the instructionafter
- the ValueNumberFrame representing values in the Java stack frame just after the execution of the instructionbindingSet
- the set of Bindings- Returns:
- if the match is successful, returns a MatchResult with the PatternElement and BindingSet; if the match is not successful, returns null
- Throws:
DataflowAnalysisException
-
acceptBranch
Return whether or not it is acceptable to take the given branch.- Parameters:
edge
- the Edge representing the branchsource
- the source instruction of the branch- Returns:
- true if the Edge is acceptable, false if not
-
minOccur
public abstract int minOccur()Return the minimum number of instructions this PatternElement must match in the ByteCodePattern. -
maxOccur
public abstract int maxOccur()Return the maximum number of instructions this PatternElement must match in the ByteCodePattern. -
addOrCheckDefinition
protected static BindingSet addOrCheckDefinition(String varName, Variable variable, BindingSet bindingSet) Add a variable definition to the given BindingSet, or if there is an existing definition, make sure it is consistent with the new definition.- Parameters:
varName
- the name of the variablevariable
- the Variable which should be added or checked for consistencybindingSet
- the existing set of bindings- Returns:
- the updated BindingSet (if the variable is consistent with the previous bindings), or null if the new variable is inconsistent with the previous bindings
-
toString
-