2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.util
.xml
;
18 import com
.intellij
.psi
.xml
.XmlElement
;
19 import com
.intellij
.psi
.xml
.XmlTag
;
20 import com
.intellij
.psi
.search
.GlobalSearchScope
;
21 import com
.intellij
.util
.xml
.reflect
.DomGenericInfo
;
22 import com
.intellij
.util
.xml
.reflect
.AbstractDomChildrenDescription
;
23 import com
.intellij
.openapi
.module
.Module
;
24 import com
.intellij
.openapi
.util
.UserDataHolder
;
25 import org
.jetbrains
.annotations
.NotNull
;
26 import org
.jetbrains
.annotations
.Nullable
;
27 import org
.jetbrains
.annotations
.NonNls
;
29 import java
.lang
.reflect
.Type
;
32 * Base interface for DOM elements. Every DOM interface should extend this one.
36 public interface DomElement
extends AnnotatedElement
, UserDataHolder
{
37 DomElement
[] EMPTY_ARRAY
= new DomElement
[0];
42 * Returns the underlying XML element/file.
44 * @return {@link com.intellij.psi.xml.XmlFile}, {@link com.intellij.psi.xml.XmlTag} or {@link com.intellij.psi.xml.XmlAttribute}
47 XmlElement
getXmlElement();
50 DomElement
getParent();
52 XmlTag
ensureTagExists();
54 XmlElement
ensureXmlElementExists();
57 * Removes all corresponding XML content. In case of being collection member, invalidates the element.
64 DomGenericInfo
getGenericInfo();
66 @NotNull @NonNls String
getXmlElementName();
68 @NotNull @NonNls String
getXmlElementNamespace();
71 * @return namespace key if this element or one of its ancestors is annotated with
72 * {@link Namespace}, or null otherwise, which means that namespace should be equal
73 * to that of the element's parent
75 @Nullable @NonNls String
getXmlElementNamespaceKey();
77 void accept(final DomElementVisitor visitor
);
79 void acceptChildren(DomElementVisitor visitor
);
82 DomManager
getManager();
85 Type
getDomElementType();
87 AbstractDomChildrenDescription
getChildDescription();
90 DomNameStrategy
getNameStrategy();
93 ElementPresentation
getPresentation();
95 GlobalSearchScope
getResolveScope();
98 * Walk up the DOM tree searching for element of requiredClass type
99 * @param requiredClass parent element's type
102 * <li>strict = false: if the current element is already of the correct type, then it is returned.</li>
103 * <li>strict = true: the returned element must be higher in the hierarchy.</li>
105 * @return the parent of requiredClass type
108 <T
extends DomElement
> T
getParentOfType(Class
<T
> requiredClass
, boolean strict
);
113 void copyFrom(DomElement other
);
115 <T
extends DomElement
> T
createMockCopy(final boolean physical
);
118 * @return stable element (see {@link DomManager#createStableValue(com.intellij.openapi.util.Factory)}}),
119 * that holds the complete 'XPath' to this element in XML. If this element is in collection, and something
120 * is inserted before it, the stable copy behaviour may be unexpected. So use this method only when you
121 * are sure that nothing serious will happen during the lifetime of the stable copy. The most usual use
122 * case is when one creates something inside {@link com.intellij.openapi.command.WriteCommandAction} and
123 * wants to use it outside the action. Due to formatting done on the command finish the element may become
124 * invalidated, but the stable copy will survive, because nothing in fact has changed in its 'XPath'.
126 <T
extends DomElement
> T
createStableCopy();