Skip to content

Commit 146213f

Browse files
committed
Address feedback.
1 parent 2af1848 commit 146213f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

src/Java.Interop.Tools.Generator/Utilities/Report.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Xml;
34
using System.Xml.Linq;
45

@@ -7,7 +8,7 @@ namespace Java.Interop.Tools.Generator
78
public class Report
89
{
910
public static int? Verbosity { get; set; }
10-
public static Action<string>? OutputDelegate { get; set; }
11+
public static Action<TraceLevel, string>? OutputDelegate { get; set; }
1112

1213
public class LocalizedMessage
1314
{
@@ -97,7 +98,7 @@ public static void LogCodedError (LocalizedMessage message, XNode? node, params
9798

9899
public static void LogCodedError (LocalizedMessage message, string? sourceFile, int line, int column, params string? [] args)
99100
{
100-
WriteOutput (Format (true, message.Code, sourceFile, line, column, message.Value, args));
101+
WriteOutput (TraceLevel.Error, Format (true, message.Code, sourceFile, line, column, message.Value, args));
101102
}
102103

103104
public static void LogCodedWarning (int verbosity, LocalizedMessage message, params string? [] args)
@@ -122,17 +123,17 @@ public static void LogCodedWarning (int verbosity, LocalizedMessage message, Exc
122123
return;
123124

124125
var supp = innerException != null ? " For details, see verbose output." : null;
125-
WriteOutput (Format (false, message.Code, sourceFile, line, column, message.Value, args) + supp);
126+
WriteOutput (TraceLevel.Warning, Format (false, message.Code, sourceFile, line, column, message.Value, args) + supp);
126127

127128
if (innerException != null)
128-
WriteOutput (innerException.ToString ());
129+
WriteOutput (TraceLevel.Warning, innerException.ToString ());
129130
}
130131

131132
public static void Verbose (int verbosity, string format, params object?[] args)
132133
{
133134
if (verbosity > (Verbosity ?? 0))
134135
return;
135-
WriteOutput (format, args);
136+
WriteOutput (TraceLevel.Verbose, format, args);
136137
}
137138

138139
public static string FormatCodedMessage (bool error, LocalizedMessage message, params object? [] args)
@@ -172,11 +173,11 @@ public static string Format (bool error, int errorCode, string? sourceFile, int
172173
return (file, pos?.LineNumber ?? -1, pos?.LinePosition ?? -1);
173174
}
174175

175-
static void WriteOutput (string format, params object?[] args)
176+
static void WriteOutput (TraceLevel traceLevel, string format, params object?[] args)
176177
{
177178
// Write to overridden output if requested
178179
if (OutputDelegate != null) {
179-
OutputDelegate (string.Format (format, args));
180+
OutputDelegate (traceLevel, string.Format (format, args));
180181
return;
181182
}
182183

tests/generator-Tests/Unit-Tests/CodeGeneratorTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Linq;
45
using System.Text;
56
using generator.SourceWriters;
@@ -528,6 +529,7 @@ public void ObsoleteBoundMethodAbstractDeclaration ()
528529

529530
// Ensure [Obsolete] was written
530531
Assert.True (writer.ToString ().Contains ("[Obsolete (@\"This is so old!\")]"), writer.ToString ());
532+
}
531533

532534
[Test]
533535
[NonParallelizable] // We are setting a static property on Report
@@ -536,7 +538,7 @@ public void WarnIfTypeNameMatchesNamespace ()
536538
var @class = new TestClass ("Object", "java.myclass.MyClass");
537539
var sb = new StringBuilder ();
538540

539-
var write_output = new Action<string> ((s) => { sb.AppendLine (s); });
541+
var write_output = new Action<TraceLevel, string> ((t, s) => { sb.AppendLine (s); });
540542
Report.OutputDelegate = write_output;
541543

542544
generator.Context.ContextTypes.Push (@class);
@@ -557,7 +559,7 @@ public void DontWarnIfNestedTypeNameMatchesNamespace ()
557559
@class.NestedTypes.Add (new TestClass ("Object", "java.myclass.MyParentClass.MyClass"));
558560
var sb = new StringBuilder ();
559561

560-
var write_output = new Action<string> ((s) => { sb.AppendLine (s); });
562+
var write_output = new Action<TraceLevel, string> ((t, s) => { sb.AppendLine (s); });
561563
Report.OutputDelegate = write_output;
562564

563565
generator.Context.ContextTypes.Push (@class);

0 commit comments

Comments
 (0)