Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Get IProject and IFile from a ICompilationUnit
Get IProject and IFile from a ICompilationUnit [message #112837] Mon, 03 November 2003 01:12 Go to next message
Eclipse UserFriend
Originally posted by: esalbuquerque.superig.com.br

Hello,

how can I get IProject and IFile from a ICompilationUnit or
IWorkingCopyManager ?

For example, from snippet code:

/*********************************************************** ******/
IWorkbenchPage wbp = window.getActivePage();
IEditorPart edt = wbp.getActiveEditor();
IEditorInput ei = edt.getEditorInput();
IWorkingCopyManager mgr = JavaUI.getWorkingCopyManager();

try {
mgr.connect(ei);
ICompilationUnit unit = mgr.getWorkingCopy(ei);
source = unit.getSource();
if (unit == null) {
System.out.print("Nao eh um arq. Java");
return;
} else {
CompilationUnit cUnit = AST.parseCompilationUnit(unit, true);
cUnit.accept(sav);
}
} catch (Throwable e) {
e.printStackTrace();
} finally {
mgr.disconnect(ei);
}
/*********************************************************** ******/

Thanks,
Eduardo Soares Albuquerque
Re: Get IProject and IFile from a ICompilationUnit [message #112976 is a reply to message #112837] Mon, 03 November 2003 11:23 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
ICompilationUnit unit = mgr.getWorkingCopy(ei);
IFile file = (IFile)unit.getResource();
IProject project = unit.getJavaProject().getProject();

"Eduardo Soares Albuquerque" <esalbuquerque@superig.com.br> wrote in message
news:bo4a1r$lm$1@eclipse.org...
> Hello,
>
> how can I get IProject and IFile from a ICompilationUnit or
> IWorkingCopyManager ?
>
> For example, from snippet code:
>
> /*********************************************************** ******/
> IWorkbenchPage wbp = window.getActivePage();
> IEditorPart edt = wbp.getActiveEditor();
> IEditorInput ei = edt.getEditorInput();
> IWorkingCopyManager mgr = JavaUI.getWorkingCopyManager();
>
> try {
> mgr.connect(ei);
> ICompilationUnit unit = mgr.getWorkingCopy(ei);
> source = unit.getSource();
> if (unit == null) {
> System.out.print("Nao eh um arq. Java");
> return;
> } else {
> CompilationUnit cUnit = AST.parseCompilationUnit(unit, true);
> cUnit.accept(sav);
> }
> } catch (Throwable e) {
> e.printStackTrace();
> } finally {
> mgr.disconnect(ei);
> }
> /*********************************************************** ******/
>
> Thanks,
> Eduardo Soares Albuquerque
>
Re: Get IProject and IFile from a ICompilationUnit [message #113168 is a reply to message #112976] Mon, 03 November 2003 14:47 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: esalbuquerque.superig.com.br

> ICompilationUnit unit = mgr.getWorkingCopy(ei);
> IFile file = (IFile)unit.getResource();

file is null... Why ??


Jerome Lanneluc wrote:

> ICompilationUnit unit = mgr.getWorkingCopy(ei);
> IFile file = (IFile)unit.getResource();
> IProject project = unit.getJavaProject().getProject();

> "Eduardo Soares Albuquerque" <esalbuquerque@superig.com.br> wrote in message
> news:bo4a1r$lm$1@eclipse.org...
> > Hello,
> >
> > how can I get IProject and IFile from a ICompilationUnit or
> > IWorkingCopyManager ?
> >
> > For example, from snippet code:
> >
> > /*********************************************************** ******/
> > IWorkbenchPage wbp = window.getActivePage();
> > IEditorPart edt = wbp.getActiveEditor();
> > IEditorInput ei = edt.getEditorInput();
> > IWorkingCopyManager mgr = JavaUI.getWorkingCopyManager();
> >
> > try {
> > mgr.connect(ei);
> > ICompilationUnit unit = mgr.getWorkingCopy(ei);
> > source = unit.getSource();
> > if (unit == null) {
> > System.out.print("Nao eh um arq. Java");
> > return;
> > } else {
> > CompilationUnit cUnit = AST.parseCompilationUnit(unit, true);
> > cUnit.accept(sav);
> > }
> > } catch (Throwable e) {
> > e.printStackTrace();
> > } finally {
> > mgr.disconnect(ei);
> > }
> > /*********************************************************** ******/
> >
> > Thanks,
> > Eduardo Soares Albuquerque
> >
Re: Get IProject and IFile from a ICompilationUnit [message #113178 is a reply to message #113168] Mon, 03 November 2003 15:00 Go to previous messageGo to next message
Jerome Lanneluc is currently offline Jerome LannelucFriend
Messages: 572
Registered: July 2009
Senior Member
From the spec of IJavaElement.getResource():
* If this element is included in an external archive, <code>null</code>
* is returned.

If this is not the case, please enter a bug report.

Jerome

"Eduardo Soares Albuquerque" <esalbuquerque@superig.com.br> wrote in message
news:bo5pqp$e28$1@eclipse.org...
> > ICompilationUnit unit = mgr.getWorkingCopy(ei);
> > IFile file = (IFile)unit.getResource();
>
> file is null... Why ??
>
>
> Jerome Lanneluc wrote:
>
> > ICompilationUnit unit = mgr.getWorkingCopy(ei);
> > IFile file = (IFile)unit.getResource();
> > IProject project = unit.getJavaProject().getProject();
>
> > "Eduardo Soares Albuquerque" <esalbuquerque@superig.com.br> wrote in
message
> > news:bo4a1r$lm$1@eclipse.org...
> > > Hello,
> > >
> > > how can I get IProject and IFile from a ICompilationUnit or
> > > IWorkingCopyManager ?
> > >
> > > For example, from snippet code:
> > >
> > > /*********************************************************** ******/
> > > IWorkbenchPage wbp = window.getActivePage();
> > > IEditorPart edt = wbp.getActiveEditor();
> > > IEditorInput ei = edt.getEditorInput();
> > > IWorkingCopyManager mgr = JavaUI.getWorkingCopyManager();
> > >
> > > try {
> > > mgr.connect(ei);
> > > ICompilationUnit unit = mgr.getWorkingCopy(ei);
> > > source = unit.getSource();
> > > if (unit == null) {
> > > System.out.print("Nao eh um arq. Java");
> > > return;
> > > } else {
> > > CompilationUnit cUnit = AST.parseCompilationUnit(unit, true);
> > > cUnit.accept(sav);
> > > }
> > > } catch (Throwable e) {
> > > e.printStackTrace();
> > > } finally {
> > > mgr.disconnect(ei);
> > > }
> > > /*********************************************************** ******/
> > >
> > > Thanks,
> > > Eduardo Soares Albuquerque
> > >
>
>
Re: Get IProject and IFile from a ICompilationUnit [message #113326 is a reply to message #112837] Mon, 03 November 2003 22:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: dave_s42.hotmail.com

Sorry, this isn't an answer, but another question building on yours. I
need to do the same thing (get an IFile) and I see what the posted code
snippet is getting at. What I don't get is the window.getActivePage()
call. It would seem as if window is an IWorkbenchWindow, correct? If
that's true, then where is it created/referenced? (ie, how does the
variable name 'window' get bound to something meaningful?)

Eduardo Soares Albuquerque wrote:

> Hello,

> how can I get IProject and IFile from a ICompilationUnit or
> IWorkingCopyManager ?

> For example, from snippet code:

> /*********************************************************** ******/
> IWorkbenchPage wbp = window.getActivePage();
> IEditorPart edt = wbp.getActiveEditor();
> IEditorInput ei = edt.getEditorInput();
> IWorkingCopyManager mgr = JavaUI.getWorkingCopyManager();

> try {
> mgr.connect(ei);
> ICompilationUnit unit = mgr.getWorkingCopy(ei);
> source = unit.getSource();
> if (unit == null) {
> System.out.print("Nao eh um arq. Java");
> return;
> } else {
> CompilationUnit cUnit = AST.parseCompilationUnit(unit, true);
> cUnit.accept(sav);
> }
> } catch (Throwable e) {
> e.printStackTrace();
> } finally {
> mgr.disconnect(ei);
> }
> /*********************************************************** ******/

> Thanks,
> Eduardo Soares Albuquerque
Re: Get IProject and IFile from a ICompilationUnit [message #113417 is a reply to message #113326] Tue, 04 November 2003 08:40 Go to previous message
Eclipse UserFriend
Originally posted by: esalbuquerque.superig.com.br

>public class XXXX implements IWorkbenchWindowActionDelegate {
> private IWorkbenchWindow window;
> .
> .
> .
>}

Dave S wrote:

> Sorry, this isn't an answer, but another question building on yours. I
> need to do the same thing (get an IFile) and I see what the posted code
> snippet is getting at. What I don't get is the window.getActivePage()
> call. It would seem as if window is an IWorkbenchWindow, correct? If
> that's true, then where is it created/referenced? (ie, how does the
> variable name 'window' get bound to something meaningful?)

> Eduardo Soares Albuquerque wrote:

> > Hello,

> > how can I get IProject and IFile from a ICompilationUnit or
> > IWorkingCopyManager ?

> > For example, from snippet code:

> > /*********************************************************** ******/
> > IWorkbenchPage wbp = window.getActivePage();
> > IEditorPart edt = wbp.getActiveEditor();
> > IEditorInput ei = edt.getEditorInput();
> > IWorkingCopyManager mgr = JavaUI.getWorkingCopyManager();

> > try {
> > mgr.connect(ei);
> > ICompilationUnit unit = mgr.getWorkingCopy(ei);
> > source = unit.getSource();
> > if (unit == null) {
> > System.out.print("Nao eh um arq. Java");
> > return;
> > } else {
> > CompilationUnit cUnit = AST.parseCompilationUnit(unit, true);
> > cUnit.accept(sav);
> > }
> > } catch (Throwable e) {
> > e.printStackTrace();
> > } finally {
> > mgr.disconnect(ei);
> > }
> > /*********************************************************** ******/

> > Thanks,
> > Eduardo Soares Albuquerque
Previous Topic:db2 and eclipse
Next Topic:Linux problem: X-Server crashes with Eclipse
Goto Forum:
  


Current Time: Sat Jul 27 16:30:40 GMT 2024

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

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

Back to the top