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
.filters
;
18 import com
.intellij
.psi
.PsiAnnotation
;
19 import com
.intellij
.psi
.PsiAnnotationParameterList
;
20 import com
.intellij
.psi
.PsiElement
;
21 import com
.intellij
.psi
.PsiNameValuePair
;
22 import com
.intellij
.util
.ReflectionCache
;
23 import org
.jetbrains
.annotations
.NonNls
;
28 public class AnnotationParameterFilter
implements ElementFilter
{
29 private final Class
<?
extends PsiElement
> myClass
;
30 @NonNls private final String myParameterName
;
31 private final String myAnnotationQualifiedName
;
34 public AnnotationParameterFilter(final Class
<?
extends PsiElement
> elementClass
,
35 final String annotationQualifiedName
,
36 @NonNls final String parameterName
) {
37 myAnnotationQualifiedName
= annotationQualifiedName
;
38 myClass
= elementClass
;
39 myParameterName
= parameterName
;
42 public boolean isAcceptable(Object element
, PsiElement context
) {
43 final PsiElement parent
= ((PsiElement
)element
).getParent();
44 if (parent
instanceof PsiNameValuePair
) {
45 final PsiNameValuePair pair
= (PsiNameValuePair
)parent
;
46 final String name
= pair
.getName();
47 if (myParameterName
.equals(name
) || name
== null && "value".equals(myParameterName
)) {
48 final PsiElement psiElement
= pair
.getParent();
49 if (psiElement
instanceof PsiAnnotationParameterList
) {
50 final PsiElement grandParent
= psiElement
.getParent();
51 if (grandParent
instanceof PsiAnnotation
) {
52 if (myAnnotationQualifiedName
.equals(((PsiAnnotation
)grandParent
).getQualifiedName())) {
62 public boolean isClassAcceptable(Class hintClass
) {
63 return ReflectionCache
.isAssignable(myClass
, hintClass
);