in packages/jsii-pacmak/lib/targets/java.ts [1882:1961]
private emitProxy(type: reflect.InterfaceType | reflect.ClassType) {
const name = INTERFACE_PROXY_CLASS_NAME;
this.code.line();
this.code.line('/**');
this.code.line(
' * A proxy class which represents a concrete javascript instance of this type.',
);
this.code.line(' */');
const baseInterfaces = this.defaultInterfacesFor(type, {
includeThisType: true,
});
if (type.isInterfaceType() && !hasDefaultInterfaces(type.assembly)) {
// Extend this interface directly since this module does not have the Jsii$Default
baseInterfaces.push(this.toNativeFqn(type.fqn));
}
const suffix = type.isInterfaceType()
? `extends software.amazon.jsii.JsiiObject implements ${baseInterfaces.join(
', ',
)}`
: `extends ${this.toNativeFqn(type.fqn)}${
baseInterfaces.length > 0
? ` implements ${baseInterfaces.join(', ')}`
: ''
}`;
const modifiers = type.isInterfaceType() ? 'final' : 'private static final';
this.code.line(ANN_INTERNAL);
this.code.openBlock(`${modifiers} class ${name} ${suffix}`);
this.code.openBlock(
`protected ${name}(final software.amazon.jsii.JsiiObjectRef objRef)`,
);
this.code.line('super(objRef);');
this.code.closeBlock();
// emit all properties
for (const reflectProp of type.allProperties.filter(
(prop) =>
prop.abstract &&
(prop.parentType.fqn === type.fqn ||
prop.parentType.isClassType() ||
!hasDefaultInterfaces(prop.assembly)),
)) {
const prop = clone(reflectProp.spec);
prop.abstract = false;
// Emitting "final" since this is a proxy and nothing will/should override this
this.emitProperty(type.spec, prop, reflectProp.definingType.spec, {
final: true,
overrides: true,
});
}
// emit all the methods
for (const reflectMethod of type.allMethods.filter(
(method) =>
method.abstract &&
(method.parentType.fqn === type.fqn ||
method.parentType.isClassType() ||
!hasDefaultInterfaces(method.assembly)),
)) {
const method = clone(reflectMethod.spec);
method.abstract = false;
// Emitting "final" since this is a proxy and nothing will/should override this
this.emitMethod(type.spec, method, { final: true, overrides: true });
for (const overloadedMethod of this.createOverloadsForOptionals(method)) {
overloadedMethod.abstract = false;
this.emitMethod(type.spec, overloadedMethod, {
final: true,
overrides: true,
});
}
}
this.code.closeBlock();
}