mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IG: introduce utility method
This commit is contained in:
+2
-8
@@ -23,8 +23,6 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
@@ -133,12 +131,8 @@ public class CloneDeclaresCloneNotSupportedInspection extends BaseInspection {
|
||||
if (MethodUtils.hasInThrows(method, "java.lang.CloneNotSupportedException")) {
|
||||
return;
|
||||
}
|
||||
final MethodSignatureBackedByPsiMethod signature = SuperMethodsSearch.search(method, null, true, false).findFirst();
|
||||
if (signature == null) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod superMethod = signature.getMethod();
|
||||
if (!MethodUtils.hasInThrows(superMethod, "java.lang.CloneNotSupportedException")) {
|
||||
final PsiMethod superMethod = MethodUtils.getSuper(method);
|
||||
if (superMethod != null && !MethodUtils.hasInThrows(superMethod, "java.lang.CloneNotSupportedException")) {
|
||||
return;
|
||||
}
|
||||
registerMethodError(method);
|
||||
|
||||
+7
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2014 Bas Leijdekkers
|
||||
* Copyright 2005-2015 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -18,19 +18,19 @@ package com.siyeh.ig.inheritance;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Query;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.EquivalenceChecker;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class RedundantMethodOverrideInspection extends BaseInspection {
|
||||
|
||||
@@ -97,14 +97,10 @@ public class RedundantMethodOverrideInspection extends BaseInspection {
|
||||
if (method.getNameIdentifier() == null) {
|
||||
return;
|
||||
}
|
||||
final Query<MethodSignatureBackedByPsiMethod> superMethodQuery =
|
||||
SuperMethodsSearch.search(method, null, true, false);
|
||||
final MethodSignatureBackedByPsiMethod signature =
|
||||
superMethodQuery.findFirst();
|
||||
if (signature == null) {
|
||||
final PsiMethod superMethod = MethodUtils.getSuper(method);
|
||||
if (superMethod == null) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod superMethod = signature.getMethod();
|
||||
final PsiCodeBlock superBody = superMethod.getBody();
|
||||
if (superBody == null) {
|
||||
return;
|
||||
|
||||
+2
-8
@@ -19,8 +19,6 @@ import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
@@ -130,12 +128,8 @@ public class RefusedBequestInspectionBase extends BaseInspection {
|
||||
|
||||
@Nullable
|
||||
private PsiMethod getDirectSuperMethod(PsiMethod method) {
|
||||
final MethodSignatureBackedByPsiMethod superSignature = SuperMethodsSearch.search(method, null, true, false).findFirst();
|
||||
if (superSignature == null) {
|
||||
return null;
|
||||
}
|
||||
final PsiMethod superMethod = superSignature.getMethod();
|
||||
if (superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
final PsiMethod superMethod = MethodUtils.getSuper(method);
|
||||
if (superMethod == null || superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
return null;
|
||||
}
|
||||
final PsiClass containingClass = superMethod.getContainingClass();
|
||||
|
||||
+2
-5
@@ -20,16 +20,15 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.javadoc.*;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -149,9 +148,7 @@ public class UnnecessaryInheritDocInspection extends BaseInspection {
|
||||
registerError(tag, WarningType.CONSTRUCTOR);
|
||||
return;
|
||||
}
|
||||
final MethodSignatureBackedByPsiMethod superMethod =
|
||||
SuperMethodsSearch.search(method, method.getContainingClass(), true, false).findFirst();
|
||||
if (superMethod == null) {
|
||||
if (!MethodUtils.hasSuper(method)) {
|
||||
registerError(tag, WarningType.NO_SUPER);
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,13 +19,11 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiParameter;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
|
||||
import com.intellij.util.Query;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.LibraryUtil;
|
||||
import com.siyeh.ig.psiutils.MethodUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ParameterNameDiffersFromOverriddenParameterInspectionBase extends BaseInspection {
|
||||
@@ -67,21 +65,15 @@ public class ParameterNameDiffersFromOverriddenParameterInspectionBase extends B
|
||||
if (parameterList.getParametersCount() == 0) {
|
||||
return;
|
||||
}
|
||||
final Query<MethodSignatureBackedByPsiMethod> query =
|
||||
SuperMethodsSearch.search(
|
||||
method, method.getContainingClass(), true, false);
|
||||
final MethodSignatureBackedByPsiMethod methodSignature =
|
||||
query.findFirst();
|
||||
if (methodSignature == null) {
|
||||
final PsiMethod superMethod = MethodUtils.getSuper(method);
|
||||
if (superMethod == null) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod superMethod = methodSignature.getMethod();
|
||||
final PsiParameter[] parameters = parameterList.getParameters();
|
||||
checkParameters(superMethod, parameters);
|
||||
}
|
||||
|
||||
private void checkParameters(PsiMethod superMethod,
|
||||
PsiParameter[] parameters) {
|
||||
private void checkParameters(@NotNull PsiMethod superMethod, PsiParameter[] parameters) {
|
||||
if (m_ignoreOverridesOfLibraryMethods) {
|
||||
final PsiClass containingClass =
|
||||
superMethod.getContainingClass();
|
||||
|
||||
+12
-2
@@ -21,6 +21,7 @@ import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.search.searches.OverridingMethodsSearch;
|
||||
import com.intellij.psi.search.searches.SuperMethodsSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.MethodSignatureBackedByPsiMethod;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Query;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
@@ -191,10 +192,19 @@ public class MethodUtils {
|
||||
}
|
||||
|
||||
public static boolean hasSuper(@NotNull PsiMethod method) {
|
||||
return getSuper(method) != null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiMethod getSuper(@NotNull PsiMethod method) {
|
||||
if (method.isConstructor() || method.hasModifierProperty(PsiModifier.STATIC) || method.hasModifierProperty(PsiModifier.PRIVATE)) {
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
return SuperMethodsSearch.search(method, null, true, false).findFirst() != null;
|
||||
final MethodSignatureBackedByPsiMethod signature = SuperMethodsSearch.search(method, null, true, false).findFirst();
|
||||
if (signature == null) {
|
||||
return null;
|
||||
}
|
||||
return signature.getMethod();
|
||||
}
|
||||
|
||||
public static boolean isOverridden(PsiMethod method) {
|
||||
|
||||
Reference in New Issue
Block a user