mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
`verboseOnly` added to call some code only if appropriate env var is set.
Some checks may be heavy, but required to debug hard-to-find bugs. You may run code with out them, and enable em with ``_PYCHARM_VERBOSE_MODE``
This commit is contained in:
@@ -858,6 +858,16 @@ public class PyUtil {
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes code only if <pre>_PYCHARM_VERBOSE_MODE</pre> is set in env (which should be done for debug purposes only)
|
||||
* @param runnable code to call
|
||||
*/
|
||||
public static void verboseOnly(@NotNull final Runnable runnable) {
|
||||
if (System.getenv().get("_PYCHARM_VERBOSE_MODE") != null) {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
public static class KnownDecoratorProviderHolder {
|
||||
public static PyKnownDecoratorProvider[] KNOWN_DECORATOR_PROVIDERS = Extensions.getExtensions(PyKnownDecoratorProvider.EP_NAME);
|
||||
|
||||
|
||||
@@ -17,7 +17,6 @@ package com.jetbrains.python.psi.impl;
|
||||
|
||||
import com.intellij.extapi.psi.StubBasedPsiElementBase;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.*;
|
||||
@@ -32,6 +31,7 @@ import com.jetbrains.python.PythonLanguage;
|
||||
import com.jetbrains.python.psi.PyElement;
|
||||
import com.jetbrains.python.psi.PyElementVisitor;
|
||||
import com.jetbrains.python.psi.PyReferenceOwner;
|
||||
import com.jetbrains.python.psi.PyUtil;
|
||||
import com.jetbrains.python.psi.resolve.PyResolveContext;
|
||||
import com.jetbrains.python.psi.types.TypeEvalContext;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -71,10 +71,7 @@ public class PyBaseElementImpl<T extends StubElement> extends StubBasedPsiElemen
|
||||
}
|
||||
|
||||
public void accept(@NotNull PsiElementVisitor visitor) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
// Good check, but too slow for production
|
||||
PyPsiUtils.assertValid(this);
|
||||
}
|
||||
PyUtil.verboseOnly(() -> PyPsiUtils.assertValid(this));
|
||||
if (visitor instanceof PyElementVisitor) {
|
||||
acceptPyVisitor(((PyElementVisitor)visitor));
|
||||
}
|
||||
|
||||
@@ -462,9 +462,7 @@ public class PyCallExpressionHelper {
|
||||
final PsiPolyVariantReference reference = ((PyReferenceExpression)callee).getReference(resolveContext);
|
||||
final List<PyType> members = new ArrayList<PyType>();
|
||||
for (PsiElement target : PyUtil.multiResolveTopPriority(reference)) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
PyPsiUtils.assertValid(target);
|
||||
}
|
||||
PyUtil.verboseOnly(() ->PyPsiUtils.assertValid(target));
|
||||
if (target != null) {
|
||||
final Ref<? extends PyType> typeRef = getCallTargetReturnType(call, target, context);
|
||||
if (typeRef != null) {
|
||||
|
||||
@@ -59,9 +59,7 @@ public class PyEvaluator {
|
||||
if (expr == null || myVisited.contains(expr)) {
|
||||
return null;
|
||||
}
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
PyPsiUtils.assertValid(expr);
|
||||
}
|
||||
PyUtil.verboseOnly(() ->PyPsiUtils.assertValid(expr));
|
||||
myVisited.add(expr);
|
||||
if (expr instanceof PyParenthesizedExpression) {
|
||||
return evaluate(((PyParenthesizedExpression)expr).getContainedExpression());
|
||||
|
||||
@@ -116,9 +116,7 @@ public class ResolveImportUtil {
|
||||
|
||||
@NotNull
|
||||
public static List<RatedResolveResult> multiResolveImportElement(PyImportElement importElement, @NotNull final QualifiedName qName) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
PyPsiUtils.assertValid(importElement);
|
||||
}
|
||||
PyUtil.verboseOnly(() ->PyPsiUtils.assertValid(importElement));
|
||||
final PyStatement importStatement = importElement.getContainingImportStatement();
|
||||
if (importStatement instanceof PyFromImportStatement) {
|
||||
return resolveNameInFromImport((PyFromImportStatement)importStatement, qName);
|
||||
|
||||
Reference in New Issue
Block a user