Refactoring: use constants instead of strings

GitOrigin-RevId: a5132bfb7c7f57ac96c6f7b171447d783f2f9cdf
This commit is contained in:
Aleksey Dobrynin
2023-11-28 15:53:28 +01:00
committed by intellij-monorepo-bot
parent 0c0e5ac871
commit 2968c44e55
19 changed files with 79 additions and 68 deletions

View File

@@ -10,6 +10,7 @@ import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.psiutils.MethodCallUtils;
import com.siyeh.ig.psiutils.TypeUtils;
import org.jetbrains.annotations.NotNull;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import static com.siyeh.ig.callMatcher.CallMatcher.anyOf;
import static com.siyeh.ig.callMatcher.CallMatcher.staticCall;
@@ -20,8 +21,8 @@ import static com.siyeh.ig.callMatcher.CallMatcher.staticCall;
public class AssertAllInliner implements CallInliner {
private static final CallMatcher ASSERT_ALL =
anyOf(
staticCall("org.junit.jupiter.api.Assertions", "assertAll").parameterTypes("org.junit.jupiter.api.function.Executable..."),
staticCall("org.junit.jupiter.api.Assertions", "assertAll")
staticCall(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assertAll").parameterTypes("org.junit.jupiter.api.function.Executable..."),
staticCall(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assertAll")
.parameterTypes(CommonClassNames.JAVA_LANG_STRING, "org.junit.jupiter.api.function.Executable...")
);

View File

@@ -7,11 +7,12 @@ import com.intellij.codeInspection.dataFlow.types.DfTypes;
import com.intellij.codeInspection.dataFlow.value.RelationType;
import com.intellij.psi.*;
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ig.psiutils.MethodCallUtils;
import org.jetbrains.annotations.NotNull;
public final class AssertInstanceOfInliner implements CallInliner {
private static final CallMatcher ASSERT_INSTANCE_OF = CallMatcher.staticCall("org.junit.jupiter.api.Assertions", "assertInstanceOf");
private static final CallMatcher ASSERT_INSTANCE_OF = CallMatcher.staticCall(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assertInstanceOf");
@Override
public boolean tryInlineCall(@NotNull CFGBuilder builder, @NotNull PsiMethodCallExpression call) {

View File

@@ -11,6 +11,7 @@ import com.siyeh.InspectionGadgetsBundle;
import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ig.psiutils.EquivalenceChecker;
import com.siyeh.ig.psiutils.ExpressionUtils;
import com.siyeh.ig.psiutils.LibraryUtil;
@@ -41,9 +42,9 @@ public class EqualsWithItselfInspection extends BaseInspection {
);
private static final CallMatcher ASSERT_ARGUMENT_COMPARISON = CallMatcher.anyOf(
CallMatcher.staticCall("org.junit.Assert", "assertEquals", "assertArrayEquals", "assertIterableEquals",
CallMatcher.staticCall(JUnitCommonClassNames.ORG_JUNIT_ASSERT, "assertEquals", "assertArrayEquals", "assertIterableEquals",
"assertLinesMatch", "assertNotEquals"),
CallMatcher.staticCall("org.junit.jupiter.api.Assertions", "assertEquals", "assertArrayEquals", "assertIterableEquals",
CallMatcher.staticCall(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assertEquals", "assertArrayEquals", "assertIterableEquals",
"assertLinesMatch", "assertNotEquals"),
CallMatcher.staticCall("org.testng.Assert", "assertEquals", "assertEqualsDeep", "assertEqualsNoOrder", "assertNotEquals",
"assertNotEqualsDeep"),
@@ -52,8 +53,8 @@ public class EqualsWithItselfInspection extends BaseInspection {
);
private static final CallMatcher ASSERT_ARGUMENTS_THE_SAME = CallMatcher.anyOf(
CallMatcher.staticCall("org.junit.Assert", "assertSame", "assertNotSame"),
CallMatcher.staticCall("org.junit.jupiter.api.Assertions", "assertSame", "assertNotSame"),
CallMatcher.staticCall(JUnitCommonClassNames.ORG_JUNIT_ASSERT, "assertSame", "assertNotSame"),
CallMatcher.staticCall(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assertSame", "assertNotSame"),
CallMatcher.staticCall("org.testng.Assert", "assertSame", "assertNotSame"),
CallMatcher.staticCall("org.testng.AssertJUnit", "assertSame", "assertNotSame")
);

View File

@@ -18,6 +18,7 @@ import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.PsiReplacementUtil;
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ig.psiutils.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
@@ -97,7 +98,7 @@ public class SimplifiableAssertionInspection extends BaseInspection implements C
private static boolean isInstanceOfMethodExistsWithMatchingParams(@NotNull AssertHint assertHint) {
final PsiClass clazz = assertHint.getMethod().getContainingClass();
if (clazz == null || !"org.junit.jupiter.api.Assertions".equals(clazz.getQualifiedName())) return false;
if (clazz == null || !JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS.equals(clazz.getQualifiedName())) return false;
final Module junitModule = ModuleUtilCore.findModuleForPsiElement(assertHint.getOriginalExpression());
if (junitModule != null) {
final String version = JavaLibraryUtil.getLibraryVersion(junitModule, "org.junit.jupiter:junit-jupiter-api");

View File

@@ -12,6 +12,7 @@ import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.util.InheritanceUtil;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.ArrayUtilRt;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ig.psiutils.ExpressionUtils;
import one.util.streamex.StreamEx;
import org.intellij.lang.annotations.RegExp;
@@ -46,10 +47,10 @@ class LambdaAndExplicitMethodPair {
new LambdaAndExplicitMethodPair(OptionalUtil.OPTIONAL_LONG, "orElseGet", "orElse", 0, "long"),
new LambdaAndExplicitMethodPair(OptionalUtil.OPTIONAL_DOUBLE, "orElseGet", "orElse", 0, "double"),
new LambdaAndExplicitMethodPair(OptionalUtil.GUAVA_OPTIONAL, "or", "*", 0, "T"),
new LambdaAndExplicitMethodPair("java.util.Objects", "requireNonNull", "*", 1, JAVA_LANG_STRING),
new LambdaAndExplicitMethodPair("java.util.Objects", "requireNonNullElseGet", "requireNonNullElse", 1, "T"),
new LambdaAndExplicitMethodPair("org.junit.jupiter.api.Assertions", "assert(?!Timeout).*|fail", "*", -1, JAVA_LANG_STRING),
new LambdaAndExplicitMethodPair("org.junit.jupiter.api.Assertions", "assert(True|False)", "*", 0, JAVA_LANG_STRING),
new LambdaAndExplicitMethodPair(CommonClassNames.JAVA_UTIL_OBJECTS, "requireNonNull", "*", 1, JAVA_LANG_STRING),
new LambdaAndExplicitMethodPair(CommonClassNames.JAVA_UTIL_OBJECTS, "requireNonNullElseGet", "requireNonNullElse", 1, "T"),
new LambdaAndExplicitMethodPair(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assert(?!Timeout).*|fail", "*", -1, JAVA_LANG_STRING),
new LambdaAndExplicitMethodPair(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assert(True|False)", "*", 0, JAVA_LANG_STRING),
new LambdaAndExplicitMethodPair(CommonClassNames.JAVA_UTIL_ARRAYS, "setAll", "fill", 1, null, "i")
};
private final @NotNull String myClass;

View File

@@ -28,7 +28,7 @@ public final class FieldDescriptor implements ItemToReplaceDescriptor {
String fieldType = PsiReflectionAccessUtil.getAccessibleReturnType(myExpression, resolveFieldType(myField, myExpression));
if (fieldType == null) {
LOG.warn("Could not resolve field type. java.lang.Object will be used instead");
fieldType = "java.lang.Object";
fieldType = CommonClassNames.JAVA_LANG_OBJECT;
}
myAccessibleType = fieldType;
}
@@ -119,8 +119,8 @@ public final class FieldDescriptor implements ItemToReplaceDescriptor {
}
methodBuilder.setStatic(outerClass.hasModifierProperty(PsiModifier.STATIC))
.addParameter("java.lang.Object", "object")
.addParameter("java.lang.Object", "value");
.addParameter(CommonClassNames.JAVA_LANG_OBJECT, "object")
.addParameter(CommonClassNames.JAVA_LANG_OBJECT, "value");
return methodBuilder.build(elementFactory, outerClass);
}

View File

@@ -28,7 +28,7 @@ public class MethodDescriptor implements ItemToReplaceDescriptor {
String returnType = PsiReflectionAccessUtil.getAccessibleReturnType(myCallExpression, resolveMethodReturnType(expression, method));
if (returnType == null) {
LOG.warn("Could not resolve method return type. java.lang.Object will be used instead");
returnType = "java.lang.Object";
returnType = CommonClassNames.JAVA_LANG_OBJECT;
}
myAccessibleReturnType = returnType;
}
@@ -59,7 +59,7 @@ public class MethodDescriptor implements ItemToReplaceDescriptor {
ReflectionAccessMethodBuilder methodBuilder = new ReflectionAccessMethodBuilder(newMethodName);
PsiMethod newMethod = methodBuilder.accessedMethod(containingClassName, myMethod.getName())
.setStatic(outerClass.hasModifierProperty(PsiModifier.STATIC))
.addParameter("java.lang.Object", "object")
.addParameter(CommonClassNames.JAVA_LANG_OBJECT, "object")
.addParameters(myMethod.getParameterList())
.setReturnType(myAccessibleReturnType)
.build(elementFactory, outerClass);

View File

@@ -20,7 +20,6 @@ import com.intellij.codeInspection.dataFlow.ContractReturnValue;
import com.intellij.codeInspection.dataFlow.JavaMethodContractUtil;
import com.intellij.codeInspection.dataFlow.MethodContract;
import com.intellij.codeInspection.options.OptPane;
import com.intellij.codeInspection.options.OptionController;
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.WriteExternalException;
import com.intellij.openapi.util.registry.Registry;
@@ -35,6 +34,7 @@ import com.siyeh.ig.BaseInspection;
import com.siyeh.ig.BaseInspectionVisitor;
import com.siyeh.ig.callMatcher.CallMapper;
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ig.psiutils.*;
import org.intellij.lang.annotations.Pattern;
import org.jdom.Element;
@@ -85,8 +85,8 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
private static final CallMatcher TEST_OR_MOCK_CONTAINER_METHODS =
CallMatcher.anyOf(
CallMatcher.staticCall("org.assertj.core.api.Assertions", "assertThatThrownBy", "catchThrowable", "catchThrowableOfType"),
CallMatcher.staticCall("org.junit.jupiter.api.Assertions", "assertDoesNotThrow", "assertThrows", "assertThrowsExactly"),
CallMatcher.staticCall("org.junit.Assert", "assertThrows"),
CallMatcher.staticCall(JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS, "assertDoesNotThrow", "assertThrows", "assertThrowsExactly"),
CallMatcher.staticCall(JUnitCommonClassNames.ORG_JUNIT_ASSERT, "assertThrows"),
CallMatcher.instanceCall("org.mockito.MockedStatic", "when", "verify")
);
@@ -100,38 +100,38 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
public IgnoreResultOfCallInspection() {
myMethodMatcher = new MethodMatcher(true, "callCheckString")
.add("java.io.File", ".*")
.add(CommonClassNames.JAVA_IO_FILE, ".*")
.add("java.io.InputStream","read|skip|available|markSupported")
.add("java.io.Reader","read|skip|ready|markSupported")
.add("java.lang.AbstractStringBuilder", "capacity|codePointAt|codePointBefore|codePointCount|indexOf|lastIndexOf|offsetByCodePoints|substring|subSequence")
.add("java.lang.Boolean",".*")
.add("java.lang.Byte",".*")
.add("java.lang.Character",".*")
.add("java.lang.Double",".*")
.add("java.lang.Float",".*")
.add("java.lang.Integer",".*")
.add("java.lang.Long",".*")
.add("java.lang.Math",".*")
.add("java.lang.Object","equals|hashCode|toString")
.add("java.lang.Short",".*")
.add("java.lang.StrictMath",".*")
.add("java.lang.String",".*")
.add(CommonClassNames.JAVA_LANG_ABSTRACT_STRING_BUILDER, "capacity|codePointAt|codePointBefore|codePointCount|indexOf|lastIndexOf|offsetByCodePoints|substring|subSequence")
.add(CommonClassNames.JAVA_LANG_BOOLEAN,".*")
.add(CommonClassNames.JAVA_LANG_BYTE,".*")
.add(CommonClassNames.JAVA_LANG_CHARACTER,".*")
.add(CommonClassNames.JAVA_LANG_DOUBLE,".*")
.add(CommonClassNames.JAVA_LANG_FLOAT,".*")
.add(CommonClassNames.JAVA_LANG_INTEGER,".*")
.add(CommonClassNames.JAVA_LANG_LONG,".*")
.add(CommonClassNames.JAVA_LANG_MATH,".*")
.add(CommonClassNames.JAVA_LANG_OBJECT,"equals|hashCode|toString")
.add(CommonClassNames.JAVA_LANG_SHORT,".*")
.add(CommonClassNames.JAVA_LANG_STRICT_MATH,".*")
.add(CommonClassNames.JAVA_LANG_STRING,".*")
.add("java.lang.Thread", "interrupted")
.add("java.math.BigDecimal",".*")
.add("java.math.BigInteger",".*")
.add("java.net.InetAddress",".*")
.add("java.net.URI",".*")
.add(CommonClassNames.JAVA_NET_URI,".*")
.add("java.nio.channels.AsynchronousChannelGroup",".*")
.add("java.nio.channels.Channel","isOpen")
.add("java.nio.channels.FileChannel","open|map|lock|tryLock|write")
.add("java.nio.channels.ScatteringByteChannel","read")
.add("java.nio.channels.SocketChannel","open|socket|isConnected|isConnectionPending")
.add("java.util.Arrays", ".*")
.add("java.util.Collections", "(?!addAll).*")
.add("java.util.List", "of")
.add("java.util.Map", "of|ofEntries|entry")
.add("java.util.Set", "of")
.add("java.util.UUID",".*")
.add(CommonClassNames.JAVA_UTIL_ARRAYS, ".*")
.add(CommonClassNames.JAVA_UTIL_COLLECTIONS, "(?!addAll).*")
.add(CommonClassNames.JAVA_UTIL_LIST, "of")
.add(CommonClassNames.JAVA_UTIL_MAP, "of|ofEntries|entry")
.add(CommonClassNames.JAVA_UTIL_SET, "of")
.add(CommonClassNames.JAVA_UTIL_UUID,".*")
.add("java.util.concurrent.BlockingQueue", "offer|remove")
.add("java.util.concurrent.CountDownLatch","await|getCount")
.add("java.util.concurrent.ExecutorService","awaitTermination|isShutdown|isTerminated")
@@ -141,11 +141,11 @@ public class IgnoreResultOfCallInspection extends BaseInspection {
.add("java.util.concurrent.locks.Lock","tryLock|newCondition")
.add("java.util.regex.Matcher","pattern|toMatchResult|start|end|group|groupCount|matches|find|lookingAt|quoteReplacement|replaceAll|replaceFirst|regionStart|regionEnd|hasTransparentBounds|hasAnchoringBounds|hitEnd|requireEnd")
.add("java.util.regex.Pattern",".*")
.add("java.util.stream.BaseStream",".*")
.add("java.util.stream.DoubleStream",".*")
.add("java.util.stream.IntStream",".*")
.add("java.util.stream.LongStream",".*")
.add("java.util.stream.Stream",".*")
.add(CommonClassNames.JAVA_UTIL_STREAM_BASE_STREAM,".*")
.add(CommonClassNames.JAVA_UTIL_STREAM_DOUBLE_STREAM,".*")
.add(CommonClassNames.JAVA_UTIL_STREAM_INT_STREAM,".*")
.add(CommonClassNames.JAVA_UTIL_STREAM_LONG_STREAM,".*")
.add(CommonClassNames.JAVA_UTIL_STREAM_STREAM,".*")
.finishDefault();
}

View File

@@ -16,6 +16,7 @@
package com.siyeh.ipp.junit;
import com.intellij.psi.*;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ipp.base.PsiElementPredicate;
import com.siyeh.ipp.psiutils.ErrorUtil;
import org.jetbrains.annotations.NonNls;
@@ -46,9 +47,9 @@ class AssertLiteralPredicate implements PsiElementPredicate {
return false;
}
final String qualifiedName = targetClass.getQualifiedName();
if (!"junit.framework.Assert".equals(qualifiedName) &&
!"org.junit.Assert".equals(qualifiedName) &&
!"org.junit.jupiter.api.Assertions".equals(qualifiedName)) {
if (!JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT.equals(qualifiedName) &&
!JUnitCommonClassNames.ORG_JUNIT_ASSERT.equals(qualifiedName) &&
!JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS.equals(qualifiedName)) {
return false;
}
return !ErrorUtil.containsError(element);

View File

@@ -16,6 +16,7 @@
package com.siyeh.ipp.junit;
import com.intellij.psi.*;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ipp.base.PsiElementPredicate;
import com.siyeh.ipp.psiutils.ErrorUtil;
import org.jetbrains.annotations.NonNls;
@@ -46,9 +47,9 @@ class AssertTrueOrFalsePredicate implements PsiElementPredicate {
return false;
}
final String qualifiedName = targetClass.getQualifiedName();
if (!"junit.framework.Assert".equals(qualifiedName) &&
!"org.junit.Assert".equals(qualifiedName) &&
!"org.junit.jupiter.api.Assertions".equals(qualifiedName)) {
if (!JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT.equals(qualifiedName) &&
!JUnitCommonClassNames.ORG_JUNIT_ASSERT.equals(qualifiedName) &&
!JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS.equals(qualifiedName)) {
return false;
}
return !ErrorUtil.containsError(element);

View File

@@ -24,6 +24,7 @@ import com.intellij.testIntegration.TestFramework;
import com.intellij.util.containers.ContainerUtil;
import com.siyeh.IntentionPowerPackBundle;
import com.siyeh.ig.PsiReplacementUtil;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ig.psiutils.BoolUtils;
import com.siyeh.ig.psiutils.ComparisonUtils;
import com.siyeh.ig.psiutils.ExpressionUtils;
@@ -136,7 +137,7 @@ public class CreateAssertIntention extends MCIntention {
builder.append(')');
final String text = builder.toString();
final String qualifier = isJUnit5(context) ? "org.junit.jupiter.api.Assertions" : "org.junit.Assert";
final String qualifier = isJUnit5(context) ? JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS : JUnitCommonClassNames.ORG_JUNIT_ASSERT;
final PsiMethodCallExpression methodCallExpression = (PsiMethodCallExpression)factory.createExpressionFromText(text, context);
final PsiMethod method = methodCallExpression.resolveMethod();
if (isJUnitMethod(method) || hasStaticImports(context) && ImportUtils.addStaticImport(qualifier, memberName, context)) {
@@ -169,7 +170,7 @@ public class CreateAssertIntention extends MCIntention {
return false;
}
final String qualifiedName = containingClass.getQualifiedName();
return "org.junit.Assert".equals(qualifiedName) || "junit.framework.TestCase".equals(qualifiedName);
return JUnitCommonClassNames.ORG_JUNIT_ASSERT.equals(qualifiedName) || JUnitCommonClassNames.JUNIT_FRAMEWORK_TEST_CASE.equals(qualifiedName);
}
private static boolean hasStaticImports(PsiElement element) {

View File

@@ -14,6 +14,7 @@ import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.roots.ModuleRootManager;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.profile.codeInspection.ProjectInspectionProfileManager;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.JavaPsiFacade;
import com.intellij.psi.PsiClass;
import com.intellij.psi.search.GlobalSearchScope;
@@ -55,7 +56,7 @@ public abstract class LightJavaInspectionTestCase extends LightJavaCodeInsightFi
Sdk sdk = ModuleRootManager.getInstance(ModuleManager.getInstance(getProject()).getModules()[0]).getSdk();
if (Objects.requireNonNull(JAVA_1_7.getSdk()).getName().equals(sdk == null ? null : sdk.getName())) {
final PsiClass object = JavaPsiFacade.getInstance(getProject()).findClass("java.lang.Object", GlobalSearchScope.allScope(getProject()));
final PsiClass object = JavaPsiFacade.getInstance(getProject()).findClass(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(getProject()));
assertNotNull(object);
final PsiClass component = JavaPsiFacade.getInstance(getProject()).findClass("java.awt.Component", GlobalSearchScope.allScope(getProject()));

View File

@@ -172,10 +172,10 @@ public class ThreadLocalConversionRule extends TypeConversionRule {
final StringBuilder result = new StringBuilder("new ");
result.append(to.getCanonicalText()).append("() {\n");
if (PsiUtil.isLanguageLevel5OrHigher(context)) {
result.append(" @java.lang.Override\n");
result.append(" @").append(CommonClassNames.JAVA_LANG_OVERRIDE).append("\n");
}
result.append(" protected ")
.append(PsiUtil.isLanguageLevel5OrHigher(context) ? to.getParameters()[0].getCanonicalText() : "java.lang.Object")
.append(PsiUtil.isLanguageLevel5OrHigher(context) ? to.getParameters()[0].getCanonicalText() : CommonClassNames.JAVA_LANG_OBJECT)
.append(" initialValue() {\n")
.append(" return ")
.append(coerceType("$qualifier$", from, to, context)).append(";\n")

View File

@@ -65,11 +65,11 @@ public final class GdkMethodUtil {
@NlsSafe public static final String WITH_OBJECT_STREAMS = "withObjectStreams";
private static final Map<String, String> AST_TO_EXPR_MAPPER =
Map.of("org.codehaus.groovy.ast.expr.ClosureExpression", "groovy.lang.Closure",
"org.codehaus.groovy.ast.expr.ListExpression", "java.util.List",
"org.codehaus.groovy.ast.expr.MapExpression", "java.util.Map",
"org.codehaus.groovy.ast.expr.TupleExpression", "groovy.lang.Tuple",
"org.codehaus.groovy.ast.expr.MethodCallExpression", "java.lang.Object");
Map.of("org.codehaus.groovy.ast.expr.ClosureExpression", GroovyCommonClassNames.GROOVY_LANG_CLOSURE,
"org.codehaus.groovy.ast.expr.ListExpression", CommonClassNames.JAVA_UTIL_LIST,
"org.codehaus.groovy.ast.expr.MapExpression", CommonClassNames.JAVA_UTIL_MAP,
"org.codehaus.groovy.ast.expr.TupleExpression", GroovyCommonClassNames.GROOVY_LANG_TUPLE,
"org.codehaus.groovy.ast.expr.MethodCallExpression", CommonClassNames.JAVA_LANG_OBJECT);
private static final String MACRO_ORIGIN_INFO = "Macro method";

View File

@@ -16,6 +16,7 @@ public interface GroovyCommonClassNames {
String GROOVY_OBJECT = "groovy.lang.GroovyObject";
String GROOVY_LANG_CLOSURE = "groovy.lang.Closure";
String GROOVY_LANG_GSTRING = "groovy.lang.GString";
String GROOVY_LANG_TUPLE = "groovy.lang.Tuple";
String DEFAULT_GROOVY_METHODS = "org.codehaus.groovy.runtime.DefaultGroovyMethods";
String GROOVY_LANG_SCRIPT = "groovy.lang.Script";
String GROOVY_LANG_RANGE = "groovy.lang.Range";

View File

@@ -62,7 +62,7 @@ public class GroovyGenerateMethodMissingHandler extends GenerateMembersHandlerBa
@Nullable
private static GrMethod genMethod(PsiClass aClass, FileTemplate template) {
Properties properties = FileTemplateManager.getInstance(aClass.getProject()).getDefaultProperties();
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, "java.lang.Object");
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, CommonClassNames.JAVA_LANG_OBJECT);
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, "null");
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, "");
String fqn = aClass.getQualifiedName();

View File

@@ -66,7 +66,7 @@ public class GroovyGeneratePropertyMissingHandler extends GenerateMembersHandler
@Nullable
private static GrMethod genGetter(PsiClass aClass, FileTemplate template) {
Properties properties = FileTemplateManager.getInstance(aClass.getProject()).getDefaultProperties();
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, "java.lang.Object");
properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, CommonClassNames.JAVA_LANG_OBJECT);
properties.setProperty(FileTemplate.ATTRIBUTE_DEFAULT_RETURN_VALUE, "null");
properties.setProperty(FileTemplate.ATTRIBUTE_CALL_SUPER, "");
properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, aClass.getQualifiedName());

View File

@@ -72,7 +72,7 @@ public class CreateLocalVariableFromUsageFix extends Intention {
@Override
public @NotNull IntentionPreviewInfo generatePreview(@NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
TypeConstraint[] constraints = GroovyExpectedTypesProvider.calculateTypeConstraints(myRefExpression);
PsiType type = constraints.length == 0 || constraints[0].getType().equals(PsiTypes.voidType()) ? JavaPsiFacade.getInstance(project).getElementFactory().createTypeByFQClassName("java.lang.Object", GlobalSearchScope.allScope(project)) : constraints[0].getType();
PsiType type = constraints.length == 0 || constraints[0].getType().equals(PsiTypes.voidType()) ? JavaPsiFacade.getInstance(project).getElementFactory().createTypeByFQClassName(CommonClassNames.JAVA_LANG_OBJECT, GlobalSearchScope.allScope(project)) : constraints[0].getType();
GrVariableDeclaration declaration = GroovyPsiElementFactory.getInstance(project)
.createVariableDeclaration(ArrayUtilRt.EMPTY_STRING_ARRAY, "", type, myRefExpression.getReferenceName());
return new IntentionPreviewInfo.CustomDiff(GroovyFileType.GROOVY_FILE_TYPE, "", declaration.getText());

View File

@@ -42,6 +42,7 @@ import com.intellij.util.ThreeState;
import com.intellij.util.containers.ContainerUtil;
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.fixes.IntroduceConstantFix;
import com.siyeh.ig.junit.JUnitCommonClassNames;
import com.siyeh.ig.psiutils.TypeUtils;
import com.siyeh.ig.psiutils.VariableAccessUtils;
import org.intellij.lang.annotations.RegExp;
@@ -876,9 +877,9 @@ public final class I18nInspection extends AbstractBaseUastLocalInspectionTool im
if (containingClass == null) {
return false;
}
return InheritanceUtil.isInheritor(containingClass,"org.junit.Assert") ||
InheritanceUtil.isInheritor(containingClass,"org.junit.jupiter.api.Assertions") ||
InheritanceUtil.isInheritor(containingClass, "junit.framework.Assert");
return InheritanceUtil.isInheritor(containingClass,JUnitCommonClassNames.ORG_JUNIT_ASSERT) ||
InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.ORG_JUNIT_JUPITER_API_ASSERTIONS) ||
InheritanceUtil.isInheritor(containingClass, JUnitCommonClassNames.JUNIT_FRAMEWORK_ASSERT);
}
private static boolean isArgOfSpecifiedExceptionConstructor(UExpression expression,