2 * Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
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
.siyeh
.ipp
.junit
;
18 import com
.intellij
.psi
.*;
19 import com
.siyeh
.ipp
.base
.PsiElementPredicate
;
20 import com
.siyeh
.ipp
.psiutils
.ErrorUtil
;
21 import org
.jetbrains
.annotations
.NonNls
;
23 class AssertTrueOrFalsePredicate
implements PsiElementPredicate
{
25 public boolean satisfiedBy(PsiElement element
){
26 if(!(element
instanceof PsiMethodCallExpression
)){
29 final PsiMethodCallExpression expression
=
30 (PsiMethodCallExpression
) element
;
31 final PsiExpressionList argumentList
= expression
.getArgumentList();
32 final int numExpressions
= argumentList
.getExpressions().length
;
33 if(numExpressions
< 1 || numExpressions
> 2){
36 final PsiReferenceExpression methodExpression
=
37 expression
.getMethodExpression();
38 @NonNls final String methodName
= methodExpression
.getReferenceName();
39 if (!"assertTrue".equals(methodName
) &&
40 !"assertFalse".equals(methodName
)) {
43 final PsiMethod method
= expression
.resolveMethod();
47 final PsiClass targetClass
= method
.getContainingClass();
48 if (targetClass
== null) {
51 final String qualifiedName
= targetClass
.getQualifiedName();
52 if (!"junit.framework.Assert".equals(qualifiedName
) &&
53 !"org.junit.Assert".equals(qualifiedName
)) {
56 return !ErrorUtil
.containsError(element
);