diff --git a/xml/dom-impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java b/xml/dom-impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java index 1210474512dc..ec7231593438 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java +++ b/xml/dom-impl/src/com/intellij/util/xml/impl/CollectionElementInvocationHandler.java @@ -65,6 +65,7 @@ public class CollectionElementInvocationHandler extends DomInvocationHandler myAccessorInvocations = SmartFMap.emptyMap(); - @Nullable protected final Stub myStub; + @Nullable protected Stub myStub; protected DomInvocationHandler(Type type, DomParentStrategy parentStrategy, @NotNull final EvaluatedXmlName tagName, @@ -734,6 +734,7 @@ public abstract class DomInvocationHandler"); + final DomManagerImpl manager = getDomManager(); + final DomFileElementImpl fileElement = manager.getFileElement(file, DomElement.class, "a"); + final DomElement rootElement = fileElement.getRootElement(); + assertNotNull(rootElement); + assertTrue(rootElement.exists()); + + rootElement.undefine(); + assertFalse(rootElement.exists()); + } + public void testElementCaching() throws Throwable { final MyElement element = createElement(""); assertSame(element.getChild(), element.getChild()); @@ -167,7 +179,8 @@ public class DomBasicsTest extends DomTestCase { assertEquals(new HashSet(Arrays.asList(foo, child, collectionChild, genericChild, info.getAttributeChildrenDescriptions().get(0))), - new HashSet(info.getChildrenDescriptions())); + new HashSet(info.getChildrenDescriptions()) + ); } private void assertFixedChildDescription(final DomFixedChildDescription description, @@ -225,7 +238,8 @@ public class DomBasicsTest extends DomTestCase { } private void assertCollectionPresentableName(final String expected, final String tagName, final DomNameStrategy strategy) { - assertEquals(expected, new CollectionChildDescriptionImpl(new XmlName(tagName), DomElement.class, null).getCommonPresentableName(strategy)); + assertEquals(expected, + new CollectionChildDescriptionImpl(new XmlName(tagName), DomElement.class, null).getCommonPresentableName(strategy)); } private void assertFixedPresentableName(final String expected, final String tagName, final DomNameStrategy strategy) { diff --git a/xml/dom-tests/tests/com/intellij/util/xml/stubs/DomStubUsingTest.java b/xml/dom-tests/tests/com/intellij/util/xml/stubs/DomStubUsingTest.java index 085960fcb45b..13d0ec6ed8be 100644 --- a/xml/dom-tests/tests/com/intellij/util/xml/stubs/DomStubUsingTest.java +++ b/xml/dom-tests/tests/com/intellij/util/xml/stubs/DomStubUsingTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * 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. @@ -15,6 +15,7 @@ */ package com.intellij.util.xml.stubs; +import com.intellij.openapi.command.WriteCommandAction; import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.psi.PsiClass; import com.intellij.psi.PsiFile; @@ -117,4 +118,38 @@ public class DomStubUsingTest extends DomStubTest { ((PsiManagerImpl)getPsiManager()).setAssertOnFileLoadingFilter(VirtualFileFilter.ALL, myTestRootDisposable); DomManager.getDomManager(getProject()).getFileElement(file, Foo.class); } + + public void testStubbedElementUndefineNotExisting() { + final DomFileElement fileElement = prepare("foo.xml", Foo.class); + final Bar bar = fileElement.getRootElement().getBars().get(0); + + assertNotNull(bar); + assertTrue(bar.exists()); + + new WriteCommandAction.Simple(null) { + @Override + protected void run() throws Throwable { + bar.undefine(); + } + }.execute().throwException(); + + assertFalse(bar.exists()); + } + + public void testRootElementUndefineNotExisting() { + final DomFileElement fileElement = prepare("foo.xml", Foo.class); + + final DomElement rootElement = fileElement.getRootElement(); + assertNotNull(rootElement); + assertTrue(rootElement.exists()); + + new WriteCommandAction.Simple(null) { + @Override + protected void run() throws Throwable { + rootElement.undefine(); + } + }.execute().throwException(); + + assertFalse(rootElement.exists()); + } }