Merge remote-tracking branch 'origin/master'

This commit is contained in:
Ekaterina Tuzova
2014-11-06 16:00:10 +03:00
14 changed files with 370 additions and 242 deletions
@@ -246,20 +246,24 @@ public class BuildDataManager implements StorageOwner {
finally {
try {
closeSourceToOutputStorages();
myOutputToTargetRegistry.close();
}
finally {
try {
closeStorage(mySrcToFormMap);
myOutputToTargetRegistry.close();
}
finally {
final Mappings mappings = myMappings;
if (mappings != null) {
try {
mappings.close();
}
catch (BuildDataCorruptedException e) {
throw e.getCause();
try {
closeStorage(mySrcToFormMap);
}
finally {
final Mappings mappings = myMappings;
if (mappings != null) {
try {
mappings.close();
}
catch (BuildDataCorruptedException e) {
throw e.getCause();
}
}
}
}
@@ -23,7 +23,8 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.Result;
import com.intellij.openapi.application.WriteAction;
import com.intellij.openapi.command.WriteCommandAction;
import com.intellij.openapi.compiler.*;
import com.intellij.openapi.compiler.CompileScope;
import com.intellij.openapi.compiler.CompilerMessage;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleType;
@@ -32,8 +33,12 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.projectRoots.Sdk;
import com.intellij.openapi.projectRoots.impl.JavaAwareProjectJdkTableImpl;
import com.intellij.openapi.roots.ModuleRootModificationUtil;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.ByteSequence;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.io.FileUtilRt;
import com.intellij.openapi.vfs.JarFileSystem;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.vfs.VirtualFile;
@@ -50,12 +55,15 @@ import org.junit.After;
import org.junit.Before;
import java.awt.*;
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.List;
import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.Manifest;
/**
* @author Vladislav.Soroka
@@ -337,6 +345,39 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase {
return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
}
@NotNull
protected VirtualFile createProjectJarSubFile(String relativePath, Pair<ByteSequence, String>... contentEntries) throws IOException {
assertTrue("Use 'jar' extension for JAR files: '" + relativePath + "'", FileUtilRt.extensionEquals(relativePath, "jar"));
File f = new File(getProjectPath(), relativePath);
FileUtil.ensureExists(f.getParentFile());
FileUtil.ensureCanCreateFile(f);
final boolean created = f.createNewFile();
if (!created) {
throw new AssertionError("Unable to create the project sub file: " + f.getAbsolutePath());
}
Manifest manifest = new Manifest();
manifest.getMainAttributes().put(Attributes.Name.MANIFEST_VERSION, "1.0");
JarOutputStream target = new JarOutputStream(new FileOutputStream(f), manifest);
for (Pair<ByteSequence, String> contentEntry : contentEntries) {
addJarEntry(contentEntry.first.getBytes(), contentEntry.second, target);
}
target.close();
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(f);
assertNotNull(virtualFile);
final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(virtualFile);
assertNotNull(jarFile);
return jarFile;
}
private static void addJarEntry(byte[] bytes, String path, JarOutputStream target) throws IOException {
JarEntry entry = new JarEntry(path.replace("\\", "/"));
target.putNextEntry(entry);
target.write(bytes);
target.close();
}
protected VirtualFile createProjectSubFile(String relativePath, String content) throws IOException {
VirtualFile file = createProjectSubFile(relativePath);
setFileContent(file, content, false);
+2 -14
View File
@@ -250,23 +250,11 @@ public class JBColor extends Color {
public static final Color CYAN = cyan;
public static Color foreground() {
return new JBColor(new NotNullProducer<Color>() {
@NotNull
@Override
public Color produce() {
return UIUtil.getLabelForeground();
}
});
return UIUtil.getLabelForeground();
}
public static Color background() {
return new JBColor(new NotNullProducer<Color>() {
@NotNull
@Override
public Color produce() {
return UIUtil.getListBackground();
}
});
return UIUtil.getListBackground();
}
public static Color border() {
@@ -680,11 +680,11 @@ public class UIUtil {
}
public static Color getLabelBackground() {
return UIManager.getColor("Label.background");
return getColor("Label.background");
}
public static Color getLabelForeground() {
return UIManager.getColor("Label.foreground");
return getColor("Label.foreground");
}
public static Color getLabelDisabledForeground() {
@@ -734,11 +734,11 @@ public class UIUtil {
}
public static Color getTableHeaderBackground() {
return UIManager.getColor("TableHeader.background");
return getColor("TableHeader.background");
}
public static Color getTreeTextForeground() {
return UIManager.getColor("Tree.textForeground");
return getColor("Tree.textForeground");
}
public static Color getTreeSelectionBackground() {
@@ -748,23 +748,22 @@ public class UIUtil {
color = UIManager.getColor("nimbusSelectionBackground");
if (color != null) return color;
}
return UIManager.getColor("Tree.selectionBackground");
return getColor("Tree.selectionBackground");
}
public static Color getTreeTextBackground() {
return UIManager.getColor("Tree.textBackground");
return getColor("Tree.textBackground");
}
public static Color getListSelectionForeground() {
final Color color = UIManager.getColor("List.selectionForeground");
if (color == null) {
if (isUnderNimbusLookAndFeel()) {
return UIManager.getColor("List[Selected].textForeground"); // Nimbus
}
return color;
return getColor("List.selectionForeground");
}
public static Color getFieldForegroundColor() {
return UIManager.getColor("field.foreground");
return getColor("field.foreground");
}
public static Color getTableSelectionBackground() {
@@ -774,11 +773,23 @@ public class UIUtil {
color = UIManager.getColor("nimbusSelectionBackground");
if (color != null) return color;
}
return UIManager.getColor("Table.selectionBackground");
return getColor("Table.selectionBackground");
}
public static Color getActiveTextColor() {
return UIManager.getColor("textActiveText");
return getColor("textActiveText");
}
@NotNull
private static Color getColor(final String property) {
return new JBColor(new NotNullProducer<Color>() {
@NotNull
@Override
public Color produce() {
final Color color = UIManager.getColor(property);
return color == null ? Gray.TRANSPARENT : color;
}
});
}
public static Color getInactiveTextColor() {
@@ -798,7 +809,7 @@ public class UIUtil {
}
public static Color getInactiveTextFieldBackgroundColor() {
return UIManager.getColor("TextField.inactiveBackground");
return getColor("TextField.inactiveBackground");
}
public static Font getTreeFont() {
@@ -810,7 +821,7 @@ public class UIUtil {
}
public static Color getTreeSelectionForeground() {
return UIManager.getColor("Tree.selectionForeground");
return getColor("Tree.selectionForeground");
}
/**
@@ -829,7 +840,7 @@ public class UIUtil {
}
public static Color getTreeSelectionBorderColor() {
return UIManager.getColor("Tree.selectionBorderColor");
return getColor("Tree.selectionBorderColor");
}
public static int getTreeRightChildIndent() {
@@ -841,23 +852,23 @@ public class UIUtil {
}
public static Color getToolTipBackground() {
return UIManager.getColor("ToolTip.background");
return getColor("ToolTip.background");
}
public static Color getToolTipForeground() {
return UIManager.getColor("ToolTip.foreground");
return getColor("ToolTip.foreground");
}
public static Color getComboBoxDisabledForeground() {
return UIManager.getColor("ComboBox.disabledForeground");
return getColor("ComboBox.disabledForeground");
}
public static Color getComboBoxDisabledBackground() {
return UIManager.getColor("ComboBox.disabledBackground");
return getColor("ComboBox.disabledBackground");
}
public static Color getButtonSelectColor() {
return UIManager.getColor("Button.select");
return getColor("Button.select");
}
public static Integer getPropertyMaxGutterIconWidth(final String propertyPrefix) {
@@ -865,7 +876,7 @@ public class UIUtil {
}
public static Color getMenuItemDisabledForeground() {
return UIManager.getColor("MenuItem.disabledForeground");
return getColor("MenuItem.disabledForeground");
}
public static Object getMenuItemDisabledForegroundObject() {
@@ -882,7 +893,7 @@ public class UIUtil {
public static Color getTableBackground() {
// Under GTK+ L&F "Table.background" often has main panel color, which looks ugly
return isUnderGTKLookAndFeel() ? getTreeTextBackground() : UIManager.getColor("Table.background");
return isUnderGTKLookAndFeel() ? getTreeTextBackground() : getColor("Table.background");
}
public static Color getTableBackground(final boolean isSelected) {
@@ -893,11 +904,11 @@ public class UIUtil {
if (isUnderNimbusLookAndFeel()) {
return UIManager.getColor("Table[Enabled+Selected].textForeground");
}
return UIManager.getColor("Table.selectionForeground");
return getColor("Table.selectionForeground");
}
public static Color getTableForeground() {
return UIManager.getColor("Table.foreground");
return getColor("Table.foreground");
}
public static Color getTableForeground(final boolean isSelected) {
@@ -905,7 +916,7 @@ public class UIUtil {
}
public static Color getTableGridColor() {
return UIManager.getColor("Table.gridColor");
return getColor("Table.gridColor");
}
public static Color getListBackground() {
@@ -915,7 +926,7 @@ public class UIUtil {
return new Color(color.getRed(), color.getGreen(), color.getBlue(), color.getAlpha());
}
// Under GTK+ L&F "Table.background" often has main panel color, which looks ugly
return isUnderGTKLookAndFeel() ? getTreeTextBackground() : UIManager.getColor("List.background");
return isUnderGTKLookAndFeel() ? getTreeTextBackground() : getColor("List.background");
}
public static Color getListBackground(boolean isSelected) {
@@ -923,7 +934,7 @@ public class UIUtil {
}
public static Color getListForeground() {
return UIManager.getColor("List.foreground");
return getColor("List.foreground");
}
public static Color getListForeground(boolean isSelected) {
@@ -931,26 +942,26 @@ public class UIUtil {
}
public static Color getPanelBackground() {
return UIManager.getColor("Panel.background");
return getColor("Panel.background");
}
public static Color getTreeBackground() {
return UIManager.getColor("Tree.background");
return getColor("Tree.background");
}
public static Color getTreeForeground() {
return UIManager.getColor("Tree.foreground");
return getColor("Tree.foreground");
}
public static Color getTableFocusCellBackground() {
return UIManager.getColor(TABLE_FOCUS_CELL_BACKGROUND_PROPERTY);
return getColor(TABLE_FOCUS_CELL_BACKGROUND_PROPERTY);
}
public static Color getListSelectionBackground() {
if (isUnderNimbusLookAndFeel()) {
return UIManager.getColor("List[Selected].textBackground"); // Nimbus
}
return UIManager.getColor("List.selectionBackground");
return getColor("List.selectionBackground");
}
public static Color getListUnfocusedSelectionBackground() {
@@ -967,11 +978,11 @@ public class UIUtil {
}
public static Color getTextFieldForeground() {
return UIManager.getColor("TextField.foreground");
return getColor("TextField.foreground");
}
public static Color getTextFieldBackground() {
return isUnderGTKLookAndFeel() ? UIManager.getColor("EditorPane.background") : UIManager.getColor("TextField.background");
return isUnderGTKLookAndFeel() ? UIManager.getColor("EditorPane.background") : getColor("TextField.background");
}
public static Font getButtonFont() {
@@ -983,7 +994,7 @@ public class UIUtil {
}
public static Color getTabbedPaneBackground() {
return UIManager.getColor("TabbedPane.background");
return getColor("TabbedPane.background");
}
public static void setSliderIsFilled(final JSlider slider, final boolean value) {
@@ -991,11 +1002,11 @@ public class UIUtil {
}
public static Color getLabelTextForeground() {
return UIManager.getColor("Label.textForeground");
return getColor("Label.textForeground");
}
public static Color getControlColor() {
return UIManager.getColor("control");
return getColor("control");
}
public static Font getOptionPaneMessageFont() {
@@ -1007,19 +1018,19 @@ public class UIUtil {
}
public static Color getSeparatorForeground() {
return UIManager.getColor("Separator.foreground");
return getColor("Separator.foreground");
}
public static Color getSeparatorBackground() {
return UIManager.getColor("Separator.background");
return getColor("Separator.background");
}
public static Color getSeparatorShadow() {
return UIManager.getColor("Separator.shadow");
return getColor("Separator.shadow");
}
public static Color getSeparatorHighlight() {
return UIManager.getColor("Separator.highlight");
return getColor("Separator.highlight");
}
public static Color getSeparatorColorUnderNimbus() {
@@ -1054,7 +1065,7 @@ public class UIUtil {
}
public static Color getTableFocusCellForeground() {
return UIManager.getColor("Table.focusCellForeground");
return getColor("Table.focusCellForeground");
}
/**
@@ -1149,15 +1160,15 @@ public class UIUtil {
}
public static Color getWindowColor() {
return UIManager.getColor("window");
return getColor("window");
}
public static Color getTextAreaForeground() {
return UIManager.getColor("TextArea.foreground");
return getColor("TextArea.foreground");
}
public static Color getOptionPaneBackground() {
return UIManager.getColor("OptionPane.background");
return getColor("OptionPane.background");
}
@SuppressWarnings({"HardCodedStringLiteral"})
@@ -68,6 +68,8 @@ import java.io.FilenameFilter;
import java.io.IOException;
import java.net.URL;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* {@link BaseGradleProjectResolverExtension} provides base implementation of Gradle project resolver.
@@ -651,6 +653,18 @@ public class BaseGradleProjectResolverExtension implements GradleProjectResolver
else {
level = LibraryLevel.PROJECT;
libraryName = String.format("%s:%s:%s", moduleVersion.getGroup(), moduleVersion.getName(), moduleVersion.getVersion());
if (binaryPath.isFile()) {
String libraryFileName = FileUtil.getNameWithoutExtension(binaryPath);
final String mavenLibraryFileName = String.format("%s-%s", moduleVersion.getName(), moduleVersion.getVersion());
if (!mavenLibraryFileName.equals(libraryFileName)) {
Pattern pattern = Pattern.compile(moduleVersion.getName() + "-" + moduleVersion.getVersion() + "-(.*)");
Matcher matcher = pattern.matcher(libraryFileName);
if (matcher.matches()) {
final String classifier = matcher.group(1);
libraryName += (":" + classifier);
}
}
}
}
final LibraryData library = new LibraryData(GradleConstants.SYSTEM_ID, libraryName, unresolved);
@@ -16,6 +16,7 @@
package org.jetbrains.plugins.gradle.importing;
import com.intellij.openapi.roots.DependencyScope;
import com.intellij.openapi.vfs.VirtualFile;
import org.gradle.util.GradleVersion;
import org.junit.Test;
@@ -60,4 +61,36 @@ public class GradleDependenciesImportingTest extends GradleImportingTestCase {
assertModuleLibDepScope("project", "Gradle: org.hamcrest:hamcrest-core:1.3", DependencyScope.TEST);
assertModuleLibDepScope("project", "Gradle: junit:junit:4.11", DependencyScope.TEST);
}
@Test
public void testDependencyWithDifferentClassifiers() throws Exception {
final VirtualFile depJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0.jar");
final VirtualFile depTestsJar = createProjectJarSubFile("lib/dep/dep/1.0/dep-1.0-tests.jar");
importProject(
"allprojects {\n" +
" apply plugin: 'java'\n" +
" sourceCompatibility = 1.5\n" +
" version = '1.0'\n" +
"\n" +
" repositories {\n" +
" mavenCentral()\n" +
" maven{ url file('lib') }\n" +
" }\n" +
"}\n" +
"\n" +
"dependencies {\n" +
" compile 'dep:dep:1.0'\n" +
" testCompile 'dep:dep:1.0:tests'\n" +
"}"
);
assertModules("project");
assertModuleLibDep("project", "Gradle: dep:dep:1.0", depJar.getUrl());
assertModuleLibDepScope("project", "Gradle: dep:dep:1.0", DependencyScope.COMPILE);
assertModuleLibDep("project", "Gradle: dep:dep:1.0:tests", depTestsJar.getUrl());
assertModuleLibDepScope("project", "Gradle: dep:dep:1.0:tests", DependencyScope.TEST);
}
}
@@ -385,6 +385,26 @@ class BaseInterpreterInterface:
return xml
def getArray(self, attr, roffset, coffset, rows, cols, format):
xml = "<xml>"
array = pydevd_vars.evalInContext(attr, self.getNamespace(), self.getNamespace())
xml += pydevd_vars.array_to_xml(array, roffset, coffset, rows, cols, format)
xml += "</xml>"
return xml
def evaluate(self, expression):
xml = "<xml>"
result = pydevd_vars.evalInContext(expression, self.getNamespace(), self.getNamespace())
xml += pydevd_vars.varToXML(result, expression)
xml += "</xml>"
return xml
def changeVariable(self, attr, value):
def do_change_variable():
Exec('%s=%s' % (attr, value), self.getNamespace(), self.getNamespace())
+2
View File
@@ -293,6 +293,8 @@ def start_server(host, port, interpreter):
server.register_function(handshake)
server.register_function(interpreter.connectToDebugger)
server.register_function(interpreter.hello)
server.register_function(interpreter.getArray)
server.register_function(interpreter.evaluate)
# Functions for GUI main loop integration
server.register_function(interpreter.enableGui)
+1 -44
View File
@@ -968,8 +968,6 @@ class InternalGetVariable(InternalThreadCommand):
#=======================================================================================================================
from pydevd_vars import getVariable
MAXIMUM_ARRAY_SIZE = 300
class InternalGetArray(InternalThreadCommand):
def __init__(self, seq, roffset, coffset, rows, cols, format, thread_id, frame_id, scope, attrs):
self.sequence = seq
@@ -988,50 +986,9 @@ class InternalGetArray(InternalThreadCommand):
try:
var = getVariable(self.thread_id, self.frame_id, 'EXPRESSION', self.attrs)
rows = min(self.rows, MAXIMUM_ARRAY_SIZE)
cols = min(self.cols, MAXIMUM_ARRAY_SIZE)
if self.rows == 1 and self.cols == 1:
rows = 1
cols = 1
elif self.rows == 1 or self.cols == 1:
is_row = True if (self.rows == 1) else False
pure_1d = False if (len(var) == 1) else True
if not pure_1d:
var = var[0]
if is_row:
var = var[self.coffset:]
cols = min(cols, len(var))
else:
var = var[self.roffset:]
rows = min(rows, len(var))
else:
var = var[self.roffset:, self.coffset:]
rows = min(rows, len(var))
cols = min(cols, len(var[0]))
xml = "<xml>"
xml += "<array name=\"%s\" rows=\"%s\" cols=\"%s\"/>" % (self.name, rows, cols)
for row in range(rows):
xml += "<row index=\"%s\"/>" % to_string(row)
for col in range(cols):
value = var
name = '%s[%s][%s]' % (self.name, row, col)
if self.rows == 1 or self.cols == 1:
if self.rows == 1 and self.cols == 1:
value = var
name = '%s' % self.name
else:
dim = col if (self.rows == 1) else row
value = var[dim]
name = '%s[%s]' % (self.name, dim)
else:
value = var[row][col]
value = self.format % value
xml += pydevd_vars.varToXML(value, name)
xml += pydevd_vars.array_to_xml(var, self.roffset, self.coffset, self.rows, self.cols, self.format)
xml += "</xml>"
cmd = dbg.cmdFactory.makeGetArrayMessage(self.sequence, xml)
+83 -39
View File
@@ -19,6 +19,7 @@ import _pydev_threading as threading
import traceback
import pydevd_save_locals
from pydev_imports import Exec, quote, execfile
from pydevd_utils import to_string
try:
import types
@@ -276,6 +277,43 @@ def customOperation(thread_id, frame_id, scope, attrs, style, code_or_file, oper
traceback.print_exc()
def evalInContext(expression, globals, locals):
result = None
try:
result = eval(expression, globals, locals)
except Exception:
s = StringIO()
traceback.print_exc(file=s)
result = s.getvalue()
try:
try:
etype, value, tb = sys.exc_info()
result = value
finally:
etype = value = tb = None
except:
pass
result = ExceptionOnEvaluate(result)
# Ok, we have the initial error message, but let's see if we're dealing with a name mangling error...
try:
if '__' in expression:
# Try to handle '__' name mangling...
split = expression.split('.')
curr = locals.get(split[0])
for entry in split[1:]:
if entry.startswith('__') and not hasattr(curr, entry):
entry = '_%s%s' % (curr.__class__.__name__, entry)
curr = getattr(curr, entry)
result = curr
except:
pass
return result
def evaluateExpression(thread_id, frame_id, expression, doExec):
'''returns the result of the evaluated expression
@param doExec: determines if we should do an exec or an eval
@@ -284,9 +322,6 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
if frame is None:
return
expression = str(expression.replace('@LINE@', '\n'))
#Not using frame.f_globals because of https://sourceforge.net/tracker2/?func=detail&aid=2541355&group_id=85796&atid=577329
#(Names not resolved in generator expression in method)
#See message: http://mail.python.org/pipermail/python-list/2009-January/526522.html
@@ -295,6 +330,7 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
updated_globals.update(frame.f_locals) #locals later because it has precedence over the actual globals
try:
expression = str(expression.replace('@LINE@', '\n'))
if doExec:
try:
@@ -311,42 +347,7 @@ def evaluateExpression(thread_id, frame_id, expression, doExec):
return
else:
result = None
try:
result = eval(expression, updated_globals, frame.f_locals)
except Exception:
s = StringIO()
traceback.print_exc(file=s)
result = s.getvalue()
try:
try:
etype, value, tb = sys.exc_info()
result = value
finally:
etype = value = tb = None
except:
pass
result = ExceptionOnEvaluate(result)
# Ok, we have the initial error message, but let's see if we're dealing with a name mangling error...
try:
if '__' in expression:
# Try to handle '__' name mangling...
split = expression.split('.')
curr = frame.f_locals.get(split[0])
for entry in split[1:]:
if entry.startswith('__') and not hasattr(curr, entry):
entry = '_%s%s' % (curr.__class__.__name__, entry)
curr = getattr(curr, entry)
result = curr
except:
pass
return result
return evalInContext(expression, updated_globals, frame.f_locals)
finally:
#Should not be kept alive if an exception happens and this frame is kept in the stack.
del updated_globals
@@ -387,6 +388,49 @@ def changeAttrExpression(thread_id, frame_id, attr, expression, dbg):
except Exception:
traceback.print_exc()
MAXIMUM_ARRAY_SIZE = 300
def array_to_xml(array, roffset, coffset, rows, cols, format):
xml = ""
rows = min(rows, MAXIMUM_ARRAY_SIZE)
cols = min(cols, MAXIMUM_ARRAY_SIZE)
if rows == 1 and cols == 1:
rows = 1
cols = 1
elif rows == 1 or cols == 1:
is_row = True if (rows == 1) else False
pure_1d = False if (len(array) == 1) else True
if not pure_1d:
array = array[0]
if is_row:
array = array[coffset:]
cols = min(cols, len(array))
else:
array = array[roffset:]
rows = min(rows, len(array))
else:
array = array[roffset:, coffset:]
rows = min(rows, len(array))
cols = min(cols, len(array[0]))
xml += "<array rows=\"%s\" cols=\"%s\"/>" % (rows, cols)
for row in range(rows):
xml += "<row index=\"%s\"/>" % to_string(row)
for col in range(cols):
value = array
if rows == 1 or cols == 1:
if rows == 1 and cols == 1:
value = array
else:
dim = col if (rows == 1) else row
value = array[dim]
else:
value = array[row][col]
value = format % value
xml += varToXML(value, '')
return xml
@@ -21,5 +21,5 @@ public interface PyFrameAccessor {
@Nullable
PyReferrersLoader getReferrersLoader();
Object[][] getArrayItems(PyDebugValue var, int colOffset, int rowOffset, int rows, int cols, String format) throws PyDebuggerException;
Object[][] getArrayItems(PyDebugValue var, int rowOffset, int colOffset, int rows, int cols, String format) throws PyDebuggerException;
}
@@ -63,6 +63,8 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
private static final String CONNECT_TO_DEBUGGER = "connectToDebugger";
private static final String HANDSHAKE = "handshake";
private static final String CLOSE = "close";
private static final String EVALUATE = "evaluate";
private static final String GET_ARRAY = "getArray";
/**
* XML-RPC client for sending messages to the server.
@@ -461,7 +463,21 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
@Override
public PyDebugValue evaluate(String expression, boolean execute, boolean doTrunc) throws PyDebuggerException {
return null; //To change body of implemented methods use File | Settings | File Templates.
if (myClient != null) {
try {
Object ret = myClient.execute(EVALUATE, new Object[]{expression});
if (ret instanceof String) {
return ProtocolParser.parseValue((String)ret, this);
}
else {
checkError(ret);
}
}
catch (Exception e) {
throw new PyDebuggerException("Evaluate in console failed", e);
}
}
return null;
}
@Nullable
@@ -532,8 +548,23 @@ public class PydevConsoleCommunication extends AbstractConsoleCommunication impl
}
@Override
public Object[][] getArrayItems(PyDebugValue var, int colOffset, int rowOffset, int rows, int cols, String format) {
return new Object[][]{new Object[]{1, 2}, new Object[]{3, 4}};
public Object[][] getArrayItems(PyDebugValue var, int rowOffset, int colOffset, int rows, int cols, String format)
throws PyDebuggerException {
if (myClient != null) {
try {
Object ret = myClient.execute(GET_ARRAY, new Object[]{var.getName(), rowOffset, colOffset, rows, cols, format});
if (ret instanceof String) {
return ProtocolParser.parseArrayValues((String)ret, this);
}
else {
checkError(ret);
}
}
catch (Exception e) {
throw new PyDebuggerException("Evaluate in console failed", e);
}
}
return null;
}
/**
@@ -56,8 +56,8 @@ public class AsyncArrayTableModel extends AbstractTableModel {
@Override
public Object[][] call() throws Exception {
return value.getFrameAccessor()
.getArrayItems(slicedValue, key.first, key.second, Math.min(CHUNK_COL_SIZE, getRowCount() - key.first),
Math.min(CHUNK_ROW_SIZE, getColumnCount() - key.second),
.getArrayItems(slicedValue, key.first, key.second, Math.min(CHUNK_ROW_SIZE, getRowCount() - key.first),
Math.min(CHUNK_COL_SIZE, getColumnCount() - key.second),
myProvider.getFormat());
}
});
@@ -99,10 +99,11 @@ public class AsyncArrayTableModel extends AbstractTableModel {
if (r < chunk.get().length) {
if (c < chunk.get()[r].length) {
return myProvider.correctStringValue((String)chunk.get()[r][c]);
return myProvider.correctStringValue(chunk.get()[r][c]);
}
}
} else {
}
else {
chunk.addListener(new Runnable() {
@Override
public void run() {
@@ -22,11 +22,14 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Pair;
import com.intellij.util.Consumer;
import com.intellij.util.ui.UIUtil;
import com.intellij.xdebugger.evaluation.XDebuggerEvaluator;
import com.intellij.xdebugger.frame.XValue;
import com.jetbrains.python.debugger.PyDebugValue;
import com.jetbrains.python.debugger.PyDebuggerEvaluator;
import com.jetbrains.python.debugger.PyDebuggerException;
import com.jetbrains.python.debugger.PyFrameAccessor;
import org.jetbrains.annotations.NotNull;
import javax.management.InvalidAttributeValueException;
@@ -164,11 +167,7 @@ public class NumpyArrayTable {
}
private void initSliceFieldActions() {
if (myComponent.getSliceTextField().getEditor() == null) {
LOG.error("Null editor in slice field.");
return;
}
myComponent.getSliceTextField().getEditor().getContentComponent().addKeyListener(new KeyAdapter() {
myComponent.getSliceTextField().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
@@ -179,11 +178,7 @@ public class NumpyArrayTable {
}
private void initFormatFieldActions() {
if (myComponent.getFormatTextField().getEditor() == null) {
LOG.error("Null editor in format field.");
return;
}
myComponent.getFormatTextField().getEditor().getContentComponent().addKeyListener(new KeyAdapter() {
myComponent.getFormatTextField().addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
@@ -197,8 +192,8 @@ public class NumpyArrayTable {
return myValue;
}
public PyDebuggerEvaluator getEvaluator() {
return myEvaluator;
public PyFrameAccessor getEvaluator() {
return myValue.getFrameAccessor();
}
public void init() {
@@ -244,10 +239,10 @@ public class NumpyArrayTable {
}
private void fillColorRange(@NotNull final Runnable returnToMain) {
XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() {
Consumer<PyDebugValue> callback = new Consumer<PyDebugValue>() {
@Override
public void evaluated(@NotNull XValue result) {
String rawValue = ((PyDebugValue)result).getValue();
public void consume(@NotNull PyDebugValue result) {
String rawValue = result.getValue();
double min;
double max;
String minValue = rawValue.substring(1, rawValue.indexOf(","));
@@ -271,11 +266,6 @@ public class NumpyArrayTable {
myTableCellRenderer.setMax(max);
returnToMain.run();
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
showError(errorMessage);
}
};
if (getMaxRow(myShape) * getMaxColumn(myShape) > HUGE_ARRAY_SIZE) {
@@ -284,7 +274,13 @@ public class NumpyArrayTable {
}
String evalTypeCommand = "[" + getNodeName() + ".min(), " + getNodeName() + ".max()]";
getEvaluator().evaluate(evalTypeCommand, callback, null);
try {
PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, false, false);
callback.consume(value);
}
catch (PyDebuggerException e) {
showError(e.getMessage());
}
}
public String getDefaultPresentation() {
@@ -341,46 +337,36 @@ public class NumpyArrayTable {
}
private void fillType(@NotNull final Runnable returnToMain) {
XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() {
@Override
public void evaluated(@NotNull XValue result) {
setDtypeKind(((PyDebugValue)result).getValue());
returnToMain.run();
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
showError(errorMessage);
}
};
String evalTypeCommand = getNodeName() + ".dtype.kind";
getEvaluator().evaluate(evalTypeCommand, callback, null);
try {
PyDebugValue value = getEvaluator().evaluate(evalTypeCommand, false, false);
setDtypeKind(value.getValue());
returnToMain.run();
}
catch (PyDebuggerException e) {
showError(e.getMessage());
}
}
private void fillShape(@NotNull final Runnable returnToMain) {
XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() {
@Override
public void evaluated(@NotNull XValue result) {
try {
setShape(parseShape(((PyDebugValue)result).getValue()));
returnToMain.run();
}
catch (InvalidAttributeValueException e) {
errorOccurred(e.getMessage());
}
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
showError(errorMessage);
}
};
String evalShapeCommand = getEvalShapeCommand(getNodeName());
getEvaluator().evaluate(evalShapeCommand, callback, null);
try {
PyDebugValue value = getEvaluator().evaluate(evalShapeCommand, false, false);
setShape(parseShape(value.getValue()));
returnToMain.run();
}
catch (Exception e) {
showError(e.getMessage());
}
}
private int[] parseShape(String value) throws InvalidAttributeValueException {
String shape = value.substring(0, value.indexOf('#'));
int index = value.indexOf('#');
if (index == -1) {
LOG.error("Wrong shape format: " + value);
return new int[]{0, 0};
}
String shape = value.substring(0, index);
if (shape.equals("()")) {
return new int[]{1, 1};
}
@@ -542,14 +528,20 @@ public class NumpyArrayTable {
};
}
public String correctStringValue(@NotNull String value) {
String corrected = value;
if (isNumeric()) {
if (value.startsWith("\'") || value.startsWith("\"")) {
corrected = value.substring(1, value.length() - 1);
public String correctStringValue(@NotNull Object value) {
if (value instanceof String) {
String corrected = (String)value;
if (isNumeric()) {
if (corrected.startsWith("\'") || corrected.startsWith("\"")) {
corrected = corrected.substring(1, corrected.length() - 1);
}
}
return corrected;
}
return corrected;
else if (value instanceof Integer) {
return Integer.toString((Integer)value);
}
return value.toString();
}
public void setDtypeKind(String dtype) {
@@ -611,28 +603,18 @@ public class NumpyArrayTable {
private void doReslice(final String newSlice, int[] shape) {
if (shape == null) {
XDebuggerEvaluator.XEvaluationCallback callback = new XDebuggerEvaluator.XEvaluationCallback() {
@Override
public void evaluated(@NotNull XValue result) {
try {
int[] shape = parseShape(((PyDebugValue)result).getValue());
if (!is2DShape(shape)) {
errorOccurred("Incorrect slice shape " + ((PyDebugValue)result).getValue() + ".");
}
doReslice(newSlice, shape);
}
catch (InvalidAttributeValueException e) {
errorOccurred(e.getMessage());
}
}
@Override
public void errorOccurred(@NotNull String errorMessage) {
showError(errorMessage);
}
};
String evalShapeCommand = getEvalShapeCommand(newSlice);
getEvaluator().evaluate(evalShapeCommand, callback, null);
try {
PyDebugValue result = getEvaluator().evaluate(evalShapeCommand, false, false);
shape = parseShape(((PyDebugValue)result).getValue());
if (!is2DShape(shape)) {
showError("Incorrect slice shape " + ((PyDebugValue)result).getValue() + ".");
}
doReslice(newSlice, shape);
}
catch (Exception e) {
showError(e.getMessage());
}
return;
}