Search in sources :

Example 71 with PsiDirectory

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

the class PackageElementNode method getVirtualFiles.

@NotNull
public VirtualFile[] getVirtualFiles() {
    final PackageElement value = getValue();
    if (value == null) {
        return VirtualFile.EMPTY_ARRAY;
    }
    final PsiDirectory[] directories = PackageUtil.getDirectories(value.getPackage(), value.getModule(), isLibraryElement());
    final VirtualFile[] result = new VirtualFile[directories.length];
    for (int i = 0; i < directories.length; i++) {
        PsiDirectory directory = directories[i];
        result[i] = directory.getVirtualFile();
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiDirectory(com.intellij.psi.PsiDirectory) NotNull(org.jetbrains.annotations.NotNull)

Example 72 with PsiDirectory

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

the class DestinationFolderComboBox method updateErrorMessage.

private void updateErrorMessage(Pass<String> updateErrorMessage, ProjectFileIndex fileIndex, Object selectedItem) {
    updateErrorMessage.pass(null);
    if (myInitialTargetDirectory != null && selectedItem instanceof DirectoryChooser.ItemWrapper && selectedItem != NULL_WRAPPER) {
        final PsiDirectory directory = ((DirectoryChooser.ItemWrapper) selectedItem).getDirectory();
        final boolean isSelectionInTestSourceContent = fileIndex.isInTestSourceContent(directory.getVirtualFile());
        final boolean inTestSourceContent = fileIndex.isInTestSourceContent(myInitialTargetDirectory.getVirtualFile());
        if (isSelectionInTestSourceContent != inTestSourceContent) {
            if (inTestSourceContent && reportBaseInTestSelectionInSource()) {
                updateErrorMessage.pass("Source root is selected while the test root is expected");
            }
            if (isSelectionInTestSourceContent && reportBaseInSourceSelectionInTest()) {
                updateErrorMessage.pass("Test root is selected while the source root is expected");
            }
        }
    }
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory)

Example 73 with PsiDirectory

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

the class DestinationFolderComboBox method setData.

public void setData(final Project project, final PsiDirectory initialTargetDirectory, final Pass<String> errorMessageUpdater, final EditorComboBox editorComboBox) {
    myInitialTargetDirectory = initialTargetDirectory;
    mySourceRoots = JavaProjectRootsUtil.getSuitableDestinationSourceRoots(project);
    new ComboboxSpeedSearch(getComboBox()) {

        @Override
        protected String getElementText(Object element) {
            if (element == NULL_WRAPPER)
                return LEAVE_IN_SAME_SOURCE_ROOT;
            if (element instanceof DirectoryChooser.ItemWrapper) {
                final VirtualFile virtualFile = ((DirectoryChooser.ItemWrapper) element).getDirectory().getVirtualFile();
                final Module module = ModuleUtil.findModuleForFile(virtualFile, project);
                if (module != null) {
                    return module.getName();
                }
            }
            return super.getElementText(element);
        }
    };
    final ProjectFileIndex fileIndex = ProjectRootManager.getInstance(project).getFileIndex();
    getComboBox().setRenderer(new ListCellRendererWrapper<DirectoryChooser.ItemWrapper>() {

        @Override
        public void customize(JList list, DirectoryChooser.ItemWrapper itemWrapper, int index, boolean selected, boolean hasFocus) {
            if (itemWrapper != NULL_WRAPPER && itemWrapper != null) {
                setIcon(itemWrapper.getIcon(fileIndex));
                setText(itemWrapper.getRelativeToProjectPath());
            } else {
                setText(LEAVE_IN_SAME_SOURCE_ROOT);
            }
        }
    });
    final VirtualFile initialSourceRoot = initialTargetDirectory != null ? fileIndex.getSourceRootForFile(initialTargetDirectory.getVirtualFile()) : null;
    final VirtualFile[] selection = new VirtualFile[] { initialSourceRoot };
    addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            VirtualFile root = MoveClassesOrPackagesUtil.chooseSourceRoot(new PackageWrapper(PsiManager.getInstance(project), getTargetPackage()), mySourceRoots, initialTargetDirectory);
            if (root == null)
                return;
            final ComboBoxModel model = getComboBox().getModel();
            for (int i = 0; i < model.getSize(); i++) {
                DirectoryChooser.ItemWrapper item = (DirectoryChooser.ItemWrapper) model.getElementAt(i);
                if (item != NULL_WRAPPER && Comparing.equal(fileIndex.getSourceRootForFile(item.getDirectory().getVirtualFile()), root)) {
                    getComboBox().setSelectedItem(item);
                    getComboBox().repaint();
                    return;
                }
            }
            setComboboxModel(getComboBox(), root, root, fileIndex, mySourceRoots, project, true, errorMessageUpdater);
        }
    });
    editorComboBox.addDocumentListener(new DocumentAdapter() {

        @Override
        public void documentChanged(DocumentEvent e) {
            JComboBox comboBox = getComboBox();
            DirectoryChooser.ItemWrapper selectedItem = (DirectoryChooser.ItemWrapper) comboBox.getSelectedItem();
            setComboboxModel(comboBox, selectedItem != null && selectedItem != NULL_WRAPPER ? fileIndex.getSourceRootForFile(selectedItem.getDirectory().getVirtualFile()) : initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater);
        }
    });
    setComboboxModel(getComboBox(), initialSourceRoot, selection[0], fileIndex, mySourceRoots, project, false, errorMessageUpdater);
    getComboBox().addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            Object selectedItem = getComboBox().getSelectedItem();
            updateErrorMessage(errorMessageUpdater, fileIndex, selectedItem);
            if (selectedItem instanceof DirectoryChooser.ItemWrapper && selectedItem != NULL_WRAPPER) {
                PsiDirectory directory = ((DirectoryChooser.ItemWrapper) selectedItem).getDirectory();
                if (directory != null) {
                    selection[0] = fileIndex.getSourceRootForFile(directory.getVirtualFile());
                }
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ActionEvent(java.awt.event.ActionEvent) DocumentAdapter(com.intellij.openapi.editor.event.DocumentAdapter) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) PackageWrapper(com.intellij.refactoring.PackageWrapper) ActionListener(java.awt.event.ActionListener) ProjectFileIndex(com.intellij.openapi.roots.ProjectFileIndex) PsiDirectory(com.intellij.psi.PsiDirectory) Module(com.intellij.openapi.module.Module) DirectoryChooser(com.intellij.ide.util.DirectoryChooser)

Example 74 with PsiDirectory

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

the class SameNamesJoiner method hasElementWithTheSameName.

private boolean hasElementWithTheSameName(PsiFile element) {
    PsiDirectory psiDirectory = element.getParent();
    PsiElement[] children = psiDirectory.getChildren();
    for (int i = 0; i < children.length; i++) {
        PsiElement child = children[i];
        if (child != element && element.getVirtualFile().getNameWithoutExtension().equals(((PsiFile) child).getVirtualFile().getNameWithoutExtension())) {
            return true;
        }
    }
    return false;
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiElement(com.intellij.psi.PsiElement)

Example 75 with PsiDirectory

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

the class PsiCachedValue method getTimeStamp.

@Override
protected long getTimeStamp(Object dependency) {
    if (dependency instanceof PsiDirectory) {
        return myManager.getModificationTracker().getOutOfCodeBlockModificationCount();
    }
    if (dependency instanceof PsiElement) {
        PsiElement element = (PsiElement) dependency;
        if (!element.isValid())
            return -1;
        PsiFile containingFile = element.getContainingFile();
        if (containingFile != null)
            return containingFile.getModificationStamp();
    }
    if (dependency == PsiModificationTracker.MODIFICATION_COUNT) {
        return myManager.getModificationTracker().getModificationCount();
    }
    if (dependency == PsiModificationTracker.OUT_OF_CODE_BLOCK_MODIFICATION_COUNT) {
        return myManager.getModificationTracker().getOutOfCodeBlockModificationCount();
    }
    if (dependency == PsiModificationTracker.JAVA_STRUCTURE_MODIFICATION_COUNT) {
        return myManager.getModificationTracker().getJavaStructureModificationCount();
    }
    return super.getTimeStamp(dependency);
}
Also used : PsiDirectory(com.intellij.psi.PsiDirectory) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

PsiDirectory (com.intellij.psi.PsiDirectory)321 VirtualFile (com.intellij.openapi.vfs.VirtualFile)122 PsiFile (com.intellij.psi.PsiFile)111 PsiElement (com.intellij.psi.PsiElement)79 Project (com.intellij.openapi.project.Project)73 Module (com.intellij.openapi.module.Module)68 Nullable (org.jetbrains.annotations.Nullable)62 NotNull (org.jetbrains.annotations.NotNull)50 IdeView (com.intellij.ide.IdeView)31 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)24 ProjectFileIndex (com.intellij.openapi.roots.ProjectFileIndex)24 PsiManager (com.intellij.psi.PsiManager)24 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)20 ArrayList (java.util.ArrayList)20 PsiPackage (com.intellij.psi.PsiPackage)17 File (java.io.File)15 PsiFileSystemItem (com.intellij.psi.PsiFileSystemItem)11 IncorrectOperationException (com.intellij.util.IncorrectOperationException)11 Course (com.jetbrains.edu.learning.courseFormat.Course)11 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)10