public class Matcher extends Object implements Cancellable
Pattern
.Modifier and Type | Method and Description |
---|---|
boolean |
cancel() |
static Matcher |
create(CompilationInfo info)
Create the Matcher for the given
CompilationInfo . |
Collection<? extends Occurrence> |
match(Pattern pattern)
Search for occurrences of the given pattern in the given subject tree.
|
Matcher |
setCancel(AtomicBoolean cancel)
Make the matching cancelable by setting
true to the given AtomicBoolean . |
Matcher |
setKeepSyntheticTrees()
When set, trees (like implicit receivers) that are not in the source code,
but have variable in the pattern, will get a synthetic entry in variables.
|
Matcher |
setPresetVariable(Map<String,TreePath> variables,
Map<String,Collection<? extends TreePath>> multiVariables,
Map<String,String> variables2Names)
Preset values of free variables in the pattern (see
Pattern.createPatternWithFreeVariables(com.sun.source.util.TreePath, java.util.Map) ). |
Matcher |
setSearchRoot(TreePath root)
Search for the occurrences only under the given tree.
|
Matcher |
setTreeTopSearch()
The matcher should perform the tree-top search: the occurrence of the pattern must correspond directly
to the search root.
|
Matcher |
setUntypedMatching()
The matching should ignore type attributes on the trees.
|
@NonNull public static Matcher create(@NonNull CompilationInfo info)
CompilationInfo
. See the set methods for default
settings of the Matcher.info
- for which the Matcher should be created@NonNull public Matcher setSearchRoot(@NonNull TreePath root)
CompilationUnitTree
of the given CompilationInfo
is used.root
- where to start the search@NonNull public Matcher setTreeTopSearch()
@NonNull public Matcher setUntypedMatching()
@NonNull public Matcher setKeepSyntheticTrees()
@NonNull public Matcher setPresetVariable(@NonNull Map<String,TreePath> variables, @NonNull Map<String,Collection<? extends TreePath>> multiVariables, @NonNull Map<String,String> variables2Names)
Pattern.createPatternWithFreeVariables(com.sun.source.util.TreePath, java.util.Map)
).
A tree node will be marked as an occurrence of the pattern only if the subtree
corresponding to a specified free variable will match the given value.
By default, no values are preset for any variables.variables
- multiVariables
- variables2Names
- @NonNull public Matcher setCancel(@NonNull AtomicBoolean cancel)
true
to the given AtomicBoolean
.cancel
- AtomicBoolean
which should be set to true
to stop the matching as soon as possible@NonNull public Collection<? extends Occurrence> match(Pattern pattern)
pattern
- for which the search should be performedpublic boolean cancel()
cancel
in interface Cancellable