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);
}
}
});
}
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);
}
}
}
});
}
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);
}
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);
}
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;
}
}
}
}
Aggregations