[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
RE: [cdt-dev] Problem when I want to find the source range of a f unction in .c file!
|
At first glance this look fine, can you drop in the debugger
And see where the exception is coming from, thanks.
You many want to drop a PR, we are a little tied right now
But ...
> -----Original Message-----
> From: cdt-dev-bounces@xxxxxxxxxxx [mailto:cdt-dev-bounces@xxxxxxxxxxx] On
> Behalf Of pengsong@xxxxxxxxxxxxxx
> Sent: Thursday, July 07, 2005 11:11 PM
> To: CDT Eclipse
> Subject: [cdt-dev] Problem when I want to find the source range of a
> function in .c file!
>
> I am trying to open a .c file in CEditor and select the source code of a
> certain function. The code are as follows:
>
> try{
> IFile file =
> fFile.getProject().getFile("main.c");//fFile list the files' names in the
> same CProject
>
> Object element =
> CoreModel.getDefault().create(file);
> if ( element instanceof ITranslationUnit ) {
> try{
> ICElement element2 =
> ((ITranslationUnit)element).getElement("main");
> if (element2
instanceof
> IFunction || element2 instanceof IMethod){
>
ISourceRange
> sourceRange = ((IDeclaration)element2).getSourceRange();
> if (
sourceRange !=
> null ) {
>
charStart =
> sourceRange.getStartPos();
>
charEnd =
> charStart + sourceRange.getLength();
>
if ( charEnd
> <= 0 ) {
>
> charStart = 0;
>
charEnd
> = 0;
>
}
> }
> }
> }
> catch( CModelException ce )
> {ce.printStackTrace();}
> (ITranslationUnit)element;
> }
>
> IEditorPart iep = IDE.openEditor(getPage(),
file,
> "org.eclipse.cdt.ui.editor.CEditor");
>
> if(iep instanceof CEditor){
>
((CEditor)iep).selectAndReveal(charStart,
> charEnd);
> }
>
> }
> catch(PartInitException pie){
> pie.printStackTrace();
> }
>
> but when I execute this code, I get:
>
> Unhandled event loop exception
> Reason:
> org/eclipse/cdt/core/model/CoreModel
>
> I wonder how to deal with this problem. Thank you!
>
> _______________________________________________
> cdt-dev mailing list
> cdt-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/cdt-dev