use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class JavaStubPsiElement method deleteChildRange.
@Override
public void deleteChildRange(PsiElement first, PsiElement last) throws IncorrectOperationException {
CheckUtil.checkWritable(this);
if (first == null) {
LOG.assertTrue(last == null);
return;
}
ASTNode firstElement = SourceTreeToPsiMap.psiElementToTree(first);
ASTNode lastElement = SourceTreeToPsiMap.psiElementToTree(last);
CompositeElement treeElement = calcTreeElement();
LOG.assertTrue(firstElement.getTreeParent() == treeElement);
LOG.assertTrue(lastElement.getTreeParent() == treeElement);
CodeEditUtil.removeChildren(treeElement, firstElement, lastElement);
}
use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class JavaStubPsiElement method subtreeChanged.
@Override
public void subtreeChanged() {
final CompositeElement compositeElement = calcTreeElement();
if (compositeElement != null)
compositeElement.clearCaches();
super.subtreeChanged();
}
use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class AstPathPsiMap method switchToStrongRefs.
void switchToStrongRefs() {
myQueue.cleanupStaleReferences();
for (MyReference reference : myMap.values()) {
StubBasedPsiElementBase<?> psi = SoftReference.dereference(reference);
if (psi != null) {
CompositeElement node = (CompositeElement) psi.getNode();
node.setPsi(psi);
psi.setSubstrateRef(SubstrateRef.createAstStrongRef(node));
}
}
myMap.clear();
}
use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class TreeChangeEventImpl method compactChanges.
private void compactChanges(ASTNode parent, int depth) {
int currentDepth = myOfEqualDepth.size();
while (--currentDepth > depth) {
final Set<ASTNode> treeElements = myOfEqualDepth.get(currentDepth);
if (treeElements == null)
continue;
final Iterator<ASTNode> iterator = treeElements.iterator();
while (iterator.hasNext()) {
boolean isUnderCompacted = false;
final TreeElement treeElement = (TreeElement) iterator.next();
ASTNode currentParent = treeElement;
while (currentParent != null) {
if (currentParent == parent) {
isUnderCompacted = true;
break;
}
currentParent = currentParent.getTreeParent();
}
if (isUnderCompacted) {
final ChangeInfoImpl compactedChange = ChangeInfoImpl.create(ChangeInfo.CONTENTS_CHANGED, treeElement);
compactedChange.compactChange(getChangesByElement(treeElement));
iterator.remove();
removeAssociatedChanges(treeElement, currentDepth);
final CompositeElement treeParent = treeElement.getTreeParent();
final TreeChange changesByElement = getChangesByElement(treeParent);
if (changesByElement != null) {
final ChangeInfoImpl changeByChild = (ChangeInfoImpl) changesByElement.getChangeByChild(treeElement);
if (changeByChild != null) {
changeByChild.setOldLength(compactedChange.getOldLength());
} else {
changesByElement.addChange(treeElement, compactedChange);
}
} else {
processElementaryChange(treeParent, treeElement, compactedChange, currentDepth - 1);
}
}
}
}
}
use of com.intellij.psi.impl.source.tree.CompositeElement in project intellij-community by JetBrains.
the class DebugUtil method treeToBuffer.
public static void treeToBuffer(@NotNull final Appendable buffer, @NotNull final ASTNode root, final int indent, final boolean skipWhiteSpaces, final boolean showRanges, final boolean showChildrenRanges, final boolean usePsi, @Nullable PairConsumer<PsiElement, Consumer<PsiElement>> extra) {
if (skipWhiteSpaces && root.getElementType() == TokenType.WHITE_SPACE)
return;
StringUtil.repeatSymbol(buffer, ' ', indent);
try {
PsiElement psiElement = null;
if (root instanceof CompositeElement) {
if (usePsi) {
psiElement = root.getPsi();
if (psiElement != null) {
buffer.append(psiElement.toString());
} else {
buffer.append(root.getElementType().toString());
}
} else {
buffer.append(root.toString());
}
} else {
final String text = fixWhiteSpaces(root.getText());
buffer.append(root.toString()).append("('").append(text).append("')");
}
if (showRanges)
buffer.append(root.getTextRange().toString());
buffer.append("\n");
if (root instanceof CompositeElement) {
ASTNode child = root.getFirstChildNode();
if (child == null) {
StringUtil.repeatSymbol(buffer, ' ', indent + 2);
buffer.append("<empty list>\n");
} else {
while (child != null) {
treeToBuffer(buffer, child, indent + 2, skipWhiteSpaces, showChildrenRanges, showChildrenRanges, usePsi, extra);
child = child.getTreeNext();
}
}
}
if (psiElement != null && extra != null) {
extra.consume(psiElement, element -> treeToBuffer(buffer, element.getNode(), indent + 2, skipWhiteSpaces, showChildrenRanges, showChildrenRanges, usePsi, null));
}
} catch (IOException e) {
LOG.error(e);
}
}
Aggregations