Re: [mdr-users] Newbie: correct way to find usages of one class by another
Martin Matula <[email protected]>
| Newsgroups | gmane.comp.java.netbeans.modules.mdr.user |
|---|---|
| Message-ID | <[email protected]> |
Hi Richard,
the MultipartIds returned from the collection represent the identifiers
in the source code. You can go up via the containment hierarchy to
navigate to the parent feature (class member) they are used in. To
navigate to a container element use refImmediateComposite() - you can go
up using this method until the result is instance of Feature.
Here is how it works - if your source code looks like:
class Foo implements com.foo.MyClass {
}
and you are looking for usages of com.foo, you will get (as one of the
references) the com.foo identifier in the implements clause. When you go
to its container (using refImmediateComposite()) you will get
com.foo.MyClass. Then from that you get to the container of
com.foo.MyClass, which is Foo class - class is an instance of Feature,
so you are done.
There are two exceptions when MultipartId is not part of any feature -
1) when it is part of the import statement (e.g. "import
com.foo.MyClass") and when it is part of the package statement ("package
com.foo").
Regards,
Martin
Richard Kennard wrote:
>Martin,
>
>Thanks for that: I deleted the 'mdrstorage' folder and it seems to run okay.
>However, my problem now is I cannot make head nor tail of what is returned?
>
>If I do:
>
> JavaClass myClass = ...resolve class...( "com.foo" );
>
> myClass.getReferences();
>
>I get back a collection of ElementReferences, but any which way I try to use
>these ElementReferences (I've tried toString(), getName(), getElement(),
>getElement().getType().getName()) they only seem to ever return information
>about 'com.foo', not the classes that are referencing it! All the
>ElementReferences are of type MultipartId$Impl?
>
>How am I supposed to use the collection returned by getReferences() to
>determine who is referencing my class?
>
>Many thanks for all your help over the months,
>
>Richard.
>
>-----Original Message-----
>From: Martin Matula [mailto:[email protected]]
>Sent: Wednesday, 1 June 2005 6:23 AM
>To: [email protected]
>Subject: Re: [mdr-users] Newbie: correct way to find usages of one class by
>another
>
>
>Hm. I think I've never seen such error. Try to clean
>$nbuserdir/var/cache/mdrstorage dir and run your code again. If you get
>the same behavior consistently, please file a new issue in issuezilla
>and provide any information you can (at least attach your messages.log
>from $nbuserdir/var/log/).
>Thanks,
>Martin
>
>Richard Kennard wrote:
>
>
>
>>Martin,
>>
>>Whenever I try to use the Collection returned from
>>JavaClass.getReference I
>>get:
>>
>>org.netbeans.mdr.util.DebugException: Invalid key
>> at
>>org.netbeans.mdr.storagemodel.MdrStorage.getObjectsFromIndex(MdrStorage
>>.java
>>:725)
>> at
>>org.netbeans.mdr.storagemodel.IndexImmutSet.getObjects(IndexImmutSet.java:6
>>
>>
>6
>
>
>>)
>> at
>>org.netbeans.mdr.storagemodel.IndexImmutSet.toArray(IndexImmutSet.java:101)
>> at
>>org.netbeans.mdr.handlers.IndexSetWrapper.toArray(IndexSetWrapper.java:129)
>> at java.util.ArrayList.<init>(ArrayList.java:137)
>>
>>I have tried this with a couple of different JavaClass', and besides
>>the error looks like it isn't something that should be in production
>>code?
>>
>>Any help would be greatly appreciated,
>>
>>Thanks,
>>
>>Richard.
>>
>>-----Original Message-----
>>From: Martin Matula [mailto:[email protected]]
>>Sent: Tuesday, 24 May 2005 6:55 AM
>>To: [email protected]
>>Cc: [email protected]
>>Subject: Re: [mdr-users] Newbie: correct way to find usages of one class by
>>another
>>
>>
>>[Cross posting to refactoring mailing list since it's more appropriate
>>for this kind of questions...]
>>
>>Richard Kennard wrote:
>>
>>
>>
>>
>>
>>>Dear All,
>>>
>>>What is the correct way to find all usages of, say, a class 'Foo'?
>>>
>>>If I construct a WhereUsedQuery and pass it a JavaClass of Foo, I only
>>>get back usages of its constructor (and static enums and the like).
>>>
>>>
>>>
>>>
>>>
>>>
>>That's weird, WhereUsedQuery should work (otherwise the Find Usages
>>feature would not work). Anyway, if you want to find usages
>>programmatically, it is better to call JavaClass.getReferences()
>>(WhereUsedQuery is kind of heavy-weight, since it wraps the results by
>>RefactoringElements).
>>Regards,
>>Martin
>>
>>
>>
>>
>>
>>
>>
>
>
>
>