Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.editor.inspection.LocalQuickFixOnPsiElementAsIntentionAdapter;
import consulo.language.editor.intention.IntentionAction;
import consulo.language.editor.intention.QuickFixAction;
import consulo.language.editor.intention.QuickFixActionRegistrar;
import consulo.language.editor.intention.UnresolvedReferenceQuickFixProvider;
import consulo.language.editor.localize.DaemonLocalize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3398,7 +3398,7 @@ public static HighlightInfo.Builder checkMustBeThrowable(
return null;
}
PsiElementFactory factory = JavaPsiFacade.getInstance(context.getProject()).getElementFactory();
PsiClassType throwable = factory.createTypeByFQClassName("java.lang.Throwable", context.getResolveScope());
PsiClassType throwable = factory.createTypeByFQClassName(JavaClassNames.JAVA_LANG_THROWABLE, context.getResolveScope());
if (!TypeConversionUtil.isAssignable(throwable, type)) {
HighlightInfo.Builder hlBuilder = createIncompatibleTypeHighlightInfo(throwable, type, context.getTextRange(), 0);
if (addCastIntention && TypeConversionUtil.areTypesConvertible(type, throwable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
public class JavaHighlightUtil {
public static boolean isSerializable(@Nonnull PsiClass aClass) {
PsiManager manager = aClass.getManager();
PsiClass serializableClass = JavaPsiFacade.getInstance(manager.getProject()).findClass("java.io.Serializable", aClass.getResolveScope());
PsiClass serializableClass = JavaPsiFacade.getInstance(manager.getProject())
.findClass(JavaClassNames.JAVA_IO_SERIALIZABLE, aClass.getResolveScope());
return serializableClass != null && aClass.isInheritor(serializableClass, true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.intellij.java.language.psi.util.TypeConversionUtil;
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.psiutils.*;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.ast.IElementType;
import consulo.language.editor.ImplicitUsageProvider;
import consulo.language.psi.PsiElement;
Expand Down Expand Up @@ -1258,8 +1259,9 @@ public void visitArrayAccessExpression(PsiArrayAccessExpression expression) {
if (toPush == null) {
toPush = myFactory.getObjectType(expression.getType(), Nullability.UNKNOWN);
}
DfaControlTransferValue transfer =
shouldHandleException() ? myFactory.controlTransfer(myExceptionCache.get("java.lang.ArrayIndexOutOfBoundsException"), myTrapStack) : null;
DfaControlTransferValue transfer = shouldHandleException()
? myFactory.controlTransfer(myExceptionCache.get(JavaClassNames.JAVA_LANG_ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION), myTrapStack)
: null;
addInstruction(new ArrayAccessInstruction(toPush, expression, transfer));
addNullCheck(expression);
finishElement(expression);
Expand Down Expand Up @@ -2022,8 +2024,9 @@ public void visitTypeCastExpression(PsiTypeCastExpression castExpression) {

final PsiTypeElement typeElement = castExpression.getCastType();
if (typeElement != null && operand != null && operand.getType() != null && !(typeElement.getType() instanceof PsiPrimitiveType)) {
DfaControlTransferValue transfer =
shouldHandleException() ? myFactory.controlTransfer(myExceptionCache.get("java.lang.ClassCastException"), myTrapStack) : null;
DfaControlTransferValue transfer = shouldHandleException()
? myFactory.controlTransfer(myExceptionCache.get(JavaClassNames.JAVA_LANG_CLASS_CAST_EXCEPTION), myTrapStack)
: null;
addInstruction(new TypeCastInstruction(castExpression, operand, typeElement.getType(), transfer));
}
finishElement(castExpression);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.psiutils.TypeUtils;
import consulo.application.util.CachedValueProvider;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.psi.util.LanguageCachedValueUtil;
import consulo.util.collection.ArrayUtil;
import consulo.util.lang.reflect.ReflectionUtil;
Expand Down Expand Up @@ -50,7 +51,7 @@ final class CustomMethodHandlers {
staticCall(JAVA_LANG_FLOAT, "toString", "toHexString").parameterTypes("float"),
staticCall(JAVA_LANG_BYTE, "toString").parameterTypes("byte"),
staticCall(JAVA_LANG_SHORT, "toString").parameterTypes("short"),
staticCall(JAVA_LANG_BOOLEAN, "parseBoolean").parameterTypes("java.lang.String"),
staticCall(JAVA_LANG_BOOLEAN, "parseBoolean").parameterTypes(JavaClassNames.JAVA_LANG_STRING),
staticCall(JAVA_LANG_INTEGER, "compare", "compareUnsigned").parameterTypes("int", "int"),
staticCall(JAVA_LANG_LONG, "compare", "compareUnsigned").parameterTypes("long", "long"),
staticCall(JAVA_LANG_DOUBLE, "compare").parameterTypes("double", "double"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.siyeh.ig.callMatcher.CallMatcher;
import com.siyeh.ig.psiutils.MethodUtils;
import com.siyeh.ig.psiutils.TypeUtils;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.inject.InjectedLanguageManager;
import consulo.language.psi.PsiElement;
import consulo.language.psi.PsiFile;
Expand Down Expand Up @@ -527,7 +528,7 @@ public static MutationSignature getHardcodedMutation(PsiMethod method) {
}
String name = method.getName();

if ("java.util.Objects".equals(className) && "requireNonNull".equals(name)) {
if (JavaClassNames.JAVA_UTIL_OBJECTS.equals(className) && "requireNonNull".equals(name)) {
PsiParameter[] parameters = method.getParameterList().getParameters();
if (parameters.length == 2 && parameters[1].getType().getCanonicalText().contains("Supplier")) {
return MutationSignature.unknown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.siyeh.ig.psiutils.CollectionUtils;
import com.siyeh.ig.psiutils.TypeUtils;
import com.siyeh.localize.InspectionGadgetsLocalize;
import consulo.java.language.module.util.JavaClassNames;
import jakarta.annotation.Nonnull;

public abstract class ExtendsConcreteCollectionInspectionBase extends BaseInspection {
Expand Down Expand Up @@ -64,7 +65,7 @@ public void visitClass(@Nonnull PsiClass aClass) {
final String qualifiedName = superClass.getQualifiedName();
if ("java.util.LinkedHashMap".equals(qualifiedName)) {
final PsiMethod[] methods = aClass.findMethodsByName("removeEldestEntry", false);
final PsiClassType entryType = TypeUtils.getType("java.util.Map.Entry", aClass);
final PsiClassType entryType = TypeUtils.getType(JavaClassNames.JAVA_UTIL_MAP_ENTRY, aClass);
for (PsiMethod method : methods) {
if (!PsiType.BOOLEAN.equals(method.getReturnType())) {
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public class ClassUtils {
immutableTypes.add("java.math.MathContext");
immutableTypes.add("java.nio.channels.FileLock");
immutableTypes.add("java.nio.charset.Charset");
immutableTypes.add("java.io.File");
immutableTypes.add(JavaClassNames.JAVA_IO_FILE);
immutableTypes.add("java.net.URI");
immutableTypes.add("java.util.regex.Pattern");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class CollectionUtils {
allCollectionClassesAndInterfaces.add("java.util.AbstractQueue");
allCollectionClassesAndInterfaces.add("java.util.AbstractSequentialList");
allCollectionClassesAndInterfaces.add("java.util.AbstractSet");
allCollectionClassesAndInterfaces.add("java.util.ArrayList");
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_ARRAY_LIST);
allCollectionClassesAndInterfaces.add("java.util.ArrayDeque");
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_COLLECTION);
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_DICTIONARY);
Expand All @@ -62,10 +62,10 @@ public class CollectionUtils {
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_LIST);
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_MAP);
allCollectionClassesAndInterfaces.add("java.util.PriorityQueue");
allCollectionClassesAndInterfaces.add("java.util.Queue");
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_QUEUE);
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_SET);
allCollectionClassesAndInterfaces.add("java.util.SortedMap");
allCollectionClassesAndInterfaces.add("java.util.SortedSet");
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_SORTED_MAP);
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_SORTED_SET);
allCollectionClassesAndInterfaces.add("java.util.Stack");
allCollectionClassesAndInterfaces.add("java.util.TreeMap");
allCollectionClassesAndInterfaces.add("java.util.TreeSet");
Expand All @@ -74,7 +74,7 @@ public class CollectionUtils {
allCollectionClassesAndInterfaces.add("java.util.concurrent.ArrayBlockingQueue");
allCollectionClassesAndInterfaces.add("java.util.concurrent.BlockingDeque");
allCollectionClassesAndInterfaces.add("java.util.concurrent.BlockingQueue");
allCollectionClassesAndInterfaces.add("java.util.concurrent.ConcurrentHashMap");
allCollectionClassesAndInterfaces.add(JavaClassNames.JAVA_UTIL_CONCURRENT_HASH_MAP);
allCollectionClassesAndInterfaces.add("java.util.concurrent.ConcurrentLinkedDeque");
allCollectionClassesAndInterfaces.add("java.util.concurrent.ConcurrentLinkedQueue");
allCollectionClassesAndInterfaces.add("java.util.concurrent.ConcurrentMap");
Expand Down Expand Up @@ -120,17 +120,17 @@ public class CollectionUtils {
s_interfaceForCollection.put("TreeSet", "SortedSet");
s_interfaceForCollection.put("Vector", "List");
s_interfaceForCollection.put("WeakHashMap", "Map");
s_interfaceForCollection.put("java.util.ArrayList", JavaClassNames.JAVA_UTIL_LIST);
s_interfaceForCollection.put(JavaClassNames.JAVA_UTIL_ARRAY_LIST, JavaClassNames.JAVA_UTIL_LIST);
s_interfaceForCollection.put("java.util.EnumMap", JavaClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.EnumSet", JavaClassNames.JAVA_UTIL_SET);
s_interfaceForCollection.put("java.util.HashMap", JavaClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.HashSet", JavaClassNames.JAVA_UTIL_SET);
s_interfaceForCollection.put(JavaClassNames.JAVA_UTIL_HASH_MAP, JavaClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put(JavaClassNames.JAVA_UTIL_HASH_SET, JavaClassNames.JAVA_UTIL_SET);
s_interfaceForCollection.put("java.util.Hashtable", JavaClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.IdentityHashMap", JavaClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.LinkedHashMap", JavaClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.LinkedHashSet", JavaClassNames.JAVA_UTIL_SET);
s_interfaceForCollection.put("java.util.LinkedList", JavaClassNames.JAVA_UTIL_LIST);
s_interfaceForCollection.put("java.util.PriorityQueue", "java.util.Queue");
s_interfaceForCollection.put("java.util.PriorityQueue", JavaClassNames.JAVA_UTIL_QUEUE);
s_interfaceForCollection.put("java.util.TreeMap", JavaClassNames.JAVA_UTIL_MAP);
s_interfaceForCollection.put("java.util.TreeSet", JavaClassNames.JAVA_UTIL_SET);
s_interfaceForCollection.put("java.util.Vector", JavaClassNames.JAVA_UTIL_LIST);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.intellij.java.language.psi.PsiReferenceExpression;
import com.intellij.java.language.psi.util.PsiUtil;
import com.siyeh.ig.callMatcher.CallMatcher;
import consulo.java.language.module.util.JavaClassNames;
import consulo.util.collection.ArrayUtil;
import jakarta.annotation.Nullable;
import org.jetbrains.annotations.Contract;
Expand All @@ -18,7 +19,7 @@
*/
public class EqualityCheck {
private static final CallMatcher OBJECT_EQUALS = CallMatcher.anyOf(
CallMatcher.staticCall("java.util.Objects", "equals").parameterCount(2),
CallMatcher.staticCall(JavaClassNames.JAVA_UTIL_OBJECTS, "equals").parameterCount(2),
CallMatcher.staticCall("com.google.common.base.Objects", "equal").parameterCount(2));
private final
@Nonnull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
import static consulo.util.lang.ObjectUtil.tryCast;

public class ExpressionUtils {
static final Set<String> STRING_BUILDER_CLASS_NAMES = Set.of("java.lang.StringBuilder", "java.lang.StringBuffer");
static final Set<String> PRINT_CLASS_NAMES = Set.of("java.io.PrintStream", "java.io.PrintWriter");
static final Set<String> STRING_BUILDER_CLASS_NAMES = Set.of(JavaClassNames.JAVA_LANG_STRING_BUILDER, JavaClassNames.JAVA_LANG_STRING_BUFFER);
static final Set<String> PRINT_CLASS_NAMES = Set.of(JavaClassNames.JAVA_IO_PRINT_STREAM, JavaClassNames.JAVA_IO_PRINT_WRITER);
static final Set<String> PRINT_METHOD_NAMES = Set.of("print", "println");
static final Set<String> SLF4J_LOGGING_CLASS_NAMES = Set.of("org.slf4j.Logger");
static final Set<String> SLF4J_LOGGING_METHOD_NAMES = Set.of("trace", "debug", "info", "warn", "error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static boolean isCompareToIgnoreCase(@Nullable PsiMethod method) {
return false;
}
final PsiClassType stringType = TypeUtils.getStringType(method);
return methodMatches(method, "java.lang.String", PsiType.INT, "compareToIgnoreCase", stringType);
return methodMatches(method, JavaClassNames.JAVA_LANG_STRING, PsiType.INT, "compareToIgnoreCase", stringType);
}

@Contract("null -> false")
Expand Down Expand Up @@ -98,7 +98,7 @@ public static boolean isEqualsIgnoreCase(@Nullable PsiMethod method) {
return false;
}
final PsiClassType stringType = TypeUtils.getStringType(method);
return methodMatches(method, "java.lang.String", PsiType.BOOLEAN, HardcodedMethodConstants.EQUALS_IGNORE_CASE, stringType);
return methodMatches(method, JavaClassNames.JAVA_LANG_STRING, PsiType.BOOLEAN, HardcodedMethodConstants.EQUALS_IGNORE_CASE, stringType);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.intellij.java.language.psi.util.InheritanceUtil;
import com.intellij.java.language.psi.util.PropertyUtil;
import com.intellij.java.language.psi.util.PsiUtil;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.ast.IElementType;
import consulo.language.psi.PsiDirectory;
import consulo.language.psi.PsiElement;
Expand Down Expand Up @@ -332,7 +333,7 @@ private static boolean isSideEffectFreeConstructor(@Nonnull PsiNewExpression new

// all Throwable descendants from java.lang are side effects free
if (CommonClassNames.DEFAULT_PACKAGE.equals(packageName) || "java.io".equals(packageName)) {
PsiClass throwableClass = JavaPsiFacade.getInstance(aClass.getProject()).findClass("java.lang.Throwable", aClass.getResolveScope());
PsiClass throwableClass = JavaPsiFacade.getInstance(aClass.getProject()).findClass(JavaClassNames.JAVA_LANG_THROWABLE, aClass.getResolveScope());
if (throwableClass != null && InheritanceUtil.isInheritorOrSelf(aClass, throwableClass, true)) {
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,15 +245,19 @@ public static PsiType unaryNumericPromotion(PsiType type) {
if (type == null) {
return null;
}
if (type.equalsToText("java.lang.Byte") || type.equalsToText("java.lang.Short") ||
type.equalsToText("java.lang.Character") || type.equalsToText("java.lang.Integer") ||
type.equals(PsiType.BYTE) || type.equals(PsiType.SHORT) || type.equals(PsiType.CHAR)) {
if (type.equalsToText(JavaClassNames.JAVA_LANG_BYTE)
|| type.equalsToText(JavaClassNames.JAVA_LANG_SHORT)
|| type.equalsToText(JavaClassNames.JAVA_LANG_CHARACTER)
|| type.equalsToText(JavaClassNames.JAVA_LANG_INTEGER)
|| type.equals(PsiType.BYTE)
|| type.equals(PsiType.SHORT)
|| type.equals(PsiType.CHAR)) {
return PsiType.INT;
} else if (type.equalsToText("java.lang.Long")) {
} else if (type.equalsToText(JavaClassNames.JAVA_LANG_LONG)) {
return PsiType.LONG;
} else if (type.equalsToText("java.lang.Float")) {
} else if (type.equalsToText(JavaClassNames.JAVA_LANG_FLOAT)) {
return PsiType.FLOAT;
} else if (type.equalsToText("java.lang.Double")) {
} else if (type.equalsToText(JavaClassNames.JAVA_LANG_DOUBLE)) {
return PsiType.DOUBLE;
}
return type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.intellij.java.language.psi.*;
import com.intellij.java.language.psi.util.PropertyUtil;
import consulo.annotation.component.ExtensionImpl;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.editor.inspection.ProblemHighlightType;
import consulo.language.editor.inspection.ProblemsHolder;
import consulo.language.psi.PsiElement;
Expand Down Expand Up @@ -158,10 +159,10 @@ private boolean usesReflection(PsiMethod method) {
}
@NonNls final String qualifiedName = containingClass.getQualifiedName();
if ("getDeclaredFields".equals(name)) {
return "java.lang.Class".equals(qualifiedName);
return JavaClassNames.JAVA_LANG_CLASS.equals(qualifiedName);
} else if ("toString".equals(name)) {
return "org.apache.commons.lang.builder.ReflectionToStringBuilder".equals(qualifiedName) ||
"java.util.Objects".equals(qualifiedName);
JavaClassNames.JAVA_UTIL_OBJECTS.equals(qualifiedName);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.intellij.java.language.psi.util.InheritanceUtil;
import com.intellij.java.language.psi.util.PropertyUtil;
import com.intellij.java.language.psi.util.PsiUtil;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.codeStyle.CodeStyleManager;
import consulo.language.psi.PsiComment;
import consulo.language.psi.PsiElement;
Expand Down Expand Up @@ -134,7 +135,7 @@ public static boolean isStringArrayType(PsiType type) {
* @return true if it's a Collection type.
*/
public static boolean isCollectionType(PsiElementFactory factory, PsiType type) {
return isTypeOf(factory, type, "java.util.Collection");
return isTypeOf(factory, type, JAVA_UTIL_COLLECTION);
}

/**
Expand Down Expand Up @@ -200,7 +201,7 @@ public static boolean isObjectType(PsiElementFactory factory, PsiType type) {
* @return true if it's a Date type.
*/
public static boolean isDateType(PsiElementFactory factory, PsiType type) {
return isTypeOf(factory, type, "java.util.Date");
return isTypeOf(factory, type, JAVA_UTIL_DATE);
}

/**
Expand All @@ -211,7 +212,7 @@ public static boolean isDateType(PsiElementFactory factory, PsiType type) {
* @return true if it's a Calendar type.
*/
public static boolean isCalendarType(PsiElementFactory factory, PsiType type) {
return isTypeOf(factory, type, "java.util.Calendar");
return isTypeOf(factory, type, JAVA_UTIL_CALENDAR);
}

/**
Expand Down Expand Up @@ -246,7 +247,7 @@ public static boolean isNumericType(PsiElementFactory factory, PsiType type) {
return "byte".equals(s) || "double".equals(s) || "float".equals(s) || "int".equals(s) || "long".equals(s) || "short".equals(s);
} else {
// test for Object type of numeric
return isTypeOf(factory, type, "java.lang.Number");
return isTypeOf(factory, type, JAVA_LANG_NUMBER);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.siyeh.ig.imports;

import com.siyeh.ig.IGInspectionTestCase;
import consulo.java.language.module.util.JavaClassNames;

public class StaticImportInspectionTest extends IGInspectionTestCase {

public void test() throws Exception {
final StaticImportInspection tool = new StaticImportInspection();
tool.allowedClasses.add("java.util.Map");
tool.allowedClasses.add(JavaClassNames.JAVA_UTIL_MAP);
doTest("com/siyeh/igtest/imports/static_import", tool);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.siyeh.ig.threading;

import com.siyeh.ig.IGInspectionTestCase;
import consulo.java.language.module.util.JavaClassNames;

public class AccessToStaticFieldLockedOnInstanceInspectionTest extends IGInspectionTestCase {

public void test() throws Exception {
final AccessToStaticFieldLockedOnInstanceInspection tool = new AccessToStaticFieldLockedOnInstanceInspection();
tool.ignoredClasses.add("java.util.List");
tool.ignoredClasses.add(JavaClassNames.JAVA_UTIL_LIST);
doTest("com/siyeh/igtest/threading/access_to_static_field_locked_on_instance_data", tool);
}
}
Loading
Loading