Skip to content

Commit 1e281f3

Browse files
committed
[GR-22797] Debugger Adapter Protocol - initial implementation.
PullRequest: graal/6199
2 parents 769e5f3 + 024bbcd commit 1e281f3

File tree

155 files changed

+22859
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

155 files changed

+22859
-25
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
com.oracle.truffle.tools.dap.types
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://github.com/microsoft/vscode-debugadapter-node.git
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
diff --git a/AttachRequestArguments.java b/AttachRequestArguments.java
2+
index a52411f..5ad36ea 100644
3+
--- a/AttachRequestArguments.java
4+
+++ b/AttachRequestArguments.java
5+
@@ -47,6 +47,20 @@ public class AttachRequestArguments extends JSONBase {
6+
return this;
7+
}
8+
9+
+ /**
10+
+ * Additional implementation specific attributes.
11+
+ *
12+
+ * @param attrName Attribute name.
13+
+ */
14+
+ public Object get(String attrName) {
15+
+ return jsonData.opt(attrName);
16+
+ }
17+
+
18+
+ public AttachRequestArguments set(String attrName, Object value) {
19+
+ jsonData.putOpt(attrName, value);
20+
+ return this;
21+
+ }
22+
+
23+
@Override
24+
public boolean equals(Object obj) {
25+
if (this == obj) {
26+
diff --git a/DataBreakpointInfoArguments.java b/DataBreakpointInfoArguments.java
27+
index 15d99ac..a6b9031 100644
28+
--- a/DataBreakpointInfoArguments.java
29+
+++ b/DataBreakpointInfoArguments.java
30+
@@ -45,7 +45,7 @@ public class DataBreakpointInfoArguments extends JSONBase {
31+
}
32+
33+
/** The name of the Variable's child to obtain data breakpoint information for.
34+
- If variableReference isn’t provided, this can be an expression.
35+
+ If variableReference isn't provided, this can be an expression.
36+
*/
37+
public String getName() {
38+
return jsonData.getString("name");
39+
diff --git a/LaunchRequestArguments.java b/LaunchRequestArguments.java
40+
index 2691baf..0fe0bfc 100644
41+
--- a/LaunchRequestArguments.java
42+
+++ b/LaunchRequestArguments.java
43+
@@ -58,6 +58,20 @@ public class LaunchRequestArguments extends JSONBase {
44+
return this;
45+
}
46+
47+
+ /**
48+
+ * Additional implementation specific attributes.
49+
+ *
50+
+ * @param attrName Attribute name.
51+
+ */
52+
+ public Object get(String attrName) {
53+
+ return jsonData.opt(attrName);
54+
+ }
55+
+
56+
+ public LaunchRequestArguments set(String attrName, Object value) {
57+
+ jsonData.putOpt(attrName, value);
58+
+ return this;
59+
+ }
60+
+
61+
@Override
62+
public boolean equals(Object obj) {
63+
if (this == obj) {
64+
diff --git a/SetExceptionBreakpointsArguments.java b/SetExceptionBreakpointsArguments.java
65+
index 37165f1..ccc41d3 100644
66+
--- a/SetExceptionBreakpointsArguments.java
67+
+++ b/SetExceptionBreakpointsArguments.java
68+
@@ -75,8 +75,8 @@ public class SetExceptionBreakpointsArguments extends JSONBase {
69+
public SetExceptionBreakpointsArguments setExceptionOptions(List<ExceptionOptions> exceptionOptions) {
70+
if (exceptionOptions != null) {
71+
final JSONArray json = new JSONArray();
72+
- for (ExceptionOptions exceptionOptions: exceptionOptions) {
73+
- json.put(exceptionOptions.jsonData);
74+
+ for (ExceptionOptions options: exceptionOptions) {
75+
+ json.put(options.jsonData);
76+
}
77+
jsonData.put("exceptionOptions", json);
78+
}
79+
diff --git a/Source.java b/Source.java
80+
index 4947842..716ba7d 100644
81+
--- a/Source.java
82+
+++ b/Source.java
83+
@@ -64,7 +64,7 @@ public class Source extends JSONBase {
84+
return this;
85+
}
86+
87+
- /** If sourceReference > 0 the contents of the source must be retrieved through the SourceRequest (even if a path is specified).
88+
+ /** If sourceReference &gt 0 the contents of the source must be retrieved through the SourceRequest (even if a path is specified).
89+
A sourceReference is only valid for a session, so it must not be used to persist a source.
90+
The value should be less than or equal to 2147483647 (2^31 - 1).
91+
*/
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

tools/generators/src/generator.ts

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,13 @@ const typeLiteralNames = new Map<TypeLiteralNode, string>();
9090
const intersected = new Map<string, (InterfaceDeclaration | TypeLiteralNode)[]>();
9191
const unionTypes = new Set<string>();
9292

93+
const javaKeywords = ['abstract', 'assert', 'boolean', 'break', 'byte', 'case', 'catch', 'char',
94+
'class', 'const', 'continue', 'default', 'do', 'double', 'else', 'enum', 'extends', 'final',
95+
'finally', 'float', 'for', 'goto', 'if', 'implements', 'import', 'instanceof', 'int', 'interface',
96+
'long', 'native', 'new', 'package', 'private', 'protected', 'public', 'return', 'short', 'static',
97+
'strictfp', 'super', 'switch', 'synchronized', 'this', 'throw', 'throws', 'transient', 'try',
98+
'void', 'volatile', 'while', 'true', 'false', 'null'];
99+
93100
const numberTypes = new Map<string, string>();
94101
numberTypes.set('Color', 'double'); //TODO: make configurable
95102

@@ -280,6 +287,7 @@ function getClassText(declNode: DeclarationStatement, moduleNode: ModuleDeclarat
280287
if (isAbstract) {
281288
text += 'public abstract class ' + clsName + ' extends JSONBase {\n';
282289
} else {
290+
const allTypeNodes: (InterfaceDeclaration | TypeLiteralNode)[] = [];
283291
let extendedType: InterfaceDeclaration;
284292
text += 'public class ' + clsName;
285293
if (declNodes[0].kind === SyntaxKind.InterfaceDeclaration && (declNodes[0] as InterfaceDeclaration).heritageClauses) {
@@ -330,13 +338,14 @@ function getClassText(declNode: DeclarationStatement, moduleNode: ModuleDeclarat
330338
}
331339

332340
// members
333-
let optionalProperties = unionTypes.has(clsName) ? new Set<PropertySignature>() : undefined;
334-
text += getClassMembersText(clsName, getMembers(declNodes, optionalProperties), isAbstract, typeParams, optionalProperties);
341+
const props = new Map<string, PropertySignature>();
342+
const nested = new Set<TypeLiteralNode>();
343+
const overridenProperties = new Map<string, PropertySignature>();
344+
findProperties(declNodes, props, overridenProperties, nested);
345+
const optionalProperties = unionTypes.has(clsName) ? new Set<PropertySignature>() : undefined;
346+
text += getClassMembersText(clsName, getMembers(declNodes, optionalProperties), isAbstract, typeParams, overridenProperties, optionalProperties);
335347
if (!isAbstract) {
336348
seedrandom(clsName, { global: true });
337-
const props = new Map<string, PropertySignature>();
338-
const nested = new Set<TypeLiteralNode>();
339-
findProperties(declNodes, props, nested);
340349
// equals
341350
text += getEqualsText(clsName, props);
342351
// hashCode
@@ -381,12 +390,12 @@ function getClassText(declNode: DeclarationStatement, moduleNode: ModuleDeclarat
381390
return importsText + text;
382391
}
383392

384-
function getClassMembersText(typeName: string, members: TypeElement[], isAbstract: boolean, typeParams: Map<string, TypeNode | string>, optionalProperties?:Set<PropertySignature>): string {
393+
function getClassMembersText(typeName: string, members: TypeElement[], isAbstract: boolean, typeParams: Map<string, TypeNode | string>, overridenProperties:Map<string, PropertySignature>, optionalProperties?:Set<PropertySignature>): string {
385394
let text: string = '';
386395
members.forEach((element: TypeElement) => {
387396
switch(element.kind) {
388397
case SyntaxKind.PropertySignature:
389-
text += getPropertyText(typeName, element as PropertySignature, isAbstract, typeParams, optionalProperties);
398+
text += getPropertyText(typeName, element as PropertySignature, isAbstract, typeParams, overridenProperties, optionalProperties);
390399
break;
391400
case SyntaxKind.MethodSignature:
392401
text += getMethodSignatureText(<MethodSignature>element);
@@ -551,6 +560,10 @@ function getNestedTypesText(types: Set<TypeLiteralNode>, typeParams: Map<string,
551560
text += (line.length > 0 ? indent.repeat(indentLevel) + line : line) + '\n';
552561
});
553562
}
563+
text += '\n' + indent;
564+
getDefaultCreatorText(name, props).trim().split('\n').forEach((line: string) => {
565+
text += (line.length > 0 ? indent.repeat(indentLevel) + line : line) + '\n';
566+
});
554567
if (nested.size > 0) {
555568
text += getNestedTypesText(nested, typeParams, indentLevel + 1);
556569
}
@@ -560,7 +573,11 @@ function getNestedTypesText(types: Set<TypeLiteralNode>, typeParams: Map<string,
560573
return text;
561574
}
562575

563-
function getPropertyText(clsName: string, node: PropertySignature, isAbstract: boolean, typeParams: Map<string, TypeNode | string>, optionalProperties?:Set<PropertySignature>): string {
576+
function getPropertyText(clsName: string, node: PropertySignature, isAbstract: boolean, typeParams: Map<string, TypeNode | string>, overridenProperties?:Map<string, PropertySignature>, optionalProperties?:Set<PropertySignature>): string {
577+
let overriden: boolean = false;
578+
if (overridenProperties && overridenProperties.has(node.name.getText())) {
579+
overriden = true;
580+
}
564581
let text: string = '\n';
565582
let comment = getComment(node, 1);
566583
if (comment) {
@@ -604,6 +621,13 @@ function getPropertyText(clsName: string, node: PropertySignature, isAbstract: b
604621
if (type === 'Boolean') {
605622
text += indent + '@SuppressFBWarnings("NP_BOOLEAN_RETURN_NULL")\n';
606623
}
624+
if (overriden) {
625+
let overridenType: Node = findType(overridenProperties.get(node.name.getText()).type);
626+
if ((optional ? getBoxedType(overridenType) : getJavaType(overridenType)) === type) {
627+
return '';
628+
}
629+
text += indent + '@Override\n';
630+
}
607631
const key: string = '"' + node.name.getText() + '"';
608632
if (isAbstract) {
609633
text += indent + 'public abstract ' + type + ' ' + getterNameFor(node.name.getText(), type) + '();\n';
@@ -1027,8 +1051,9 @@ function getDefaultCreatorText(type: string, props: Map<string, PropertySignatur
10271051
if (params) {
10281052
params += ', ';
10291053
}
1030-
params += getBoxedType(propType) + ' ' + propName;
1031-
body += creatorPropInit(prop, propName, propName, propType, type + '.create');
1054+
let paramName = varNameFor(propName);
1055+
params += getBoxedType(propType) + ' ' + paramName;
1056+
body += creatorPropInit(prop, propName, paramName, propType, type + '.create');
10321057
}
10331058
}
10341059
}
@@ -1633,11 +1658,14 @@ function getHash(node: Node): string {
16331658
}
16341659

16351660
function varNameFor(type: string): string {
1636-
return type.charAt(0).toLowerCase() + type.slice(1);
1661+
if (javaKeywords.includes(type)) {
1662+
return type + 'Value';
1663+
}
1664+
return removeUnderscores(type.charAt(0).toLowerCase() + type.slice(1));
16371665
}
16381666

16391667
function valueNameFor(type: string): string {
1640-
return varNameFor(type) + 'Value';
1668+
return removeUnderscores(type.charAt(0).toLowerCase() + type.slice(1) + 'Value');
16411669
}
16421670

16431671
function unionInfoGetter(unionInfo:{typeRef: TypeReferenceNode; enumRef: TypeReferenceNode; arrType: ArrayTypeNode}, varName: string, resultPrefix: string, resultSuffix:string, hasNull: boolean, baseIndent: number): string {
@@ -1706,19 +1734,34 @@ function unionInfoSetter(unionInfo:{typeRef: TypeReferenceNode; enumRef: TypeRef
17061734
}
17071735

17081736
function getterNameFor(name: string, type: string): string {
1737+
name = removeUnderscores(name);
17091738
if (type === 'boolean') {
17101739
return name.startsWith('is') ? name : 'is' + name.charAt(0).toUpperCase() + name.slice(1);
17111740
}
17121741
return 'get' + name.charAt(0).toUpperCase() + name.slice(1);
17131742
}
17141743

17151744
function setterNameFor(name: string, type: string): string {
1745+
name = removeUnderscores(name);
17161746
if (type === 'boolean' && name.startsWith('is') && name.length > 2) {
17171747
return 'set' + name.charAt(2).toUpperCase() + name.slice(3);
17181748
}
17191749
return 'set' + name.charAt(0).toUpperCase() + name.slice(1);
17201750
}
17211751

1752+
function removeUnderscores(s: string): string {
1753+
for(let idx = s.indexOf('_'); idx >= 0; idx = s.indexOf('_')) {
1754+
if (idx === 0) {
1755+
s = s.slice(1);
1756+
} else if (idx < s.length - 1) {
1757+
s = s.slice(0, idx) + s.charAt(idx + 1).toUpperCase() + s.slice(idx + 2);
1758+
} else {
1759+
s = s.slice(0, idx);
1760+
}
1761+
}
1762+
return s;
1763+
}
1764+
17221765
function suffixFor(name: string): string {
17231766
for (let i = name.length - 1; i >= 0; i--) {
17241767
if (name.charAt(i).toUpperCase() === name.charAt(i)) {
@@ -2023,12 +2066,14 @@ function getMembers(decls: (InterfaceDeclaration | TypeLiteralNode)[], optionalP
20232066
return members;
20242067
}
20252068

2026-
function findProperties(decls: (InterfaceDeclaration | TypeLiteralNode)[], props: Map<string, PropertySignature>, nested: Set<TypeLiteralNode>): void {
2069+
function findProperties(decls: (InterfaceDeclaration | TypeLiteralNode)[], props: Map<string, PropertySignature>, overridenProperties: Map<string, PropertySignature>, nested: Set<TypeLiteralNode>): void {
20272070
getMembers(decls).forEach((member: TypeElement) => {
20282071
if (member.kind === SyntaxKind.PropertySignature) {
20292072
let memberName: string = member.name.getText();
20302073
if (!props.has(memberName)) {
20312074
props.set(memberName, member as PropertySignature);
2075+
} else {
2076+
overridenProperties.set(memberName, member as PropertySignature);
20322077
}
20332078
if (nested) {
20342079
let memberType = (member as PropertySignature).type;
@@ -2054,7 +2099,7 @@ function findProperties(decls: (InterfaceDeclaration | TypeLiteralNode)[], props
20542099
}
20552100
});
20562101
if (!hasMethods) {
2057-
findProperties([extDecl], props, null);
2102+
findProperties([extDecl], props, overridenProperties, null);
20582103
}
20592104
}
20602105
});

0 commit comments

Comments
 (0)