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.
18 * Created by IntelliJ IDEA.
23 package com
.intellij
.xml
.breadcrumbs
;
25 import com
.intellij
.lang
.Language
;
26 import com
.intellij
.lang
.html
.HTMLLanguage
;
27 import com
.intellij
.lang
.xhtml
.XHTMLLanguage
;
28 import com
.intellij
.lang
.xml
.XMLLanguage
;
29 import com
.intellij
.psi
.PsiElement
;
30 import com
.intellij
.psi
.xml
.XmlAttribute
;
31 import com
.intellij
.psi
.xml
.XmlTag
;
32 import org
.jetbrains
.annotations
.NonNls
;
33 import org
.jetbrains
.annotations
.NotNull
;
34 import org
.jetbrains
.annotations
.Nullable
;
36 import java
.util
.StringTokenizer
;
38 public class XmlLanguageBreadcrumbsInfoProvider
extends BreadcrumbsInfoProvider
{
39 @NonNls private static final String CLASS_ATTRIBUTE_NAME
= "class";
40 @NonNls private static final String ID_ATTRIBUTE_NAME
= "id";
42 public boolean acceptElement(@NotNull final PsiElement e
) {
43 return e
instanceof XmlTag
&& e
.isValid();
46 public Language
[] getLanguages() {
47 return new Language
[]{XHTMLLanguage
.INSTANCE
, HTMLLanguage
.INSTANCE
};
51 public String
getElementInfo(@NotNull final PsiElement e
) {
52 final XmlTag tag
= (XmlTag
)e
;
53 final StringBuffer sb
= new StringBuffer();
55 sb
.append(tag
.getName());
57 final boolean addHtmlInfo
= e
.getContainingFile().getLanguage() != XMLLanguage
.INSTANCE
;
60 final String id_value
= tag
.getAttributeValue(ID_ATTRIBUTE_NAME
);
61 if (null != id_value
) {
62 sb
.append("#").append(id_value
);
65 final String class_value
= tag
.getAttributeValue(CLASS_ATTRIBUTE_NAME
);
66 if (null != class_value
) {
67 final StringTokenizer tokenizer
= new StringTokenizer(class_value
, " ");
68 while (tokenizer
.hasMoreTokens()) {
69 sb
.append(".").append(tokenizer
.nextToken());
78 public String
getElementTooltip(@NotNull final PsiElement e
) {
79 final XmlTag tag
= (XmlTag
)e
;
80 final StringBuffer result
= new StringBuffer("<");
81 result
.append(tag
.getName());
82 final XmlAttribute
[] attributes
= tag
.getAttributes();
83 for (final XmlAttribute each
: attributes
) {
84 result
.append(" ").append(each
.getText());
91 result
.append(">...</").append(tag
.getName()).append(">");
94 return result
.toString();