Write interface added to ASTNode. Implementations delegate to ChangeUtil.

This commit is contained in:
Maxim Shafirov
2005-01-20 00:22:28 +03:00
parent f6521186bd
commit 4f77751e8b
4 changed files with 55 additions and 7 deletions
@@ -30,5 +30,11 @@ public interface ASTNode extends UserDataHolder {
ASTNode[] getChildren(TokenSet filter);
void addChild(ASTNode child, ASTNode anchorBefore);
void removeChild(ASTNode child);
void replaceChild(ASTNode oldChild, ASTNode newChild);
void replaceAllChildrenToChildrenOf(ASTNode anotherParent);
void addChildren(ASTNode firstChild, ASTNode lastChild, ASTNode anchorBefore);
Object clone();
}
@@ -1,18 +1,17 @@
package com.intellij.psi.impl.source.tree;
import com.intellij.lang.ASTNode;
import com.intellij.lexer.JavaLexer;
import com.intellij.lexer.Lexer;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.editor.Document;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.*;
import com.intellij.psi.impl.DebugUtil;
import com.intellij.psi.impl.PsiDocumentManagerImpl;
import com.intellij.psi.impl.PsiManagerImpl;
import com.intellij.psi.impl.PsiTreeChangeEventImpl;
import com.intellij.psi.impl.PsiDocumentManagerImpl;
import com.intellij.psi.impl.compiled.ClsFileImpl;
import com.intellij.psi.impl.cache.RepositoryManager;
import com.intellij.psi.impl.light.LightClassReference;
import com.intellij.psi.impl.light.LightTypeElement;
@@ -22,11 +21,12 @@ import com.intellij.psi.impl.source.codeStyle.CodeStyleManagerEx;
import com.intellij.psi.impl.source.parsing.*;
import com.intellij.util.CharTable;
import com.intellij.util.IncorrectOperationException;
import com.intellij.lang.ASTNode;
public class ChangeUtil implements Constants {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.ChangeUtil");
private ChangeUtil() {}
public static void addChild(final CompositeElement parent, final TreeElement child, TreeElement anchorBefore) {
LOG.assertTrue(anchorBefore == null || anchorBefore.getTreeParent() == parent);
@@ -93,7 +93,7 @@ public class ChangeUtil implements Constants {
}
}
public static void registerLeafsInCharTab(CharTable newCharTab, ASTNode child, CharTable oldCharTab) {
private static void registerLeafsInCharTab(CharTable newCharTab, ASTNode child, CharTable oldCharTab) {
if(newCharTab == oldCharTab) return;
while(child != null){
CharTable charTable = child.getUserData(CharTable.CHAR_TABLE_KEY);
@@ -306,4 +306,24 @@ public class CompositeElement extends TreeElement implements Cloneable{
public ASTNode getLastChildNode() {
return lastChild;
}
public void addChild(ASTNode child, ASTNode anchorBefore) {
ChangeUtil.addChild(this, (TreeElement)child, (TreeElement)anchorBefore);
}
public void removeChild(ASTNode child) {
ChangeUtil.removeChild(this, (TreeElement)child);
}
public void replaceChild(ASTNode oldChild, ASTNode newChild) {
ChangeUtil.replaceChild(this, (TreeElement)oldChild, (TreeElement)newChild);
}
public void replaceAllChildrenToChildrenOf(ASTNode anotherParent) {
ChangeUtil.replaceAllChildren(this, (CompositeElement)anotherParent);
}
public void addChildren(ASTNode firstChild, ASTNode lastChild, ASTNode anchorBefore) {
ChangeUtil.addChildren(this, (TreeElement)firstChild, lastChild, (TreeElement)anchorBefore);
}
}
@@ -3,8 +3,10 @@ package com.intellij.psi.impl.source.tree;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.TokenSet;
import com.intellij.util.CharTable;
import com.intellij.util.IncorrectOperationException;
import com.intellij.util.text.StringSearcher;
import com.intellij.lang.ASTNode;
import sun.plugin.dom.exception.InvalidStateException;
public abstract class LeafElement extends TreeElement {
private volatile int myState = 0; // 16 bit for type, 15 bit for state and 1 bit for parentFlag
@@ -127,5 +129,25 @@ public abstract class LeafElement extends TreeElement {
public ASTNode[] getChildren(TokenSet filter) {
return TreeElement.EMPTY_ARRAY;
}
}
public void addChild(ASTNode child, ASTNode anchorBefore) {
throw new InvalidStateException("Leaf elements cannot have children.");
}
public void removeChild(ASTNode child) {
throw new InvalidStateException("Leaf elements cannot have children.");
}
public void replaceChild(ASTNode oldChild, ASTNode newChild) {
throw new InvalidStateException("Leaf elements cannot have children.");
}
public void replaceAllChildrenToChildrenOf(ASTNode anotherParent) {
throw new InvalidStateException("Leaf elements cannot have children.");
}
public void addChildren(ASTNode firstChild, ASTNode lastChild, ASTNode anchorBefore) {
throw new InvalidStateException("Leaf elements cannot have children.");
}
}