public class MethodUsageEvent extends UsageEvent
MethodUsageEvent
describes the information
about a method usage that is reported through the
MethodUsageListener. It contains the URL, the start/end
offsets of the usage, and a usage code describing the location
the usage occurred, such as the method declaration. Usage will return as usages, method declarations for the search method down the class hierarchy only. In general, it is expected that searches will be performed on classes or interfaces that are highest up in the inheritance graph where the method is first declared or defined. Therefore, method declarations or invocations on methods in superclasses or superinterfaces will not be reported by this usage engine.
For example (A), if you search for AbstractList.addAll( Collection ), the usage verifier will return USAGE_METHOD_DECLARATION hits for the following:
AbstractList.addAll( Collection ) ArrayListList.addAll( Collection ) ...It will not return hits for the same method in the following superclasses or superinterfaces:
Collection.addAll( Collection ) List.addAll( Collection ) AbstractCollection.addAll( Collection )As another example (B), if you search for AbstractList.iterator(), the usage verifier will return USAGE_METHOD_DECLARATION hits for the following:
AbstractList.iterator()but not for the same method in the following superclasses or superinterfaces:
Collection.iterator() List.iterator() AbstractCollection.iterator()Note that static methods cannot be overridden, so if a subclass declares a static method with the same signature, it will not be reported as a usage hit.
Similar to DECLARATION behavior above, usage will return as usages, method invocations for the search method down the class hierarchy only. Again it is expected that searches will be performed on classes or interfaces that are highest up on the inheritance graph where the method is first declared or defined.
What is different about INVOCATION, is that (for instance methods anyways), there is a declared (or implicit "this") object (primary) involved that the method is invoked upon. So the usage constant reported describes the relationship of the invocation object (primary) class to the search class of the method.
If the primary class is above the search class in the inheritance graph, then the usage hit will not be reported. If the primary class is the search class, or one of its subclasses or subinterfaces, then it will be reported as a valid hit.
For example (C), suppose you were searching for invocations of List.size(), the usage verifier will return USAGE_METHOD_INVOCATION hits for the following:
List list, list->size() ArrayList alist, alist->size()but not for the same method in the following superinterface:
Collection col, col->size()Similarly, in the following example (D), suppose you were searching for invocations of JTextComponent.getText(), the usage verifier would return USAGE_METHOD_INVOCATION hits for the following:
JTextComponent tc, tc->getText() Within JEditorPane, super->getText() JEditorPane ed, ed->getText()Static methods cannot be overridden, so usage will only report hits for actual inocations of the static method. This is because static invocations of methods are based only on the declared primary class, not on what the actual underlying object class is.
Modifier and Type | Field and Description |
---|---|
static int |
USAGE_METHOD_DECLARATION
Constant indicating that the usage is a method declaration in
the search class, or one of its descendants in its class
hierarchy.
|
static int |
USAGE_METHOD_INVOCATION
Constant indicating that the method invocation is on a primary
class that is the search class, or one of its descendants in
its class hierarchy.
|
_endOffset, _source, _startOffset, _url, _usageCode, USAGE_CANCELLED, USAGE_FAILED, USAGE_FINISHED, USAGE_KEYWORD_SKIPPED, USAGE_URL_SKIPPED
Constructor and Description |
---|
MethodUsageEvent(UsageQueryTask source,
int usageCode,
java.net.URL url,
int startOffset,
int endOffset)
Construct a new usage event.
|
Modifier and Type | Method and Description |
---|---|
protected java.lang.String |
usageCodeToString(int code)
Return a human-readable version of the usage code.
|
getEndOffset, getSource, getStartOffset, getURL, getUsageCode, toString
public static final int USAGE_METHOD_DECLARATION
public static final int USAGE_METHOD_INVOCATION
public MethodUsageEvent(UsageQueryTask source, int usageCode, java.net.URL url, int startOffset, int endOffset)
source
- the query taskusageCode
- the usage code describing this eventurl
- the URL where the event occurredstartOffset
- the starting offsetendOffset
- the ending offsetprotected java.lang.String usageCodeToString(int code)
usageCodeToString
in class UsageEvent
code
- the usage code