use of com.intellij.psi.PsiPackage 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.PsiPackage in project intellij-community by JetBrains.
the class PsiPackageFavoriteNodeProvider method createPathFromUrl.
@Override
public Object[] createPathFromUrl(final Project project, final String url, final String moduleName) {
final Module module = moduleName != null ? ModuleManager.getInstance(project).findModuleByName(moduleName) : null;
// module can be null if 'show module' turned off
final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(url);
if (aPackage == null)
return null;
PackageElement packageElement = new PackageElement(module, aPackage, false);
return new Object[] { packageElement };
}
use of com.intellij.psi.PsiPackage 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.PsiPackage 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.PsiPackage in project intellij-community by JetBrains.
the class PackageWrapper method exists.
public boolean exists() {
final Project project = myManager.getProject();
final PsiPackage aPackage = JavaPsiFacade.getInstance(project).findPackage(myQualifiedName);
return aPackage != null && aPackage.getDirectories(GlobalSearchScope.projectScope(project)).length > 0;
}
Aggregations