Java Reference
In-Depth Information
constraint within type hierarchy , determines that the search should be also
made within the class hierarchy of the type being matched. It has sense only when
the variable's target is restricted to a particular type name.
The Occurrences count constraints dictate how many sequential elements (in
a parameter, declaration or statement list) a variable can include and whether a
variable is required to be present in a pattern. By default, both the minimum
and maximum counts are set to 1, meaning only a single symbol should match
the variable.
The Expression constraints allow you to apply semantic conditions to the
search. For example, you can find all the instances where the symbol is read or
written to. Other options in this group work in a similar way to those available for
the text constraints.
The final option, This variable is the target of the search , lets you tell the
search engine that the matches against the current variable are what you wanted
reported in the search results. Otherwise, the default behavior of matches against
the entire search template are in effect.
Replacing structurally
The command Search | Replace Structurally ( Ctrl+Shft+M ) expands the
search capabilities by allowing you to perform replacements on the matches auto-
matically. It adds a Replacement template field to the search interface in which
you specify the replacement code to be generated (see figure 9.11). You can use
any of the variables from the search template to design your replacement code.
This lets you use SSR as a powerful refactoring tool.
Let's take as an example a refactoring operation where a class has changed
from using static utility methods to a singleton pattern. For instance, the method
XmlUtils.removeNode() has become XmlUtils.getInstance().removeNode() . To
accomplish this replacement, you use the following search template
XmlUtils.$MethodCall$($Params$)
and this replacement template:
XmlUtils.getInstance().$MethodCall$($Params$)
For constraints, you also need to set the minimum count of the $Params$ variable
to 0, to account for methods with no arguments, and the maximum count to a
huge value. Otherwise, with the default values of 1 and 1, you'll only match meth-
ods with single arguments. If necessary, you can use the fully qualified name of
the target class in the search template, as well.
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search