Skip to content

Commit 9f2f058

Browse files
committed
Add support for Java with basic type definitions
Update readme, changelog Bump version
1 parent 020c1db commit 9f2f058

File tree

5 files changed

+180
-15
lines changed

5 files changed

+180
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
88
### Known issues
99
- The visualization is not shown after hiding the webview with another window and showing it again
1010

11+
## [0.10.0]
12+
### Added
13+
- Support for Java
14+
- Visualization of Java arrays, numbers and points
15+
1116
## [0.9.0]
1217
### Added
1318
- Support for debugpy Python debugger

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ You can download this extension from [Visual Studio Marketplace](https://marketp
4848
* 2D values/geometries
4949
* System.Drawing: `Point`
5050

51+
##### Java (java)
52+
53+
* Containers of values, points and other geometries
54+
* Array
55+
* java.util: `ArrayList`, `LinkedList`, `Vector`
56+
* 1D values
57+
* java.lang: `Byte`, `Double`, `Float`, `Integer`, `Long`, `Short`
58+
* 2D values/geometries
59+
* java.awt: `Point`
60+
* java.awt.geom: `Point2D.Double`, `Point2D.Float`
61+
5162
##### Javascript (chrome, msedge, node, pwa-node, pwa-chrome, pwa-msedge)
5263

5364
* Containers of values, points and other geometries

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphicaldebugging-vscode",
3-
"version": "0.9.0",
3+
"version": "0.10.0",
44
"publisher": "AdamWulkiewicz",
55
"author": {
66
"name": "Adam Wulkiewicz"
@@ -17,8 +17,8 @@
1717
"Other"
1818
],
1919
"keywords": [
20-
"2d", "array", "boost", "box", "c", "c++", "cartesian", "chart", "complex", "container", "curve",
21-
"debug", "debugging", "deque", "geographic", "geometry", "gis", "graphical", "javascript", "linestring", "list",
20+
"2d", "array", "boost", "box", "c", "c++", "c#", "cartesian", "chart", "complex", "container", "curve",
21+
"debug", "debugging", "deque", "geographic", "geometry", "gis", "graphical", "java", "javascript", "linestring", "list",
2222
"plot", "point", "polygon", "python", "rgeo", "ring", "ruby", "segment", "shapely", "spherical", "std", "stl", "tuple", "vector",
2323
"visualization", "visualize"
2424
],

resources/java.json

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"name": "graphicaldebugging",
3+
"language": "java",
4+
"types": [
5+
{
6+
"type": "[a-zA-Z_][\\w<,>:\\s]*\\[\\]",
7+
"kind": "container",
8+
"array": {
9+
"start": "$this",
10+
"size": "$this.length"
11+
},
12+
"_comment": "Java array"
13+
},
14+
{
15+
"type": "ArrayList",
16+
"kind": "container",
17+
"iarray": {
18+
"element": "$this.get($i)",
19+
"size": "$this.size()"
20+
}
21+
},
22+
{
23+
"type": "LinkedList",
24+
"kind": "container",
25+
"iarray": {
26+
"element": "$this.get($i)",
27+
"size": "$this.size()"
28+
}
29+
},
30+
{
31+
"type": "Vector",
32+
"kind": "container",
33+
"iarray": {
34+
"element": "$this.get($i)",
35+
"size": "$this.size()"
36+
}
37+
},
38+
{
39+
"type": "Point",
40+
"kind": "point",
41+
"system": "cartesian",
42+
"coordinates": {
43+
"x": "$this.x",
44+
"y": "$this.y"
45+
}
46+
},
47+
{
48+
"type": "Point2D.Double",
49+
"kind": "point",
50+
"system": "cartesian",
51+
"coordinates": {
52+
"x": "$this.x",
53+
"y": "$this.y"
54+
}
55+
},
56+
{
57+
"type": "Point2D.Float",
58+
"kind": "point",
59+
"system": "cartesian",
60+
"coordinates": {
61+
"x": "$this.x",
62+
"y": "$this.y"
63+
}
64+
},
65+
{
66+
"type": "Byte",
67+
"kind": "value",
68+
"name": "$this.value"
69+
},
70+
{
71+
"type": "Double",
72+
"kind": "value",
73+
"name": "$this.value"
74+
},
75+
{
76+
"type": "Float",
77+
"kind": "value",
78+
"name": "$this.value"
79+
},
80+
{
81+
"type": "Integer",
82+
"kind": "value",
83+
"name": "$this.value"
84+
},
85+
{
86+
"type": "Long",
87+
"kind": "value",
88+
"name": "$this.value"
89+
},
90+
{
91+
"type": "Short",
92+
"kind": "value",
93+
"name": "$this.value"
94+
}
95+
]
96+
}

src/loader.ts

Lines changed: 65 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,24 +100,27 @@ export class Variable {
100100

101101

102102
interface IExpressionPart {
103-
toString(variable: Variable): string;
103+
toString(variable: Variable, parameter: number | undefined): string;
104104
}
105105
class ExpressionString implements IExpressionPart {
106106
constructor(private _str: string) {}
107-
toString(variable: Variable): string { return this._str; }
107+
toString(variable: Variable, parameter: number | undefined): string { return this._str; }
108108
}
109109
class ExpressionThis implements IExpressionPart {
110-
toString(variable: Variable): string { return '(' + variable.name + ')'; }
110+
toString(variable: Variable, parameter: number | undefined): string { return '(' + variable.name + ')'; }
111111
}
112112
class ExpressionNParam implements IExpressionPart {
113113
constructor(protected _i: number) {}
114-
toString(variable: Variable): string { return variable.nparam(this._i); }
114+
toString(variable: Variable, parameter: number | undefined): string { return variable.nparam(this._i); }
115115
}
116116
class ExpressionTParam extends ExpressionNParam {
117-
toString(variable: Variable): string { return variable.tparam(this._i); }
117+
toString(variable: Variable, parameter: number | undefined): string { return variable.tparam(this._i); }
118118
}
119119
class ExpressionType implements IExpressionPart {
120-
toString(variable: Variable): string { return variable.type; }
120+
toString(variable: Variable, parameter: number | undefined): string { return variable.type; }
121+
}
122+
class ExpressionIndex implements IExpressionPart {
123+
toString(variable: Variable, parameter: number | undefined): string { return parameter !== undefined ? parameter.toString() : "0"; }
121124
}
122125
export class Expression
123126
{
@@ -148,17 +151,21 @@ export class Expression
148151
this._parts.push(new ExpressionNParam(parseInt(match[0].substr(2))));
149152
index = match.index + match[0].length;
150153
}
154+
else if (match[0] === '$i') {
155+
this._parts.push(new ExpressionIndex());
156+
index = match.index + 2;
157+
}
151158
}
152159
}
153160
if (index < expression.length) {
154161
this._parts.push(new ExpressionString(expression.substr(index)));
155162
}
156163
}
157164

158-
toString(variable: Variable): string {
165+
toString(variable: Variable, parameter: number | undefined = undefined): string {
159166
let result: string = '';
160167
for (let part of this._parts) {
161-
result += part.toString(variable);
168+
result += part.toString(variable, parameter);
162169
}
163170
// TODO: do this only for C++ ?
164171
// It is possible that this should depend on the debugger
@@ -197,6 +204,15 @@ async function evaluateExpression(dbg: debug.Debugger, variable: Variable, expre
197204
return new EvaluatedExpression(expr, str, vt[1]);
198205
}
199206

207+
async function evaluateIndexedExpression(dbg: debug.Debugger, variable: Variable, expressionName: string, parameter: number): Promise<EvaluatedExpression | undefined> {
208+
const expr = new Expression(expressionName);
209+
const str = expr.toString(variable, parameter);
210+
let vt = await dbg.getValueAndRawType(str);
211+
if (vt === undefined)
212+
return undefined;
213+
return new EvaluatedExpression(expr, str, vt[1]);
214+
}
215+
200216
function getValueFromExpressionStr(dbg: debug.Debugger, str: string): number | boolean | undefined {
201217
const language = dbg.language();
202218
if (language != undefined) {
@@ -240,10 +256,9 @@ export class Container {
240256
}
241257

242258
export class RandomAccessContainer extends Container {}
243-
244259
export class ContiguousContainer extends RandomAccessContainer {}
245260

246-
// Static array
261+
// Indexed array
247262
export class Array extends ContiguousContainer
248263
{
249264
constructor(private _start: Expression, private _size: Expression) {
@@ -276,8 +291,8 @@ export class Array extends ContiguousContainer
276291
}
277292
}
278293

279-
// Dynamic array
280-
export class DArray extends RandomAccessContainer {
294+
// Indexed array with size defined by two pointers
295+
export class DArray extends ContiguousContainer {
281296
constructor(private _start: Expression, private _finish: Expression) {
282297
super();
283298
}
@@ -303,6 +318,38 @@ export class DArray extends RandomAccessContainer {
303318
}
304319
}
305320

321+
export class IArray extends RandomAccessContainer
322+
{
323+
constructor(private _element: Expression, private _size: Expression) {
324+
super();
325+
}
326+
327+
element(variable: Variable): string | undefined {
328+
return this._element.toString(variable, 0);
329+
}
330+
331+
async size(dbg: debug.Debugger, variable: Variable): Promise<number> {
332+
const sizeStr = this._size.toString(variable);
333+
// TODO: Check if it's possible to parse size at this point
334+
const sizeVal = await dbg.getValue(sizeStr);
335+
return sizeVal !== undefined ? parseInt(sizeVal) : 0;
336+
}
337+
338+
async *elements(dbg: debug.Debugger, variable: Variable): AsyncGenerator<string, void, unknown> {
339+
const size = await this.size(dbg, variable);
340+
if (! (size > 0)) // also handle NaN
341+
return;
342+
// NOTE: This loop could be done asynchroniously with await Promise.all()
343+
// but an array can potentially store great number of objects so there
344+
// would be great number of promises. And it will not be possible to
345+
// end fast in case of error because the program would wait for all.
346+
for (let i = 0; i < size; ++i) {
347+
const elStr = this._element.toString(variable, i);
348+
yield elStr;
349+
}
350+
}
351+
}
352+
306353
// TODO: Later when direct memory access is implemented allow passing pointers
307354
export class LinkedList extends Container
308355
{
@@ -1262,6 +1309,12 @@ async function _getContainer(dbg: debug.Debugger, variable: Variable, entry: any
12621309
if (start && finish) {
12631310
return new DArray(start.expression, finish.expression);
12641311
}
1312+
} else if (entry.iarray && entry.iarray.element && entry.iarray.size) {
1313+
const element = await evaluateIndexedExpression(dbg, variable, entry.iarray.element, 0);
1314+
const size = await evaluateExpression(dbg, variable, entry.iarray.size);
1315+
if (element && size) {
1316+
return new IArray(element.expression, size.expression);
1317+
}
12651318
} else if (entry.linkedlist && entry.linkedlist.size && entry.linkedlist.value) {
12661319
if (entry.linkedlist.head && entry.linkedlist.next) {
12671320
const size = await evaluateExpression(dbg, variable, entry.linkedlist.size);

0 commit comments

Comments
 (0)