Search in sources :

Example 6 with PsiTreeChangeEventImpl

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

the class PsiVFSListener method handleVfsChangeWithoutPsi.

private void handleVfsChangeWithoutPsi(@NotNull VirtualFile vFile) {
    if (!myReportedUnloadedPsiChange && isInRootModel(vFile)) {
        PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(myManager);
        myFileManager.firePropertyChangedForUnloadedPsi(event, vFile);
        myReportedUnloadedPsiChange = true;
    }
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl)

Example 7 with PsiTreeChangeEventImpl

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

the class PsiVFSListener method beforeFileDeletion.

@Override
public void beforeFileDeletion(@NotNull VirtualFileEvent event) {
    final VirtualFile vFile = event.getFile();
    VirtualFile parent = vFile.getParent();
    final PsiDirectory parentDir = getCachedDirectory(parent);
    // do not notify listeners if parent directory was never accessed via PSI
    if (parentDir == null)
        return;
    ApplicationManager.getApplication().runWriteAction(new ExternalChangeAction() {

        @Override
        public void run() {
            if (!vFile.isDirectory()) {
                PsiFile psiFile = myFileManager.getCachedPsiFile(vFile);
                if (psiFile != null) {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    treeEvent.setChild(psiFile);
                    myManager.beforeChildRemoval(treeEvent);
                }
            } else {
                PsiDirectory psiDir = myFileManager.findDirectory(vFile);
                if (psiDir != null) {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    treeEvent.setChild(psiDir);
                    myManager.beforeChildRemoval(treeEvent);
                }
            }
        }
    });
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl)

Example 8 with PsiTreeChangeEventImpl

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

the class PsiVFSListener method beforePropertyChange.

@Override
public void beforePropertyChange(@NotNull final VirtualFilePropertyEvent event) {
    final VirtualFile vFile = event.getFile();
    final String propertyName = event.getPropertyName();
    final FileViewProvider viewProvider = myFileManager.findCachedViewProvider(vFile);
    VirtualFile parent = vFile.getParent();
    final PsiDirectory parentDir = viewProvider != null && parent != null ? myFileManager.findDirectory(parent) : getCachedDirectory(parent);
    // do not notifyListeners event if parent directory was never accessed via PSI
    if (parent != null && parentDir == null)
        return;
    ApplicationManager.getApplication().runWriteAction(new ExternalChangeAction() {

        @Override
        public void run() {
            PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
            treeEvent.setParent(parentDir);
            if (VirtualFile.PROP_NAME.equals(propertyName)) {
                final String newName = (String) event.getNewValue();
                if (parentDir == null)
                    return;
                if (vFile.isDirectory()) {
                    PsiDirectory psiDir = myFileManager.findDirectory(vFile);
                    if (psiDir != null) {
                        if (!myFileTypeManager.isFileIgnored(newName)) {
                            treeEvent.setChild(psiDir);
                            treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_DIRECTORY_NAME);
                            treeEvent.setOldValue(vFile.getName());
                            treeEvent.setNewValue(newName);
                            myManager.beforePropertyChange(treeEvent);
                        } else {
                            treeEvent.setChild(psiDir);
                            myManager.beforeChildRemoval(treeEvent);
                        }
                    } else {
                        if ((!Registry.is("ide.hide.excluded.files") || !isExcludeRoot(vFile)) && !myFileTypeManager.isFileIgnored(newName)) {
                            myManager.beforeChildAddition(treeEvent);
                        }
                    }
                } else {
                    final FileViewProvider viewProvider = myFileManager.findViewProvider(vFile);
                    PsiFile psiFile = viewProvider.getPsi(viewProvider.getBaseLanguage());
                    PsiFile psiFile1 = createFileCopyWithNewName(vFile, newName);
                    if (psiFile != null) {
                        if (psiFile1 == null) {
                            treeEvent.setChild(psiFile);
                            myManager.beforeChildRemoval(treeEvent);
                        } else if (!psiFile1.getClass().equals(psiFile.getClass())) {
                            treeEvent.setOldChild(psiFile);
                            myManager.beforeChildReplacement(treeEvent);
                        } else {
                            treeEvent.setChild(psiFile);
                            treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_FILE_NAME);
                            treeEvent.setOldValue(vFile.getName());
                            treeEvent.setNewValue(newName);
                            myManager.beforePropertyChange(treeEvent);
                        }
                    } else {
                        if (psiFile1 != null) {
                            myManager.beforeChildAddition(treeEvent);
                        }
                    }
                }
            } else if (VirtualFile.PROP_WRITABLE.equals(propertyName)) {
                PsiFile psiFile = myFileManager.getCachedPsiFileInner(vFile);
                if (psiFile == null)
                    return;
                treeEvent.setElement(psiFile);
                treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_WRITABLE);
                treeEvent.setOldValue(event.getOldValue());
                treeEvent.setNewValue(event.getNewValue());
                myManager.beforePropertyChange(treeEvent);
            }
        }
    });
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl)

Example 9 with PsiTreeChangeEventImpl

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

the class PsiVFSListener method fileMoved.

@Override
public void fileMoved(@NotNull VirtualFileMoveEvent event) {
    final VirtualFile vFile = event.getFile();
    final PsiDirectory oldParentDir = myFileManager.findDirectory(event.getOldParent());
    final PsiDirectory newParentDir = myFileManager.findDirectory(event.getNewParent());
    if (oldParentDir == null && newParentDir == null)
        return;
    final PsiElement oldElement = vFile.isDirectory() ? myFileManager.getCachedDirectory(vFile) : myFileManager.getCachedPsiFileInner(vFile);
    myFileManager.removeInvalidFilesAndDirs(true);
    final PsiElement newElement;
    final FileViewProvider newViewProvider;
    if (!vFile.isDirectory()) {
        newViewProvider = myFileManager.createFileViewProvider(vFile, true);
        newElement = newViewProvider.getPsi(myFileManager.findViewProvider(vFile).getBaseLanguage());
    } else {
        newElement = myFileManager.findDirectory(vFile);
        newViewProvider = null;
    }
    if (oldElement == null && newElement == null)
        return;
    ApplicationManager.getApplication().runWriteAction(new ExternalChangeAction() {

        @Override
        public void run() {
            PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
            if (oldElement == null) {
                myFileManager.setViewProvider(vFile, newViewProvider);
                treeEvent.setParent(newParentDir);
                treeEvent.setChild(newElement);
                myManager.childAdded(treeEvent);
            } else {
                if (newElement == null) {
                    clearViewProvider(vFile, "PSI moved");
                    treeEvent.setParent(oldParentDir);
                    treeEvent.setChild(oldElement);
                    myManager.childRemoved(treeEvent);
                } else {
                    if (newElement instanceof PsiDirectory || FileManagerImpl.areViewProvidersEquivalent(newViewProvider, ((PsiFile) oldElement).getViewProvider())) {
                        treeEvent.setOldParent(oldParentDir);
                        treeEvent.setNewParent(newParentDir);
                        treeEvent.setChild(oldElement);
                        myManager.childMoved(treeEvent);
                    } else {
                        myFileManager.setViewProvider(vFile, newViewProvider);
                        PsiTreeChangeEventImpl treeRemoveEvent = new PsiTreeChangeEventImpl(myManager);
                        treeRemoveEvent.setParent(oldParentDir);
                        treeRemoveEvent.setChild(oldElement);
                        myManager.childRemoved(treeRemoveEvent);
                        PsiTreeChangeEventImpl treeAddEvent = new PsiTreeChangeEventImpl(myManager);
                        treeAddEvent.setParent(newParentDir);
                        treeAddEvent.setChild(newElement);
                        myManager.childAdded(treeAddEvent);
                    }
                }
            }
        }
    });
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl)

Example 10 with PsiTreeChangeEventImpl

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

the class PsiVFSListener method propertyChanged.

@Override
public void propertyChanged(@NotNull final VirtualFilePropertyEvent event) {
    final String propertyName = event.getPropertyName();
    final VirtualFile vFile = event.getFile();
    final FileViewProvider oldFileViewProvider = myFileManager.findCachedViewProvider(vFile);
    final PsiFile oldPsiFile;
    if (oldFileViewProvider instanceof SingleRootFileViewProvider) {
        oldPsiFile = ((SingleRootFileViewProvider) oldFileViewProvider).getCachedPsi(oldFileViewProvider.getBaseLanguage());
    } else {
        oldPsiFile = null;
    }
    VirtualFile parent = vFile.getParent();
    final PsiDirectory parentDir = oldPsiFile != null && parent != null ? myFileManager.findDirectory(parent) : getCachedDirectory(parent);
    if (// there is no need to rebuild if there were no PSI in the first place
    oldFileViewProvider != null && FileContentUtilCore.FORCE_RELOAD_REQUESTOR.equals(event.getRequestor())) {
        myFileManager.forceReload(vFile);
        return;
    }
    // do not suppress reparse request for light files
    if (parentDir == null) {
        boolean fire = VirtualFile.PROP_NAME.equals(propertyName) && vFile.isDirectory();
        if (fire) {
            PsiDirectory psiDir = myFileManager.getCachedDirectory(vFile);
            fire = psiDir != null;
        }
        if (!fire && !VirtualFile.PROP_WRITABLE.equals(propertyName)) {
            handleVfsChangeWithoutPsi(vFile);
            return;
        }
    }
    ApplicationManager.getApplication().runWriteAction(new ExternalChangeAction() {

        @Override
        public void run() {
            PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
            treeEvent.setParent(parentDir);
            if (VirtualFile.PROP_NAME.equals(propertyName)) {
                if (vFile.isDirectory()) {
                    PsiDirectory psiDir = myFileManager.getCachedDirectory(vFile);
                    if (psiDir != null) {
                        if (myFileTypeManager.isFileIgnored(vFile)) {
                            myFileManager.removeFilesAndDirsRecursively(vFile);
                            treeEvent.setChild(psiDir);
                            myManager.childRemoved(treeEvent);
                        } else {
                            treeEvent.setElement(psiDir);
                            treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_DIRECTORY_NAME);
                            treeEvent.setOldValue(event.getOldValue());
                            treeEvent.setNewValue(event.getNewValue());
                            myManager.propertyChanged(treeEvent);
                        }
                    } else {
                        PsiDirectory psiDir1 = myFileManager.findDirectory(vFile);
                        if (psiDir1 != null) {
                            treeEvent.setChild(psiDir1);
                            myManager.childAdded(treeEvent);
                        }
                    }
                } else {
                    final FileViewProvider fileViewProvider = myFileManager.createFileViewProvider(vFile, true);
                    final PsiFile newPsiFile = fileViewProvider.getPsi(fileViewProvider.getBaseLanguage());
                    if (oldPsiFile != null) {
                        if (newPsiFile == null) {
                            clearViewProvider(vFile, "PSI renamed");
                            treeEvent.setChild(oldPsiFile);
                            myManager.childRemoved(treeEvent);
                        } else if (!FileManagerImpl.areViewProvidersEquivalent(fileViewProvider, oldFileViewProvider)) {
                            myFileManager.setViewProvider(vFile, fileViewProvider);
                            treeEvent.setOldChild(oldPsiFile);
                            treeEvent.setNewChild(newPsiFile);
                            myManager.childReplaced(treeEvent);
                        } else {
                            FileManagerImpl.clearPsiCaches(oldFileViewProvider);
                            treeEvent.setElement(oldPsiFile);
                            treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_FILE_NAME);
                            treeEvent.setOldValue(event.getOldValue());
                            treeEvent.setNewValue(event.getNewValue());
                            myManager.propertyChanged(treeEvent);
                        }
                    } else if (newPsiFile != null) {
                        myFileManager.setViewProvider(vFile, fileViewProvider);
                        if (parentDir != null) {
                            treeEvent.setChild(newPsiFile);
                            myManager.childAdded(treeEvent);
                        }
                    }
                }
            } else if (VirtualFile.PROP_WRITABLE.equals(propertyName)) {
                if (oldPsiFile == null)
                    return;
                treeEvent.setElement(oldPsiFile);
                treeEvent.setPropertyName(PsiTreeChangeEvent.PROP_WRITABLE);
                treeEvent.setOldValue(event.getOldValue());
                treeEvent.setNewValue(event.getNewValue());
                myManager.propertyChanged(treeEvent);
            } else if (VirtualFile.PROP_ENCODING.equals(propertyName)) {
                if (oldPsiFile == null)
                    return;
                treeEvent.setElement(oldPsiFile);
                treeEvent.setPropertyName(VirtualFile.PROP_ENCODING);
                treeEvent.setOldValue(event.getOldValue());
                treeEvent.setNewValue(event.getNewValue());
                myManager.propertyChanged(treeEvent);
            }
        }
    });
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl)

Aggregations

PsiTreeChangeEventImpl (com.intellij.psi.impl.PsiTreeChangeEventImpl)11 ASTNode (com.intellij.lang.ASTNode)1 TextRange (com.intellij.openapi.util.TextRange)1 ChangeInfo (com.intellij.pom.tree.events.ChangeInfo)1 ReplaceChangeInfo (com.intellij.pom.tree.events.ReplaceChangeInfo)1 TreeChange (com.intellij.pom.tree.events.TreeChange)1 ChangeInfoImpl (com.intellij.pom.tree.events.impl.ChangeInfoImpl)1 TreeChangeImpl (com.intellij.pom.tree.events.impl.TreeChangeImpl)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiManagerImpl (com.intellij.psi.impl.PsiManagerImpl)1