diff --git a/python/src/com/jetbrains/python/PyNames.java b/python/src/com/jetbrains/python/PyNames.java index 5c975dbe48c0..42b0295216af 100644 --- a/python/src/com/jetbrains/python/PyNames.java +++ b/python/src/com/jetbrains/python/PyNames.java @@ -344,10 +344,10 @@ public class PyNames { * @return true iff name is not reserved and is a well-formed identifier. */ public static boolean isIdentifier(@NotNull @NonNls String name) { - return ! isReserved(name) && isIndentifierString(name); + return !isReserved(name) && isIdentifierString(name); } - public static boolean isIndentifierString(String name) { + public static boolean isIdentifierString(String name) { return IDENTIFIER_PATTERN.matcher(name).matches(); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyConstantExpressionEvaluator.java b/python/src/com/jetbrains/python/psi/impl/PyConstantExpressionEvaluator.java index 2c25016ff0ee..4f312f6b146d 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyConstantExpressionEvaluator.java +++ b/python/src/com/jetbrains/python/psi/impl/PyConstantExpressionEvaluator.java @@ -21,24 +21,37 @@ public class PyConstantExpressionEvaluator { final PyNumericLiteralExpression numericLiteral = (PyNumericLiteralExpression)expr; if (numericLiteral.isIntegerLiteral()) { final BigInteger value = numericLiteral.getBigIntegerValue(); - if ((long) value.intValue() == value.longValue()) { + if ((long)value.intValue() == value.longValue()) { return value.intValue(); } } } - if (expr instanceof PyBoolLiteralExpression){ + if (expr instanceof PyBoolLiteralExpression) { return ((PyBoolLiteralExpression)expr).getValue(); } - if (expr instanceof PyReferenceExpression){ + if (expr instanceof PyReferenceExpression) { final String text = expr.getText(); - if ("true".equals(text) || "True".equals(text)){ + if ("true".equals(text) || "True".equals(text)) { return true; } - if ("false".equals(text) || "False".equals(text)){ + if ("false".equals(text) || "False".equals(text)) { return false; } } return null; } + public static boolean evaluateBoolean(final PyExpression expr, boolean defaultValue) { + Object result = evaluate(expr); + if (result instanceof Boolean) { + return (Boolean)result; + } + else { + return defaultValue; + } + } + + public static boolean evaluateBoolean(final PyExpression expr) { + return evaluateBoolean(expr, true); + } } diff --git a/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java b/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java index 3d46ff9745ab..371fcec7dc1c 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java +++ b/python/src/com/jetbrains/python/psi/impl/PyReferenceExpressionImpl.java @@ -153,7 +153,7 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere } else if (ret == null && elt instanceof PyElement && target.isValidResult()) { // remember this result, but a further reference may be the next resolve result - ret = new QualifiedResolveResultImpl(target.getElement(), qualifiers, target instanceof ImplicitResolveResult); + ret = new QualifiedResolveResultImpl(elt, qualifiers, target instanceof ImplicitResolveResult); } } // all resolve results checked, reassignment not detected, nothing more to do @@ -232,7 +232,7 @@ public class PyReferenceExpressionImpl extends PyElementImpl implements PyRefere return Ref.create(PyBuiltinCache.getInstance(pyClass).getObjectType(PyNames.PROPERTY)); } final Maybe accessor = property.getByDirection(AccessDirection.of(this)); - final PyFunction function = accessor.value(); + final PyFunction function = accessor.valueOrNull(); final PyType type = (function != null) ? function.getReturnType(context, this) : null; return Ref.create(type); } diff --git a/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionManipulator.java b/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionManipulator.java index baebcc625e78..fd7eabf5e07d 100644 --- a/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionManipulator.java +++ b/python/src/com/jetbrains/python/psi/impl/PyStringLiteralExpressionManipulator.java @@ -1,6 +1,7 @@ package com.jetbrains.python.psi.impl; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.TextRange; import com.intellij.psi.AbstractElementManipulator; import com.jetbrains.python.PythonStringUtil; @@ -13,10 +14,14 @@ public class PyStringLiteralExpressionManipulator extends AbstractElementManipul private static final Logger LOG = Logger.getInstance(PyStringLiteralExpressionManipulator.class); public PyStringLiteralExpressionImpl handleContentChange(PyStringLiteralExpressionImpl element, TextRange range, String newContent) { - String newName = range.replace(element.getText(), newContent); - if (!PythonStringUtil.isQuoted(newName)) { - LOG.error("Should be quoted: " + newName); + Pair quotes = PythonStringUtil.getQuotes(range.substring(element.getText())); + + if (quotes != null) { + range = TextRange.create(range.getStartOffset() + quotes.first.length(), range.getEndOffset() - quotes.second.length()); } + + String newName = range.replace(element.getText(), newContent); + return (PyStringLiteralExpressionImpl)element .replace(PyElementGenerator.getInstance(element.getProject()).createStringLiteralAlreadyEscaped(newName)); } diff --git a/python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java b/python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java index c4c4fd5fcd7b..221f353f2789 100644 --- a/python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java +++ b/python/src/com/jetbrains/python/testing/VFSTestFrameworkListener.java @@ -8,7 +8,6 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.openapi.vfs.newvfs.BulkFileListener; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; @@ -56,9 +55,7 @@ public class VFSTestFrameworkListener implements ApplicationComponent, Persisten @Override public void after(@NotNull List events) { for (VFileEvent event : events) { - VirtualFile vFile = event.getFile(); - if (vFile == null) continue; - String path = vFile.getUrl().toLowerCase(); + String path = event.getPath(); boolean containsNose = path.contains(PyNames.NOSE_TEST); boolean containsPy = path.contains("py-1") || path.contains(PyNames.PY_TEST); boolean containsAt = path.contains(PyNames.AT_TEST); @@ -66,7 +63,7 @@ public class VFSTestFrameworkListener implements ApplicationComponent, Persisten SDKLOOP: for (Sdk sdk : PythonSdkType.getAllSdks()) { for (String root : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) { - if (vFile.getUrl().contains(root)) { + if (path.contains(root)) { if (containsNose) { updateTestFrameworks(sdk.getHomePath(), NOSETESTSEARCHER, PyNames.NOSE_TEST); break SDKLOOP;