Skip to content

Commit 2d57285

Browse files
committed
Merge tag 'v2.0.1' into develop
v2.0.1
2 parents 5f71aa5 + 6bea9fd commit 2d57285

File tree

10 files changed

+125
-19
lines changed

10 files changed

+125
-19
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using JavaToCSharp;
2+
using Xunit;
3+
4+
namespace TypeHelperTests
5+
{
6+
public class ConvertTypeTests
7+
{
8+
[Fact]
9+
public void ConvertType_Int()
10+
{
11+
Assert.Equal("int", TypeHelper.ConvertType("int"));
12+
}
13+
14+
[Fact]
15+
public void ConvertType_String()
16+
{
17+
Assert.Equal("string", TypeHelper.ConvertType("String"));
18+
}
19+
20+
[Fact]
21+
public void ConvertType_Object()
22+
{
23+
Assert.Equal("object", TypeHelper.ConvertType("Object"));
24+
}
25+
26+
[Fact]
27+
public void ConvertType_IntArray_BracketsAfterType()
28+
{
29+
Assert.Equal("int[]", TypeHelper.ConvertType("int[]"));
30+
}
31+
32+
[Fact]
33+
public void ConvertType_GenericSingleParameter()
34+
{
35+
Assert.Equal("MyType<string>", TypeHelper.ConvertType("MyType<String>"));
36+
}
37+
38+
[Fact]
39+
public void ConvertType_GenericMultipleParameters()
40+
{
41+
Assert.Equal("MyType<string, object>", TypeHelper.ConvertType("MyType<String, Object>"));
42+
}
43+
44+
[Fact]
45+
public void ConvertType_WithGenericWildcard_ShouldReplaceToken()
46+
{
47+
Assert.Equal("MyType<TWildcardTodo>", TypeHelper.ConvertType("MyType<?>"));
48+
}
49+
}
50+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net5.0</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.4" />
11+
<PackageReference Include="xunit" Version="2.4.1" />
12+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
13+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
14+
<PrivateAssets>all</PrivateAssets>
15+
</PackageReference>
16+
<PackageReference Include="coverlet.collector" Version="3.0.2">
17+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
18+
<PrivateAssets>all</PrivateAssets>
19+
</PackageReference>
20+
</ItemGroup>
21+
22+
<ItemGroup>
23+
<ProjectReference Include="..\JavaToCSharp\JavaToCSharp.csproj" />
24+
</ItemGroup>
25+
26+
<ItemGroup>
27+
<Reference Include="javaparser-core-3.0.0-SNAPSHOT">
28+
<HintPath>..\Lib\javaparser-core-3.0.0-SNAPSHOT.dll</HintPath>
29+
</Reference>
30+
</ItemGroup>
31+
32+
</Project>

JavaToCSharp.sln

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2020
.editorconfig = .editorconfig
2121
EndProjectSection
2222
EndProject
23+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JavaToCSharp.Tests", "JavaToCSharp.Tests\JavaToCSharp.Tests.csproj", "{0CBBEF05-FD79-474A-A5F0-25B341B8B77D}"
24+
EndProject
25+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{DE56E074-10C7-47BA-8E8A-DAB0F3F92181}"
26+
EndProject
2327
Global
2428
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2529
Debug|Any CPU = Debug|Any CPU
@@ -38,10 +42,17 @@ Global
3842
{DAA3F412-0460-40C3-98F7-3244649820F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
3943
{DAA3F412-0460-40C3-98F7-3244649820F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
4044
{DAA3F412-0460-40C3-98F7-3244649820F9}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{0CBBEF05-FD79-474A-A5F0-25B341B8B77D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{0CBBEF05-FD79-474A-A5F0-25B341B8B77D}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{0CBBEF05-FD79-474A-A5F0-25B341B8B77D}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{0CBBEF05-FD79-474A-A5F0-25B341B8B77D}.Release|Any CPU.Build.0 = Release|Any CPU
4149
EndGlobalSection
4250
GlobalSection(SolutionProperties) = preSolution
4351
HideSolutionNode = FALSE
4452
EndGlobalSection
53+
GlobalSection(NestedProjects) = preSolution
54+
{0CBBEF05-FD79-474A-A5F0-25B341B8B77D} = {DE56E074-10C7-47BA-8E8A-DAB0F3F92181}
55+
EndGlobalSection
4556
GlobalSection(ExtensibilityGlobals) = postSolution
4657
SolutionGuid = {EB538484-5025-4753-B0A5-2C66A6C06193}
4758
EndGlobalSection

JavaToCSharp/JavaToCSharp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>2.0.0</Version>
3+
<Version>2.0.1</Version>
44
<TargetFramework>net5.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<LangVersion>latest</LangVersion>

JavaToCSharp/TypeHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public static class TypeHelper
1818
["ICloseable"] = "IDisposable",
1919
["Integer"] = "int",
2020
["String"] = "string",
21+
["Object"] = "object",
2122

2223
// Generic types
2324
["ArrayList"] = "List",

JavaToCSharp/TypeNameParser.cs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ private enum TokenType
1212
Identifier,
1313
Extends,
1414
Super,
15-
LeftBracket,
16-
RightBracket,
15+
LeftSquareBracket,
16+
RightSquareBracket,
17+
LeftAngleBracket,
18+
RightAngleBracket,
1719
Comma,
1820
QuestionMark
1921
}
2022

21-
private static readonly Regex _tokenizePattern = new(@"\w+|<|>|,|\?", RegexOptions.Compiled);
23+
private static readonly Regex _tokenizePattern = new(@"\w+|\[|\]|<|>|,|\?", RegexOptions.Compiled);
2224

2325
private static (string, TokenType)[] _tokens;
2426
private static (string text, TokenType type) _token;
@@ -41,7 +43,7 @@ internal static string ParseTypeName(string typename, Func<string, string> trans
4143
_sb.Clear();
4244

4345
if (TypeName() && _token.type is TokenType.EndOfString)
44-
{
46+
{
4547
// Otherwise we have extra tokens.
4648
return _sb.ToString();
4749
}
@@ -59,8 +61,10 @@ private static (string, TokenType)[] Tokenize(string typeName)
5961
string s = match.Value;
6062
tokens[i] = s switch
6163
{
62-
"<" => (s, TokenType.LeftBracket),
63-
">" => (s, TokenType.RightBracket),
64+
"[" => (s, TokenType.LeftSquareBracket),
65+
"]" => (s, TokenType.RightSquareBracket),
66+
"<" => (s, TokenType.LeftAngleBracket),
67+
">" => (s, TokenType.RightAngleBracket),
6468
"," => (s, TokenType.Comma),
6569
"?" => (s, TokenType.QuestionMark),
6670
"extends" => (s, TokenType.Extends),
@@ -84,7 +88,7 @@ private static bool TypeName()
8488
{
8589
_sb.Append(_translate(_token.text));
8690
NextToken();
87-
if (_token.type is TokenType.LeftBracket)
91+
if (_token.type is TokenType.LeftAngleBracket)
8892
{
8993
_sb.Append("<");
9094
NextToken();
@@ -96,7 +100,7 @@ private static bool TypeName()
96100
NextToken();
97101
if (!TypeArgument()) return false;
98102
}
99-
if (_token.type is TokenType.RightBracket)
103+
if (_token.type is TokenType.RightAngleBracket)
100104
{
101105
_sb.Append(">");
102106
NextToken();
@@ -117,12 +121,17 @@ private static bool TypeArgument()
117121
// TypeArgument = [ "?" [ "extends" | "super" ] ] TypeName.
118122
if (_token.type is TokenType.QuestionMark)
119123
{
120-
// C# does not have this. Ignore. We could fix it by replacing IList<T> by IList for example.
124+
_sb.Append("TWildcardTodo");
121125
NextToken();
126+
122127
if (_token.type is TokenType.Extends or TokenType.Super)
123128
{
124129
NextToken();
125130
}
131+
else if (_token.type is TokenType.RightAngleBracket)
132+
{
133+
return true;
134+
}
126135
}
127136
return TypeName();
128137
}

JavaToCSharpCli/JavaToCSharpCli.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>2.0.0</Version>
3+
<Version>2.0.1</Version>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net5.0</TargetFramework>
66
</PropertyGroup>

JavaToCSharpGui/JavaToCSharpGui.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<Version>2.0.0</Version>
3+
<Version>2.0.1</Version>
44
<OutputType>WinExe</OutputType>
55
<TargetFramework>net5.0-windows</TargetFramework>
66
<UseWPF>true</UseWPF>

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
Java to C# Converter
22
====================
33

4-
Java to C# converter, work in progress. Uses javaparser with 1.7
4+
Java to C# converter. Uses javaparser with Java 8
55
support from https://github.com/before/javaparser, IKVM.NET to
6-
convert the javaparser .jar into a .NET .dll, and the Roslyn CTP
7-
for C# AST generation.
6+
convert the javaparser .jar into a .NET .dll, and Roslyn for C# AST generation.
87

9-
This was a quick hack only, it is still very much a work in progress.
108
Pull requests and issue submission welcome.
119

1210
Getting Started
@@ -20,6 +18,8 @@ minutes on large files.
2018
Alternatively, launch the command line (Cli) version to process files
2119
from the command line.
2220

21+
The core library is installable via NuGet at https://www.nuget.org/packages/JavaToCSharp/
22+
2323
License for JavaParser
2424
======================
2525

infrastructure/publish-exe.ps1 renamed to infrastructure/publish.ps1

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ param([Parameter(Mandatory)] $version);
22

33
# Requires the dotnet-setversion tool installed:
44
# dotnet tool install -g dotnet-setversion
5+
setversion $version ../JavaToCSharp/JavaToCSharp.csproj
56
setversion $version ../JavaToCSharpCli/JavaToCSharpCli.csproj
67
setversion $version ../JavaToCSharpGui/JavaToCSharpGui.csproj
78

89
dotnet publish ../JavaToCSharpGui/JavaToCSharpGui.csproj -c Release -r win10-x64 --self-contained true -o ../publish/gui/
910
dotnet publish ../JavaToCSharpCli/JavaToCSharpCli.csproj -c Release -r win10-x64 --self-contained true -o ../publish/cli/
1011

11-
Compress-Archive @("../publish/gui/", "../publish/cli/") -DestinationPath ../publish/JavaToCSharp-$version.zip
12+
Compress-Archive @("../publish/gui/", "../publish/cli/") -DestinationPath ../publish/JavaToCSharp-$version.zip -Force
13+
14+
dotnet pack ../JavaToCSharp/JavaToCSharp.csproj -c Release

0 commit comments

Comments
 (0)