From a2c6156a3bb306de9d61d01249012059edce4b72 Mon Sep 17 00:00:00 2001 From: Dmitry Avdeev Date: Thu, 24 Aug 2017 17:32:20 +0300 Subject: [PATCH] fixing attribute value cache --- .../codeInsight/daemon/XmlStressTest.java | 74 +++++++++++++++++++ .../psi/impl/source/xml/XmlTagImpl.java | 3 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 xml/tests/src/com/intellij/codeInsight/daemon/XmlStressTest.java diff --git a/xml/tests/src/com/intellij/codeInsight/daemon/XmlStressTest.java b/xml/tests/src/com/intellij/codeInsight/daemon/XmlStressTest.java new file mode 100644 index 000000000000..0a918c721a99 --- /dev/null +++ b/xml/tests/src/com/intellij/codeInsight/daemon/XmlStressTest.java @@ -0,0 +1,74 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.codeInsight.daemon; + +import com.intellij.codeInsight.daemon.impl.analysis.XmlPathReferenceInspection; +import com.intellij.codeInsight.daemon.impl.analysis.XmlUnboundNsPrefixInspection; +import com.intellij.codeInspection.LocalInspectionTool; +import com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection; +import com.intellij.javaee.ExternalResourceManagerExImpl; +import com.intellij.testFramework.PlatformTestUtil; +import com.intellij.xml.util.CheckDtdReferencesInspection; +import com.intellij.xml.util.CheckXmlFileWithXercesValidatorInspection; +import com.intellij.xml.util.XmlDuplicatedIdInspection; +import com.intellij.xml.util.XmlInvalidIdInspection; + +import java.io.File; + +public class XmlStressTest extends DaemonAnalyzerTestCase { + + public void testSchemaValidator() throws Exception { + for (int i = 0; i < 100; i++) { + doTest("xml/WsdlValidation.wsdl", false, false); + System.out.println(i); + } + } + + private static final String BASE_PATH = "/xml/"; + + @Override + protected LocalInspectionTool[] configureLocalInspectionTools() { + return new LocalInspectionTool[]{ + new RequiredAttributesInspection(), + new XmlDuplicatedIdInspection(), + new XmlInvalidIdInspection(), + new CheckDtdReferencesInspection(), + new XmlUnboundNsPrefixInspection(), + new XmlPathReferenceInspection() + }; + } + + @Override + public void setUp() throws Exception { + super.setUp(); + enableInspectionTool(new CheckXmlFileWithXercesValidatorInspection()); + + ExternalResourceManagerExImpl.registerResourceTemporarily("http://schemas.xmlsoap.org/wsdl/", + getTestDataPath() + BASE_PATH + "wsdl11.xsd", + getTestRootDisposable()); + ExternalResourceManagerExImpl.registerResourceTemporarily("http://schemas.xmlsoap.org/wsdl/soap/", + getTestDataPath() + BASE_PATH + "wsdl11_soapbinding.xsd", + getTestRootDisposable()); + ExternalResourceManagerExImpl.registerResourceTemporarily("http://schemas.xmlsoap.org/soap/encoding/", + getTestDataPath() + BASE_PATH + "soap-encoding.xsd", + getTestRootDisposable()); + } + + @Override + protected String getTestDataPath() { + return PlatformTestUtil.getCommunityPath().replace(File.separatorChar, '/') + "/xml/tests/testData/"; + } +} diff --git a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java index 313126af9eb1..1668303fe50d 100644 --- a/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/psi/impl/source/xml/XmlTagImpl.java @@ -628,7 +628,8 @@ public class XmlTagImpl extends XmlElementImpl implements XmlTag, HintedReferenc for (XmlAttribute attribute : getAttributes()) { cacheOneAttributeValue(attribute.getName(), attribute.getValue(), map); } - myAttributeValueMap = map; + // copy map to prevent instruction reordering by compiler + myAttributeValueMap = new THashMap<>(map); } return map.get(qname); }