Skip to content

Commit 62a56cf

Browse files
committed
Removing unnecessary entry point
Add test logger
1 parent 881cd4e commit 62a56cf

File tree

3 files changed

+115
-13
lines changed

3 files changed

+115
-13
lines changed
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License. See LICENSE file in the project root for full license information.
3+
4+
namespace Microsoft.VisualStudio.Jdt.Tests
5+
{
6+
using System;
7+
using System.Text;
8+
9+
/// <summary>
10+
/// Mock logger to test <see cref="JsonTransformation"/>
11+
/// </summary>
12+
public class JsonTransformationTestLogger : IJsonTransformationLogger
13+
{
14+
private readonly StringBuilder errorLog = new StringBuilder();
15+
16+
private readonly StringBuilder warningLog = new StringBuilder();
17+
18+
private readonly StringBuilder messageLog = new StringBuilder();
19+
20+
/// <summary>
21+
/// Gets the text from the error log
22+
/// </summary>
23+
public string ErrorLogText
24+
{
25+
get
26+
{
27+
return this.errorLog.ToString();
28+
}
29+
}
30+
31+
/// <summary>
32+
/// Gets the text from the warning log
33+
/// </summary>
34+
public string WarningLogText
35+
{
36+
get
37+
{
38+
return this.warningLog.ToString();
39+
}
40+
}
41+
42+
/// <summary>
43+
/// Gets the text from the message log
44+
/// </summary>
45+
public string MessageLogText
46+
{
47+
get
48+
{
49+
return this.messageLog.ToString();
50+
}
51+
}
52+
53+
/// <inheritdoc/>
54+
public void LogError(string message)
55+
{
56+
this.errorLog.AppendLine(message);
57+
}
58+
59+
/// <inheritdoc/>
60+
public void LogError(string message, string fileName, int lineNumber, int linePosition)
61+
{
62+
this.errorLog.AppendLine(this.BuildLine(message, fileName, lineNumber, linePosition));
63+
}
64+
65+
/// <inheritdoc/>
66+
public void LogErrorFromException(Exception ex)
67+
{
68+
this.errorLog.AppendLine($"Exception: {ex.Message}");
69+
}
70+
71+
/// <inheritdoc/>
72+
public void LogErrorFromException(Exception ex, string fileName, int lineNumber, int linePosition)
73+
{
74+
this.errorLog.AppendLine(this.BuildLine($"Exception: {ex.Message}", fileName, lineNumber, linePosition));
75+
}
76+
77+
/// <inheritdoc/>
78+
public void LogMessage(string message)
79+
{
80+
this.messageLog.AppendLine(message);
81+
}
82+
83+
/// <inheritdoc/>
84+
public void LogWarning(string message)
85+
{
86+
this.warningLog.AppendLine(message);
87+
}
88+
89+
/// <inheritdoc/>
90+
public void LogWarning(string message, string fileName)
91+
{
92+
this.warningLog.AppendLine($"{message} {fileName}");
93+
}
94+
95+
/// <inheritdoc/>
96+
public void LogWarning(string message, string fileName, int lineNumber, int linePosition)
97+
{
98+
this.warningLog.AppendLine(this.BuildLine(message, fileName, lineNumber, linePosition));
99+
}
100+
101+
private string BuildLine(string message, string fileName, int lineNumber, int linePosition)
102+
{
103+
string line = message;
104+
if (fileName != null)
105+
{
106+
line += " " + fileName;
107+
}
108+
109+
line += $" {lineNumber} {linePosition}";
110+
111+
return line;
112+
}
113+
}
114+
}

src/Microsoft.VisualStudio.Jdt/IJsonTransformationLogger.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,6 @@ public interface IJsonTransformationLogger
1616
/// <param name="message">The message text</param>
1717
void LogMessage(string message);
1818

19-
/// <summary>
20-
/// Logs a message
21-
/// </summary>
22-
/// <param name="message">The message</param>
23-
/// <param name="fileName">The full path to the file that caused the message. Can be null</param>
24-
/// <param name="lineNumber">The line that caused the message</param>
25-
/// <param name="linePosition">The position in the line that caused the message</param>
26-
void LogMessage(string message, string fileName, int lineNumber, int linePosition);
27-
2819
/// <summary>
2920
/// Logs a warning
3021
/// </summary>

src/Microsoft.VisualStudio.Jdt/JsonTransformation.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,7 @@ private void SetTransform(Stream transformStream)
162162
this.loadSettings = new JsonLoadSettings()
163163
{
164164
CommentHandling = CommentHandling.Ignore,
165-
166-
// Obs: LineInfo is handled on Ignore and not Load
167-
// See https://github.com/JamesNK/Newtonsoft.Json/issues/1249
168-
LineInfoHandling = LineInfoHandling.Ignore
165+
LineInfoHandling = LineInfoHandling.Load
169166
};
170167

171168
using (StreamReader transformStreamReader = new StreamReader(transformStream))

0 commit comments

Comments
 (0)