diff --git a/java/java-tests/testSrc/com/intellij/psi/impl/PsiModificationTrackerTest.java b/java/java-tests/testSrc/com/intellij/psi/impl/PsiModificationTrackerTest.java index 0d2ae299f0fa..00efef76d9ff 100644 --- a/java/java-tests/testSrc/com/intellij/psi/impl/PsiModificationTrackerTest.java +++ b/java/java-tests/testSrc/com/intellij/psi/impl/PsiModificationTrackerTest.java @@ -425,7 +425,7 @@ public class PsiModificationTrackerTest extends CodeInsightTestCase { public void testNoIncrementOnWorkspaceFileChange() { FixtureRuleKt.runInLoadComponentStateMode(myProject, () -> { - ProjectKt.getStateStore(myProject).save(new SmartList<>(), false); + ProjectKt.getStateStore(myProject).save(new SmartList<>(), true); PsiModificationTracker tracker = getTracker(); long mc = tracker.getModificationCount(); @@ -503,10 +503,10 @@ public class PsiModificationTrackerTest extends CodeInsightTestCase { WriteCommandAction.runWriteCommandAction(getProject(), () -> { TextRange methodRange = anon.getMethods()[0].getTextRange(); getEditor().getDocument().deleteString(methodRange.getStartOffset(), methodRange.getEndOffset()); - + int gooIndex = file.getText().indexOf("goo"); getEditor().getDocument().deleteString(gooIndex, gooIndex + 3); - + PsiDocumentManager.getInstance(myProject).commitDocument(getEditor().getDocument()); }); @@ -542,7 +542,7 @@ public class PsiModificationTrackerTest extends CodeInsightTestCase { PsiUtilCore.ensureValid(method); Arrays.stream(method.findSuperMethods()).forEach(PsiUtilCore::ensureValid); - + assertFalse(javaCount == getTracker().getJavaStructureModificationCount()); } @@ -550,5 +550,4 @@ public class PsiModificationTrackerTest extends CodeInsightTestCase { private PsiModificationTracker getTracker() { return PsiManager.getInstance(getProject()).getModificationTracker(); } - } diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/xslt/Xslt2HighlightingTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/xslt/Xslt2HighlightingTest.java index dec5834973e5..d42b95d88ad4 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/xslt/Xslt2HighlightingTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/xslt/Xslt2HighlightingTest.java @@ -1,35 +1,23 @@ -/* - * Copyright 2000-2011 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. - */ +// Copyright 2000-2018 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 org.intellij.lang.xpath.xslt; import com.intellij.javaee.ExternalResourceManagerEx; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.util.ArrayUtil; import org.intellij.lang.xpath.TestBase; import org.intellij.lang.xpath.xslt.impl.XsltStuffProvider; +import java.util.ArrayList; +import java.util.List; + public class Xslt2HighlightingTest extends TestBase { @Override protected void setUp() throws Exception { super.setUp(); myFixture.enableInspections(XsltStuffProvider.INSPECTION_CLASSES); - ApplicationManager.getApplication().runWriteAction(() -> { - ExternalResourceManagerEx.getInstanceEx().addIgnoredResource("urn:my"); - ExternalResourceManagerEx.getInstanceEx().addIgnoredResource("nsx"); - }); + List list = new ArrayList<>(); + list.add("urn:my"); + list.add("nsx"); + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(list, getTestRootDisposable()); } public void testCurrentMode() { diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/xslt/XsltHighlightingTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/xslt/XsltHighlightingTest.java index 9d7e11217bce..06043d40ad21 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/xslt/XsltHighlightingTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/xslt/XsltHighlightingTest.java @@ -1,23 +1,8 @@ -/* - * Copyright 2000-2009 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. - */ +// Copyright 2000-2018 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 org.intellij.lang.xpath.xslt; import com.intellij.codeInsight.daemon.impl.analysis.XmlUnusedNamespaceInspection; import com.intellij.javaee.ExternalResourceManagerEx; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.ReadAction; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDocumentManager; @@ -26,135 +11,138 @@ import com.intellij.util.ArrayUtil; import org.intellij.lang.xpath.TestBase; import org.intellij.lang.xpath.xslt.impl.XsltStuffProvider; +import java.util.Collections; + public class XsltHighlightingTest extends TestBase { - @Override - protected void setUp() throws Exception { - super.setUp(); - myFixture.enableInspections(XsltStuffProvider.INSPECTION_CLASSES); - ApplicationManager.getApplication().runWriteAction(() -> ExternalResourceManagerEx.getInstanceEx().addIgnoredResource("urn:my")); - } + @Override + protected void setUp() throws Exception { + super.setUp(); - public void xtestBackwardIncludedVariable() { - doXsltHighlighting(); - } + myFixture.enableInspections(XsltStuffProvider.INSPECTION_CLASSES); + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(Collections.singletonList("urn:my"), getTestRootDisposable()); + } - public void testUnknownTemplate() { - doXsltHighlighting(); - } + public void xtestBackwardIncludedVariable() { + doXsltHighlighting(); + } - public void testDuplicateTemplate() { - doXsltHighlighting(); - } + public void testUnknownTemplate() { + doXsltHighlighting(); + } - public void testUnknownMode() { - doXsltHighlighting(); - } + public void testDuplicateTemplate() { + doXsltHighlighting(); + } - public void testUndeclaredParam() { - doXsltHighlighting(); - } + public void testUnknownMode() { + doXsltHighlighting(); + } - public void testMissingParam() { - doXsltHighlighting(); - } + public void testUndeclaredParam() { + doXsltHighlighting(); + } - public void testUnusedVariable() { - doXsltHighlighting(); - } + public void testMissingParam() { + doXsltHighlighting(); + } - public void testDuplicateVariable() { - doXsltHighlighting(); - } + public void testUnusedVariable() { + doXsltHighlighting(); + } - public void testNonDuplicateVariable() { - doXsltHighlighting(); - } + public void testDuplicateVariable() { + doXsltHighlighting(); + } - public void testShadowedVariable() { - doXsltHighlighting(); - } + public void testNonDuplicateVariable() { + doXsltHighlighting(); + } - public void testShadowedVariable2() { - doXsltHighlighting(); - } + public void testShadowedVariable() { + doXsltHighlighting(); + } - public void testValidPatterns() { - doXsltHighlighting(); - } + public void testShadowedVariable2() { + doXsltHighlighting(); + } - public void testInvalidPattern1() { - doXsltHighlighting(); - } + public void testValidPatterns() { + doXsltHighlighting(); + } - public void testInvalidPattern2() { - doXsltHighlighting(); - } + public void testInvalidPattern1() { + doXsltHighlighting(); + } - public void testInvalidPattern3() { - doXsltHighlighting(); - } + public void testInvalidPattern2() { + doXsltHighlighting(); + } - public void testInvalidPattern4() { - doXsltHighlighting(); - } + public void testInvalidPattern3() { + doXsltHighlighting(); + } - public void testInvalidPattern5() { - doXsltHighlighting(); - } + public void testInvalidPattern4() { + doXsltHighlighting(); + } - public void testInvalidPattern6() { - doXsltHighlighting(); - } + public void testInvalidPattern5() { + doXsltHighlighting(); + } - public void testEmptyExpression() { - doXsltHighlighting(); - } + public void testInvalidPattern6() { + doXsltHighlighting(); + } - public void testEmptyAVT() { - doXsltHighlighting(); - } + public void testEmptyExpression() { + doXsltHighlighting(); + } - public void testInvalidSingleClosingBrace() { - doXsltHighlighting(); - } + public void testEmptyAVT() { + doXsltHighlighting(); + } - public void testEscapedXPathString() { - doXsltHighlighting(); - } + public void testInvalidSingleClosingBrace() { + doXsltHighlighting(); + } - public void testXsltFreeze() { - doXsltHighlighting(); - } + public void testEscapedXPathString() { + doXsltHighlighting(); + } - public void testTemplateWithPrefix() { - myFixture.enableInspections(XmlUnusedNamespaceInspection.class); - doXsltHighlighting(); - } + public void testXsltFreeze() { + doXsltHighlighting(); + } - public void xtestPerformance() { - myFixture.configureByFile(getTestFileName() + ".xsl"); - final long l = runHighlighting(); - assertTrue("Highlighting took " + l + "ms", l < 6000); - } + public void testTemplateWithPrefix() { + myFixture.enableInspections(XmlUnusedNamespaceInspection.class); + doXsltHighlighting(); + } - private long runHighlighting() { - final Project project = myFixture.getProject(); - PsiDocumentManager.getInstance(project).commitAllDocuments(); + public void xtestPerformance() { + myFixture.configureByFile(getTestFileName() + ".xsl"); + final long l = runHighlighting(); + assertTrue("Highlighting took " + l + "ms", l < 6000); + } - return ReadAction.compute(() -> { - final long l = System.currentTimeMillis(); - CodeInsightTestFixtureImpl.instantiateAndRun(myFixture.getFile(), myFixture.getEditor(), ArrayUtil.EMPTY_INT_ARRAY, false); - return System.currentTimeMillis() - l; - }); - } + private long runHighlighting() { + final Project project = myFixture.getProject(); + PsiDocumentManager.getInstance(project).commitAllDocuments(); - private void doXsltHighlighting() { - final String name = getTestFileName(); - myFixture.testHighlighting(true, false, false, name + ".xsl"); - } + return ReadAction.compute(() -> { + final long l = System.currentTimeMillis(); + CodeInsightTestFixtureImpl.instantiateAndRun(myFixture.getFile(), myFixture.getEditor(), ArrayUtil.EMPTY_INT_ARRAY, false); + return System.currentTimeMillis() - l; + }); + } - @Override - protected String getSubPath() { - return "xslt/highlighting"; - } + private void doXsltHighlighting() { + final String name = getTestFileName(); + myFixture.testHighlighting(true, false, false, name + ".xsl"); + } + + @Override + protected String getSubPath() { + return "xslt/highlighting"; + } } diff --git a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/IgnoreExtResourceAction.java b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/IgnoreExtResourceAction.java index 3e02cf8f5be8..eba7e8851a37 100644 --- a/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/IgnoreExtResourceAction.java +++ b/xml/impl/src/com/intellij/codeInsight/daemon/impl/quickfix/IgnoreExtResourceAction.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2013 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. - */ +// Copyright 2000-2018 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.codeInsight.daemon.impl.quickfix; import com.intellij.javaee.ExternalResourceManagerEx; @@ -23,6 +9,8 @@ import com.intellij.util.IncorrectOperationException; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; + /** * @author mike */ @@ -40,6 +28,6 @@ public class IgnoreExtResourceAction extends BaseExtResourceAction { @Override protected void doInvoke(@NotNull final PsiFile file, final int offset, @NotNull final String uri, final Editor editor) throws IncorrectOperationException { - ExternalResourceManagerEx.getInstanceEx().addIgnoredResource(uri); + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(Collections.singletonList(uri), null); } } diff --git a/xml/impl/src/com/intellij/javaee/ExternalResourceConfigurable.java b/xml/impl/src/com/intellij/javaee/ExternalResourceConfigurable.java index f2a9ba1bcada..e046a4d316dd 100644 --- a/xml/impl/src/com/intellij/javaee/ExternalResourceConfigurable.java +++ b/xml/impl/src/com/intellij/javaee/ExternalResourceConfigurable.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2014 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. - */ +// Copyright 2000-2018 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.javaee; import com.intellij.openapi.application.ApplicationManager; @@ -162,10 +148,7 @@ public class ExternalResourceConfigurable extends BaseConfigurable } } - for (Object myIgnoredUrl : myIgnoredUrls) { - String url = (String)myIgnoredUrl; - manager.addIgnoredResource(url); - } + manager.addIgnoredResources(myIgnoredUrls, null); }); setModified(false); diff --git a/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java b/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java index 1d1047a2f0d5..49f91633cc12 100644 --- a/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java +++ b/xml/relaxng/test/org/intellij/plugins/relaxNG/HighlightingTestBase.java @@ -21,14 +21,12 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo; import com.intellij.codeInspection.*; import com.intellij.codeInspection.htmlInspections.RequiredAttributesInspection; import com.intellij.javaee.ExternalResourceManagerEx; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Document; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; -import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.io.FileUtil; import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiFile; @@ -49,6 +47,7 @@ import org.intellij.plugins.testUtil.ResourceUtil; import org.jetbrains.annotations.NotNull; import java.util.Collection; +import java.util.Collections; public abstract class HighlightingTestBase extends UsefulTestCase implements IdeaCodeInsightTestCase { protected CodeInsightTestFixture myTestFixture; @@ -118,10 +117,7 @@ public abstract class HighlightingTestBase extends UsefulTestCase implements Ide public abstract String getTestDataPath(); protected void init() { - ExternalResourceManagerEx resourceManager = ExternalResourceManagerEx.getInstanceEx(); - String url = "urn:test:undefined"; - ApplicationManager.getApplication().runWriteAction(() -> resourceManager.addIgnoredResource(url)); - Disposer.register(getTestRootDisposable(), () -> ApplicationManager.getApplication().runWriteAction(() -> resourceManager.removeIgnoredResource(url))); + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(Collections.singletonList("urn:test:undefined"), getTestRootDisposable()); } @Override diff --git a/xml/relaxng/test/org/intellij/plugins/relaxNG/RngXmlHighlightingTest.java b/xml/relaxng/test/org/intellij/plugins/relaxNG/RngXmlHighlightingTest.java index 4d5f310cf7b4..40543d569320 100644 --- a/xml/relaxng/test/org/intellij/plugins/relaxNG/RngXmlHighlightingTest.java +++ b/xml/relaxng/test/org/intellij/plugins/relaxNG/RngXmlHighlightingTest.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.intellij.plugins.relaxNG; import com.intellij.javaee.ExternalResourceManagerEx; @@ -21,8 +20,10 @@ import com.intellij.javaee.ExternalResourceManagerExImpl; import com.intellij.openapi.application.ApplicationManager; import org.intellij.plugins.testUtil.CopyFile; -public class RngXmlHighlightingTest extends HighlightingTestBase { +import java.util.ArrayList; +import java.util.List; +public class RngXmlHighlightingTest extends HighlightingTestBase { @Override public String getTestDataPath() { return "highlighting"; @@ -33,7 +34,6 @@ public class RngXmlHighlightingTest extends HighlightingTestBase { super.init(); ApplicationManager.getApplication().runWriteAction(() -> { - final ExternalResourceManagerEx m = ExternalResourceManagerEx.getInstanceEx(); ExternalResourceManagerExImpl .addTestResource("urn:test:simple.rng", toAbsolutePath("highlighting/simple.rng"), getTestRootDisposable()); ExternalResourceManagerExImpl.addTestResource("urn:test:addressBook", toAbsolutePath("highlighting/rnc/addressbook.rnc"), @@ -48,18 +48,20 @@ public class RngXmlHighlightingTest extends HighlightingTestBase { ExternalResourceManagerExImpl .addTestResource("http://www.w3.org/1999/xhtml", toAbsolutePath("highlighting/html5/xhtml5.rnc"), getTestRootDisposable()); - m.addIgnoredResource("urn:intelliForm:Spaces"); - m.addIgnoredResource("http://www.w3.org/1999/xlink"); - m.addIgnoredResource("http://www.w3.org/2000/svg"); - m.addIgnoredResource("http://www.ascc.net/xml/schematron"); - m.addIgnoredResource("http://www.w3.org/2000/svg"); - m.addIgnoredResource("http://www.w3.org/1998/Math/MathML"); - m.addIgnoredResource("http://www.w3.org/1999/02/22-rdf-syntax-ns#"); - m.addIgnoredResource("http://nwalsh.com/xmlns/schema-control/"); - m.addIgnoredResource("http://xml.apache.org/fop/extensions"); - m.addIgnoredResource("http://www.antennahouse.com/names/XSL/Extensions"); - m.addIgnoredResource("http://www.renderx.com/XSL/Extensions"); - m.addIgnoredResource("http://relaxng.org/ns/compatibility/annotations/1.0"); + List list = new ArrayList<>(); + list.add("urn:intelliForm:Spaces"); + list.add("http://www.w3.org/1999/xlink"); + list.add("http://www.w3.org/2000/svg"); + list.add("http://www.ascc.net/xml/schematron"); + list.add("http://www.w3.org/2000/svg"); + list.add("http://www.w3.org/1998/Math/MathML"); + list.add("http://www.w3.org/1999/02/22-rdf-syntax-ns#"); + list.add("http://nwalsh.com/xmlns/schema-control/"); + list.add("http://xml.apache.org/fop/extensions"); + list.add("http://www.antennahouse.com/names/XSL/Extensions"); + list.add("http://www.renderx.com/XSL/Extensions"); + list.add("http://relaxng.org/ns/compatibility/annotations/1.0"); + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(list, getTestRootDisposable()); }); } diff --git a/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java b/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java index d87dd33ab9ce..84b5531dff2e 100644 --- a/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java +++ b/xml/tests/src/com/intellij/codeInsight/daemon/XmlHighlightingTest.java @@ -1,18 +1,4 @@ -/* - * 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. - */ +// Copyright 2000-2018 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.codeInsight.daemon; import com.intellij.application.options.XmlSettings; @@ -40,7 +26,6 @@ import com.intellij.openapi.actionSystem.ActionManager; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.IdeActions; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.EditorFactory; @@ -565,26 +550,19 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { } public void testExternalValidatorOnValidXmlWithNamespacesNotSetup() throws Exception { - final ExternalResourceManagerEx instanceEx = ExternalResourceManagerEx.getInstanceEx(); - WriteCommandAction.runWriteCommandAction(null, () -> { - instanceEx.addIgnoredResource("http://xml.apache.org/axis/wsdd2/"); - instanceEx.addIgnoredResource("http://xml.apache.org/axis/wsdd2/providers/java"); - instanceEx.addIgnoredResource("http://soapinterop.org/xsd2"); - }); + List list = new ArrayList<>(); + list.add("http://xml.apache.org/axis/wsdd2/"); + list.add("http://xml.apache.org/axis/wsdd2/providers/java"); + list.add("http://soapinterop.org/xsd2"); + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(list, getTestRootDisposable()); doTest(getFullRelativeTestName(".xml"), true, false); } @HighlightingFlags(HighlightingFlag.SkipExternalValidation) public void testExternalValidatorOnValidXmlWithNamespacesNotSetup2() throws Exception { - final ExternalResourceManagerEx instanceEx = ExternalResourceManagerEx.getInstanceEx(); - try { - WriteCommandAction.runWriteCommandAction(null, () -> instanceEx.addIgnoredResource("")); - - doTest(getFullRelativeTestName(".xml"), true, false); - } finally { - WriteCommandAction.runWriteCommandAction(null, () -> instanceEx.removeIgnoredResource("")); - } + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(Collections.singletonList(""), getTestRootDisposable()); + doTest(getFullRelativeTestName(".xml"), true, false); } public void testXercesMessagesBinding() throws Exception { @@ -1041,10 +1019,8 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { } public void testIgnoredNamespaceHighlighting() throws Exception { - WriteCommandAction.runWriteCommandAction(null, () -> ExternalResourceManagerEx.getInstanceEx().addIgnoredResource("http://ignored/uri")); - + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(Collections.singletonList("http://ignored/uri"), getTestRootDisposable()); doTest(); - ApplicationManager.getApplication().runWriteAction(() -> ExternalResourceManagerEx.getInstanceEx().removeIgnoredResource("http://ignored/uri")); } public void testNonEnumeratedValuesHighlighting() throws Exception { @@ -1614,18 +1590,11 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { BASE_PATH +testName +"TestSchema.xsd" ); - ExternalResourceManagerEx externalResourceManager = ExternalResourceManagerEx.getInstanceEx(); - try { - ApplicationManager.getApplication().runWriteAction(() -> externalResourceManager.addIgnoredResource("oxf:/apps/somefile.xml")); + ExternalResourceManagerEx.getInstanceEx().addIgnoredResources(Collections.singletonList("oxf:/apps/somefile.xml"), getTestRootDisposable()); + doDoTest(true, false, true); - doDoTest(true, false, true); - - VirtualFile[] includedFiles = FileIncludeManager.getManager(getProject()).getIncludedFiles(getFile().getVirtualFile(), true); - assertEquals(1, includedFiles.length); - } - finally { - ApplicationManager.getApplication().runWriteAction(() -> externalResourceManager.removeIgnoredResource("oxf:/apps/somefile.xml")); - } + VirtualFile[] includedFiles = FileIncludeManager.getManager(getProject()).getIncludedFiles(getFile().getVirtualFile(), true); + assertEquals(1, includedFiles.length); } public void testComplexRedefine() throws Exception { @@ -1787,11 +1756,9 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { } public void testComplexRedefineFromJar() { - String[][] urls = null; - configureByFiles(null,BASE_PATH + getTestName(false) + ".xml", BASE_PATH + "mylib.jar"); String path = myFile.getVirtualFile().getParent().getPath() + "/"; - urls = new String[][] { + String[][] urls = new String[][] { {"http://graphml.graphdrawing.org/xmlns",path + "mylib.jar!/graphml.xsd"}, {"http://graphml.graphdrawing.org/xmlns/1.0/graphml-structure.xsd",path + "mylib.jar!/graphml-structure.xsd"}, {"http://www.w3.org/1999/xlink",path + "mylib.jar!/xlink.xsd"} @@ -2074,7 +2041,7 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { List list = PlatformTestUtil.collectWebReferences(myFile); assertEquals(2, list.size()); - Collections.sort(list, (o1, o2) -> o1.getCanonicalText().length() - o2.getCanonicalText().length()); + Collections.sort(list, Comparator.comparingInt(o -> o.getCanonicalText().length())); assertEquals("https://www.jetbrains.com/ruby/download", list.get(0).getCanonicalText()); assertTrue(list.get(0).getElement() instanceof XmlAttributeValue); @@ -2250,7 +2217,11 @@ public class XmlHighlightingTest extends DaemonAnalyzerTestCase { @Override protected void tearDown() throws Exception { - XmlSettings.getInstance().SHOW_XML_ADD_IMPORT_HINTS = old; - super.tearDown(); + try { + XmlSettings.getInstance().SHOW_XML_ADD_IMPORT_HINTS = old; + } + finally { + super.tearDown(); + } } } \ No newline at end of file diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/CoreExternalResourceManager.java b/xml/xml-psi-impl/src/com/intellij/javaee/CoreExternalResourceManager.java index 405aa6d07d16..655351adf13a 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/CoreExternalResourceManager.java +++ b/xml/xml-psi-impl/src/com/intellij/javaee/CoreExternalResourceManager.java @@ -1,20 +1,7 @@ -/* - * Copyright 2000-2015 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. - */ +// Copyright 2000-2018 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.javaee; +import com.intellij.openapi.Disposable; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; @@ -24,6 +11,8 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + /** * @author yole */ @@ -61,6 +50,11 @@ public class CoreExternalResourceManager extends ExternalResourceManagerEx { throw new UnsupportedOperationException(); } + @Override + public void addIgnoredResources(@NotNull List urls, @Nullable Disposable disposable) { + throw new UnsupportedOperationException(); + } + @Override public void removeIgnoredResource(@NotNull String url) { throw new UnsupportedOperationException(); @@ -196,7 +190,7 @@ public class CoreExternalResourceManager extends ExternalResourceManagerEx { } @Override - public String[] getResourceUrls(@Nullable FileType fileType, @NotNull @NonNls String version, boolean includeStandard) { + public String[] getResourceUrls(@Nullable FileType fileType, @Nullable @NonNls String version, boolean includeStandard) { throw new UnsupportedOperationException(); } } diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerEx.java b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerEx.java index be8d0f047c8d..1d36a04eae53 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerEx.java +++ b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerEx.java @@ -1,20 +1,7 @@ -/* - * Copyright 2000-2015 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. - */ +// Copyright 2000-2018 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.javaee; +import com.intellij.openapi.Disposable; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.MultiMap; @@ -22,6 +9,8 @@ import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.List; + public abstract class ExternalResourceManagerEx extends ExternalResourceManager { @NonNls public static final String STANDARD_SCHEMAS = "/standardSchemas/"; @@ -46,8 +35,18 @@ public abstract class ExternalResourceManagerEx extends ExternalResourceManager public abstract void clearAllResources(Project project); + /** + * @deprecated Use {@link #addIgnoredResources(List, Disposable)} + */ + @Deprecated public abstract void addIgnoredResource(@NotNull String url); + public abstract void addIgnoredResources(@NotNull List urls, @Nullable Disposable disposable); + + /** + * @deprecated Use {@link #addIgnoredResources(List, Disposable)} + */ + @Deprecated public abstract void removeIgnoredResource(@NotNull String url); public abstract boolean isIgnoredResource(@NotNull String url); diff --git a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java index 9fd86bed5979..a806df990faf 100644 --- a/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java +++ b/xml/xml-psi-impl/src/com/intellij/javaee/ExternalResourceManagerExImpl.java @@ -350,6 +350,47 @@ public class ExternalResourceManagerExImpl extends ExternalResourceManagerEx imp } } + public void addIgnoredResources(@NotNull List urls, @Nullable Disposable disposable) { + Application app = ApplicationManager.getApplication(); + if (app.isWriteAccessAllowed()) { + doAddIgnoredResources(urls, disposable); + } + else { + app.runWriteAction(() -> { + doAddIgnoredResources(urls, disposable); + }); + } + } + + private void doAddIgnoredResources(@NotNull List urls, @Nullable Disposable disposable) { + long modificationCount = getModificationCount(); + for (String url : urls) { + addIgnoredSilently(url); + } + + if (modificationCount != getModificationCount()) { + if (disposable != null) { + //noinspection CodeBlock2Expr + Disposer.register(disposable, () -> { + ApplicationManager.getApplication().runWriteAction(() -> { + boolean isChanged = false; + for (String url : urls) { + if (myIgnoredResources.remove(url)) { + isChanged = true; + } + } + + if (isChanged) { + fireExternalResourceChanged(); + } + }); + }); + } + + fireExternalResourceChanged(); + } + } + private boolean addIgnoredSilently(@NotNull String url) { if (myStandardIgnoredResources.contains(url)) { return false;