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
.source
;
18 import com
.intellij
.lang
.ASTNode
;
19 import com
.intellij
.openapi
.diagnostic
.Logger
;
20 import com
.intellij
.openapi
.util
.text
.StringUtil
;
21 import com
.intellij
.psi
.*;
22 import com
.intellij
.psi
.impl
.java
.stubs
.PsiMethodStub
;
23 import com
.intellij
.psi
.impl
.source
.tree
.ChildRole
;
24 import com
.intellij
.util
.PatchedSoftReference
;
25 import org
.jetbrains
.annotations
.NonNls
;
26 import org
.jetbrains
.annotations
.NotNull
;
31 public class PsiAnnotationMethodImpl
extends PsiMethodImpl
implements PsiAnnotationMethod
{
32 private static final Logger LOG
= Logger
.getInstance("#com.intellij.psi.impl.source.PsiAnnotationMethodImpl");
33 private PatchedSoftReference
<PsiAnnotationMemberValue
> myCachedDefaultValue
= null;
35 public PsiAnnotationMethodImpl(final PsiMethodStub stub
) {
39 public PsiAnnotationMethodImpl(final ASTNode node
) {
43 public boolean hasModifierProperty(@NotNull String name
) {
44 return PsiModifier
.ABSTRACT
.equals(name
) || PsiModifier
.PUBLIC
.equals(name
) || super.hasModifierProperty(name
);
47 protected void dropCached() {
48 myCachedDefaultValue
= null;
51 public PsiAnnotationMemberValue
getDefaultValue() {
52 final PsiMethodStub stub
= getStub();
54 final String text
= stub
.getDefaultValueText();
55 if (StringUtil
.isEmpty(text
)) return null;
57 if (myCachedDefaultValue
!= null) {
58 final PsiAnnotationMemberValue value
= myCachedDefaultValue
.get();
64 @NonNls final String annoText
= "@interface _Dummy_ { Class foo() default " + text
+ "; }";
65 final PsiJavaFile file
= (PsiJavaFile
)PsiFileFactory
.getInstance(getProject()).createFileFromText("a.java", annoText
);
66 final PsiAnnotationMemberValue value
= ((PsiAnnotationMethod
)file
.getClasses()[0].getMethods()[0]).getDefaultValue();
67 myCachedDefaultValue
= new PatchedSoftReference
<PsiAnnotationMemberValue
>(value
);
71 myCachedDefaultValue
= null;
73 final ASTNode node
= getNode().findChildByRole(ChildRole
.ANNOTATION_DEFAULT_VALUE
);
74 if (node
== null) return null;
75 return (PsiAnnotationMemberValue
)node
.getPsi();
79 public String
toString() {
80 return "PsiAnnotationMethod:" + getName();
83 public final void accept(@NotNull PsiElementVisitor visitor
) {
84 if (visitor
instanceof JavaElementVisitor
) {
85 ((JavaElementVisitor
)visitor
).visitAnnotationMethod(this);
88 visitor
.visitElement(this);