From c5dd1c8ed1075af7fae96427a8cfbb4856e5bfe7 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Tue, 6 Sep 2011 11:52:56 +0400 Subject: [PATCH] IDEA-73793 --- .../impl/source/tree/CompositeElement.java | 4 +- .../impl/source/tree/CompositePsiElement.java | 14 ++++--- .../source/tree/LazyParseableElement.java | 40 +++++++++---------- .../source/tree/LazyParseablePsiElement.java | 15 ++++--- .../psi/impl/source/xml/XmlDocumentImpl.java | 3 +- 5 files changed, 41 insertions(+), 35 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/CompositeElement.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/CompositeElement.java index a8ac05100c11..6a1df7da140e 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/CompositeElement.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/CompositeElement.java @@ -66,7 +66,7 @@ public class CompositeElement extends TreeElement { return myModificationsCount; } - public Object clone() { + public CompositeElement clone() { CompositeElement clone = (CompositeElement)super.clone(); synchronized (PsiLock.LOCK) { @@ -109,8 +109,8 @@ public class CompositeElement extends TreeElement { PsiFile psiFile = null; boolean ok = ApplicationManager.getApplication().isWriteAccessAllowed() || Thread.holdsLock(START_OFFSET_LOCK) || - wrapper != null && !wrapper.isPhysical() || (fileElement = TreeUtil.getFileElement(this)) == null || + wrapper != null && !wrapper.isPhysical() || (psiFile = (PsiFile)fileElement.getPsi()) == null || psiFile instanceof DummyHolder || psiFile.getViewProvider() instanceof FreeThreadedFileViewProvider || diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/CompositePsiElement.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/CompositePsiElement.java index 9a135a13f673..591a5fc5a76c 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/CompositePsiElement.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/CompositePsiElement.java @@ -43,6 +43,14 @@ public abstract class CompositePsiElement extends CompositeElement implements Ps protected CompositePsiElement(IElementType type) { super(type); + setPsi(this); + } + + @Override + public CompositePsiElement clone() { + CompositePsiElement clone = (CompositePsiElement)super.clone(); + clone.setPsi(clone); + return clone; } @NotNull @@ -259,11 +267,6 @@ public abstract class CompositePsiElement extends CompositeElement implements Ps return this; } - @Override - protected PsiElement createPsiNoLock() { - return this; - } - private PsiElement addInnerBefore(final PsiElement element, final PsiElement anchor) throws IncorrectOperationException { CheckUtil.checkWritable(this); TreeElement elementCopy = ChangeUtil.copyToElement(element); @@ -276,3 +279,4 @@ public abstract class CompositePsiElement extends CompositeElement implements Ps return this == another; } } + diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/LazyParseableElement.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/LazyParseableElement.java index bd49759d983f..973a9a6dff20 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/LazyParseableElement.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/LazyParseableElement.java @@ -146,38 +146,36 @@ public class LazyParseableElement extends CompositeElement { } private void ensureParsed() { - ASTNode parsedNode; + CharSequence text = myText(); + if (text == null) return; + + if (TreeUtil.getFileElement(this) == null) { + LOG.error("Chameleons must not be parsed till they're in file tree: " + this); + } + + ApplicationManager.getApplication().assertReadAccessAllowed(); + + ILazyParseableElementType type = (ILazyParseableElementType)getElementType(); + ASTNode parsedNode = type.parseContents(this); + + if (parsedNode == null && text.length() > 0) { + CharSequence diagText = ApplicationManager.getApplication().isInternal() ? text : ""; + LOG.error("No parse for a non-empty string: " + diagText + "; type=" + LogUtil.objectAndClass(type)); + } + synchronized (lock) { if (myText == null) return; if (rawFirstChild() != null) { LOG.error("Reentrant parsing?"); } - if (TreeUtil.getFileElement(this) == null) { - LOG.error("Chameleons must not be parsed till they're in file tree: " + this); - } - - ApplicationManager.getApplication().assertReadAccessAllowed(); - - ILazyParseableElementType type = (ILazyParseableElementType)getElementType(); - parsedNode = type.parseContents(this); - - if (parsedNode == null && myText.length() > 0) { - if (ApplicationManager.getApplication().isInternal() && !ApplicationManager.getApplication().isUnitTestMode()) { - LOG.error("No parse for a non-empty string: " + myText + "; type=" + LogUtil.objectAndClass(type)); - } else { - LOG.error("No parse for a non-empty string: type=" + LogUtil.objectAndClass(type)); - } - } - - //CharSequence text = myText; myText = null; if (parsedNode == null) return; - rawAddChildrenWithoutNotifications((TreeElement)parsedNode); + super.rawAddChildrenWithoutNotifications((TreeElement)parsedNode); //if (getNotCachedLength() != text.length()) { - // if (ApplicationManagerEx.getApplicationEx().isInternal()) { + // if (ApplicationManager.getApplication().isInternal()) { // LOG.error("Inconsistent reparse: type=" + getElementType() + "; text=" + text + "; treeText=" + getText()); // } else { // LOG.error("Inconsistent reparse: type=" + getElementType()); diff --git a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/LazyParseablePsiElement.java b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/LazyParseablePsiElement.java index 6e930f422839..efc31d120b4c 100644 --- a/platform/lang-impl/src/com/intellij/psi/impl/source/tree/LazyParseablePsiElement.java +++ b/platform/lang-impl/src/com/intellij/psi/impl/source/tree/LazyParseablePsiElement.java @@ -51,6 +51,14 @@ public class LazyParseablePsiElement extends LazyParseableElement implements Psi public LazyParseablePsiElement(@NotNull IElementType type, CharSequence buffer) { super(type, buffer); + setPsi(this); + } + + @Override + public LazyParseablePsiElement clone() { + LazyParseablePsiElement clone = (LazyParseablePsiElement)super.clone(); + clone.setPsi(clone); + return clone; } @NotNull @@ -72,7 +80,7 @@ public class LazyParseablePsiElement extends LazyParseableElement implements Psi for (PsiElement cur = getFirstChild(); cur != null; cur = cur.getNextSibling()) { if (ReflectionCache.isInstance(cur, aClass)) result.add((T)cur); } - return result.toArray((T[]) Array.newInstance(aClass, result.size())); + return result.toArray((T[])Array.newInstance(aClass, result.size())); } public PsiElement getFirstChild() { @@ -287,11 +295,6 @@ public class LazyParseablePsiElement extends LazyParseableElement implements Psi return this; } - @Override - protected PsiElement createPsiNoLock() { - return this; - } - private PsiElement addInnerBefore(final PsiElement element, final PsiElement anchor) throws IncorrectOperationException { CheckUtil.checkWritable(this); TreeElement elementCopy = ChangeUtil.copyToElement(element); diff --git a/xml/impl/src/com/intellij/psi/impl/source/xml/XmlDocumentImpl.java b/xml/impl/src/com/intellij/psi/impl/source/xml/XmlDocumentImpl.java index eb920c654a50..38d8cedcecf0 100644 --- a/xml/impl/src/com/intellij/psi/impl/source/xml/XmlDocumentImpl.java +++ b/xml/impl/src/com/intellij/psi/impl/source/xml/XmlDocumentImpl.java @@ -31,6 +31,7 @@ import com.intellij.psi.*; import com.intellij.psi.impl.PsiCachedValueImpl; import com.intellij.psi.impl.meta.MetaRegistry; import com.intellij.psi.impl.source.html.dtd.HtmlNSDescriptorImpl; +import com.intellij.psi.impl.source.tree.CompositePsiElement; import com.intellij.psi.impl.source.tree.TreeElement; import com.intellij.psi.meta.PsiMetaData; import com.intellij.psi.meta.PsiMetaOwner; @@ -287,7 +288,7 @@ public class XmlDocumentImpl extends XmlElementImpl implements XmlDocument { return descriptor; } - public Object clone() { + public CompositePsiElement clone() { HashMap> cacheStrict = new HashMap>( myDefaultDescriptorsCacheStrict );