mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
remove unnecessary method and unnecessary class and cleanup
This commit is contained in:
@@ -628,7 +628,7 @@ manual.array.copy.display.name=Manual array copy
|
||||
manual.array.to.collection.copy.display.name=Manual array to collection copy
|
||||
long.literals.ending.with.lowercase.l.display.name='long' literal ending with 'l' instead of 'L'
|
||||
overly.complex.arithmetic.expression.display.name=Overly complex arithmetic expression
|
||||
j.unit.abstract.test.class.naming.convention.display.name=JUnit abstract test class naming convention
|
||||
junit.abstract.test.class.naming.convention.display.name=JUnit abstract test class naming convention
|
||||
unnecessary.parentheses.display.name=Unnecessary parentheses
|
||||
test.case.in.product.code.display.name=JUnit TestCase in product source
|
||||
test.method.in.product.code.display.name=JUnit test method in product source
|
||||
@@ -805,7 +805,7 @@ class.in.top.level.package.display.name=Class without package statement
|
||||
confusing.else.display.name=Confusing 'else' branch
|
||||
public.field.accessed.in.synchronized.context.display.name=Non-private field accessed in synchronized context
|
||||
string.replaceable.by.string.buffer.display.name=Non-constant String should be StringBuilder
|
||||
j.unit.test.class.naming.convention.display.name=JUnit test class naming convention
|
||||
junit.test.class.naming.convention.display.name=JUnit test class naming convention
|
||||
method.coupling.display.name=Overly coupled method
|
||||
collections.must.have.initial.capacity.display.name=Collection without initial capacity
|
||||
anonymous.inner.class.display.name=Anonymous inner class
|
||||
@@ -1131,12 +1131,12 @@ instance.variable.name.convention.problem.descriptor.regex.mismatch=Instance fie
|
||||
interface.name.convention.problem.descriptor.short=Interface name <code>#ref</code> is too short #loc
|
||||
interface.name.convention.problem.descriptor.long=Interface name <code>#ref</code> is too long #loc
|
||||
interface.name.convention.problem.descriptor.regex.mismatch=Interface name <code>#ref</code> doesn''t match regex ''{0}'' #loc
|
||||
j.unit.abstract.test.class.naming.convention.problem.descriptor.short=Abstract JUnit test class name <code>#ref</code> is too short #loc
|
||||
j.unit.abstract.test.class.naming.convention.problem.descriptor.long=Abstract JUnit test class name <code>#ref</code> is too long #loc
|
||||
j.unit.abstract.test.class.naming.convention.problem.descriptor.regex.mismatch=Abstract JUnit test class name <code>#ref</code> doesn''t match regex ''{0}'' #loc
|
||||
j.unit.test.class.naming.convention.problem.descriptor.short=JUnit test class name <code>#ref</code> is too short #loc
|
||||
j.unit.test.class.naming.convention.problem.descriptor.long=JUnit test class name <code>#ref</code> is too long #loc
|
||||
j.unit.test.class.naming.convention.problem.descriptor.regex.mismatch=JUnit test class name <code>#ref</code> doesn''t match regex ''{0}'' #loc
|
||||
junit.abstract.test.class.naming.convention.problem.descriptor.short=Abstract JUnit test class name <code>#ref</code> is too short #loc
|
||||
junit.abstract.test.class.naming.convention.problem.descriptor.long=Abstract JUnit test class name <code>#ref</code> is too long #loc
|
||||
junit.abstract.test.class.naming.convention.problem.descriptor.regex.mismatch=Abstract JUnit test class name <code>#ref</code> doesn''t match regex ''{0}'' #loc
|
||||
junit.test.class.naming.convention.problem.descriptor.short=JUnit test class name <code>#ref</code> is too short #loc
|
||||
junit.test.class.naming.convention.problem.descriptor.long=JUnit test class name <code>#ref</code> is too long #loc
|
||||
junit.test.class.naming.convention.problem.descriptor.regex.mismatch=JUnit test class name <code>#ref</code> doesn''t match regex ''{0}'' #loc
|
||||
local.variable.naming.convention.problem.descriptor.short=Local variable name <code>#ref</code> is too short #loc
|
||||
local.variable.naming.convention.problem.descriptor.long=Local variable name <code>#ref</code> is too long #loc
|
||||
local.variable.naming.convention.problem.descriptor.regex.mismatch=Local variable name <code>#ref</code> doesn''t match regex ''{0}'' #loc
|
||||
@@ -1182,7 +1182,7 @@ unnecessary.boxing.remove.quickfix=Remove boxing
|
||||
unnecessary.unboxing.remove.quickfix=Remove unboxing
|
||||
misordered.assert.equals.parameters.flip.quickfix=Flip compared parameters
|
||||
setup.calls.super.setup.add.quickfix=Add call to 'super.setUp()'
|
||||
simplify.j.unit.assertion.simplify.quickfix=Simplify assertion
|
||||
simplify.junit.assertion.simplify.quickfix=Simplify assertion
|
||||
teardown.calls.super.teardown.add.quickfix=Add call to 'super.tearDown()'
|
||||
test.method.is.public.void.no.arg.problem.descriptor1=Test method <code>#ref()</code> should probably not have parameters #loc
|
||||
test.method.is.public.void.no.arg.problem.descriptor2=Test method <code>#ref()</code> is not declared 'public void' #loc
|
||||
@@ -1831,4 +1831,7 @@ shift.out.of.range.quickfix=Replace ''{0}'' with ''{1}''
|
||||
boxing.boxed.value.display.name=Boxing of already boxed value
|
||||
boxing.boxed.value.problem.descriptor=Boxing of already boxed <code>#ref</code>
|
||||
boxing.boxed.value.quickfix=Remove unnecessary boxing
|
||||
unnecessary.javadoc.link.option=Ignore inline links to super methods
|
||||
unnecessary.javadoc.link.option=Ignore inline links to super methods
|
||||
constant.junit.assert.argument.display.name=Constant JUnit assert argument
|
||||
constant.junit.assert.argument.problem.descriptor=Argument <code>#ref</code> is constant
|
||||
test.case.with.no.test.methods.option=Ignore test cases which have super classes with test methods
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,6 +17,7 @@ package com.siyeh.ig;
|
||||
|
||||
import com.intellij.codeInspection.ProblemsHolder;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class BaseInspectionVisitor extends JavaElementVisitor{
|
||||
@@ -49,7 +50,8 @@ public abstract class BaseInspectionVisitor extends JavaElementVisitor{
|
||||
}
|
||||
|
||||
protected final void registerMethodCallError(
|
||||
@NotNull PsiMethodCallExpression expression, Object... infos) {
|
||||
@NotNull PsiMethodCallExpression expression,
|
||||
@NonNls Object... infos) {
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
final PsiElement nameToken = methodExpression.getReferenceNameElement();
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,10 @@
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.EquivalenceChecker;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -91,9 +91,9 @@ public class CollectionAddedToSelfInspection extends BaseInspection {
|
||||
if(qualifierClass == null){
|
||||
return;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(qualifierClass,
|
||||
if(!InheritanceUtil.isInheritor(qualifierClass,
|
||||
CommonClassNames.JAVA_UTIL_COLLECTION) &&
|
||||
!ClassUtils.isSubclass(qualifierClass,
|
||||
!InheritanceUtil.isInheritor(qualifierClass,
|
||||
CommonClassNames.JAVA_UTIL_MAP)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -22,12 +22,12 @@ import com.intellij.codeInspection.ui.RemoveAction;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.LibraryUtil;
|
||||
import com.siyeh.ig.ui.*;
|
||||
import com.siyeh.ig.ui.ToggleAction;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -154,7 +154,7 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
|
||||
continue;
|
||||
}
|
||||
final String className = classNames.get(i);
|
||||
if (!ClassUtils.isSubclass(aClass, className)) {
|
||||
if (!InheritanceUtil.isInheritor(aClass, className)) {
|
||||
continue;
|
||||
}
|
||||
registerMethodCallError(call, aClass);
|
||||
@@ -198,7 +198,6 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
|
||||
JCheckBox nonLibraryCheckbox;
|
||||
|
||||
Form(){
|
||||
super();
|
||||
addButton.setAction(new AddAction(table));
|
||||
removeButton.setAction(new RemoveAction(table));
|
||||
nonLibraryCheckbox.setAction(new ToggleAction(
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2010 Bas Leijdekkers
|
||||
* Copyright 2007-2011 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,12 +18,12 @@ package com.siyeh.ig.bugs;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
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.ClassUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -120,7 +120,7 @@ public class NewStringBufferWithCharArgumentInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass aClass = constructor.getContainingClass();
|
||||
if (!ClassUtils.isSubclass(aClass,
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_ABSTRACT_STRING_BUILDER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-2
@@ -18,13 +18,13 @@ package com.siyeh.ig.bugs;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
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.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -224,7 +224,8 @@ public class StringConcatenationInMessageFormatCallInspection
|
||||
return false;
|
||||
}
|
||||
final PsiClass aClass = (PsiClass) target;
|
||||
return ClassUtils.isSubclass(aClass, "java.text.MessageFormat");
|
||||
return InheritanceUtil.isInheritor(aClass,
|
||||
"java.text.MessageFormat");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2005-2010 Bas Leijdekkers
|
||||
* Copyright 2005-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,10 @@
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -76,7 +76,7 @@ public class SuspiciousToArrayCallInspection extends BaseInspection {
|
||||
final PsiClassType classType = (PsiClassType)type;
|
||||
final PsiClass aClass = classType.resolve();
|
||||
if (aClass == null ||
|
||||
!ClassUtils.isSubclass(aClass,
|
||||
!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+10
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008 Bas Leijdekkers
|
||||
* Copyright 2008-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,24 +17,26 @@ package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.Query;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ThrowableResultOfMethodCallIgnoredInspection
|
||||
extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"throwable.result.of.method.call.ignored.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
@@ -46,6 +48,7 @@ public class ThrowableResultOfMethodCallIgnoredInspection
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new ThrowableResultOfMethodCallIgnoredVisitor();
|
||||
}
|
||||
@@ -75,7 +78,7 @@ public class ThrowableResultOfMethodCallIgnoredInspection
|
||||
}
|
||||
if (!method.hasModifierProperty(PsiModifier.STATIC)) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (ClassUtils.isSubclass(containingClass,
|
||||
if (InheritanceUtil.isInheritor(containingClass,
|
||||
CommonClassNames.JAVA_LANG_THROWABLE)) {
|
||||
return;
|
||||
}
|
||||
@@ -117,11 +120,9 @@ public class ThrowableResultOfMethodCallIgnoredInspection
|
||||
while (usageParent instanceof PsiParenthesizedExpression) {
|
||||
usageParent = usageParent.getParent();
|
||||
}
|
||||
if (usageParent instanceof PsiThrowStatement) {
|
||||
return;
|
||||
} else if (usageParent instanceof PsiReturnStatement) {
|
||||
return;
|
||||
} else if (usageParent instanceof PsiExpressionList) {
|
||||
if (usageParent instanceof PsiThrowStatement ||
|
||||
usageParent instanceof PsiReturnStatement ||
|
||||
usageParent instanceof PsiExpressionList) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,11 @@
|
||||
package com.siyeh.ig.bugs;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -65,7 +65,8 @@ public class UseOfPropertiesAsHashtableInspection extends BaseInspection {
|
||||
if(containingClass == null){
|
||||
return;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(containingClass, "java.util.Hashtable")){
|
||||
if(!InheritanceUtil.isInheritor(containingClass,
|
||||
"java.util.Hashtable")){
|
||||
return;
|
||||
}
|
||||
final PsiExpression qualifier =
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -218,8 +218,8 @@ public class MissingOverrideAnnotationInspection extends BaseInspection {
|
||||
final List<PsiMethod> toExclude = new SmartList<PsiMethod>();
|
||||
for (PsiMethod superMethod : superMethods) {
|
||||
final PsiClass superClass = superMethod.getContainingClass();
|
||||
if (!InheritanceUtil.isCorrectDescendant(methodClass,
|
||||
superClass, true)) {
|
||||
if (!InheritanceUtil.isInheritorOrSelf(methodClass, superClass,
|
||||
true)) {
|
||||
toExclude.add(superMethod);
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,13 +15,13 @@
|
||||
*/
|
||||
package com.siyeh.ig.controlflow;
|
||||
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -144,7 +144,7 @@ public class ForLoopWithMissingComponentInspection extends BaseInspection {
|
||||
if(declaredClass == null){
|
||||
continue;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(declaredClass,
|
||||
if(!InheritanceUtil.isInheritor(declaredClass,
|
||||
CommonClassNames.JAVA_UTIL_ITERATOR)){
|
||||
continue;
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,10 @@ package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CheckedExceptionClassInspection extends BaseInspection {
|
||||
@@ -47,11 +47,11 @@ public class CheckedExceptionClassInspection extends BaseInspection {
|
||||
private static class CheckedExceptionClassVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
@Override public void visitClass(@NotNull PsiClass aClass) {
|
||||
if (!ClassUtils.isSubclass(aClass,
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_THROWABLE)) {
|
||||
return;
|
||||
}
|
||||
if (ClassUtils.isSubclass(aClass,
|
||||
if (InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,11 @@
|
||||
package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -73,7 +73,7 @@ public class ErrorRethrownInspection extends BaseInspection {
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass,
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_ERROR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,12 +19,12 @@ import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiField;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.MakeFieldFinalFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -69,7 +69,7 @@ public class NonFinalFieldOfExceptionInspection extends BaseInspection {
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(containingClass,
|
||||
if (!InheritanceUtil.isInheritor(containingClass,
|
||||
CommonClassNames.JAVA_LANG_EXCEPTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,10 @@ package com.siyeh.ig.errorhandling;
|
||||
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UncheckedExceptionClassInspection extends BaseInspection {
|
||||
@@ -48,13 +48,13 @@ public class UncheckedExceptionClassInspection extends BaseInspection {
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override public void visitClass(@NotNull PsiClass aClass) {
|
||||
if (!ClassUtils.isSubclass(aClass,
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_THROWABLE)) {
|
||||
return;
|
||||
}
|
||||
if (ClassUtils.isSubclass(aClass,
|
||||
if (InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_EXCEPTION) &&
|
||||
!ClassUtils.isSubclass(aClass,
|
||||
!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2009 Bas Leijdekkers
|
||||
* Copyright 2008-2011 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,11 +18,11 @@ package com.siyeh.ig.fixes;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
|
||||
import com.intellij.psi.search.SearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Query;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
@@ -74,9 +74,8 @@ public class ExtractParameterAsLocalVariableFix
|
||||
if (body == null) {
|
||||
return;
|
||||
}
|
||||
final PsiManager manager = PsiManager.getInstance(project);
|
||||
final CodeStyleManager codeStyleManager =
|
||||
manager.getCodeStyleManager();
|
||||
CodeStyleManager.getInstance(project);
|
||||
final String parameterName = parameterReference.getText();
|
||||
final JavaCodeStyleManager javaCodeStyleManager =
|
||||
JavaCodeStyleManager.getInstance(project);
|
||||
@@ -192,7 +191,7 @@ public class ExtractParameterAsLocalVariableFix
|
||||
(PsiAssignmentExpression)parent;
|
||||
final IElementType tokenType =
|
||||
assignmentExpression.getOperationTokenType();
|
||||
if (tokenType != JavaTokenType.EQ) {
|
||||
if (!JavaTokenType.EQ.equals(tokenType)) {
|
||||
return false;
|
||||
}
|
||||
final PsiExpression lExpression =
|
||||
|
||||
+5
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,18 +29,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
public class OverriddenMethodCallDuringObjectConstructionInspection
|
||||
extends BaseInspection{
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName(){
|
||||
return InspectionGadgetsBundle.message(
|
||||
"overridden.method.call.in.constructor.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos){
|
||||
return InspectionGadgetsBundle.message(
|
||||
"overridden.method.call.in.constructor.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor(){
|
||||
return new OverriddenMethodCallInConstructorVisitor();
|
||||
}
|
||||
@@ -90,7 +93,7 @@ public class OverriddenMethodCallDuringObjectConstructionInspection
|
||||
}
|
||||
final PsiClass calledMethodClass =
|
||||
calledMethod.getContainingClass();
|
||||
if(!InheritanceUtil.isCorrectDescendant(containingClass,
|
||||
if(!InheritanceUtil.isInheritorOrSelf(containingClass,
|
||||
calledMethodClass, true)){
|
||||
return;
|
||||
}
|
||||
|
||||
+9
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,18 +28,21 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ClassWithoutConstructorInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"class.without.constructor.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"class.without.constructor.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new ClassWithoutConstructorFix();
|
||||
}
|
||||
@@ -53,12 +56,13 @@ public class ClassWithoutConstructorInspection extends BaseInspection {
|
||||
"class.without.constructor.create.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement classIdentifier = descriptor.getPsiElement();
|
||||
final PsiClass aClass = (PsiClass)classIdentifier.getParent();
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
|
||||
final PsiElementFactory factory =
|
||||
JavaPsiFacade.getElementFactory(project);
|
||||
final PsiMethod constructor = factory.createConstructor();
|
||||
final PsiModifierList modifierList = constructor.getModifierList();
|
||||
if (aClass == null) {
|
||||
@@ -78,11 +82,12 @@ public class ClassWithoutConstructorInspection extends BaseInspection {
|
||||
}
|
||||
aClass.add(constructor);
|
||||
final CodeStyleManager styleManager =
|
||||
psiManager.getCodeStyleManager();
|
||||
CodeStyleManager.getInstance(project);
|
||||
styleManager.reformat(constructor);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new ClassWithoutConstructorVisitor();
|
||||
}
|
||||
|
||||
+16
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 Bas Leijdekkers
|
||||
* Copyright 2007-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.Query;
|
||||
@@ -28,7 +29,6 @@ import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.PsiElementOrderComparator;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -179,8 +179,7 @@ public class EnumerationCanBeIterationInspection extends BaseInspection {
|
||||
PsiMethodCallExpression methodCallExpression,
|
||||
String variableName, PsiType parameterType)
|
||||
throws IncorrectOperationException {
|
||||
final StringBuilder newStatementText =
|
||||
new StringBuilder();
|
||||
@NonNls final StringBuilder newStatementText = new StringBuilder();
|
||||
final Project project = methodCallExpression.getProject();
|
||||
final CodeStyleSettings codeStyleSettings =
|
||||
CodeStyleSettingsManager.getSettings(project);
|
||||
@@ -231,12 +230,13 @@ public class EnumerationCanBeIterationInspection extends BaseInspection {
|
||||
return null;
|
||||
}
|
||||
newStatementText.append(';');
|
||||
final PsiManager manager = methodCallExpression.getManager();
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
final PsiElementFactory factory =
|
||||
JavaPsiFacade.getElementFactory(project);
|
||||
final PsiStatement statement =
|
||||
factory.createStatementFromText(newStatementText.toString(),
|
||||
methodExpression);
|
||||
final JavaCodeStyleManager styleManager = JavaCodeStyleManager.getInstance(project);
|
||||
final JavaCodeStyleManager styleManager =
|
||||
JavaCodeStyleManager.getInstance(project);
|
||||
styleManager.shortenClassReferences(statement);
|
||||
return statement;
|
||||
}
|
||||
@@ -293,9 +293,9 @@ public class EnumerationCanBeIterationInspection extends BaseInspection {
|
||||
(PsiMethodCallExpression) referenceGrandParent;
|
||||
final PsiReferenceExpression foundReferenceExpression =
|
||||
callExpression.getMethodExpression();
|
||||
final String foundName =
|
||||
@NonNls final String foundName =
|
||||
foundReferenceExpression.getReferenceName();
|
||||
final String newExpressionText;
|
||||
@NonNls final String newExpressionText;
|
||||
if ("hasMoreElements".equals(foundName)) {
|
||||
newExpressionText = newVariableName + ".hasNext()";
|
||||
} else if ("nextElement".equals(foundName)) {
|
||||
@@ -312,6 +312,7 @@ public class EnumerationCanBeIterationInspection extends BaseInspection {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NonNls
|
||||
private static String createVariableName(PsiElement context) {
|
||||
final Project project = context.getProject();
|
||||
final JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
|
||||
@@ -339,6 +340,7 @@ public class EnumerationCanBeIterationInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new EnumerationCanBeIterationVisitor();
|
||||
}
|
||||
@@ -400,10 +402,10 @@ public class EnumerationCanBeIterationInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (ClassUtils.isSubclass(containingClass,
|
||||
if (InheritanceUtil.isInheritor(containingClass,
|
||||
"java.util.Vector")) {
|
||||
registerMethodCallError(expression, ITERATOR_TEXT);
|
||||
} else if (ClassUtils.isSubclass(containingClass,
|
||||
} else if (InheritanceUtil.isInheritor(containingClass,
|
||||
"java.util.Hashtable")) {
|
||||
registerMethodCallError(expression, VALUES_ITERATOR_TEXT);
|
||||
}
|
||||
@@ -413,7 +415,7 @@ public class EnumerationCanBeIterationInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (ClassUtils.isSubclass(containingClass,
|
||||
if (InheritanceUtil.isInheritor(containingClass,
|
||||
"java.util.Hashtable")) {
|
||||
registerMethodCallError(expression, KEY_SET_ITERATOR_TEXT);
|
||||
}
|
||||
@@ -446,7 +448,8 @@ public class EnumerationCanBeIterationInspection extends BaseInspection {
|
||||
super.visitMethodCallExpression(expression);
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
@NonNls final String methodName =
|
||||
methodExpression.getReferenceName();
|
||||
if (!"hasMoreElements".equals(methodName) &&
|
||||
!"nextElement".equals(methodName)) {
|
||||
return;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,23 +35,27 @@ import java.util.Collection;
|
||||
|
||||
public class VarargParameterInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID(){
|
||||
return "VariableArgumentMethod";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"variable.argument.method.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"variable.argument.method.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new VarargParameterFix();
|
||||
@@ -65,6 +69,7 @@ public class VarargParameterInspection extends BaseInspection {
|
||||
"variable.argument.method.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement element = descriptor.getPsiElement();
|
||||
@@ -121,8 +126,9 @@ public class VarargParameterInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
builder.append('}');
|
||||
final PsiManager manager = referenceExpression.getManager();
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory();
|
||||
final Project project = referenceExpression.getProject();
|
||||
final PsiElementFactory factory =
|
||||
JavaPsiFacade.getElementFactory(project);
|
||||
final PsiExpression arrayExpression =
|
||||
factory.createExpressionFromText(builder.toString(),
|
||||
referenceExpression);
|
||||
@@ -136,12 +142,15 @@ public class VarargParameterInspection extends BaseInspection {
|
||||
argumentList.add(arrayExpression);
|
||||
}
|
||||
final CodeStyleManager codeStyleManager =
|
||||
manager.getCodeStyleManager();
|
||||
JavaCodeStyleManager.getInstance(manager.getProject()).shortenClassReferences(argumentList);
|
||||
CodeStyleManager.getInstance(project);
|
||||
final JavaCodeStyleManager javaCodeStyleManager =
|
||||
JavaCodeStyleManager.getInstance(project);
|
||||
javaCodeStyleManager.shortenClassReferences(argumentList);
|
||||
codeStyleManager.reformat(argumentList);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new VarargParameterVisitor();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -1066,7 +1066,7 @@ public class ForCanBeForeachInspection extends BaseInspection{
|
||||
if(declaredClass == null){
|
||||
return false;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(declaredClass,
|
||||
if(!InheritanceUtil.isInheritor(declaredClass,
|
||||
CommonClassNames.JAVA_UTIL_ITERATOR)){
|
||||
return false;
|
||||
}
|
||||
@@ -1107,9 +1107,9 @@ public class ForCanBeForeachInspection extends BaseInspection{
|
||||
if(qualifierClass == null){
|
||||
return false;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(qualifierClass,
|
||||
if(!InheritanceUtil.isInheritor(qualifierClass,
|
||||
CommonClassNames.JAVA_LANG_ITERABLE) &&
|
||||
!ClassUtils.isSubclass(qualifierClass,
|
||||
!InheritanceUtil.isInheritor(qualifierClass,
|
||||
CommonClassNames.JAVA_UTIL_COLLECTION)){
|
||||
return false;
|
||||
}
|
||||
@@ -1288,7 +1288,8 @@ public class ForCanBeForeachInspection extends BaseInspection{
|
||||
return false;
|
||||
}
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
return ClassUtils.isSubclass(aClass, CommonClassNames.JAVA_UTIL_LIST);
|
||||
return InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_UTIL_LIST);
|
||||
}
|
||||
|
||||
private static Holder getCollectionFromListMethodCall(
|
||||
@@ -1319,7 +1320,7 @@ public class ForCanBeForeachInspection extends BaseInspection{
|
||||
return null;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (!ClassUtils.isSubclass(containingClass,
|
||||
if (!InheritanceUtil.isInheritor(containingClass,
|
||||
CommonClassNames.JAVA_UTIL_LIST)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,6 +21,7 @@ import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.ReferencesSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
@@ -31,7 +32,6 @@ import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.StringUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import com.siyeh.ig.psiutils.VariableAccessUtils;
|
||||
@@ -467,9 +467,9 @@ public class WhileCanBeForeachInspection extends BaseInspection {
|
||||
if (qualifierClass == null) {
|
||||
return false;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(qualifierClass,
|
||||
if (!InheritanceUtil.isInheritor(qualifierClass,
|
||||
CommonClassNames.JAVA_LANG_ITERABLE) &&
|
||||
!ClassUtils.isSubclass(qualifierClass,
|
||||
!InheritanceUtil.isInheritor(qualifierClass,
|
||||
CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
return false;
|
||||
}
|
||||
@@ -586,7 +586,6 @@ public class WhileCanBeForeachInspection extends BaseInspection {
|
||||
private final PsiVariable iterator;
|
||||
|
||||
private NumCallsToIteratorNextVisitor(PsiVariable iterator) {
|
||||
super();
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@@ -626,7 +625,6 @@ public class WhileCanBeForeachInspection extends BaseInspection {
|
||||
private final PsiVariable iterator;
|
||||
|
||||
private IteratorRemoveVisitor(@NotNull PsiVariable iterator) {
|
||||
super();
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
@@ -670,7 +668,6 @@ public class WhileCanBeForeachInspection extends BaseInspection {
|
||||
private final PsiVariable iterator;
|
||||
|
||||
private IteratorHasNextVisitor(PsiVariable iterator) {
|
||||
super();
|
||||
this.iterator = iterator;
|
||||
}
|
||||
|
||||
|
||||
+7
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2010 Bas Leijdekkers
|
||||
* Copyright 2007-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -77,8 +77,10 @@ public class AssertEqualsBetweenInconvertibleTypesInspection
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (!ClassUtils.isSubclass(containingClass, "junit.framework.Assert") &&
|
||||
!ClassUtils.isSubclass(containingClass, "org.junit.Assert")) {
|
||||
if (!InheritanceUtil.isInheritor(containingClass,
|
||||
"junit.framework.Assert") &&
|
||||
!InheritanceUtil.isInheritor(containingClass,
|
||||
"org.junit.Assert")) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
|
||||
+10
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, 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,10 +18,10 @@ package com.siyeh.ig.junit;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -30,23 +30,27 @@ import java.util.Set;
|
||||
|
||||
public class AssertsWithoutMessagesInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"asserts.without.messages.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "MessageMissingOnJUnitAssertion";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"asserts.without.messages.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new AssertionsWithoutMessagesVisitor();
|
||||
}
|
||||
@@ -123,9 +127,10 @@ public class AssertsWithoutMessagesInspection extends BaseInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiClass targetClass = method.getContainingClass();
|
||||
return targetClass != null &&
|
||||
(ClassUtils.isSubclass(targetClass, "junit.framework.Assert") ||
|
||||
ClassUtils.isSubclass(targetClass, "org.junit.Assert"));
|
||||
return InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.Assert") ||
|
||||
InheritanceUtil.isInheritor(targetClass,
|
||||
"org.junit.Assert");
|
||||
}
|
||||
}
|
||||
}
|
||||
+18
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009 Bas Leijdekkers
|
||||
* Copyright 2009-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,20 +15,22 @@
|
||||
*/
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
public class ConstantJUnitAssertArgumentInspection extends BaseInspection {
|
||||
|
||||
@NonNls
|
||||
private static final Set<String> ASSERT_METHODS = new HashSet();
|
||||
|
||||
static {
|
||||
@@ -42,21 +44,23 @@ public class ConstantJUnitAssertArgumentInspection extends BaseInspection {
|
||||
@Nls
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return "Constant JUnit assert argument";
|
||||
return InspectionGadgetsBundle.message(
|
||||
"constant.junit.assert.argument.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return "Argument <code>#ref</code> is constant";
|
||||
return InspectionGadgetsBundle.message(
|
||||
"constant.junit.assert.argument.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new ConstantJUnitAssertArugmentVisitor();
|
||||
return new ConstantJUnitAssertArgumentVisitor();
|
||||
}
|
||||
|
||||
private static class ConstantJUnitAssertArugmentVisitor
|
||||
private static class ConstantJUnitAssertArgumentVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override
|
||||
@@ -74,8 +78,10 @@ public class ConstantJUnitAssertArgumentInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (!ClassUtils.isSubclass(containingClass, "junit.framework.Assert") &&
|
||||
!ClassUtils.isSubclass(containingClass, "org.junit.Assert")) {
|
||||
if (!InheritanceUtil.isInheritor(containingClass,
|
||||
"junit.framework.Assert") &&
|
||||
!InheritanceUtil.isInheritor(containingClass,
|
||||
"org.junit.Assert")) {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010 Bas Leijdekkers
|
||||
* Copyright 2010-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,10 @@ package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.ExceptionUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -89,7 +89,7 @@ public class ExpectedExceptionNeverThrownInspection
|
||||
}
|
||||
final PsiClassType classType = (PsiClassType) type;
|
||||
final PsiClass aClass = classType.resolve();
|
||||
if (ClassUtils.isSubclass(aClass,
|
||||
if (InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+16
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, 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,12 +18,12 @@ package com.siyeh.ig.junit;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import com.siyeh.ig.naming.ConventionInspection;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class JUnitAbstractTestClassNamingConventionInspection
|
||||
@@ -32,47 +32,55 @@ public class JUnitAbstractTestClassNamingConventionInspection
|
||||
private static final int DEFAULT_MIN_LENGTH = 12;
|
||||
private static final int DEFAULT_MAX_LENGTH = 64;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"j.unit.abstract.test.class.naming.convention.display.name");
|
||||
"junit.abstract.test.class.naming.convention.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
final String className = (String)infos[0];
|
||||
if (className.length() < getMinLength()) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"j.unit.abstract.test.class.naming.convention.problem.descriptor.short");
|
||||
"junit.abstract.test.class.naming.convention.problem.descriptor.short");
|
||||
} else if (className.length() > getMaxLength()) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"j.unit.abstract.test.class.naming.convention.problem.descriptor.long");
|
||||
"junit.abstract.test.class.naming.convention.problem.descriptor.long");
|
||||
}
|
||||
return InspectionGadgetsBundle.message(
|
||||
"j.unit.abstract.test.class.naming.convention.problem.descriptor.regex.mismatch",
|
||||
"junit.abstract.test.class.naming.convention.problem.descriptor.regex.mismatch",
|
||||
getRegex());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getDefaultRegex() {
|
||||
return "[A-Z][A-Za-z\\d]*TestCase";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultMinLength() {
|
||||
return DEFAULT_MIN_LENGTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDefaultMaxLength() {
|
||||
return DEFAULT_MAX_LENGTH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new NamingConventionsVisitor();
|
||||
}
|
||||
@@ -90,7 +98,8 @@ public class JUnitAbstractTestClassNamingConventionInspection
|
||||
if(!aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
return;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(aClass, "junit.framework.TestCase")) {
|
||||
if(!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
final String name = aClass.getName();
|
||||
|
||||
+8
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,12 +19,12 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import com.siyeh.ig.naming.ConventionInspection;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -38,7 +38,7 @@ public class JUnitTestClassNamingConventionInspection
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"j.unit.test.class.naming.convention.display.name");
|
||||
"junit.test.class.naming.convention.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,13 +57,13 @@ public class JUnitTestClassNamingConventionInspection
|
||||
final String className = (String)infos[0];
|
||||
if (className.length() < getMinLength()) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"j.unit.test.class.naming.convention.problem.descriptor.short");
|
||||
"junit.test.class.naming.convention.problem.descriptor.short");
|
||||
} else if (className.length() > getMaxLength()) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"j.unit.test.class.naming.convention.problem.descriptor.long");
|
||||
"junit.test.class.naming.convention.problem.descriptor.long");
|
||||
}
|
||||
return InspectionGadgetsBundle.message(
|
||||
"j.unit.test.class.naming.convention.problem.descriptor.regex.mismatch",
|
||||
"junit.test.class.naming.convention.problem.descriptor.regex.mismatch",
|
||||
getRegex());
|
||||
}
|
||||
|
||||
@@ -100,7 +100,8 @@ public class JUnitTestClassNamingConventionInspection
|
||||
if(aClass.hasModifierProperty(PsiModifier.ABSTRACT)) {
|
||||
return;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(aClass, "junit.framework.TestCase")) {
|
||||
if(!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
if (!hasJUnit4TestMethods(aClass)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+13
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,30 +19,33 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
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.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisorderedAssertEqualsParametersInspection
|
||||
extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misordered.assert.equals.parameters.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misordered.assert.equals.parameters.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new FlipParametersFix();
|
||||
}
|
||||
@@ -55,6 +58,7 @@ public class MisorderedAssertEqualsParametersInspection
|
||||
"misordered.assert.equals.parameters.flip.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement methodNameIdentifier = descriptor.getPsiElement();
|
||||
@@ -95,6 +99,7 @@ public class MisorderedAssertEqualsParametersInspection
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new MisorderedAssertEqualsParametersVisitor();
|
||||
}
|
||||
@@ -167,8 +172,8 @@ public class MisorderedAssertEqualsParametersInspection
|
||||
return false;
|
||||
}
|
||||
final PsiField field = (PsiField) target;
|
||||
return !(!field.hasModifierProperty(PsiModifier.STATIC) ||
|
||||
!field.hasModifierProperty(PsiModifier.FINAL));
|
||||
return field.hasModifierProperty(PsiModifier.STATIC) &&
|
||||
field.hasModifierProperty(PsiModifier.FINAL);
|
||||
}
|
||||
|
||||
private static boolean isAssertEquals(
|
||||
@@ -185,11 +190,10 @@ public class MisorderedAssertEqualsParametersInspection
|
||||
return false;
|
||||
}
|
||||
final PsiClass targetClass = method.getContainingClass();
|
||||
if (targetClass == null) {
|
||||
return false;
|
||||
}
|
||||
return ClassUtils.isSubclass(targetClass, "junit.framework.Assert")
|
||||
|| ClassUtils.isSubclass(targetClass, "org.junit.Assert");
|
||||
return InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.Assert") ||
|
||||
InheritanceUtil.isInheritor(targetClass,
|
||||
"org.junit.Assert");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,37 +17,42 @@ package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisspelledSetUpInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.set.up.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.set.up.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix("setUp");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new MisspelledSetUpVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
|
||||
return true;
|
||||
}
|
||||
@@ -64,7 +69,8 @@ public class MisspelledSetUpInspection extends BaseInspection {
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "junit.framework.TestCase")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
registerMethodError(method);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,37 +17,42 @@ package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class MisspelledTearDownInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.tear.down.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"misspelled.tear.down.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new RenameFix("tearDown");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new MisspelledSetUpVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
|
||||
return true;
|
||||
}
|
||||
@@ -64,7 +69,8 @@ public class MisspelledTearDownInspection extends BaseInspection {
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "junit.framework.TestCase")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
registerMethodError(method);
|
||||
|
||||
+12
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,28 +19,31 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
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.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SetupCallsSuperSetupInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "SetUpDoesntCallSuperSetUp";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"setup.calls.super.setup.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
@@ -55,6 +58,7 @@ public class SetupCallsSuperSetupInspection extends BaseInspection {
|
||||
"setup.calls.super.setup.add.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement methodName = descriptor.getPsiElement();
|
||||
@@ -64,22 +68,24 @@ public class SetupCallsSuperSetupInspection extends BaseInspection {
|
||||
if (body == null) {
|
||||
return;
|
||||
}
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
|
||||
final PsiElementFactory factory =
|
||||
JavaPsiFacade.getElementFactory(project);
|
||||
final PsiStatement newStatement =
|
||||
factory.createStatementFromText("super.setUp();", null);
|
||||
final CodeStyleManager styleManager =
|
||||
psiManager.getCodeStyleManager();
|
||||
CodeStyleManager.getInstance(project);
|
||||
final PsiJavaToken brace = body.getLBrace();
|
||||
body.addAfter(newStatement, brace);
|
||||
styleManager.reformat(body);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new AddSuperSetUpCall();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new SetupCallsSuperSetupVisitor();
|
||||
}
|
||||
@@ -107,7 +113,7 @@ public class SetupCallsSuperSetupInspection extends BaseInspection {
|
||||
if (targetClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(targetClass,
|
||||
if (!InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
|
||||
+10
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,32 +16,36 @@
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SetupIsPublicVoidNoArgInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "SetUpWithIncorrectSignature";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"setup.is.public.void.no.arg.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"setup.is.public.void.no.arg.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new SetupIsPublicVoidNoArgVisitor();
|
||||
}
|
||||
@@ -63,16 +67,14 @@ public class SetupIsPublicVoidNoArgInspection extends BaseInspection {
|
||||
if (targetClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(targetClass,
|
||||
if (!InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList.getParametersCount() != 0) {
|
||||
registerMethodError(method);
|
||||
} else if (!returnType.equals(PsiType.VOID)) {
|
||||
registerMethodError(method);
|
||||
} else if (!method.hasModifierProperty(PsiModifier.PUBLIC) &&
|
||||
if (parameterList.getParametersCount() != 0 ||
|
||||
!returnType.equals(PsiType.VOID) ||
|
||||
!method.hasModifierProperty(PsiModifier.PUBLIC) &&
|
||||
!method.hasModifierProperty(PsiModifier.PROTECTED)) {
|
||||
registerMethodError(method);
|
||||
}
|
||||
|
||||
+22
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -54,7 +54,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
@NotNull
|
||||
public String getName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"simplify.j.unit.assertion.simplify.quickfix");
|
||||
"simplify.junit.assertion.simplify.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -163,7 +163,8 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
@NonNls final StringBuilder newExpression = new StringBuilder();
|
||||
addStaticImportIfPossible(callExpression, "assertEquals", newExpression);
|
||||
addStaticImportIfPossible(callExpression, "assertEquals",
|
||||
newExpression);
|
||||
newExpression.append("assertEquals(");
|
||||
if (message != null) {
|
||||
newExpression.append(message.getText());
|
||||
@@ -222,9 +223,11 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
@NonNls final StringBuilder newExpression = new StringBuilder();
|
||||
final PsiReferenceExpression methodExpression =
|
||||
callExpression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
final String memberName;
|
||||
if ("assertFalse".equals(methodName) ^ tokenType.equals(JavaTokenType.NE)) {
|
||||
@NonNls final String methodName =
|
||||
methodExpression.getReferenceName();
|
||||
@NonNls final String memberName;
|
||||
if ("assertFalse".equals(methodName) ^
|
||||
tokenType.equals(JavaTokenType.NE)) {
|
||||
memberName = "assertNotNull";
|
||||
} else {
|
||||
memberName = "assertNull";
|
||||
@@ -286,8 +289,9 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
@NonNls final StringBuilder newExpression = new StringBuilder();
|
||||
final PsiReferenceExpression methodExpression =
|
||||
callExpression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
final String memberName;
|
||||
@NonNls final String methodName =
|
||||
methodExpression.getReferenceName();
|
||||
@NonNls final String memberName;
|
||||
if ("assertFalse".equals(methodName) ^
|
||||
tokenType.equals(JavaTokenType.NE)) {
|
||||
memberName = "assertNotSame";
|
||||
@@ -338,8 +342,10 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
secondTestPosition = 1;
|
||||
message = null;
|
||||
}
|
||||
final PsiExpression firstTestArgument = arguments[firstTestPosition];
|
||||
final PsiExpression secondTestArgument = arguments[secondTestPosition];
|
||||
final PsiExpression firstTestArgument =
|
||||
arguments[firstTestPosition];
|
||||
final PsiExpression secondTestArgument =
|
||||
arguments[secondTestPosition];
|
||||
final String literalValue;
|
||||
final String compareValue;
|
||||
if (isSimpleLiteral(firstTestArgument, secondTestArgument)) {
|
||||
@@ -353,7 +359,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
Character.toUpperCase(literalValue.charAt(0)) +
|
||||
literalValue.substring(1);
|
||||
@NonNls final StringBuilder newExpression = new StringBuilder();
|
||||
final String methodName = "assert" + uppercaseLiteralValue;
|
||||
@NonNls final String methodName = "assert" + uppercaseLiteralValue;
|
||||
addStaticImportIfPossible(callExpression, methodName, newExpression);
|
||||
newExpression.append(methodName);
|
||||
newExpression.append('(');
|
||||
@@ -367,8 +373,9 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
newExpression.toString());
|
||||
}
|
||||
|
||||
private static void addStaticImportIfPossible(PsiMethodCallExpression context,
|
||||
String memberName, StringBuilder out) {
|
||||
private static void addStaticImportIfPossible(
|
||||
PsiMethodCallExpression context, @NonNls String memberName,
|
||||
@NonNls StringBuilder out) {
|
||||
final PsiMethod containingMethod = PsiTreeUtil.getParentOfType(
|
||||
context, PsiMethod.class);
|
||||
if (TestUtils.isJUnit4TestMethod(containingMethod)) {
|
||||
@@ -470,7 +477,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
(PsiBinaryExpression) argument;
|
||||
final IElementType tokenType =
|
||||
binaryExpression.getOperationTokenType();
|
||||
return tokenType == JavaTokenType.EQEQ;
|
||||
return JavaTokenType.EQEQ.equals(tokenType);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -768,7 +775,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
|
||||
private static boolean isAssertMethodCall(
|
||||
@NotNull PsiMethodCallExpression expression,
|
||||
@NotNull String assertMethodName) {
|
||||
@NonNls @NotNull String assertMethodName) {
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
@NonNls final String methodName = methodExpression.getReferenceName();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,31 +19,35 @@ import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiParameterList;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class StaticSuiteInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "SuiteNotDeclaredStatic";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message("static.suite.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"static.suite.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new StaticSuiteVisitor();
|
||||
}
|
||||
@@ -60,7 +64,8 @@ public class StaticSuiteInspection extends BaseInspection {
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "junit.framework.TestCase")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
|
||||
+16
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,34 +19,42 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
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.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TeardownCallsSuperTeardownInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "TearDownDoesntCallSuperTearDown";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"teardown.calls.super.teardown.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"teardown.calls.super.teardown.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new AddSuperTearDownCall();
|
||||
}
|
||||
|
||||
private static class AddSuperTearDownCall extends InspectionGadgetsFix {
|
||||
|
||||
@NotNull
|
||||
@@ -54,7 +62,7 @@ public class TeardownCallsSuperTeardownInspection extends BaseInspection {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"teardown.calls.super.teardown.add.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement methodName = descriptor.getPsiElement();
|
||||
@@ -66,22 +74,19 @@ public class TeardownCallsSuperTeardownInspection extends BaseInspection {
|
||||
if (body == null) {
|
||||
return;
|
||||
}
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final PsiElementFactory factory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
|
||||
final PsiElementFactory factory =
|
||||
JavaPsiFacade.getElementFactory(project);
|
||||
final PsiStatement newStatement =
|
||||
factory.createStatementFromText("super.tearDown();", null);
|
||||
final CodeStyleManager styleManager =
|
||||
psiManager.getCodeStyleManager();
|
||||
CodeStyleManager.getInstance(project);
|
||||
final PsiJavaToken brace = body.getRBrace();
|
||||
body.addBefore(newStatement, brace);
|
||||
styleManager.reformat(body);
|
||||
}
|
||||
}
|
||||
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new AddSuperTearDownCall();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new TeardownCallsSuperTeardownVisitor();
|
||||
}
|
||||
@@ -109,7 +114,7 @@ public class TeardownCallsSuperTeardownInspection extends BaseInspection {
|
||||
if (targetClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(targetClass,
|
||||
if (!InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,32 +16,36 @@
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TeardownIsPublicVoidNoArgInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "TearDownWithIncorrectSignature";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"teardown.is.public.void.no.arg.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"teardown.is.public.void.no.arg.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new TeardownIsPublicVoidNoArgVisitor();
|
||||
}
|
||||
@@ -63,18 +67,14 @@ public class TeardownIsPublicVoidNoArgInspection extends BaseInspection {
|
||||
if (targetClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(targetClass,
|
||||
if (!InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
if (parameterList.getParametersCount() != 0) {
|
||||
registerMethodError(method);
|
||||
}
|
||||
else if (!returnType.equals(PsiType.VOID)) {
|
||||
registerMethodError(method);
|
||||
}
|
||||
else if (!method.hasModifierProperty(PsiModifier.PUBLIC) &&
|
||||
if (parameterList.getParametersCount() != 0 ||
|
||||
!returnType.equals(PsiType.VOID) ||
|
||||
!method.hasModifierProperty(PsiModifier.PUBLIC) &&
|
||||
!method.hasModifierProperty(PsiModifier.PROTECTED)) {
|
||||
registerMethodError(method);
|
||||
}
|
||||
|
||||
+10
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,42 +16,48 @@
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.MoveClassFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class TestCaseInProductCodeInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"test.case.in.product.code.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "JUnitTestCaseInProductSource";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"test.case.in.product.code.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new MoveClassFix();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean buildQuickFixesOnlyForOnTheFlyErrors() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new TestCaseInProductCodeVisitor();
|
||||
}
|
||||
@@ -63,7 +69,8 @@ public class TestCaseInProductCodeInspection extends BaseInspection {
|
||||
if (TestUtils.isTest(aClass)) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "junit.framework.TestCase")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
registerClassError(aClass);
|
||||
|
||||
+14
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,15 +15,15 @@
|
||||
*/
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
import com.intellij.psi.PsiModifier;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.codeInspection.ui.SingleCheckboxOptionsPanel;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -35,28 +35,36 @@ public class TestCaseWithNoTestMethodsInspection extends BaseInspection {
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean ignoreSupers = false;
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "JUnitTestCaseWithNoTests";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"test.case.with.no.test.methods.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"test.case.with.no.test.methods.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel("Ignore test cases which have super classes with test methods", this, "ignoreSupers");
|
||||
return new SingleCheckboxOptionsPanel(
|
||||
InspectionGadgetsBundle.message(
|
||||
"test.case.with.no.test.methods.option"), this,
|
||||
"ignoreSupers");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new TestCaseWithNoTestMethodsVisitor();
|
||||
}
|
||||
@@ -74,7 +82,8 @@ public class TestCaseWithNoTestMethodsInspection extends BaseInspection {
|
||||
if (aClass instanceof PsiTypeParameter) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "junit.framework.TestCase")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod[] methods = aClass.getMethods();
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2009 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,10 @@ package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -94,7 +94,7 @@ public class TestMethodIsPublicVoidNoArgInspection extends BaseInspection {
|
||||
final PsiClass targetClass = method.getContainingClass();
|
||||
if (!AnnotationUtil.isAnnotated(method, "org.junit.Test", true)) {
|
||||
if (targetClass == null ||
|
||||
!ClassUtils.isSubclass(targetClass,
|
||||
!InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
|
||||
+7
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,17 +16,17 @@
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.codeInspection.ui.ListTable;
|
||||
import com.intellij.codeInspection.ui.ListWrappingTableModel;
|
||||
import com.intellij.openapi.actionSystem.ActionToolbar;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.TestUtils;
|
||||
import com.intellij.codeInspection.ui.ListWrappingTableModel;
|
||||
import com.siyeh.ig.ui.CheckBox;
|
||||
import com.siyeh.ig.ui.UiUtils;
|
||||
import org.jdom.Element;
|
||||
@@ -53,6 +53,7 @@ public class TestMethodWithoutAssertionInspection extends BaseInspection {
|
||||
private final List<String> classNames = new ArrayList();
|
||||
private Map<String, Pattern> patternCache = null;
|
||||
|
||||
@SuppressWarnings({"PublicField"})
|
||||
public boolean assertKeywordIsAssertion = false;
|
||||
|
||||
public TestMethodWithoutAssertionInspection() {
|
||||
@@ -197,8 +198,8 @@ public class TestMethodWithoutAssertionInspection extends BaseInspection {
|
||||
if (methodName == null) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0, methodNamesSize = methodNamePatterns.size();
|
||||
i < methodNamesSize; i++) {
|
||||
final int methodNamesSize = methodNamePatterns.size();
|
||||
for (int i = 0; i < methodNamesSize; i++) {
|
||||
final String pattern = methodNamePatterns.get(i);
|
||||
if (!methodNamesMatch(methodName, pattern)) {
|
||||
continue;
|
||||
@@ -208,7 +209,7 @@ public class TestMethodWithoutAssertionInspection extends BaseInspection {
|
||||
continue;
|
||||
}
|
||||
final PsiClass aClass = method.getContainingClass();
|
||||
if (!ClassUtils.isSubclass(aClass, classNames.get(i))) {
|
||||
if (!InheritanceUtil.isInheritor(aClass, classNames.get(i))) {
|
||||
continue;
|
||||
}
|
||||
containsAssertion = true;
|
||||
|
||||
+6
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,10 @@
|
||||
package com.siyeh.ig.junit;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.TypeUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -62,7 +62,8 @@ public class UnconstructableTestCaseInspection extends BaseInspection {
|
||||
if (aClass instanceof PsiTypeParameter) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "junit.framework.TestCase")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"junit.framework.TestCase")) {
|
||||
return;
|
||||
}
|
||||
final PsiMethod[] constructors = aClass.getConstructors();
|
||||
@@ -81,7 +82,8 @@ public class UnconstructableTestCaseInspection extends BaseInspection {
|
||||
hasNoArgConstructor = true;
|
||||
}
|
||||
if (parametersCount == 1) {
|
||||
final PsiParameter[] parameters = parameterList.getParameters();
|
||||
final PsiParameter[] parameters =
|
||||
parameterList.getParameters();
|
||||
final PsiType type = parameters[0].getType();
|
||||
if (TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_STRING,
|
||||
type)) {
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, 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,12 +18,12 @@ package com.siyeh.ig.naming;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiTypeParameter;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.RenameFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -81,7 +81,7 @@ public class ExceptionNameDoesntEndWithExceptionInspection
|
||||
if (className.endsWith(exception)) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass,
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_EXCEPTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* 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,13 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
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.fixes.RenameFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -123,11 +123,12 @@ public class NonExceptionNameEndsWithExceptionInspection
|
||||
if (!className.endsWith(exception)) {
|
||||
return;
|
||||
}
|
||||
if (ClassUtils.isSubclass(aClass,
|
||||
if (InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_EXCEPTION)) {
|
||||
return;
|
||||
}
|
||||
registerClassError(aClass, className, Boolean.valueOf(isOnTheFly()));
|
||||
registerClassError(aClass, className,
|
||||
Boolean.valueOf(isOnTheFly()));
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,6 @@ public class InnerClassReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
private boolean referencesStaticallyAccessible = true;
|
||||
|
||||
public InnerClassReferenceVisitor(PsiClass innerClass) {
|
||||
super();
|
||||
this.innerClass = innerClass;
|
||||
}
|
||||
|
||||
@@ -42,14 +41,14 @@ public class InnerClassReferenceVisitor extends JavaRecursiveElementVisitor {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (InheritanceUtil.isCorrectDescendant(innerClass, aClass, true)) {
|
||||
if (InheritanceUtil.isInheritorOrSelf(innerClass, aClass, true)) {
|
||||
return true;
|
||||
}
|
||||
PsiClass classScope = aClass;
|
||||
final PsiClass outerClass =
|
||||
ClassUtils.getContainingClass(innerClass);
|
||||
while (classScope != null) {
|
||||
if (InheritanceUtil.isCorrectDescendant(outerClass, classScope,
|
||||
if (InheritanceUtil.isInheritorOrSelf(outerClass, classScope,
|
||||
true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
+7
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2010 Bas Leijdekkers
|
||||
* Copyright 2006-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,12 +19,16 @@ import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
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.*;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import com.siyeh.ig.psiutils.ParenthesesUtils;
|
||||
import com.siyeh.ig.psiutils.SideEffectChecker;
|
||||
import com.siyeh.ig.psiutils.VariableAccessUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -563,7 +567,7 @@ public class ManualArrayToCollectionCopyInspection extends BaseInspection {
|
||||
return false;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
return ClassUtils.isSubclass(containingClass,
|
||||
return InheritanceUtil.isInheritor(containingClass,
|
||||
CommonClassNames.JAVA_UTIL_COLLECTION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2005 Dave Griffith
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,6 @@ class MethodReferenceVisitor extends JavaRecursiveElementVisitor{
|
||||
private final PsiMember m_method;
|
||||
|
||||
MethodReferenceVisitor(PsiMember method){
|
||||
super();
|
||||
m_method = method;
|
||||
}
|
||||
|
||||
@@ -40,7 +39,8 @@ class MethodReferenceVisitor extends JavaRecursiveElementVisitor{
|
||||
super.visitElement(element);
|
||||
}
|
||||
|
||||
@Override public void visitReferenceElement(PsiJavaCodeReferenceElement reference){
|
||||
@Override public void visitReferenceElement(
|
||||
PsiJavaCodeReferenceElement reference){
|
||||
super.visitReferenceElement(reference);
|
||||
final PsiElement resolvedElement = reference.resolve();
|
||||
if(!(resolvedElement instanceof PsiClass)){
|
||||
@@ -77,7 +77,8 @@ class MethodReferenceVisitor extends JavaRecursiveElementVisitor{
|
||||
m_referencesStaticallyAccessible = false;
|
||||
}
|
||||
|
||||
@Override public void visitThisExpression(@NotNull PsiThisExpression expression){
|
||||
@Override public void visitThisExpression(
|
||||
@NotNull PsiThisExpression expression){
|
||||
super.visitThisExpression(expression);
|
||||
m_referencesStaticallyAccessible = false;
|
||||
}
|
||||
@@ -91,7 +92,7 @@ class MethodReferenceVisitor extends JavaRecursiveElementVisitor{
|
||||
}
|
||||
final PsiClass referenceContainingClass = m_method.getContainingClass();
|
||||
final PsiClass containingClass = member.getContainingClass();
|
||||
return !InheritanceUtil.isCorrectDescendant(referenceContainingClass,
|
||||
return !InheritanceUtil.isInheritorOrSelf(referenceContainingClass,
|
||||
containingClass, true);
|
||||
}
|
||||
}
|
||||
|
||||
+13
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -33,17 +33,20 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TailRecursionInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message("tail.recursion.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"tail.recursion.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
final PsiMethod containingMethod = (PsiMethod) infos[0];
|
||||
@@ -74,6 +77,7 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
"tail.recursion.replace.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement tailCallToken = descriptor.getPsiElement();
|
||||
@@ -87,9 +91,12 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
if (body == null) {
|
||||
return;
|
||||
}
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
@NonNls final StringBuilder builder = new StringBuilder();
|
||||
builder.append('{');
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
final String thisVariableName;
|
||||
final JavaCodeStyleManager styleManager =
|
||||
JavaCodeStyleManager.getInstance(project);
|
||||
@@ -121,9 +128,8 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
tailCallIsContainedInLoop = false;
|
||||
}
|
||||
builder.append("while(true)");
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final CodeStyleManager codeStyleManager =
|
||||
psiManager.getCodeStyleManager();
|
||||
CodeStyleManager.getInstance(project);
|
||||
replaceTailCalls(body, method, thisVariableName,
|
||||
tailCallIsContainedInLoop, builder);
|
||||
builder.append('}');
|
||||
@@ -222,13 +228,8 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
out.append('.');
|
||||
}
|
||||
out.append(text);
|
||||
} else if (element instanceof PsiThisExpression) {
|
||||
if (thisVariableName == null) {
|
||||
out.append(text);
|
||||
} else {
|
||||
out.append(thisVariableName);
|
||||
}
|
||||
} else if (element instanceof PsiSuperExpression) {
|
||||
} else if (element instanceof PsiThisExpression ||
|
||||
element instanceof PsiSuperExpression) {
|
||||
if (thisVariableName == null) {
|
||||
out.append(text);
|
||||
} else {
|
||||
@@ -358,6 +359,7 @@ public class TailRecursionInspection extends BaseInspection {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new TailRecursionVisitor();
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007-2010 Bas Leijdekkers
|
||||
* Copyright 2007-2011 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,12 +18,12 @@ package com.siyeh.ig.performance;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
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.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.CollectionUtils;
|
||||
import com.siyeh.ig.psiutils.ExpressionUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
@@ -135,7 +135,7 @@ public class ToArrayCallWithZeroLengthArrayArgumentInspection
|
||||
final PsiType componentType = type.getComponentType();
|
||||
final String typeText = componentType.getCanonicalText();
|
||||
@NonNls final String replacementText =
|
||||
"new " + typeText + "[" + qualifierText + ".size()]";
|
||||
"new " + typeText + '[' + qualifierText + ".size()]";
|
||||
return getElementText(expression, referenceExpression,
|
||||
replacementText);
|
||||
}
|
||||
@@ -191,7 +191,7 @@ public class ToArrayCallWithZeroLengthArrayArgumentInspection
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (!ClassUtils.isSubclass(containingClass,
|
||||
if (!InheritanceUtil.isInheritor(containingClass,
|
||||
CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+9
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,32 +16,35 @@
|
||||
package com.siyeh.ig.portability;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UseOfAWTPeerClassInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"use.of.awt.peer.class.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"use.of.awt.peer.class.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new UseOfAWTPeerClassVisitor();
|
||||
}
|
||||
|
||||
private static class UseOfAWTPeerClassVisitor extends BaseInspectionVisitor {
|
||||
|
||||
private static class UseOfAWTPeerClassVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override public void visitVariable(@NotNull PsiVariable variable) {
|
||||
super.visitVariable(variable);
|
||||
@@ -65,7 +68,7 @@ public class UseOfAWTPeerClassInspection extends BaseInspection {
|
||||
if(resolveClass instanceof PsiTypeParameter){
|
||||
return;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(resolveClass,
|
||||
if(!InheritanceUtil.isInheritor(resolveClass,
|
||||
"java.awt.peer.ComponentPeer")) {
|
||||
return;
|
||||
}
|
||||
@@ -97,7 +100,7 @@ public class UseOfAWTPeerClassInspection extends BaseInspection {
|
||||
if(resolveClass instanceof PsiTypeParameter) {
|
||||
return;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(resolveClass,
|
||||
if(!InheritanceUtil.isInheritor(resolveClass,
|
||||
"java.awt.peer.ComponentPeer")) {
|
||||
return;
|
||||
}
|
||||
|
||||
+7
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,26 +16,29 @@
|
||||
package com.siyeh.ig.portability;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UseOfJDBCDriverClassInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"use.of.concrete.jdbc.driver.class.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"use.of.concrete.jdbc.driver.class.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new UseOfJDBCDriverClassVisitor();
|
||||
}
|
||||
@@ -65,7 +68,7 @@ public class UseOfJDBCDriverClassInspection extends BaseInspection {
|
||||
if(resolveClass instanceof PsiTypeParameter){
|
||||
return;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(resolveClass, "java.sql.Driver")) {
|
||||
if(!InheritanceUtil.isInheritor(resolveClass, "java.sql.Driver")) {
|
||||
return;
|
||||
}
|
||||
final PsiTypeElement typeElement = variable.getTypeElement();
|
||||
@@ -96,7 +99,7 @@ public class UseOfJDBCDriverClassInspection extends BaseInspection {
|
||||
if(resolveClass instanceof PsiTypeParameter){
|
||||
return;
|
||||
}
|
||||
if(!ClassUtils.isSubclass(resolveClass, "java.sql.Driver")) {
|
||||
if(!InheritanceUtil.isInheritor(resolveClass, "java.sql.Driver")) {
|
||||
return;
|
||||
}
|
||||
registerNewExpressionError(newExpression);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,15 +15,11 @@
|
||||
*/
|
||||
package com.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.TypeConversionUtil;
|
||||
import com.intellij.util.Query;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashSet;
|
||||
@@ -81,19 +77,6 @@ public class ClassUtils {
|
||||
private ClassUtils() {
|
||||
}
|
||||
|
||||
public static boolean isSubclass(@Nullable PsiClass aClass,
|
||||
@NonNls String ancestorName) {
|
||||
if (aClass == null) {
|
||||
return false;
|
||||
}
|
||||
final PsiManager psiManager = aClass.getManager();
|
||||
final Project project = psiManager.getProject();
|
||||
final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
|
||||
final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(project);
|
||||
final PsiClass ancestorClass = psiFacade.findClass(ancestorName, scope);
|
||||
return InheritanceUtil.isCorrectDescendant(aClass, ancestorClass, true);
|
||||
}
|
||||
|
||||
public static boolean isPrimitive(PsiType type) {
|
||||
return TypeConversionUtil.isPrimitiveAndNotNull(type);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,18 +16,17 @@
|
||||
package com.siyeh.ig.psiutils;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiUtil;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CloneUtils{
|
||||
|
||||
private CloneUtils(){
|
||||
super();
|
||||
}
|
||||
private CloneUtils(){}
|
||||
|
||||
public static boolean isCloneable(@NotNull PsiClass aClass){
|
||||
return ClassUtils.isSubclass(aClass,
|
||||
return InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_CLONEABLE);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,10 +30,9 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ImportUtils{
|
||||
public class ImportUtils {
|
||||
|
||||
private ImportUtils(){
|
||||
}
|
||||
private ImportUtils() {}
|
||||
|
||||
public static void addImportIfNeeded(PsiJavaFile file, PsiClass aClass) {
|
||||
final PsiFile containingFile = aClass.getContainingFile();
|
||||
@@ -78,7 +77,7 @@ public class ImportUtils{
|
||||
if (containingClass == null) {
|
||||
return false;
|
||||
}
|
||||
if (ClassUtils.isSubclass(containingClass, fqName)) {
|
||||
if (InheritanceUtil.isInheritor(containingClass, fqName)) {
|
||||
return true;
|
||||
}
|
||||
final PsiField field =
|
||||
@@ -424,7 +423,7 @@ public class ImportUtils{
|
||||
throws IncorrectOperationException {
|
||||
final PsiClass containingClass =
|
||||
PsiTreeUtil.getParentOfType(context, PsiClass.class);
|
||||
if (ClassUtils.isSubclass(containingClass, qualifierClass)) {
|
||||
if (InheritanceUtil.isInheritor(containingClass, qualifierClass)) {
|
||||
return;
|
||||
}
|
||||
final PsiFile psiFile = context.getContainingFile();
|
||||
@@ -524,7 +523,7 @@ public class ImportUtils{
|
||||
}
|
||||
final PsiClass containingClass =
|
||||
PsiTreeUtil.getParentOfType(context, PsiClass.class);
|
||||
if (InheritanceUtil.isCorrectDescendant(containingClass, memberClass,
|
||||
if (InheritanceUtil.isInheritorOrSelf(containingClass, memberClass,
|
||||
true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2006 Bas Leijdekkers
|
||||
* Copyright 2003-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -55,10 +55,6 @@ public class IteratorUtils {
|
||||
CommonClassNames.JAVA_UTIL_ITERATOR, PsiType.BOOLEAN, "hasNext");
|
||||
}
|
||||
|
||||
public static boolean isIterator(PsiClass aClass) {
|
||||
return ClassUtils.isSubclass(aClass, CommonClassNames.JAVA_UTIL_ITERATOR);
|
||||
}
|
||||
|
||||
private static class CallsIteratorNextVisitor
|
||||
extends JavaRecursiveElementVisitor {
|
||||
|
||||
@@ -91,7 +87,8 @@ public class IteratorUtils {
|
||||
super.visitMethodCallExpression(expression);
|
||||
if (checkScanner) {
|
||||
if (!MethodCallUtils.isCallToMethod(expression,
|
||||
CommonClassNames.JAVA_UTIL_ITERATOR, null, SCANNER_PATTERN)) {
|
||||
CommonClassNames.JAVA_UTIL_ITERATOR, null,
|
||||
SCANNER_PATTERN)) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@@ -119,7 +116,7 @@ public class IteratorUtils {
|
||||
final PsiReferenceExpression referenceExpression =
|
||||
(PsiReferenceExpression) qualifier;
|
||||
final PsiElement element = referenceExpression.resolve();
|
||||
if (target != element) {
|
||||
if (!target.equals(element)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
* Copyright 2000-2011 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.
|
||||
@@ -130,7 +130,8 @@ public class MethodUtils{
|
||||
}
|
||||
if (containingClassName != null) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
return ClassUtils.isSubclass(containingClass, containingClassName);
|
||||
return InheritanceUtil.isInheritor(containingClass,
|
||||
containingClassName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -186,7 +187,8 @@ public class MethodUtils{
|
||||
}
|
||||
if (containingClassName != null) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
return ClassUtils.isSubclass(containingClass, containingClassName);
|
||||
return InheritanceUtil.isInheritor(containingClass,
|
||||
containingClassName);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -335,7 +337,7 @@ public class MethodUtils{
|
||||
}
|
||||
final PsiClass fieldContainingClass = field.getContainingClass();
|
||||
final PsiClass methodContainingClass = method.getContainingClass();
|
||||
if (InheritanceUtil.isCorrectDescendant(methodContainingClass,
|
||||
if (InheritanceUtil.isInheritorOrSelf(methodContainingClass,
|
||||
fieldContainingClass, true)) {
|
||||
return field;
|
||||
} else {
|
||||
@@ -408,7 +410,7 @@ public class MethodUtils{
|
||||
final PsiField field = (PsiField) referent;
|
||||
final PsiClass fieldContainingClass = field.getContainingClass();
|
||||
final PsiClass methodContainingClass = method.getContainingClass();
|
||||
if(!InheritanceUtil.isCorrectDescendant(methodContainingClass,
|
||||
if(!InheritanceUtil.isInheritorOrSelf(methodContainingClass,
|
||||
fieldContainingClass, true)){
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.siyeh.ig.psiutils;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
@@ -26,12 +27,12 @@ public class SerializationUtils {
|
||||
private SerializationUtils() {}
|
||||
|
||||
public static boolean isSerializable(@Nullable PsiClass aClass) {
|
||||
return ClassUtils.isSubclass(aClass,
|
||||
return InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_IO_SERIALIZABLE);
|
||||
}
|
||||
|
||||
public static boolean isExternalizable(@Nullable PsiClass aClass) {
|
||||
return ClassUtils.isSubclass(aClass,
|
||||
return InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_IO_EXTERNALIZABLE);
|
||||
}
|
||||
|
||||
@@ -56,7 +57,8 @@ public class SerializationUtils {
|
||||
}
|
||||
|
||||
public static boolean hasReadObject(@NotNull PsiClass aClass) {
|
||||
final PsiMethod[] methods = aClass.findMethodsByName("readObject", false);
|
||||
final PsiMethod[] methods =
|
||||
aClass.findMethodsByName("readObject", false);
|
||||
for (final PsiMethod method : methods) {
|
||||
if (isReadObject(method)) {
|
||||
return true;
|
||||
@@ -130,9 +132,9 @@ public class SerializationUtils {
|
||||
if (isExternalizable(psiClass)) {
|
||||
return true;
|
||||
}
|
||||
if (ClassUtils.isSubclass(psiClass,
|
||||
if (InheritanceUtil.isInheritor(psiClass,
|
||||
CommonClassNames.JAVA_UTIL_COLLECTION) ||
|
||||
ClassUtils.isSubclass(psiClass,
|
||||
InheritanceUtil.isInheritor(psiClass,
|
||||
CommonClassNames.JAVA_UTIL_MAP)) {
|
||||
final PsiType[] parameters = classTYpe.getParameters();
|
||||
for (PsiType parameter : parameters) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,16 +21,15 @@ import com.intellij.openapi.roots.ProjectFileIndex;
|
||||
import com.intellij.openapi.roots.ProjectRootManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class TestUtils {
|
||||
|
||||
private TestUtils() {
|
||||
super();
|
||||
}
|
||||
private TestUtils() {}
|
||||
|
||||
public static boolean isTest(@Nullable PsiClass aClass) {
|
||||
if (aClass == null) {
|
||||
@@ -104,6 +103,7 @@ public class TestUtils {
|
||||
|
||||
public static boolean isJUnitTestClass(@Nullable PsiClass targetClass){
|
||||
return targetClass != null &&
|
||||
ClassUtils.isSubclass(targetClass, "junit.framework.TestCase");
|
||||
InheritanceUtil.isInheritor(targetClass,
|
||||
"junit.framework.TestCase");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, 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,6 +18,8 @@ package com.siyeh.ig.psiutils;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -29,7 +31,8 @@ public class TypeUtils {
|
||||
private TypeUtils() {}
|
||||
|
||||
public static boolean expressionHasType(
|
||||
@Nullable PsiExpression expression, @NonNls @NotNull String typeName) {
|
||||
@Nullable PsiExpression expression,
|
||||
@NonNls @NotNull String typeName) {
|
||||
if (expression == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -79,7 +82,7 @@ public class TypeUtils {
|
||||
}
|
||||
final PsiClassType classType = (PsiClassType) type;
|
||||
final PsiClass aClass = classType.resolve();
|
||||
return aClass != null && ClassUtils.isSubclass(aClass, typeName);
|
||||
return aClass != null && InheritanceUtil.isInheritor(aClass, typeName);
|
||||
}
|
||||
|
||||
//getTypeIfOneOfOrSubtype
|
||||
@@ -102,7 +105,7 @@ public class TypeUtils {
|
||||
return null;
|
||||
}
|
||||
for (String typeName : typeNames) {
|
||||
if (ClassUtils.isSubclass(aClass, typeName)) {
|
||||
if (InheritanceUtil.isInheritor(aClass, typeName)) {
|
||||
return typeName;
|
||||
}
|
||||
}
|
||||
@@ -128,7 +131,7 @@ public class TypeUtils {
|
||||
return false;
|
||||
}
|
||||
for (String typeName : typeNames) {
|
||||
if (ClassUtils.isSubclass(aClass, typeName)) {
|
||||
if (InheritanceUtil.isInheritor(aClass, typeName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2008-2010 Bas Leijdekkers
|
||||
* Copyright 2008-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -305,9 +305,9 @@ public class WeakestTypeFinder {
|
||||
HardcodedMethodConstants.INDEX_OF.equals(methodName) ||
|
||||
HardcodedMethodConstants.LAST_INDEX_OF.equals(methodName)) {
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (ClassUtils.isSubclass(containingClass,
|
||||
if (InheritanceUtil.isInheritor(containingClass,
|
||||
CommonClassNames.JAVA_UTIL_MAP) ||
|
||||
ClassUtils.isSubclass(containingClass,
|
||||
InheritanceUtil.isInheritor(containingClass,
|
||||
CommonClassNames.JAVA_UTIL_COLLECTION)) {
|
||||
final PsiReferenceExpression methodExpression =
|
||||
methodCallExpression.getMethodExpression();
|
||||
@@ -521,9 +521,9 @@ public class WeakestTypeFinder {
|
||||
if (aClass == null) {
|
||||
return true;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass,
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_RUNTIME_EXCEPTION) &&
|
||||
!ClassUtils.isSubclass(aClass,
|
||||
!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_LANG_ERROR)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+8
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,34 +16,38 @@
|
||||
package com.siyeh.ig.security;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CustomClassloaderInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"custom.classloader.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"custom.classloader.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new CustomClassloaderVisitor();
|
||||
}
|
||||
|
||||
private static class CustomClassloaderVisitor extends BaseInspectionVisitor {
|
||||
private static class CustomClassloaderVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override public void visitClass(@NotNull PsiClass aClass) {
|
||||
if (!ClassUtils.isSubclass(aClass, "java.lang.ClassLoader")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass, "java.lang.ClassLoader")) {
|
||||
return;
|
||||
}
|
||||
if ("java.lang.ClassLoader".equals(aClass.getQualifiedName())) {
|
||||
|
||||
+7
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,26 +16,29 @@
|
||||
package com.siyeh.ig.security;
|
||||
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class CustomSecurityManagerInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"custom.security.manager.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"custom.security.manager.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new CustomSecurityManagerVisitor();
|
||||
}
|
||||
@@ -44,7 +47,8 @@ public class CustomSecurityManagerInspection extends BaseInspection {
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override public void visitClass(@NotNull PsiClass aClass) {
|
||||
if (!ClassUtils.isSubclass(aClass, "java.lang.SecurityManager")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
"java.lang.SecurityManager")) {
|
||||
return;
|
||||
}
|
||||
if ("java.lang.SecurityManager".equals(aClass.getQualifiedName())) {
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,10 @@ package com.siyeh.ig.security;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.ConstantExpressionUtil;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class JDBCExecuteWithNonConstantStringInspection
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "java.sql.Statement")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass, "java.sql.Statement")) {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,10 @@ package com.siyeh.ig.security;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.ConstantExpressionUtil;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -80,7 +80,7 @@ public class JDBCPrepareStatementWithNonConstantStringInspection
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "java.sql.Connection")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass, "java.sql.Connection")) {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,10 +17,10 @@ package com.siyeh.ig.security;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.ConstantExpressionUtil;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -66,7 +66,7 @@ public class LoadLibraryWithNonConstantStringInspection
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "java.lang.System")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass, "java.lang.System")) {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
|
||||
+8
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,22 +16,24 @@
|
||||
package com.siyeh.ig.security;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class UnsecureRandomNumberGenerationInspection
|
||||
extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"unsecure.random.number.generation.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
@NonNls final String text = ((PsiElement)infos[0]).getText();
|
||||
@@ -47,6 +49,7 @@ public class UnsecureRandomNumberGenerationInspection
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new InsecureRandomNumberGenerationVisitor();
|
||||
}
|
||||
@@ -54,7 +57,8 @@ public class UnsecureRandomNumberGenerationInspection
|
||||
private static class InsecureRandomNumberGenerationVisitor
|
||||
extends BaseInspectionVisitor {
|
||||
|
||||
@Override public void visitNewExpression(@NotNull PsiNewExpression expression) {
|
||||
@Override public void visitNewExpression(
|
||||
@NotNull PsiNewExpression expression) {
|
||||
super.visitNewExpression(expression);
|
||||
final PsiJavaCodeReferenceElement reference =
|
||||
expression.getClassReference();
|
||||
@@ -66,7 +70,7 @@ public class UnsecureRandomNumberGenerationInspection
|
||||
return;
|
||||
}
|
||||
final PsiClass aClass = (PsiClass) element;
|
||||
if (!ClassUtils.isSubclass(aClass, "java.util.Random")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass, "java.util.Random")) {
|
||||
return;
|
||||
}
|
||||
final String qualifiedName = aClass.getQualifiedName();
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2006-2011 Dave Griffith, 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,12 +18,12 @@ package com.siyeh.ig.serialization;
|
||||
import com.intellij.psi.CommonClassNames;
|
||||
import com.intellij.psi.PsiAnonymousClass;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.MakeSerializableFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.SerializationUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -63,7 +63,7 @@ public class ComparatorNotSerializableInspection extends BaseInspection {
|
||||
if (aClass instanceof PsiAnonymousClass) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass,
|
||||
if (!InheritanceUtil.isInheritor(aClass,
|
||||
CommonClassNames.JAVA_UTIL_COMPARATOR)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+8
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2007 Bas Leijdekkers
|
||||
* Copyright 2007-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -15,22 +15,20 @@
|
||||
*/
|
||||
package com.siyeh.ig.serialization;
|
||||
|
||||
import com.intellij.codeInspection.ui.AddAction;
|
||||
import com.intellij.codeInspection.ui.ListTable;
|
||||
import com.intellij.codeInspection.ui.ListWrappingTableModel;
|
||||
import com.intellij.codeInspection.ui.RemoveAction;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.siyeh.ig.psiutils.SerializationUtils;
|
||||
import com.intellij.codeInspection.ui.AddAction;
|
||||
import org.jdom.Element;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -44,16 +42,19 @@ public abstract class SerializableInspection extends BaseInspection {
|
||||
parseString(superClassString, superClassList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
final Form form = new Form();
|
||||
return form.getContentPanel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readSettings(Element node) throws InvalidDataException {
|
||||
super.readSettings(node);
|
||||
parseString(superClassString, superClassList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSettings(Element node) throws WriteExternalException {
|
||||
superClassString = formatString(superClassList);
|
||||
super.writeSettings(node);
|
||||
@@ -64,7 +65,7 @@ public abstract class SerializableInspection extends BaseInspection {
|
||||
return false;
|
||||
}
|
||||
for (String superClassName : superClassList) {
|
||||
if (ClassUtils.isSubclass(aClass, superClassName)) {
|
||||
if (InheritanceUtil.isInheritor(aClass, superClassName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2010 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -81,9 +81,8 @@ public class ImplicitCallToSuperInspection extends BaseInspection {
|
||||
JavaPsiFacade.getElementFactory(project);
|
||||
final PsiStatement newStatement =
|
||||
factory.createStatementFromText("super();", null);
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final CodeStyleManager styleManager =
|
||||
psiManager.getCodeStyleManager();
|
||||
CodeStyleManager.getInstance(project);
|
||||
if (body == null) {
|
||||
return;
|
||||
}
|
||||
@@ -116,7 +115,8 @@ public class ImplicitCallToSuperInspection extends BaseInspection {
|
||||
final PsiClass superClass = containingClass.getSuperClass();
|
||||
if (superClass != null) {
|
||||
final String superClassName = superClass.getQualifiedName();
|
||||
if (CommonClassNames.JAVA_LANG_OBJECT.equals(superClassName)) {
|
||||
if (CommonClassNames.JAVA_LANG_OBJECT.equals(
|
||||
superClassName)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
+10
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, 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,37 +18,42 @@ package com.siyeh.ig.threading;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
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.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ConditionSignalInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "CallToSignalInsteadOfSignalAll";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message("condition.signal.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"condition.signal.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new ConditionSignalVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new ConditionSignalFix();
|
||||
}
|
||||
@@ -61,6 +66,7 @@ public class ConditionSignalInspection extends BaseInspection {
|
||||
"condition.signal.replace.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement methodNameElement = descriptor.getPsiElement();
|
||||
@@ -105,9 +111,8 @@ public class ConditionSignalInspection extends BaseInspection {
|
||||
if (containingClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils
|
||||
.isSubclass(containingClass,
|
||||
"java.util.concurrent.locks.Condition")) {
|
||||
if (!InheritanceUtil.isInheritor(containingClass,
|
||||
"java.util.concurrent.locks.Condition")) {
|
||||
return;
|
||||
}
|
||||
registerMethodCallError(expression);
|
||||
|
||||
+9
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,28 +16,31 @@
|
||||
package com.siyeh.ig.threading;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SleepWhileHoldingLockInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"sleep.while.holding.lock.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"sleep.while.holding.lock.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new SleepWhileHoldingLockVisitor();
|
||||
}
|
||||
@@ -50,7 +53,8 @@ public class SleepWhileHoldingLockInspection extends BaseInspection {
|
||||
super.visitMethodCallExpression(expression);
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
@NonNls final String methodName = methodExpression.getReferenceName();
|
||||
@NonNls final String methodName =
|
||||
methodExpression.getReferenceName();
|
||||
if (!"sleep".equals(methodName)) {
|
||||
return;
|
||||
}
|
||||
@@ -76,7 +80,8 @@ public class SleepWhileHoldingLockInspection extends BaseInspection {
|
||||
}
|
||||
final PsiClass methodClass = method.getContainingClass();
|
||||
if (methodClass == null ||
|
||||
!ClassUtils.isSubclass(methodClass, "java.lang.Thread")) {
|
||||
!InheritanceUtil.isInheritor(methodClass,
|
||||
"java.lang.Thread")) {
|
||||
return;
|
||||
}
|
||||
registerMethodCallError(expression);
|
||||
|
||||
+10
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2008 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,12 +36,14 @@ public class SynchronizedMethodInspection extends BaseInspection {
|
||||
public boolean m_includeNativeMethods = true;
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"synchronized.method.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
final PsiMethod method = (PsiMethod)infos[0];
|
||||
@@ -49,6 +51,7 @@ public class SynchronizedMethodInspection extends BaseInspection {
|
||||
"synchronized.method.problem.descriptor", method.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InspectionGadgetsFix buildFix(Object... infos) {
|
||||
final PsiMethod method = (PsiMethod)infos[0];
|
||||
if (method.getBody() == null) {
|
||||
@@ -57,10 +60,12 @@ public class SynchronizedMethodInspection extends BaseInspection {
|
||||
return new SynchronizedMethodFix();
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new SynchronizedMethodVisitor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent createOptionsPanel() {
|
||||
return new SingleCheckboxOptionsPanel(InspectionGadgetsBundle.message(
|
||||
"synchronized.method.include.option"),
|
||||
@@ -75,6 +80,7 @@ public class SynchronizedMethodInspection extends BaseInspection {
|
||||
"synchronized.method.move.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement nameElement = descriptor.getPsiElement();
|
||||
@@ -100,14 +106,14 @@ public class SynchronizedMethodInspection extends BaseInspection {
|
||||
replacementText = "{ synchronized(this){" + text.substring(1) +
|
||||
'}';
|
||||
}
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
final PsiElementFactory elementFactory = JavaPsiFacade.getInstance(psiManager.getProject()).getElementFactory();
|
||||
final PsiElementFactory elementFactory =
|
||||
JavaPsiFacade.getElementFactory(project);
|
||||
final PsiCodeBlock block =
|
||||
elementFactory.createCodeBlockFromText(replacementText,
|
||||
null);
|
||||
body.replace(block);
|
||||
final CodeStyleManager codeStyleManager =
|
||||
psiManager.getCodeStyleManager();
|
||||
CodeStyleManager.getInstance(project);
|
||||
codeStyleManager.reformat(method);
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2009 Bas Leijdekkers
|
||||
* Copyright 2009-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,11 +16,12 @@
|
||||
package com.siyeh.ig.threading;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.InspectionGadgetsBundle;import com.siyeh.ig.BaseInspection;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.fixes.MakeFieldStaticFinalFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -66,7 +67,7 @@ public class ThreadLocalNotStaticFinalInspection extends BaseInspection {
|
||||
if (aClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(aClass, "java.lang.ThreadLocal")) {
|
||||
if (!InheritanceUtil.isInheritor(aClass, "java.lang.ThreadLocal")) {
|
||||
return;
|
||||
}
|
||||
final PsiModifierList modifierList = field.getModifierList();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, 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,6 +18,7 @@ package com.siyeh.ig.threading;
|
||||
import com.intellij.codeInspection.ProblemDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.siyeh.HardcodedMethodConstants;
|
||||
@@ -25,26 +26,29 @@ import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
import com.siyeh.ig.InspectionGadgetsFix;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ThreadRunInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message("thread.run.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "CallToThreadRun";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message("thread.run.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public InspectionGadgetsFix buildFix(Object... infos) {
|
||||
return new ThreadRunFix();
|
||||
}
|
||||
@@ -57,6 +61,7 @@ public class ThreadRunInspection extends BaseInspection {
|
||||
"thread.run.replace.quickfix");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFix(@NotNull Project project, ProblemDescriptor descriptor)
|
||||
throws IncorrectOperationException {
|
||||
final PsiElement methodNameIdentifier = descriptor.getPsiElement();
|
||||
@@ -101,7 +106,7 @@ public class ThreadRunInspection extends BaseInspection {
|
||||
if (methodClass == null) {
|
||||
return;
|
||||
}
|
||||
if (!ClassUtils.isSubclass(methodClass, "java.lang.Thread")) {
|
||||
if (!InheritanceUtil.isInheritor(methodClass, "java.lang.Thread")) {
|
||||
return;
|
||||
}
|
||||
if (isInsideThreadRun(expression)) {
|
||||
@@ -125,7 +130,7 @@ public class ThreadRunInspection extends BaseInspection {
|
||||
if (methodClass == null) {
|
||||
return false;
|
||||
}
|
||||
return ClassUtils.isSubclass(methodClass, "java.lang.Thread");
|
||||
return InheritanceUtil.isInheritor(methodClass, "java.lang.Thread");
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.siyeh.ig.threading;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.BaseInspection;
|
||||
import com.siyeh.ig.BaseInspectionVisitor;
|
||||
@@ -25,23 +26,27 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class ThreadStartInConstructionInspection extends BaseInspection {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getID() {
|
||||
return "CallToThreadStartDuringObjectConstruction";
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getDisplayName() {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"thread.start.in.construction.display.name");
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String buildErrorString(Object... infos) {
|
||||
return InspectionGadgetsBundle.message(
|
||||
"thread.start.in.construction.problem.descriptor");
|
||||
}
|
||||
|
||||
@Override
|
||||
public BaseInspectionVisitor buildVisitor() {
|
||||
return new ThreadStartInConstructionVisitor();
|
||||
}
|
||||
@@ -83,13 +88,14 @@ public class ThreadStartInConstructionInspection extends BaseInspection {
|
||||
if (method == null) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
final PsiParameterList parameterList =
|
||||
method.getParameterList();
|
||||
if (parameterList.getParametersCount() != 0) {
|
||||
return;
|
||||
}
|
||||
final PsiClass methodClass = method.getContainingClass();
|
||||
if (methodClass == null ||
|
||||
!ClassUtils.isSubclass(methodClass,
|
||||
!InheritanceUtil.isInheritor(methodClass,
|
||||
"java.lang.Thread")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2003-2007 Dave Griffith, Bas Leijdekkers
|
||||
* Copyright 2003-2011 Dave Griffith, Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,20 +16,19 @@
|
||||
package com.siyeh.ig.threading;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class ThreadingUtils {
|
||||
|
||||
private ThreadingUtils() {
|
||||
super();
|
||||
}
|
||||
private ThreadingUtils() {}
|
||||
|
||||
public static boolean isWaitCall(
|
||||
@NotNull PsiMethodCallExpression expression) {
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
@NonNls final String methodName = methodExpression.getReferenceName();
|
||||
if (!"wait".equals(methodName)) {
|
||||
return false;
|
||||
}
|
||||
@@ -62,7 +61,7 @@ class ThreadingUtils {
|
||||
@NotNull PsiMethodCallExpression expression) {
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
@NonNls final String methodName = methodExpression.getReferenceName();
|
||||
if (!"notify".equals(methodName) && !"notifyAll".equals(methodName)) {
|
||||
return false;
|
||||
}
|
||||
@@ -75,7 +74,7 @@ class ThreadingUtils {
|
||||
@NotNull PsiMethodCallExpression expression) {
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
@NonNls final String methodName = methodExpression.getReferenceName();
|
||||
if (!"signal".equals(methodName) && !"signalAll".equals(methodName)) {
|
||||
return false;
|
||||
}
|
||||
@@ -92,15 +91,15 @@ class ThreadingUtils {
|
||||
if (containingClass == null) {
|
||||
return false;
|
||||
}
|
||||
return ClassUtils.isSubclass(containingClass,
|
||||
"java.util.concurrent.locks.Condition");
|
||||
return InheritanceUtil.isInheritor(containingClass,
|
||||
"java.util.concurrent.locks.Condition");
|
||||
}
|
||||
|
||||
public static boolean isAwaitCall(
|
||||
@NotNull PsiMethodCallExpression expression) {
|
||||
final PsiReferenceExpression methodExpression =
|
||||
expression.getMethodExpression();
|
||||
final String methodName = methodExpression.getReferenceName();
|
||||
@NonNls final String methodName = methodExpression.getReferenceName();
|
||||
if (!"await".equals(methodName)
|
||||
&& !"awaitUntil".equals(methodName)
|
||||
&& !"awaitUninterruptibly".equals(methodName)
|
||||
@@ -115,7 +114,7 @@ class ThreadingUtils {
|
||||
if (containingClass == null) {
|
||||
return false;
|
||||
}
|
||||
return ClassUtils.isSubclass(containingClass,
|
||||
"java.util.concurrent.locks.Condition");
|
||||
return InheritanceUtil.isInheritor(containingClass,
|
||||
"java.util.concurrent.locks.Condition");
|
||||
}
|
||||
}
|
||||
@@ -1,109 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.siyeh.ig.ui;
|
||||
|
||||
import com.intellij.codeInspection.ui.ListTable;
|
||||
import com.intellij.codeInspection.ui.ListWrappingTableModel;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.util.ClassFilter;
|
||||
import com.intellij.ide.util.TreeClassChooser;
|
||||
import com.intellij.ide.util.TreeClassChooserFactory;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.DataKeys;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
public class TreeClassChooserAction extends AbstractAction {
|
||||
|
||||
private final ListTable table;
|
||||
private final String chooserTitle;
|
||||
private final String[] ancestorClasses;
|
||||
|
||||
public TreeClassChooserAction(ListTable table, String chooserTitle,
|
||||
@NonNls String... ancestorClasses) {
|
||||
this.table = table;
|
||||
this.chooserTitle = chooserTitle;
|
||||
this.ancestorClasses = ancestorClasses;
|
||||
putValue(NAME, InspectionGadgetsBundle.message("button.add"));
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final DataManager dataManager = DataManager.getInstance();
|
||||
final Object source = e.getSource();
|
||||
if (!(source instanceof Component)) {
|
||||
return;
|
||||
}
|
||||
final DataContext dataContext =
|
||||
dataManager.getDataContext((Component) source);
|
||||
final Project project = DataKeys.PROJECT.getData(dataContext);
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
final TreeClassChooserFactory chooserFactory =
|
||||
TreeClassChooserFactory.getInstance(project);
|
||||
final ClassFilter filter;
|
||||
if (ancestorClasses.length == 0) {
|
||||
filter = ClassFilter.ALL;
|
||||
} else {
|
||||
filter = new ClassFilter() {
|
||||
public boolean isAccepted(PsiClass aClass) {
|
||||
for (String ancestorClass : ancestorClasses) {
|
||||
if (ClassUtils.isSubclass(aClass, ancestorClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
final TreeClassChooser classChooser =
|
||||
chooserFactory.createWithInnerClassesScopeChooser(chooserTitle,
|
||||
GlobalSearchScope.allScope(project), filter, null);
|
||||
classChooser.showDialog();
|
||||
final PsiClass selectedClass = classChooser.getSelected();
|
||||
if (selectedClass == null) {
|
||||
return;
|
||||
}
|
||||
final String qualifiedName = selectedClass.getQualifiedName();
|
||||
final ListWrappingTableModel tableModel = table.getModel();
|
||||
final int index = tableModel.indexOf(qualifiedName, 0);
|
||||
final int rowIndex;
|
||||
if (index < 0) {
|
||||
tableModel.addRow(qualifiedName);
|
||||
rowIndex = tableModel.getRowCount() - 1;
|
||||
} else {
|
||||
rowIndex = index;
|
||||
}
|
||||
final ListSelectionModel selectionModel =
|
||||
table.getSelectionModel();
|
||||
selectionModel.setSelectionInterval(rowIndex, rowIndex);
|
||||
EventQueue.invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
final Rectangle rectangle =
|
||||
table.getCellRect(rowIndex, 0, true);
|
||||
table.scrollRectToVisible(rectangle);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010 Bas Leijdekkers
|
||||
* Copyright 2010-2011 Bas Leijdekkers
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,9 +24,9 @@ import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.InheritanceUtil;
|
||||
import com.intellij.util.Icons;
|
||||
import com.siyeh.InspectionGadgetsBundle;
|
||||
import com.siyeh.ig.psiutils.ClassUtils;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -251,7 +251,7 @@ public class UiUtils {
|
||||
|
||||
public boolean isAccepted(PsiClass aClass) {
|
||||
for (String ancestorClass : ancestorClasses) {
|
||||
if (ClassUtils.isSubclass(aClass, ancestorClass)) {
|
||||
if (InheritanceUtil.isInheritor(aClass, ancestorClass)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user