Get IProject and IFile from a ICompilationUnit [message #112837] |
Mon, 03 November 2003 01:12 |
Eclipse User |
|
|
|
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 #113168 is a reply to message #112976] |
Mon, 03 November 2003 14:47 |
Eclipse User |
|
|
|
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 #113326 is a reply to message #112837] |
Mon, 03 November 2003 22:56 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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
|
|
|
Powered by
FUDForum. Page generated in 0.04519 seconds