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 @@ -13,7 +13,6 @@
import com.siyeh.ig.psiutils.CommentTracker;
import consulo.annotation.access.RequiredReadAction;
import consulo.java.analysis.localize.JavaAnalysisLocalize;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.editor.WriteCommandAction;
import consulo.language.editor.inspection.LocalQuickFixOnPsiElement;
import consulo.language.editor.intention.BaseIntentionAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.intellij.java.language.psi.util.PsiUtil;
import consulo.annotation.access.RequiredReadAction;
import consulo.java.language.module.extension.JavaModuleExtension;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.psi.PsiElement;
import consulo.language.util.ModuleUtilCore;
import consulo.util.lang.ObjectUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import com.intellij.java.language.psi.*;
import com.intellij.java.language.psi.util.InheritanceUtil;
import consulo.annotation.component.ExtensionImpl;
import consulo.java.language.module.util.JavaClassNames;
import consulo.language.editor.inspection.LocalInspectionToolSession;
import consulo.language.editor.inspection.ProblemHighlightType;
import consulo.language.editor.inspection.ProblemsHolder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@
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;
import consulo.language.psi.PsiElementVisitor;
import jakarta.annotation.Nonnull;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.java.generate.GenerateToStringContext;
import org.jetbrains.java.generate.GenerateToStringUtils;

import jakarta.annotation.Nonnull;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +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.annotation.access.RequiredReadAction;
import consulo.language.codeStyle.CodeStyleManager;
import consulo.language.psi.PsiComment;
import consulo.language.psi.PsiElement;
Expand All @@ -33,11 +33,9 @@
import consulo.util.collection.ArrayUtil;
import consulo.util.lang.StringUtil;
import jakarta.annotation.Nonnull;

import jakarta.annotation.Nullable;
import java.util.*;

import static consulo.java.language.module.util.JavaClassNames.*;
import java.util.*;

/**
* Basic PSI Adapter with common function that works in all supported versions of IDEA.
Expand Down Expand Up @@ -120,11 +118,7 @@ public static boolean isObjectArrayType(PsiType type) {
* @return true if it's a String array type.
*/
public static boolean isStringArrayType(PsiType type) {
if (isPrimitiveType(type)) {
return false;
}

return type.getCanonicalText().indexOf("String[]") > 0;
return !isPrimitiveType(type) && type.getCanonicalText().indexOf("String[]") > 0;
}

/**
Expand All @@ -135,7 +129,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, CommonClassNames.JAVA_UTIL_COLLECTION);
}

/**
Expand All @@ -146,7 +140,7 @@ public static boolean isCollectionType(PsiElementFactory factory, PsiType type)
* @return true if it's a Map type.
*/
public static boolean isMapType(PsiElementFactory factory, PsiType type) {
return isTypeOf(factory, type, JAVA_UTIL_MAP);
return isTypeOf(factory, type, CommonClassNames.JAVA_UTIL_MAP);
}

/**
Expand All @@ -157,7 +151,7 @@ public static boolean isMapType(PsiElementFactory factory, PsiType type) {
* @return true if it's a Map type.
*/
public static boolean isSetType(PsiElementFactory factory, PsiType type) {
return isTypeOf(factory, type, JAVA_UTIL_SET);
return isTypeOf(factory, type, CommonClassNames.JAVA_UTIL_SET);
}

/**
Expand All @@ -168,7 +162,7 @@ public static boolean isSetType(PsiElementFactory factory, PsiType type) {
* @return true if it's a Map type.
*/
public static boolean isListType(PsiElementFactory factory, PsiType type) {
return isTypeOf(factory, type, JAVA_UTIL_LIST);
return isTypeOf(factory, type, CommonClassNames.JAVA_UTIL_LIST);
}

/**
Expand All @@ -179,7 +173,7 @@ public static boolean isListType(PsiElementFactory factory, PsiType type) {
* @return true if it's a String type.
*/
public static boolean isStringType(PsiElementFactory factory, PsiType type) {
return isTypeOf(factory, type, JAVA_LANG_STRING);
return isTypeOf(factory, type, CommonClassNames.JAVA_LANG_STRING);
}

/**
Expand All @@ -190,7 +184,7 @@ public static boolean isStringType(PsiElementFactory factory, PsiType type) {
* @return true if it's an Object type.
*/
public static boolean isObjectType(PsiElementFactory factory, PsiType type) {
return isTypeOf(factory, type, JAVA_LANG_OBJECT);
return isTypeOf(factory, type, CommonClassNames.JAVA_LANG_OBJECT);
}

/**
Expand All @@ -201,7 +195,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, CommonClassNames.JAVA_UTIL_DATE);
}

/**
Expand All @@ -212,7 +206,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, CommonClassNames.JAVA_UTIL_CALENDAR);
}

/**
Expand All @@ -229,7 +223,7 @@ public static boolean isBooleanType(PsiElementFactory factory, PsiType type) {
return "boolean".equals(s);
} else {
// test for Object type of Boolean
return isTypeOf(factory, type, JAVA_LANG_BOOLEAN);
return isTypeOf(factory, type, CommonClassNames.JAVA_LANG_BOOLEAN);
}
}

Expand All @@ -247,7 +241,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, CommonClassNames.JAVA_LANG_NUMBER);
}
}

Expand All @@ -258,6 +252,7 @@ public static boolean isNumericType(PsiElementFactory factory, PsiType type) {
* @param importStatement import statement to test existing for.
* @return true if the javafile has the import statement.
*/
@RequiredReadAction
public static boolean hasImportStatement(PsiJavaFile javaFile, String importStatement) {
PsiImportList importList = javaFile.getImportList();
if (importList == null) {
Expand All @@ -278,6 +273,7 @@ public static boolean hasImportStatement(PsiJavaFile javaFile, String importStat
* @param importStatementOnDemand name of import statement, must be with a wildcard (etc. java.util.*).
* @throws IncorrectOperationException is thrown if there is an error creating the import statement.
*/
@RequiredReadAction
public static void addImportStatement(PsiJavaFile javaFile, String importStatementOnDemand) {
PsiElementFactory factory = JavaPsiFacade.getInstance(javaFile.getProject()).getElementFactory();
PsiImportStatement is = factory.createImportStatementOnDemand(fixImportStatement(importStatementOnDemand));
Expand Down Expand Up @@ -373,12 +369,12 @@ public static PsiMethod findPublicStaticVoidMainMethod(PsiClass clazz) {
// is it public static void main(String[] args)
for (PsiMethod method : methods) {
// must be public
if (!method.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!method.isPublic()) {
continue;
}

// must be static
if (!method.hasModifierProperty(PsiModifier.STATIC)) {
if (!method.isStatic()) {
continue;
}

Expand Down Expand Up @@ -417,8 +413,9 @@ public static PsiMethod findPublicStaticVoidMainMethod(PsiClass clazz) {
* @throws IncorrectOperationException is thrown if error adding/replacing the javadoc comment.
*/
@Nullable
@RequiredReadAction
public static PsiComment addOrReplaceJavadoc(PsiMethod method, String javadoc, boolean replace) {
final Project project = method.getProject();
Project project = method.getProject();
PsiElementFactory factory = JavaPsiFacade.getInstance(project).getElementFactory();
PsiComment comment = factory.createCommentFromText(javadoc, null);

Expand All @@ -428,7 +425,7 @@ public static PsiComment addOrReplaceJavadoc(PsiMethod method, String javadoc, b
if (replace) {
// javadoc already exists, so replace
doc.replace(comment);
final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
codeStyleManager.reformat(method); // to reformat javadoc
return comment;
} else {
Expand All @@ -438,7 +435,7 @@ public static PsiComment addOrReplaceJavadoc(PsiMethod method, String javadoc, b
} else {
// add new javadoc
method.addBefore(comment, method.getFirstChild());
final CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
CodeStyleManager codeStyleManager = CodeStyleManager.getInstance(project);
codeStyleManager.reformat(method); // to reformat javadoc
return comment;
}
Expand Down Expand Up @@ -468,11 +465,8 @@ public static boolean isGetterMethod(PsiMethod method) {
if (isTypeOfVoid(method.getReturnType())) {
return false;
}
final PsiParameterList parameterList = method.getParameterList();
if (parameterList.getParametersCount() != 0) {
return false;
}
return true;
PsiParameterList parameterList = method.getParameterList();
return parameterList.getParametersCount() == 0;
}

/**
Expand Down Expand Up @@ -510,8 +504,8 @@ public static boolean isEnumField(PsiField field) {
if (!(type instanceof PsiClassType)) {
return false;
}
final PsiClassType classType = (PsiClassType) type;
final PsiClass aClass = classType.resolve();
PsiClassType classType = (PsiClassType) type;
PsiClass aClass = classType.resolve();
return (aClass != null) && aClass.isEnum();
}

Expand All @@ -522,7 +516,7 @@ public static boolean isEnumField(PsiField field) {
* @return true if class is an exception.
*/
public static boolean isExceptionClass(PsiClass clazz) {
return InheritanceUtil.isInheritor(clazz, JAVA_LANG_THROWABLE);
return InheritanceUtil.isInheritor(clazz, CommonClassNames.JAVA_LANG_THROWABLE);
}

/**
Expand All @@ -538,12 +532,12 @@ public static PsiMethod findEqualsMethod(PsiClass clazz) {
// is it public boolean equals(Object o)
for (PsiMethod method : methods) {
// must be public
if (!method.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!method.isPublic()) {
continue;
}

// must not be static
if (method.hasModifierProperty(PsiModifier.STATIC)) {
if (method.isStatic()) {
continue;
}

Expand All @@ -560,7 +554,7 @@ public static PsiMethod findEqualsMethod(PsiClass clazz) {
}

// parameter must be Object
if (!(parameters[0].getType().getCanonicalText().equals(JAVA_LANG_OBJECT))) {
if (!(parameters[0].getType().getCanonicalText().equals(CommonClassNames.JAVA_LANG_OBJECT))) {
continue;
}

Expand All @@ -585,12 +579,12 @@ public static PsiMethod findHashCodeMethod(PsiClass clazz) {
// is it public int hashCode()
for (PsiMethod method : methods) {
// must be public
if (!method.hasModifierProperty(PsiModifier.PUBLIC)) {
if (!method.isPublic()) {
continue;
}

// must not be static
if (method.hasModifierProperty(PsiModifier.STATIC)) {
if (method.isStatic()) {
continue;
}

Expand Down Expand Up @@ -646,6 +640,7 @@ protected static boolean isTypeOf(PsiElementFactory factory, PsiType type, Strin
* @param clazz the class
* @return the names.
*/
@RequiredReadAction
public static String[] getImplementsClassnames(PsiClass clazz) {
PsiClass[] interfaces = clazz.getInterfaces();

Expand All @@ -672,6 +667,7 @@ public static boolean isPrimitiveType(PsiType type) {
return type instanceof PsiPrimitiveType;
}

@RequiredReadAction
public static int getJavaVersion(@Nonnull PsiElement element) {
JavaSdkVersion sdkVersion = JavaVersionService.getInstance().getJavaSdkVersion(element);
if (sdkVersion == null) {
Expand Down Expand Up @@ -716,7 +712,7 @@ public static boolean isNestedArray(PsiType aType) {
if (!(aType instanceof PsiArrayType)) {
return false;
}
final PsiType componentType = ((PsiArrayType) aType).getComponentType();
PsiType componentType = ((PsiArrayType) aType).getComponentType();
return componentType instanceof PsiArrayType;
}
}
Loading
Loading