Home » Eclipse Projects » Eclipse Platform » Getting references from IType
Getting references from IType [message #163066] |
Thu, 27 November 2003 19:04 ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Teemu Kanstren![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=kibaltsis%40hotmail.com) Messages: 5 Registered: July 2009 |
Junior Member |
|
|
How can I get all references to other types from an IType? I mean things
like class fields, method parameters, local variables, ...
I managed to use SearchEngine to find them, but I could only find the type
name as written in the source. This I managed by getting the compilation
unit and getting the substring between start and end (in a Collector).
However, I would prefer to get a real object that can tell me the fully
qualified name, etc.
For now, I just want to count the number of different types. So just finding
the names would be ok, but if someone imports java.util.List and declares
two variables "List foo" and "java.util.List bar", I will get two
references to java.util.List but with different names..
|
|
|
Re: Getting references from IType [message #163276 is a reply to message #163066] |
Fri, 28 November 2003 12:26 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Jerome Lanneluc![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=jerome_lanneluc%40fr.ibm.com) Messages: 572 Registered: July 2009 |
Senior Member |
|
|
Have you tried SearchEngine.searchDeclarationsOfReferencedTypes(...) passing
the ICompilationUnit as the enclosing element?
Jerome
"Teemu Kanstren" <kibaltsis@hotmail.com> wrote in message
news:bq5hqk$vb$1@eclipse.org...
> How can I get all references to other types from an IType? I mean things
> like class fields, method parameters, local variables, ...
>
> I managed to use SearchEngine to find them, but I could only find the type
> name as written in the source. This I managed by getting the compilation
> unit and getting the substring between start and end (in a Collector).
> However, I would prefer to get a real object that can tell me the fully
> qualified name, etc.
>
> For now, I just want to count the number of different types. So just
finding
> the names would be ok, but if someone imports java.util.List and declares
> two variables "List foo" and "java.util.List bar", I will get two
> references to java.util.List but with different names..
>
>
|
|
|
Re: Getting references from IType [message #163406 is a reply to message #163066] |
Fri, 28 November 2003 18:17 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Eclipse User![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=) |
|
|
|
Originally posted by: pmuse.pmayer.net
Hi Teemu,
> How can I get all references to other types from an IType? I mean things
> like class fields, method parameters, local variables, ...
There is a difference between types,fields,methods on the one hand and
local variables, method parameters (and other smaller elements) etc. on the
other hand. There are no ITypes for the latter, only AST Nodes.
If you parse a compilation unit using
ICompilationUnit current = ...
CompilationUnit cu = AST.parseCompilationUnit(current, true);
you can access the AST Nodes in cu (for example via a Visitor). The "true"
in parseCompilationUnit tells the parser to resolve the information so that
you can get the full qualified name of variable's type etc.
However, I think its not possible to directly convert from I<Something> to
AST<Something>. You have to do it via the whole CompilationUnit.
-phil
|
|
|
Re: Getting references from IType [message #163411 is a reply to message #163276] |
Fri, 28 November 2003 18:41 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) ![Go to next message Go to next message](theme/Solstice/images/down.png) |
Teemu Kanstren![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=kibaltsis%40hotmail.com) Messages: 5 Registered: July 2009 |
Junior Member |
|
|
No, I had not tried that. I now got it working great with that approach.
Thanks a lot !
A small problem; for some reason searchDeclarationsOfReferencedTypes() is
not calling my aboutToStart() and done() methods in the collector. Only the
accept(). Can you think of any reason for this? I can work around it easily
though, so its not such a big deal.
-Teemu
"Jerome Lanneluc" <jerome_lanneluc@fr.ibm.com> wrote in message
news:bq7eps$pfm$1@eclipse.org...
> Have you tried SearchEngine.searchDeclarationsOfReferencedTypes(...)
passing
> the ICompilationUnit as the enclosing element?
>
> Jerome
>
> "Teemu Kanstren" <kibaltsis@hotmail.com> wrote in message
> news:bq5hqk$vb$1@eclipse.org...
> > How can I get all references to other types from an IType? I mean things
> > like class fields, method parameters, local variables, ...
> >
> > I managed to use SearchEngine to find them, but I could only find the
type
> > name as written in the source. This I managed by getting the compilation
> > unit and getting the substring between start and end (in a Collector).
> > However, I would prefer to get a real object that can tell me the fully
> > qualified name, etc.
> >
> > For now, I just want to count the number of different types. So just
> finding
> > the names would be ok, but if someone imports java.util.List and
declares
> > two variables "List foo" and "java.util.List bar", I will get two
> > references to java.util.List but with different names..
> >
> >
>
>
|
|
|
Re: Getting references from IType [message #163908 is a reply to message #163411] |
Mon, 01 December 2003 11:15 ![Go to previous message Go to previous message](theme/Solstice/images/up.png) |
Jerome Lanneluc![Friend of Eclipse Friend](/donate/web-api/friends_decorator.php?email=jerome_lanneluc%40fr.ibm.com) Messages: 572 Registered: July 2009 |
Senior Member |
|
|
This sounds like a bug. I entered
https://bugs.eclipse.org/bugs/show_bug.cgi?id=47787 to investigate.
Jerome
"Teemu Kanstren" <kibaltsis@hotmail.com> wrote in message
news:bq84ru$l33$1@eclipse.org...
> No, I had not tried that. I now got it working great with that approach.
> Thanks a lot !
>
> A small problem; for some reason searchDeclarationsOfReferencedTypes() is
> not calling my aboutToStart() and done() methods in the collector. Only
the
> accept(). Can you think of any reason for this? I can work around it
easily
> though, so its not such a big deal.
>
> -Teemu
>
> "Jerome Lanneluc" <jerome_lanneluc@fr.ibm.com> wrote in message
> news:bq7eps$pfm$1@eclipse.org...
> > Have you tried SearchEngine.searchDeclarationsOfReferencedTypes(...)
> passing
> > the ICompilationUnit as the enclosing element?
> >
> > Jerome
> >
> > "Teemu Kanstren" <kibaltsis@hotmail.com> wrote in message
> > news:bq5hqk$vb$1@eclipse.org...
> > > How can I get all references to other types from an IType? I mean
things
> > > like class fields, method parameters, local variables, ...
> > >
> > > I managed to use SearchEngine to find them, but I could only find the
> type
> > > name as written in the source. This I managed by getting the
compilation
> > > unit and getting the substring between start and end (in a Collector).
> > > However, I would prefer to get a real object that can tell me the
fully
> > > qualified name, etc.
> > >
> > > For now, I just want to count the number of different types. So just
> > finding
> > > the names would be ok, but if someone imports java.util.List and
> declares
> > > two variables "List foo" and "java.util.List bar", I will get two
> > > references to java.util.List but with different names..
> > >
> > >
> >
> >
>
>
|
|
|
Goto Forum:
Current Time: Sat Aug 17 01:21:59 GMT 2024
Powered by FUDForum. Page generated in 0.03366 seconds
|