Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
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
Teemu Kanstren is currently offline Teemu KanstrenFriend
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 messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
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 messageGo to next message
Eclipse UserFriend
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 messageGo to next message
Teemu Kanstren is currently offline Teemu KanstrenFriend
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
Jerome Lanneluc is currently offline Jerome LannelucFriend
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..
> > >
> > >
> >
> >
>
>
Previous Topic:Closing views on platform shutdown
Next Topic:Bugzilla, I kill you!!
Goto Forum:
  


Current Time: Fri Apr 26 11:38:03 GMT 2024

Powered by FUDForum. Page generated in 0.03210 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top