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
.pom
.PomDeclarationSearcher
;
19 import com
.intellij
.pom
.PomTarget
;
20 import com
.intellij
.psi
.PsiElement
;
21 import com
.intellij
.psi
.PsiLanguageInjectionHost
;
22 import com
.intellij
.psi
.tree
.IElementType
;
23 import com
.intellij
.psi
.xml
.*;
24 import com
.intellij
.util
.Consumer
;
25 import com
.intellij
.util
.xml
.*;
26 import org
.jetbrains
.annotations
.NotNull
;
31 public class DomDeclarationSearcher
extends PomDeclarationSearcher
{
32 public void findDeclarationsAt(@NotNull PsiElement psiElement
, int offsetInElement
, Consumer
<PomTarget
> consumer
) {
33 if (!(psiElement
instanceof XmlToken
)) return;
35 final IElementType tokenType
= ((XmlToken
)psiElement
).getTokenType();
37 final DomManager domManager
= DomManager
.getDomManager(psiElement
.getProject());
38 final DomElement domElement
;
39 if (tokenType
== XmlTokenType
.XML_DATA_CHARACTERS
&& psiElement
.getParent() instanceof XmlText
&& psiElement
.getParent().getParent() instanceof XmlTag
) {
40 final XmlTag tag
= (XmlTag
)psiElement
.getParent().getParent();
41 for (XmlText text
: tag
.getValue().getTextElements()) {
42 if (GenericValueReferenceProvider
.hasInjections((PsiLanguageInjectionHost
)text
)) {
47 domElement
= domManager
.getDomElement(tag
);
48 } else if (tokenType
== XmlTokenType
.XML_ATTRIBUTE_VALUE_TOKEN
&& psiElement
.getParent() instanceof XmlAttributeValue
&& psiElement
.getParent().getParent() instanceof XmlAttribute
) {
49 final PsiElement attributeValue
= psiElement
.getParent();
50 if (GenericValueReferenceProvider
.hasInjections((PsiLanguageInjectionHost
)attributeValue
)) {
53 domElement
= domManager
.getDomElement((XmlAttribute
)attributeValue
.getParent());
58 if (!(domElement
instanceof GenericDomValue
)) {
62 final NameValue nameValue
= domElement
.getAnnotation(NameValue
.class);
63 if (nameValue
!= null && nameValue
.referencable()) {
64 DomElement parent
= domElement
.getParent();
65 assert parent
!= null;
66 final DomTarget target
= DomTarget
.getTarget(parent
);
68 consumer
.consume(target
);