[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.tools] Weird problem: ICompilationUnit & IFile?

Hi there,
I have some code snipset below in popup menu action:

 public void selectionChanged(IAction action, ISelection selection)
 {
  _selectedFile = null;
  if (selection instanceof IStructuredSelection)
  {
   IStructuredSelection structuredSelection =
    (IStructuredSelection) selection;
   if (structuredSelection.size() == 1)
   {
    Object selectedResource = structuredSelection.getFirstElement();
    if (selectedResource instanceof ICompilationUnit)
    {
     _selectedJava = (ICompilationUnit) selectedResource;
    }
    if (selectedResource instanceof IFile)
    {
     _selectedFile = (IFile) selectedResource;
     System.out.println("_selectedFile is not null");
    }
    Assert.isNotNull(_selectedJava, "_selectedJava shouldn't be null");
    Assert.isNotNull(_selectedFile, "_selectedFile shouldn't be null");
   }
  }
 }

My question is why _selectedJava is not null while _selectedFile is null
when I right click on a java file? I also tried "_selectedFile = (IFile)
_selectedJava.getAdapter(IFile.class)" which doesn't work either. Why???
Thanks for your reply!