Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(dontet): excessive overrides generated #3355

Merged
merged 2 commits into from Jan 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -76,7 +76,7 @@ IEnumerable<Override> GetMethodOverrides()
var inheritedAttribute = method.GetAttribute<JsiiMethodAttribute>();
var uninheritedAttribute = method.GetAttribute<JsiiMethodAttribute>(false);

if ((inheritedAttribute != null && uninheritedAttribute == null) || uninheritedAttribute?.IsOverride == true)
if (inheritedAttribute != null && uninheritedAttribute == null)
{
yield return new Override(method: (inheritedAttribute ?? uninheritedAttribute)!.Name);
}
Expand All @@ -93,7 +93,7 @@ IEnumerable<Override> GetPropertyOverrides()
var inheritedAttribute = property.GetAttribute<JsiiPropertyAttribute>();
var uninheritedAttribute = property.GetAttribute<JsiiPropertyAttribute>(false);

if ((inheritedAttribute != null && uninheritedAttribute == null) || uninheritedAttribute?.IsOverride == true)
if (inheritedAttribute != null && uninheritedAttribute == null)
{
yield return new Override(property: (inheritedAttribute ?? uninheritedAttribute)!.Name);
}
Expand Down
Expand Up @@ -12,6 +12,7 @@ public sealed class JsiiMethodAttribute : Attribute
string? returnsJson = null,
string? parametersJson = null,
bool isAsync = false,
// Unused, retained for backwards-compatibility
bool isOverride = false)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Expand All @@ -23,7 +24,6 @@ public sealed class JsiiMethodAttribute : Attribute
: JsonConvert.DeserializeObject<Parameter[]>(parametersJson)
?? throw new ArgumentException("Invalid JSON descriptor", nameof(parametersJson));
IsAsync = isAsync;
IsOverride = isOverride;
}

public string Name { get; }
Expand All @@ -34,7 +34,5 @@ public sealed class JsiiMethodAttribute : Attribute


public bool IsAsync { get; }

public bool IsOverride { get; }
}
}
}
Expand Up @@ -7,22 +7,24 @@ namespace Amazon.JSII.Runtime.Deputy
[AttributeUsage(AttributeTargets.Property)]
public sealed class JsiiPropertyAttribute : Attribute, IOptionalValue
{
public JsiiPropertyAttribute(string name, string typeJson, bool isOptional = false, bool isOverride = false)
public JsiiPropertyAttribute(
string name,
string typeJson,
bool isOptional = false,
// Unused, retained for backwards-compatibility
bool isOverride = false)
{
Name = name ?? throw new ArgumentNullException(nameof(name));
Type = JsonConvert.DeserializeObject<TypeReference>(typeJson ??
throw new ArgumentNullException(nameof(typeJson)))
?? throw new ArgumentException("Invalid JSON descriptor", nameof(typeJson));
IsOptional = isOptional;
IsOverride = isOverride;
}

public string Name { get; }

public TypeReference Type { get; }

public bool IsOptional { get; }

public bool IsOverride { get; }
}
}
}
2 changes: 1 addition & 1 deletion packages/jsii-pacmak/lib/targets/dotnet/dotnetgenerator.ts
Expand Up @@ -942,7 +942,7 @@ export class DotNetGenerator extends Generator {
if (prop.optional) {
this.code.line('[JsiiOptional]');
}
this.dotnetRuntimeGenerator.emitAttributesForProperty(prop, datatype);
this.dotnetRuntimeGenerator.emitAttributesForProperty(prop);

let isOverrideKeyWord = '';
let isVirtualKeyWord = '';
Expand Down
15 changes: 4 additions & 11 deletions packages/jsii-pacmak/lib/targets/dotnet/dotnetruntimegenerator.ts
Expand Up @@ -78,8 +78,6 @@ export class DotNetRuntimeGenerator {
cls: spec.ClassType | spec.InterfaceType,
method: spec.Method /*, emitForProxyOrDatatype: boolean = false*/,
): void {
const isOverride =
spec.isClassType(cls) && method.overrides ? ', isOverride: true' : '';
const isAsync =
spec.isClassType(cls) && method.async ? ', isAsync: true' : '';
const parametersJson = method.parameters
Expand All @@ -92,28 +90,23 @@ export class DotNetRuntimeGenerator {
.replace(/"/g, '\\"')
.replace(/\\{2}"/g, 'test')}"`
: '';
const jsiiAttribute = `[JsiiMethod(name: "${method.name}"${returnsJson}${parametersJson}${isAsync}${isOverride})]`;
const jsiiAttribute = `[JsiiMethod(name: "${method.name}"${returnsJson}${parametersJson}${isAsync})]`;
this.code.line(jsiiAttribute);
this.emitDeprecatedAttributeIfNecessary(method);
}

/**
* Emits the proper jsii .NET attribute for a property
*
* Ex: [JsiiProperty(name: "foo", typeJson: "{\"fqn\":\"@scope/jsii-calc-base-of-base.Very\"}", isOptional: true, isOverride: true)]
* Ex: [JsiiProperty(name: "foo", typeJson: "{\"fqn\":\"@scope/jsii-calc-base-of-base.Very\"}", isOptional: true)]
*/
public emitAttributesForProperty(
prop: spec.Property,
datatype = false,
): void {
// If we are on a datatype then we want the property to override in Jsii
const isJsiiOverride = datatype ? ', isOverride: true' : '';
public emitAttributesForProperty(prop: spec.Property): void {
const isOptionalJsii = prop.optional ? ', isOptional: true' : '';
const jsiiAttribute =
`[JsiiProperty(name: "${prop.name}", ` +
`typeJson: "${JSON.stringify(prop.type)
.replace(/"/g, '\\"')
.replace(/\\{2}"/g, 'test')}"${isOptionalJsii}${isJsiiOverride})]`;
.replace(/\\{2}"/g, 'test')}"${isOptionalJsii})]`;
this.code.line(jsiiAttribute);
this.emitDeprecatedAttributeIfNecessary(prop);
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.