Search in sources :

Example 1 with PsiTreeChangeEventImpl

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

the class PsiVFSListener method beforeFileMovement.

@Override
public void beforeFileMovement(@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;
    if (myFileTypeManager.isFileIgnored(vFile))
        return;
    ApplicationManager.getApplication().runWriteAction(new ExternalChangeAction() {

        @Override
        public void run() {
            PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
            boolean isExcluded = vFile.isDirectory() && Registry.is("ide.hide.excluded.files") && myProjectRootManager.getFileIndex().isExcluded(vFile);
            if (oldParentDir != null && !isExcluded) {
                if (newParentDir != null) {
                    treeEvent.setOldParent(oldParentDir);
                    treeEvent.setNewParent(newParentDir);
                    if (vFile.isDirectory()) {
                        PsiDirectory psiDir = myFileManager.findDirectory(vFile);
                        treeEvent.setChild(psiDir);
                    } else {
                        PsiFile psiFile = myFileManager.findFile(vFile);
                        treeEvent.setChild(psiFile);
                    }
                    myManager.beforeChildMovement(treeEvent);
                } else {
                    treeEvent.setParent(oldParentDir);
                    if (vFile.isDirectory()) {
                        PsiDirectory psiDir = myFileManager.findDirectory(vFile);
                        treeEvent.setChild(psiDir);
                    } else {
                        PsiFile psiFile = myFileManager.findFile(vFile);
                        treeEvent.setChild(psiFile);
                    }
                    myManager.beforeChildRemoval(treeEvent);
                }
            } else {
                // checked above
                LOG.assertTrue(newParentDir != null);
                treeEvent.setParent(newParentDir);
                myManager.beforeChildAddition(treeEvent);
            }
        }
    });
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl)

Example 2 with PsiTreeChangeEventImpl

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

the class PsiVFSListener method fileCreated.

@Override
public void fileCreated(@NotNull VirtualFileEvent event) {
    final VirtualFile vFile = event.getFile();
    ApplicationManager.getApplication().runWriteAction(new ExternalChangeAction() {

        @Override
        public void run() {
            VirtualFile parent = vFile.getParent();
            PsiDirectory parentDir = getCachedDirectory(parent);
            if (parentDir == null) {
                // parent directory was never accessed via PSI
                handleVfsChangeWithoutPsi(vFile);
                return;
            }
            if (!vFile.isDirectory()) {
                PsiFile psiFile = myFileManager.findFile(vFile);
                if (psiFile != null && psiFile.getProject() == myManager.getProject()) {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    myManager.beforeChildAddition(treeEvent);
                    treeEvent.setChild(psiFile);
                    myManager.childAdded(treeEvent);
                }
            } else {
                PsiDirectory psiDir = myFileManager.findDirectory(vFile);
                if (psiDir != null && psiDir.getProject() == myManager.getProject()) {
                    PsiTreeChangeEventImpl treeEvent = new PsiTreeChangeEventImpl(myManager);
                    treeEvent.setParent(parentDir);
                    myManager.beforeChildAddition(treeEvent);
                    treeEvent.setChild(psiDir);
                    myManager.childAdded(treeEvent);
                }
            }
        }
    });
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl)

Example 3 with PsiTreeChangeEventImpl

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

the class BlockSupportImpl method sendBeforeChildrenChangeEvent.

public static void sendBeforeChildrenChangeEvent(@NotNull PsiManagerImpl manager, @NotNull PsiElement scope, boolean isGenericChange) {
    if (!scope.isPhysical()) {
        manager.beforeChange(false);
        return;
    }
    PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(manager);
    event.setParent(scope);
    event.setFile(scope.getContainingFile());
    TextRange range = scope.getTextRange();
    event.setOffset(range == null ? 0 : range.getStartOffset());
    event.setOldLength(scope.getTextLength());
    // the "generic" event is being sent on every PSI change. It does not carry any specific info except the fact that "something has changed"
    event.setGenericChange(isGenericChange);
    manager.beforeChildrenChange(event);
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl) TextRange(com.intellij.openapi.util.TextRange)

Example 4 with PsiTreeChangeEventImpl

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

the class BlockSupportImpl method sendAfterChildrenChangedEvent.

public static void sendAfterChildrenChangedEvent(@NotNull PsiManagerImpl manager, @NotNull PsiFile scope, int oldLength, boolean isGenericChange) {
    if (!scope.isPhysical()) {
        manager.afterChange(false);
        return;
    }
    PsiTreeChangeEventImpl event = new PsiTreeChangeEventImpl(manager);
    event.setParent(scope);
    event.setFile(scope);
    event.setOffset(0);
    event.setOldLength(oldLength);
    event.setGenericChange(isGenericChange);
    manager.childrenChanged(event);
}
Also used : PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl)

Example 5 with PsiTreeChangeEventImpl

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

the class PsiEventWrapperAspect method sendAfterEvents.

private static void sendAfterEvents(TreeChangeEvent changeSet) {
    ASTNode rootElement = changeSet.getRootElement();
    final PsiFile file = (PsiFile) SourceTreeToPsiMap.treeElementToPsi(rootElement);
    final PsiManagerImpl manager = (PsiManagerImpl) file.getManager();
    if (manager == null)
        return;
    if (!file.isPhysical()) {
        manager.afterChange(false);
        return;
    }
    final ASTNode[] changedElements = changeSet.getChangedElements();
    for (ASTNode changedElement : changedElements) {
        TreeChange changesByElement = changeSet.getChangesByElement(changedElement);
        PsiElement psiParent = null;
        while (changedElement != null && ((psiParent = changedElement.getPsi()) == null || !checkPsiForChildren(changesByElement.getAffectedChildren()))) {
            final ASTNode parent = changedElement.getTreeParent();
            final ChangeInfoImpl changeInfo = ChangeInfoImpl.create(ChangeInfo.CONTENTS_CHANGED, changedElement);
            changeInfo.compactChange(changesByElement);
            changesByElement = new TreeChangeImpl(parent);
            changesByElement.addChange(changedElement, changeInfo);
            changedElement = parent;
        }
        if (changedElement == null)
            continue;
        final ASTNode[] affectedChildren = changesByElement.getAffectedChildren();
        for (final ASTNode treeElement : affectedChildren) {
            PsiTreeChangeEventImpl psiEvent = new PsiTreeChangeEventImpl(manager);
            psiEvent.setParent(psiParent);
            psiEvent.setFile(file);
            final PsiElement psiChild = treeElement.getPsi();
            psiEvent.setChild(psiChild);
            final ChangeInfo changeByChild = changesByElement.getChangeByChild(treeElement);
            switch(changeByChild.getChangeType()) {
                case ChangeInfo.ADD:
                    psiEvent.setOffset(treeElement.getStartOffset());
                    psiEvent.setOldLength(0);
                    manager.childAdded(psiEvent);
                    break;
                case ChangeInfo.REPLACE:
                    final ReplaceChangeInfo change = (ReplaceChangeInfo) changeByChild;
                    psiEvent.setOffset(treeElement.getStartOffset());
                    final ASTNode replaced = change.getReplaced();
                    psiEvent.setOldChild(replaced.getPsi());
                    psiEvent.setNewChild(psiChild);
                    psiEvent.setOldLength(replaced.getTextLength());
                    manager.childReplaced(psiEvent);
                    break;
                case ChangeInfo.CONTENTS_CHANGED:
                    psiEvent.setOffset(treeElement.getStartOffset());
                    psiEvent.setParent(psiChild);
                    psiEvent.setOldLength(changeByChild.getOldLength());
                    manager.childrenChanged(psiEvent);
                    break;
                case ChangeInfo.REMOVED:
                    psiEvent.setOffset(changesByElement.getChildOffsetInNewTree(treeElement));
                    psiEvent.setOldParent(psiParent);
                    psiEvent.setOldChild(psiChild);
                    psiEvent.setOldLength(changeByChild.getOldLength());
                    manager.childRemoved(psiEvent);
                    break;
            }
        }
    }
}
Also used : ReplaceChangeInfo(com.intellij.pom.tree.events.ReplaceChangeInfo) PsiManagerImpl(com.intellij.psi.impl.PsiManagerImpl) TreeChange(com.intellij.pom.tree.events.TreeChange) TreeChangeImpl(com.intellij.pom.tree.events.impl.TreeChangeImpl) ReplaceChangeInfo(com.intellij.pom.tree.events.ReplaceChangeInfo) ChangeInfo(com.intellij.pom.tree.events.ChangeInfo) ASTNode(com.intellij.lang.ASTNode) ChangeInfoImpl(com.intellij.pom.tree.events.impl.ChangeInfoImpl) PsiFile(com.intellij.psi.PsiFile) PsiTreeChangeEventImpl(com.intellij.psi.impl.PsiTreeChangeEventImpl) PsiElement(com.intellij.psi.PsiElement)

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