├── .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)?.Count() > 0; 57 | } 58 | return property; 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /CodeConverterCore/ImportExport/ImportHelper.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Model; 3 | using Newtonsoft.Json; 4 | using System.Collections.Generic; 5 | 6 | namespace CodeConverterCore.ImportExport 7 | { 8 | public static class ImportHelper 9 | { 10 | public static List ImportClasses(string inClassJson) 11 | { 12 | var tmpClassList = JsonConvert.DeserializeObject>(inClassJson); 13 | tmpClassList.ForEach(inItem => inItem.ClassType = ClassTypeEnum.System); 14 | return tmpClassList; 15 | } 16 | 17 | public static List ImportAliasList(string inClassJson) 18 | { 19 | return JsonConvert.DeserializeObject>(inClassJson); 20 | } 21 | 22 | public static List ImportMappingList(string inMappingJson) 23 | { 24 | return JsonConvert.DeserializeObject>(inMappingJson); 25 | } 26 | 27 | public static List ImportStringReplacements(string inReplacementJson) 28 | { 29 | return JsonConvert.DeserializeObject>(inReplacementJson); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /CodeConverterCore/ImportExport/LanguageMappingObject.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace CodeConverterCore.ImportExport 4 | { 5 | /// 6 | /// Alias Object 7 | /// 8 | [DebuggerDisplay("{Source} -> {Target}")] 9 | public class LanguageMappingObject 10 | { 11 | /// 12 | /// Source information about the system class (language the code has been loaded in) 13 | /// 14 | public MappingObject Source { get; set; } 15 | 16 | /// 17 | /// Target information about the system class (language the code shall be written in) 18 | /// 19 | public MappingObject Target { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CodeConverterCore/ImportExport/MappingObject.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace CodeConverterCore.ImportExport 4 | { 5 | /// 6 | /// Alias Object 7 | /// 8 | [DebuggerDisplay("{Namespace} {ClassName} {MethodeName}")] 9 | public class MappingObject 10 | { 11 | /// 12 | /// Class namespace 13 | /// 14 | public string Namespace { get; set; } 15 | 16 | /// 17 | /// Name of the class used for this mapping 18 | /// 19 | public string ClassName { get; set; } 20 | 21 | /// 22 | /// Name of the Methode used for this mapping, can be null 23 | /// 24 | public string MethodeName { get; set; } 25 | 26 | /// 27 | /// Write the Methode as Property if supported by the output Language 28 | /// 29 | public bool MethodeAsProperty { get; set; } 30 | 31 | public bool IsMethodeMapping() 32 | { 33 | return !string.IsNullOrEmpty(MethodeName); 34 | } 35 | 36 | public bool IsClassMapping() 37 | { 38 | return string.IsNullOrEmpty(MethodeName); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CodeConverterCore/ImportExport/StringReplacement.cs: -------------------------------------------------------------------------------- 1 | namespace CodeConverterCore.ImportExport 2 | { 3 | /// 4 | /// Definition to replace a string inside a text 5 | /// 6 | public class StringReplacement 7 | { 8 | /// 9 | /// 10 | /// 11 | public string NameRegex { get; set; } 12 | 13 | /// 14 | /// Text to look for 15 | /// 16 | public string SourceText { get; set; } 17 | 18 | /// 19 | /// Replacement text 20 | /// 21 | public string ReplacementText { get; set; } 22 | 23 | /// 24 | /// Contains a Using, if one is required after this replacement 25 | /// 26 | public string RequiredUsing { get; set; } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /CodeConverterCore/Interface/CodeResultType.cs: -------------------------------------------------------------------------------- 1 | namespace CodeConverterCore.Interface 2 | { 3 | public enum CodeResultType 4 | { 5 | None = 1, 6 | Comment = 2, 7 | InCurlyBracket = 3, 8 | LineEnd = 4, 9 | InBracket = 5, 10 | } 11 | 12 | public enum CodeLineResultType 13 | { 14 | EndOfLine = 1, 15 | Comment = 2, 16 | CurlyStart = 3, 17 | CurlyEnd = 4, 18 | } 19 | 20 | 21 | public enum FormatResultType 22 | { 23 | EndOfLine = 1, 24 | CurlyStart = 2, 25 | CurlyEnd = 3, 26 | SingleLineCommentStart = 4, 27 | SingleLineCommentEnd = 5, 28 | MultiLineCommentStart = 6, 29 | MultiLineCommentEnd = 7, 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CodeConverterCore/Interface/ICodeEntry.cs: -------------------------------------------------------------------------------- 1 | namespace CodeConverterCore.Interface 2 | { 3 | public interface ICodeEntry 4 | { 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /CodeConverterCore/Interface/ICodeStepperEvents.cs: -------------------------------------------------------------------------------- 1 | namespace CodeConverterCore.Interface 2 | { 3 | public interface ICodeStepperEvents 4 | { 5 | /// 6 | /// Called ever time the CodeStepper finds a ICodeEntry object 7 | /// 8 | /// 9 | void CodeEntryStep(ICodeEntry inCodeEntry); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /CodeConverterCore/Interface/ILoadOOPLanguage.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.Interface 9 | { 10 | public interface ILoadOOPLanguage 11 | { 12 | ProjectInformation CreateObjectInformation(List inFileContents, IniParser.Model.IniData inConfiguration); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /CodeConverterCore/Interface/IMissingTypes.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Model; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeConverterCore.Interface 5 | { 6 | public interface IMissingTypes 7 | { 8 | /// 9 | /// Add a Missing Class 10 | /// 11 | void AddMissingClass(string inTypeName); 12 | 13 | /// 14 | /// Add missing Methode to Class Lsit 15 | /// 16 | void AddMissingMethode(string inMethodeName, TypeContainer inClassType, List inParamList, string inOutType); 17 | 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CodeConverterCore/Interface/IName.cs: -------------------------------------------------------------------------------- 1 | namespace CodeConverterCore.Interface 2 | { 3 | public interface IName 4 | { 5 | string Name { get; } 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /CodeConverterCore/Interface/INameConverter.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Model; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeConverterCore.Interface 5 | { 6 | public interface INameConverter 7 | { 8 | /// 9 | /// Change the Namespace 10 | /// 11 | string ChangeNamespace(string inNamespace); 12 | 13 | /// 14 | /// Change the Name of a Methode 15 | /// Consistency Required for the Code to work Propertly 16 | /// 17 | string ChangeMethodeName(string inMethodeName); 18 | 19 | /// 20 | /// Change the Name of a Methode 21 | /// Consistency Required for the Code to work Propertly 22 | /// 23 | string ChangeMethodeParameterName(string inMethodeParameterName); 24 | 25 | /// 26 | /// Change the Name of a Methode 27 | /// Consistency Required for the Code to work Propertly 28 | /// 29 | string ChangeFieldName(string inFieldName); 30 | 31 | /// 32 | /// Change the Name of a Methode 33 | /// Consistency Required for the Code to work Propertly 34 | /// 35 | List MapAndSortAttributes(List inAttributeList, bool inProperty = false); 36 | 37 | /// 38 | /// Return the Class for a spezific Type 39 | /// 40 | /// 41 | /// 42 | /// 43 | ClassContainer GetClassForType(string inType, List inNamespaces); 44 | 45 | /// 46 | /// Map a Type from the Old langugae to the New One 47 | /// 48 | /// Full Qualified Type 49 | string MapType(string inType, List inNamespaces); 50 | 51 | /// 52 | /// Map a Function from the Old langugae to the New One 53 | /// 54 | /// New Name of the Methode 55 | string MapFunction(string inFunction, string inType, List inNamespaces); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CodeConverterCore/Interface/IResolveMethodeContentToIL.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Model; 2 | 3 | namespace CodeConverterCore.Interface 4 | { 5 | public interface IResolveMethodeContentToIL 6 | { 7 | void Resolve(MethodeContainer inMethodeContainer); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/BaseType.cs: -------------------------------------------------------------------------------- 1 | using System.Diagnostics; 2 | 3 | namespace CodeConverterCore.Model 4 | { 5 | [DebuggerDisplay("{Namespace}.{Name}")] 6 | public class BaseType 7 | { 8 | public BaseType(string inName, string inNamespace) 9 | { 10 | Name = inName; 11 | Namespace = inNamespace; 12 | } 13 | 14 | /// 15 | /// Unknown Types or Types to be Defined 16 | /// 17 | /// 18 | public BaseType(string inName) 19 | { 20 | Name = inName; 21 | Namespace = ""; 22 | } 23 | 24 | /// 25 | /// Name des Typs 26 | /// 27 | public string Name { get; set; } 28 | 29 | /// 30 | /// Typen Namespace 31 | /// 32 | public string Namespace { get; set; } 33 | 34 | /// 35 | /// Void BaseType 36 | /// 37 | public static BaseType Void = new BaseType("void"); 38 | 39 | public override bool Equals(object obj) 40 | { 41 | return Equals(obj as BaseType); 42 | } 43 | 44 | public bool Equals(BaseType inComapreType) 45 | { 46 | if (Name != inComapreType.Name) 47 | { 48 | return false; 49 | } 50 | if (Namespace != inComapreType.Namespace) 51 | { 52 | return false; 53 | } 54 | return true; 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/ClassContainer.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using Newtonsoft.Json; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | using System.Linq; 6 | 7 | namespace CodeConverterCore.Model 8 | { 9 | /// 10 | /// Definition einer Klasse 11 | /// 12 | [JsonObject(MemberSerialization.OptIn)] 13 | [DebuggerDisplay("{Namespace}: {Type}")] 14 | public class ClassContainer 15 | { 16 | /// 17 | /// Class-Name 18 | /// 19 | public string Name 20 | { 21 | get 22 | { 23 | return Type?.Name ?? "BBBBB"; 24 | } 25 | } 26 | 27 | /// 28 | /// Class Type 29 | /// 30 | [JsonProperty] 31 | public TypeContainer Type { get; set; } 32 | 33 | /// 34 | /// Namespace der Klasse 35 | /// 36 | [JsonProperty] 37 | public string Namespace { get; set; } 38 | 39 | /// 40 | /// Comment in the Namespace of the Class 41 | /// 42 | public string NamespaceComment { get; set; } 43 | 44 | /// 45 | /// Class Comment 46 | /// 47 | public string Comment { get; set; } 48 | 49 | /// 50 | /// Usings, welche der Klasse angefügt sind. 51 | /// 52 | [JsonProperty] 53 | public List UsingList { get; set; } = new List(); 54 | 55 | /// 56 | /// Parent and a List of Implemented Interfaces 57 | /// 58 | [JsonProperty] 59 | public List InterfaceList { get; set; } = new List(); 60 | 61 | /// 62 | /// Klassenattribute (sealed, Abstract, ....) 63 | /// 64 | [JsonProperty] 65 | public List ModifierList { get; set; } = new List(); 66 | 67 | /// 68 | /// Liste der Felder (Field, ggf. Property) 69 | /// 70 | [JsonProperty] 71 | public List FieldList { get; set; } = new List(); 72 | 73 | /// 74 | /// Liste der Methoden 75 | /// 76 | [JsonProperty] 77 | public List MethodeList { get; } = new List(); 78 | 79 | public void AddMethode(MethodeContainer inNewMethode) 80 | { 81 | MethodeList.Add(inNewMethode); 82 | inNewMethode.Parent = this; 83 | } 84 | 85 | /// 86 | /// List of inner Classes 87 | /// 88 | public List InnerClasses { get; set; } = new List(); 89 | 90 | /// 91 | /// System Classes do not need to be put into the Output 92 | /// Loaded and Unknown Classes do net to be put into Output 93 | /// 94 | public ClassTypeEnum ClassType { get; set; } = ClassTypeEnum.Normal; 95 | 96 | /// 97 | /// CHeck for Empty 98 | /// 99 | /// 100 | public bool IsEmpty() 101 | { 102 | if (string.IsNullOrEmpty(Name)) 103 | { 104 | return true; 105 | } 106 | return false; 107 | } 108 | 109 | /// 110 | /// Has this Class been Corectly Converted into the IL language? 111 | /// 112 | public bool IsAnalyzed { get; internal set; } 113 | 114 | /// 115 | /// Ist it an Interface? 116 | /// 117 | /// 118 | public bool IsInterface() 119 | { 120 | return ModifierList.Contains("interface"); 121 | } 122 | 123 | /// 124 | /// Parent Project Information 125 | /// 126 | public ProjectInformation Parent { get; internal set; } 127 | 128 | public List FullUsingList 129 | { 130 | get 131 | { 132 | return UsingList.Concat(new List { Namespace }).ToList(); 133 | } 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/CodeBlock.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeConverterCore.Model 5 | { 6 | public class CodeBlock 7 | { 8 | public List CodeEntries { get; set; } = new List(); 9 | 10 | /// 11 | /// Override TOString to better debug and Read 12 | /// 13 | /// 14 | public override string ToString() 15 | { 16 | return string.Join(" ", CodeEntries); 17 | } 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/CodeBlockContainer.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | 3 | namespace CodeConverterCore.Model 4 | { 5 | public class CodeBlockContainer : ICodeEntry 6 | { 7 | /// 8 | /// Name of the Variable to access (filled from Code-Resolver) 9 | /// 10 | public CodeBlock InnerBlock { get; set; } = new CodeBlock(); 11 | 12 | public override string ToString() 13 | { 14 | return $"{InnerBlock}"; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/CodeExpression.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | using CodeConverterCore.Enum; 3 | using System.Collections.Generic; 4 | 5 | 6 | namespace CodeConverterCore.Model 7 | { 8 | public class CodeExpression : ICodeEntry 9 | { 10 | /// 11 | /// What sort of Manipulation is done? 12 | /// 13 | public VariableOperatorType Manipulator { get; set; } 14 | 15 | public List SubClauseEntries { get; set; } = new List(); 16 | 17 | /// 18 | /// Override TOString to better debug and Read 19 | /// 20 | /// 21 | public override string ToString() 22 | { 23 | return $"({string.Join($" {Manipulator} ", SubClauseEntries)})"; 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/CodeState.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeConverterCore.Model 5 | { 6 | /// 7 | /// Current State of the Code 8 | /// 9 | public class CodeState 10 | { 11 | public CodeState(INameConverter inConverter, List inUsingList) 12 | { 13 | _converter = inConverter; 14 | _usingList = inUsingList; 15 | } 16 | private INameConverter _converter; 17 | private List _usingList; 18 | 19 | private int LeftSpacing = 1; 20 | 21 | public void AddSpacing() 22 | { 23 | LeftSpacing++; 24 | } 25 | public void ReduceSpacing() 26 | { 27 | LeftSpacing--; 28 | } 29 | 30 | public string GetSpacing() 31 | { 32 | var tmpString = ""; 33 | 34 | for (var tmpI = 0; tmpI < LeftSpacing; tmpI++) 35 | { 36 | tmpString += " "; 37 | } 38 | return tmpString; 39 | } 40 | 41 | //Add a Variable to the Code State 42 | public void AddVariable(string inType, string inName, bool inForceAdd = true) 43 | { 44 | var tmpClass = _converter.GetClassForType(inType, _usingList); 45 | if (tmpClass == null) 46 | { 47 | //throw new Exception("not found"); 48 | } 49 | if (!inForceAdd) 50 | { 51 | if (_typeDictionary.ContainsKey(inName)) 52 | { 53 | return; 54 | } 55 | } 56 | _typeDictionary.Add(inName, tmpClass); 57 | } 58 | 59 | /// 60 | /// Clear all Variables 61 | /// 62 | public void ClearVariableList() 63 | { 64 | _MethodeParams.Clear(); 65 | _typeDictionary.Clear(); 66 | } 67 | 68 | /// 69 | /// Add a Variable to the Code State 70 | /// 71 | /// 72 | /// 73 | /// 74 | public void AddMethodeParam(string inType, string inName, bool inForceAdd = true) 75 | { 76 | AddVariable(inType, inName, inForceAdd); 77 | _MethodeParams.Add(inName); 78 | } 79 | 80 | //Add a Variable to the Code State 81 | public bool HasVariable(string inName) 82 | { 83 | return _typeDictionary.ContainsKey(inName); 84 | } 85 | 86 | public TypeContainer CurrentType { get; set; } 87 | 88 | /// 89 | /// Is it a Methode in Params? 90 | /// 91 | /// 92 | /// 93 | public bool IsVariableMethodeParam(string inName) 94 | { 95 | return _MethodeParams.Contains(inName); 96 | } 97 | 98 | /// 99 | /// Typ aufgrund des Namens laden 100 | /// 101 | /// 102 | /// 103 | public ClassContainer GetType(string inName) 104 | { 105 | if (_typeDictionary.TryGetValue(inName, out var tmpClass)) 106 | { 107 | return tmpClass; 108 | } 109 | return null; 110 | } 111 | 112 | private Dictionary _typeDictionary = new Dictionary(); 113 | private HashSet _MethodeParams = new HashSet(); 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/ConstantValue.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | using System; 3 | 4 | namespace CodeConverterCore.Model 5 | { 6 | public class ConstantValue : ICodeEntry 7 | { 8 | public ConstantValue() { } 9 | 10 | public ConstantValue(object inValue) 11 | { 12 | Value = inValue; 13 | } 14 | public object Value { get; set; } 15 | 16 | public TypeContainer Type { get; set; } 17 | 18 | /// 19 | /// Return Constant as Type with Value 20 | /// 21 | /// 22 | public override string ToString() 23 | { 24 | if (Type == null) 25 | { 26 | return Value?.ToString(); 27 | } 28 | return $"({Type.ToString()}){Value}"; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/FieldContainer.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | 5 | namespace CodeConverterCore.Model 6 | { 7 | /// 8 | /// Felddeklaration, Methodenparameter,... 9 | /// Every Field Container is also a Variable Declarion for Code Usage 10 | /// 11 | [JsonObject(MemberSerialization.OptIn)] 12 | public class FieldContainer: VariableDeclaration 13 | { 14 | /// 15 | /// Attributes (private, public, abstract, override,...) 16 | /// 17 | [JsonProperty] 18 | public List ModifierList { get; set; } = new List(); 19 | 20 | /// 21 | /// Kommentar, welcher zu diesem Feld geschrieben wurde 22 | /// 23 | public string Comment { get; set; } 24 | 25 | /// 26 | /// Default Wert 27 | /// 28 | public CodeBlock DefaultValue { get; set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/FieldNameFinder.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Security.Permissions; 3 | 4 | namespace CodeConverterCore.Model 5 | { 6 | public class FieldNameFinder 7 | { 8 | public FieldNameFinder() { } 9 | 10 | public FieldNameFinder(ClassContainer inClass) 11 | { 12 | Class = inClass; 13 | MethodeParentClass = inClass; 14 | } 15 | 16 | public FieldNameFinder(FieldNameFinder inParentFinder) 17 | { 18 | Class = inParentFinder.Class; 19 | MethodeParentClass = inParentFinder.MethodeParentClass; 20 | VariableList = inParentFinder.VariableList; 21 | VariableStack = inParentFinder.VariableStack; 22 | MethodeVarList = inParentFinder.MethodeVarList; 23 | } 24 | 25 | public ClassContainer Class { get; set; } 26 | 27 | /// 28 | /// Base Class from the Calling Methode 29 | /// 30 | public ClassContainer MethodeParentClass { get; set; } 31 | 32 | public List VariableList { get; set; } = new List(); 33 | 34 | private Stack> VariableStack = new Stack>(); 35 | 36 | private List MethodeVarList; 37 | 38 | public List GetMethodeVariableList() 39 | { 40 | if (MethodeVarList != null) 41 | { 42 | return MethodeVarList; 43 | } 44 | return VariableList; 45 | } 46 | 47 | public void StackVariables(bool inCopyCurrentList = false, bool inMethodeStack = false) 48 | { 49 | var tmpVarList = new List(VariableList); 50 | VariableStack.Push(tmpVarList); 51 | if (inMethodeStack && tmpVarList.Count > 0) 52 | { 53 | MethodeVarList = tmpVarList; 54 | } 55 | if (!inCopyCurrentList) 56 | { 57 | VariableList.Clear(); 58 | } 59 | } 60 | 61 | public void UnstackVariableList() 62 | { 63 | VariableList = VariableStack.Pop(); 64 | if (MethodeVarList == VariableList) 65 | { 66 | MethodeVarList = null; 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/MethodeCall.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeConverterCore.Model 5 | { 6 | public class MethodeCall : ICodeEntry 7 | { 8 | public string Name 9 | { 10 | get => MethodeLink?.Name ?? _name; 11 | set => _name = value; 12 | } 13 | private string _name; 14 | 15 | /// 16 | /// Methode Return Type 17 | /// 18 | public MethodeContainer MethodeLink { get; set; } 19 | 20 | /// 21 | /// Methode Parameter 22 | /// 23 | public List Parameter { get; set; } = new List(); 24 | 25 | /// 26 | /// Return Constant as Type with Value 27 | /// 28 | /// 29 | public override string ToString() 30 | { 31 | return $" {Name} ({string.Join(",", Parameter)})"; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/MethodeContainer.cs: -------------------------------------------------------------------------------- 1 | using Antlr4.Runtime.Tree; 2 | using Newtonsoft.Json; 3 | using System.Collections.Generic; 4 | using System.Diagnostics; 5 | 6 | namespace CodeConverterCore.Model 7 | { 8 | /// 9 | /// Methodendefinition für eine Klasse 10 | /// 11 | [JsonObject(MemberSerialization.OptIn)] 12 | [DebuggerDisplay("{Name}")] 13 | public class MethodeContainer 14 | { 15 | public MethodeContainer() { } 16 | /// 17 | /// Name of the Methode 18 | /// 19 | [JsonProperty] 20 | public string Name 21 | { 22 | get => ParentContainer?.Name ?? _name; 23 | set => _name = value; 24 | } 25 | private string _name; 26 | 27 | /// 28 | /// Returntype. Might be void 29 | /// 30 | [JsonProperty] 31 | public TypeContainer ReturnType { get; set; } 32 | 33 | /// 34 | /// List of Generic Sub-Types 35 | /// 36 | [JsonProperty] 37 | public List GenericTypes { get; set; } = new List(); 38 | 39 | /// 40 | /// A List of the Methode Params 41 | /// 42 | [JsonProperty] 43 | public List Parameter { get; set; } = new List(); 44 | 45 | /// 46 | /// Attributes (private, public, abstract, override,...) 47 | /// 48 | [JsonProperty] 49 | public List ModifierList { get; set; } = new List(); 50 | 51 | /// 52 | /// Constructor base calls (this and base) 53 | /// 54 | public MethodeCall ConstructorCall { get; set; } 55 | 56 | /// 57 | /// Methode Comment 58 | /// 59 | public string Comment { get; set; } 60 | 61 | /// 62 | /// Code, from Inside the Methode 63 | /// 64 | public CodeBlock Code { get; set; } 65 | 66 | /// 67 | /// Code, from Inside the Methode 68 | /// 69 | public IParseTree AntlrCode { get; set; } 70 | 71 | /// 72 | /// Filled, if the Methode is a Constructor with a Base Call (:this /:base) 73 | /// 74 | public MethodeContainer Constructorinfo { get; set; } 75 | 76 | /// 77 | /// Methode is a Property, if supported by the Language 78 | /// 79 | public bool IsProperty { get; set; } 80 | 81 | /// 82 | /// Parent Container when 83 | /// 84 | public MethodeContainer ParentContainer { get; set; } 85 | 86 | /// 87 | /// Methode Parent if this Methode overrides another Methode 88 | /// 89 | public ClassContainer Parent { get; set; } 90 | 91 | public bool IsConstructor { get; set; } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/MissingFunctionInformation.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace CodeConverterCore.Model 4 | { 5 | public class MissingFunctionInformation 6 | { 7 | /// 8 | /// Methode Name 9 | /// 10 | public string Name { get; set; } 11 | 12 | /// 13 | /// Return Type 14 | /// 15 | public TypeContainer ReturnType { get; set; } 16 | 17 | /// 18 | /// List of the Methode Params 19 | /// 20 | public List ParamList { get; set; } = new List(); 21 | } 22 | 23 | public class FunctionParam 24 | { 25 | /// 26 | /// Name 27 | /// 28 | public string Name { get; set; } 29 | 30 | /// 31 | /// Type 32 | /// 33 | public TypeContainer Type { get; set; } 34 | 35 | /// 36 | /// Methode Param Modifier 37 | /// 38 | public List ModifierList { get; set; } = new List(); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/NewObjectDeclaration.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeConverterCore.Model 5 | { 6 | public class NewObjectDeclaration : ICodeEntry 7 | { 8 | public ICodeEntry InnerCode { get; set; } 9 | 10 | public List ArgumentList { get; set; } 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/ReturnCodeEntry.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | 3 | namespace CodeConverterCore.Model 4 | { 5 | /// 6 | /// Return Code Entry for handling of Return elements 7 | /// 8 | public class ReturnCodeEntry : CodeBlock, ICodeEntry 9 | { 10 | /// 11 | /// Yield Return? 12 | /// 13 | public bool IsYield { get; set; } 14 | 15 | public override string ToString() 16 | { 17 | return $"{(IsYield ? "yield " : "")}return " + base.ToString(); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/SetFieldWithValue.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | 3 | namespace CodeConverterCore.Model 4 | { 5 | public class SetFieldWithValue : ICodeEntry 6 | { 7 | /// 8 | /// Variable that is accessed 9 | /// 10 | public CodeBlock VariableToAccess { get; set; } = new CodeBlock(); 11 | 12 | /// 13 | /// Value to be set to the Variable 14 | /// 15 | public CodeBlock ValueToSet { get; set; } = new CodeBlock(); 16 | 17 | /// 18 | /// Override TOString to better debug and Read 19 | /// 20 | /// 21 | public override string ToString() 22 | { 23 | return VariableToAccess.ToString() + "=" + ValueToSet.ToString(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/StatementCode.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Interface; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | 6 | namespace CodeConverterCore.Model 7 | { 8 | public class StatementCode : ICodeEntry 9 | { 10 | public StatementCode() 11 | { 12 | 13 | } 14 | 15 | /// 16 | /// Type of Statement 17 | /// 18 | public StatementTypeEnum StatementType { get; set; } 19 | 20 | /// 21 | /// Content inside the Statement 22 | /// 23 | public CodeBlock InnerContent { get; set; } 24 | 25 | /// 26 | /// Code that is Required by the statement (aka if expression or for(;;) information) 27 | /// 28 | public List StatementCodeBlocks { get; set; } 29 | 30 | /// 31 | /// Override TOString to better debug and Read 32 | /// 33 | /// 34 | public override string ToString() 35 | { 36 | switch (StatementType) 37 | { 38 | case StatementTypeEnum.Elvis: 39 | return $" {StatementCodeBlocks[0]} ? {StatementCodeBlocks[1]} : {StatementCodeBlocks[2]};"; 40 | } 41 | return $"{StatementType} {StatementCodeBlocks.FirstOrDefault()}{{{InnerContent}}}"; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/TypeConversion.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | 3 | namespace CodeConverterCore.Model 4 | { 5 | public class TypeConversion : ICodeEntry 6 | { 7 | public TypeConversion() { } 8 | 9 | /// 10 | /// Type to be Converted to 11 | /// 12 | public TypeContainer Type { get; set; } 13 | 14 | /// 15 | /// Value on the right side that needs to be Converted 16 | /// 17 | public CodeBlock PreconversionValue { get; set; } 18 | 19 | /// 20 | /// Ist the Conversion "as" or fix. 21 | /// 22 | /// 23 | /// false: (String)inObject 24 | /// true: inObject as String 25 | /// 26 | public bool IsAsConversion { get; set; } 27 | 28 | /// 29 | /// Return Constant as Type with Value 30 | /// 31 | /// 32 | public override string ToString() 33 | { 34 | if (Type == null) 35 | { 36 | return PreconversionValue?.ToString(); 37 | } 38 | return $"({Type}){PreconversionValue}"; 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/UnknownTypeClass.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Diagnostics; 3 | 4 | namespace CodeConverterCore.Model 5 | { 6 | [DebuggerDisplay("{Type}")] 7 | public class UnknownTypeClass : ClassContainer 8 | { 9 | public UnknownTypeClass(string inName) 10 | { 11 | Type = new TypeContainer { Type = new BaseType(inName), Name = inName }; 12 | } 13 | 14 | /// 15 | /// Possible Namespaces 16 | /// 17 | public List PossibleNamespace { get; set; } = new List(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/VariableAccess.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | 3 | namespace CodeConverterCore.Model 4 | { 5 | public class VariableAccess : ICodeEntry 6 | { 7 | /// 8 | /// Name of the Variable to access (filled from Code-Resolver) 9 | /// 10 | public ICodeEntry Access { get; set; } 11 | 12 | /// 13 | /// Next Child for Access 14 | /// resolves what will be done further with the Access 15 | /// 16 | public ICodeEntry Child { get; set; } 17 | 18 | /// 19 | /// Is Access to an Array 20 | /// 21 | public bool IsArrayAccess { get; set; } 22 | 23 | /// 24 | /// Base Code Entry with link to the actual source 25 | /// (Field, Methode-call, Variable, inParameter) 26 | /// filled during code-analysis 27 | /// 28 | public ICodeEntry BaseDataSource { get; set; } 29 | 30 | public override string ToString() 31 | { 32 | return $"{Access} {BaseDataSource} {Child}"; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /CodeConverterCore/Model/VariableDeclaration.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Interface; 2 | using Newtonsoft.Json; 3 | using System.Diagnostics; 4 | 5 | namespace CodeConverterCore.Model 6 | { 7 | [DebuggerDisplay("{Type}: {Name}")] 8 | public class VariableDeclaration : ICodeEntry, IName 9 | { 10 | /// 11 | /// Type of the Declaring Variable 12 | /// 13 | [JsonProperty] 14 | public TypeContainer Type { get; set; } 15 | 16 | /// 17 | /// Variablename 18 | /// 19 | public string Name { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /CodeConverterCore/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("CodeConverterCore")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CodeConverterCore")] 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("d70fe1c1-3cbe-42f1-8361-b05fa406a39c")] 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 | -------------------------------------------------------------------------------- /CodeConverterCore/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CodeConverterCore_Unittest/Analyzer/AnalyzerClassAndMethodeTypeLinks_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Model; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace CodeConverterCore_Unittest 8 | { 9 | /// 10 | /// Text Analyzer linking of Types 11 | /// 12 | public class AnalyzerClassAndMethodeTypeLinks_Unittest 13 | { 14 | 15 | [Test] 16 | public void MethodeReturnType() 17 | { 18 | var tmpProject = new ProjectInformation(); 19 | tmpProject.FillClasses(new List 20 | { 21 | Class_TestX(), 22 | Class_TestY(), 23 | }); 24 | new AnalyzerCore().LinkProjectInformation(tmpProject); 25 | 26 | Assert.AreEqual(tmpProject.ClassList[0].Type.Type, tmpProject.ClassList[0].MethodeList[0].ReturnType.Type); 27 | } 28 | 29 | [Test] 30 | public void MethodeParam1Type() 31 | { 32 | var tmpProject = new ProjectInformation(); 33 | tmpProject.FillClasses(new List 34 | { 35 | Class_TestX(), 36 | Class_TestY(), 37 | }); 38 | new AnalyzerCore().LinkProjectInformation(tmpProject); 39 | 40 | Assert.AreEqual(tmpProject.ClassList[1].Type.Type, tmpProject.ClassList[0].MethodeList[0].Parameter[0].Type.Type); 41 | } 42 | 43 | 44 | private ClassContainer Class_TestX(Action inChanges = null) 45 | { 46 | var tmpClass = new ClassContainer 47 | { 48 | Type = new TypeContainer { Name = "TestX" }, 49 | Namespace = "Base", 50 | 51 | }; 52 | tmpClass.MethodeList.AddRange(new List 53 | { 54 | new MethodeContainer 55 | { 56 | Name ="TestXFunc", 57 | ReturnType ="TestX", 58 | ModifierList =new List{ "public","static"}, 59 | Parameter =new List(){ 60 | new FieldContainer 61 | { 62 | Name ="inTestY", 63 | Type ="TestY", 64 | } 65 | }, 66 | } 67 | }); 68 | inChanges?.Invoke(tmpClass); 69 | return tmpClass; 70 | } 71 | 72 | private ClassContainer Class_TestY(Action inChanges = null) 73 | { 74 | var tmpClass = new ClassContainer 75 | { 76 | Type = new TypeContainer { Name = "TestY" }, 77 | Namespace = "Base", 78 | }; 79 | tmpClass.MethodeList.AddRange(new List 80 | { 81 | new MethodeContainer 82 | { 83 | Name ="TestXFunc", 84 | ReturnType ="TestX", 85 | } 86 | }); 87 | inChanges?.Invoke(tmpClass); 88 | return tmpClass; 89 | } 90 | } 91 | } -------------------------------------------------------------------------------- /CodeConverterCore_Unittest/Analyzer/AnalyzerClassTypeLinks_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Model; 3 | using NUnit.Framework; 4 | using System; 5 | using System.Collections.Generic; 6 | 7 | namespace CodeConverterCore_Unittest 8 | { 9 | /// 10 | /// Text Analyzer linking of Types 11 | /// 12 | public class AnalyzerClassTypeLinks_Unittest 13 | { 14 | 15 | [Test] 16 | public void CheckInterface() 17 | { 18 | var tmpProject = new ProjectInformation(); 19 | tmpProject.FillClasses(new List 20 | { 21 | Class_TestX(), 22 | Class_TestY(inItem=> inItem.InterfaceList.Add(new TypeContainer{Name=Class_TestX().Name })), 23 | }); 24 | new AnalyzerCore().LinkProjectInformation(tmpProject); 25 | 26 | Assert.AreEqual(tmpProject.ClassList[0].Type.Type, tmpProject.ClassList[1].InterfaceList[0].Type); 27 | } 28 | 29 | [Test] 30 | public void SamePartialClass() 31 | { 32 | var tmpProject = new ProjectInformation(); 33 | tmpProject.FillClasses(new List 34 | { 35 | Class_TestX(), 36 | Class_TestX(), 37 | }); 38 | new AnalyzerCore().LinkProjectInformation(tmpProject); 39 | 40 | Assert.AreEqual(tmpProject.ClassList[0].Type.Type, tmpProject.ClassList[1].Type.Type); 41 | } 42 | 43 | [Test] 44 | public void SameClassNameDifferentNamespace() 45 | { 46 | var tmpProject = new ProjectInformation(); 47 | tmpProject.FillClasses(new List 48 | { 49 | Class_TestX(), 50 | Class_TestX(inItem=> inItem.Namespace="DifferentNamespace"), 51 | }); 52 | new AnalyzerCore().LinkProjectInformation(tmpProject); 53 | 54 | Assert.AreNotEqual(tmpProject.ClassList[0].Type.Type, tmpProject.ClassList[1].Type.Type); 55 | } 56 | 57 | private ClassContainer Class_TestX(Action inChanges = null) 58 | { 59 | var tmpClass = new ClassContainer 60 | { 61 | Type = new TypeContainer { Name = "TestX" }, 62 | Namespace = "Base", 63 | }; 64 | inChanges?.Invoke(tmpClass); 65 | return tmpClass; 66 | } 67 | 68 | private ClassContainer Class_TestY(Action inChanges = null) 69 | { 70 | var tmpClass = new ClassContainer 71 | { 72 | Type = new TypeContainer { Name = "TestY" }, 73 | Namespace = "Base", 74 | }; 75 | inChanges?.Invoke(tmpClass); 76 | return tmpClass; 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /CodeConverterCore_Unittest/Analyzer/AnalyzerClassVariableLinks_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using NUnit.Framework; 5 | 6 | namespace CodeConverterCore_Unittest 7 | { 8 | /// 9 | /// Text Analyzer linking of Types 10 | /// 11 | public class AnalyzerClassVariableLinks_Unittest 12 | { 13 | 14 | [Test] 15 | public void CheckInterface() 16 | { 17 | var tmpProject = new ProjectInformation(); 18 | var tmpClass1 = Create.AddClass("Class1"); 19 | tmpClass1.AddMethode("M1", new TypeContainer { Name = "void" }); 20 | var tmpMethode = tmpClass1.MethodeList[0]; 21 | tmpMethode.Code = new CodeBlock(); 22 | var tmpVar = Create.AddVariable(tmpMethode.Code, "tmpVar", new TypeContainer { Name = "string" }); 23 | Create.SetFieldValue(tmpMethode.Code, tmpVar.CodeEntries[0], new ConstantValue { Value = "\"BBBB\"" }); 24 | new AnalyzerCore().LinkProjectInformation(tmpProject); 25 | 26 | Assert.AreEqual("tmpVar", (tmpVar.CodeEntries[0] as VariableDeclaration).Name); 27 | } 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /CodeConverterCore_Unittest/Analyzer/MethodeCall_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using NUnit.Framework; 5 | using System.Collections.Generic; 6 | 7 | namespace CodeConverterCore_Unittest 8 | { 9 | /// 10 | /// Text Analyzer linking of Types 11 | /// 12 | public class MethodeCall_Unittest 13 | { 14 | 15 | [Test] 16 | public void CallKnownMethodeOnItself() 17 | { 18 | var tmpProject = new ProjectInformation(); 19 | var tmpClass1 = Create.AddClass("Class1"); 20 | tmpProject.FillClasses(new List { tmpClass1 }); 21 | var tmpMethodeName = "inStr"; 22 | tmpClass1.AddMethode(tmpMethodeName, new TypeContainer { Name = "void" }); 23 | var tmpMethode = tmpClass1.MethodeList[0]; 24 | tmpMethode.Code = new CodeBlock(); 25 | var tmpMethodeCall = Create.CallMethode(tmpMethode.Code, tmpMethodeName); 26 | new AnalyzerCore().LinkProjectInformation(tmpProject); 27 | 28 | 29 | Assert.AreEqual(tmpMethode, tmpMethodeCall.MethodeLink); 30 | } 31 | 32 | [Test] 33 | public void CallKnownMethodeOnItselfWithThis() 34 | { 35 | var tmpProject = new ProjectInformation(); 36 | var tmpClass1 = Create.AddClass("Class1"); 37 | tmpProject.FillClasses(new List { tmpClass1 }); 38 | var tmpMethodeName = "compareTo"; 39 | tmpClass1.AddMethode(tmpMethodeName, new TypeContainer { Name = "void" }); 40 | var tmpMethode = tmpClass1.MethodeList[0]; 41 | tmpMethode.Code = new CodeBlock(); 42 | var tmpMethodeCall = Create.CallMethode(new CodeBlock(), tmpMethodeName); 43 | var tmpVarAccess = new VariableAccess() 44 | { 45 | Access = new ConstantValue("this"), 46 | Child = tmpMethodeCall, 47 | }; 48 | tmpMethode.Code.CodeEntries.Add(tmpVarAccess); 49 | new AnalyzerCore().LinkProjectInformation(tmpProject); 50 | tmpMethode.Name = "Blah"; 51 | 52 | 53 | Assert.AreEqual(tmpMethode, tmpMethodeCall.MethodeLink); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /CodeConverterCore_Unittest/Analyzer/MethodeParam_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using NUnit.Framework; 5 | 6 | namespace CodeConverterCore_Unittest 7 | { 8 | /// 9 | /// Text Analyzer linking of Types 10 | /// 11 | public class MethodeParam_Unittest 12 | { 13 | 14 | [Test] 15 | public void WriteIntToMethodeParam() 16 | { 17 | var tmpProject = new ProjectInformation(); 18 | var tmpClass1 = Create.AddClass("Class1"); 19 | var tmpFieldName = "inStr"; 20 | tmpClass1.AddMethode("M1", new TypeContainer { Name = "void" }, Create.AddField(tmpClass1, tmpFieldName, new BaseType("string"))); 21 | var tmpMethode = tmpClass1.MethodeList[0]; 22 | tmpMethode.Code = new CodeBlock(); 23 | var tmpSet= Create.SetFieldValue(tmpMethode.Code, tmpClass1.MethodeList[0].Parameter[0], new ConstantValue { Value = "\"BBBB\"" }); 24 | new AnalyzerCore().LinkProjectInformation(tmpProject); 25 | 26 | Assert.AreEqual(tmpClass1.MethodeList[0].Parameter[0], (tmpSet.CodeEntries[0] as SetFieldWithValue).VariableToAccess.CodeEntries[0]); 27 | } 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /CodeConverterCore_Unittest/Analyzer/PropertyStackingAccess_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using NUnit.Framework; 5 | using NUnit.Framework.Internal.Execution; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterCore_Unittest 9 | { 10 | /// 11 | /// Text Analyzer linking of Types 12 | /// 13 | public class PropertyStackingAccess_Unittest 14 | { 15 | 16 | [Test] 17 | public void PropertysThis_FullName_ToLower() 18 | { 19 | var tmpProject = new ProjectInformation(); 20 | 21 | var tmpClassString = Create.AddClass("String"); 22 | var tmpGetFullName = "getFullName"; 23 | var tmpFullNameMethode = tmpClassString.AddMethode(tmpGetFullName, new TypeContainer { Name = "String" }); 24 | 25 | var tmpClass1 = Create.AddClass("Class1"); 26 | var tmpMethodeName = "getChildResources"; 27 | tmpClass1.AddMethode(tmpMethodeName, new TypeContainer { Name = "void" }); 28 | var tmpMethode = tmpClass1.MethodeList[0]; 29 | Create.AddField(tmpClass1, "Text", new BaseType("String")); 30 | 31 | tmpMethode.Code = new CodeBlock(); 32 | 33 | var tmpReturn = new ReturnCodeEntry 34 | { 35 | CodeEntries = new List 36 | { 37 | new VariableAccess 38 | { 39 | Access= new VariableAccess 40 | { 41 | Child= new VariableAccess 42 | { 43 | Access = new ConstantValue 44 | { 45 | Value="Text", 46 | } 47 | }, 48 | Access= new ConstantValue 49 | { 50 | Value = "this" 51 | } 52 | }, 53 | Child= new VariableAccess 54 | { 55 | Access= new MethodeCall 56 | { 57 | Name =tmpGetFullName 58 | } 59 | } 60 | } 61 | } 62 | }; 63 | tmpMethode.Code.CodeEntries.Add(tmpReturn); 64 | 65 | var tmpText = tmpReturn.ToString(); 66 | Assert.AreEqual("return this Text getFullName () ", tmpText); 67 | 68 | tmpProject.FillClasses(new List { tmpClass1, tmpClassString }); 69 | 70 | new AnalyzerCore().LinkProjectInformation(tmpProject); 71 | 72 | tmpFullNameMethode.IsProperty = true; 73 | tmpFullNameMethode.Name = "FullName"; 74 | 75 | Assert.AreEqual(tmpFullNameMethode.Name, (((tmpReturn.CodeEntries[0] as VariableAccess).Child as VariableAccess).Access as MethodeCall).Name); 76 | } 77 | } 78 | } -------------------------------------------------------------------------------- /CodeConverterCore_Unittest/CodeConverterCore_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 | -------------------------------------------------------------------------------- /CodeConverterJava/JavaLoader.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterCore.ImportExport; 3 | using CodeConverterCore.Interface; 4 | using CodeConverterCore.Model; 5 | using CodeConverterJava.Resources; 6 | using MoreLinq; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | 11 | namespace CodeConverterJava.Model 12 | { 13 | public class JavaLoader : ILoadOOPLanguage 14 | { 15 | public bool LoadDefaultData { get; set; } = false; 16 | 17 | public ProjectInformation CreateObjectInformation(List inFileContents, IniParser.Model.IniData inConfiguration) 18 | { 19 | var tmpClassList = new List(); 20 | ProjectInformation tmpObjectInformation = new ProjectInformation(); 21 | if (LoadDefaultData) 22 | { 23 | tmpObjectInformation = ProjectInformationHelper.CreateSystemProjectInformation(ImportHelper.ImportClasses(JavaLangClassJson.JavaLang), ImportHelper.ImportAliasList(CompilerAliasHelper.SystemAliasJson), "java.lang"); 24 | } 25 | 26 | foreach (var tmpFile in inFileContents) 27 | { 28 | //tmpClassList.AddRange(JavaClassLoader.LoadFile(tmpFile)); 29 | tmpClassList.AddRange(JavaAntlrClassLoader.LoaderOptimization(tmpFile)); 30 | } 31 | tmpObjectInformation.FillClasses(tmpClassList); 32 | //Add Mapped Methodes to Class List (So we don't need String oä as a Class List 33 | var tmpAdditionalClasses = new List(); 34 | 35 | //Load all Classes, with Methodes we might need 36 | if (inConfiguration != null) 37 | { 38 | foreach (var tmpMap in inConfiguration["Methode"]) 39 | { 40 | var tmpLeftSplit = tmpMap.KeyName.Split('.'); 41 | var tmpNamespace = string.Join(".", tmpLeftSplit.SkipLast(2)); 42 | var tmpName = (TypeContainer)tmpLeftSplit.SkipLast(1).Last(); 43 | var tmpMethodeName = tmpLeftSplit.Last(); 44 | 45 | var tmpClass = tmpAdditionalClasses.FirstOrDefault(inItem => 46 | inItem.Namespace == tmpNamespace && inItem.Type == tmpName); 47 | if (tmpClass == null) 48 | { 49 | tmpClass = new ClassContainer 50 | { 51 | Type = tmpName, 52 | Namespace = tmpNamespace 53 | }; 54 | tmpAdditionalClasses.Add(tmpClass); 55 | } 56 | 57 | if (!tmpClass.MethodeList.Any(inItem => inItem.Name == tmpMethodeName)) 58 | { 59 | //TODO Check for Param Equality 60 | if (tmpClass.MethodeList.Count(inItem => inItem.Name == tmpMethodeName) > 1) 61 | { 62 | throw new NotImplementedException("Methode differenting with params not implemented"); 63 | } 64 | 65 | var tmpNewMethode = new MethodeContainer(); 66 | tmpNewMethode.Name = tmpMethodeName; 67 | tmpNewMethode.ModifierList = new List { "public" }; 68 | tmpClass.MethodeList.Add(tmpNewMethode); 69 | } 70 | } 71 | } 72 | 73 | IResolveMethodeContentToIL tmpCodeHandler = new JavaMethodeCodeResolver(); 74 | foreach (var tmpClass in tmpClassList) 75 | { 76 | foreach (var tmpMethode in tmpClass.MethodeList) 77 | { 78 | tmpCodeHandler.Resolve(tmpMethode); 79 | } 80 | } 81 | 82 | foreach (var tmpClassouter in tmpClassList) 83 | { 84 | foreach (var tmpClass in tmpClassouter.InnerClasses) 85 | { 86 | foreach (var tmpMethode in tmpClass.MethodeList) 87 | { 88 | tmpCodeHandler.Resolve(tmpMethode); 89 | } 90 | } 91 | } 92 | 93 | //Fill them into the object Information 94 | tmpObjectInformation.FillClasses(tmpAdditionalClasses); 95 | return tmpObjectInformation; 96 | } 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /CodeConverterJava/JavaStaticInfo.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using System.Collections.Generic; 3 | 4 | namespace CodeConverterJava.Model 5 | { 6 | public static class JavaStaticInfo 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 | } 49 | -------------------------------------------------------------------------------- /CodeConverterJava/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("CodeConverterJava")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("CodeConverterJava")] 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("863f8c69-dd75-4a95-a8a0-8dc3863857b2")] 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 | -------------------------------------------------------------------------------- /CodeConverterJava/Resources/CompilerAliasHelper.cs: -------------------------------------------------------------------------------- 1 | namespace CodeConverterJava.Resources 2 | { 3 | public static class CompilerAliasHelper 4 | { 5 | public static string SystemAliasJson = @"[ 6 | {'From':'Object','To':'object'}, 7 | {'From':'Integer','To':'int'}, 8 | {'From':'String','To':'string'}, 9 | {'From':'Boolean','To':'boolean'}, 10 | {'From':'True','To':'true'}, 11 | {'From':'False','To':'false'}, 12 | {'From':'Int64','To':'long'}, 13 | {'From':'Float','To':'float'}, 14 | {'From':'Double','To':'double'}, 15 | {'From':'Void','To':'void'}, 16 | ]"; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CodeConverterJava/antlr/IFormalParameterContext.cs: -------------------------------------------------------------------------------- 1 | using static CodeConverterJava.Model.JavaParser; 2 | 3 | namespace CodeConverterJava.Model 4 | { 5 | /// 6 | /// FormalParamContext 7 | /// 8 | public interface IFormalParameterContext 9 | { 10 | TypeTypeContext typeType(); 11 | 12 | VariableDeclaratorIdContext variableDeclaratorId(); 13 | 14 | VariableModifierContext[] variableModifier(); 15 | 16 | VariableModifierContext variableModifier(int i); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /CodeConverterJava/antlr/Interfaces.cs: -------------------------------------------------------------------------------- 1 | using Antlr4.Runtime.Tree; 2 | using static CodeConverterJava.Model.JavaParser; 3 | 4 | namespace CodeConverterCore.Model 5 | { 6 | public interface IClassAndInterfaceBaseData 7 | { 8 | ITerminalNode IDENTIFIER(); 9 | 10 | ITerminalNode EXTENDS(); 11 | 12 | TypeParametersContext typeParameters(); 13 | 14 | TypeListContext typeList(); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /CodeConverterJava/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/AbstractPropertiesMethods_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCore.Model; 5 | using CodeConverterCSharp; 6 | using CodeConverterCSharp.Lucenene; 7 | using CodeConverterJava.Model; 8 | using NUnit.Framework; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | 12 | namespace CodeConverterJavaToCSharp_Unittest 13 | { 14 | public class AbstractPropertiesMethods_Unittest 15 | { 16 | [Test] 17 | public void AbstractMethode() 18 | { 19 | var tmpIniData = DataHelper.LoadIni(""); 20 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { JavaClass }, tmpIniData); 21 | var tmpAnalyerSettings = new AnalyzerSettings(); 22 | var tmpUnknownTypeCounter = 0; 23 | tmpAnalyerSettings.UnknownTypeAdded += (UnknownTypeClass inItem) => { tmpUnknownTypeCounter++; }; 24 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation, tmpAnalyerSettings); 25 | 26 | new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation); 27 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 28 | 29 | Assert.AreEqual(1, tmpResult.Count); 30 | Assert.AreEqual("Bits", tmpResult[0].FullName); 31 | 32 | Assert.AreEqual(CSharpResult1, tmpResult[0].Content); 33 | } 34 | 35 | 36 | private string JavaClass = @"package org.apache.lucene.util; 37 | public abstract class Bits 38 | { 39 | public abstract void AbstrMethode(); 40 | }"; 41 | 42 | private string CSharpResult1 = @" 43 | 44 | namespace LuceNET.util 45 | { 46 | public abstract class Bits 47 | { 48 | public abstract void AbstrMethode(); 49 | } 50 | } 51 | "; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/AssertStatement_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCSharp; 4 | using CodeConverterJava.Model; 5 | using JavaToCSharpConverter.Model; 6 | using NUnit.Framework; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | 10 | namespace CodeConverterJavaToCSharp_Unittest 11 | { 12 | /// 13 | /// Checking Field Write Access 14 | /// 15 | public class AssertStatement_Unittest 16 | { 17 | [Test] 18 | public void SimpleAssert() 19 | { 20 | var tmpClass = @" 21 | package org; 22 | public class Class1 { 23 | public void OneSmallerThanTwo(int in1, int in2){ 24 | assert in1>0; 25 | } 26 | "; 27 | var tmpIniData = DataHelper.LoadIni(""); 28 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 29 | 30 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 31 | 32 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList(); 33 | 34 | var tmpExpectedResult = @" 35 | 36 | namespace org 37 | { 38 | public class Class1 39 | { 40 | public void OneSmallerThanTwo(int in1, int in2) 41 | { 42 | Trace.Assert (in1 > 0); 43 | } 44 | } 45 | } 46 | "; 47 | //Statement IF 48 | Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content); 49 | 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/ConverterGithubExample.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCSharp; 4 | using CodeConverterJava.Model; 5 | using JavaToCSharpConverter.Model; 6 | using NUnit.Framework; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | 10 | namespace CodeConverterJavaToCSharp_Unittest 11 | { 12 | public class ConverterGithubExample 13 | { 14 | [Test] 15 | public void IfWIthConstant() 16 | { 17 | var tmpIniData = DataHelper.LoadIni(""); 18 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { JavaClass }, tmpIniData); 19 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 20 | 21 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList(); 22 | Assert.AreEqual(1, tmpResult.Count); 23 | Assert.AreEqual("Class1", tmpResult[0].FullName); 24 | Assert.AreEqual(CSharpResult1, tmpResult[0].Content); 25 | } 26 | 27 | 28 | private string JavaClass = @" 29 | package org.apache.lucene.util; 30 | 31 | import java.util.Collections; 32 | 33 | public class Class1 { 34 | private string Value; 35 | public Class1 CreateInstance(){ 36 | return null; 37 | } 38 | public void SetValue(string inValue){ 39 | Value=inValue; 40 | } 41 | }}"; 42 | 43 | private string CSharpResult1 = @"using java.util.Collections; 44 | 45 | namespace org.apache.lucene.util 46 | { 47 | public class Class1 48 | { 49 | private string Value; 50 | 51 | public Class1 CreateInstance() 52 | { 53 | return null; 54 | } 55 | 56 | public void SetValue(string inValue) 57 | { 58 | Value = inValue; 59 | } 60 | } 61 | } 62 | "; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/ElvisOperator_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Enum; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCore.Model; 5 | using CodeConverterCSharp; 6 | using CodeConverterJava.Model; 7 | using JavaToCSharpConverter.Model; 8 | using NUnit.Framework; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | 12 | namespace CodeConverterJavaToCSharp_Unittest 13 | { 14 | /// 15 | /// Checking Field Write Access 16 | /// 17 | public class ElvisOperator_Unittest 18 | { 19 | [Test] 20 | public void SimpleReturnElvis() 21 | { 22 | var tmpClass = @" 23 | package org; 24 | public class Class1 { 25 | public void OneSmallerThanTwo(bool inFirst,int in1, int in2){ 26 | return inFirst? in1:in2; 27 | } 28 | "; 29 | var tmpIniData = DataHelper.LoadIni(""); 30 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 31 | 32 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 33 | 34 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList(); 35 | 36 | var tmpExpectedResult = @" 37 | 38 | namespace org 39 | { 40 | public class Class1 41 | { 42 | public void OneSmallerThanTwo(bool inFirst, int in1, int in2) 43 | { 44 | return inFirst ? in1 : in2; 45 | } 46 | } 47 | } 48 | "; 49 | //Check Elvis Result 50 | Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/ForStatement_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 CodeConverterCSharp.Lucenene; 8 | using CodeConverterJava.Model; 9 | using JavaToCSharpConverter.Model; 10 | using NUnit.Framework; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | 14 | namespace CodeConverterJavaToCSharp_Unittest 15 | { 16 | /// 17 | /// Checking Field Write Access 18 | /// 19 | public class ForStatement_Unittest 20 | { 21 | [Test] 22 | public void SimpleFor() 23 | { 24 | var tmpClass = @" 25 | package org; 26 | public class Class1 { 27 | public void forIInLength(int len){ 28 | for(int i=0;i { tmpClass }, tmpIniData); 36 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 37 | 38 | new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation); 39 | 40 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()) 41 | .ToList() 42 | .Last(); 43 | 44 | var tmpExpectedResult = @" 45 | 46 | namespace org 47 | { 48 | public class Class1 49 | { 50 | public void ForIInLength(int inLen) 51 | { 52 | for (int i = 0;(i < inLen);i++) 53 | { 54 | i--; 55 | } 56 | return false; 57 | } 58 | } 59 | } 60 | "; 61 | //Check Elvis Result 62 | Assert.AreEqual(tmpExpectedResult, tmpResult.Content); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/GenericClassReplace_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCore.ImportExport; 5 | using CodeConverterCore.Model; 6 | using CodeConverterCSharp; 7 | using CodeConverterCSharp.Lucenene; 8 | using CodeConverterJava.Model; 9 | using JavaToCSharpConverter.Resources; 10 | using NUnit.Framework; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | 14 | namespace CodeConverterJavaToCSharp_Unittest 15 | { 16 | public class GenericClassReplace_Unittest 17 | { 18 | [Test] 19 | public void SingleGenericClassReplace() 20 | { 21 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun( 22 | ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, 23 | SingleReplacement); 24 | 25 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last(); 26 | 27 | Assert.AreEqual("Bits", tmpResult.FullName); 28 | 29 | Assert.AreEqual(CSharpResultSingle, tmpResult.Content); 30 | } 31 | 32 | 33 | private string SingleReplacement = @"package org.apache.lucene.util; 34 | public abstract class Bits 35 | { 36 | public abstract void AbstrMethode(){ 37 | Class c1 = this.getClass(); 38 | } 39 | }"; 40 | 41 | private string CSharpResultSingle = @"using System; 42 | 43 | namespace LuceNET.util 44 | { 45 | public abstract class Bits 46 | { 47 | public void AbstrMethode() 48 | { 49 | Type c1 = this.GetType(); 50 | } 51 | } 52 | } 53 | "; 54 | 55 | [Test] 56 | public void DoubleGenericClassReplace() 57 | { 58 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun( 59 | ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, 60 | DoubleReplacement); 61 | 62 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last(); 63 | 64 | Assert.AreEqual("Bits", tmpResult.FullName); 65 | 66 | Assert.AreEqual(CSharpResultDouble, tmpResult.Content); 67 | } 68 | 69 | private string DoubleReplacement = @"package org.apache.lucene.util; 70 | public abstract class Bits 71 | { 72 | public abstract void AbstrMethode(Bits other){ 73 | Class c1 = this.getClass(); 74 | Class c2 = other.getClass(); 75 | } 76 | }"; 77 | 78 | 79 | private string CSharpResultDouble = @"using System; 80 | 81 | namespace LuceNET.util 82 | { 83 | public abstract class Bits 84 | { 85 | public void AbstrMethode(Bits inOther) 86 | { 87 | Type c1 = this.GetType(); 88 | Type c2 = inOther.GetType(); 89 | } 90 | } 91 | } 92 | "; 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/InplaceClassCreation_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCSharp; 5 | using CodeConverterCSharp.Lucenene; 6 | using CodeConverterJava.Model; 7 | using JavaToCSharpConverter.Model; 8 | using NUnit.Framework; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | 12 | namespace CodeConverterJavaToCSharp_Unittest 13 | { 14 | /// 15 | /// Checking Field Write Access 16 | /// 17 | public class InplaceClassCreation_Unittest 18 | { 19 | [Test] 20 | public void ClassCreationWithOveride() 21 | { 22 | var tmpClass = @"public abstract class LongValues { 23 | 24 | /** Get value at index. */ 25 | public abstract long get(long index); 26 | 27 | /** An instance that returns the provided value. */ 28 | public static final LongValues IDENTITY = new LongValues() { 29 | 30 | @Override 31 | public long get(long index) { 32 | return index; 33 | } 34 | }; 35 | }"; 36 | var tmpIniData = DataHelper.LoadIni(""); 37 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 38 | 39 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 40 | new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation); 41 | 42 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList(); 43 | 44 | var tmpExpectedResult = @" 45 | 46 | namespace 47 | { 48 | public abstract class LongValues 49 | { 50 | /// 51 | /// An instance that returns the provided value. 52 | /// 53 | public readonly static LongValues IDENTITY = new LongValues_0(); 54 | 55 | public abstract long Get(long inIndex); 56 | public class LongValues_0 : LongValues 57 | { 58 | public override long Get(long inIndex) 59 | { 60 | return inIndex; 61 | } 62 | } 63 | } 64 | } 65 | "; 66 | //Check Elvis Result 67 | Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/JavaClassMapping_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCore.ImportExport; 5 | using CodeConverterCore.Model; 6 | using CodeConverterCSharp; 7 | using CodeConverterCSharp.Lucenene; 8 | using CodeConverterJava.Model; 9 | using JavaToCSharpConverter.Resources; 10 | using NUnit.Framework; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | 14 | namespace CodeConverterJavaToCSharp_Unittest 15 | { 16 | public class JavaClassMapping_Unittest 17 | { 18 | [Test] 19 | public void PropertyInInterfaceWithDefaultValue() 20 | { 21 | var tmpAnalyerSettings = new AnalyzerSettings(); 22 | 23 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, JavaClass); 24 | 25 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()) 26 | .Where(inItem=> inItem.FullName == "MutableValue") 27 | .ToList(); 28 | 29 | Assert.AreEqual(1, tmpResult.Count); 30 | Assert.AreEqual("MutableValue", tmpResult[0].FullName); 31 | 32 | Assert.AreEqual(CSharpResult1, tmpResult[0].Content); 33 | } 34 | 35 | 36 | private string JavaClass = @"package java.lang; 37 | public abstract class MutableValue 38 | { 39 | public int compareTo(MutableValue other) { 40 | Class c1 = other.getClass(); 41 | } 42 | }"; 43 | 44 | private string CSharpResult1 = @"using System; 45 | 46 | namespace System 47 | { 48 | public class MutableValue 49 | { 50 | public int CompareTo(MutableValue inOther) 51 | { 52 | Type c1 = inOther.GetType(); 53 | } 54 | } 55 | } 56 | "; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/NewObjectParamCall_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCSharp; 4 | using CodeConverterJava.Model; 5 | using JavaToCSharpConverter.Model; 6 | using NUnit.Framework; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | 10 | namespace CodeConverterJavaToCSharp_Unittest 11 | { 12 | /// 13 | /// Checking Field Write Access 14 | /// 15 | public class NewObjectParamCall_Unittest 16 | { 17 | [Test] 18 | public void SimpleReturnNewObject() 19 | { 20 | var tmpClass = @" 21 | package org; 22 | public class Class1 { 23 | public void OneSmallerThanTwo(bool inFirst,int in1, int in2){ 24 | return new Date(in1); 25 | } 26 | "; 27 | var tmpIniData = DataHelper.LoadIni(""); 28 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 29 | 30 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 31 | 32 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList(); 33 | 34 | var tmpExpectedResult = @" 35 | 36 | namespace org 37 | { 38 | public class Class1 39 | { 40 | public void OneSmallerThanTwo(bool inFirst, int in1, int in2) 41 | { 42 | return new Date(in1); 43 | } 44 | } 45 | } 46 | "; 47 | //Check Elvis Result 48 | Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content); 49 | } 50 | [Test] 51 | public void SetVariableTonewObject() 52 | { 53 | var tmpClass = @" 54 | package org; 55 | public class Class1 { 56 | public void OneSmallerThanTwo(bool inFirst,int in1, int in2){ 57 | var b= new Date(in1); 58 | } 59 | "; 60 | var tmpIniData = DataHelper.LoadIni(""); 61 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 62 | 63 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 64 | 65 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList(); 66 | 67 | var tmpExpectedResult = @" 68 | 69 | namespace org 70 | { 71 | public class Class1 72 | { 73 | public void OneSmallerThanTwo(bool inFirst, int in1, int in2) 74 | { 75 | var b = new Date(in1); 76 | } 77 | } 78 | } 79 | "; 80 | //Check Elvis Result 81 | Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content); 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/ObjectMethodeCallReplace_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCore.ImportExport; 5 | using CodeConverterCSharp; 6 | using CodeConverterCSharp.Lucenene; 7 | using CodeConverterJava.Model; 8 | using JavaToCSharpConverter.Resources; 9 | using NUnit.Framework; 10 | using System.Collections.Generic; 11 | using System.Linq; 12 | using System.Text.RegularExpressions; 13 | 14 | namespace CodeConverterJavaToCSharp_Unittest.LuceneTests 15 | { 16 | 17 | public class ObjectMethodeCallReplace_Unittest 18 | { 19 | [Test] 20 | public void CheckMitableValueCompareTo() 21 | { 22 | 23 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun( 24 | ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, 25 | CompareToString); 26 | 27 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last(); 28 | 29 | Assert.AreEqual("MutableValue", tmpResult.FullName); 30 | 31 | Assert.AreEqual(true, tmpResult.Content.Contains("Type c1 = this.GetType()")); 32 | Assert.AreEqual(true, tmpResult.Content.Contains(" - c2.GetHashCode()")); 33 | } 34 | 35 | private string CompareToString = @" 36 | package org.apache.lucene.util.mutable; 37 | 38 | public abstract class MutableValue implements Comparable { 39 | 40 | public void compareTo(MutableValue other) 41 | { 42 | Class c1 = this.getClass(); 43 | Class c2 = other.getClass(); 44 | int c = c1.hashCode() -c2.hashCode(); 45 | } 46 | }"; 47 | 48 | [Test] 49 | public void CheckMitableValueEquals() 50 | { 51 | 52 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun( 53 | ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, 54 | EqualsString); 55 | 56 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last(); 57 | 58 | Assert.AreEqual("MutableValue", tmpResult.FullName); 59 | 60 | Assert.AreEqual(true, tmpResult.Content.Contains(" return ((GetType() == inOther.GetType()) && this.equalsSameType(inOther));")); 61 | } 62 | 63 | private string EqualsString = @" 64 | package org.apache.lucene.util.mutable; 65 | 66 | public abstract class MutableValue implements Comparable { 67 | 68 | @Override 69 | public boolean equals(Object other) { 70 | return (getClass() == other.getClass()) && this.equalsSameType(other); 71 | } 72 | }"; 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/PropertyWithDefaultValue_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCore.Model; 5 | using CodeConverterCSharp; 6 | using CodeConverterCSharp.Lucenene; 7 | using CodeConverterJava.Model; 8 | using NUnit.Framework; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | 12 | namespace CodeConverterJavaToCSharp_Unittest 13 | { 14 | public class PropertyWithDefaultValue_Unittest 15 | { 16 | [Test] 17 | public void PropertyInInterfaceWithDefaultValue() 18 | { 19 | var tmpIniData = DataHelper.LoadIni(""); 20 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { JavaClass }, tmpIniData); 21 | var tmpAnalyerSettings = new AnalyzerSettings(); 22 | var tmpUnknownTypeCounter = 0; 23 | tmpAnalyerSettings.UnknownTypeAdded += (UnknownTypeClass inItem) => { tmpUnknownTypeCounter++; }; 24 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation, tmpAnalyerSettings); 25 | 26 | new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation); 27 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 28 | 29 | Assert.AreEqual(1, tmpResult.Count); 30 | Assert.AreEqual("Bits", tmpResult[0].FullName); 31 | 32 | Assert.AreEqual(CSharpResult1, tmpResult[0].Content); 33 | } 34 | 35 | 36 | private string JavaClass = @"package org.apache.lucene.util; 37 | public interface Bits 38 | { 39 | Bits[] EMPTY_ARRAY = new Bits[0]; 40 | }"; 41 | 42 | private string CSharpResult1 = @" 43 | 44 | namespace LuceNET.util 45 | { 46 | public interface Bits 47 | { 48 | Bits[] EMPTY_ARRAY = new Bits[0]; 49 | 50 | } 51 | } 52 | "; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/SystemMerging_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterCore.ImportExport; 3 | using CodeConverterCSharp; 4 | using CodeConverterCSharp.Lucenene; 5 | using CodeConverterJava.Model; 6 | using JavaToCSharpConverter.Resources; 7 | using NUnit.Framework; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | 11 | namespace CodeConverterJavaToCSharp_Unittest 12 | { 13 | /// 14 | /// Checking Field Write Access 15 | /// 16 | public class SystemMerging_Unittest 17 | { 18 | [Test] 19 | public void SuperCallModifiedToBase() 20 | { 21 | var tmpClass = @" 22 | package org; 23 | public final class ThreadInterruptedException extends RuntimeException { 24 | public ThreadInterruptedException(InterruptedException ie) { 25 | super(ie); 26 | }}"; 27 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, tmpClass); 28 | 29 | var tmpMethodeContent = tmpObjectInformation.ClassList.Last().MethodeList[0]; 30 | Assert.AreEqual("base", tmpMethodeContent.ConstructorCall.Name); 31 | } 32 | 33 | [Test] 34 | public void SuperCallModifiedToBaseToCSharp() 35 | { 36 | var tmpClass = @" 37 | package org; 38 | public final class ThreadInterruptedException extends RuntimeException { 39 | public ThreadInterruptedException(InterruptedException ie) { 40 | super(ie); 41 | }}"; 42 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, tmpClass); 43 | 44 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 45 | 46 | var tmpExpectedResult = @"using System; 47 | 48 | namespace org 49 | { 50 | public sealed class ThreadInterruptedException : RuntimeException 51 | { 52 | public ThreadInterruptedException(InterruptedException inIe) 53 | :base(inIe) 54 | { 55 | } 56 | } 57 | } 58 | "; 59 | var tmpResultText = tmpResult.Last().Content; 60 | Assert.AreEqual(tmpExpectedResult, tmpResultText); 61 | } 62 | 63 | [Test] 64 | public void Test() 65 | { 66 | var tmpClass = @" 67 | package java.lang; 68 | public class Collection{ 69 | }"; 70 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, tmpClass); 71 | 72 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 73 | 74 | ///Write to JSON to add additional Java Base Classes 75 | var b= ExportHelper.CreateJsonFromClassList(tmpObjectInformation.ClassList.Where(inItem=> inItem.ClassType == CodeConverterCore.Enum.ClassTypeEnum.Normal).ToList()); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/TertiaerReturn_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterCore.ImportExport; 3 | using CodeConverterCore.Model; 4 | using CodeConverterCSharp; 5 | using CodeConverterCSharp.Lucenene; 6 | using CodeConverterJava.Model; 7 | using JavaToCSharpConverter.Resources; 8 | using NUnit.Framework; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | 12 | namespace CodeConverterJavaToCSharp_Unittest 13 | { 14 | /// 15 | /// Checking Field Write Access 16 | /// 17 | public class TertiaerReturn_Unittest 18 | { 19 | [Test] 20 | public void SimpleSingleTypeConversionExplizitWithCSharpWrite() 21 | { 22 | var tmpClass = @" 23 | package java.lang; 24 | public abstract class Class1 { 25 | public abstract boolean exists(); 26 | public abstract object toObject(); 27 | @Override 28 | public String toString() { 29 | return exists() ? toObject().toString() : ""(null)""; 30 | } 31 | } 32 | "; 33 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, tmpClass); 34 | 35 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last(); 36 | 37 | var tmpExpectedResult = @"using System; 38 | 39 | namespace System 40 | { 41 | public abstract class Class1 42 | { 43 | public abstract bool Exists(); 44 | 45 | public abstract object ToObject(); 46 | 47 | public override String ToString() 48 | { 49 | return Exists() ? ToObject().ToString() : ""(null)""; 50 | } 51 | } 52 | } 53 | "; 54 | Assert.AreEqual(tmpExpectedResult, tmpResult.Content); 55 | } 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/TypeConvertion_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterCore.ImportExport; 3 | using CodeConverterCore.Model; 4 | using CodeConverterCSharp; 5 | using CodeConverterCSharp.Lucenene; 6 | using CodeConverterJava.Model; 7 | using JavaToCSharpConverter.Resources; 8 | using NUnit.Framework; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | 12 | namespace CodeConverterJavaToCSharp_Unittest 13 | { 14 | /// 15 | /// Checking Field Write Access 16 | /// 17 | public class TypeConvertion_Unittest 18 | { 19 | [Test] 20 | public void SimpleSingleTypeConversionExplizit() 21 | { 22 | var tmpClass = @" 23 | package java.lang; 24 | public class Class1 { 25 | public void Run(object value){ 26 | var tmpValue=(String)value; 27 | } 28 | } 29 | "; 30 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, tmpClass); 31 | 32 | var tmpMethodeContent = tmpObjectInformation.ClassList.Last().MethodeList[0]; 33 | 34 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0] as VariableDeclaration); 35 | Assert.AreEqual("tmpValue", tmpCodeLine1.Name); 36 | 37 | var tmpFirstConversion = tmpMethodeContent.Code.CodeEntries[1] as TypeConversion; 38 | Assert.AreEqual("String", tmpFirstConversion.Type.ToString()); 39 | Assert.AreEqual("inValue", ((tmpFirstConversion.PreconversionValue.CodeEntries[0] as ConstantValue).Value as FieldContainer).Name); 40 | } 41 | 42 | [Test] 43 | public void SimpleSingleTypeConversionExplizitWithCSharpWrite() 44 | { 45 | var tmpClass = @" 46 | package java.lang; 47 | public class Class1 { 48 | public void Run(object value){ 49 | var tmpValue=(String)value; 50 | } 51 | } 52 | "; 53 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, tmpClass); 54 | 55 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 56 | 57 | var tmpExpectedResult = @"using System; 58 | 59 | namespace System 60 | { 61 | public class Class1 62 | { 63 | public void Run(object inValue) 64 | { 65 | var tmpValue = (String)inValue; 66 | } 67 | } 68 | } 69 | "; 70 | Assert.AreEqual(tmpExpectedResult, tmpResult.Last().Content); 71 | } 72 | 73 | [Test] 74 | public void DoubleConversionExplizit() 75 | { 76 | var tmpClass = @" 77 | package java.lang; 78 | public class Class1 { 79 | public void Run(object value){ 80 | var tmpValue=(Int32)(String)value; 81 | } 82 | } 83 | "; 84 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader() { LoadDefaultData = true }, tmpClass); 85 | 86 | 87 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 88 | 89 | var tmpExpectedResult = @"using System; 90 | 91 | namespace System 92 | { 93 | public class Class1 94 | { 95 | public void Run(object inValue) 96 | { 97 | var tmpValue = (Int32)(String)inValue; 98 | } 99 | } 100 | } 101 | "; 102 | Assert.AreEqual(tmpExpectedResult, tmpResult.Last().Content); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/BaseTests/WhileStatement_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 CodeConverterCSharp.Lucenene; 8 | using CodeConverterJava.Model; 9 | using JavaToCSharpConverter.Model; 10 | using NUnit.Framework; 11 | using System.Collections.Generic; 12 | using System.Linq; 13 | 14 | namespace CodeConverterJavaToCSharp_Unittest 15 | { 16 | /// 17 | /// Checking Field Write Access 18 | /// 19 | public class WhileStatement_Unittest 20 | { 21 | [Test] 22 | public void SimpleWhile() 23 | { 24 | var tmpClass = @" 25 | package org; 26 | public class Class1 { 27 | public void OneSmallerThanTwo(){ 28 | while(true){ 29 | return true; 30 | } 31 | } 32 | } 33 | "; 34 | var tmpIniData = DataHelper.LoadIni(""); 35 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 36 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 37 | 38 | new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation); 39 | 40 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()) 41 | .ToList() 42 | .Last(); 43 | 44 | var tmpExpectedResult = @" 45 | 46 | namespace org 47 | { 48 | public class Class1 49 | { 50 | public void OneSmallerThanTwo() 51 | { 52 | while (true) 53 | { 54 | return true; 55 | } 56 | } 57 | } 58 | } 59 | "; 60 | //Check Elvis Result 61 | Assert.AreEqual(tmpExpectedResult, tmpResult.Content); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/CodeConverterJavaToCSharp_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 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/LuceneTests/Accountable_Interface_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCSharp; 5 | using CodeConverterCSharp.Lucenene; 6 | using CodeConverterJava.Model; 7 | using NUnit.Framework; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text.RegularExpressions; 11 | 12 | namespace CodeConverterJavaToCSharp_Unittest.LuceneTests 13 | { 14 | class Accountable_Interface_Unittest 15 | { 16 | [Test] 17 | public void CheckAccountableInterfaceComments() 18 | { 19 | var tmpIniData = DataHelper.LoadIni(""); 20 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { JavaBits }, tmpIniData); 21 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 22 | 23 | new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation); 24 | 25 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 26 | 27 | Assert.AreEqual(1, tmpResult.Count); 28 | Assert.AreEqual("Accountable", tmpResult[0].FullName); 29 | //Check for no double Comments 30 | Assert.AreEqual(false, tmpResult[0].Content.Contains("/*/*")); 31 | //Check for no double Comments 32 | int tmpCommentLineCount = new Regex(Regex.Escape("///")).Matches(tmpResult[0].Content).Count; 33 | Assert.AreEqual(29, tmpCommentLineCount); 34 | 35 | Assert.AreEqual(true, tmpResult[0].Content.Contains("Collections.emptyList();")); 36 | Assert.AreEqual(true, tmpResult[0].Content.Contains("public Collection")); 37 | } 38 | 39 | private string JavaBits = @"/* 40 | * Licensed to the Apache Software Foundation (ASF) under one or more 41 | * contributor license agreements. See the NOTICE file distributed with 42 | * this work for additional information regarding copyright ownership. 43 | * The ASF licenses this file to You under the Apache License, Version 2.0 44 | * (the ""License""); you may not use this file except in compliance with 45 | * the License.You may obtain a copy of the License at 46 | * 47 | * http://www.apache.org/licenses/LICENSE-2.0 48 | * 49 | * Unless required by applicable law or agreed to in writing, software 50 | * distributed under the License is distributed on an ""AS IS"" BASIS, 51 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 52 | * See the License for the specific language governing permissions and 53 | * limitations under the License. 54 | */ 55 | package org.apache.lucene.util; 56 | 57 | 58 | import java.util.Collection; 59 | import java.util.Collections; 60 | 61 | /** 62 | * An object whose RAM usage can be computed. 63 | * 64 | * @lucene.internal 65 | */ 66 | public interface Accountable 67 | { 68 | 69 | /** 70 | * Return the memory usage of this object in bytes. Negative values are illegal. 71 | */ 72 | long ramBytesUsed(); 73 | 74 | /** 75 | * Returns nested resources of this class. 76 | * The result should be a point-in-time snapshot (to avoid race conditions). 77 | * @see Accountables 78 | */ 79 | default Collection getChildResources() 80 | { 81 | return Collections.emptyList(); 82 | } 83 | 84 | } 85 | "; 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/LuceneTests/Attribute_Interface_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCSharp; 5 | using CodeConverterCSharp.Lucenene; 6 | using CodeConverterJava.Model; 7 | using JavaToCSharpConverter.Model; 8 | using NUnit.Framework; 9 | using System.Collections.Generic; 10 | using System.Linq; 11 | using System.Text.RegularExpressions; 12 | 13 | namespace CodeConverterJavaToCSharp_Unittest.LuceneTests 14 | { 15 | public class Attribute_Interface_Unittest 16 | { 17 | [Test] 18 | public void CheckAttributeInterfaceComments() 19 | { 20 | var tmpIniData = DataHelper.LoadIni(""); 21 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { JavaBits }, tmpIniData); 22 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 23 | 24 | new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation); 25 | 26 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 27 | Assert.AreEqual(1, tmpResult.Count); 28 | Assert.AreEqual("Attribute", tmpResult[0].FullName); 29 | //Check for no double Comments 30 | Assert.AreEqual(false, tmpResult[0].Content.Contains("/*/*")); 31 | //Check for no double Comments 32 | int tmpCommentLineCount = new Regex(Regex.Escape("///")).Matches(tmpResult[0].Content).Count; 33 | Assert.AreEqual(19, tmpCommentLineCount); 34 | } 35 | 36 | private string JavaBits = @"/* 37 | * Licensed to the Apache Software Foundation (ASF) under one or more 38 | * contributor license agreements. See the NOTICE file distributed with 39 | * this work for additional information regarding copyright ownership. 40 | * The ASF licenses this file to You under the Apache License, Version 2.0 41 | * (the ""License""); you may not use this file except in compliance with 42 | * the License.You may obtain a copy of the License at 43 | * 44 | * http://www.apache.org/licenses/LICENSE-2.0 45 | * 46 | * Unless required by applicable law or agreed to in writing, software 47 | * distributed under the License is distributed on an ""AS IS"" BASIS, 48 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 49 | * See the License for the specific language governing permissions and 50 | * limitations under the License. 51 | */ 52 | package org.apache.lucene.util; 53 | 54 | /** 55 | * Base interface for attributes. 56 | */ 57 | public interface Attribute 58 | { 59 | }"; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /CodeConverterJavaToCSharp_Unittest/LuceneTests/LongValues_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Converter; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCSharp; 5 | using CodeConverterCSharp.Lucenene; 6 | using CodeConverterJava.Model; 7 | using NUnit.Framework; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | using System.Text.RegularExpressions; 11 | 12 | namespace CodeConverterJavaToCSharp_Unittest.LuceneTests 13 | { 14 | // public abstract class LongValues 15 | // { 16 | 17 | 18 | // /** Get value at index. */ 19 | // public abstract long get(long index); 20 | 21 | // /** An instance that returns the provided value. */ 22 | // public static LongValues IDENTITY = new LongValues() 23 | // { 24 | 25 | // public override long get(long index) 26 | // { 27 | // return index; 28 | // } 29 | 30 | // }; 31 | 32 | // public static LongValues ZEROES = new LongValues() 33 | // { 34 | 35 | 36 | 37 | // public override long get(long index) 38 | // { 39 | // return 0; 40 | // } 41 | 42 | //}; 43 | // } 44 | 45 | class LongValues_Unittest 46 | { 47 | [Test] 48 | public void CheckAccountableInterfaceComments() 49 | { 50 | var tmpIniData = DataHelper.LoadIni(""); 51 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { JavaBits }, tmpIniData); 52 | new AnalyzerCore().LinkProjectInformation(tmpObjectInformation); 53 | 54 | new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation); 55 | 56 | var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList(); 57 | 58 | Assert.AreEqual(1, tmpResult.Count); 59 | Assert.AreEqual("Accountable", tmpResult[0].FullName); 60 | //Check for no double Comments 61 | Assert.AreEqual(false, tmpResult[0].Content.Contains("/*/*")); 62 | //Check for no double Comments 63 | int tmpCommentLineCount = new Regex(Regex.Escape("///")).Matches(tmpResult[0].Content).Count; 64 | Assert.AreEqual(29, tmpCommentLineCount); 65 | 66 | Assert.AreEqual(true, tmpResult[0].Content.Contains("Collections.emptyList();")); 67 | Assert.AreEqual(true, tmpResult[0].Content.Contains("public Collection")); 68 | } 69 | 70 | private string JavaBits = @"/* 71 | * Licensed to the Apache Software Foundation (ASF) under one or more 72 | * contributor license agreements. See the NOTICE file distributed with 73 | * this work for additional information regarding copyright ownership. 74 | * The ASF licenses this file to You under the Apache License, Version 2.0 75 | * (the ""License""); you may not use this file except in compliance with 76 | * the License.You may obtain a copy of the License at 77 | * 78 | * http://www.apache.org/licenses/LICENSE-2.0 79 | * 80 | * Unless required by applicable law or agreed to in writing, software 81 | * distributed under the License is distributed on an ""AS IS"" BASIS, 82 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 83 | * See the License for the specific language governing permissions and 84 | * limitations under the License. 85 | */ 86 | package org.apache.lucene.util; 87 | 88 | 89 | import java.util.Collection; 90 | import java.util.Collections; 91 | 92 | /** 93 | * An object whose RAM usage can be computed. 94 | * 95 | * @lucene.internal 96 | */ 97 | public interface Accountable 98 | { 99 | 100 | /** 101 | * Return the memory usage of this object in bytes. Negative values are illegal. 102 | */ 103 | long ramBytesUsed(); 104 | 105 | /** 106 | * Returns nested resources of this class. 107 | * The result should be a point-in-time snapshot (to avoid race conditions). 108 | * @see Accountables 109 | */ 110 | default Collection getChildResources() 111 | { 112 | return Collections.emptyList(); 113 | } 114 | 115 | } 116 | "; 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/CodeConverterJava_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 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/AssertStatement_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using CodeConverterJava.Model; 5 | using NUnit.Framework; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterJava_Unittest.Methode 9 | { 10 | /// 11 | /// Checking Field Write Access 12 | /// 13 | public class AssertStatement_Unittest 14 | { 15 | [Test] 16 | public void SimpleAssert() 17 | { 18 | var tmpClass = @" 19 | package org; 20 | public class Class1 { 21 | public void OneSmallerThanTwo(int in1, int in2){ 22 | assert in1>0; 23 | } 24 | "; 25 | var tmpIniData = DataHelper.LoadIni(""); 26 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 27 | 28 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 29 | var tmpStatement = (tmpMethodeContent.Code.CodeEntries[0]) as StatementCode; 30 | 31 | //Statement IF 32 | Assert.AreEqual(StatementTypeEnum.Assert, tmpStatement.StatementType); 33 | 34 | Assert.AreNotEqual(null, tmpStatement.StatementCodeBlocks[0]); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/BitShifting_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using CodeConverterJava.Model; 5 | using NUnit.Framework; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterJava_Unittest.Methode 9 | { 10 | /// 11 | /// Checking Field Write Access 12 | /// 13 | public class BitShifting_Unittest 14 | { 15 | [Test] 16 | public void ShiftBits() 17 | { 18 | var tmpClass = @" 19 | package org; 20 | public class Class1 { 21 | public void Run(){ 22 | return (int)(value>>32); 23 | } 24 | } 25 | "; 26 | var tmpIniData = DataHelper.LoadIni(""); 27 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 28 | 29 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 30 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0] as ReturnCodeEntry).CodeEntries[0] as TypeConversion; 31 | var tmpExpr = (tmpCodeLine1.PreconversionValue.CodeEntries[0] as CodeBlockContainer).InnerBlock.CodeEntries[0] as CodeExpression; 32 | Assert.AreEqual(VariableOperatorType.BitShiftRight, tmpExpr.Manipulator); 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/ElvisOperator_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using CodeConverterJava.Model; 5 | using NUnit.Framework; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterJava_Unittest.Methode 9 | { 10 | /// 11 | /// Checking Field Write Access 12 | /// 13 | public class ElvisOperator_Unittest 14 | { 15 | [Test] 16 | public void SimpleReturnElvis() 17 | { 18 | var tmpClass = @" 19 | package org; 20 | public class Class1 { 21 | public void OneSmallerThanTwo(bool inFirst,int in1, int in2){ 22 | return inFirst? in1:in2; 23 | } 24 | "; 25 | var tmpIniData = DataHelper.LoadIni(""); 26 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 27 | 28 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 29 | var tmpStatement = ((tmpMethodeContent.Code.CodeEntries[0]) as ReturnCodeEntry).CodeEntries[0] as StatementCode; 30 | 31 | //Statement Elvis 32 | Assert.AreEqual(StatementTypeEnum.Elvis, tmpStatement.StatementType); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/ForStatement_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using CodeConverterJava.Model; 5 | using NUnit.Framework; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterJava_Unittest.Methode 9 | { 10 | /// 11 | /// Checking Field Write Access 12 | /// 13 | public class ForStatement_Unittest 14 | { 15 | [Test] 16 | public void SimpleFor() 17 | { 18 | var tmpClass = @" 19 | package org; 20 | public class Class1 { 21 | public void forIInLength(int len){ 22 | for(int i=0;i { tmpClass }, tmpIniData); 30 | 31 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 32 | var tmpStatement = (tmpMethodeContent.Code.CodeEntries[0]) as StatementCode; 33 | 34 | //Statement IF 35 | Assert.AreEqual(StatementTypeEnum.For, tmpStatement.StatementType); 36 | 37 | //Inner Content (return true); 38 | Assert.AreEqual(VariableOperatorType.MinusMinus, (tmpStatement.InnerContent.CodeEntries[0] as CodeExpression).Manipulator); 39 | 40 | //Inner Content (return true); 41 | Assert.AreEqual(VariableOperatorType.PlusPlus, (tmpStatement.StatementCodeBlocks[2].CodeEntries[0] as CodeExpression).Manipulator); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/InplaceClassCreation_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterJava.Model; 3 | using NUnit.Framework; 4 | using System.Collections.Generic; 5 | 6 | namespace CodeConverterJava_Unittest.Methode 7 | { 8 | /// 9 | /// Checking Field Write Access 10 | /// 11 | public class InplaceClassCreation_Unittest 12 | { 13 | [Test] 14 | public void ClassCreationWithOveride() 15 | { 16 | var tmpClass = @"public abstract class LongValues { 17 | 18 | /** Get value at index. */ 19 | public abstract long get(long index); 20 | 21 | /** An instance that returns the provided value. */ 22 | public static final LongValues IDENTITY = new LongValues() { 23 | 24 | @Override 25 | public long get(long index) { 26 | return index; 27 | } 28 | }; 29 | }"; 30 | var tmpIniData = DataHelper.LoadIni(""); 31 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 32 | 33 | var tmpInnerClassMethode = tmpObjectInformation.ClassList[0].InnerClasses[0].MethodeList[0]; 34 | 35 | //Statement Elvis 36 | Assert.AreEqual("get", tmpInnerClassMethode.Name); 37 | Assert.AreEqual("LongValues_0", tmpObjectInformation.ClassList[0].InnerClasses[0].Name); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/MethodeCall_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using CodeConverterJava.Model; 5 | using NUnit.Framework; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterJava_Unittest.Methode 9 | { 10 | /// 11 | /// Checking Field Write Access 12 | /// 13 | public class MethodeCall_Unittest 14 | { 15 | [Test] 16 | public void CallFunctionWithoutParameter() 17 | { 18 | var tmpClass = @" 19 | package org; 20 | public class Class1 { 21 | public void Run(){ 22 | Run(); 23 | } 24 | } 25 | "; 26 | var tmpIniData = DataHelper.LoadIni(""); 27 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 28 | 29 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 30 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0]) as MethodeCall; 31 | Assert.AreEqual("Run", tmpCodeLine1.Name); 32 | } 33 | 34 | [Test] 35 | public void CallFunctionWithParameter() 36 | { 37 | var tmpClass = @" 38 | package org; 39 | public class Class1 { 40 | public void Run(string inData){ 41 | Run(inData); 42 | } 43 | } 44 | "; 45 | var tmpIniData = DataHelper.LoadIni(""); 46 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 47 | 48 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 49 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0] as MethodeCall); 50 | Assert.AreEqual("Run", tmpCodeLine1.Name); 51 | var tmpEntry = tmpCodeLine1.Parameter[0].CodeEntries[0] as ConstantValue; 52 | Assert.AreEqual("inData", tmpEntry.Value); 53 | } 54 | 55 | [Test] 56 | public void CallFunctionWithThisParameter() 57 | { 58 | var tmpClass = @" 59 | package org; 60 | public class Class1 { 61 | public void Run(){ 62 | this.Run(); 63 | } 64 | } 65 | "; 66 | var tmpIniData = DataHelper.LoadIni(""); 67 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 68 | 69 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 70 | var tmpVarAccess = (tmpMethodeContent.Code.CodeEntries[0]) as VariableAccess; 71 | Assert.AreEqual("this", (tmpVarAccess.Access as ConstantValue).Value); 72 | var tmpMethode = (tmpVarAccess.Child as VariableAccess).Access as MethodeCall; 73 | Assert.AreEqual("Run", tmpMethode.Name); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/NewObjectParamCall_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterCore.Model; 3 | using CodeConverterJava.Model; 4 | using NUnit.Framework; 5 | using System.Collections.Generic; 6 | 7 | namespace CodeConverterJava_Unittest.Methode 8 | { 9 | /// 10 | /// Checking Field Write Access 11 | /// 12 | public class NewObjectParamCall_Unittest 13 | { 14 | [Test] 15 | public void SimpleReturnNewObject() 16 | { 17 | var tmpClass = @" 18 | package org; 19 | public class Class1 { 20 | public void OneSmallerThanTwo(int in1){ 21 | return new Date(in1); 22 | } 23 | "; 24 | var tmpIniData = DataHelper.LoadIni(""); 25 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 26 | 27 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 28 | var tmpNewObject = ((tmpMethodeContent.Code.CodeEntries[0]) as ReturnCodeEntry).CodeEntries[0] as NewObjectDeclaration; 29 | 30 | //new Statement with Parameters 31 | Assert.AreNotEqual(null, tmpNewObject); 32 | Assert.AreEqual(1, tmpNewObject.ArgumentList.Count); 33 | } 34 | [Test] 35 | public void SetFieldTonewValue() 36 | { 37 | var tmpClass = @" 38 | package org; 39 | public class Class1 { 40 | public void OneSmallerThanTwo(int in1){ 41 | var b= new Date(in1); 42 | } 43 | "; 44 | var tmpIniData = DataHelper.LoadIni(""); 45 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 46 | 47 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 48 | var tmpNewObject = ((tmpMethodeContent.Code.CodeEntries[0]) as VariableDeclaration); 49 | 50 | //new Statement with Parameters 51 | Assert.AreEqual(2, tmpMethodeContent.Code.CodeEntries.Count); 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/SuperCall_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Converter; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.ImportExport; 4 | using CodeConverterCore.Model; 5 | using CodeConverterJava.Model; 6 | using JavaToCSharpConverter.Resources; 7 | using NUnit.Framework; 8 | using System.Collections.Generic; 9 | using System.Linq; 10 | 11 | namespace CodeConverterJava_Unittest.Methode 12 | { 13 | /// 14 | /// Checking Field Write Access 15 | /// 16 | public class SuperCall_Unittest 17 | { 18 | [Test] 19 | public void SuperCallInCOnstructor() 20 | { 21 | var tmpClass = @" 22 | package org; 23 | public final class ThreadInterruptedException extends RuntimeException { 24 | public ThreadInterruptedException(InterruptedException ie) { 25 | super(ie); 26 | }}"; 27 | var tmpIniData = DataHelper.LoadIni(""); 28 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 29 | 30 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 31 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0]) as MethodeCall; 32 | Assert.AreEqual("super", tmpCodeLine1.Name); 33 | } 34 | 35 | [Test] 36 | public void SuperCallModifiedToBase() 37 | { 38 | var tmpClass = @" 39 | package org; 40 | public final class ThreadInterruptedException extends RuntimeException { 41 | public ThreadInterruptedException(InterruptedException ie) { 42 | super(ie); 43 | }}"; 44 | var tmpObjectInformation = ProjectInformationHelper.DoFullRun(new List(), new ConverterBase(), new JavaLoader() { LoadDefaultData = true }, tmpClass); 45 | 46 | var tmpMethodeContent = tmpObjectInformation.ClassList.Last().MethodeList[0]; 47 | Assert.AreEqual("ThreadInterruptedException", tmpMethodeContent.Name); 48 | Assert.AreEqual("super", (tmpMethodeContent.Code.CodeEntries[0] as MethodeCall).Name); 49 | } 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/TypeConvertion_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterCore.Model; 3 | using CodeConverterJava.Model; 4 | using NUnit.Framework; 5 | using System.Collections.Generic; 6 | 7 | namespace CodeConverterJava_Unittest.Methode 8 | { 9 | /// 10 | /// Checking Field Write Access 11 | /// 12 | public class TypeConvertion_Unittest 13 | { 14 | [Test] 15 | public void SimpleSingleTypeConversionExplizit() 16 | { 17 | var tmpClass = @" 18 | package org; 19 | public class Class1 { 20 | public void Run(){ 21 | var tmpValue=(String)Value; 22 | } 23 | } 24 | "; 25 | var tmpIniData = DataHelper.LoadIni(""); 26 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 27 | 28 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 29 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0] as VariableDeclaration); 30 | Assert.AreEqual("tmpValue", tmpCodeLine1.Name); 31 | 32 | var tmpFirstConversion = tmpMethodeContent.Code.CodeEntries[1] as TypeConversion; 33 | Assert.AreEqual("String", tmpFirstConversion.Type.ToString()); 34 | Assert.AreEqual("Value", (tmpFirstConversion.PreconversionValue.CodeEntries[0] as ConstantValue).Value); 35 | } 36 | 37 | [Test] 38 | public void DoubleConversionExplizit() 39 | { 40 | var tmpClass = @" 41 | package org; 42 | public class Class1 { 43 | public void Run(){ 44 | var tmpValue=(Int32)(String)Value; 45 | } 46 | } 47 | "; 48 | var tmpIniData = DataHelper.LoadIni(""); 49 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 50 | 51 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 52 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0] as VariableDeclaration); 53 | Assert.AreEqual("tmpValue", tmpCodeLine1.Name); 54 | 55 | var tmpFirstConversion = tmpMethodeContent.Code.CodeEntries[1] as TypeConversion; 56 | var tmpSecondConversion = (tmpFirstConversion.PreconversionValue.CodeEntries[0] as TypeConversion); 57 | 58 | Assert.AreEqual("Int32", tmpFirstConversion.Type.ToString()); 59 | Assert.AreEqual("String", tmpSecondConversion.Type.ToString()); 60 | Assert.AreEqual("Value", (tmpSecondConversion.PreconversionValue.CodeEntries[0] as ConstantValue).Value); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/VariableCreation_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Enum; 3 | using CodeConverterCore.Helper; 4 | using CodeConverterCore.ImportExport; 5 | using CodeConverterCore.Model; 6 | using CodeConverterJava.Model; 7 | using NUnit.Framework; 8 | using System.Collections.Generic; 9 | 10 | namespace CodeConverterJava_Unittest.Methode 11 | { 12 | /// 13 | /// Checking Field Write Access 14 | /// 15 | public class VariableCreation_Unittest 16 | { 17 | [Test] 18 | public void CreateVariable() 19 | { 20 | var tmpClass = @" 21 | package org; 22 | public class Class1 { 23 | public void Run(){ 24 | var tmpValue=4; 25 | } 26 | } 27 | "; 28 | var tmpIniData = DataHelper.LoadIni(""); 29 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 30 | 31 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 32 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0] as VariableDeclaration); 33 | Assert.AreEqual("tmpValue", tmpCodeLine1.Name); 34 | 35 | var tmpValue = tmpMethodeContent.Code.CodeEntries[1] as ConstantValue; 36 | Assert.AreEqual("4", tmpValue.Value); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Methode/WhileStatement_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using CodeConverterJava.Model; 5 | using NUnit.Framework; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterJava_Unittest.Methode 9 | { 10 | /// 11 | /// Checking Field Write Access 12 | /// 13 | public class WhileStatement_Unittest 14 | { 15 | [Test] 16 | public void SimpleWhile() 17 | { 18 | var tmpClass = @" 19 | package org; 20 | public class Class1 { 21 | public void OneSmallerThanTwo(int in1, int in2){ 22 | while(true){ 23 | return true; 24 | } 25 | } 26 | } 27 | "; 28 | var tmpIniData = DataHelper.LoadIni(""); 29 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 30 | 31 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 32 | var tmpStatement = (tmpMethodeContent.Code.CodeEntries[0]) as StatementCode; 33 | 34 | //Statement IF 35 | Assert.AreEqual(StatementTypeEnum.While, tmpStatement.StatementType); 36 | 37 | //Inner Content (return true); 38 | Assert.AreNotEqual(null, tmpStatement.InnerContent); 39 | 40 | //IF Statement (in1 { tmpClass }, tmpIniData); 23 | 24 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0] as StatementCode; 25 | var tmpIfCodeEntries = (tmpMethodeContent.StatementCodeBlocks[0].CodeEntries[0] as CodeExpression); 26 | Assert.AreEqual(2, tmpIfCodeEntries.SubClauseEntries.Count); 27 | Assert.AreEqual("true", tmpIfCodeEntries.SubClauseEntries[0].ToString()); 28 | Assert.AreEqual(VariableOperatorType.Equals, tmpIfCodeEntries.Manipulator); 29 | Assert.AreEqual(StatementTypeEnum.If, tmpMethodeContent.StatementType); 30 | } 31 | 32 | [Test] 33 | public void IfWithOROfBooleanOperators() 34 | { 35 | var tmpClass = @" 36 | package org; 37 | public class Class1 { 38 | public void Run(){ 39 | if(true||true){} 40 | }}"; 41 | var tmpIniData = DataHelper.LoadIni(""); 42 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 43 | 44 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0] as StatementCode; 45 | var tmpIfCodeEntries = (tmpMethodeContent.StatementCodeBlocks[0].CodeEntries[0] as CodeExpression); 46 | Assert.AreEqual(2, tmpIfCodeEntries.SubClauseEntries.Count); 47 | Assert.AreEqual(VariableOperatorType.Or, tmpIfCodeEntries.Manipulator); 48 | Assert.AreEqual("(true Or true)", tmpIfCodeEntries.ToString()); 49 | } 50 | 51 | [Test] 52 | public void IfWithMultipleBooleanOperators1() 53 | { 54 | var tmpClass = @" 55 | package org; 56 | public class Class1 { 57 | public void Run(){ 58 | if(true||true&&false){} 59 | }}"; 60 | var tmpIniData = DataHelper.LoadIni(""); 61 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 62 | 63 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0] as StatementCode; 64 | var tmpIfCodeEntries = (tmpMethodeContent.StatementCodeBlocks[0].CodeEntries[0] as CodeExpression); 65 | Assert.AreEqual(2, tmpIfCodeEntries.SubClauseEntries.Count); 66 | Assert.AreEqual(VariableOperatorType.Or, tmpIfCodeEntries.Manipulator); 67 | Assert.AreEqual("(true Or (true And false))", tmpIfCodeEntries.ToString()); 68 | } 69 | 70 | [Test] 71 | public void IfWithMultipleBooleanOperators2() 72 | { 73 | var tmpClass = @" 74 | package org; 75 | public class Class1 { 76 | public void Run(){ 77 | if(true&&true||false){} 78 | }}"; 79 | var tmpIniData = DataHelper.LoadIni(""); 80 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 81 | 82 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0] as StatementCode; 83 | var tmpIfCodeEntries = (tmpMethodeContent.StatementCodeBlocks[0].CodeEntries[0] as CodeExpression); 84 | Assert.AreEqual(2, tmpIfCodeEntries.SubClauseEntries.Count); 85 | Assert.AreEqual(VariableOperatorType.Or, tmpIfCodeEntries.Manipulator); 86 | Assert.AreEqual("((true And true) Or false)", tmpIfCodeEntries.ToString()); 87 | } 88 | } 89 | } 90 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Objektstruktur/Calculation_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterJava.Model; 3 | using CodeConverterCore.Model; 4 | using NUnit.Framework; 5 | using System.Collections.Generic; 6 | 7 | namespace CodeConverterJava_Unittest.Objektstruktur 8 | { 9 | public class Calculation_Unittest 10 | { 11 | [Test] 12 | public void SetVariableWithMultiplyCalculation() 13 | { 14 | var tmpClass = @" 15 | package org; 16 | public class Class1 { 17 | public void Run(int inResult){ 18 | inResult=4*6; 19 | }}"; 20 | var tmpIniData = DataHelper.LoadIni(""); 21 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 22 | 23 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0]; 24 | var tmpVarSetter = (tmpMethodeContent) as SetFieldWithValue; 25 | Assert.AreEqual("inResult", tmpVarSetter.VariableToAccess.CodeEntries[0].ToString()); 26 | Assert.AreEqual("(4 Multiplication 6)", tmpVarSetter.ValueToSet.ToString()); 27 | } 28 | [Test] 29 | public void SetVariableWithTrippleMultiplyCalculation() 30 | { 31 | var tmpClass = @" 32 | package org; 33 | public class Class1 { 34 | public void Run(int inResult){ 35 | inResult=4*6*8; 36 | }}"; 37 | var tmpIniData = DataHelper.LoadIni(""); 38 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 39 | 40 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0]; 41 | var tmpVarSetter = (tmpMethodeContent) as SetFieldWithValue; 42 | Assert.AreEqual("inResult", tmpVarSetter.VariableToAccess.CodeEntries[0].ToString()); 43 | Assert.AreEqual("((4 Multiplication 6) Multiplication 8)", tmpVarSetter.ValueToSet.ToString()); 44 | } 45 | 46 | [Test] 47 | public void SetVariableWithMultiplyCalculationWithSubElementCheck() 48 | { 49 | var tmpClass = @" 50 | package org; 51 | public class Class1 { 52 | public void Run(int inResult){ 53 | inResult=4*6; 54 | }}"; 55 | var tmpIniData = DataHelper.LoadIni(""); 56 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 57 | 58 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0]; 59 | var tmpVarSetter = (tmpMethodeContent) as SetFieldWithValue; 60 | Assert.AreEqual("inResult", (tmpVarSetter.VariableToAccess.CodeEntries[0] as ConstantValue).Value); 61 | Assert.AreEqual(2, (tmpVarSetter.ValueToSet.CodeEntries[0] as CodeExpression).SubClauseEntries.Count); 62 | } 63 | 64 | [Test] 65 | public void CalculationWithoutOrderOfMath() 66 | { 67 | var tmpClass = @" 68 | package org; 69 | public class Class1 { 70 | public void Run(int inResult){ 71 | inResult=4*6+6-3*2; 72 | }}"; 73 | var tmpIniData = DataHelper.LoadIni(""); 74 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 75 | 76 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0]; 77 | var tmpVarSetter = (tmpMethodeContent) as SetFieldWithValue; 78 | Assert.AreEqual("inResult", tmpVarSetter.VariableToAccess.CodeEntries[0].ToString()); 79 | Assert.AreEqual("(((4 Multiplication 6) Addition 6) Substraction (3 Multiplication 2))", tmpVarSetter.ValueToSet.ToString()); 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Objektstruktur/Extends_Implements_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterJava.Model; 3 | using NUnit.Framework; 4 | using System.Collections.Generic; 5 | 6 | namespace CodeConverterJava_Unittest.Objektstruktur 7 | { 8 | public class Extends_Implements_Unittest 9 | { 10 | [Test] 11 | public void Interface_Implements1() 12 | { 13 | var tmpClass = @" 14 | package org.apache.lucene.util; 15 | 16 | public interface Accountable implements object{ 17 | bool Get(int inIndex) 18 | }"; 19 | var tmpIniData = DataHelper.LoadIni(""); 20 | var tmpProjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 21 | 22 | var tmpClass1 = tmpProjectInformation.ClassList[0]; 23 | Assert.AreEqual(1, tmpClass1.InterfaceList.Count); 24 | 25 | Assert.AreEqual("object", tmpClass1.InterfaceList[0].Name); 26 | } 27 | 28 | [Test] 29 | public void Interface_ImplementMultiple() 30 | { 31 | var tmpClass = @" 32 | package org.apache.lucene.util; 33 | 34 | public interface Accountable implements object, IAccountable{ 35 | bool Get(int inIndex) 36 | }"; 37 | var tmpIniData = DataHelper.LoadIni(""); 38 | var tmpProjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 39 | 40 | var tmpClass1 = tmpProjectInformation.ClassList[0]; 41 | Assert.AreEqual(2, tmpClass1.InterfaceList.Count); 42 | 43 | Assert.AreEqual("object", tmpClass1.InterfaceList[0].Name); 44 | } 45 | 46 | [Test] 47 | public void Interface_Extends1() 48 | { 49 | var tmpClass = @" 50 | package org.apache.lucene.util; 51 | 52 | public interface Accountable extends object{ 53 | bool Get(int inIndex) 54 | }"; 55 | var tmpIniData = DataHelper.LoadIni(""); 56 | var tmpProjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 57 | 58 | var tmpClass1 = tmpProjectInformation.ClassList[0]; 59 | Assert.AreEqual(1, tmpClass1.InterfaceList.Count); 60 | 61 | Assert.AreEqual("object", tmpClass1.InterfaceList[0].Name); 62 | } 63 | 64 | [Test] 65 | public void Class_ImplementMultiple() 66 | { 67 | var tmpClass = @" 68 | package org.apache.lucene.util; 69 | 70 | public class Accountable implements object, IAccountable{ 71 | bool Get(int inIndex) 72 | }"; 73 | var tmpIniData = DataHelper.LoadIni(""); 74 | var tmpProjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 75 | 76 | var tmpClass1 = tmpProjectInformation.ClassList[0]; 77 | Assert.AreEqual(2, tmpClass1.InterfaceList.Count); 78 | 79 | Assert.AreEqual("object", tmpClass1.InterfaceList[0].Name); 80 | } 81 | 82 | [Test] 83 | public void Class_Extends1() 84 | { 85 | var tmpClass = @" 86 | package org.apache.lucene.util; 87 | 88 | public class Accountable extends object{ 89 | bool Get(int inIndex) 90 | }"; 91 | var tmpIniData = DataHelper.LoadIni(""); 92 | var tmpProjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 93 | 94 | var tmpClass1 = tmpProjectInformation.ClassList[0]; 95 | Assert.AreEqual(1, tmpClass1.InterfaceList.Count); 96 | 97 | Assert.AreEqual("object", tmpClass1.InterfaceList[0].Name); 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Objektstruktur/FieldAccess_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Model; 4 | using CodeConverterJava.Model; 5 | using NUnit.Framework; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterJava_Unittest.Objektstruktur 9 | { 10 | /// 11 | /// Checking Field Write Access 12 | /// 13 | public class FieldAccess_Unittest 14 | { 15 | [Test] 16 | public void MethodeVariableDeclaration() 17 | { 18 | var tmpClass = @" 19 | package org; 20 | public class Class1 { 21 | public int Value; 22 | public void Run(){ 23 | Value=4; 24 | } 25 | } 26 | "; 27 | var tmpIniData = DataHelper.LoadIni(""); 28 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 29 | 30 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 31 | var tmpCodeLine1 = (tmpMethodeContent.Code.CodeEntries[0]) as SetFieldWithValue; 32 | Assert.AreEqual("Value", (tmpCodeLine1.VariableToAccess.CodeEntries[0] as ConstantValue).Value); 33 | Assert.AreEqual("4", (tmpCodeLine1.ValueToSet.CodeEntries[0] as ConstantValue).Value); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Objektstruktur/MethodeCall_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterJava.Model; 3 | using CodeConverterCore.Model; 4 | using NUnit.Framework; 5 | using System.Collections.Generic; 6 | 7 | namespace CodeConverterJava_Unittest.Objektstruktur 8 | { 9 | public class MethodeCall_Unittest 10 | { 11 | [Test] 12 | public void CallKnownMethodeOnItselfNoAnalyzer() 13 | { 14 | var tmpClass = @" 15 | package org; 16 | public class Class1 { 17 | public void Run(){ 18 | Run(); 19 | }}"; 20 | var tmpIniData = DataHelper.LoadIni(""); 21 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 22 | 23 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 24 | Assert.AreEqual(1, tmpMethodeContent.Code.CodeEntries.Count); 25 | Assert.AreEqual("Run", (tmpMethodeContent.Code.CodeEntries[0] as MethodeCall).Name); 26 | Assert.AreEqual(0, (tmpMethodeContent.Code.CodeEntries[0] as MethodeCall).Parameter.Count); 27 | } 28 | 29 | [Test] 30 | public void CallUnknownMethodeOnItselfNoAnalyzer() 31 | { 32 | var tmpClass = @" 33 | package org; 34 | public class Class1 { 35 | public void Run(){ 36 | NotRun(); 37 | }}"; 38 | var tmpIniData = DataHelper.LoadIni(""); 39 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 40 | 41 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 42 | Assert.AreEqual(1, tmpMethodeContent.Code.CodeEntries.Count); 43 | Assert.AreEqual("NotRun", (tmpMethodeContent.Code.CodeEntries[0] as MethodeCall).Name); 44 | Assert.AreEqual(0, (tmpMethodeContent.Code.CodeEntries[0] as MethodeCall).Parameter.Count); 45 | } 46 | 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Objektstruktur/MethodeCode_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using CodeConverterJava.Model; 3 | using CodeConverterCore.Model; 4 | using NUnit.Framework; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace CodeConverterJava_Unittest.Objektstruktur 10 | { 11 | public class MethodeCode_Unittest 12 | { 13 | [Test] 14 | public void MethodeVariableDeclaration() 15 | { 16 | var tmpClass = @" 17 | package org; 18 | public class Class1 { 19 | public void Run(){ 20 | int tmpInt; 21 | } 22 | } 23 | "; 24 | var tmpIniData = DataHelper.LoadIni(""); 25 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 26 | 27 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 28 | Assert.AreEqual(1, tmpMethodeContent.Code.CodeEntries.Count); 29 | Assert.AreEqual("int", (tmpMethodeContent.Code.CodeEntries[0] as VariableDeclaration).Type.Name); 30 | } 31 | 32 | [Test] 33 | public void MethodeVariableWithSimpleValueSetAsInt() 34 | { 35 | var tmpClass = @" 36 | package org; 37 | public class Class1 { 38 | public void Run(){ 39 | var tmpInt=0; 40 | } 41 | } 42 | "; 43 | var tmpIniData = DataHelper.LoadIni(""); 44 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 45 | 46 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 47 | Assert.AreEqual("0", (tmpMethodeContent.Code.CodeEntries[1] as ConstantValue).Value); 48 | } 49 | 50 | [Test] 51 | public void MethodeVariableWithSimpleValueSetAsString() 52 | { 53 | var tmpClass = @" 54 | package org; 55 | public class Class1 { 56 | public void Run(){ 57 | var tmpStr=""0""; 58 | } 59 | } 60 | "; 61 | var tmpIniData = DataHelper.LoadIni(""); 62 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 63 | 64 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0]; 65 | Assert.AreEqual("\"0\"", (tmpMethodeContent.Code.CodeEntries[1] as ConstantValue).Value); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Objektstruktur/MethodeFunctionCode_Unittest.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterJava.Model; 4 | using CodeConverterCore.Model; 5 | using NUnit.Framework; 6 | using System.Collections.Generic; 7 | 8 | namespace CodeConverterJava_Unittest.Objektstruktur 9 | { 10 | public class MethodeFunctionCode 11 | { 12 | [Test] 13 | public void IfWIthConstant() 14 | { 15 | var tmpClass = @" 16 | package org; 17 | public class Class1 { 18 | public void Run(){ 19 | if(true){} 20 | }}"; 21 | var tmpIniData = DataHelper.LoadIni(""); 22 | var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 23 | 24 | var tmpMethodeContent = tmpObjectInformation.ClassList[0].MethodeList[0].Code.CodeEntries[0]; 25 | Assert.AreEqual(StatementTypeEnum.If, (tmpMethodeContent as StatementCode).StatementType); 26 | } 27 | 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/Objektstruktur/UnknownTypeWithMethode.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Analyzer; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterJava.Model; 4 | using NUnit.Framework; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace CodeConverterJava_Unittest.Objektstruktur 10 | { 11 | public class UnknownTypeWithMethode 12 | { 13 | [Test] 14 | public void SimpleMethode() 15 | { 16 | var tmpClass = @" 17 | package org.apache.lucene.util; 18 | 19 | public interface Accountable{ 20 | default Collection getChildResources() 21 | { 22 | return Collections.emptyList(); 23 | } 24 | }"; 25 | var tmpIniData = DataHelper.LoadIni(""); 26 | var tmpProjectInformation = new JavaLoader().CreateObjectInformation(new List { tmpClass }, tmpIniData); 27 | 28 | new AnalyzerCore().LinkProjectInformation(tmpProjectInformation); 29 | 30 | var tmpClass1 = tmpProjectInformation.ClassList[0]; 31 | Assert.AreEqual("getChildResources", tmpClass1.MethodeList[0].Name); 32 | 33 | Assert.AreEqual(2, tmpProjectInformation.GetAllUnknownTypes().Count); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/TextHelpData/JavaMapperObject.cs: -------------------------------------------------------------------------------- 1 |  2 | 3 | namespace JavaCodeLoader_Unittest.TextHelpData 4 | { 5 | public static class JavaMapperObject 6 | { 7 | public static string JavaMapper = @";Excplicit Type Mapping (From what Java Type to Waht C# Type) 8 | [Namespace] 9 | java.io.Reader=System.IO 10 | java.io.IOException=System.IO.Exception 11 | java.nio.charset.StandardCharsets=System 12 | 13 | ;Fuzzy Search Type Mapping (Used to Map this Project to 'LuceNET') 14 | [TypeStartsWith] 15 | org.apache.lucene=LuceNET 16 | 17 | ;Currently Unused 18 | [Type] 19 | IndexOutOfBoundsException=System.IO.Exception.IndexOutOfBoundsException 20 | String=string 21 | boolean=bool 22 | 23 | ;Methode Mapping (to be Implemented) 24 | [Methode] 25 | String.substring=Substring 26 | object.getName=GetType().Name 27 | 28 | "; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /JavaCodeLoader_Unittest/TextHelpData/JsonFormatingHelper.cs: -------------------------------------------------------------------------------- 1 | using NUnit.Framework; 2 | using CodeConverterJava.Resources; 3 | using CodeConverterCore.ImportExport; 4 | 5 | namespace CodeConverterJava_Unittest.Objektstruktur 6 | { 7 | public class JsonFormatingHelper 8 | { 9 | [Test] 10 | public void FormatJSON() 11 | { 12 | var tmpNewText = ExportHelper.CreateJsonFromClassList(ImportHelper.ImportClasses(JavaLangClassJson.JavaLang)); 13 | Assert.AreEqual(true, true); 14 | } 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /JavaCoreReplacer/FLoatCompareHelper.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace JavaCoreReplacer 4 | { 5 | public static class FLoatCompareHelper 6 | { 7 | public static int FloatCompare(float in1, float in2) 8 | { 9 | return 0; 10 | } 11 | 12 | 13 | public static int FloatToIntBits(float in1) 14 | { 15 | return 0; 16 | } 17 | 18 | public static int DoubleCompare(double in1, double in2) 19 | { 20 | return 0; 21 | } 22 | 23 | 24 | public static long DoubleToLongBits(double in1) 25 | { 26 | return 0; 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /JavaCoreReplacer/JavaCoreReplacer.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netstandard2.0 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /JavaCoreReplacer_Unittest/JavaCoreReplacer_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 | 23 | -------------------------------------------------------------------------------- /JavaCoreReplacer_Unittest/UnitTest1.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.ImportExport; 2 | using NUnit.Framework; 3 | using System.Collections.Generic; 4 | 5 | namespace JavaCoreReplacer_Unittest 6 | { 7 | public class FLoatCompareHelper 8 | { 9 | [Test] 10 | public void Test1() 11 | { 12 | Assert.Pass(); 13 | } 14 | } 15 | } -------------------------------------------------------------------------------- /JavaToCSharpImporter/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/Helper/NamespaceHelper.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Interface; 4 | using CodeConverterCore.Model; 5 | using JavaToCSharpConverter.Model; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Linq; 9 | using System.Runtime.InteropServices; 10 | using System.Text; 11 | using System.Threading.Tasks; 12 | 13 | namespace JavaToCSharpConverter.Helper 14 | { 15 | public static class NamespaceHelper 16 | { 17 | /// 18 | /// Add all required Usings depending on the Classes 19 | /// 20 | /// 21 | public static void HandleNamespaces(ClassContainer inClass) 22 | { 23 | if (!inClass.UsingList.Contains("UnknownTypes")) 24 | { 25 | inClass.UsingList.Add("UnknownTypes"); 26 | } 27 | if (!inClass.UsingList.Contains("System")) 28 | { 29 | inClass.UsingList.Add("System"); 30 | } 31 | 32 | var tmpNamespaceStepper = new NamespaceCodeStepper(inClass); 33 | CodeSteppingHelper.CheckClassCodeBlocks(tmpNamespaceStepper, inClass); 34 | 35 | //Check Methode Return Type if Using is Required 36 | foreach (var tmpMethode in inClass.MethodeList) 37 | { 38 | if (tmpMethode.ReturnType != null) 39 | { 40 | NamespaceCodeStepper.AddToUsingIfRequired(inClass, tmpMethode.ReturnType); 41 | } 42 | } 43 | 44 | //Check Elvis Statements for struct with null Problem. 45 | var tmpElvisStepper = new ElvisStatementCodeStepper(inClass); 46 | CodeSteppingHelper.CheckClassCodeBlocks(tmpElvisStepper, inClass); 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/Model/NamespaceCodeStepper.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Enum; 2 | using CodeConverterCore.Helper; 3 | using CodeConverterCore.Interface; 4 | using CodeConverterCore.Model; 5 | 6 | namespace JavaToCSharpConverter.Model 7 | { 8 | public class NamespaceCodeStepper : ICodeStepperEvents 9 | { 10 | public NamespaceCodeStepper(ClassContainer inCurrentClass) 11 | { 12 | _currentClass = inCurrentClass; 13 | } 14 | private ClassContainer _currentClass; 15 | 16 | public void CodeEntryStep(ICodeEntry inCodeEntry) 17 | { 18 | if (inCodeEntry is StatementCode) 19 | { 20 | var tmpStatement = inCodeEntry as StatementCode; 21 | if (tmpStatement.StatementType == StatementTypeEnum.Assert) 22 | { 23 | AddToUsingIfRequired(_currentClass, Modifiers.SystemDiagnosis); 24 | } 25 | } 26 | else if (inCodeEntry is VariableDeclaration) 27 | { 28 | var tmpVarDecl = inCodeEntry as VariableDeclaration; 29 | AddToUsingIfRequired(_currentClass, tmpVarDecl.Type); 30 | } 31 | else if (inCodeEntry is MethodeCall) 32 | { 33 | var tmpMethodeCall = inCodeEntry as MethodeCall; 34 | //throw new System.Exception("Resolve Methode Call to Static Methodes with Namespace of other Class"); 35 | } 36 | else 37 | { 38 | 39 | } 40 | } 41 | 42 | /// 43 | /// AddUsing to ClassContainer if Required 44 | /// 45 | /// 46 | /// 47 | public static void AddToUsingIfRequired(ClassContainer inClass, TypeContainer inType) 48 | { 49 | var tmpType = inClass.Parent.ClassFromBaseType(inType); 50 | if (tmpType == null) 51 | { 52 | return; 53 | } 54 | AddToUsingIfRequired(inClass, tmpType.Namespace); 55 | } 56 | 57 | /// 58 | /// AddUsing to ClassContainer if Required 59 | /// 60 | /// 61 | /// 62 | private static void AddToUsingIfRequired(ClassContainer inClass, string inUsingToCheck) 63 | { 64 | if (!inClass.FullUsingList.Contains(inUsingToCheck)) 65 | { 66 | inClass.UsingList.Add(inUsingToCheck); 67 | } 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/Model/ReplaceInFile.cs: -------------------------------------------------------------------------------- 1 | using JavaToCSharpConverter; 2 | using System; 3 | using System.Collections.Generic; 4 | 5 | namespace JavaToCSharpConverter.Model 6 | { 7 | /// 8 | /// Suchen und ersetzen in Dateien 9 | /// 10 | public class ReplaceInFile : SearchInFile 11 | { 12 | public List Replacelist { get; set; } = new List(); 13 | 14 | public override void Search() 15 | { 16 | var tmpFile = LoadFile(); 17 | 18 | string tmpNewFile = tmpFile; 19 | foreach (var tmpReplace in Replacelist) 20 | { 21 | tmpNewFile = tmpReplace.Apply(tmpNewFile); 22 | } 23 | //Prüfem pb was geändert hat 24 | if (tmpNewFile != tmpFile) 25 | { 26 | System.IO.File.WriteAllText(FilePath, tmpNewFile); 27 | FoundCount = 1; 28 | ResultCache.Bag.Add(FilePath); 29 | Console.WriteLine("File Changed: " + FilePath); 30 | } 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/Model/SearchAndReplacePattern.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Text.RegularExpressions; 3 | 4 | namespace JavaToCSharpConverter.Model 5 | { 6 | public class SearchAndReplacePattern 7 | { 8 | public string SearchPattern { get; set; } 9 | public RegexOptions Options { get; set; } 10 | public string ReplacePattern { get; set; } 11 | public int FoundCount { get; set; } 12 | 13 | public string Apply(string inText) 14 | { 15 | var tmpRegex = new Regex(SearchPattern, Options); 16 | if (string.IsNullOrEmpty(ReplacePattern)) 17 | { 18 | //Search 19 | FoundCount = tmpRegex.Matches(inText).Count; 20 | if (FoundCount > 0) 21 | { 22 | Console.WriteLine("Found: " + FoundCount); 23 | } 24 | return inText; 25 | } 26 | 27 | //Replace 28 | var tmpNewText = tmpRegex.Replace(inText, ReplacePattern); 29 | if (tmpNewText != inText) 30 | { 31 | FoundCount = 1; 32 | } 33 | return tmpNewText; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/Model/SearchInFile.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 JavaToCSharpConverter.Model 9 | { 10 | /// 11 | /// Anzahl Element in einer Datei ausfindig machen 12 | /// 13 | public class SearchInFile 14 | { 15 | public string FilePath { get; set; } 16 | 17 | public string SearchPattern { get; set; } 18 | 19 | protected string LoadFile() 20 | { 21 | return System.IO.File.ReadAllText(FilePath); 22 | } 23 | 24 | public virtual void Search() 25 | { 26 | var tmpFile = LoadFile(); 27 | var tmpRegex = new Regex(SearchPattern); 28 | FoundCount = tmpRegex.Matches(tmpFile).Count; 29 | } 30 | 31 | public int FoundCount { get; set; } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/Program.cs: -------------------------------------------------------------------------------- 1 | using CodeConverterCore.Helper; 2 | using System; 3 | using System.Diagnostics; 4 | 5 | namespace JavaToCSharpConverter 6 | { 7 | public class Program 8 | { 9 | 10 | static void Main(string[] args) 11 | { 12 | var tmpJavaSourcePath = @"C:\Data\LucenTestData\Working\"; 13 | var tmpCSharpOutputpath = @"C:\Data\LucenTestData\Result\"; 14 | 15 | var tmpTimer = Stopwatch.StartNew(); 16 | ConverterHelper.ConvertFiles(tmpJavaSourcePath, tmpCSharpOutputpath); 17 | 18 | tmpTimer.Stop(); 19 | Console.WriteLine(""); 20 | Console.WriteLine("Miliseconds Coversion Time: " + tmpTimer.ElapsedMilliseconds); 21 | Console.ReadLine(); 22 | } 23 | 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/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("JavaToCSharpConverter")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("JavaToCSharpConverter")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 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("74ed4af5-38df-4589-927b-0a391c4d0ad0")] 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 | // übernehmen, indem Sie "*" eingeben: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/Resource/ClassRenameJson.cs: -------------------------------------------------------------------------------- 1 | namespace JavaToCSharpConverter.Resources 2 | { 3 | public static class ClassRenameJson 4 | { 5 | public static string SystemAliasJson = @"[ 6 | {'Source':{'Namespace':'java.lang','ClassName':'Object','MethodeName':'super'},'Target':{'Namespace':'System','ClassName':'object','MethodeName':'base'}}, 7 | {'Source':{'Namespace':'java.lang','ClassName':'Object','MethodeName':'getClass'},'Target':{'Namespace':'System','ClassName':'object','MethodeName':'GetType'}}, 8 | {'Source':{'Namespace':'java.lang','ClassName':'Object','MethodeName':'hashCode'},'Target':{'Namespace':'System','ClassName':'object','MethodeName':'GetHashCode'}}, 9 | {'Source':{'Namespace':'java.lang','ClassName':'Object','MethodeName':'toString'},'Target':{'Namespace':'System','ClassName':'object','MethodeName':'ToString'}}, 10 | {'Source':{'Namespace':'java.lang','ClassName':'Object'},'Target':{'Namespace':'System','ClassName':'object'}}, 11 | {'Source':{'Namespace':'java.lang','ClassName':'Boolean'},'Target':{'Namespace':'System','ClassName':'bool'}}, 12 | {'Source':{'Namespace':'java.lang','ClassName':'Integer'},'Target':{'Namespace':'System','ClassName':'int'}}, 13 | {'Source':{'Namespace':'java.lang','ClassName':'Void'},'Target':{'Namespace':'System','ClassName':'void'}}, 14 | {'Source':{'Namespace':'java.lang','ClassName':'True'},'Target':{'Namespace':'System','ClassName':'true'}}, 15 | {'Source':{'Namespace':'java.lang','ClassName':'False'},'Target':{'Namespace':'System','ClassName':'false'}}, 16 | {'Source':{'Namespace':'java.lang','ClassName':'Int64'},'Target':{'Namespace':'System','ClassName':'long'}}, 17 | {'Source':{'Namespace':'java.lang','ClassName':'Float'},'Target':{'Namespace':'System','ClassName':'float'}}, 18 | {'Source':{'Namespace':'java.lang','ClassName':'Double'},'Target':{'Namespace':'System','ClassName':'double'}}, 19 | {'Source':{'Namespace':'java.lang','ClassName':'String','MethodeName':'compareTo'},'Target':{'Namespace':'System','ClassName':'String','MethodeName':'CompareTo'}}, 20 | {'Source':{'Namespace':'java.lang','ClassName':'String'},'Target':{'Namespace':'System','ClassName':'String'}}, 21 | {'Source':{'Namespace':'java.lang','ClassName':'Collection'},'Target':{'Namespace':'System.Collections.ObjectModel','ClassName':'Collection'}}, 22 | {'Source':{'Namespace':'java.lang','ClassName':'Class','MethodeName':'getCanonicalName'},'Target':{'Namespace':'System','ClassName':'Type','MethodeName':'FullName','MethodeAsProperty':true}}, 23 | {'Source':{'Namespace':'java.lang','ClassName':'Class'},'Target':{'Namespace':'System','ClassName':'Type'}}, 24 | {'Source':{'Namespace':'java.lang','ClassName':'Comparable','MethodeName':'compareTo'},'Target':{'Namespace':'System','ClassName':'IComparable','MethodeName':'CompareTo'}}, 25 | {'Source':{'Namespace':'java.lang','ClassName':'Comparable'},'Target':{'Namespace':'System','ClassName':'IComparable'}}, 26 | {'Source':{'Namespace':'java.lang','ClassName':'Date'},'Target':{'Namespace':'System','ClassName':'DateTime'}}, 27 | ]"; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/Resource/StringReplacementJson.cs: -------------------------------------------------------------------------------- 1 | namespace JavaToCSharpConverter.Resource 2 | { 3 | public static class StringReplacementJson 4 | { 5 | public static string ReplacementJson = @"[ 6 | { 7 | ""NameRegex"": ""."", 8 | ""SourceText"": ""double.compare"", 9 | ""ReplacementText"": ""FLoatCompareHelper.DoubleCompare"", 10 | ""RequiredUsing"": ""JavaCoreReplacer"" 11 | }, 12 | { 13 | ""NameRegex"": ""."", 14 | ""SourceText"": ""float.compare"", 15 | ""ReplacementText"": ""FLoatCompareHelper.FloatCompare"", 16 | ""RequiredUsing"": ""JavaCoreReplacer"" 17 | }, 18 | { 19 | ""NameRegex"": ""."", 20 | ""SourceText"": ""float.floatToIntBits"", 21 | ""ReplacementText"": ""FLoatCompareHelper.FloatToIntBits"", 22 | ""RequiredUsing"": ""JavaCoreReplacer"" 23 | }, 24 | { 25 | ""NameRegex"": ""."", 26 | ""SourceText"": ""double.doubleToLongBits"", 27 | ""ReplacementText"": ""(int)FLoatCompareHelper.DoubleToLongBits"", 28 | ""RequiredUsing"": ""JavaCoreReplacer"" 29 | } 30 | ]"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/ResultCache.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Concurrent; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace JavaToCSharpConverter 9 | { 10 | public static class ResultCache 11 | { 12 | public static ConcurrentBag Bag = new ConcurrentBag(); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /JavaToCSharpImporter/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | --------------------------------------------------------------------------------