remove some PsiLock usages in AST cloning and injection

This commit is contained in:
peter
2016-12-20 12:47:28 +01:00
parent 687bdaf2a8
commit d71b731f7a
5 changed files with 27 additions and 35 deletions
@@ -75,36 +75,32 @@ public class CompositeElement extends TreeElement {
public CompositeElement clone() {
CompositeElement clone = (CompositeElement)super.clone();
synchronized (PsiLock.LOCK) {
clone.firstChild = null;
clone.lastChild = null;
clone.myModificationsCount = 0;
clone.myWrapper = null;
for (ASTNode child = rawFirstChild(); child != null; child = child.getTreeNext()) {
clone.rawAddChildrenWithoutNotifications((TreeElement)child.clone());
}
clone.clearCaches();
clone.firstChild = null;
clone.lastChild = null;
clone.myModificationsCount = 0;
clone.myWrapper = null;
for (ASTNode child = rawFirstChild(); child != null; child = child.getTreeNext()) {
clone.rawAddChildrenWithoutNotifications((TreeElement)child.clone());
}
clone.clearCaches();
return clone;
}
public void subtreeChanged() {
synchronized (PsiLock.LOCK) {
CompositeElement compositeElement = this;
while(compositeElement != null) {
compositeElement.clearCaches();
if (!(compositeElement instanceof PsiElement)) {
final PsiElement psi = compositeElement.myWrapper;
if (psi instanceof ASTDelegatePsiElement) {
((ASTDelegatePsiElement)psi).subtreeChanged();
}
else if (psi instanceof PsiFile) {
((PsiFile)psi).subtreeChanged();
}
CompositeElement compositeElement = this;
while(compositeElement != null) {
compositeElement.clearCaches();
if (!(compositeElement instanceof PsiElement)) {
final PsiElement psi = compositeElement.myWrapper;
if (psi instanceof ASTDelegatePsiElement) {
((ASTDelegatePsiElement)psi).subtreeChanged();
}
else if (psi instanceof PsiFile) {
((PsiFile)psi).subtreeChanged();
}
compositeElement = compositeElement.getTreeParent();
}
compositeElement = compositeElement.getTreeParent();
}
}
@@ -22,13 +22,11 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectCoreUtil;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiLock;
import com.intellij.psi.TokenType;
import com.intellij.psi.impl.DebugUtil;
import com.intellij.psi.impl.ElementBase;
import com.intellij.psi.impl.PsiManagerEx;
import com.intellij.psi.impl.source.PsiFileImpl;
import com.intellij.psi.stubs.IStubElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.CharTable;
import org.jetbrains.annotations.NonNls;
@@ -57,13 +55,10 @@ public abstract class TreeElement extends ElementBase implements ASTNode, Clonea
@Override
public Object clone() {
TreeElement clone = (TreeElement)super.clone();
synchronized (PsiLock.LOCK) {
clone.myNextSibling = null;
clone.myPrevSibling = null;
clone.myParent = null;
clone.myStartOffsetInParent = -1;
}
clone.myNextSibling = null;
clone.myPrevSibling = null;
clone.myParent = null;
clone.myStartOffsetInParent = -1;
return clone;
}
@@ -64,6 +64,7 @@ import java.util.*;
*/
public class InjectedLanguageManagerImpl extends InjectedLanguageManager implements Disposable {
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.source.tree.injected.InjectedLanguageManagerImpl");
static final Object ourInjectionPsiLock = new String("injectionPsiLock");
private final Project myProject;
private final DumbService myDumbService;
private volatile DaemonProgressIndicator myProgress;
@@ -152,7 +153,7 @@ public class InjectedLanguageManagerImpl extends InjectedLanguageManager impleme
if (myProgress.isCanceled()) return;
JobLauncher.getInstance().invokeConcurrentlyUnderProgress(new ArrayList<>(injected), myProgress, true, commitProcessor);
synchronized (PsiLock.LOCK) {
synchronized (ourInjectionPsiLock) {
injected.clear();
injected.addAll(newDocuments);
}
@@ -466,7 +466,7 @@ public class InjectedLanguageUtil {
}
if (hostFile != null) {
// modification of cachedInjectedDocuments must be under PsiLock
synchronized (PsiLock.LOCK) {
synchronized (InjectedLanguageManagerImpl.ourInjectionPsiLock) {
List<DocumentWindow> cachedInjectedDocuments = getCachedInjectedDocuments(hostFile);
for (int i = cachedInjectedDocuments.size() - 1; i >= 0; i--) {
DocumentWindow cachedInjectedDocument = cachedInjectedDocuments.get(i);
@@ -231,7 +231,7 @@ public class MultiHostRegistrarImpl implements MultiHostRegistrar, ModificationT
SmartPsiElementPointer<PsiLanguageInjectionHost> pointer = ((ShredImpl)shreds.get(0)).getSmartPointer();
synchronized (PsiLock.LOCK) {
synchronized (InjectedLanguageManagerImpl.ourInjectionPsiLock) {
final ASTNode parsedNode = keepTreeFromChameleoningBack(psiFile);
assert parsedNode instanceof FileElement : "Parsed to "+parsedNode+" instead of FileElement";