Search in sources :

Example 6 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class TodoPackageNode method getFileCount.

private int getFileCount(final PackageElement packageElement) {
    int count = 0;
    if (getSettings().isFlattenPackages()) {
        final PsiPackage aPackage = packageElement.getPackage();
        final Module module = packageElement.getModule();
        final GlobalSearchScope scope = module != null ? GlobalSearchScope.moduleScope(module) : GlobalSearchScope.projectScope(aPackage.getProject());
        final PsiDirectory[] directories = aPackage.getDirectories(scope);
        for (PsiDirectory directory : directories) {
            Iterator<PsiFile> iterator = myBuilder.getFilesUnderDirectory(directory);
            while (iterator.hasNext()) {
                PsiFile psiFile = iterator.next();
                if (getStructure().accept(psiFile))
                    count++;
            }
        }
    } else {
        Iterator<PsiFile> iterator = getFiles(packageElement);
        while (iterator.hasNext()) {
            PsiFile psiFile = iterator.next();
            if (getStructure().accept(psiFile)) {
                count++;
            }
        }
    }
    return count;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 7 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class JavaProjectViewDirectoryHelper method getLocationString.

@Nullable
@Override
public String getLocationString(@NotNull PsiDirectory directory, boolean includeUrl, boolean includeRootType) {
    String result = null;
    PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
    if (ProjectRootsUtil.isSourceRoot(directory) && aPackage != null) {
        //package prefix
        result = StringUtil.nullize(aPackage.getQualifiedName(), true);
    }
    String baseString = super.getLocationString(directory, includeUrl, includeRootType);
    if (result == null)
        return baseString;
    if (baseString == null)
        return result;
    return result + "," + FontUtil.spaceAndThinSpace() + baseString;
}
Also used : PsiPackage(com.intellij.psi.PsiPackage) Nullable(org.jetbrains.annotations.Nullable)

Example 8 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class JavaProjectViewDirectoryHelper method getNodeName.

@Nullable
@Override
public String getNodeName(final ViewSettings settings, final Object parentValue, final PsiDirectory directory) {
    PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(directory);
    PsiPackage parentPackage;
    if (!ProjectRootsUtil.isSourceRoot(directory) && aPackage != null && !aPackage.getQualifiedName().isEmpty() && parentValue instanceof PsiDirectory) {
        parentPackage = JavaDirectoryService.getInstance().getPackage(((PsiDirectory) parentValue));
    } else if (ProjectRootsUtil.isSourceRoot(directory) && aPackage != null) {
        //package prefix
        aPackage = null;
        parentPackage = null;
    } else {
        parentPackage = null;
    }
    return PackageUtil.getNodeName(settings, aPackage, parentPackage, directory.getName(), isShowFQName(settings, parentValue, directory));
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiPackage(com.intellij.psi.PsiPackage) Nullable(org.jetbrains.annotations.Nullable)

Example 9 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class PackageElementNode method getChildren.

@Override
@NotNull
public Collection<AbstractTreeNode> getChildren() {
    final PackageElement value = getValue();
    if (value == null)
        return Collections.emptyList();
    final List<AbstractTreeNode> children = new ArrayList<>();
    final Module module = value.getModule();
    final PsiPackage aPackage = value.getPackage();
    if (!getSettings().isFlattenPackages()) {
        final PsiPackage[] subpackages = PackageUtil.getSubpackages(aPackage, module, isLibraryElement());
        for (PsiPackage subpackage : subpackages) {
            PackageUtil.addPackageAsChild(children, subpackage, module, getSettings(), isLibraryElement());
        }
    }
    // process only files in package's directories
    final GlobalSearchScope scopeToShow = PackageUtil.getScopeToShow(aPackage.getProject(), module, isLibraryElement());
    PsiFile[] packageChildren = aPackage.getFiles(scopeToShow);
    for (PsiFile file : packageChildren) {
        if (file.getVirtualFile() != null) {
            children.add(new PsiFileNode(getProject(), file, getSettings()));
        }
    }
    return children;
}
Also used : GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiPackage(com.intellij.psi.PsiPackage) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with PsiPackage

use of com.intellij.psi.PsiPackage in project intellij-community by JetBrains.

the class FileStructureDialogTest method testFileStructureForClass.

public void testFileStructureForClass() throws Exception {
    final PsiPackage aPackage = JavaDirectoryService.getInstance().getPackage(getPackageDirectory());
    assertNotNull(aPackage);
    final PsiClass psiClass = aPackage.getClasses()[0];
    final VirtualFile virtualFile = psiClass.getContainingFile().getVirtualFile();
    assertNotNull(virtualFile);
    final StructureViewBuilder structureViewBuilder = StructureViewBuilder.PROVIDER.getStructureViewBuilder(virtualFile.getFileType(), virtualFile, myProject);
    assertNotNull(structureViewBuilder);
    final StructureViewModel structureViewModel = ((TreeBasedStructureViewBuilder) structureViewBuilder).createStructureViewModel(null);
    final EditorFactory factory = EditorFactory.getInstance();
    assertNotNull(factory);
    final Document document = FileDocumentManager.getInstance().getDocument(virtualFile);
    assertNotNull(document);
    final Editor editor = factory.createEditor(document, myProject);
    try {
        final FileStructureDialog dialog = new FileStructureDialog(structureViewModel, editor, myProject, psiClass, new Disposable() {

            @Override
            public void dispose() {
                structureViewModel.dispose();
            }
        }, true);
        try {
            final CommanderPanel panel = dialog.getPanel();
            assertListsEqual((ListModel) panel.getModel(), "Inner1\n" + "Inner2\n" + "__method(): void\n" + "_myField1: int\n" + "_myField2: String\n");
        } finally {
            dialog.close(0);
        }
    } finally {
        factory.releaseEditor(editor);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewBuilder(com.intellij.ide.structureView.StructureViewBuilder) EditorFactory(com.intellij.openapi.editor.EditorFactory) TreeBasedStructureViewBuilder(com.intellij.ide.structureView.TreeBasedStructureViewBuilder) StructureViewModel(com.intellij.ide.structureView.StructureViewModel) PsiClass(com.intellij.psi.PsiClass) PsiPackage(com.intellij.psi.PsiPackage) Document(com.intellij.openapi.editor.Document) CommanderPanel(com.intellij.ide.commander.CommanderPanel) FileStructureDialog(com.intellij.ide.util.FileStructureDialog) Editor(com.intellij.openapi.editor.Editor)

Aggregations

PsiPackage (com.intellij.psi.PsiPackage)93 PsiDirectory (com.intellij.psi.PsiDirectory)24 PsiClass (com.intellij.psi.PsiClass)22 Module (com.intellij.openapi.module.Module)19 Project (com.intellij.openapi.project.Project)14 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)14 VirtualFile (com.intellij.openapi.vfs.VirtualFile)13 JavaAnalysisScope (com.intellij.analysis.JavaAnalysisScope)12 PsiFile (com.intellij.psi.PsiFile)12 PsiElement (com.intellij.psi.PsiElement)11 JavaPsiFacade (com.intellij.psi.JavaPsiFacade)10 NotNull (org.jetbrains.annotations.NotNull)10 CyclicDependenciesBuilder (com.intellij.cyclicDependencies.CyclicDependenciesBuilder)9 Nullable (org.jetbrains.annotations.Nullable)9 AnalysisScope (com.intellij.analysis.AnalysisScope)8 HashSet (java.util.HashSet)6 List (java.util.List)5 LookupElement (com.intellij.codeInsight.lookup.LookupElement)4 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)4 ArrayList (java.util.ArrayList)4