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
.impl
;
18 import com
.intellij
.psi
.xml
.XmlTag
;
19 import com
.intellij
.psi
.xml
.XmlFile
;
20 import com
.intellij
.util
.ArrayUtil
;
21 import com
.intellij
.util
.NotNullFunction
;
22 import com
.intellij
.util
.xml
.DomElement
;
23 import com
.intellij
.util
.xml
.DomReflectionUtil
;
24 import com
.intellij
.util
.xml
.JavaMethod
;
25 import com
.intellij
.util
.xml
.EvaluatedXmlName
;
26 import com
.intellij
.util
.xml
.reflect
.CustomDomChildrenDescription
;
27 import org
.jetbrains
.annotations
.NotNull
;
28 import org
.jetbrains
.annotations
.Nullable
;
30 import java
.util
.List
;
31 import java
.util
.Collections
;
32 import java
.lang
.reflect
.Type
;
37 public class CustomDomChildrenDescriptionImpl
extends AbstractDomChildDescriptionImpl
implements CustomDomChildrenDescription
, AbstractCollectionChildDescription
{
38 @Nullable private final JavaMethod myGetter
;
39 public static final NotNullFunction
<DomInvocationHandler
,List
<XmlTag
>> CUSTOM_TAGS_GETTER
= new NotNullFunction
<DomInvocationHandler
, List
<XmlTag
>>() {
41 public List
<XmlTag
> fun(final DomInvocationHandler handler
) {
42 return DomImplUtil
.getCustomSubTags(handler
, handler
.getXmlTag().getSubTags(), handler
.getFile());
46 public CustomDomChildrenDescriptionImpl(@NotNull final JavaMethod getter
) {
47 this(getter
, DomReflectionUtil
.extractCollectionElementType(getter
.getGenericReturnType()));
50 public CustomDomChildrenDescriptionImpl(@Nullable final JavaMethod getter
, @NotNull Type type
) {
55 @Nullable public JavaMethod
getGetterMethod() {
60 public List
<?
extends DomElement
> getValues(@NotNull final DomInvocationHandler parent
) {
61 if (!parent
.getGenericInfo().checkInitialized()) {
62 return Collections
.emptyList();
64 return parent
.getCollectionChildren(this, CUSTOM_TAGS_GETTER
);
68 public List
<?
extends DomElement
> getValues(@NotNull final DomElement parent
) {
69 final DomInvocationHandler handler
= DomManagerImpl
.getDomInvocationHandler(parent
);
70 if (handler
!= null) return getValues(handler
);
72 assert myGetter
!= null;
73 return (List
<?
extends DomElement
>)myGetter
.invoke(parent
, ArrayUtil
.EMPTY_OBJECT_ARRAY
);
76 public int compareTo(final AbstractDomChildDescriptionImpl o
) {
77 return equals(o
) ?
0 : -1;
80 public List
<XmlTag
> getSubTags(final DomInvocationHandler handler
, final XmlTag
[] subTags
, final XmlFile file
) {
81 return DomImplUtil
.getCustomSubTags(handler
, subTags
, file
);
84 public EvaluatedXmlName
createEvaluatedXmlName(final DomInvocationHandler parent
, final XmlTag childTag
) {
85 return new DummyEvaluatedXmlName(childTag
.getLocalName(), childTag
.getNamespace());