use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class PsiPackageFavoriteNodeProvider method getFavoriteNodes.
@Override
public Collection<AbstractTreeNode> getFavoriteNodes(final DataContext context, final ViewSettings viewSettings) {
final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null)
return null;
PsiElement[] elements = LangDataKeys.PSI_ELEMENT_ARRAY.getData(context);
if (elements == null) {
final PsiElement element = CommonDataKeys.PSI_ELEMENT.getData(context);
if (element != null) {
elements = new PsiElement[] { element };
}
}
final Collection<AbstractTreeNode> result = new ArrayList<>();
if (elements != null) {
for (PsiElement element : elements) {
if (element instanceof PsiPackage) {
final PsiPackage psiPackage = (PsiPackage) element;
final PsiDirectory[] directories = psiPackage.getDirectories();
if (directories.length > 0) {
final VirtualFile firstDir = directories[0].getVirtualFile();
final boolean isLibraryRoot = ProjectRootsUtil.isLibraryRoot(firstDir, project);
final PackageElement packageElement = new PackageElement(LangDataKeys.MODULE.getData(context), psiPackage, isLibraryRoot);
result.add(new PackageElementNode(project, packageElement, viewSettings));
}
}
}
return result.isEmpty() ? null : result;
}
final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
final Module[] modules = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(context);
if (modules != null) {
for (Module module : modules) {
if (PackageViewPane.ID.equals(currentViewId)) {
result.add(new PackageViewModuleNode(project, module, viewSettings));
} else {
result.add(new ProjectViewModuleNode(project, module, viewSettings));
}
}
} else {
final ModuleGroup[] data = ModuleGroup.ARRAY_DATA_KEY.getData(context);
if (data != null) {
for (ModuleGroup moduleGroup : data) {
if (PackageViewPane.ID.equals(currentViewId)) {
result.add(new PackageViewModuleGroupNode(project, moduleGroup, viewSettings));
} else {
result.add(new ProjectViewModuleGroupNode(project, moduleGroup, viewSettings));
}
}
}
}
return null;
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class PsiPackageFavoriteNodeProvider method elementContainsFile.
@Override
public boolean elementContainsFile(final Object element, final VirtualFile vFile) {
if (element instanceof PackageElement) {
final Set<Boolean> find = new HashSet<>();
final ContentIterator contentIterator = new ContentIterator() {
@Override
public boolean processFile(VirtualFile fileOrDir) {
if (fileOrDir != null && fileOrDir.getPath().equals(vFile.getPath())) {
find.add(Boolean.TRUE);
}
return true;
}
};
final PackageElement packageElement = (PackageElement) element;
final PsiPackage aPackage = packageElement.getPackage();
final Project project = aPackage.getProject();
final GlobalSearchScope scope = packageElement.getModule() != null ? GlobalSearchScope.moduleScope(packageElement.getModule()) : GlobalSearchScope.projectScope(project);
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
final PsiDirectory[] directories = aPackage.getDirectories(scope);
for (PsiDirectory directory : directories) {
projectFileIndex.iterateContentUnderDirectory(directory.getVirtualFile(), contentIterator);
}
return !find.isEmpty();
}
return false;
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class CyclicDependenciesAction method getInspectionScopeImpl.
@Nullable
private static AnalysisScope getInspectionScopeImpl(DataContext dataContext) {
//Possible scopes: package, project, module.
Project projectContext = PlatformDataKeys.PROJECT_CONTEXT.getData(dataContext);
if (projectContext != null) {
return null;
}
Module moduleContext = LangDataKeys.MODULE_CONTEXT.getData(dataContext);
if (moduleContext != null) {
return null;
}
final Module[] modulesArray = LangDataKeys.MODULE_CONTEXT_ARRAY.getData(dataContext);
if (modulesArray != null && modulesArray.length > 0) {
return new AnalysisScope(modulesArray);
}
PsiElement psiTarget = CommonDataKeys.PSI_ELEMENT.getData(dataContext);
if (psiTarget instanceof PsiDirectory) {
PsiDirectory psiDirectory = (PsiDirectory) psiTarget;
if (!psiDirectory.getManager().isInProject(psiDirectory))
return null;
return new AnalysisScope(psiDirectory);
} else if (psiTarget instanceof PsiPackage) {
PsiPackage pack = (PsiPackage) psiTarget;
PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(pack.getProject()));
if (dirs.length == 0)
return null;
return new JavaAnalysisScope(pack, LangDataKeys.MODULE.getData(dataContext));
}
return null;
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class AnalysisScopeRule method getData.
@Override
public Object getData(final DataProvider dataProvider) {
final Object psiFile = dataProvider.getData(CommonDataKeys.PSI_FILE.getName());
if (psiFile instanceof PsiJavaFile) {
return new JavaAnalysisScope((PsiJavaFile) psiFile);
}
Object psiTarget = dataProvider.getData(CommonDataKeys.PSI_ELEMENT.getName());
if (psiTarget instanceof PsiPackage) {
PsiPackage pack = (PsiPackage) psiTarget;
PsiManager manager = pack.getManager();
if (!manager.isInProject(pack))
return null;
PsiDirectory[] dirs = pack.getDirectories(GlobalSearchScope.projectScope(manager.getProject()));
if (dirs.length == 0)
return null;
return new JavaAnalysisScope(pack, (Module) dataProvider.getData(LangDataKeys.MODULE.getName()));
}
return null;
}
use of com.intellij.psi.PsiDirectory in project intellij-community by JetBrains.
the class ClassBrowser method configureDialog.
private void configureDialog(final TreeClassChooser dialog) {
final String className = getText();
final PsiClass psiClass = findClass(className);
if (psiClass == null)
return;
final PsiDirectory directory = psiClass.getContainingFile().getContainingDirectory();
if (directory != null)
dialog.selectDirectory(directory);
dialog.select(psiClass);
}
Aggregations