├── .gitattributes
├── .gitignore
├── CONTRIBUTING.md
├── CodeConverterCSharp
├── CSharpClassWriter.cs
├── CSharpWriter.cs
├── CodeConverterCSharp.csproj
├── Lucenene
│ └── ConverterLucene.cs
├── Model
│ ├── CSharpStaticInfo.cs
│ ├── ConverterJavaToCSharp.cs
│ └── FileWriteInfo.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── CodeConverterCSharp_Unittest
├── ClassGeneration_Unittest.cs
├── CodeConverterCSharp_Unittest.csproj
├── InterfaceGeneration_Unittest.cs
├── Methode
│ └── IfStatement_Unittest.cs
└── MethodeAsPropertyGet_Unittest.cs
├── CodeConverterCore
├── Analyzer
│ ├── AnalyzerCore.cs
│ ├── AnalyzerSettings.cs
│ └── DictionaryHelper.cs
├── CodeConverterCore.csproj
├── Converter
│ ├── ConverterBase.cs
│ ├── IConverter.cs
│ └── NamingConvertionHelper.cs
├── Enum
│ ├── ClayyTypeEnum.cs
│ ├── StatementTypeEnum.cs
│ └── VariableManipulatorType.cs
├── Helper
│ ├── AntlrHelper.cs
│ ├── CTSExtensions.cs
│ ├── ClassHelper.cs
│ ├── CodeSteppingHelper.cs
│ ├── Create.cs
│ ├── DataHelper.cs
│ ├── Modifiers.cs
│ ├── ProjectInformationHelper.cs
│ └── RegexHelper.cs
├── ImportExport
│ ├── AliasObject.cs
│ ├── ExportHelper.cs
│ ├── ImportHelper.cs
│ ├── LanguageMappingObject.cs
│ ├── MappingObject.cs
│ └── StringReplacement.cs
├── Interface
│ ├── CodeResultType.cs
│ ├── ICodeEntry.cs
│ ├── ICodeStepperEvents.cs
│ ├── ILoadOOPLanguage.cs
│ ├── IMissingTypes.cs
│ ├── IName.cs
│ ├── INameConverter.cs
│ └── IResolveMethodeContentToIL.cs
├── Model
│ ├── BaseType.cs
│ ├── ClassContainer.cs
│ ├── CodeBlock.cs
│ ├── CodeBlockContainer.cs
│ ├── CodeExpression.cs
│ ├── CodeState.cs
│ ├── ConstantValue.cs
│ ├── FieldContainer.cs
│ ├── FieldNameFinder.cs
│ ├── MethodeCall.cs
│ ├── MethodeContainer.cs
│ ├── MissingFunctionInformation.cs
│ ├── NewObjectDeclaration.cs
│ ├── ProjectInformation.cs
│ ├── ReturnCodeEntry.cs
│ ├── SetFieldWithValue.cs
│ ├── StatementCode.cs
│ ├── TypeContainer.cs
│ ├── TypeConversion.cs
│ ├── UnknownTypeClass.cs
│ ├── VariableAccess.cs
│ └── VariableDeclaration.cs
├── Properties
│ └── AssemblyInfo.cs
└── packages.config
├── CodeConverterCore_Unittest
├── Analyzer
│ ├── AnalyzerClassAndMethodeTypeLinks_Unittest.cs
│ ├── AnalyzerClassTypeLinks_Unittest.cs
│ ├── AnalyzerClassVariableLinks_Unittest.cs
│ ├── MethodeCall_Unittest.cs
│ ├── MethodeParam_Unittest.cs
│ └── PropertyStackingAccess_Unittest.cs
└── CodeConverterCore_Unittest.csproj
├── CodeConverterJava
├── CodeConverterJava.csproj
├── JavaAntlrClassLoader.cs
├── JavaLoader.cs
├── JavaMethodeCodeResolver.cs
├── JavaStaticInfo.cs
├── Properties
│ └── AssemblyInfo.cs
├── Resources
│ ├── CompilerAliasHelper.cs
│ └── JavaLangClassJson.cs
├── antlr
│ ├── IFormalParameterContext.cs
│ ├── IJavaParserListener.cs
│ ├── Interfaces.cs
│ ├── JavaLexer.g4.cs
│ ├── JavaParser.g4.cs
│ └── JavaParserVisitor.cs
└── packages.config
├── CodeConverterJavaToCSharp_Unittest
├── BaseTests
│ ├── AbstractPropertiesMethods_Unittest.cs
│ ├── AssertStatement_Unittest.cs
│ ├── ConverterGithubExample.cs
│ ├── ElvisOperator_Unittest.cs
│ ├── ForStatement_Unittest.cs
│ ├── GenericClassReplace_Unittest.cs
│ ├── InplaceClassCreation_Unittest.cs
│ ├── JavaClassMapping_Unittest.cs
│ ├── NewObjectParamCall_Unittest.cs
│ ├── ObjectMethodeCallReplace_Unittest.cs
│ ├── PropertyWithDefaultValue_Unittest.cs
│ ├── SystemMerging_Unittest.cs
│ ├── TertiaerReturn_Unittest.cs
│ ├── TypeConvertion_Unittest.cs
│ └── WhileStatement_Unittest.cs
├── CodeConverterJavaToCSharp_Unittest.csproj
└── LuceneTests
│ ├── Accountable_Interface_Unittest.cs
│ ├── Attribute_Interface_Unittest.cs
│ ├── Bits_Interface_Unittest.cs
│ ├── LongValues_Unittest.cs
│ └── MutableValue_Unittest.cs
├── JavaCodeLoader_Unittest
├── CodeConverterJava_Unittest.csproj
├── Methode
│ ├── AssertStatement_Unittest.cs
│ ├── BitShifting_Unittest.cs
│ ├── ElvisOperator_Unittest.cs
│ ├── ForStatement_Unittest.cs
│ ├── IfStatement_Unittest.cs
│ ├── InplaceClassCreation_Unittest.cs
│ ├── MethodeCall_Unittest.cs
│ ├── NewObjectParamCall_Unittest.cs
│ ├── SuperCall_Unittest.cs
│ ├── TypeConvertion_Unittest.cs
│ ├── VariableCreation_Unittest.cs
│ └── WhileStatement_Unittest.cs
├── Objektstruktur
│ ├── BooleanCheck_Unittest.cs
│ ├── Calculation_Unittest.cs
│ ├── Class_Namespace_Unittest.cs
│ ├── Extends_Implements_Unittest.cs
│ ├── FieldAccess_Unittest.cs
│ ├── MethodeCall_Unittest.cs
│ ├── MethodeCode_Unittest.cs
│ ├── MethodeDefinition_Unittest.cs
│ ├── MethodeFunctionCode_Unittest.cs
│ └── UnknownTypeWithMethode.cs
└── TextHelpData
│ ├── JavaMapperObject.cs
│ └── JsonFormatingHelper.cs
├── JavaCoreReplacer
├── FLoatCompareHelper.cs
└── JavaCoreReplacer.csproj
├── JavaCoreReplacer_Unittest
├── JavaCoreReplacer_Unittest.csproj
└── UnitTest1.cs
├── JavaToCSharpImporter.sln
├── JavaToCSharpImporter
├── App.config
├── CodeConverterJavaToCSharp.csproj
├── Helper
│ ├── ConverterHelper.cs
│ └── NamespaceHelper.cs
├── Model
│ ├── ElvisStatementCodeStepper.cs
│ ├── NamespaceCodeStepper.cs
│ ├── ReplaceInFile.cs
│ ├── SearchAndReplacePattern.cs
│ └── SearchInFile.cs
├── Program.cs
├── Properties
│ └── AssemblyInfo.cs
├── Resource
│ ├── ClassRenameJson.cs
│ └── StringReplacementJson.cs
├── ResultCache.cs
├── TestData.cs
└── packages.config
├── LICENSE
└── README.md
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | I welcome everybody who is willing tho help.
2 | The target is to get this working with more Features (Java Code Loading) and in to Create C# Code out of the Intermediate Language.
3 |
--------------------------------------------------------------------------------
/CodeConverterCSharp/CSharpWriter.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Converter;
2 | using CodeConverterCore.Model;
3 | using CodeConverterCSharp.Model;
4 | using System;
5 | using System.Collections.Generic;
6 |
7 | namespace CodeConverterCSharp
8 | {
9 | public static class CSharpWriter
10 | {
11 | ///
12 | /// Create C# Classes for the spezified Project
13 | ///
14 | ///
15 | ///
16 | public static IEnumerable CreateClassesFromObjectInformation(ProjectInformation inObjectInformation, IConverter inConverter)
17 | {
18 | var tmpWriter = new CSharpClassWriter();
19 | foreach (var tmpClass in inObjectInformation.ClassList)
20 | {
21 | yield return tmpWriter.CreateClassFile(tmpClass);
22 | }
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/CodeConverterCSharp/CodeConverterCSharp.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {AF3B0441-044A-4EA3-8052-57982E8BFCB5}
8 | Library
9 | Properties
10 | CodeConverterCSharp
11 | CodeConverterCSharp
12 | v4.8
13 | 512
14 | true
15 |
16 |
17 | true
18 | full
19 | false
20 | bin\Debug\
21 | DEBUG;TRACE
22 | prompt
23 | 4
24 |
25 |
26 | pdbonly
27 | true
28 | bin\Release\
29 | TRACE
30 | prompt
31 | 4
32 |
33 |
34 |
35 | ..\packages\ini-parser.2.5.2\lib\net20\INIFileParser.dll
36 |
37 |
38 | ..\packages\morelinq.3.1.0\lib\net451\MoreLinq.dll
39 |
40 |
41 | ..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
42 |
43 |
44 |
45 |
46 | ..\packages\System.ValueTuple.4.4.0\lib\net47\System.ValueTuple.dll
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | {d70fe1c1-3cbe-42f1-8361-b05fa406a39c}
70 | CodeConverterCore
71 |
72 |
73 |
74 |
--------------------------------------------------------------------------------
/CodeConverterCSharp/Lucenene/ConverterLucene.cs:
--------------------------------------------------------------------------------
1 | using JavaToCSharpConverter.Model;
2 | using System.Collections.Generic;
3 |
4 | namespace CodeConverterCSharp.Lucenene
5 | {
6 | public class ConverterLucene : ConverterJavaToCSharp
7 | {
8 |
9 | ///
10 | /// Namespace Changes to fit C# Namings
11 | ///
12 | ///
13 | ///
14 | public override IEnumerable Namespace(params string[] inNamespace)
15 | {
16 | foreach (var tmpNamespace in base.Namespace(inNamespace))
17 | {
18 | if (tmpNamespace.StartsWith("org.apache.lucene"))
19 | {
20 | yield return tmpNamespace.Replace("org.apache.lucene", "LuceNET");
21 | }
22 | else if (tmpNamespace == "java.lang")
23 | {
24 | yield return "System";
25 | }
26 | else if (tmpNamespace.StartsWith("java"))
27 | {
28 | //DoNothing
29 | }
30 | else
31 | {
32 | yield return tmpNamespace;
33 | }
34 | }
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/CodeConverterCSharp/Model/CSharpStaticInfo.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Enum;
2 | using System.Collections.Generic;
3 |
4 | namespace CodeConverterCSharp.Model
5 | {
6 | public static class CSharpStaticInfo
7 | {
8 | public static Dictionary VariableOperators = new Dictionary
9 | {
10 | //Math Operators
11 | {"+", VariableOperatorType.Addition},
12 | {"-", VariableOperatorType.Substraction},
13 | {"*", VariableOperatorType.Multiplication},
14 | {"/", VariableOperatorType.Division},
15 |
16 | //Boolean Operators
17 | {"==", VariableOperatorType.Equals},
18 | {"!=", VariableOperatorType.NotEquals},
19 | {"&&", VariableOperatorType.And},
20 | {"||", VariableOperatorType.Or},
21 | {"<", VariableOperatorType.LessThan},
22 | {">", VariableOperatorType.MoreThan},
23 | {"<=", VariableOperatorType.LessOrEquals},
24 | {">=", VariableOperatorType.MoreOrEquals},
25 | {"^", VariableOperatorType.XOR},
26 | {"!", VariableOperatorType.Not},
27 |
28 | //Bitshift Operators
29 | {">>", VariableOperatorType.BitShiftRight},
30 | {"<<", VariableOperatorType.BitShiftLeft},
31 | {">> ", VariableOperatorType.BitShiftRightUnsigned},
32 | {"<< ", VariableOperatorType.BitShiftLeftUnsigned},
33 | {"&", VariableOperatorType.BitwiseAnd},
34 | {"|", VariableOperatorType.BitwiseOr},
35 |
36 | //VarOperations With Set
37 | {"++", VariableOperatorType.PlusPlus},
38 | {"--", VariableOperatorType.MinusMinus},
39 | {"+=", VariableOperatorType.PlusEquals},
40 | {"-=", VariableOperatorType.MinusEquals},
41 | };
42 |
43 | public static VariableOperatorType GetManipulator(string inOperatorAssString)
44 | {
45 | return VariableOperators[inOperatorAssString];
46 | }
47 |
48 | public static Dictionary _operatorToString;//= new Dictionary
49 |
50 | public static string GetOperatorString(VariableOperatorType inOperator)
51 | {
52 | if (_operatorToString == null)
53 | {
54 | _operatorToString = new Dictionary();
55 | foreach (var tmpEntry in VariableOperators)
56 | {
57 | _operatorToString.Add(tmpEntry.Value, tmpEntry.Key);
58 | }
59 | }
60 | return _operatorToString[inOperator];
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/CodeConverterCSharp/Model/FileWriteInfo.cs:
--------------------------------------------------------------------------------
1 | namespace CodeConverterCSharp.Model
2 | {
3 | ///
4 | /// Simple Class for Output File Informations
5 | ///
6 | public class FileWriteInfo
7 | {
8 | public string FullName { get; set; }
9 | public string RelativePath { get; set; }
10 | public string Content { get; set; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/CodeConverterCSharp/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // Allgemeine Informationen über eine Assembly werden über die folgenden
6 | // Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
7 | // die einer Assembly zugeordnet sind.
8 | [assembly: AssemblyTitle("CodeConverterCSharp")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("CodeConverterCSharp")]
13 | [assembly: AssemblyCopyright("Copyright © 2020")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
18 | // für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
19 | // COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
20 | [assembly: ComVisible(false)]
21 |
22 | // Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
23 | [assembly: Guid("af3b0441-044a-4ea3-8052-57982e8bfcb5")]
24 |
25 | // Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
26 | //
27 | // Hauptversion
28 | // Nebenversion
29 | // Buildnummer
30 | // Revision
31 | //
32 | // Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
33 | // indem Sie "*" wie unten gezeigt eingeben:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/CodeConverterCSharp/packages.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/CodeConverterCSharp_Unittest/ClassGeneration_Unittest.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Converter;
2 | using CodeConverterCore.Model;
3 | using CodeConverterCSharp;
4 | using NUnit.Framework;
5 | using System.Linq;
6 |
7 | namespace CodeConverterCSharp_Unittest
8 | {
9 | public class ClassGeneration_Unittest
10 | {
11 | [Test]
12 | public void CheckfoBaseErrors()
13 | {
14 | var tmpProject = new ProjectInformation();
15 | var tmpObjectInformation = CSharpWriter.CreateClassesFromObjectInformation(tmpProject,new ConverterBase()).ToList();
16 |
17 | Assert.AreEqual(0, tmpObjectInformation.Count);
18 | }
19 |
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/CodeConverterCSharp_Unittest/CodeConverterCSharp_Unittest.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/CodeConverterCSharp_Unittest/Methode/IfStatement_Unittest.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Analyzer;
2 | using CodeConverterCore.Converter;
3 | using CodeConverterCore.Enum;
4 | using CodeConverterCore.Helper;
5 | using CodeConverterCore.Model;
6 | using CodeConverterCSharp;
7 | using NUnit.Framework;
8 | using System.Linq;
9 |
10 | namespace CodeConverterCSharp_Unittest.Methode
11 | {
12 | public class IfStatement_Unittest
13 | {
14 | [Test]
15 | public void SimpleIfWithReturns()
16 | {
17 | var tmpIniData = DataHelper.LoadIni("");
18 | var tmpProject = new ProjectInformation();
19 | var tmpClass = Create.AddClass("IAttribute");
20 | tmpClass.ModifierList.Add("public");
21 | tmpClass.ModifierList.Add("interface");
22 |
23 | tmpProject.ClassList.Add(tmpClass);
24 | var tmpMethode = Create.AddMethode(tmpClass, "m1", TypeContainer.Void
25 | , new FieldContainer { Name = "in1", Type = new TypeContainer { Name = "int" } }
26 | , new FieldContainer { Name = "in2", Type = new TypeContainer { Name = "int" } });
27 |
28 | tmpMethode.Code = new CodeBlock();
29 |
30 | tmpMethode.Code.AddIfStatement(
31 | Create.CreateComparisionBlock("in1", VariableOperatorType.LessOrEquals, "in2"),
32 | Create.AddReturnStatement(new CodeBlock(), "true"));
33 |
34 | Create.AddReturnStatement(tmpMethode.Code, "false");
35 |
36 | new AnalyzerCore().LinkProjectInformation(tmpProject);
37 |
38 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpProject, new ConverterBase()).ToList();
39 |
40 | var tmpExpectedResult = @"
41 |
42 | namespace
43 | {
44 | public interface IAttribute
45 | {
46 | void m1(int in1, int in2)
47 | {
48 | if(in1 <= in2)
49 | {
50 | return true;
51 | }
52 | return false;
53 | }
54 | }
55 | }
56 | ";
57 | Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content);
58 | }
59 |
60 |
61 | [Test]
62 | public void IfWithElse()
63 | {
64 | var tmpIniData = DataHelper.LoadIni("");
65 | var tmpProject = new ProjectInformation();
66 | var tmpClass = Create.AddClass("IAttribute");
67 | tmpClass.ModifierList.Add("public");
68 | tmpClass.ModifierList.Add("interface");
69 |
70 | tmpProject.ClassList.Add(tmpClass);
71 | var tmpMethode = Create.AddMethode(tmpClass, "m1", TypeContainer.Void
72 | , new FieldContainer { Name = "in1", Type = new TypeContainer { Name = "int" } }
73 | , new FieldContainer { Name = "in2", Type = new TypeContainer { Name = "int" } });
74 |
75 | tmpMethode.Code = new CodeBlock();
76 |
77 | tmpMethode.Code.AddIfStatement(
78 | Create.CreateComparisionBlock("in1", VariableOperatorType.LessOrEquals, "in2"),
79 | Create.AddReturnStatement(new CodeBlock(), "true"),
80 | Create.AddReturnStatement(new CodeBlock(), "false"));
81 |
82 |
83 | new AnalyzerCore().LinkProjectInformation(tmpProject);
84 |
85 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpProject, new ConverterBase()).ToList();
86 |
87 | var tmpExpectedResult = @"
88 |
89 | namespace
90 | {
91 | public interface IAttribute
92 | {
93 | void m1(int in1, int in2)
94 | {
95 | if(in1 <= in2)
96 | {
97 | return true;
98 | }
99 | else {
100 | return false;
101 | }
102 | }
103 | }
104 | }
105 | ";
106 | Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content);
107 | }
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/CodeConverterCSharp_Unittest/MethodeAsPropertyGet_Unittest.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Converter;
2 | using CodeConverterCore.Helper;
3 | using CodeConverterCore.Model;
4 | using CodeConverterCSharp;
5 | using NUnit.Framework;
6 | using System.Linq;
7 |
8 | namespace CodeConverterCSharp_Unittest
9 | {
10 | public class MethodeAsPropertyGet_Unittest
11 | {
12 | [Test]
13 | public void PropertyGet()
14 | {
15 | var tmpProject = new ProjectInformation();
16 | var tmpClass = Create.AddClass("v1");
17 | var tmpMethode=tmpClass.AddMethode("Name", new TypeContainer("string"));
18 | tmpMethode.IsProperty = true;
19 | tmpProject.FillClasses(new System.Collections.Generic.List { tmpClass });
20 | var tmpObjectInformation = CSharpWriter.CreateClassesFromObjectInformation(tmpProject,new ConverterBase()).ToList();
21 |
22 |
23 | Assert.AreEqual(1, tmpObjectInformation.Count);
24 | Assert.AreEqual(true, tmpObjectInformation[0].Content.Contains("string Name{"));
25 | Assert.AreEqual(false, tmpObjectInformation[0].Content.Contains("string Name()"));
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/CodeConverterCore/Analyzer/AnalyzerSettings.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Model;
2 |
3 | namespace CodeConverterCore.Analyzer
4 | {
5 | public class AnalyzerSettings
6 | {
7 |
8 | public int MaxAmountOfParallelism { get; set; } = 7;
9 |
10 | ///
11 | /// An Unknown Type has been added
12 | ///
13 | public event UnknownTypeHandler UnknownTypeAdded;
14 |
15 | internal void InvokeUnknownTypeAdded(UnknownTypeClass inUnknownType)
16 | {
17 | UnknownTypeAdded?.Invoke(inUnknownType);
18 | }
19 | public delegate void UnknownTypeHandler(UnknownTypeClass inUnknownType);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/CodeConverterCore/Analyzer/DictionaryHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace CodeConverterCore.Analyzer
6 | {
7 | public static class DictionaryHelper
8 | {
9 | ///
10 | /// Add Listable Value to Dictionary
11 | ///
12 | ///
13 | ///
14 | ///
15 | ///
16 | ///
17 | /// False if the Value was already added
18 | public static bool Add(this Dictionary> inDictionary, TKey inKey, TValueEntry inValue)
19 | {
20 | if (!inDictionary.TryGetValue(inKey, out var tmpList))
21 | {
22 | tmpList = new List();
23 | inDictionary.Add(inKey, tmpList);
24 | }
25 | if (tmpList.Contains(inValue))
26 | {
27 | return false;
28 | }
29 | tmpList.Add(inValue);
30 | return true;
31 | }
32 | ///
33 | /// Add Listable Value to Dictionary
34 | ///
35 | ///
36 | ///
37 | ///
38 | ///
39 | ///
40 | /// False if the Value was already added
41 | public static bool TryGetValue(this Dictionary> inDictionary, TKey inKey, Func inListSearch, out TValueEntry outValue)
42 | {
43 | if (inDictionary.TryGetValue(inKey, out var tmpList))
44 | {
45 | var tmpVal = tmpList.FirstOrDefault(inListSearch);
46 | if (tmpVal != null)
47 | {
48 | outValue = tmpVal;
49 | return true;
50 | }
51 | }
52 | outValue = default(TValueEntry);
53 | return false;
54 | }
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/CodeConverterCore/Converter/ConverterBase.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Model;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace CodeConverterCore.Converter
6 | {
7 | ///
8 | /// Helper to Convert Data
9 | ///
10 | public class ConverterBase : IConverter
11 | {
12 | ///
13 | /// Create Comment from Comment-String
14 | ///
15 | /// Comment string (single or Multiline)
16 | /// Simple Comment, or Methode/Class definition Comment
17 | public virtual string Comment(string inOldComment, bool inDefinitionCommennt = false)
18 | {
19 | return inOldComment;
20 | }
21 |
22 | ///
23 | /// Class Name handling
24 | ///
25 | public virtual string ClassName(ClassContainer inClass)
26 | {
27 | return inClass.Type.Type.Name;
28 | }
29 |
30 | ///
31 | /// Class Name handling
32 | ///
33 | public virtual IEnumerable Namespace(params string[] inNamespace)
34 | {
35 | return inNamespace.ToList();
36 | }
37 |
38 | ///
39 | /// MethodeParameter Handling
40 | ///
41 | public virtual string MethodeInParameter(FieldContainer inMethodeParameter)
42 | {
43 | return inMethodeParameter.Name;
44 | }
45 |
46 | ///
47 | /// Map and Sort Attributes of classes, fields and methods
48 | ///
49 | ///
50 | ///
51 | ///
52 | public virtual List MapAndSortAttributes(List inAttributeList, bool inProperty = false)
53 | {
54 | return inAttributeList;
55 | }
56 |
57 | ///
58 | /// Change Methode Names to be matching C# names
59 | ///
60 | ///
61 | ///
62 | public virtual string MethodeName(MethodeContainer inMethode)
63 | {
64 | return inMethode.Name;
65 | }
66 |
67 | ///
68 | /// Handle Things, not handled inside other code
69 | ///
70 | ///
71 | public virtual void AnalyzerClassModifier(ClassContainer inClass)
72 | {
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/CodeConverterCore/Converter/IConverter.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Model;
2 | using System.Collections.Generic;
3 |
4 | namespace CodeConverterCore.Converter
5 | {
6 | ///
7 | /// Interace for Convertion Data
8 | ///
9 | public interface IConverter
10 | {
11 | ///
12 | /// Create Comment from Comment-String
13 | ///
14 | /// Comment string (single or Multiline)
15 | /// Simple Comment, or Methode/Class definition Comment
16 | string Comment(string inComment, bool inDefinitionCommennt = false);
17 |
18 | ///
19 | /// Mapp and Sort the Attributes from Java to C#
20 | ///
21 | ///
22 | ///
23 | ///
24 | List MapAndSortAttributes(List inAttributeList, bool inProperty = false);
25 |
26 | ///
27 | /// Class Name handling
28 | ///
29 | string ClassName(ClassContainer inClass);
30 |
31 | ///
32 | /// MethodeParameter Handling
33 | ///
34 | string MethodeInParameter(FieldContainer inMethodeParameter);
35 |
36 | ///
37 | /// Namespace Renaming
38 | ///
39 | ///
40 | ///
41 | IEnumerable Namespace(params string[] inNamespace);
42 |
43 | ///
44 | /// Change Methode Names to be matching C# names
45 | ///
46 | ///
47 | /// new Methode Name
48 | string MethodeName(MethodeContainer inMethode);
49 |
50 | ///
51 | /// Handle Things, not handled inside other code
52 | ///
53 | ///
54 | void AnalyzerClassModifier(ClassContainer inClass);
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/CodeConverterCore/Enum/ClayyTypeEnum.cs:
--------------------------------------------------------------------------------
1 | namespace CodeConverterCore.Enum
2 | {
3 | ///
4 | /// From where does this Class come?
5 | ///
6 | public enum ClassTypeEnum
7 | {
8 | Normal=0,
9 | System = 1,
10 | Unknown = 2,
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/CodeConverterCore/Enum/StatementTypeEnum.cs:
--------------------------------------------------------------------------------
1 | namespace CodeConverterCore.Enum
2 | {
3 | public enum StatementTypeEnum
4 | {
5 | If = 1,
6 | ElseIf = 2,
7 | Else = 3,
8 | For = 4,
9 | While = 5,
10 | Assert = 6,
11 | Elvis = 7,
12 | Throw = 8,
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/CodeConverterCore/Enum/VariableManipulatorType.cs:
--------------------------------------------------------------------------------
1 | namespace CodeConverterCore.Enum
2 | {
3 | public enum VariableOperatorType
4 | {
5 | //Matzh Operators
6 | Addition=1,
7 | Substraction=2,
8 | Multiplication=3,
9 | Division = 4,
10 |
11 | //Boolean operators
12 | Equals = 10,
13 | NotEquals = 11,
14 | MoreThan = 12,
15 | MoreOrEquals = 13,
16 | LessThan = 14,
17 | LessOrEquals = 15,
18 | And = 16,
19 | Or= 17,
20 | XOR = 18,
21 | Not = 19,
22 |
23 | //Bitshift Operators
24 | BitShiftRight = 20,
25 | BitShiftLeft = 21,
26 | BitShiftRightUnsigned = 22,
27 | BitShiftLeftUnsigned = 23,
28 | BitwiseAnd = 24,
29 | BitwiseOr = 25,
30 |
31 | //MathEqualsOperatiosn
32 | PlusPlus = 31,
33 | MinusMinus = 32,
34 | PlusEquals = 33,
35 | MinusEquals = 34,
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/CodeConverterCore/Helper/AntlrHelper.cs:
--------------------------------------------------------------------------------
1 | using Antlr4.Runtime.Tree;
2 | using System.Collections.Generic;
3 |
4 | namespace CodeConverterCore.Helper
5 | {
6 | public static class AntlrHelper
7 | {
8 | ///
9 | /// Get All Children of Tree Element
10 | ///
11 | ///
12 | ///
13 | public static IEnumerable GetChildren(this IParseTree inTree)
14 | {
15 | if (inTree == null)
16 | {
17 | yield break;
18 | }
19 | for (var tmpI = 0; tmpI < inTree.ChildCount; tmpI++)
20 | {
21 | var tmpChild = inTree.GetChild(tmpI);
22 | yield return tmpChild;
23 | }
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/CodeConverterCore/Helper/CTSExtensions.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Model;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 |
6 | namespace CodeConverterCore.Helper
7 | {
8 | public static class CTSExtensions
9 | {
10 | ///
11 | /// Forach auf einer Liste ausführen
12 | ///
13 | ///
14 | ///
15 | ///
16 | ///
17 | public static IEnumerable Foreach(this IEnumerable inData, Action inAction)
18 | {
19 | foreach (var tmpData in inData)
20 | {
21 | inAction(tmpData);
22 | yield return tmpData;
23 | }
24 | }
25 |
26 | ///
27 | /// Uppens the first Char
28 | ///
29 | ///
30 | ///
31 | public static string PascalCase(this string inMethodeName)
32 | {
33 | if (inMethodeName == null)
34 | {
35 | return null;
36 | }
37 | if (inMethodeName.Length < 2)
38 | {
39 | return inMethodeName.ToUpper();
40 | }
41 | return inMethodeName.First().ToString().ToUpper() + inMethodeName.Substring(1);
42 | }
43 |
44 | ///
45 | /// Uppens the first Char
46 | ///
47 | ///
48 | ///
49 | public static int FirstIndexofAny(this string inText, char[] inIndexSearch)
50 | {
51 | var tmpFirstIndex = inText.Length + 1;
52 | foreach (var tmpChar in inIndexSearch)
53 | {
54 | var tmpIndexOf = inText.IndexOf(tmpChar);
55 | if (tmpIndexOf != -1)
56 | {
57 | tmpFirstIndex = Math.Min(tmpFirstIndex, tmpIndexOf);
58 | }
59 | }
60 |
61 | if (tmpFirstIndex == inText.Length + 1)
62 | {
63 | return -1;
64 | }
65 | return tmpFirstIndex;
66 | }
67 |
68 | ///
69 | /// Gets all Valid Types for a Generic Value.
70 | /// The Last one might be 'IsArray'
71 | ///
72 | ///
73 | ///
74 | public static List GetGenericObjectsForType(this string inFullType)
75 | {
76 | return inFullType
77 | .Split(new char[] { '<', '>', ',' })
78 | .Select(inItem => inItem.Trim(' '))
79 | .Where(inItem => !string.IsNullOrEmpty(inItem))
80 | .Skip(1) //Skip the first Element (Class Name)
81 | .ToList();
82 | }
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/CodeConverterCore/Helper/ClassHelper.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Model;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace CodeConverterCore.Helper
9 | {
10 | public static class ClassHelper
11 | {
12 | ///
13 | /// Get Parent Class for Class
14 | ///
15 | ///
16 | ///
17 | ///
18 | public static ClassContainer GetParentClass(this ClassContainer inClass)
19 | {
20 | var tmpPartentClass = inClass.InterfaceList
21 | .Where(inItem => inItem.Type != null)
22 | .Select(inItem => inClass.Parent.GetClassForType(inItem.Type.Name, inClass.FullUsingList))
23 | .FirstOrDefault(inItem => inItem != null && !inItem.ModifierList.Any(inModifier => inModifier == "interface"));
24 |
25 | if (tmpPartentClass != null)
26 | {
27 | return tmpPartentClass;
28 | }
29 |
30 | if (inClass.Name?.ToLower() != "object")
31 | {
32 | //object type laden
33 | return inClass.Parent.GetClassForType("Object", new List { inClass.Parent.SystemNamespace })
34 | ?? inClass.Parent.GetAliasType("object");
35 | }
36 | else
37 | {
38 | return null;
39 | }
40 | }
41 |
42 | ///
43 | /// Find a Methode in the CLass, Matching the Template
44 | ///
45 | ///
46 | ///
47 | ///
48 | public static MethodeContainer FindMatchingMethode(this MethodeContainer inMethodeTemplate, ClassContainer inClass, bool inCheckParams = true)
49 | {
50 | var tmpMethodeList = inClass.MethodeList
51 | .Where(inItem => inItem.Name == inMethodeTemplate.Name);
52 |
53 | if (inCheckParams)
54 | {
55 | //Match Methode Parameter lenght
56 | tmpMethodeList = tmpMethodeList.Where(inItem => inItem.Parameter.Count == inMethodeTemplate.Parameter.Count);
57 |
58 | //TODO Find Methode by Matching Params
59 | }
60 |
61 | return tmpMethodeList.FirstOrDefault();
62 | }
63 |
64 | ///
65 | /// Handle Modifiers of a List to add/Remove spezific Modifiers
66 | ///
67 | ///
68 | ///
69 | ///
70 | public static void HandleListContent(this List inModifierList, string inModifierToHandle, bool inAddModifier = true)
71 | {
72 | if (inAddModifier)
73 | {
74 | if (!inModifierList.Contains(inModifierToHandle))
75 | {
76 | inModifierList.Add(inModifierToHandle);
77 | }
78 | }
79 | else
80 | {
81 | if (inModifierList.Contains(inModifierToHandle))
82 | {
83 | inModifierList.Remove(inModifierToHandle);
84 | }
85 | }
86 | }
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/CodeConverterCore/Helper/DataHelper.cs:
--------------------------------------------------------------------------------
1 | using IniParser;
2 | using IniParser.Model;
3 | using System.Collections.Generic;
4 | using System.IO;
5 |
6 | namespace CodeConverterCore.Helper
7 | {
8 | public static class DataHelper
9 | {
10 | public static List LoadJavaBaseFiles()
11 | {
12 | return new List();
13 | }
14 |
15 | ///
16 | /// Load an Ini File
17 | ///
18 | ///
19 | ///
20 | public static IniData LoadIniByPath(string inPath)
21 | {
22 | var parser = new FileIniDataParser();
23 | IniData data = parser.ReadFile(inPath);
24 |
25 | return data;
26 | }
27 | ///
28 | /// Load an Ini File
29 | ///
30 | ///
31 | ///
32 | public static IniData LoadIni(string inIniAsText)
33 | {
34 | var parser = new FileIniDataParser();
35 | var stream = new MemoryStream();
36 | var writer = new StreamWriter(stream);
37 | writer.Write(inIniAsText);
38 | writer.Flush();
39 | stream.Position = 0;
40 |
41 | IniData data = parser.ReadData(new System.IO.StreamReader(stream));
42 |
43 | return data;
44 | }
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/CodeConverterCore/Helper/Modifiers.cs:
--------------------------------------------------------------------------------
1 | namespace CodeConverterCore.Helper
2 | {
3 | public static class Modifiers
4 | {
5 | ///
6 | /// Override Modifier
7 | ///
8 | public static string Override = "override";
9 |
10 | ///
11 | /// Abstract Modifier
12 | ///
13 | public static string Abstract = "abstract";
14 |
15 | ///
16 | /// Struct Modifier
17 | ///
18 | public static string Struct = "struct";
19 |
20 | ///
21 | /// System.Diagnostics
22 | ///
23 | public static string SystemDiagnosis = "System.Diagnostics";
24 |
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/CodeConverterCore/Helper/RegexHelper.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Text.RegularExpressions;
6 | using System.Threading.Tasks;
7 |
8 | namespace CodeConverterCore.Helper
9 | {
10 | public partial class RegexHelper
11 | {
12 | public static Regex WordCheck = new Regex("\\w", RegexOptions.Compiled);
13 |
14 | public static Regex NumberCheck = new Regex(@"^-?[0-9][0-9,\.]+(d|m|f|L|UL|U){0,1}$", RegexOptions.Compiled);
15 |
16 | public static Regex NameStartsWith_In = new Regex("^(i|I)n([A-Z0-9]){1,1}", RegexOptions.Compiled);
17 |
18 | public static Regex NameStartsWith_Out = new Regex("^(o|O)ut([A-Z0-9]){1,1}", RegexOptions.Compiled);
19 |
20 | public static Regex NameStartsWith_Tmp = new Regex("^(t|T)mp([A-Z0-9]){1,1}", RegexOptions.Compiled);
21 |
22 | ///
23 | /// Check if the FIrst char in the String is an Upper char letter
24 | ///
25 | /// inputstring
26 | ///
27 | public static bool IsFirstCharUpper(string inInput)
28 | {
29 | if (string.IsNullOrEmpty(inInput))
30 | {
31 | return false;
32 | }
33 | if (inInput[0] > 64 && inInput[0] < 91)
34 | {
35 | return true;
36 | }
37 | return false;
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/CodeConverterCore/ImportExport/AliasObject.cs:
--------------------------------------------------------------------------------
1 | namespace CodeConverterCore.ImportExport
2 | {
3 | ///
4 | /// Alias Object
5 | ///
6 | public class AliasObject
7 | {
8 | ///
9 | /// Name of the Class as object
10 | ///
11 | public string From { get; set; }
12 | ///
13 | /// Name of the Alias
14 | ///
15 | public string To { get; set; }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/CodeConverterCore/ImportExport/ExportHelper.cs:
--------------------------------------------------------------------------------
1 | using CodeConverterCore.Model;
2 | using Newtonsoft.Json;
3 | using Newtonsoft.Json.Serialization;
4 | using System;
5 | using System.Collections;
6 | using System.Collections.Generic;
7 | using System.Linq;
8 | using System.Reflection;
9 |
10 | namespace CodeConverterCore.ImportExport
11 | {
12 | public static class ExportHelper
13 | {
14 | private static JsonSerializerSettings Settings()
15 | {
16 | return new JsonSerializerSettings
17 | {
18 | Formatting = Formatting.Indented,
19 | NullValueHandling = NullValueHandling.Ignore,
20 | DefaultValueHandling = DefaultValueHandling.Ignore,
21 | ContractResolver = ShouldSerializeContractResolver.Instance,
22 | };
23 | }
24 |
25 | public static string CreateJsonFromClassList(List inClassList)
26 | {
27 | return JsonConvert.SerializeObject(inClassList, Settings());
28 | }
29 | public static string SaveAliasList(List inAliasList)
30 | {
31 | return JsonConvert.SerializeObject(inAliasList, Settings());
32 | }
33 | public static string SaveMappingList(List inMappingObjectList)
34 | {
35 | return JsonConvert.SerializeObject(inMappingObjectList, Settings());
36 | }
37 |
38 | public static string SaveStringReplacements(List inStringReplacementList)
39 | {
40 | return JsonConvert.SerializeObject(inStringReplacementList, Settings());
41 | }
42 | }
43 |
44 | public class ShouldSerializeContractResolver : DefaultContractResolver
45 | {
46 | public static readonly ShouldSerializeContractResolver Instance = new ShouldSerializeContractResolver();
47 |
48 | protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
49 | {
50 | JsonProperty property = base.CreateProperty(member, memberSerialization);
51 |
52 | if (property.PropertyType != typeof(string))
53 | {
54 | if (property.PropertyType.GetInterface(nameof(IEnumerable)) != null)
55 | property.ShouldSerialize =
56 | instance => (instance?.GetType().GetProperty(property.PropertyName).GetValue(instance) as IEnumerable