[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [cdt-dev] How to open a file at a particular function
|
I'm pretty sure you'll find similar code in the Open Declaration
implementation...
Doug Schaefer, QNX Software Systems
Eclipse CDT Project Lead, http://cdtdoug.blogspot.com
> -----Original Message-----
> From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On
> Behalf Of subs
> Sent: Wednesday, November 14, 2007 2:38 PM
> To: CDT General developers list.
> Subject: Re: [cdt-dev] How to open a file at a particular function
>
> Here's some code that shows how I did it, in case anybody is interested:
>
> public void findFunctionInSource(IProject project, String
> functionName) {
> ICProject cProject = CoreModel.getDefault().getCModel().getCProject(
> project.getName());
> IIndexManager manager = CCorePlugin.getIndexManager();
> try {
> index = manager.getIndex(cProject);
> index.acquireReadLock();
> IBinding[] bindings = index.findBindings(
> functionName.toCharArray(), IndexFilter.ALL,
> new NullProgressMonitor());
> for (int binding = 0; binding < bindings.length; binding++)
> {
> if (bindings[binding] instanceof IFunction) {
> IFunction ifunction = (IFunction) bindings[binding];
> IIndexName[] names = index.findNames(ifunction,
> IIndex.FIND_DEFINITIONS);
> for (int j = 0; j < names.length; j++) {
> IIndexFile file = names[j].getFile();
> if (file != null) {
> IIndexFileLocation filelocation = file
> .getLocation();
> String fileName = filelocation.getFullPath();
> }
> IASTFileLocation location = names[j].getFileLocation();
> if (location != null) {
> int .offset = location.getNodeOffset();
> }
> }
> }
> }
>
> } catch (Exception e) {
>
> } finally {
> if (index != null)
> index.releaseReadLock();
> }
> }
>
> Doug Schaefer wrote:
> >> -----Original Message-----
> >> From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-
> bounces@xxxxxxxxxxx] On
> >> Behalf Of subs
> >> Sent: Wednesday, November 14, 2007 12:16 PM
> >> To: CDT General developers list.
> >> Subject: Re: [cdt-dev] How to open a file at a particular
> function
> >>
> >> Phew - I'm there.
> >>
> >> Whilst there are docs for the API, there doesn't seem to be
> anything that
> >> describes *how* to use them. Maybe it is documented in this
> series of
> >> emails?
> >
> > I think you just did ;)
> >
> > Documenting something like this is definitely on my wish list
> for API docs.
> > Not just javadoc, but howto's too.
> >
> >> Anyway, thanks very much for your help - it is very much
> appreciated.
> >>
> >>
> >> Schorn, Markus wrote:
> >>> Line numbers are not stored in the index, you can only
> obtain the
> >>> offset.
> >>> Markus.
> >>>
> >>>> -----Original Message-----
> >>>> From: cdt-dev-bounces@xxxxxxxxxxx
> >>>> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of subs
> >>>> Sent: Mittwoch, 14. November 2007 15:11
> >>>> To: CDT General developers list.
> >>>> Subject: Re: [cdt-dev] How to open a file at a particular
> function
> >>>> Importance: Low
> >>>>
> >>>> Markus,
> >>>>
> >>>> Almost there now...
> >>>>
> >>>> I now get a list of all my functions in an IIndexName[].
> I
> >>>> can get the files
> >>>> they are defined in through IIndexName#getFile(). However,
> >>>> IIndexName#getFileLocation().getStartingLineNumber() always
> >>>> returns zero. The
> >>>> javaDoc (for IASTFileLocation) states "Locations obtained via
> >>>> the index do not
> >>>> have line numbers and return 0".
> >>>>
> >>>> So, (hopefully) one last question: how do obtain the line
> number?
> >>>>
> >>>> Thanks very much for you help so far.
> >>>>
> >>>> Schorn, Markus wrote:
> >>>>> An IBinding does not have a location, you need to obtain
> a name
> >>>>> (declaration or reference) first.
> >>>>> IIndex.findName(IBinding ...) or similar.
> >>>>> Markus.
> >>>>>
> >>>>>> -----Original Message-----
> >>>>>> From: cdt-dev-bounces@xxxxxxxxxxx
> >>>>>> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of subs
> >>>>>> Sent: Mittwoch, 14. November 2007 10:02
> >>>>>> To: CDT General developers list.
> >>>>>> Subject: Re: [cdt-dev] How to open a file at a
> particular function
> >>>>>> Importance: Low
> >>>>>>
> >>>>>> Markus,
> >>>>>>
> >>>>>> OK, I now have an IBinding to my function, but again
> it's not
> >>>>>> obvious how to
> >>>>>> turn this into a source file/line number (or a direct
> way to
> >>>>>> open the source
> >>>>>> file at the line number). I've tried ILinkage, IScope,
> ...
> >>>>>>
> >>>>>> Thanks again.
> >>>>>>
> >>>>>> Schorn, Markus wrote:
> >>>>>>> Far from obvious:
> >>>>>>> CoreModel.getDefault().getCModel().getCProject(..
> >>>>>>> Markus.
> >>>>>>>> -----Original Message-----
> >>>>>>>> From: cdt-dev-bounces@xxxxxxxxxxx
> >>>>>>>> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of subs
> >>>>>>>> Sent: Dienstag, 13. November 2007 22:07
> >>>>>>>> To: CDT General developers list.
> >>>>>>>> Subject: Re: [cdt-dev] How to open a file at a
> >>>> particular function
> >>>>>>>> Importance: Low
> >>>>>>>>
> >>>>>>>> Markus,
> >>>>>>>>
> >>>>>>>> I've just come to implement this - thanks for the
> pointer.
> >>>>>>>>
> >>>>>>>> One question - how do I convert an IProject (which I
> have
> >>>>>>>> readily available at
> >>>>>>>> debug time) into its corresponding ICProject?
> >>>>>>>>
> >>>>>>>> Thanks
> >>>>>>>>
> >>>>>>>> Schorn, Markus wrote:
> >>>>>>>>> You should use the interface
> >>>>>> org.eclipse.cdt.core.index.IIndex. It's
> >>>>>>>>> experimental API but most likely it will only be
> extended,
> >>>>>>>> not changed.
> >>>>>>>>> The interfaces for accessing the index are well
> documented.
> >>>>>>>> Many of the
> >>>>>>>>> testcases in CDT illustrate how to use them,
> >>>>>>>>> e.g.: org.eclipse.cdt.internal.index.tests.IndexBugsTests
> >>>>>>>>> Markus.
> >>>>>>>>>
> >>>>>>>>>> -----Original Message-----
> >>>>>>>>>> From: cdt-dev-bounces@xxxxxxxxxxx
> >>>>>>>>>> [mailto:cdt-dev-bounces@xxxxxxxxxxx] On Behalf Of subs
> >>>>>>>>>> Sent: Mittwoch, 17. Oktober 2007 22:11
> >>>>>>>>>> To: CDT General developers list.
> >>>>>>>>>> Subject: [cdt-dev] How to open a file at a particular
> function
> >>>>>>>>>> Importance: Low
> >>>>>>>>>>
> >>>>>>>>>> Hi,
> >>>>>>>>>>
> >>>>>>>>>> Given a function or method name (as a String), how
> can I
> >>>>>>>>>> locate the file it is
> >>>>>>>>>> defined in and open that file at the function
> definition? Any
> >>>>>>>>>> pointers to code,
> >>>>>>>>>> snippets or docs would be very useful.
> >>>>>>>>>>
> >>>>>>>>>> Thanks
> >>>>>>>>>>
> >>>>>>>>>> --
> >>>>>>>>>> Derek
> >>>>>>>>>>
> >>>>>>>>>> --
> >>>>>>>>>> Derek
> >>>>>>>>>> _______________________________________________
> >>>>>>>>>> cdt-dev mailing list
> >>>>>>>>>> cdt-dev@xxxxxxxxxxx
> >>>>>>>>>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>>>>>>>>>
> >>>>>>>>> _______________________________________________
> >>>>>>>>> cdt-dev mailing list
> >>>>>>>>> cdt-dev@xxxxxxxxxxx
> >>>>>>>>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>>>>>>>>
> >>>>>>>> --
> >>>>>>>> Derek
> >>>>>>>> _______________________________________________
> >>>>>>>> cdt-dev mailing list
> >>>>>>>> cdt-dev@xxxxxxxxxxx
> >>>>>>>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>>>>>>>
> >>>>>>> _______________________________________________
> >>>>>>> cdt-dev mailing list
> >>>>>>> cdt-dev@xxxxxxxxxxx
> >>>>>>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>>>>>>
> >>>>>> --
> >>>>>> Derek
> >>>>>> _______________________________________________
> >>>>>> cdt-dev mailing list
> >>>>>> cdt-dev@xxxxxxxxxxx
> >>>>>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>>>>>
> >>>>> _______________________________________________
> >>>>> cdt-dev mailing list
> >>>>> cdt-dev@xxxxxxxxxxx
> >>>>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>>>>
> >>>> --
> >>>> Derek
> >>>> _______________________________________________
> >>>> cdt-dev mailing list
> >>>> cdt-dev@xxxxxxxxxxx
> >>>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>>>
> >>> _______________________________________________
> >>> cdt-dev mailing list
> >>> cdt-dev@xxxxxxxxxxx
> >>> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >>>
> >> --
> >> Derek
> >> _______________________________________________
> >> cdt-dev mailing list
> >> cdt-dev@xxxxxxxxxxx
> >> https://dev.eclipse.org/mailman/listinfo/cdt-dev
> > _______________________________________________
> > cdt-dev mailing list
> > cdt-dev@xxxxxxxxxxx
> > https://dev.eclipse.org/mailman/listinfo/cdt-dev
> >
>
> --
> Derek
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev