diff --git a/tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs b/tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs
index b0d6f3f49..ef1ed6060 100644
--- a/tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs
+++ b/tests/generator-Tests/Unit-Tests/XmlApiImporterTests.cs
@@ -1,4 +1,5 @@
using System;
+using System.Linq;
using System.Xml.Linq;
using MonoDroid.Generation;
using NUnit.Framework;
@@ -226,5 +227,22 @@ public void CreateParameter_NotNull ()
Assert.True (p.NotNull);
}
+
+ [Test]
+ public void PreserveSourceLineInfo ()
+ {
+ var xml = XDocument.Parse ("\n\n\n\n", LoadOptions.SetBaseUri | LoadOptions.SetLineInfo);
+ var klass = XmlApiImporter.CreateClass (xml.Root, xml.Root.Element ("class"), new CodeGenerationOptions { ApiXmlFile = "obj/Debug/api.xml" });
+
+ Assert.AreEqual (2, klass.LineNumber);
+ Assert.AreEqual (2, klass.LinePosition);
+ Assert.AreEqual ("obj/Debug/api.xml", klass.SourceFile);
+
+ var method = klass.Methods.Single ();
+
+ Assert.AreEqual (3, method.LineNumber);
+ Assert.AreEqual (2, method.LinePosition);
+ Assert.AreEqual ("obj/Debug/api.xml", method.SourceFile);
+ }
}
}
diff --git a/tools/generator/CodeGenerationOptions.cs b/tools/generator/CodeGenerationOptions.cs
index 3fb2eba63..7218798f5 100644
--- a/tools/generator/CodeGenerationOptions.cs
+++ b/tools/generator/CodeGenerationOptions.cs
@@ -48,6 +48,7 @@ internal CodeGenerator CreateCodeGenerator (TextWriter writer)
readonly SortedSet jni_marshal_delegates = new SortedSet ();
readonly object jni_marshal_delegates_lock = new object ();
+ public string ApiXmlFile { get; set; }
public bool UseGlobal { get; set; }
public bool IgnoreNonPublicType { get; set; }
public string AssemblyName { get; set; }
diff --git a/tools/generator/CodeGenerator.cs b/tools/generator/CodeGenerator.cs
index 3213aafed..d88daaafd 100644
--- a/tools/generator/CodeGenerator.cs
+++ b/tools/generator/CodeGenerator.cs
@@ -60,6 +60,7 @@ static void Run (CodeGeneratorOptions options, DirectoryAssemblyResolver resolve
string api_xml_adjuster_output = options.ApiXmlAdjusterOutput;
var apiSource = "";
var opt = new CodeGenerationOptions () {
+ ApiXmlFile = options.ApiDescriptionFile,
CodeGenerationTarget = options.CodeGenerationTarget,
UseGlobal = options.GlobalTypeNames,
IgnoreNonPublicType = true,
diff --git a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs
index a1aac094f..c24e65c3d 100644
--- a/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.CodeGeneration/CodeGenerator.cs
@@ -393,11 +393,11 @@ public bool WriteFields (List fields, string indent, GenBase gen, HashSet
bool needsProperty = false;
foreach (Field f in fields) {
if (gen.ContainsName (f.Name)) {
- Report.LogCodedWarning (0, SourceWriterExtensions.GetFieldCollisionMessage (gen, f), gen.FullName, f.Name, gen.JavaName);
+ Report.LogCodedWarning (0, SourceWriterExtensions.GetFieldCollisionMessage (gen, f), f, gen.FullName, f.Name, gen.JavaName);
continue;
}
if (seen != null && seen.Contains (f.Name)) {
- Report.LogCodedWarning (0, Report.WarningDuplicateField, gen.FullName, f.Name, gen.JavaName);
+ Report.LogCodedWarning (0, Report.WarningDuplicateField, f, gen.FullName, f.Name, gen.JavaName);
continue;
}
if (f.Validate (opt, gen.TypeParameters, Context)) {
@@ -935,11 +935,11 @@ public void WriteInterfaceListenerEventsAndProperties (InterfaceGen @interface,
foreach (var method in eventMethods) {
string name = method.CalculateEventName (target.ContainsName);
if (String.IsNullOrEmpty (name)) {
- Report.LogCodedWarning (0, Report.WarningEmptyEventName, @interface.FullName, method.Name);
+ Report.LogCodedWarning (0, Report.WarningEmptyEventName, method, @interface.FullName, method.Name);
continue;
}
if (opt.GetSafeIdentifier (name) != name) {
- Report.LogCodedWarning (0, Report.WarningInvalidEventName, @interface.FullName, method.Name);
+ Report.LogCodedWarning (0, Report.WarningInvalidEventName, method, @interface.FullName, method.Name);
continue;
}
var prop = target.Properties.FirstOrDefault (p => p.Setter == method);
@@ -996,7 +996,7 @@ public void WriteInterfaceListenerEventOrProperty (InterfaceGen @interface, Meth
full_delegate_name += "Handler";
if (m.RetVal.IsVoid || m.IsEventHandlerWithHandledProperty) {
if (opt.GetSafeIdentifier (name) != name) {
- Report.LogCodedWarning (0, Report.WarningInvalidEventName2, @interface.FullName, name);
+ Report.LogCodedWarning (0, Report.WarningInvalidEventName2, m, @interface.FullName, name);
return;
} else {
var mt = target.Methods.Where (method => string.Compare (method.Name, connector_fmt, StringComparison.OrdinalIgnoreCase) == 0 && method.IsListenerConnector).FirstOrDefault ();
@@ -1005,7 +1005,7 @@ public void WriteInterfaceListenerEventOrProperty (InterfaceGen @interface, Meth
}
} else {
if (opt.GetSafeIdentifier (name) != name) {
- Report.LogCodedWarning (0, Report.WarningInvalidEventPropertyName, @interface.FullName, name);
+ Report.LogCodedWarning (0, Report.WarningInvalidEventPropertyName, m, @interface.FullName, name);
return;
}
writer.WriteLine ("{0}WeakReference{2} weak_implementor_{1};", indent, name, opt.NullableOperator);
diff --git a/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs b/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs
index 32ad809eb..ebb58aa6d 100644
--- a/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.Importers/XmlApiImporter.cs
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using System.Text.RegularExpressions;
+using System.Xml;
using System.Xml.Linq;
using Java.Interop.Tools.JavaCallableWrappers;
using MonoDroid.Utils;
@@ -26,6 +27,7 @@ public static ClassGen CreateClass (XElement pkg, XElement elem, CodeGenerationO
};
FillApiSince (klass, pkg, elem);
+ SetLineInfo (klass, elem, options);
foreach (var child in elem.Elements ()) {
switch (child.Name.LocalName) {
@@ -35,18 +37,18 @@ public static ClassGen CreateClass (XElement pkg, XElement elem, CodeGenerationO
klass.AddImplementedInterface (iname);
break;
case "method":
- klass.AddMethod (CreateMethod (klass, child));
+ klass.AddMethod (CreateMethod (klass, child, options));
break;
case "constructor":
- klass.Ctors.Add (CreateCtor (klass, child));
+ klass.Ctors.Add (CreateCtor (klass, child, options));
break;
case "field":
- klass.AddField (CreateField (klass, child));
+ klass.AddField (CreateField (klass, child, options));
break;
case "typeParameters":
break; // handled at GenBaseSupport
default:
- Report.LogCodedWarning (0, Report.WarningUnexpectedChild, child.Name.ToString ());
+ Report.LogCodedWarning (0, Report.WarningUnexpectedChild, klass, child.Name.ToString ());
break;
}
}
@@ -54,7 +56,7 @@ public static ClassGen CreateClass (XElement pkg, XElement elem, CodeGenerationO
return klass;
}
- public static Ctor CreateCtor (GenBase declaringType, XElement elem)
+ public static Ctor CreateCtor (GenBase declaringType, XElement elem, CodeGenerationOptions options = null)
{
var ctor = new Ctor (declaringType) {
ApiAvailableSince = declaringType.ApiAvailableSince,
@@ -65,6 +67,8 @@ public static Ctor CreateCtor (GenBase declaringType, XElement elem)
Visibility = elem.Visibility ()
};
+ SetLineInfo (ctor, elem, options);
+
var idx = ctor.Name.LastIndexOf ('.');
if (idx > 0)
@@ -81,14 +85,14 @@ public static Ctor CreateCtor (GenBase declaringType, XElement elem)
if (enclosingType == null) {
ctor.MissingEnclosingClass = true;
- Report.LogCodedWarning (0, Report.WarningMissingClassForConstructor, ctor.Name, expectedEnclosingName);
+ Report.LogCodedWarning (0, Report.WarningMissingClassForConstructor, ctor, ctor.Name, expectedEnclosingName);
} else
- ctor.Parameters.AddFirst (CreateParameterFromClassElement (enclosingType));
+ ctor.Parameters.AddFirst (CreateParameterFromClassElement (enclosingType, options));
}
foreach (var child in elem.Elements ()) {
if (child.Name == "parameter")
- ctor.Parameters.Add (CreateParameter (child));
+ ctor.Parameters.Add (CreateParameter (child, options));
}
ctor.Name = EnsureValidIdentifer (ctor.Name);
@@ -98,7 +102,7 @@ public static Ctor CreateCtor (GenBase declaringType, XElement elem)
return ctor;
}
- public static Field CreateField (GenBase declaringType, XElement elem)
+ public static Field CreateField (GenBase declaringType, XElement elem, CodeGenerationOptions options = null)
{
var field = new Field {
ApiAvailableSince = declaringType.ApiAvailableSince,
@@ -110,7 +114,7 @@ public static Field CreateField (GenBase declaringType, XElement elem)
IsStatic = elem.XGetAttribute ("static") == "true",
JavaName = elem.XGetAttribute ("name"),
NotNull = elem.XGetAttribute ("not-null") == "true",
- SetterParameter = CreateParameter (elem),
+ SetterParameter = CreateParameter (elem, options),
TypeName = elem.XGetAttribute ("type"),
Value = elem.XGetAttribute ("value"), // do not trim
Visibility = elem.XGetAttribute ("visibility")
@@ -131,6 +135,7 @@ public static Field CreateField (GenBase declaringType, XElement elem)
}
FillApiSince (field, elem);
+ SetLineInfo (field, elem, options);
return field;
}
@@ -214,6 +219,7 @@ public static InterfaceGen CreateInterface (XElement pkg, XElement elem, CodeGen
};
FillApiSince (iface, pkg, elem);
+ SetLineInfo (iface, elem, options);
foreach (var child in elem.Elements ()) {
switch (child.Name.LocalName) {
@@ -223,15 +229,15 @@ public static InterfaceGen CreateInterface (XElement pkg, XElement elem, CodeGen
iface.AddImplementedInterface (iname);
break;
case "method":
- iface.AddMethod (CreateMethod (iface, child));
+ iface.AddMethod (CreateMethod (iface, child, options));
break;
case "field":
- iface.AddField (CreateField (iface, child));
+ iface.AddField (CreateField (iface, child, options));
break;
case "typeParameters":
break; // handled at GenBaseSupport
default:
- Report.LogCodedWarning (0, Report.WarningUnexpectedInterfaceChild, child.ToString ());
+ Report.LogCodedWarning (0, Report.WarningUnexpectedInterfaceChild, iface, child.ToString ());
break;
}
}
@@ -239,7 +245,7 @@ public static InterfaceGen CreateInterface (XElement pkg, XElement elem, CodeGen
return iface;
}
- public static Method CreateMethod (GenBase declaringType, XElement elem)
+ public static Method CreateMethod (GenBase declaringType, XElement elem, CodeGenerationOptions options = null)
{
var method = new Method (declaringType) {
ApiAvailableSince = declaringType.ApiAvailableSince,
@@ -284,7 +290,7 @@ public static Method CreateMethod (GenBase declaringType, XElement elem)
foreach (var child in elem.Elements ()) {
if (child.Name == "parameter")
- method.Parameters.Add (CreateParameter (child));
+ method.Parameters.Add (CreateParameter (child, options));
}
method.Name = EnsureValidIdentifer (method.Name);
@@ -292,11 +298,12 @@ public static Method CreateMethod (GenBase declaringType, XElement elem)
method.FillReturnType ();
FillApiSince (method, elem);
+ SetLineInfo (method, elem, options);
return method;
}
- public static Parameter CreateParameter (XElement elem)
+ public static Parameter CreateParameter (XElement elem, CodeGenerationOptions options = null)
{
string managedName = elem.XGetAttribute ("managedName");
string name = !string.IsNullOrEmpty (managedName) ? managedName : TypeNameUtilities.MangleName (EnsureValidIdentifer (elem.XGetAttribute ("name")));
@@ -308,15 +315,19 @@ public static Parameter CreateParameter (XElement elem)
var result = new Parameter (name, enum_type ?? java_type, enum_type ?? managed_type, enum_type != null, java_type, not_null);
if (elem.Attribute ("sender") != null)
result.IsSender = true;
+ SetLineInfo (result, elem, options);
return result;
}
- public static Parameter CreateParameterFromClassElement (XElement elem)
+ public static Parameter CreateParameterFromClassElement (XElement elem, CodeGenerationOptions options)
{
string name = "__self";
string java_type = elem.XGetAttribute ("name");
string java_package = elem.Parent.XGetAttribute ("name");
- return new Parameter (name, java_package + "." + java_type, null, false);
+ var p = new Parameter (name, java_package + "." + java_type, null, false);
+
+ SetLineInfo (p, elem, options);
+ return p;
}
static string EnsureValidIdentifer (string name)
@@ -403,5 +414,15 @@ static bool IsPrefixableName (string name)
// IBlahBlah is not prefixed with 'I'
return name.Length <= 2 || name [0] != 'I' || !char.IsUpper (name [1]);
}
+
+ static void SetLineInfo (ISourceLineInfo model, XNode node, CodeGenerationOptions options)
+ {
+ model.SourceFile = options?.ApiXmlFile;
+
+ if (node is IXmlLineInfo info && info.HasLineInfo ()) {
+ model.LineNumber = info.LineNumber;
+ model.LinePosition = info.LinePosition;
+ }
+ }
}
}
diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs
index 1d04a5f76..e65a9f296 100644
--- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ClassGen.cs
@@ -294,13 +294,13 @@ protected override bool OnValidate (CodeGenerationOptions opt, GenericParameterD
base_symbol = IsAnnotation ? opt.SymbolTable.Lookup ("java.lang.Object") : BaseType != null ? opt.SymbolTable.Lookup (BaseType) : null;
if (base_symbol == null && FullName != "Java.Lang.Object" && FullName != "System.Object") {
- Report.LogCodedWarning (0, Report.WarningUnknownBaseType, FullName, BaseType);
+ Report.LogCodedWarning (0, Report.WarningUnknownBaseType, this, FullName, BaseType);
IsValid = false;
return false;
}
if ((base_symbol != null && !base_symbol.Validate (opt, TypeParameters, context)) || !base.OnValidate (opt, type_params, context)) {
- Report.LogCodedWarning (0, Report.WarningInvalidBaseType, FullName, BaseType);
+ Report.LogCodedWarning (0, Report.WarningInvalidBaseType, this, FullName, BaseType);
IsValid = false;
return false;
}
diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs
index 8dd82cbe2..7df4d8348 100644
--- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Field.cs
@@ -4,7 +4,7 @@
namespace MonoDroid.Generation
{
- public class Field : ApiVersionsSupport.IApiAvailability
+ public class Field : ApiVersionsSupport.IApiAvailability, ISourceLineInfo
{
public string Annotation { get; set; }
public int ApiAvailableSince { get; set; }
@@ -25,6 +25,10 @@ public class Field : ApiVersionsSupport.IApiAvailability
public string Value { get; set; }
public string Visibility { get; set; }
+ public int LineNumber { get; set; } = -1;
+ public int LinePosition { get; set; } = -1;
+ public string SourceFile { get; set; }
+
internal string GetMethodPrefix => TypeNameUtilities.GetCallPrefix (Symbol);
internal string ID => JavaName + "_jfieldId";
@@ -38,7 +42,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.GetContextTypeMember ());
+ Report.LogCodedWarning (0, Report.WarningUnexpectedFieldType, this, TypeName, context.GetContextTypeMember ());
return false;
}
diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs
index dc098c96f..2fa22ee43 100644
--- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/GenBase.cs
@@ -6,7 +6,7 @@
namespace MonoDroid.Generation
{
- public abstract class GenBase : IGeneratable, ApiVersionsSupport.IApiAvailability
+ public abstract class GenBase : IGeneratable, ApiVersionsSupport.IApiAvailability, ISourceLineInfo
{
bool enum_updated;
bool property_filled;
@@ -33,6 +33,10 @@ protected GenBase (GenBaseSupport support)
public string DefaultValue { get; set; }
public bool HasVirtualMethods { get; set; }
+ public int LineNumber { get; set; } = -1;
+ public int LinePosition { get; set; } = -1;
+ public string SourceFile { get; set; }
+
public string ReturnCast => string.Empty;
// This means Ctors/Methods/Properties/Fields has not been populated yet.
@@ -662,9 +666,9 @@ protected virtual bool OnValidate (CodeGenerationOptions opt, GenericParameterDe
Interfaces.Add (isym);
else {
if (isym == null)
- Report.LogCodedWarning (0, Report.WarningBaseInterfaceNotFound, FullName, iface_name);
+ Report.LogCodedWarning (0, Report.WarningBaseInterfaceNotFound, this, FullName, iface_name);
else
- Report.LogCodedWarning (0, Report.WarningBaseInterfaceInvalid, FullName, iface_name);
+ Report.LogCodedWarning (0, Report.WarningBaseInterfaceInvalid, this, FullName, iface_name);
iface_validation_failed = true;
}
}
diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ISourceLineInfo.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ISourceLineInfo.cs
new file mode 100644
index 000000000..1c0fec851
--- /dev/null
+++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ISourceLineInfo.cs
@@ -0,0 +1,15 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace MonoDroid.Generation
+{
+ public interface ISourceLineInfo
+ {
+ int LineNumber { get; set; }
+ int LinePosition { get; set; }
+ string SourceFile { get; set; }
+ }
+}
diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/InterfaceGen.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/InterfaceGen.cs
index e4154fb24..70f090d38 100644
--- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/InterfaceGen.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/InterfaceGen.cs
@@ -204,9 +204,9 @@ protected override bool OnValidate (CodeGenerationOptions opt, GenericParameterD
if (!base.OnValidate (opt, type_params, context) || iface_validation_failed || MethodValidationFailed) {
if (iface_validation_failed)
- Report.LogCodedWarning (0, Report.WarningInvalidDueToInterfaces, FullName);
+ Report.LogCodedWarning (0, Report.WarningInvalidDueToInterfaces, this, FullName);
else if (MethodValidationFailed)
- Report.LogCodedWarning (0, Report.WarningInvalidDueToMethods, FullName);
+ Report.LogCodedWarning (0, Report.WarningInvalidDueToMethods, this, FullName);
foreach (GenBase nest in NestedTypes)
nest.Invalidate ();
IsValid = false;
diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs
index c0b3d5efe..e79b7c78d 100644
--- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/MethodBase.cs
@@ -5,7 +5,7 @@
namespace MonoDroid.Generation
{
- public abstract class MethodBase : ApiVersionsSupport.IApiAvailability
+ public abstract class MethodBase : ApiVersionsSupport.IApiAvailability, ISourceLineInfo
{
protected MethodBase (GenBase declaringType)
{
@@ -24,6 +24,10 @@ protected MethodBase (GenBase declaringType)
public ParameterList Parameters { get; } = new ParameterList ();
public string Visibility { get; set; }
+ public int LineNumber { get; set; } = -1;
+ public int LinePosition { get; set; } = -1;
+ public string SourceFile { get; set; }
+
public string [] AutoDetectEnumifiedOverrideParameters (AncestorDescendantCache cache)
{
if (Parameters.All (p => p.Type != "int"))
diff --git a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs
index 19c4bb9ce..120f728d2 100644
--- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/Parameter.cs
@@ -10,14 +10,18 @@
namespace MonoDroid.Generation {
- public class Parameter {
-
+ public class Parameter : ISourceLineInfo
+ {
bool is_sender;
string name;
string type, managed_type, rawtype;
ISymbol sym;
bool is_enumified;
+ public int LineNumber { get; set; } = -1;
+ public int LinePosition { get; set; } = -1;
+ public string SourceFile { get; set; }
+
internal Parameter (string name, string type, string managedType, bool isEnumified, string rawtype = null, bool notNull = false)
{
this.name = name;
@@ -262,11 +266,11 @@ public bool Validate (CodeGenerationOptions opt, GenericParameterDefinitionList
{
sym = opt.SymbolTable.Lookup (type, type_params);
if (sym == null) {
- Report.LogCodedWarning (0, Report.WarningUnknownParameterType, type, context.GetContextTypeMember ());
+ Report.LogCodedWarning (0, Report.WarningUnknownParameterType, this, type, context.GetContextTypeMember ());
return false;
}
if (!sym.Validate (opt, type_params, context)) {
- Report.LogCodedWarning (0, Report.WarningInvalidParameterType, type, context.GetContextTypeMember ());
+ Report.LogCodedWarning (0, Report.WarningInvalidParameterType, this, 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 a25eb6489..efb07e660 100644
--- a/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs
+++ b/tools/generator/Java.Interop.Tools.Generator.ObjectModel/ReturnValue.cs
@@ -14,12 +14,14 @@ public class ReturnValue {
string managed_type;
string raw_type;
bool is_enumified;
+ Method owner;
public ReturnValue (Method owner, string java_type, string managed_type, bool isEnumified, bool notNull)
{
this.raw_type = this.java_type = java_type;
this.managed_type = managed_type;
this.is_enumified = isEnumified;
+ this.owner = owner;
NotNull = notNull;
}
@@ -121,11 +123,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.GetContextTypeMember ());
+ Report.LogCodedWarning (0, Report.WarningUnknownReturnType, owner, java_type, context.GetContextTypeMember ());
return false;
}
if (!sym.Validate (opt, type_params, context)) {
- Report.LogCodedWarning (0, Report.WarningInvalidReturnType, java_type, context.GetContextTypeMember ());
+ Report.LogCodedWarning (0, Report.WarningInvalidReturnType, owner, java_type, context.GetContextTypeMember ());
return false;
}
return true;
diff --git a/tools/generator/SourceWriters/Extensions/SourceWriterExtensions.cs b/tools/generator/SourceWriters/Extensions/SourceWriterExtensions.cs
index fee55891a..06928531c 100644
--- a/tools/generator/SourceWriters/Extensions/SourceWriterExtensions.cs
+++ b/tools/generator/SourceWriters/Extensions/SourceWriterExtensions.cs
@@ -24,12 +24,12 @@ public static bool AddFields (TypeWriter tw, GenBase gen, List fields, Ha
foreach (var f in fields) {
if (gen.ContainsName (f.Name)) {
- Report.LogCodedWarning (0, GetFieldCollisionMessage (gen, f), gen.FullName, f.Name, gen.JavaName);
+ Report.LogCodedWarning (0, GetFieldCollisionMessage (gen, f), f, gen.FullName, f.Name, gen.JavaName);
continue;
}
if (seen != null && seen.Contains (f.Name)) {
- Report.LogCodedWarning (0, Report.WarningDuplicateField, gen.FullName, f.Name, gen.JavaName);
+ Report.LogCodedWarning (0, Report.WarningDuplicateField, f, gen.FullName, f.Name, gen.JavaName);
continue;
}
@@ -66,12 +66,12 @@ public static void AddInterfaceListenerEventsAndProperties (TypeWriter tw, Inter
var name = method.CalculateEventName (target.ContainsName);
if (string.IsNullOrEmpty (name)) {
- Report.LogCodedWarning (0, Report.WarningEmptyEventName, iface.FullName, method.Name);
+ Report.LogCodedWarning (0, Report.WarningEmptyEventName, method, iface.FullName, method.Name);
continue;
}
if (opt.GetSafeIdentifier (name) != name) {
- Report.LogCodedWarning (0, Report.WarningInvalidEventName, iface.FullName, method.Name);
+ Report.LogCodedWarning (0, Report.WarningInvalidEventName, method, iface.FullName, method.Name);
continue;
}
@@ -150,7 +150,7 @@ public static void AddInterfaceListenerEventOrProperty (TypeWriter tw, Interface
if (method.RetVal.IsVoid || method.IsEventHandlerWithHandledProperty) {
if (opt.GetSafeIdentifier (name) != name) {
- Report.LogCodedWarning (0, Report.WarningInvalidEventName2, iface.FullName, name);
+ Report.LogCodedWarning (0, Report.WarningInvalidEventName2, method, iface.FullName, name);
return;
} else {
var mt = target.Methods.Where (method => string.Compare (method.Name, connector_fmt, StringComparison.OrdinalIgnoreCase) == 0 && method.IsListenerConnector).FirstOrDefault ();
@@ -160,7 +160,7 @@ public static void AddInterfaceListenerEventOrProperty (TypeWriter tw, Interface
}
} else {
if (opt.GetSafeIdentifier (name) != name) {
- Report.LogCodedWarning (0, Report.WarningInvalidEventPropertyName, iface.FullName, name);
+ Report.LogCodedWarning (0, Report.WarningInvalidEventPropertyName, method, iface.FullName, name);
return;
}
diff --git a/tools/generator/SourceWriters/InterfaceMemberAlternativeClass.cs b/tools/generator/SourceWriters/InterfaceMemberAlternativeClass.cs
index f37981157..8da4efe2f 100644
--- a/tools/generator/SourceWriters/InterfaceMemberAlternativeClass.cs
+++ b/tools/generator/SourceWriters/InterfaceMemberAlternativeClass.cs
@@ -101,12 +101,12 @@ bool AddInterfaceFields (InterfaceGen iface, List fields, HashSet
foreach (var f in fields) {
if (iface.ContainsName (f.Name)) {
- Report.LogCodedWarning (0, SourceWriterExtensions.GetFieldCollisionMessage (iface, f), iface.FullName, f.Name, iface.JavaName);
+ Report.LogCodedWarning (0, SourceWriterExtensions.GetFieldCollisionMessage (iface, f), f, iface.FullName, f.Name, iface.JavaName);
continue;
}
if (seen.Contains (f.Name)) {
- Report.LogCodedWarning (0, Report.WarningDuplicateField, iface.FullName, f.Name, iface.JavaName);
+ Report.LogCodedWarning (0, Report.WarningDuplicateField, f, iface.FullName, f.Name, iface.JavaName);
continue;
}
diff --git a/tools/generator/Utilities/Report.cs b/tools/generator/Utilities/Report.cs
index d32bb1d63..b752b00e2 100644
--- a/tools/generator/Utilities/Report.cs
+++ b/tools/generator/Utilities/Report.cs
@@ -91,6 +91,9 @@ public static void LogCodedError (LocalizedMessage message, Exception innerExcep
public static void LogCodedWarning (int verbosity, LocalizedMessage message, params string [] args)
=> LogCodedWarning (verbosity, message, null, null, -1, -1, args);
+ public static void LogCodedWarning (int verbosity, LocalizedMessage message, ISourceLineInfo sourceInfo, params string [] args)
+ => LogCodedWarning (verbosity, message, null, sourceInfo.SourceFile, sourceInfo.LineNumber, sourceInfo.LinePosition, args);
+
public static void LogCodedWarning (int verbosity, LocalizedMessage message, Exception innerException, params string [] args)
=> LogCodedWarning (verbosity, message, innerException, null, -1, -1, args);
diff --git a/tools/generator/generator.slnf b/tools/generator/generator.slnf
index f697d9753..a292ff721 100644
--- a/tools/generator/generator.slnf
+++ b/tools/generator/generator.slnf
@@ -7,6 +7,7 @@
"src\\Java.Interop.Tools.Cecil\\Java.Interop.Tools.Cecil.csproj",
"src\\Java.Interop.Tools.JavaCallableWrappers\\Java.Interop.Tools.JavaCallableWrappers.csproj",
"src\\Java.Interop.Tools.Diagnostics\\Java.Interop.Tools.Diagnostics.csproj",
+ "src\\Java.Interop.Tools.Generator\\Java.Interop.Tools.Generator.csproj",
"src\\Xamarin.Android.Tools.AnnotationSupport\\Xamarin.Android.Tools.AnnotationSupport.csproj",
"src\\Xamarin.Android.Tools.ApiXmlAdjuster\\Xamarin.Android.Tools.ApiXmlAdjuster.csproj",
"src\\Xamarin.Android.Tools.Bytecode\\Xamarin.Android.Tools.Bytecode.csproj",