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
.*;
19 import com
.intellij
.psi
.util
.InheritanceUtil
;
20 import org
.jetbrains
.annotations
.NonNls
;
22 import java
.util
.Arrays
;
23 import java
.util
.HashSet
;
26 public class PsiMethodCallFilter
implements ElementFilter
{
27 @NonNls private final String myClassName
;
28 @NonNls private final Set
<String
> myMethodNames
;
31 public PsiMethodCallFilter(@NonNls final String className
, @NonNls final String
... methodNames
) {
32 myClassName
= className
;
33 myMethodNames
= new HashSet
<String
>(Arrays
.asList(methodNames
));
36 public boolean isAcceptable(Object element
, PsiElement context
) {
37 if (element
instanceof PsiMethodCallExpression
) {
38 final PsiMethodCallExpression callExpression
= (PsiMethodCallExpression
)element
;
39 final PsiMethod psiMethod
= callExpression
.resolveMethod();
40 if (psiMethod
!= null) {
41 if (!myMethodNames
.contains(psiMethod
.getName())) {
44 final PsiClass psiClass
= psiMethod
.getContainingClass();
45 final PsiClass expectedClass
= JavaPsiFacade
.getInstance(psiClass
.getProject()).findClass(myClassName
, psiClass
.getResolveScope());
46 return InheritanceUtil
.isInheritorOrSelf(psiClass
, expectedClass
, true);
52 public boolean isClassAcceptable(Class hintClass
) {
53 return PsiMethodCallExpression
.class.isAssignableFrom(hintClass
);
57 public String
toString() {
58 return "methodcall(" + myClassName
+ "." + myMethodNames
+ ")";