void () { final MyElement[] element = new MyElement[]{null}; final MyElement stable = getDomManager().createStableValue(() -> { try { return element[0] = createElement("<root/>").addChildElement(); } catch (IncorrectOperationException e) { throw new RuntimeException(e); } }); assertNotNull(element[0]); //noinspection CastToIncompatibleInterface assertSame(element[0], ((StableElement<?>)stable).getWrappedElement()); assertEquals(element[0], stable); assertEquals(stable, element[0]); MyElement oldElement = element[0]; assertFalse(stable.getChild().equals(stable)); final GenericDomValue<Boolean> oldGenericValue = stable.getGenericValue(); assertEquals(oldGenericValue, oldElement.getGenericValue()); assertEquals(stable.getChild(), oldElement.getChild()); assertSame(element[0], oldElement); final MyElement child1 = stable.addChildElement(); final MyElement child2 = stable.addChildElement(); MyElement oldChild1 = oldElement.getChildElements().get(0); assertEquals(oldChild1, child1); assertEquals(child1, oldChild1); final MyElement oldElement1 = oldElement; WriteCommandAction.runWriteCommandAction(getProject(), () -> oldElement1.undefine()); assertFalse(oldChild1.isValid()); assertFalse(oldElement.isValid()); assertFalse(element[0].isValid()); assertTrue(stable.isValid()); assertTrue(element[0].isValid()); assertNotSame(element[0], oldElement); assertFalse(child1.isValid()); assertFalse(child2.isValid()); assertEquals(DomUtil.getFileElement(element[0]), DomUtil.getFileElement(stable)); assertEquals(element[0].getParent(), stable.getParent()); oldElement = element[0]; oldChild1 = oldElement.getChild(); ((StableElement<?>)stable).invalidate(); assertTrue(oldElement.isValid()); assertTrue(oldChild1.isValid()); assertFalse(oldElement.equals(((StableElement<?>)stable).getWrappedElement())); }