fix class name completion inside xml tag value
[fedora-idea.git] / dom / openapi / src / com / intellij / util / xml / DomMetaData.java
blob6f76effffa1a796ee07139712c7bb4f248ddffe0
1 /*
2 * Copyright 2000-2007 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.PsiElement;
19 import com.intellij.psi.meta.PsiMetaData;
20 import com.intellij.psi.meta.PsiPresentableMetaData;
21 import com.intellij.psi.meta.PsiWritableMetaData;
22 import com.intellij.psi.xml.XmlTag;
23 import com.intellij.util.IncorrectOperationException;
24 import org.jetbrains.annotations.NonNls;
25 import org.jetbrains.annotations.Nullable;
27 import javax.swing.*;
29 /**
30 * @author peter
32 public class DomMetaData<T extends DomElement> implements PsiWritableMetaData, PsiPresentableMetaData, PsiMetaData {
33 private T myElement;
34 @Nullable
35 private GenericDomValue myNameElement;
37 public final PsiElement getDeclaration() {
38 return myElement.getXmlTag();
41 public T getElement() {
42 return myElement;
45 @NonNls
46 public String getName(PsiElement context) {
47 return getName();
50 @NonNls
51 public final String getName() {
52 final String s = ElementPresentationManager.getElementName(myElement);
53 if (s != null) return s;
55 final GenericDomValue value = getNameElement(myElement);
56 return value == null ? null : value.getStringValue();
59 public void init(PsiElement element) {
60 myElement = (T) DomManager.getDomManager(element.getProject()).getDomElement((XmlTag)element);
61 assert myElement != null : element;
62 myNameElement = getNameElement(myElement);
65 @Nullable
66 protected GenericDomValue getNameElement(final T t) {
67 return myElement.getGenericInfo().getNameDomElement(t);
70 public Object[] getDependences() {
71 final PsiElement declaration = getDeclaration();
72 if (myElement != null && myElement.isValid()) {
73 return new Object[]{myElement.getRoot(), declaration};
75 return new Object[]{declaration};
78 public void setName(String name) throws IncorrectOperationException {
79 if (myNameElement != null) {
80 myNameElement.setStringValue(name);
84 public String getTypeName() {
85 return ElementPresentationManager.getTypeNameForObject(myElement);
88 public Icon getIcon() {
89 return ElementPresentationManager.getIcon(myElement);