コード例 #1
0
        public void CallKnownMethodeOnItselfWithThis()
        {
            var tmpProject = new ProjectInformation();
            var tmpClass1  = Create.AddClass("Class1");

            tmpProject.FillClasses(new List <ClassContainer> {
                tmpClass1
            });
            var tmpMethodeName = "compareTo";

            tmpClass1.AddMethode(tmpMethodeName, new TypeContainer {
                Name = "void"
            });
            var tmpMethode = tmpClass1.MethodeList[0];

            tmpMethode.Code = new CodeBlock();
            var tmpMethodeCall = Create.CallMethode(new CodeBlock(), tmpMethodeName);
            var tmpVarAccess   = new VariableAccess()
            {
                Access = new ConstantValue("this"),
                Child  = tmpMethodeCall,
            };

            tmpMethode.Code.CodeEntries.Add(tmpVarAccess);
            new AnalyzerCore().LinkProjectInformation(tmpProject);
            tmpMethode.Name = "Blah";


            Assert.AreEqual(tmpMethode, tmpMethodeCall.MethodeLink);
        }
        public void MethodeParam1Type()
        {
            var tmpProject = new ProjectInformation();

            tmpProject.FillClasses(new List <ClassContainer>
            {
                Class_TestX(),
                Class_TestY(),
            });
            new AnalyzerCore().LinkProjectInformation(tmpProject);

            Assert.AreEqual(tmpProject.ClassList[1].Type.Type, tmpProject.ClassList[0].MethodeList[0].Parameter[0].Type.Type);
        }
        public void SameClassNameDifferentNamespace()
        {
            var tmpProject = new ProjectInformation();

            tmpProject.FillClasses(new List <ClassContainer>
            {
                Class_TestX(),
                Class_TestX(inItem => inItem.Namespace = "DifferentNamespace"),
            });
            new AnalyzerCore().LinkProjectInformation(tmpProject);

            Assert.AreNotEqual(tmpProject.ClassList[0].Type.Type, tmpProject.ClassList[1].Type.Type);
        }
コード例 #4
0
        /// <summary>
        /// Create Project from system known data
        /// </summary>
        /// <param name="inProject"></param>
        /// <param name="inAliasList"></param>
        /// <param name="inSystemNamespace"></param>
        public static ProjectInformation CreateSystemProjectInformation(List <ClassContainer> inSystemClassList, List <AliasObject> inAliasList, string inSystemNamespace)
        {
            var tmpProject = new ProjectInformation();

            tmpProject.FillClasses(inSystemClassList);

            foreach (var tmpAlias in inAliasList)
            {
                tmpProject.AddAlias(tmpAlias.To, tmpProject.GetClassOrUnknownForType(tmpAlias.From, new List <string> {
                    inSystemNamespace
                }));
            }

            return(tmpProject);
        }
        public void CheckInterface()
        {
            var tmpProject = new ProjectInformation();

            tmpProject.FillClasses(new List <ClassContainer>
            {
                Class_TestX(),
                Class_TestY(inItem => inItem.InterfaceList.Add(new TypeContainer {
                    Name = Class_TestX().Name
                })),
            });
            new AnalyzerCore().LinkProjectInformation(tmpProject);

            Assert.AreEqual(tmpProject.ClassList[0].Type.Type, tmpProject.ClassList[1].InterfaceList[0].Type);
        }
コード例 #6
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()"));
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        public void CallKnownMethodeOnItself()
        {
            var tmpProject = new ProjectInformation();
            var tmpClass1  = Create.AddClass("Class1");

            tmpProject.FillClasses(new List <ClassContainer> {
                tmpClass1
            });
            var tmpMethodeName = "inStr";

            tmpClass1.AddMethode(tmpMethodeName, new TypeContainer {
                Name = "void"
            });
            var tmpMethode = tmpClass1.MethodeList[0];

            tmpMethode.Code = new CodeBlock();
            var tmpMethodeCall = Create.CallMethode(tmpMethode.Code, tmpMethodeName);

            new AnalyzerCore().LinkProjectInformation(tmpProject);


            Assert.AreEqual(tmpMethode, tmpMethodeCall.MethodeLink);
        }
コード例 #9
0
        public ProjectInformation CreateObjectInformation(List <string> inFileContents, IniParser.Model.IniData inConfiguration)
        {
            var tmpClassList = new List <ClassContainer>();
            ProjectInformation tmpObjectInformation = new ProjectInformation();

            if (LoadDefaultData)
            {
                tmpObjectInformation = ProjectInformationHelper.CreateSystemProjectInformation(ImportHelper.ImportClasses(JavaLangClassJson.JavaLang), ImportHelper.ImportAliasList(CompilerAliasHelper.SystemAliasJson), "java.lang");
            }

            foreach (var tmpFile in inFileContents)
            {
                //tmpClassList.AddRange(JavaClassLoader.LoadFile(tmpFile));
                tmpClassList.AddRange(JavaAntlrClassLoader.LoaderOptimization(tmpFile));
            }
            tmpObjectInformation.FillClasses(tmpClassList);
            //Add Mapped Methodes to Class List (So we don't need String oä as a Class List
            var tmpAdditionalClasses = new List <ClassContainer>();

            //Load all Classes, with Methodes we might need
            if (inConfiguration != null)
            {
                foreach (var tmpMap in inConfiguration["Methode"])
                {
                    var tmpLeftSplit   = tmpMap.KeyName.Split('.');
                    var tmpNamespace   = string.Join(".", tmpLeftSplit.SkipLast(2));
                    var tmpName        = (TypeContainer)tmpLeftSplit.SkipLast(1).Last();
                    var tmpMethodeName = tmpLeftSplit.Last();

                    var tmpClass = tmpAdditionalClasses.FirstOrDefault(inItem =>
                                                                       inItem.Namespace == tmpNamespace && inItem.Type == tmpName);
                    if (tmpClass == null)
                    {
                        tmpClass = new ClassContainer
                        {
                            Type      = tmpName,
                            Namespace = tmpNamespace
                        };
                        tmpAdditionalClasses.Add(tmpClass);
                    }

                    if (!tmpClass.MethodeList.Any(inItem => inItem.Name == tmpMethodeName))
                    {
                        //TODO Check for Param Equality
                        if (tmpClass.MethodeList.Count(inItem => inItem.Name == tmpMethodeName) > 1)
                        {
                            throw new NotImplementedException("Methode differenting with params not implemented");
                        }

                        var tmpNewMethode = new MethodeContainer();
                        tmpNewMethode.Name         = tmpMethodeName;
                        tmpNewMethode.ModifierList = new List <string> {
                            "public"
                        };
                        tmpClass.MethodeList.Add(tmpNewMethode);
                    }
                }
            }

            IResolveMethodeContentToIL tmpCodeHandler = new JavaMethodeCodeResolver();

            foreach (var tmpClass in tmpClassList)
            {
                foreach (var tmpMethode in tmpClass.MethodeList)
                {
                    tmpCodeHandler.Resolve(tmpMethode);
                }
            }

            foreach (var tmpClassouter in tmpClassList)
            {
                foreach (var tmpClass in tmpClassouter.InnerClasses)
                {
                    foreach (var tmpMethode in tmpClass.MethodeList)
                    {
                        tmpCodeHandler.Resolve(tmpMethode);
                    }
                }
            }

            //Fill them into the object Information
            tmpObjectInformation.FillClasses(tmpAdditionalClasses);
            return(tmpObjectInformation);
        }
コード例 #10
0
        public void PropertysThis_FullName_ToLower()
        {
            var tmpProject = new ProjectInformation();

            var tmpClassString     = Create.AddClass("String");
            var tmpGetFullName     = "getFullName";
            var tmpFullNameMethode = tmpClassString.AddMethode(tmpGetFullName, new TypeContainer {
                Name = "String"
            });

            var tmpClass1      = Create.AddClass("Class1");
            var tmpMethodeName = "getChildResources";

            tmpClass1.AddMethode(tmpMethodeName, new TypeContainer {
                Name = "void"
            });
            var tmpMethode = tmpClass1.MethodeList[0];

            Create.AddField(tmpClass1, "Text", new BaseType("String"));

            tmpMethode.Code = new CodeBlock();

            var tmpReturn = new ReturnCodeEntry
            {
                CodeEntries = new List <CodeConverterCore.Interface.ICodeEntry>
                {
                    new VariableAccess
                    {
                        Access = new VariableAccess
                        {
                            Child = new VariableAccess
                            {
                                Access = new ConstantValue
                                {
                                    Value = "Text",
                                }
                            },
                            Access = new ConstantValue
                            {
                                Value = "this"
                            }
                        },
                        Child = new VariableAccess
                        {
                            Access = new MethodeCall
                            {
                                Name = tmpGetFullName
                            }
                        }
                    }
                }
            };

            tmpMethode.Code.CodeEntries.Add(tmpReturn);

            var tmpText = tmpReturn.ToString();

            Assert.AreEqual("return this  Text     getFullName ()  ", tmpText);

            tmpProject.FillClasses(new List <ClassContainer> {
                tmpClass1, tmpClassString
            });

            new AnalyzerCore().LinkProjectInformation(tmpProject);

            tmpFullNameMethode.IsProperty = true;
            tmpFullNameMethode.Name       = "FullName";

            Assert.AreEqual(tmpFullNameMethode.Name, (((tmpReturn.CodeEntries[0] as VariableAccess).Child as VariableAccess).Access as MethodeCall).Name);
        }