public void SuperCallModifiedToBaseToCSharp()
        {
            var tmpClass             = @"
package org;
public final class ThreadInterruptedException extends RuntimeException {
  public ThreadInterruptedException(InterruptedException ie) {
    super(ie);
  }}";
            var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader()
            {
                LoadDefaultData = true
            }, tmpClass);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList();

            var tmpExpectedResult = @"using System;

namespace org
{
    public sealed class ThreadInterruptedException : RuntimeException
    {
        public ThreadInterruptedException(InterruptedException inIe)
            :base(inIe)
        {
        }
    }
}
";
            var tmpResultText     = tmpResult.Last().Content;

            Assert.AreEqual(tmpExpectedResult, tmpResultText);
        }
        public void CheckfoBaseErrors()
        {
            var tmpProject           = new ProjectInformation();
            var tmpObjectInformation = CSharpWriter.CreateClassesFromObjectInformation(tmpProject, new ConverterBase()).ToList();

            Assert.AreEqual(0, tmpObjectInformation.Count);
        }
        public void DoubleConversionExplizit()
        {
            var tmpClass             = @"
package java.lang;
public class Class1 {
public void Run(object value){
var tmpValue=(Int32)(String)value;
}
}
";
            var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader()
            {
                LoadDefaultData = true
            }, tmpClass);


            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList();

            var tmpExpectedResult = @"using System;

namespace System
{
    public class Class1
    {
        public void Run(object inValue)
        {
            var tmpValue =             (Int32)(String)inValue;
        }
    }
}
";

            Assert.AreEqual(tmpExpectedResult, tmpResult.Last().Content);
        }
        public void SimpleReturnElvis()
        {
            var tmpClass             = @"
package org;
public class Class1 {
public void OneSmallerThanTwo(bool inFirst,int in1, int in2){
return inFirst? in1:in2;
}
";
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                tmpClass
            }, tmpIniData);

            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList();

            var tmpExpectedResult = @"

namespace org
{
    public class Class1
    {
        public void OneSmallerThanTwo(bool inFirst, int in1, int in2)
        {
            return inFirst ? in1 : in2;
        }
    }
}
";

            //Check Elvis Result
            Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content);
        }
        public void SimpleAssert()
        {
            var tmpClass             = @"
package org;
public class Class1 {
public void OneSmallerThanTwo(int in1, int in2){
assert in1>0;
}
";
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                tmpClass
            }, tmpIniData);

            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList();

            var tmpExpectedResult = @"

namespace org
{
    public class Class1
    {
        public void OneSmallerThanTwo(int in1, int in2)
        {
            Trace.Assert (in1 > 0);
        }
    }
}
";

            //Statement IF
            Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content);
        }
示例#6
0
        public void CheckAccountableInterfaceComments()
        {
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                JavaBits
            }, tmpIniData);

            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation);

            new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList();

            Assert.AreEqual(1, tmpResult.Count);
            Assert.AreEqual("Accountable", tmpResult[0].FullName);
            //Check for no double Comments
            Assert.AreEqual(false, tmpResult[0].Content.Contains("/*/*"));
            //Check for no double Comments
            int tmpCommentLineCount = new Regex(Regex.Escape("///")).Matches(tmpResult[0].Content).Count;

            Assert.AreEqual(29, tmpCommentLineCount);

            Assert.AreEqual(true, tmpResult[0].Content.Contains("Collections.emptyList();"));
            Assert.AreEqual(true, tmpResult[0].Content.Contains("public Collection<Accountable>"));
        }
        public void CheckBits1()
        {
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                JavaBits
            }, tmpIniData);
            var tmpAnalyerSettings    = new AnalyzerSettings();
            var tmpUnknownTypeCounter = 0;

            tmpAnalyerSettings.UnknownTypeAdded += (UnknownTypeClass inItem) => { tmpUnknownTypeCounter++; };
            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation, tmpAnalyerSettings);

            new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation);
            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList();

            Assert.AreEqual(1, tmpResult.Count);
            Assert.AreEqual("Bits", tmpResult[0].FullName);
            //Check for inner classes existing

            //Expecting four unknown Types: true, false, int and boolean, two which I have not yet added a Pre-Runtime class
            Assert.AreEqual(0, tmpUnknownTypeCounter);

            Assert.AreEqual(true, tmpResult[0].Content.Contains("MatchAllBits"));

            Assert.AreEqual(true, tmpResult[0].Content.Contains("this.len = inLen;"));

            Assert.AreEqual(true, tmpResult[0].Content.Contains("Bits[] EMPTY_ARRAY =  new Bits[0];"));
        }
示例#8
0
        public void IfWithElse()
        {
            var tmpIniData = DataHelper.LoadIni("");
            var tmpProject = new ProjectInformation();
            var tmpClass   = Create.AddClass("IAttribute");

            tmpClass.ModifierList.Add("public");
            tmpClass.ModifierList.Add("interface");

            tmpProject.ClassList.Add(tmpClass);
            var tmpMethode = Create.AddMethode(tmpClass, "m1", TypeContainer.Void
                                               , new FieldContainer {
                Name = "in1", Type = new TypeContainer {
                    Name = "int"
                }
            }
                                               , new FieldContainer {
                Name = "in2", Type = new TypeContainer {
                    Name = "int"
                }
            });

            tmpMethode.Code = new CodeBlock();

            tmpMethode.Code.AddIfStatement(
                Create.CreateComparisionBlock("in1", VariableOperatorType.LessOrEquals, "in2"),
                Create.AddReturnStatement(new CodeBlock(), "true"),
                Create.AddReturnStatement(new CodeBlock(), "false"));


            new AnalyzerCore().LinkProjectInformation(tmpProject);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpProject, new ConverterBase()).ToList();

            var tmpExpectedResult = @"

namespace 
{
    public interface IAttribute
    {
        void m1(int in1, int in2)
        {
            if(in1 <= in2)
            {
                return true;
            }
            else {
                return false;
            }
        }
    }
}
";

            Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content);
        }
        public void ClassCreationWithOveride()
        {
            var tmpClass             = @"public abstract class LongValues  {

  /** Get value at <code>index</code>. */
  public abstract long get(long index);

  /** An instance that returns the provided value. */
  public static final LongValues IDENTITY = new LongValues() {

    @Override
    public long get(long index) {
      return index;
    }
  };
}";
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                tmpClass
            }, tmpIniData);

            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation);
            new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList();

            var tmpExpectedResult = @"

namespace 
{
    public abstract class LongValues
    {
        /// <summary>
        /// An instance that returns the provided value.
        /// </summary>
        public readonly static LongValues IDENTITY =  new LongValues_0();

        public abstract long Get(long inIndex);
        public class LongValues_0 : LongValues
        {
            public override long Get(long inIndex)
            {
                return inIndex;
            }
        }
    }
}
";

            //Check Elvis Result
            Assert.AreEqual(tmpExpectedResult, tmpResult[0].Content);
        }
        public void InterfaceCheck()
        {
            var tmpProject = new ProjectInformation();
            var tmpClass = Create.AddClass("IAttribute");
            tmpClass.ModifierList.Add("public");
            tmpClass.ModifierList.Add("interface");

            tmpProject.ClassList.Add(tmpClass);
            new AnalyzerCore().LinkProjectInformation(tmpProject);
            var tmpObjectInformation = CSharpWriter.CreateClassesFromObjectInformation(tmpProject, new ConverterBase()).ToList();

            Assert.AreEqual(1, tmpObjectInformation.Count);
            Assert.AreEqual(true, tmpObjectInformation[0].Content.Contains("public interface IAttribute"));
        }
示例#11
0
        public void DoubleGenericClassReplace()
        {
            var tmpObjectInformation = ProjectInformationHelper.DoFullRun(
                ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader()
            {
                LoadDefaultData = true
            },
                DoubleReplacement);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last();

            Assert.AreEqual("Bits", tmpResult.FullName);

            Assert.AreEqual(CSharpResultDouble, tmpResult.Content);
        }
        public void CheckMitableValueEquals()
        {
            var tmpObjectInformation = ProjectInformationHelper.DoFullRun(
                ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader()
            {
                LoadDefaultData = true
            },
                EqualsString);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last();

            Assert.AreEqual("MutableValue", tmpResult.FullName);

            Assert.AreEqual(true, tmpResult.Content.Contains("   return ((GetType() == inOther.GetType()) && this.equalsSameType(inOther));"));
        }
        public void IfWIthConstant()
        {
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                JavaClass
            }, tmpIniData);

            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp()).ToList();

            Assert.AreEqual(1, tmpResult.Count);
            Assert.AreEqual("Class1", tmpResult[0].FullName);
            Assert.AreEqual(CSharpResult1, tmpResult[0].Content);
        }
        public void Test()
        {
            var tmpClass             = @"
package java.lang;
public class Collection<T>{
}";
            var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader()
            {
                LoadDefaultData = true
            }, tmpClass);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList();

            ///Write to JSON to add additional Java Base Classes
            var b = ExportHelper.CreateJsonFromClassList(tmpObjectInformation.ClassList.Where(inItem => inItem.ClassType == CodeConverterCore.Enum.ClassTypeEnum.Normal).ToList());
        }
        public void CheckMitableValueCompareTo()
        {
            var tmpObjectInformation = ProjectInformationHelper.DoFullRun(
                ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader()
            {
                LoadDefaultData = true
            },
                CompareToString);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last();

            Assert.AreEqual("MutableValue", tmpResult.FullName);

            Assert.AreEqual(true, tmpResult.Content.Contains("Type c1 =             this.GetType()"));
            Assert.AreEqual(true, tmpResult.Content.Contains(" - c2.GetHashCode()"));
        }
示例#16
0
        public void SimpleFor()
        {
            var tmpClass             = @"
package org;
public class Class1 {
public void forIInLength(int len){
 for(int i=0;i<len;i++) {
       i--;
      }
return false;
}
";
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                tmpClass
            }, tmpIniData);

            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation);

            new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp())
                            .ToList()
                            .Last();

            var tmpExpectedResult = @"

namespace org
{
    public class Class1
    {
        public void ForIInLength(int inLen)
        {
            for (int i = 0:(i < inLen):i++)
            {
                i--;
            }
            return false;
        }
    }
}
";

            //Check Elvis Result
            Assert.AreEqual(tmpExpectedResult, tmpResult.Content);
        }
示例#17
0
        public void PropertyGet()
        {
            var tmpProject = new ProjectInformation();
            var tmpClass   = Create.AddClass("v1");
            var tmpMethode = tmpClass.AddMethode("Name", new TypeContainer("string"));

            tmpMethode.IsProperty = true;
            tmpProject.FillClasses(new System.Collections.Generic.List <ClassContainer> {
                tmpClass
            });
            var tmpObjectInformation = CSharpWriter.CreateClassesFromObjectInformation(tmpProject, new ConverterBase()).ToList();


            Assert.AreEqual(1, tmpObjectInformation.Count);
            Assert.AreEqual(true, tmpObjectInformation[0].Content.Contains("string Name{"));
            Assert.AreEqual(false, tmpObjectInformation[0].Content.Contains("string Name()"));
        }
        public void SimpleWhile()
        {
            var tmpClass             = @"
package org;
public class Class1 {
public void OneSmallerThanTwo(){
while(true){
return true;
}
}
}
";
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                tmpClass
            }, tmpIniData);

            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation);

            new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterJavaToCSharp())
                            .ToList()
                            .Last();

            var tmpExpectedResult = @"

namespace org
{
    public class Class1
    {
        public void OneSmallerThanTwo()
        {
            while (true)
            {
                return true;
            }
        }
    }
}
";

            //Check Elvis Result
            Assert.AreEqual(tmpExpectedResult, tmpResult.Content);
        }
示例#19
0
        public void PropertyInInterfaceWithDefaultValue()
        {
            var tmpAnalyerSettings = new AnalyzerSettings();

            var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader()
            {
                LoadDefaultData = true
            }, JavaClass);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene())
                            .Where(inItem => inItem.FullName == "MutableValue")
                            .ToList();

            Assert.AreEqual(1, tmpResult.Count);
            Assert.AreEqual("MutableValue", tmpResult[0].FullName);

            Assert.AreEqual(CSharpResult1, tmpResult[0].Content);
        }
示例#20
0
        public void PropertyInInterfaceWithDefaultValue()
        {
            var tmpIniData           = DataHelper.LoadIni("");
            var tmpObjectInformation = new JavaLoader().CreateObjectInformation(new List <string> {
                JavaClass
            }, tmpIniData);
            var tmpAnalyerSettings    = new AnalyzerSettings();
            var tmpUnknownTypeCounter = 0;

            tmpAnalyerSettings.UnknownTypeAdded += (UnknownTypeClass inItem) => { tmpUnknownTypeCounter++; };
            new AnalyzerCore().LinkProjectInformation(tmpObjectInformation, tmpAnalyerSettings);

            new NamingConvertionHelper(new ConverterLucene()).ConvertProject(tmpObjectInformation);
            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList();

            Assert.AreEqual(1, tmpResult.Count);
            Assert.AreEqual("Bits", tmpResult[0].FullName);

            Assert.AreEqual(CSharpResult1, tmpResult[0].Content);
        }
示例#21
0
        public void SimpleSingleTypeConversionExplizitWithCSharpWrite()
        {
            var tmpClass             = @"
package java.lang;
public abstract  class Class1 {
 public abstract boolean exists();
public abstract object toObject();
  @Override
  public String toString() {
    return exists() ? toObject().toString() : ""(null)"";
  }
    }
";
            var tmpObjectInformation = ProjectInformationHelper.DoFullRun(ImportHelper.ImportMappingList(ClassRenameJson.SystemAliasJson), new ConverterLucene(), new JavaLoader()
            {
                LoadDefaultData = true
            }, tmpClass);

            var tmpResult = CSharpWriter.CreateClassesFromObjectInformation(tmpObjectInformation, new ConverterLucene()).ToList().Last();

            var tmpExpectedResult = @"using System;

namespace System
{
    public abstract class Class1
    {
        public abstract bool Exists();

        public abstract object ToObject();

        public override String ToString()
        {
            return Exists() ? ToObject().ToString() : ""(null)"";
        }
    }
}
";

            Assert.AreEqual(tmpExpectedResult, tmpResult.Content);
        }
        public void InnerClassWithInterfaceWhoWasRenamed()
        {
            var tmpProject = new ProjectInformation();
            var tmpClass = Create.AddClass("IAttribute");
            tmpClass.ModifierList.Add("public");
            tmpClass.ModifierList.Add("interface");

            var tmpInnerClass = Create.AddClass("AttributeEmpty");
            tmpInnerClass.ModifierList.Add("internal");
            tmpInnerClass.ModifierList.Add("class");
            tmpInnerClass.InterfaceList.Add("IAttribute");
            tmpClass.InnerClasses.Add(tmpInnerClass);

            tmpProject.FillClasses(new List<ClassContainer> { tmpClass });
            new AnalyzerCore().LinkProjectInformation(tmpProject);
            tmpClass.Type.Type.Name = "ISpezialAttribute";

            var tmpObjectInformation = CSharpWriter.CreateClassesFromObjectInformation(tmpProject, new ConverterBase()).ToList();

            Assert.AreEqual(1, tmpObjectInformation.Count);
            Assert.AreEqual(true, tmpObjectInformation[0].Content.Contains("public interface ISpezialAttribute"));
            Assert.AreEqual(true, tmpObjectInformation[0].Content.Contains("internal class AttributeEmpty : ISpezialAttribute"));
        }