Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions JavaToCSharp.Tests/ConvertExpressionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ public class ConvertExpressionTests
[InlineData("lst.set(i, value)", "lst[i] = value")]
[InlineData("str.length()", "str.Length")]
[InlineData("arr.length", "arr.Length")]
[InlineData("e.getMessage()", "e.Message")]
[InlineData("obj.getMessage(i)", "obj.GetMessage(i)")]

//Conversion not done if param number does not match the required
[InlineData("obj.size(i)", "obj.Size(i)")]
Expand Down
1 change: 1 addition & 0 deletions JavaToCSharp.Tests/IntegrationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ public void GeneralUnsuccessfulConversionTest(string filePath)
[InlineData("Resources/InstanceInitializers.java")]
[InlineData("Resources/StaticImports.java")]
[InlineData("Resources/LabeledBreakContinue.java")]
[InlineData("Resources/ExceptionGetMessage.java")]
public void FullIntegrationTests(string filePath, bool allowWarnings = false)
=> RunFullIntegrationTest(filePath, allowWarnings);

Expand Down
13 changes: 13 additions & 0 deletions JavaToCSharp.Tests/Resources/ExceptionGetMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// Expect:
/// - output: "caught: boom\n"
package example;

public class Program {
public static void main(String[] args) {
try {
throw new IllegalArgumentException("boom");
} catch (IllegalArgumentException e) {
System.out.println("caught: " + e.getMessage());
}
}
}
7 changes: 7 additions & 0 deletions JavaToCSharp/TypeHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,13 @@ public static bool TryTransformMethodCall(ConversionContext context, MethodCallE
return true;
}

case "getMessage" when args.size() == 0:
{
var scopeSyntaxMessage = ExpressionVisitor.VisitExpression(context, scope);
transformedSyntax = ReplaceMethodByProperty(scopeSyntaxMessage, "Message");
return true;
}

case "get" when args.size() == 1:
{
var scopeSyntaxGet = ExpressionVisitor.VisitExpression(context, scope);
Expand Down
Loading