IG: internationalize "@RunWith(Parameterized.class) without data provider" inspection (IDEA-266717)

all message changed to make this task easier

GitOrigin-RevId: de62ba84bde08c20a91b1db3fb8b549fbd1571b5
This commit is contained in:
Bas Leijdekkers
2021-05-19 10:43:59 +00:00
committed by intellij-monorepo-bot
parent 22b145dc6e
commit 7275ed3569
7 changed files with 36 additions and 67 deletions
@@ -2411,8 +2411,12 @@ inspection.comparator.combinators.description=Can be replaced with 'Comparator'
inspection.comparator.combinators.description2=Can be replaced with ''{0}''
inspection.unnecessary.string.escape.report.char.literals.option=Report char literals
inspection.method.call.in.loop.ignore.known.methods.option=Ignore known methods with side-effects
fix.data.provider.signature.family.name=Fix data provider signature
fix.data.provider.signature.problem=Class #ref annotated @RunWith(Parameterized.class) lacks data provider
fix.data.provider.signature.fix.name=Change method signature to ''{0}''
fix.data.provider.create.method.fix.name=Create data provider method '@Parameters public static Iterable<Object> parameters()'
fix.data.provider.signature.family.name=Fix data provider method signature
fix.data.provider.signature.missing.method.problem=Parameterized test class <code>#ref</code> lacks data provider method annotated with '@Parameters'
fix.data.provider.signature.incorrect.problem=Data provider method <code>#ref()</code> has an incorrect signature
fix.data.provider.multiple.methods.problem=Multiple @Parameters data provider methods present in class <code>#ref</code>
allow.suppressions.fix.family.name=Allow suppressions
allow.suppressions.fix.text=Allow these suppressions
remove.suppress.comment.fix.family.name=Remove //{0}
@@ -2431,7 +2435,7 @@ utility.class.without.private.constructor.cant.generate.constructor.title=Can't
utility.class.without.private.constructor.cant.generate.constructor.message=Utility class has instantiations, private constructor will not be created
inspection.suspicious.package.private.access.problem={0} overrides a package-private method from {1} which is declared in a different module ''{2}''
inspection.condition.covered.by.further.condition.descr=Condition ''{0}'' covered by subsequent {1, choice, 1#condition ''''{2}''''|2#conditions}
inspection.parameterized.parameters.static.collection.display.name=@RunWith(Parameterized.class) without data provider
inspection.parameterized.parameters.static.collection.display.name=Parameterized test class without data provider method
create.missing.switch.branch=Create missing switch branch ''{0}''
create.missing.switch.branches=Create missing branches: {0}
redundant.as.list.for.iteration.problem=Unnecessary 'Arrays.asList()' call
@@ -19,9 +19,6 @@ import com.siyeh.ig.InspectionGadgetsFix;
import com.siyeh.ig.psiutils.TestUtils;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
public class ParameterizedParametersStaticCollectionInspection extends BaseInspection {
protected static final String PARAMETERS_FQN = "org.junit.runners.Parameterized.Parameters";
@@ -30,7 +27,8 @@ public class ParameterizedParametersStaticCollectionInspection extends BaseInspe
protected InspectionGadgetsFix buildFix(final Object... infos) {
if (infos[0] instanceof PsiClass) {
final PsiClass aClass = (PsiClass)infos[0];
return new DelegatingFix(CreateMethodQuickFix.createFix(aClass, "@" + PARAMETERS_FQN + " public static java.lang.Iterable<java.lang.Object[]> parameters()", ""));
final String signature = "@" + PARAMETERS_FQN + " public static java.lang.Iterable<java.lang.Object[]> parameters()";
return new DelegatingFix(CreateMethodQuickFix.createFix(aClass, signature, ""));
}
return new InspectionGadgetsFix() {
@@ -46,7 +44,7 @@ public class ParameterizedParametersStaticCollectionInspection extends BaseInspe
return;
}
final PsiMethod method = (PsiMethod)element;
final PsiType type = (PsiType)infos[2];
final PsiType type = (PsiType)infos[1];
final ChangeSignatureProcessor csp =
new ChangeSignatureProcessor(project, method, false, PsiModifier.PUBLIC, method.getName(), type, new ParameterInfoImpl[0]);
csp.run();
@@ -55,7 +53,7 @@ public class ParameterizedParametersStaticCollectionInspection extends BaseInspe
@Override
@NotNull
public String getName() {
return (String)infos[0];
return InspectionGadgetsBundle.message("fix.data.provider.signature.fix.name", infos[0]);
}
@NotNull
@@ -70,8 +68,8 @@ public class ParameterizedParametersStaticCollectionInspection extends BaseInspe
@NotNull
protected String buildErrorString(Object... infos) {
return infos.length > 1
? (String)infos[1]
: InspectionGadgetsBundle.message("fix.data.provider.signature.problem");
? InspectionGadgetsBundle.message("fix.data.provider.signature.incorrect.problem")
: InspectionGadgetsBundle.message("fix.data.provider.signature.missing.method.problem");
}
@Override
@@ -82,76 +80,43 @@ public class ParameterizedParametersStaticCollectionInspection extends BaseInspe
if (!TestUtils.isParameterizedTest(aClass)) {
return;
}
final List<MethodCandidate> candidates = new ArrayList<>();
final Project project = aClass.getProject();
final PsiClass iterableClass =
JavaPsiFacade.getInstance(project).findClass(CommonClassNames.JAVA_LANG_ITERABLE, GlobalSearchScope.allScope(project));
if (iterableClass == null) {
return;
}
boolean methodFound = false;
for (PsiMethod method : aClass.getMethods()) {
if (!AnnotationUtil.isAnnotated(method, PARAMETERS_FQN, 0)) {
continue;
}
final PsiModifierList modifierList = method.getModifierList();
final String fixMessage = "Make method '" + method.getName() + "' ";
String errorString = "Method '#ref()' should";
String signatureDescription = "";
if (!modifierList.hasModifierProperty(PsiModifier.PUBLIC)) {
signatureDescription += PsiModifier.PUBLIC;
errorString += " be ";
}
if (!modifierList.hasModifierProperty(PsiModifier.STATIC)) {
if (!signatureDescription.isEmpty()) {
signatureDescription += " " + PsiModifier.STATIC;
}
else {
signatureDescription += PsiModifier.STATIC;
errorString += " be ";
}
}
methodFound = true;
final boolean notPublic = !method.hasModifierProperty(PsiModifier.PUBLIC);
final boolean notStatic = !method.hasModifierProperty(PsiModifier.STATIC);
PsiType returnType = method.getReturnType();
final PsiClass returnTypeClass = PsiUtil.resolveClassInType(returnType);
boolean objectArray = returnType instanceof PsiArrayType &&
returnType.getDeepComponentType().equalsToText(CommonClassNames.JAVA_LANG_OBJECT);
boolean iterable = returnTypeClass != null && InheritanceUtil.isInheritorOrSelf(returnTypeClass, iterableClass, true);
final boolean objectArray = returnType instanceof PsiArrayType &&
returnType.getDeepComponentType().equalsToText(CommonClassNames.JAVA_LANG_OBJECT);
final boolean iterable = returnTypeClass != null && InheritanceUtil.isInheritorOrSelf(returnTypeClass, iterableClass, true);
final String signatureText;
if (!objectArray && !iterable) {
if (!signatureDescription.isEmpty()) {
signatureDescription += " and";
}
signatureDescription += " have return type Iterable or Object[]";
returnType = JavaPsiFacade.getElementFactory(project).createType(iterableClass);
signatureText = "public static Iterable<Object[]> " + method.getName() + "()";
returnType = JavaPsiFacade.getElementFactory(project)
.createTypeFromText(CommonClassNames.JAVA_LANG_ITERABLE + "<java.lang.Object[]>", method);
}
if (!signatureDescription.isEmpty()) {
candidates.add(new MethodCandidate(method, fixMessage + signatureDescription, errorString + signatureDescription, returnType));
continue;
else {
signatureText = "public static " + returnType.getPresentableText() + " " + method.getName() + "()";
}
if (notPublic || notStatic || (!objectArray && !iterable)) {
registerMethodError(method, signatureText, returnType);
}
return;
}
if (candidates.isEmpty()) {
if (!methodFound) {
registerClassError(aClass, aClass);
}
else {
for (MethodCandidate candidate : candidates) {
registerMethodError(candidate.myMethod, candidate.myProblem, candidate.myErrorString, candidate.myReturnType);
}
}
}
};
}
private static class MethodCandidate {
PsiMethod myMethod;
String myProblem;
private final String myErrorString;
PsiType myReturnType;
MethodCandidate(PsiMethod method, String problem, String errorString, PsiType returnType) {
myMethod = method;
myProblem = problem;
myErrorString = errorString;
myReturnType = returnType;
}
}
}
@@ -1,2 +1,2 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class <warning descr="Class Createmethod annotated @RunWith(Parameterized.class) lacks data provider">Createmethod</warning> {}
public class <warning descr="Parameterized test class 'Createmethod' lacks data provider method annotated with '@Parameters'"><caret>Createmethod</warning> {}
@@ -1,7 +1,7 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature {
@org.junit.runners.Parameterized.Parameters
java.util.Collection <warning descr="Method 'regExValues()' should be public static">regExValues</warning>() {
@org.junit.runners.Parameterized.Parameters
java.util.Collection <warning descr="Data provider method 'regExValues()' has an incorrect signature"><caret>regExValues</warning>() {
return null;
}
}
@@ -1,7 +1,7 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature1 {
@org.junit.runners.Parameterized.Parameters
static Integer <warning descr="Method 'regExValues()' should be public and have return type Iterable or Object[]">regExValues</warning>() {
static Integer <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}
@@ -1,7 +1,7 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature2 {
@org.junit.runners.Parameterized.Parameters
public static Integer <warning descr="Method 'regExValues()' should have return type Iterable or Object[]">regExValues</warning>() {
public static Integer <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}
@@ -1,7 +1,7 @@
@org.junit.runner.RunWith(org.junit.runners.Parameterized.class)
public class Wrongsignature3 {
@org.junit.runners.Parameterized.Parameters
public static Integer[] <warning descr="Method 'regExValues()' should have return type Iterable or Object[]">regExValues</warning>() {
public static Integer[] <warning descr="Data provider method 'regExValues()' has an incorrect signature">regExValues</warning>() {
return null;
}
}