コード例 #1
0
 @Nullable
 private PsiDirectory[] getSelectedDirectories() {
   if (myBuilder == null) return null;
   final Object[] selectedNodeElements = getSelectedNodeElements();
   if (selectedNodeElements.length != 1) return null;
   for (FavoriteNodeProvider nodeProvider :
       Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
     final PsiElement psiElement = nodeProvider.getPsiElement(selectedNodeElements[0]);
     if (psiElement instanceof PsiDirectory) {
       return new PsiDirectory[] {(PsiDirectory) psiElement};
     } else if (psiElement instanceof PsiDirectoryContainer) {
       final String moduleName = nodeProvider.getElementModuleName(selectedNodeElements[0]);
       GlobalSearchScope searchScope = GlobalSearchScope.projectScope(myProject);
       if (moduleName != null) {
         final Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleName);
         if (module != null) {
           searchScope = GlobalSearchScope.moduleScope(module);
         }
       }
       return ((PsiDirectoryContainer) psiElement).getDirectories(searchScope);
     }
   }
   return selectedNodeElements[0] instanceof PsiDirectory
       ? new PsiDirectory[] {(PsiDirectory) selectedNodeElements[0]}
       : null;
 }
コード例 #2
0
 @NotNull
 private PsiElement[] getSelectedPsiElements() {
   final Object[] elements = getSelectedNodeElements();
   if (elements == null) {
     return PsiElement.EMPTY_ARRAY;
   }
   ArrayList<PsiElement> result = new ArrayList<PsiElement>();
   for (Object element : elements) {
     if (element instanceof PsiElement) {
       result.add((PsiElement) element);
     } else if (element instanceof SmartPsiElementPointer) {
       PsiElement psiElement = ((SmartPsiElementPointer) element).getElement();
       if (psiElement != null) {
         result.add(psiElement);
       }
     } else {
       for (FavoriteNodeProvider provider :
           Extensions.getExtensions(FavoriteNodeProvider.EP_NAME, myProject)) {
         final PsiElement psiElement = provider.getPsiElement(element);
         if (psiElement != null) {
           result.add(psiElement);
           break;
         }
       }
     }
   }
   return result.toArray(new PsiElement[result.size()]);
 }