IDEADEV-40452
[fedora-idea.git] / plugins / InspectionGadgets / src / com / siyeh / ig / psiutils / LibraryUtil.java
blob4ffd7262130077ab739f4dcc140464d64eb2f72d
1 /*
2 * Copyright 2003-2006 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.ig.psiutils;
18 import com.intellij.psi.*;
19 import org.jetbrains.annotations.NotNull;
21 public class LibraryUtil {
23 private LibraryUtil() {
24 super();
27 public static boolean classIsInLibrary(@NotNull PsiClass aClass) {
28 return aClass instanceof PsiCompiledElement;
31 public static boolean callOnLibraryMethod(
32 @NotNull PsiMethodCallExpression expression) {
33 final PsiMethod method = expression.resolveMethod();
34 return method != null && method instanceof PsiCompiledElement;
37 public static boolean isOverrideOfLibraryMethod(PsiMethod method){
38 final PsiMethod[] superMethods = method.findSuperMethods();
39 for(PsiMethod superMethod : superMethods){
40 final PsiClass containingClass =
41 superMethod.getContainingClass();
42 if(containingClass != null &&
43 classIsInLibrary(containingClass)){
44 return true;
46 if(isOverrideOfLibraryMethod(superMethod)){
47 return true;
50 return false;
53 public static boolean isOverrideOfLibraryMethodParameter(
54 PsiVariable variable) {
55 if (variable instanceof PsiParameter) {
56 final PsiParameter parameter = (PsiParameter)variable;
57 final PsiElement scope = parameter.getDeclarationScope();
58 if (scope instanceof PsiMethod) {
59 final PsiMethod method = (PsiMethod)scope;
60 if (isOverrideOfLibraryMethod(method)) {
61 return true;
65 return false;