use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.
the class TodoJavaTreeHelper method getSelectedElement.
@Override
public PsiElement getSelectedElement(final Object userObject) {
if (userObject instanceof TodoPackageNode) {
TodoPackageNode descriptor = (TodoPackageNode) userObject;
final PackageElement packageElement = descriptor.getValue();
return packageElement != null ? packageElement.getPackage() : null;
}
return super.getSelectedElement(userObject);
}
use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.
the class TodoJavaTreeHelper method traverseSubPackages.
private static void traverseSubPackages(PsiPackage psiPackage, Module module, TodoTreeBuilder builder, Project project, Set<PsiPackage> packages) {
if (!isPackageEmpty(new PackageElement(module, psiPackage, false), builder, project)) {
packages.add(psiPackage);
}
GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
final PsiPackage[] subPackages = psiPackage.getSubPackages(scope);
for (PsiPackage subPackage : subPackages) {
traverseSubPackages(subPackage, module, builder, project, packages);
}
}
use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.
the class PackageViewPane method getSelectedPackageElement.
@Nullable
private PackageElement getSelectedPackageElement() {
PackageElement result = null;
final DefaultMutableTreeNode selectedNode = getSelectedNode();
if (selectedNode != null) {
Object o = selectedNode.getUserObject();
if (o instanceof AbstractTreeNode) {
Object selected = ((AbstractTreeNode) o).getValue();
result = selected instanceof PackageElement ? (PackageElement) selected : null;
}
}
return result;
}
use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.
the class CoverageProjectViewClassNodeDecorator method decorate.
public void decorate(ProjectViewNode node, PresentationData data) {
final CoverageDataManager coverageDataManager = getCoverageDataManager();
final CoverageSuitesBundle currentSuite = coverageDataManager.getCurrentSuitesBundle();
final Project project = node.getProject();
final JavaCoverageAnnotator javaCovAnnotator = getCovAnnotator(currentSuite, project);
// This decorator is applicable only to JavaCoverageAnnotator
if (javaCovAnnotator == null) {
return;
}
final Object value = node.getValue();
PsiElement element = null;
if (value instanceof PsiElement) {
element = (PsiElement) value;
} else if (value instanceof SmartPsiElementPointer) {
element = ((SmartPsiElementPointer) value).getElement();
} else if (value instanceof PackageElement) {
PackageElement packageElement = (PackageElement) value;
final String coverageString = javaCovAnnotator.getPackageCoverageInformationString(packageElement.getPackage(), packageElement.getModule(), coverageDataManager);
data.setLocationString(coverageString);
}
if (element instanceof PsiClass) {
final GlobalSearchScope searchScope = currentSuite.getSearchScope(project);
final VirtualFile vFile = PsiUtilCore.getVirtualFile(element);
if (vFile != null && searchScope.contains(vFile)) {
final String qName = ((PsiClass) element).getQualifiedName();
if (qName != null) {
data.setLocationString(javaCovAnnotator.getClassCoverageInformationString(qName, coverageDataManager));
}
}
}
}
use of com.intellij.ide.projectView.impl.nodes.PackageElement in project intellij-community by JetBrains.
the class TodoJavaTreeHelper method addPackagesToChildren.
@Override
public void addPackagesToChildren(final ArrayList<AbstractTreeNode> children, final Module module, final TodoTreeBuilder builder) {
Project project = getProject();
final PsiManager psiManager = PsiManager.getInstance(project);
final List<VirtualFile> sourceRoots = new ArrayList<>();
if (module == null) {
final ProjectRootManager projectRootManager = ProjectRootManager.getInstance(project);
ContainerUtil.addAll(sourceRoots, projectRootManager.getContentSourceRoots());
} else {
ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
ContainerUtil.addAll(sourceRoots, moduleRootManager.getSourceRoots());
}
final Set<PsiPackage> topLevelPackages = new HashSet<>();
for (final VirtualFile root : sourceRoots) {
final PsiDirectory directory = psiManager.findDirectory(root);
if (directory == null) {
continue;
}
final PsiPackage directoryPackage = JavaDirectoryService.getInstance().getPackage(directory);
if (directoryPackage == null || PackageUtil.isPackageDefault(directoryPackage)) {
// add subpackages
final PsiDirectory[] subdirectories = directory.getSubdirectories();
for (PsiDirectory subdirectory : subdirectories) {
final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(subdirectory);
if (aPackage != null && !PackageUtil.isPackageDefault(aPackage)) {
topLevelPackages.add(aPackage);
} else {
final Iterator<PsiFile> files = builder.getFiles(subdirectory);
if (!files.hasNext())
continue;
TodoDirNode dirNode = new TodoDirNode(project, subdirectory, builder);
if (!children.contains(dirNode)) {
children.add(dirNode);
}
}
}
// add non-dir items
final Iterator<PsiFile> filesUnderDirectory = builder.getFilesUnderDirectory(directory);
for (; filesUnderDirectory.hasNext(); ) {
final PsiFile file = filesUnderDirectory.next();
TodoFileNode todoFileNode = new TodoFileNode(project, file, builder, false);
if (!children.contains(todoFileNode)) {
children.add(todoFileNode);
}
}
} else {
// this is the case when a source root has pakage prefix assigned
topLevelPackages.add(directoryPackage);
}
}
GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(project);
ArrayList<PsiPackage> packages = new ArrayList<>();
for (PsiPackage psiPackage : topLevelPackages) {
final PsiPackage aPackage = findNonEmptyPackage(psiPackage, module, project, builder, scope);
if (aPackage != null) {
packages.add(aPackage);
}
}
for (PsiPackage psiPackage : packages) {
if (!builder.getTodoTreeStructure().getIsFlattenPackages()) {
PackageElement element = new PackageElement(module, psiPackage, false);
TodoPackageNode packageNode = new TodoPackageNode(project, element, builder, psiPackage.getQualifiedName());
if (!children.contains(packageNode)) {
children.add(packageNode);
}
} else {
Set<PsiPackage> allPackages = new HashSet<>();
traverseSubPackages(psiPackage, module, builder, project, allPackages);
for (PsiPackage aPackage : allPackages) {
TodoPackageNode packageNode = new TodoPackageNode(project, new PackageElement(module, aPackage, false), builder);
if (!children.contains(packageNode)) {
children.add(packageNode);
}
}
}
}
final List<VirtualFile> roots = collectContentRoots(module);
roots.removeAll(sourceRoots);
addDirsToChildren(roots, children, builder);
}
Aggregations