mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Simplify several methods in PyCharm utility classes
* Use Collections.addAll(xs, arr) instead of xs.addAll(Arrays.asList(arr)) * QualifiedName#toString is the same as StringUtil.join(qn.getComponents(), ".") * PyUtil.as is the same as ObjectUtils.tryCast * Several methods in PyUtil contain redundant trailing conditions
This commit is contained in:
@@ -50,10 +50,7 @@ import com.intellij.psi.tree.TokenSet;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.QualifiedName;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.PlatformIcons;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.jetbrains.NotNullPredicate;
|
||||
import com.jetbrains.python.PyBundle;
|
||||
@@ -847,13 +844,7 @@ public class PyUtil {
|
||||
@Nullable
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T as(@Nullable final Object expression, @NotNull final Class<T> clazz) {
|
||||
if (expression == null) {
|
||||
return null;
|
||||
}
|
||||
if (clazz.isAssignableFrom(expression.getClass())) {
|
||||
return (T)expression;
|
||||
}
|
||||
return null;
|
||||
return ObjectUtils.tryCast(expression, clazz);
|
||||
}
|
||||
|
||||
// TODO: Move to PsiElement?
|
||||
@@ -1165,8 +1156,8 @@ public class PyUtil {
|
||||
public static Collection<VirtualFile> getSourceRoots(@NotNull Module module) {
|
||||
final Set<VirtualFile> result = new LinkedHashSet<VirtualFile>();
|
||||
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
|
||||
result.addAll(Arrays.asList(manager.getSourceRoots()));
|
||||
result.addAll(Arrays.asList(manager.getContentRoots()));
|
||||
Collections.addAll(result, manager.getSourceRoots());
|
||||
Collections.addAll(result, manager.getContentRoots());
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -1708,10 +1699,7 @@ public class PyUtil {
|
||||
|
||||
private static boolean isObject(@NotNull final PyMemberInfo<PyElement> classMemberInfo) {
|
||||
final PyElement element = classMemberInfo.getMember();
|
||||
if ((element instanceof PyClass) && PyNames.OBJECT.equals(element.getName())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return (element instanceof PyClass) && PyNames.OBJECT.equals(element.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1751,10 +1739,7 @@ public class PyUtil {
|
||||
*/
|
||||
public static boolean isObjectClass(@NotNull PyClass cls) {
|
||||
final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(cls);
|
||||
if (cls == builtinCache.getClass(PyNames.OBJECT) || cls == builtinCache.getClass(PyNames.FAKE_OLD_BASE)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return cls == builtinCache.getClass(PyNames.OBJECT) || cls == builtinCache.getClass(PyNames.FAKE_OLD_BASE);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1768,9 +1753,6 @@ public class PyUtil {
|
||||
*/
|
||||
public static boolean isObjectType(@NotNull PyType type, @NotNull PsiElement anchor) {
|
||||
final PyBuiltinCache builtinCache = PyBuiltinCache.getInstance(anchor);
|
||||
if (type == builtinCache.getObjectType() || type == builtinCache.getOldstyleClassobjType()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return type == builtinCache.getObjectType() || type == builtinCache.getOldstyleClassobjType();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleUtilCore;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -175,7 +174,7 @@ public class ResolveImportUtil {
|
||||
if (qualifiedName == null || sourceFile == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
final String marker = StringUtil.join(qualifiedName.getComponents(), ".") + "#" + Integer.toString(relativeLevel);
|
||||
final String marker = qualifiedName + "#" + Integer.toString(relativeLevel);
|
||||
final Set<String> beingImported = ourBeingImported.get();
|
||||
if (beingImported.contains(marker)) {
|
||||
return Collections.emptyList(); // break endless loop in import
|
||||
|
||||
@@ -297,8 +297,8 @@ public class PyRefactoringUtil {
|
||||
final FindUsagesHandler handler = new PyFindUsagesHandlerFactory().createFindUsagesHandler(element, forHighlightUsages);
|
||||
assert handler != null;
|
||||
final List<PsiElement> elementsToProcess = new ArrayList<PsiElement>();
|
||||
elementsToProcess.addAll(Arrays.asList(handler.getPrimaryElements()));
|
||||
elementsToProcess.addAll(Arrays.asList(handler.getSecondaryElements()));
|
||||
Collections.addAll(elementsToProcess, handler.getPrimaryElements());
|
||||
Collections.addAll(elementsToProcess, handler.getSecondaryElements());
|
||||
for (PsiElement e : elementsToProcess) {
|
||||
handler.processElementUsages(e, new Processor<UsageInfo>() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user