remove dom/sem clearCaches from public API

GitOrigin-RevId: 12151d373d0f74778eee2218d92a4e29ec532dbb
This commit is contained in:
peter
2019-08-30 12:55:33 +02:00
committed by intellij-monorepo-bot
parent 78efd6e964
commit 7a2c48afbc
4 changed files with 2 additions and 151 deletions

View File

@@ -25,6 +25,4 @@ public abstract class SemService {
}
public abstract <T extends SemElement> List<T> getSemElements(SemKey<T> key, @NotNull PsiElement psi);
public abstract void clearCache();
}

View File

@@ -111,13 +111,11 @@ public final class SemServiceImpl extends SemService {
return map;
}
@Override
public void clearCache() {
private void clearCache() {
myCache.set(null);
}
@Override
@Nullable
public <T extends SemElement> List<T> getSemElements(@NotNull SemKey<T> key, @NotNull final PsiElement psi) {
List<T> cached = _getCachedSemElements(key, psi);
if (cached != null) {

View File

@@ -473,7 +473,7 @@ public final class DomManagerImpl extends DomManager {
}
}
public void clearCache() {
private void clearCache() {
incModificationCount();
}
}

View File

@@ -1,145 +0,0 @@
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.util.xml;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.xml.XmlFile;
import com.intellij.psi.xml.XmlTag;
import com.intellij.testFramework.ServiceContainerUtil;
import com.intellij.testFramework.Timings;
import com.intellij.util.ConcurrencyUtil;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.xml.impl.DomTestCase;
import com.intellij.util.xml.reflect.DomExtender;
import com.intellij.util.xml.reflect.DomExtenderEP;
import com.intellij.util.xml.reflect.DomExtensionsRegistrar;
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
import java.util.List;
import java.util.Random;
import java.util.concurrent.CountDownLatch;
/**
* @author peter
*/
public class DomConcurrencyStressTest extends DomTestCase {
private void registerExtender(final Class elementClass, final Class extenderClass) {
final DomExtenderEP extenderEP = new DomExtenderEP();
extenderEP.domClassName = elementClass.getName();
extenderEP.extenderClassName = extenderClass.getName();
ServiceContainerUtil.registerExtension(ApplicationManager.getApplication(), DomExtenderEP.EP_NAME, extenderEP, getTestRootDisposable());
}
private static void runThreads(int threadCount, final Runnable runnable) throws Throwable {
for (int i=0; i<threadCount/8 + 1; i++) {
final Ref<Throwable> exc = Ref.create(null);
int N = 8;
final CountDownLatch reads = new CountDownLatch(N);
List<Thread> threads = ContainerUtil.map(Collections.nCopies(N, ""), s -> new Thread("dom concurrency") {
@Override
public void run() {
try {
runnable.run();
}
catch (Throwable e) {
exc.set(e);
}
finally {
reads.countDown();
}
}
});
threads.forEach(Thread::start);
reads.await();
if (!exc.isNull()) {
throw exc.get();
}
ConcurrencyUtil.joinAll(threads);
}
}
public interface MyElement extends DomElement {
MyElement getFooChild();
MyElement getBarChild();
MyElement getSomeChild();
List<MyElement> getFooElements();
MyElement addFooElement();
List<MyElement> getChildren();
MyElement addChild();
GenericAttributeValue<String> getAttr();
GenericAttributeValue<String> getAttr2();
@SubTag(indicator = true)
GenericDomValue<Boolean> getBool();
}
public void testBigCustomFile() throws Throwable {
final int ITERATIONS = Timings.adjustAccordingToMySpeed(239, true);
getDomManager().registerFileDescription(new DomFileDescription<>(MyAllCustomElement.class, "component"), getTestRootDisposable());
registerExtender(MyAllCustomElement.class, MyAllCustomExtender.class);
String line = "<tag1><tag2><tag3 attr=\"42\">value</tag3></tag2></tag1>\n";
String text = "<component>\n" + StringUtil.repeat(line, 100) + "</component>";
XmlFile file = (XmlFile)createFile("a.xml", text);
runThreads(42, () -> {
final Random random = new Random();
for (int i = 0; i < ITERATIONS; i++) {
ApplicationManager.getApplication().runReadAction(() -> {
int offset = random.nextInt(file.getTextLength() - 10);
XmlTag tag = PsiTreeUtil.findElementOfClassAtOffset(file, offset, XmlTag.class, false);
assert tag != null : offset;
DomElement element = DomUtil.getDomElement(tag);
assert element instanceof MyAllCustomElement : element;
});
if (random.nextInt(20) == 0) {
getDomManager().clearCache();
}
}
});
}
public interface MyAllCustomElement extends DomElement {}
public static class MyAllCustomExtender extends DomExtender<MyAllCustomElement> {
@Override
public void registerExtensions(@NotNull MyAllCustomElement element, @NotNull DomExtensionsRegistrar registrar) {
try {
DomElement parent = element;
while (parent != null) {
for (DomElement child : DomUtil.getDefinedChildren(parent, true, true)) {
DomElement childParent = child.getParent();
if (!parent.equals(childParent)) {
String parentText = parent.getXmlTag().getText();
String childText = child.getXmlElement().getText();
child.getParent();
parent.equals(childParent);
throw new AssertionError(parent.getXmlElement() + "; " + childParent + "; " + child.getXmlElement().getText());
}
}
parent = parent.getParent();
}
}
catch (StackOverflowError e) {
System.out.println(Thread.currentThread() + ": " + element.getXmlTag().getName() + element.getXmlTag().hashCode());
throw e;
}
registrar.registerCustomChildrenExtension(MyAllCustomElement.class);
}
}
}