update copyright
[fedora-idea.git] / java / java-impl / src / com / intellij / psi / impl / compiled / ClsAnnotationValueImpl.java
blobab843c856fee0894e4da9d932a1266f2a8c61b34
1 /*
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.psi.impl.compiled;
18 import com.intellij.openapi.diagnostic.Logger;
19 import com.intellij.pom.Navigatable;
20 import com.intellij.psi.*;
21 import com.intellij.psi.impl.PsiImplUtil;
22 import com.intellij.psi.impl.meta.MetaRegistry;
23 import com.intellij.psi.impl.source.SourceTreeToPsiMap;
24 import com.intellij.psi.impl.source.tree.TreeElement;
25 import com.intellij.psi.meta.PsiMetaData;
26 import com.intellij.util.IncorrectOperationException;
27 import org.jetbrains.annotations.NonNls;
28 import org.jetbrains.annotations.NotNull;
29 import org.jetbrains.annotations.Nullable;
31 /**
32 * @author ven
34 public abstract class ClsAnnotationValueImpl extends ClsElementImpl implements PsiAnnotation, Navigatable {
35 private static final Logger LOG = Logger.getInstance("com.intellij.psi.impl.compiled.ClsAnnotationValueImpl");
36 public static final ClsAnnotationImpl[] EMPTY_ARRAY = new ClsAnnotationImpl[0];
37 private final ClsJavaCodeReferenceElementImpl myReferenceElement;
38 private final ClsAnnotationParameterListImpl myParameterList;
39 private final ClsElementImpl myParent;
41 public ClsAnnotationValueImpl(ClsElementImpl parent) {
42 myReferenceElement = createReference();
43 myParameterList = createParameterList();
44 myParent = parent;
47 protected abstract ClsAnnotationParameterListImpl createParameterList();
49 protected abstract ClsJavaCodeReferenceElementImpl createReference();
51 public void appendMirrorText(final int indentLevel, final StringBuffer buffer) {
52 buffer.append("@").append(myReferenceElement.getCanonicalText());
53 myParameterList.appendMirrorText(indentLevel, buffer);
56 public void setMirror(@NotNull TreeElement element) {
57 setMirrorCheckingType(element, null);
59 PsiAnnotation mirror = (PsiAnnotation)SourceTreeToPsiMap.treeElementToPsi(element);
60 ((ClsElementImpl)getParameterList()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getParameterList()));
61 ((ClsElementImpl)getNameReferenceElement()).setMirror((TreeElement)SourceTreeToPsiMap.psiElementToTree(mirror.getNameReferenceElement()));
64 @NotNull
65 public PsiElement[] getChildren() {
66 return new PsiElement[]{myReferenceElement, myParameterList};
69 public PsiElement getParent() {
70 return myParent;
73 public void accept(@NotNull PsiElementVisitor visitor) {
74 if (visitor instanceof JavaElementVisitor) {
75 ((JavaElementVisitor)visitor).visitAnnotation(this);
77 else {
78 visitor.visitElement(this);
82 @NotNull
83 public PsiAnnotationParameterList getParameterList() {
84 return myParameterList;
87 @Nullable public String getQualifiedName() {
88 if (myReferenceElement == null) return null;
89 return myReferenceElement.getCanonicalText();
92 public PsiJavaCodeReferenceElement getNameReferenceElement() {
93 return myReferenceElement;
96 public PsiAnnotationMemberValue findAttributeValue(String attributeName) {
97 return PsiImplUtil.findAttributeValue(this, attributeName);
100 @Nullable
101 public PsiAnnotationMemberValue findDeclaredAttributeValue(@NonNls final String attributeName) {
102 return PsiImplUtil.findDeclaredAttributeValue(this, attributeName);
105 public <T extends PsiAnnotationMemberValue> T setDeclaredAttributeValue(@NonNls String attributeName, T value) {
106 throw new IncorrectOperationException(CAN_NOT_MODIFY_MESSAGE);
109 public String getText() {
110 final StringBuffer buffer = new StringBuffer();
111 appendMirrorText(0, buffer);
112 return buffer.toString();
115 public PsiMetaData getMetaData() {
116 return MetaRegistry.getMetaBase(this);