Skip to content

Commit 3257223

Browse files
author
Elad Ben-Israel
authored
fix(java): support abstract return types (#224)
Generate a $proxy class for all abstract classes and use them when the return type is abstract, similar to interface proxies. This change also adds "abstract: true" to all interface members, so the proxy generator can treat interfaces and classes polymorphically. Added a compliance test "returnAbstract" which verifies this behavior. Fixes #220 Related to #223 (.NET) Related to aws/aws-cdk#680 (require jsii update)
1 parent 72927bd commit 3257223

File tree

69 files changed

+7834
-6804
lines changed

Some content is hidden

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

69 files changed

+7834
-6804
lines changed

package-lock.json

Lines changed: 1321 additions & 1321 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/codemaker/package-lock.json

Lines changed: 641 additions & 641 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jsii-build-tools/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jsii-calc-base-of-base/test/assembly.jsii

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
"name": "VeryBaseProps",
5959
"properties": [
6060
{
61+
"abstract": true,
6162
"name": "foo",
6263
"type": {
6364
"fqn": "@scope/jsii-calc-base-of-base.Very"
@@ -67,5 +68,5 @@
6768
}
6869
},
6970
"version": "0.7.4",
70-
"fingerprint": "xM+yEz06NDR7n4G5n4VDoITs275dSqMhFDXgKOErl/M="
71+
"fingerprint": "uxjBWk0nRDSHNR2FL01kRusKUoxa53smUFsizIJYBSs="
7172
}

packages/jsii-calc-base/test/assembly.jsii

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
"name": "BaseProps",
9292
"properties": [
9393
{
94+
"abstract": true,
9495
"name": "bar",
9596
"type": {
9697
"primitive": "string"
@@ -100,5 +101,5 @@
100101
}
101102
},
102103
"version": "0.7.4",
103-
"fingerprint": "/t6/DercTjOI1TLjj3MowD7pZkpm70sJQdeKwQMpa9M="
104+
"fingerprint": "6NsGM++itCYmctZJdOp8kPJ3CfBnajQ78wNpY+EwZIQ="
104105
}

packages/jsii-calc-lib/test/assembly.jsii

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@
101101
"kind": "interface",
102102
"methods": [
103103
{
104+
"abstract": true,
104105
"docs": {
105106
"comment": "Say hello!"
106107
},
@@ -123,6 +124,7 @@
123124
"name": "MyFirstStruct",
124125
"properties": [
125126
{
127+
"abstract": true,
126128
"docs": {
127129
"comment": "An awesome number value"
128130
},
@@ -132,6 +134,7 @@
132134
}
133135
},
134136
{
137+
"abstract": true,
135138
"docs": {
136139
"comment": "A string value"
137140
},
@@ -141,6 +144,7 @@
141144
}
142145
},
143146
{
147+
"abstract": true,
144148
"name": "firstOptional",
145149
"type": {
146150
"collection": {
@@ -250,6 +254,7 @@
250254
"name": "StructWithOnlyOptionals",
251255
"properties": [
252256
{
257+
"abstract": true,
253258
"docs": {
254259
"comment": "The first optional!"
255260
},
@@ -260,13 +265,15 @@
260265
}
261266
},
262267
{
268+
"abstract": true,
263269
"name": "optional2",
264270
"type": {
265271
"optional": true,
266272
"primitive": "number"
267273
}
268274
},
269275
{
276+
"abstract": true,
270277
"name": "optional3",
271278
"type": {
272279
"optional": true,
@@ -317,5 +324,5 @@
317324
}
318325
},
319326
"version": "0.7.4",
320-
"fingerprint": "dGLkY7rPKJjBMLQCOCj5AXR3Q1+cZcoiazcIhDUV++8="
327+
"fingerprint": "PD1bhVhBjZ0dNrD8K4FK6RT+W5RhpkTEJDml/OiM7Ws="
321328
}

packages/jsii-calc/lib/compliance.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -813,4 +813,56 @@ export namespace InterfaceInNamespaceIncludesClasses {
813813
*/
814814
export interface InterfaceWithOptionalMethodArguments {
815815
hello(arg1: string, arg2?: number): void
816+
}
817+
818+
/**
819+
* awslabs/jsii#220
820+
* Abstract return type
821+
*/
822+
823+
export interface InterfaceImplementedByAbstractClass {
824+
readonly propFromInterface: string;
825+
}
826+
827+
export abstract class AbstractClassBase {
828+
public abstract readonly abstractProperty: string;
829+
}
830+
831+
export abstract class AbstractClass extends AbstractClassBase implements InterfaceImplementedByAbstractClass {
832+
public nonAbstractMethod() {
833+
return 42;
834+
}
835+
836+
public abstract abstractMethod(name: string): string;
837+
838+
public get propFromInterface() {
839+
return 'propFromInterfaceValue';
840+
}
841+
}
842+
843+
class ConcreteClass extends AbstractClass {
844+
public abstractMethod(name: string) {
845+
return `Hello, ${name}!!`;
846+
}
847+
848+
public get abstractProperty() {
849+
return 'Hello, dude!';
850+
}
851+
}
852+
853+
854+
export class AbstractClassReturner {
855+
public giveMeAbstract(): AbstractClass {
856+
return new ConcreteClass();
857+
}
858+
859+
public giveMeInterface(): InterfaceImplementedByAbstractClass {
860+
return new ConcreteClass();
861+
}
862+
863+
public get returnAbstractFromProperty(): AbstractClassBase {
864+
return {
865+
abstractProperty: 'hello-abstract-property'
866+
}
867+
}
816868
}

0 commit comments

Comments
 (0)