use of com.intellij.pom.tree.events.ChangeInfo in project intellij-community by JetBrains.
the class TreeChangeImpl method getOldLength.
@Override
public int getOldLength() {
int oldLength = ((TreeElement) myParent).getNotCachedLength();
for (final Map.Entry<ASTNode, ChangeInfo> entry : myChanges.entrySet()) {
final ASTNode key = entry.getKey();
final ChangeInfo change = entry.getValue();
final int length = ((TreeElement) key).getNotCachedLength();
switch(change.getChangeType()) {
case ChangeInfo.ADD:
oldLength -= length;
break;
case ChangeInfo.REMOVED:
oldLength += length;
break;
case ChangeInfo.REPLACE:
case ChangeInfo.CONTENTS_CHANGED:
oldLength += change.getOldLength() - length;
break;
}
}
return oldLength;
}
use of com.intellij.pom.tree.events.ChangeInfo in project intellij-community by JetBrains.
the class TreeChangeImpl method toString.
@SuppressWarnings({ "HardCodedStringLiteral" })
public String toString() {
final StringBuilder buffer = new StringBuilder();
final Iterator<Pair<ASTNode, Integer>> iterator = mySortedChanges.iterator();
while (iterator.hasNext()) {
final Pair<ASTNode, Integer> pair = iterator.next();
final ASTNode node = pair.getFirst();
buffer.append("(");
buffer.append(node.getElementType().toString());
buffer.append(" at ").append(pair.getSecond()).append(", ");
ChangeInfo child = getChangeByChild(node);
buffer.append(child != null ? child.toString() : "null");
buffer.append(")");
if (iterator.hasNext())
buffer.append(", ");
}
return buffer.toString();
}
use of com.intellij.pom.tree.events.ChangeInfo 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