fix issues from IDEA-COMMUNITY-CR-987

This commit is contained in:
Alexander Marchuk
2014-11-19 13:34:22 +03:00
parent 6924197ed8
commit 911b2a36e5
7 changed files with 100 additions and 77 deletions
+6 -4
View File
@@ -390,11 +390,13 @@ class BaseInterpreterInterface:
name = attr.split("\t")[-1]
array = pydevd_vars.evalInContext(name, self.getNamespace(), self.getNamespace())
metaxml, r, c, f = pydevd_vars.array_to_meta_xml(array, name, format)
xml += metaxml
format = '%' + f
if rows == -1 and cols == -1:
xml += pydevd_vars.array_to_meta_xml(array, name, format)
else:
xml += pydevd_vars.array_to_xml(array, roffset, coffset, rows, cols, format)
rows = r
cols = c
xml += pydevd_vars.array_to_xml(array, roffset, coffset, rows, cols, format)
xml += "</xml>"
return xml
+6 -4
View File
@@ -991,11 +991,13 @@ class InternalGetArray(InternalThreadCommand):
xml = "<xml>"
# need metadata
metaxml, rows, cols, format = pydevd_vars.array_to_meta_xml(var, self.name, self.format)
xml += metaxml
self.format = '%' + format
if self.rows == -1 and self.cols == -1:
xml += pydevd_vars.array_to_meta_xml(var, self.name, self.format)
else:
xml += pydevd_vars.array_to_xml(var, self.roffset, self.coffset, self.rows, self.cols, self.format)
self.rows = rows
self.cols = cols
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)
dbg.writer.addCommand(cmd)
+4 -4
View File
@@ -414,7 +414,7 @@ def array_to_xml(array, roffset, coffset, rows, cols, format):
array = array[roffset:]
rows = min(rows, len(array))
xml += "<array meta=\"%s\" rows=\"%s\" cols=\"%s\"/>" % (False, rows, cols)
xml += "<arraydata rows=\"%s\" cols=\"%s\"/>" % (rows, cols)
for row in range(rows):
xml += "<row index=\"%s\"/>" % to_string(row)
for col in range(cols):
@@ -491,9 +491,9 @@ def array_to_meta_xml(array, name, format):
bounds = (0, 0)
if type in "biufc":
bounds = (array.min(), array.max())
xml = '<array meta=\"%s\" slice=\"%s\" rows=\"%s\" cols=\"%s\" format=\"%s\" type=\"%s\" max=\"%s\" min=\"%s\"/>' % \
(True, slice, rows, cols, format, type, bounds[1], bounds[0])
return xml
xml = '<array slice=\"%s\" rows=\"%s\" cols=\"%s\" format=\"%s\" type=\"%s\" max=\"%s\" min=\"%s\"/>' % \
(slice, rows, cols, format, type, bounds[1], bounds[0])
return xml, rows, cols, format
@@ -88,16 +88,4 @@ public class ArrayChunk {
public Object[][] getData() {
return myData;
}
public boolean metaOnly() {
return myData == null;
}
public boolean containsMeta() {
return !mySlicePresentation.isEmpty() &&
myRows > 0 &&
myColumns > 0 &&
!myFormat.isEmpty() &&
!myType.isEmpty();
}
}
@@ -181,34 +181,42 @@ public class ProtocolParser {
public static ArrayChunk parseArrayValues(final String text, final PyFrameAccessor frameAccessor) throws PyDebuggerException {
final XppReader reader = openReader(text, false);
int cols = 0;
int rows = 0;
ArrayChunk result = null;
if (reader.hasMoreChildren()) {
reader.moveDown();
if (!"array".equals(reader.getNodeName())) {
throw new PyDebuggerException("Expected <array> at first node, found " + reader.getNodeName());
}
boolean meta = readString(reader, "meta", null).equals("True");
if (meta) {
String slice = readString(reader, "slice", null);
rows = readInt(reader, "rows", null);
cols = readInt(reader, "cols", null);
String format = "%" + readString(reader, "format", null);
String type = readString(reader, "type", null);
String max = readString(reader, "max", null);
String min = readString(reader, "min", null);
return new ArrayChunk(new PyDebugValue(slice, null, null, false, false, frameAccessor), slice, rows, cols, max, min, format, type, null);
String slice = readString(reader, "slice", null);
int rows = readInt(reader, "rows", null);
int cols = readInt(reader, "cols", null);
String format = "%" + readString(reader, "format", null);
String type = readString(reader, "type", null);
String max = readString(reader, "max", null);
String min = readString(reader, "min", null);
result =
new ArrayChunk(new PyDebugValue(slice, null, null, false, false, frameAccessor), slice, rows, cols, max, min, format, type, null);
reader.moveUp();
}
Object[][] data = parseArrayValues(reader, frameAccessor);
return new ArrayChunk(result.getValue(), result.getSlicePresentation(), result.getRows(), result.getColumns(), result.getMax(),
result.getMin(), result.getFormat(), result.getType(), data);
}
public static Object[][] parseArrayValues(final XppReader reader, final PyFrameAccessor frameAccessor) throws PyDebuggerException {
int rows = -1;
int cols = -1;
if (reader.hasMoreChildren()) {
reader.moveDown();
if (!"arraydata".equals(reader.getNodeName())) {
throw new PyDebuggerException("Expected <arraydata> at second node, found " + reader.getNodeName());
}
rows = readInt(reader, "rows", null);
cols = readInt(reader, "cols", null);
reader.moveUp();
}
return parseArrayValues(reader, frameAccessor, cols, rows);
}
public static ArrayChunk parseArrayValues(final XppReader reader, final PyFrameAccessor frameAccessor, final int cols, final int rows) throws PyDebuggerException {
if (rows <= 0 || cols <= 0) {
throw new PyDebuggerException("Array xml: bad rows or columns number: (" + rows + ", " + cols + ")");
}
@@ -231,15 +239,16 @@ public class ProtocolParser {
}
currRow += 1;
currCol = 0;
} else {
}
else {
PyDebugValue value = parseValue(reader, frameAccessor);
values[currRow-1][currCol] = value.getValue();
values[currRow - 1][currCol] = value.getValue();
currCol += 1;
}
reader.moveUp();
}
return new ArrayChunk(new PyDebugValue("", null, null, false, false, frameAccessor), "", rows, cols, null, null, null, null, values);
return values;
}
private static XppReader openReader(final String text, final boolean checkForContent) throws PyDebuggerException {
@@ -26,6 +26,8 @@ import com.jetbrains.python.debugger.ArrayChunk;
import com.jetbrains.python.debugger.PyDebugValue;
import javax.swing.table.AbstractTableModel;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.*;
/**
@@ -165,7 +167,51 @@ public class AsyncArrayTableModel extends AbstractTableModel {
}
}
public void addToCache(ArrayChunk chunk) {
//TODO: add preloaded values
public void addToCache(final ArrayChunk chunk) {
Object[][] data = chunk.getData();
int cols = data.length;
int rows = data[0].length;
for (int roffset = 0; roffset < rows / CHUNK_ROW_SIZE; roffset++) {
for (int coffset = 0; coffset < cols / CHUNK_COL_SIZE; coffset++) {
Pair<Integer, Integer> key = itemToChunkKey(roffset * CHUNK_ROW_SIZE, coffset * CHUNK_COL_SIZE);
final Object[][] chunkData = new Object[CHUNK_ROW_SIZE][CHUNK_COL_SIZE];
for (int r = 0; r < CHUNK_ROW_SIZE; r++) {
for (int c = 0; c < CHUNK_COL_SIZE; c++) {
chunkData[r][c] = data[roffset + r][coffset + c];
}
}
myChunkCache.put(key, new ListenableFuture<ArrayChunk>() {
@Override
public void addListener(Runnable listener, Executor executor) {
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
@Override
public boolean isCancelled() {
return false;
}
@Override
public boolean isDone() {
return true;
}
@Override
public ArrayChunk get() throws InterruptedException, ExecutionException {
return new ArrayChunk(chunk.getValue(), null, 0, 0, null, null, null, null, chunkData);
}
@Override
public ArrayChunk get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
return new ArrayChunk(chunk.getValue(), null, 0, 0, null, null, null, null, chunkData);
}
});
}
}
}
}
@@ -174,9 +174,6 @@ public class NumpyArrayTable {
initComponent();
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
final ExecutorService myExecutorService = Executors.newSingleThreadExecutor();
@Override
public void run() {
final PyDebugValue value = getDebugValue();
@@ -187,35 +184,18 @@ public class NumpyArrayTable {
final String format = getFormat().isEmpty() ? "%" : getFormat();
final ListenableFutureTask<ArrayChunk> task = ListenableFutureTask.create(new Callable<ArrayChunk>() {
@Override
public ArrayChunk call() throws Exception {
return value.getFrameAccessor()
.getArrayItems(slicedValue, 0, 0, -1, -1, format);
}
});
task.addListener(new Runnable() {
@Override
public void run() {
if (task.isDone()) {
try {
initUi(task.get(), inPlace);
}
catch (Exception e) {
showError(e.getMessage());
}
}
}
}, myExecutorService);
myExecutorService.execute(task);
try {
initUi(value.getFrameAccessor()
.getArrayItems(slicedValue, 0, 0, -1, -1, format), inPlace);
}
catch (PyDebuggerException e) {
showError(e.getMessage());
}
}
});
}
private void initUi(@NotNull final ArrayChunk chunk, final boolean inPlace) {
if (chunk.containsMeta()) {
myPagingModel = new AsyncArrayTableModel(Math.min(chunk.getRows(), ROWS_IN_DEFAULT_VIEW),
Math.min(chunk.getColumns(), COLUMNS_IN_DEFAULT_VIEW), this);
myPagingModel.addToCache(chunk);
@@ -249,10 +229,6 @@ public class NumpyArrayTable {
}
}
});
}
else {
showError("Bad metadata for array " + chunk.getValue());
}
}
private static String getTitlePresentation(String slice) {