From 4131e6f9cacf4c9cf780526c838cc311b45e0b7a Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Fri, 28 Aug 2020 11:55:05 -0500 Subject: [PATCH 1/3] [generator] Fix localization error. --- tools/generator/CodeGeneratorContext.cs | 1 + .../Java.Interop.Tools.Generator.ObjectModel/Field.cs | 2 +- .../GenericParameterDefinition.cs | 2 +- .../Java.Interop.Tools.Generator.ObjectModel/Parameter.cs | 4 ++-- .../Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs | 4 ++-- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/tools/generator/CodeGeneratorContext.cs b/tools/generator/CodeGeneratorContext.cs index c91e58769..21855d1f4 100644 --- a/tools/generator/CodeGeneratorContext.cs +++ b/tools/generator/CodeGeneratorContext.cs @@ -16,5 +16,6 @@ public class CodeGeneratorContext string ContextMethodString => ContextMethod != null ? "in method " + ContextMethod.Name + " " : null; string ContextTypeString => ContextType != null ? "in managed type " + ContextType.FullName : null; public string ContextString => ContextFieldString + ContextMethodString + ContextTypeString; + public string ContextTypeMember => (ContextType != null ? $"{ContextType.FullName}." : string.Empty) + ContextMethod?.Name ?? ContextField?.Name; } } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs index be75bbb2a..91f8d0ce5 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs @@ -38,7 +38,7 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList Symbol = opt.SymbolTable.Lookup (TypeName, type_params); if (Symbol == null || !Symbol.Validate (opt, type_params, context)) { - Report.LogCodedWarning (0, Report.WarningUnexpectedFieldType, TypeName, context.ContextString); + Report.LogCodedWarning (0, Report.WarningUnexpectedFieldType, TypeName, context.ContextTypeMember); return false; } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenericParameterDefinition.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenericParameterDefinition.cs index d98f88634..36ffdd378 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenericParameterDefinition.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenericParameterDefinition.cs @@ -38,7 +38,7 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList foreach (var c in ConstraintExpressions) { var sym = opt.SymbolTable.Lookup (c, type_params); if (sym == null) { - Report.LogCodedWarning (0, Report.WarningUnknownGenericConstraint, c, context.ContextString); + Report.LogCodedWarning (0, Report.WarningUnknownGenericConstraint, c, context.ContextTypeMember); validated = true; return false; } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs index c4ff3c7c2..128f1719f 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs @@ -260,11 +260,11 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList { sym = opt.SymbolTable.Lookup (type, type_params); if (sym == null) { - Report.LogCodedWarning (0, Report.WarningUnknownParameterType, type, context.ContextString); + Report.LogCodedWarning (0, Report.WarningUnknownParameterType, type, context.ContextTypeMember); return false; } if (!sym.Validate (opt, type_params, context)) { - Report.LogCodedWarning (0, Report.WarningInvalidParameterType, type, context.ContextString); + Report.LogCodedWarning (0, Report.WarningInvalidParameterType, type, context.ContextTypeMember); return false; } return true; diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs index 484e537ca..d2d43cd19 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs @@ -121,11 +121,11 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList { sym = (IsEnumified ? opt.SymbolTable.Lookup (managed_type, type_params) : null) ?? opt.SymbolTable.Lookup (java_type, type_params); if (sym == null) { - Report.LogCodedWarning (0, Report.WarningUnknownReturnType, java_type, context.ContextString); + Report.LogCodedWarning (0, Report.WarningUnknownReturnType, java_type, context.ContextTypeMember); return false; } if (!sym.Validate (opt, type_params, context)) { - Report.LogCodedWarning (0, Report.WarningInvalidReturnType, java_type, context.ContextString); + Report.LogCodedWarning (0, Report.WarningInvalidReturnType, java_type, context.ContextTypeMember); return false; } return true; From 5fdd9447071692a823c242016d24091bfde66b17 Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Fri, 28 Aug 2020 13:30:37 -0500 Subject: [PATCH 2/3] Address feedback. --- tools/generator/CodeGeneratorContext.cs | 13 ++++++++++++- .../Field.cs | 2 +- .../GenericParameterDefinition.cs | 2 +- .../Parameter.cs | 6 ++++-- .../ReturnValue.cs | 4 ++-- 5 files changed, 20 insertions(+), 7 deletions(-) diff --git a/tools/generator/CodeGeneratorContext.cs b/tools/generator/CodeGeneratorContext.cs index 21855d1f4..c4aa4cb4e 100644 --- a/tools/generator/CodeGeneratorContext.cs +++ b/tools/generator/CodeGeneratorContext.cs @@ -16,6 +16,17 @@ public class CodeGeneratorContext string ContextMethodString => ContextMethod != null ? "in method " + ContextMethod.Name + " " : null; string ContextTypeString => ContextType != null ? "in managed type " + ContextType.FullName : null; public string ContextString => ContextFieldString + ContextMethodString + ContextTypeString; - public string ContextTypeMember => (ContextType != null ? $"{ContextType.FullName}." : string.Empty) + ContextMethod?.Name ?? ContextField?.Name; + + public string GetContextTypeMember () + { + var output = ContextType?.FullName ?? string.Empty; + + if (ContextMethod != null) { + output += $"{ContextMethod.Name} ({string.Join (", ", ContextMethod?.Parameters.Select (p => p.RawType).ToArray ())})"; + return output; + } + + return output + ContextField?.Name; + } } } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs index 91f8d0ce5..8dd82cbe2 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs @@ -38,7 +38,7 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList Symbol = opt.SymbolTable.Lookup (TypeName, type_params); if (Symbol == null || !Symbol.Validate (opt, type_params, context)) { - Report.LogCodedWarning (0, Report.WarningUnexpectedFieldType, TypeName, context.ContextTypeMember); + Report.LogCodedWarning (0, Report.WarningUnexpectedFieldType, TypeName, context.GetContextTypeMember ()); return false; } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenericParameterDefinition.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenericParameterDefinition.cs index 36ffdd378..9cf846206 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenericParameterDefinition.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenericParameterDefinition.cs @@ -38,7 +38,7 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList foreach (var c in ConstraintExpressions) { var sym = opt.SymbolTable.Lookup (c, type_params); if (sym == null) { - Report.LogCodedWarning (0, Report.WarningUnknownGenericConstraint, c, context.ContextTypeMember); + Report.LogCodedWarning (0, Report.WarningUnknownGenericConstraint, c, context.GetContextTypeMember ()); validated = true; return false; } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs index 128f1719f..9ebd71cf6 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs @@ -224,6 +224,8 @@ public string Type { get { return managed_type ?? sym.FullName; } } + public string RawType => type; + public string Annotation { get; internal set; } public void SetGeneratedEnumType (string enumType) @@ -260,11 +262,11 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList { sym = opt.SymbolTable.Lookup (type, type_params); if (sym == null) { - Report.LogCodedWarning (0, Report.WarningUnknownParameterType, type, context.ContextTypeMember); + Report.LogCodedWarning (0, Report.WarningUnknownParameterType, type, context.GetContextTypeMember ()); return false; } if (!sym.Validate (opt, type_params, context)) { - Report.LogCodedWarning (0, Report.WarningInvalidParameterType, type, context.ContextTypeMember); + Report.LogCodedWarning (0, Report.WarningInvalidParameterType, type, context.GetContextTypeMember ()); return false; } return true; diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs index d2d43cd19..a25eb6489 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs @@ -121,11 +121,11 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList { sym = (IsEnumified ? opt.SymbolTable.Lookup (managed_type, type_params) : null) ?? opt.SymbolTable.Lookup (java_type, type_params); if (sym == null) { - Report.LogCodedWarning (0, Report.WarningUnknownReturnType, java_type, context.ContextTypeMember); + Report.LogCodedWarning (0, Report.WarningUnknownReturnType, java_type, context.GetContextTypeMember ()); return false; } if (!sym.Validate (opt, type_params, context)) { - Report.LogCodedWarning (0, Report.WarningInvalidReturnType, java_type, context.ContextTypeMember); + Report.LogCodedWarning (0, Report.WarningInvalidReturnType, java_type, context.GetContextTypeMember ()); return false; } return true; From 441024e08b2a8b0bf661e82a4029b974da64c77e Mon Sep 17 00:00:00 2001 From: Jonathan Pobst Date: Fri, 28 Aug 2020 14:14:31 -0500 Subject: [PATCH 3/3] Address feedback. --- tools/generator/CodeGeneratorContext.cs | 2 +- .../Java.Interop.Tools.Generator.ObjectModel/Parameter.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/generator/CodeGeneratorContext.cs b/tools/generator/CodeGeneratorContext.cs index c4aa4cb4e..87a321500 100644 --- a/tools/generator/CodeGeneratorContext.cs +++ b/tools/generator/CodeGeneratorContext.cs @@ -22,7 +22,7 @@ public string GetContextTypeMember () var output = ContextType?.FullName ?? string.Empty; if (ContextMethod != null) { - output += $"{ContextMethod.Name} ({string.Join (", ", ContextMethod?.Parameters.Select (p => p.RawType).ToArray ())})"; + output += $"{ContextMethod.Name} ({string.Join (", ", ContextMethod?.Parameters.Select (p => p.InternalType).ToArray ())})"; return output; } diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs index 9ebd71cf6..19c4bb9ce 100644 --- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs +++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs @@ -224,7 +224,7 @@ public string Type { get { return managed_type ?? sym.FullName; } } - public string RawType => type; + public string InternalType => managed_type ?? sym?.FullName ?? type; public string Annotation { get; internal set; }