Merge branch 'master' of git.labs.intellij.net:idea/ultimate

This commit is contained in:
Dmitry Jemerov
2010-12-17 12:32:18 +03:00
10 changed files with 121 additions and 22 deletions
+5 -1
View File
@@ -130,7 +130,11 @@ def buildDebuggerEgg(paths, buildName) {
fileset(dir: "$home/python/resources/debugger-egg/EGG-INFO")
}
ant.replace(file: "$eggDir/EGG-INFO/PKG-INFO") {
ant.replace(file: "$eggDir/pydev/PKG-INFO") {
replacefilter(token: "@@BUILD_NUMBER@@", value: buildName)
}
ant.replace(file: "$eggDir/pydev/pydevd_comm.py") {
replacefilter(token: "@@BUILD_NUMBER@@", value: buildName)
}
ant.zip(destfile: egg) {
+8 -3
View File
@@ -77,6 +77,7 @@ import pydevd_tracing
import pydevd_vm_type
import pydevd_file_utils
import traceback
from pydevd_utils import *
from pydevd_tracing import GetExceptionTracebackStr
@@ -141,7 +142,7 @@ ID_TO_MEANING = {
MAX_IO_MSG_SIZE = 1000 #if the io is too big, we'll not send all (could make the debugger too non-responsive)
#this number can be changed if there's need to do so
VERSION_STRING = "PYCHARM-1.1"
VERSION_STRING = "@@BUILD_NUMBER@@"
#--------------------------------------------------------------------------------------------------- UTILITIES
@@ -615,9 +616,13 @@ class InternalGetVariable(InternalThreadCommand):
valDict = pydevd_vars.resolveCompoundVariable(self.thread_id, self.frame_id, self.scope, self.attributes)
keys = valDict.keys()
if hasattr(keys, 'sort'):
keys.sort() #Python 3.0 does not have it
keys.sort(compare_object_attrs) #Python 3.0 does not have it
else:
keys = sorted(keys, key=str) #Jython 2.1 does not have it (and all must be compared as strings).
if (IS_PY3K):
keys = sorted(keys, key=cmp_to_key(compare_object_attrs)) #Jython 2.1 does not have it (and all must be compared as strings).
else:
keys = sorted(keys, cmp=compare_object_attrs) #Jython 2.1 does not have it (and all must be compared as strings).
for k in keys:
xml += pydevd_vars.varToXML(valDict[k], str(k))
+57
View File
@@ -0,0 +1,57 @@
from numbers import *
def to_number(x):
if isinstance(x, Number):
return x
if (isinstance(x, basestring)):
try:
n = float(x)
return n
except ValueError:
pass
l = x.find('(')
if (l != -1):
y = x[0:l-1]
#print y
try:
n = float(y)
return n
except ValueError:
pass
return None
def compare_object_attrs(x, y):
try:
x_num = to_number(x)
y_num = to_number(y)
if (x_num is not None and y_num is not None):
return int(x_num - y_num)
if ('__len__' == x):
return -1
if ('__len__' == y):
return 1
return x.__cmp__(y)
except:
return cmp(str(x), str(y))
def cmp_to_key(mycmp):
'Convert a cmp= function into a key= function'
class K(object):
def __init__(self, obj, *args):
self.obj = obj
def __lt__(self, other):
return mycmp(self.obj, other.obj) < 0
def __gt__(self, other):
return mycmp(self.obj, other.obj) > 0
def __eq__(self, other):
return mycmp(self.obj, other.obj) == 0
def __le__(self, other):
return mycmp(self.obj, other.obj) <= 0
def __ge__(self, other):
return mycmp(self.obj, other.obj) >= 0
def __ne__(self, other):
return mycmp(self.obj, other.obj) != 0
return K
@@ -133,7 +133,7 @@ public class PyDebugValue extends XValue {
}
catch (PyDebuggerException e) {
if (!node.isObsolete()) {
node.setErrorMessage("Unable to display children");
node.setErrorMessage("Unable to display children:" + e.getMessage());
}
LOG.warn(e);
}
@@ -157,4 +157,8 @@ public class PyDebugValue extends XValue {
return DebuggerIcons.VALUE_ICON;
}
}
boolean isException() {
return myValue.startsWith("Traceback (most recent call last):");
}
}
@@ -125,10 +125,6 @@ public class ProtocolParser {
value = value.substring(type.length() + 2);
}
if (value.startsWith("Traceback (most recent call last):")) { // convert traceback to exception
throw new PyDebuggerException(value);
}
return new PyDebugValue(name, type, value, "True".equals(isContainer));
}
@@ -59,8 +59,6 @@ public class PyConvertLambdaToFunctionIntention extends BaseIntentionAction {
functionBuilder.statement("return " + body.getText());
PyFunction function = functionBuilder.buildFunction(project);
PyFunction parentFunction = PsiTreeUtil.getTopmostParentOfType(lambdaExpression, PyFunction.class);
if (parentFunction != null ) {
PyClass parentClass = PsiTreeUtil.getTopmostParentOfType(parentFunction, PyClass.class);
@@ -3,6 +3,8 @@ package com.jetbrains.python.codeInsight.intentions;
import com.intellij.codeInsight.intention.impl.BaseIntentionAction;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiComment;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.IncorrectOperationException;
@@ -11,6 +13,8 @@ import com.jetbrains.python.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
/**
* User: catherine
* Intention to merge the if clauses in the case of nested ifs where only the inner if contains code (the outer if only contains the inner one)
@@ -37,10 +41,13 @@ public class PyJoinIfIntention extends BaseIntentionAction {
PyIfStatement expression =
PsiTreeUtil.getParentOfType(file.findElementAt(editor.getCaretModel().getOffset()), PyIfStatement.class);
PyIfStatement ifStatement = getIfStatement(expression);
PyStatement firstStatement = getFirstStatement(ifStatement);
if (firstStatement != null) {
if (((PyIfStatement)firstStatement).getElifParts().length != 0) return false;
if (((PyIfStatement)firstStatement).getElsePart() != null) return false;
PyStatementList stList = ((PyIfStatement)firstStatement).getIfPart().getStatementList();
if (stList != null)
if (stList.getStatements().length != 0)
@@ -59,11 +66,22 @@ public class PyJoinIfIntention extends BaseIntentionAction {
if (firstStatement != null && firstStatement instanceof PyIfStatement) {
PyExpression condition = ((PyIfStatement)firstStatement).getIfPart().getCondition();
PyElementGenerator elementGenerator = PyElementGenerator.getInstance(project);
PyExpression newCondition = elementGenerator.createExpressionFromText(ifStatement.getIfPart().getCondition().getText() + " and " + condition.getText());
PyExpression newCondition = elementGenerator.createExpressionFromText(
ifStatement.getIfPart().getCondition().getText() + " and " + condition.getText());
ifStatement.getIfPart().getCondition().replace(newCondition);
PyStatementList stList = ((PyIfStatement)firstStatement).getIfPart().getStatementList();
PyStatementList ifStatementList = ifStatement.getIfPart().getStatementList();
List<PsiComment> comments = PsiTreeUtil.getChildrenOfTypeAsList(ifStatement.getIfPart(), PsiComment.class);
comments.addAll(PsiTreeUtil.getChildrenOfTypeAsList(((PyIfStatement)firstStatement).getIfPart(), PsiComment.class));
comments.addAll(PsiTreeUtil.getChildrenOfTypeAsList(ifStatementList, PsiComment.class));
comments.addAll(PsiTreeUtil.getChildrenOfTypeAsList(stList, PsiComment.class));
for (PsiElement comm : comments) {
ifStatement.getIfPart().addBefore(comm, ifStatementList);
comm.delete();
}
ifStatementList.replace(stList);
}
}
@@ -8,6 +8,7 @@ import com.intellij.execution.process.ProcessListener;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.execution.ui.ExecutionConsole;
import com.intellij.openapi.application.ApplicationInfo;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.progress.Task;
@@ -124,6 +125,7 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
try {
myDebugger.waitForConnect();
handshake();
getSession().rebuildViews();
registerBreakpoints();
new RunCommand(myDebugger).execute();
}
@@ -142,8 +144,16 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
}
private void handshake() throws PyDebuggerException {
final String remoteVersion = myDebugger.handshake();
printToConsole("Connected to pydevd (version " + remoteVersion + ")\n", ConsoleViewContentType.SYSTEM_OUTPUT);
String remoteVersion = myDebugger.handshake();
String currentBuild = ApplicationInfo.getInstance().getBuild().asStringWithoutProductCode();
if ("@@BUILD_NUMBER@@".equals(remoteVersion)) {
remoteVersion = currentBuild;
}
printToConsole("Connected to pydev debugger (build " + remoteVersion + ")\n", ConsoleViewContentType.SYSTEM_OUTPUT);
if (!remoteVersion.equals(currentBuild)) {
printToConsole("Warning: wrong debugger version. Use pycharm-debugger.egg from PyCharm installation folder.", ConsoleViewContentType.ERROR_OUTPUT);
}
}
public void printToConsole(String text, ConsoleViewContentType contentType) {
@@ -431,10 +441,11 @@ public class PyDebugProcess extends XDebugProcess implements IPyDebugProcess, Pr
public String getCurrentStateMessage() {
if (getSession().isStopped()) {
return XDebuggerBundle.message("debugger.state.message.disconnected");
} else
if (myDebugger.isConnected()) {
}
else if (myDebugger.isConnected()) {
return XDebuggerBundle.message("debugger.state.message.connected");
} else {
}
else {
return "Waiting for connection...";
}
}
@@ -2,6 +2,7 @@ package com.jetbrains.python.inspections;
import com.intellij.codeInspection.ProblemsHolder;
import com.intellij.psi.PsiElementVisitor;
import com.intellij.psi.tree.TokenSet;
import com.jetbrains.python.PyBundle;
import com.jetbrains.python.PyTokenTypes;
import com.jetbrains.python.actions.AugmentedAssignmentQuickFix;
@@ -43,17 +44,19 @@ public class PyAugmentAssignmentInspection extends PyInspection {
PyExpression leftExpression = expression.getLeftExpression();
PyExpression rightExpression = expression.getRightExpression();
if (rightExpression != null) {
boolean changedParts = false;
if (rightExpression.getText().equals(target.getText())) {
PyExpression tmp = rightExpression;
rightExpression = leftExpression;
leftExpression = tmp;
changedParts = true;
}
PyElementType op = expression.getOperator();
if (PyTokenTypes.ADDITIVE_OPERATIONS.contains(op) ||
PyTokenTypes.MULTIPLICATIVE_OPERATIONS.contains(op) ||
PyTokenTypes.SHIFT_OPERATIONS.contains(op) ||
PyTokenTypes.BITWISE_OPERATIONS.contains(op) ||
op == PyTokenTypes.EXP) {
final TokenSet operations = TokenSet.create(PyTokenTypes.PLUS, PyTokenTypes.MINUS, PyTokenTypes.MULT,
PyTokenTypes.FLOORDIV, PyTokenTypes.DIV, PyTokenTypes.PERC, PyTokenTypes.AND, PyTokenTypes.OR,
PyTokenTypes.XOR, PyTokenTypes.LTLT, PyTokenTypes.GTGT, PyTokenTypes.EXP);
final TokenSet commutativeOperations = TokenSet.create(PyTokenTypes.PLUS, PyTokenTypes.MULT);
if ((operations.contains(op) && !changedParts) || (changedParts && commutativeOperations.contains(op))) {
if (leftExpression != null
&& (leftExpression instanceof PyReferenceExpression || leftExpression instanceof PySubscriptionExpression)) {
if (leftExpression.getText().equals(target.getText())) {
@@ -25,3 +25,6 @@ var_7 += 2
<warning descr="Assignment can be replaced with augmented assignment">x = x | 3</warning>
<warning descr="Assignment can be replaced with augmented assignment">x = x & 3</warning>
<warning descr="Assignment can be replaced with augmented assignment">x = x ^ 3</warning>
#PY-2514
dy = 1 - dy