mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
common constants
This commit is contained in:
+3
-3
@@ -70,9 +70,9 @@ public class AssertEqualsBetweenInconvertibleTypesInspection extends BaseInspect
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
final boolean junit5Assertions = InheritanceUtil.isInheritor(containingClass, "org.junit.jupiter.api.Assertions");
|
||||
if (!InheritanceUtil.isInheritor(containingClass, "junit.framework.Assert") &&
|
||||
!InheritanceUtil.isInheritor(containingClass, "org.junit.Assert") &&
|
||||
final boolean junit5Assertions = InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS);
|
||||
if (!InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT) &&
|
||||
!InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.ORG_JUNIT_ASSERT) &&
|
||||
!junit5Assertions) {
|
||||
return;
|
||||
}
|
||||
|
||||
+4
-3
@@ -31,6 +31,7 @@ import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class AssertEqualsCalledOnArrayInspection extends BaseInspection {
|
||||
|
||||
@Nls
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -66,7 +67,7 @@ public class AssertEqualsCalledOnArrayInspection extends BaseInspection {
|
||||
}
|
||||
final PsiReferenceExpression methodExpression = (PsiReferenceExpression)parent;
|
||||
final PsiExpression qualifier = methodExpression.getQualifierExpression();
|
||||
if (qualifier == null && ImportUtils.addStaticImport("org.junit.Assert", "assertArrayEquals", methodExpression)) {
|
||||
if (qualifier == null && ImportUtils.addStaticImport(JUnitCommonClassNames.ORG_JUNIT_ASSERT, "assertArrayEquals", methodExpression)) {
|
||||
PsiReplacementUtil.replaceExpression(methodExpression, "assertArrayEquals");
|
||||
}
|
||||
else {
|
||||
@@ -117,8 +118,8 @@ public class AssertEqualsCalledOnArrayInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (!InheritanceUtil.isInheritor(containingClass, "junit.framework.Assert") &&
|
||||
!InheritanceUtil.isInheritor(containingClass, "org.junit.Assert") &&
|
||||
if (!InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT) &&
|
||||
!InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.ORG_JUNIT_ASSERT) &&
|
||||
!InheritanceUtil.isInheritor(containingClass, "org.testng.AssertJUnit")) {
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-1
@@ -119,7 +119,8 @@ public class AssertEqualsMayBeAssertSameInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final String qualifiedName = aClass.getQualifiedName();
|
||||
if (!"org.junit.Assert".equals(qualifiedName) && !"junit.framework.Assert".equals(qualifiedName) &&
|
||||
if (!JUnitCommonClassNames.ORG_JUNIT_ASSERT.equals(qualifiedName) && !JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT
|
||||
.equals(qualifiedName) &&
|
||||
!"junit.framework.TestCase".equals(qualifiedName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
+2
-2
@@ -82,8 +82,8 @@ public class AssertsWithoutMessagesInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (!InheritanceUtil.isInheritor(containingClass, "junit.framework.Assert") &&
|
||||
!InheritanceUtil.isInheritor(containingClass, "org.junit.Assert")) {
|
||||
if (!InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT) &&
|
||||
!InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.ORG_JUNIT_ASSERT)) {
|
||||
return;
|
||||
}
|
||||
final PsiParameterList parameterList = method.getParameterList();
|
||||
|
||||
+2
-2
@@ -79,9 +79,9 @@ public class ConstantJUnitAssertArgumentInspection extends BaseInspection {
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (!InheritanceUtil.isInheritor(containingClass,
|
||||
"junit.framework.Assert") &&
|
||||
JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT) &&
|
||||
!InheritanceUtil.isInheritor(containingClass,
|
||||
"org.junit.Assert")) {
|
||||
JUnitCommonClassNames.ORG_JUNIT_ASSERT)) {
|
||||
return;
|
||||
}
|
||||
final PsiExpressionList argumentList = expression.getArgumentList();
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2000-2016 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.
|
||||
* 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.junit;
|
||||
|
||||
public class JUnitCommonClassNames {
|
||||
public static final String ORG_JUNIT_ASSERT = "org.junit.Assert";
|
||||
public static final String JUNIT_FRAMEWORK_ASSERT = "junit.framework.Assert";
|
||||
public static final String ORG_JUNIT_JUPITER_API_ASSERTIONS = "org.junit.jupiter.api.Assertions";
|
||||
}
|
||||
+4
-4
@@ -91,8 +91,8 @@ public abstract class MisorderedAssertEqualsArgumentsInspectionBase extends Base
|
||||
junit = false;
|
||||
}
|
||||
else if (InheritanceUtil.isInheritor(containingClass, "org.testng.AssertJUnit") ||
|
||||
InheritanceUtil.isInheritor(containingClass, "junit.framework.Assert") ||
|
||||
InheritanceUtil.isInheritor(containingClass, "org.junit.Assert")) {
|
||||
InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT) ||
|
||||
InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.ORG_JUNIT_ASSERT)) {
|
||||
junit = true;
|
||||
}
|
||||
else {
|
||||
@@ -156,8 +156,8 @@ public abstract class MisorderedAssertEqualsArgumentsInspectionBase extends Base
|
||||
final PsiExpression actualArgument;
|
||||
if (checkTestNG() ?
|
||||
InheritanceUtil.isInheritor(containingClass, "org.testng.AssertJUnit") :
|
||||
InheritanceUtil.isInheritor(containingClass, "junit.framework.Assert") ||
|
||||
InheritanceUtil.isInheritor(containingClass, "org.junit.Assert")) {
|
||||
InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT) ||
|
||||
InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.ORG_JUNIT_ASSERT)) {
|
||||
final PsiType firstArgumentType = arguments[0].getType();
|
||||
if (stringType.equals(firstArgumentType) && arguments.length > 2) {
|
||||
expectedArgument = arguments[1];
|
||||
|
||||
+4
-4
@@ -90,8 +90,8 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass containingClass = method.getContainingClass();
|
||||
if (containingClass != null && "org.junit.Assert".equals(containingClass.getQualifiedName()) &&
|
||||
!ImportUtils.addStaticImport("org.junit.Assert", methodName, originalMethodCall)) {
|
||||
if (containingClass != null && JUnitCommonClassNames.ORG_JUNIT_ASSERT.equals(containingClass.getQualifiedName()) &&
|
||||
!ImportUtils.addStaticImport(JUnitCommonClassNames.ORG_JUNIT_ASSERT, methodName, originalMethodCall)) {
|
||||
// add qualifier if old call was to JUnit4 method and adding static import failed
|
||||
out.append("org.junit.Assert.");
|
||||
}
|
||||
@@ -721,7 +721,7 @@ public class SimplifiableJUnitAssertionInspection extends BaseInspection {
|
||||
return false;
|
||||
}
|
||||
final String qualifiedName = targetClass.getQualifiedName();
|
||||
return "junit.framework.Assert".equals(qualifiedName) || "junit.framework.TestCase".equals(qualifiedName) ||
|
||||
"org.junit.Assert".equals(qualifiedName);
|
||||
return JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT.equals(qualifiedName) || "junit.framework.TestCase".equals(qualifiedName) ||
|
||||
JUnitCommonClassNames.ORG_JUNIT_ASSERT.equals(qualifiedName);
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -35,8 +35,8 @@ public class TestMethodWithoutAssertionInspectionBase extends BaseInspection {
|
||||
|
||||
public TestMethodWithoutAssertionInspectionBase() {
|
||||
methodMatcher = new MethodMatcher(true, "assertionMethods")
|
||||
.add("org.junit.Assert", "assert.*|fail.*")
|
||||
.add("junit.framework.Assert", "assert.*|fail.*")
|
||||
.add(JUnitCommonClassNames.ORG_JUNIT_ASSERT, "assert.*|fail.*")
|
||||
.add(JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT, "assert.*|fail.*")
|
||||
.add("org.mockito.Mockito", "verify.*")
|
||||
.add("org.mockito.InOrder", "verify")
|
||||
.add("org.junit.rules.ExpectedException", "expect.*")
|
||||
|
||||
+4
-4
@@ -67,7 +67,7 @@ public class UseOfObsoleteAssertInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass newAssertClass = JavaPsiFacade.getInstance(project)
|
||||
.findClass("org.junit.Assert", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
|
||||
.findClass(JUnitCommonClassNames.ORG_JUNIT_ASSERT, GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(module));
|
||||
if (newAssertClass == null) {
|
||||
return;
|
||||
}
|
||||
@@ -80,7 +80,7 @@ public class UseOfObsoleteAssertInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final String name = containingClass.getQualifiedName();
|
||||
if ("junit.framework.Assert".equals(name) || "junit.framework.TestCase".equals(name)) {
|
||||
if (JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT.equals(name) || "junit.framework.TestCase".equals(name)) {
|
||||
registerMethodCallError(expression, name);
|
||||
}
|
||||
}
|
||||
@@ -94,9 +94,9 @@ public class UseOfObsoleteAssertInspection extends BaseInspection {
|
||||
return;
|
||||
}
|
||||
final PsiClass newAssertClass =
|
||||
JavaPsiFacade.getInstance(project).findClass("org.junit.Assert", GlobalSearchScope.allScope(project));
|
||||
JavaPsiFacade.getInstance(project).findClass(JUnitCommonClassNames.ORG_JUNIT_ASSERT, GlobalSearchScope.allScope(project));
|
||||
final PsiClass oldAssertClass =
|
||||
JavaPsiFacade.getInstance(project).findClass("junit.framework.Assert", GlobalSearchScope.allScope(project));
|
||||
JavaPsiFacade.getInstance(project).findClass(JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT, GlobalSearchScope.allScope(project));
|
||||
|
||||
if (newAssertClass == null) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user