Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2012-07-23 12:25:06 +04:00
5 changed files with 32 additions and 17 deletions
+2 -2
View File
@@ -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();
}
@@ -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);
}
}
@@ -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.<PyType>create(PyBuiltinCache.getInstance(pyClass).getObjectType(PyNames.PROPERTY));
}
final Maybe<PyFunction> 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);
}
@@ -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<String, String> 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));
}
@@ -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<? extends VFileEvent> 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;