diff --git a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/completion/XPathCompletionContributor.java b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/completion/XPathCompletionContributor.java index 25d74e5a34c7..5710cf8d6fc9 100644 --- a/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/completion/XPathCompletionContributor.java +++ b/plugins/xpath/xpath-lang/src/org/intellij/lang/xpath/completion/XPathCompletionContributor.java @@ -18,7 +18,6 @@ package org.intellij.lang.xpath.completion; import com.intellij.codeInsight.completion.*; import com.intellij.codeInsight.lookup.LookupItem; -import com.intellij.openapi.application.ApplicationManager; import com.intellij.patterns.PatternCondition; import com.intellij.psi.PsiElement; import com.intellij.psi.util.PsiTreeUtil; @@ -90,10 +89,6 @@ public class XPathCompletionContributor extends CompletionContributor { } final NamespaceContext namespaceContext = parent.getXPathContext().getNamespaceContext(); - if (ApplicationManager.getApplication().isUnitTestMode()) { - System.out.println("XPathCompletionContributor.addCompletions"); - System.out.println("namespaceContext = " + namespaceContext); - } if (namespaceContext != null) { final String prefixForURI = namespaceContext.getPrefixForURI(XPath2Type.XMLSCHEMA_NS, parent.getXPathContext().getContextElement()); if (prefixForURI != null && prefixForURI.length() > 0) { diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestNamespaceContext.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestNamespaceContext.java index 22e028b51f19..30200c8a5741 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestNamespaceContext.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/TestNamespaceContext.java @@ -16,19 +16,35 @@ package org.intellij.lang.xpath; import com.intellij.codeInsight.intention.IntentionAction; +import com.intellij.openapi.Disposable; +import com.intellij.openapi.util.Disposer; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiReference; import com.intellij.psi.xml.XmlElement; +import org.intellij.lang.xpath.context.ContextProvider; import org.intellij.lang.xpath.context.NamespaceContext; import org.intellij.lang.xpath.psi.XPath2Type; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.annotations.TestOnly; import java.util.Collection; import java.util.Collections; class TestNamespaceContext implements NamespaceContext { - public static final TestNamespaceContext INSTANCE = new TestNamespaceContext(); + private static final TestNamespaceContext INSTANCE = new TestNamespaceContext(); + + @TestOnly + public static void install(Disposable parent) { + final NamespaceContext old = ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT; + ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + Disposer.register(parent, new Disposable() { + @Override + public void dispose() { + ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = old; + } + }); + } @Override public String getNamespaceURI(String prefix, XmlElement context) { diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.groovy similarity index 74% rename from plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.java rename to plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.groovy index 404218afb757..01d82ffcba16 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2CompletionTest.groovy @@ -13,21 +13,26 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.intellij.lang.xpath; +package org.intellij.lang.xpath public class XPath2CompletionTest extends TestBase { public void testCastInsert() throws Throwable { - final String name = getTestFileName(); - myFixture.testCompletion(name + ".xpath2", name + "_after.xpath2"); + TestNamespaceContext.install(getTestRootDisposable()); + configure() + assert myFixture.lookupElementStrings.containsAll("xs:anyAtomicType", "xs:untypedAtomic", "xs:anyURI") } - public void testTreatInsert() throws Throwable { + private void configure() { final String name = getTestFileName(); myFixture.configureByFile(name + ".xpath2"); myFixture.completeBasic(); + } + + public void testTreatInsert() throws Throwable { + configure() myFixture.type('\n'); - myFixture.checkResultByFile(name + "_after.xpath2"); + myFixture.checkResultByFile(getTestFileName() + "_after.xpath2"); } @Override diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ExpressionTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ExpressionTest.java index dbf81367beaa..20e47127c18c 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ExpressionTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2ExpressionTest.java @@ -15,7 +15,6 @@ */ package org.intellij.lang.xpath; -import org.intellij.lang.xpath.context.ContextProvider; import org.intellij.lang.xpath.psi.XPath2SequenceType; import org.intellij.lang.xpath.psi.XPathBinaryExpression; import org.intellij.lang.xpath.psi.XPathExpression; @@ -32,7 +31,7 @@ public class XPath2ExpressionTest extends TestBase { @Override protected void setUp() throws Exception { super.setUp(); - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); } public void testIntegerPlusInteger() throws Throwable { diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2HighlightingTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2HighlightingTest.java index 37e497a81fae..38a26f5090e6 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2HighlightingTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2HighlightingTest.java @@ -15,8 +15,6 @@ */ package org.intellij.lang.xpath; -import org.intellij.lang.xpath.context.ContextProvider; - /* * Created by IntelliJ IDEA. * User: sweinreuter @@ -64,7 +62,7 @@ public class XPath2HighlightingTest extends XPath2HighlightingTestBase { } public void testValidOperations2() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } diff --git a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java index cf72ebc5994d..bc0d53af06b4 100644 --- a/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java +++ b/plugins/xpath/xpath-lang/test/org/intellij/lang/xpath/XPath2TypeTest.java @@ -15,8 +15,6 @@ */ package org.intellij.lang.xpath; -import org.intellij.lang.xpath.context.ContextProvider; - public class XPath2TypeTest extends XPath2HighlightingTestBase { public void testQNameToQName() throws Throwable { @@ -116,12 +114,12 @@ public class XPath2TypeTest extends XPath2HighlightingTestBase { } public void testDatePlusDuration() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } public void testDatePlusDate() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } @@ -142,37 +140,37 @@ public class XPath2TypeTest extends XPath2HighlightingTestBase { } public void testDateMinusDuration() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } public void testDateMinusDuration2() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } public void testDurationMinusDate() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } public void testNumericDivDuration() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } public void testNumericIDivDuration() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } public void testDurationDivNumeric() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } public void testDurationIDivNumeric() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } @@ -185,7 +183,7 @@ public class XPath2TypeTest extends XPath2HighlightingTestBase { } public void testRedundantTypeConversion() throws Throwable { - ContextProvider.DefaultProvider.NULL_NAMESPACE_CONTEXT = TestNamespaceContext.INSTANCE; + TestNamespaceContext.install(getTestRootDisposable()); doXPathHighlighting(); } diff --git a/plugins/xpath/xpath-lang/testData/xpath2/completion/castInsert_after.xpath2 b/plugins/xpath/xpath-lang/testData/xpath2/completion/castInsert_after.xpath2 deleted file mode 100644 index 5ce9450ed036..000000000000 --- a/plugins/xpath/xpath-lang/testData/xpath2/completion/castInsert_after.xpath2 +++ /dev/null @@ -1 +0,0 @@ -1 cast as a \ No newline at end of file diff --git a/plugins/xpath/xpath.iml b/plugins/xpath/xpath.iml index 704e2e46ba61..5e0762e6cb22 100644 --- a/plugins/xpath/xpath.iml +++ b/plugins/xpath/xpath.iml @@ -22,6 +22,7 @@ +