当前位置: 首页>>代码示例>>C#>>正文


C# LibSrcMLRunner.GenerateSrcMLFromString方法代码示例

本文整理汇总了C#中LibSrcMLRunner.GenerateSrcMLFromString方法的典型用法代码示例。如果您正苦于以下问题:C# LibSrcMLRunner.GenerateSrcMLFromString方法的具体用法?C# LibSrcMLRunner.GenerateSrcMLFromString怎么用?C# LibSrcMLRunner.GenerateSrcMLFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LibSrcMLRunner的用法示例。


在下文中一共展示了LibSrcMLRunner.GenerateSrcMLFromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestRemoveClass_Global

        public void TestRemoveClass_Global() {
            string fooXml = @"class Foo {
                private int bar;
                public Foo() { bar = 42; }
                public int GetBar() { return bar; }
            }";
            LibSrcMLRunner run = new LibSrcMLRunner();
            string srcML = run.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs");
            var beforeScope = CodeParser.ParseFileUnit(fooFileUnit);

            string bazXml = @"class Baz {
              public static int DoWork() { return 0; }
            }";
            LibSrcMLRunner runA = new LibSrcMLRunner();
            string srcMLA = runA.GenerateSrcMLFromString(bazXml, "Baz.cs", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Baz.cs");
            var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit));

            Assert.AreEqual(0, afterScope.ChildStatements.OfType<NamespaceDefinition>().Count());
            Assert.AreEqual(2, afterScope.ChildStatements.OfType<TypeDefinition>().Count());

            afterScope.RemoveFile("Baz.cs");

            DataAssert.StatementsAreEqual(beforeScope, afterScope);
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:26,代码来源:FileRemovalTests_CSharp.cs

示例2: TestGetCallsTo_Simple

        public void TestGetCallsTo_Simple() {

            string xml = @"void foo() {
              printf('Hello');
            }
            
            int main() {
              foo();
              return 0;
            }";
            LibSrcMLRunner run = new LibSrcMLRunner();
            string srcML = run.GenerateSrcMLFromString(xml, "Foo.cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var xmlElement = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.cpp");

            var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlElement);
            var fooMethod = globalScope.GetNamedChildren<MethodDefinition>("foo").First();
            var mainMethod = globalScope.GetNamedChildren<MethodDefinition>("main").First();

            Assert.That(mainMethod.ContainsCallTo(fooMethod));
            var fooCalls = mainMethod.GetCallsTo(fooMethod, true).ToList();
            Assert.AreEqual(1, fooCalls.Count);
            var expectedFooCall = mainMethod.FindExpressions<MethodCall>(true).First(mc => mc.Name == "foo");
            Assert.AreSame(expectedFooCall, fooCalls[0]);

            var callsToFoo = fooMethod.GetCallsToSelf().ToList();
            Assert.AreEqual(1, callsToFoo.Count);
            Assert.AreSame(expectedFooCall, callsToFoo[0]);
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:28,代码来源:StatementExtensionTests.cs

示例3: TestGetCallsTo_Multiple

        public void TestGetCallsTo_Multiple() {

            string xml = @"void star() { }
            
            void bar() { star(); }
            
            void foo() {
                bar();
                if(0) bar();
            }";

            LibSrcMLRunner run = new LibSrcMLRunner();
            string srcML = run.GenerateSrcMLFromString(xml, "Foo.cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var unit = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.cpp");

            var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(unit);

            var methodFoo = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "foo");
            var methodBar = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "bar");
            var methodStar = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "star");

            Assert.That(methodFoo.ContainsCallTo(methodBar));
            Assert.AreEqual(2, methodFoo.GetCallsTo(methodBar, true).Count());

            Assert.That(methodBar.ContainsCallTo(methodStar));
            Assert.AreEqual(1, methodBar.GetCallsTo(methodStar, true).Count());

            Assert.IsFalse(methodFoo.ContainsCallTo(methodStar));
            Assert.IsFalse(methodBar.ContainsCallTo(methodFoo));
            Assert.IsFalse(methodStar.ContainsCallTo(methodFoo));
            Assert.IsFalse(methodStar.ContainsCallTo(methodBar));
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:32,代码来源:StatementExtensionTests.cs

示例4: TestCppBuiltIns_WithDoubleWord

        public void TestCppBuiltIns_WithDoubleWord() {
            // #a.cpp #example: "unsigned int a;"; MODIFIER TYPE a; MODIFIER TYPE b;
            string xmlFormat = @"{0} {1} a; {0} {1} b;";

            foreach(var builtInModifier in new string[] { "unsigned", "signed", "long" }) {
                foreach(var builtIn in new string[] { "int", "double" }) {
                    LibSrcMLRunner run = new LibSrcMLRunner();
                    string srcML = run.GenerateSrcMLFromString(String.Format(xmlFormat, builtInModifier, builtIn), "a.cpp", Language.CPlusPlus, new Collection<UInt32>() { }, false);

                    var aXml = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "a.cpp");

                    var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(aXml);
                    var variables = from stmt in globalScope.GetDescendants()
                                    from declaration in stmt.GetExpressions().OfType<VariableDeclaration>()
                                    select declaration;
                    var variableA = variables.FirstOrDefault();
                    var variableB = variables.LastOrDefault();
                    
                    Assert.AreEqual("a", variableA.Name);
                    Assert.AreEqual("b", variableB.Name);
                    Assert.AreEqual(String.Format("{0} {1}", builtInModifier, builtIn), variableA.VariableType.Name, "TODO: Fix compound types");
                    var typeOfA = variableA.VariableType.FindMatches().First();
                    var typeOfB = variableB.VariableType.FindMatches().First();
                    Assert.AreSame(typeOfA, typeOfB);
                }
            }
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:27,代码来源:BuiltInTypeFactoryTests.cs

示例5: TestCppBuiltIns_WithSingleWord

        public void TestCppBuiltIns_WithSingleWord() {
            // #a.cpp TYPE a; TYPE b;

            string xmlFormat = @"{0} a; {0} b;";

            foreach(var builtIn in new string[] { "char", "short", "int", "long", "bool", "float", "double", "wchar_t" }) {
                LibSrcMLRunner run = new LibSrcMLRunner();
                string srcML = run.GenerateSrcMLFromString(String.Format(xmlFormat, builtIn), "a.cpp", Language.CPlusPlus, new Collection<UInt32>() { }, false);

                var aXml = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "a.cpp");

                var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(aXml);
                var variables = from stmt in globalScope.GetDescendants()
                                from declaration in stmt.GetExpressions().OfType<VariableDeclaration>()
                                select declaration;
                var variableA = variables.FirstOrDefault();
                var variableB = variables.LastOrDefault();

                Assert.AreEqual("a", variableA.Name);
                Assert.AreEqual("b", variableB.Name);
                Assert.AreEqual(builtIn, variableA.VariableType.Name);

                var typeOfA = variableA.VariableType.FindMatches().First();
                var typeOfB = variableB.VariableType.FindMatches().First();
                Assert.AreSame(typeOfA, typeOfB);
            }
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:27,代码来源:BuiltInTypeFactoryTests.cs

示例6: TestField

        public void TestField(Language lang) {

            string xml = @"class A {
              int Foo;
              Bar baz;
            }";
            LibSrcMLRunner run = new LibSrcMLRunner();
            string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");

            var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
            var declStmts = globalScope.GetDescendantsAndSelf<DeclarationStatement>().ToList();
            Assert.AreEqual(2, declStmts.Count);

            var foo = declStmts[0].Content.GetDescendantsAndSelf<VariableDeclaration>().FirstOrDefault();
            Assert.IsNotNull(foo);
            Assert.AreEqual("Foo", foo.Name);
            Assert.AreEqual("int", foo.VariableType.Name);
            Assert.AreEqual(AccessModifier.None, foo.Accessibility);

            var baz = declStmts[1].Content.GetDescendantsAndSelf<VariableDeclaration>().FirstOrDefault();
            Assert.IsNotNull(baz);
            Assert.AreEqual("baz", baz.Name);
            Assert.AreEqual("Bar", baz.VariableType.Name);
            Assert.AreEqual(AccessModifier.None, baz.Accessibility);
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:26,代码来源:CodeParserTests.cs

示例7: TestRemovePartialClass

        public void TestRemovePartialClass() {
            string a1Xml = @"public partial class A {
              public int Execute() {
                   return 0;
              }
            }";
            LibSrcMLRunner run = new LibSrcMLRunner();
            string srcML = run.GenerateSrcMLFromString(a1Xml, "A1.cs", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "A1.cs");
            var beforeScope = CodeParser.ParseFileUnit(a1FileUnit);

            string a2Xml = @"public partial class A {
              private bool Foo() {
                return true;
              }
            }";
            LibSrcMLRunner runA = new LibSrcMLRunner();
            string srcMLA = runA.GenerateSrcMLFromString(a2Xml, "A2.cs", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A2.cs");
            var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(a2FileUnit));

            Assert.AreEqual(1, afterScope.ChildStatements.Count());
            var typeA = afterScope.ChildStatements.First() as TypeDefinition;
            Assert.IsNotNull(typeA);
            Assert.AreEqual(2, typeA.ChildStatements.OfType<MethodDefinition>().Count());
            Assert.IsTrue(typeA.ChildStatements.OfType<MethodDefinition>().Any(m => m.Name == "Execute"));
            Assert.IsTrue(typeA.ChildStatements.OfType<MethodDefinition>().Any(m => m.Name == "Foo"));

            afterScope.RemoveFile("A2.cs");

            DataAssert.StatementsAreEqual(beforeScope, afterScope);
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:32,代码来源:FileRemovalTests_CSharp.cs

示例8: TestCreateTypeDefinition_ClassInPackage

        public void TestCreateTypeDefinition_ClassInPackage() {
            string xml = @"package A.B.C;
            public class D { }";
            LibSrcMLRunner runD = new LibSrcMLRunner();
            string srcMLA = runD.GenerateSrcMLFromString(xml, "D.java", Language.Java, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "D.java");

            var globalScope = codeParser.ParseFileUnit(xmlElement);
            Assert.IsTrue(globalScope.IsGlobal);
            Assert.AreEqual(1, globalScope.ChildStatements.Count());

            var packageA = globalScope.ChildStatements.First() as NamespaceDefinition;
            Assert.IsNotNull(packageA);
            Assert.AreEqual("A", packageA.Name);
            Assert.IsFalse(packageA.IsGlobal);
            Assert.AreEqual(1, packageA.ChildStatements.Count());

            var packageAB = packageA.ChildStatements.First() as NamespaceDefinition;
            Assert.IsNotNull(packageAB);
            Assert.AreEqual("B", packageAB.Name);
            Assert.IsFalse(packageAB.IsGlobal);
            Assert.AreEqual(1, packageAB.ChildStatements.Count());

            var packageABC = packageAB.ChildStatements.First() as NamespaceDefinition;
            Assert.IsNotNull(packageABC);
            Assert.AreEqual("C", packageABC.Name);
            Assert.IsFalse(packageABC.IsGlobal);
            Assert.AreEqual(1, packageABC.ChildStatements.Count());

            var typeD = packageABC.ChildStatements.First() as TypeDefinition;
            Assert.IsNotNull(typeD, "Type D is not a type definition");
            Assert.AreEqual("D", typeD.Name);
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:33,代码来源:JavaCodeParserTests.cs

示例9: TestRemoveMethodFromClass

        public void TestRemoveMethodFromClass() {
            string cppXml = @"int Foo::Add(int b) {
              return this->a + b;
            }";
            LibSrcMLRunner runA = new LibSrcMLRunner();
            string srcMLA = runA.GenerateSrcMLFromString(cppXml, "A.cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);

            var cppFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp");

            string hXml = @"class Foo {
              public:
                int a;
                int Add(int b);
            };";
            LibSrcMLRunner runB = new LibSrcMLRunner();
            string srcMLB = runB.GenerateSrcMLFromString(hXml, "A.h", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);

            var hFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "A.h");

            var beforeScope = CodeParser.ParseFileUnit(hFileunit);
            var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(cppFileUnit));

            Assert.AreEqual(1, afterScope.ChildStatements.Count());
            Assert.IsNotNull(afterScope.ChildStatements.First() as TypeDefinition);

            afterScope.RemoveFile("A.cpp");

            DataAssert.StatementsAreEqual(beforeScope, afterScope);
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:29,代码来源:FileRemovalTests_Cpp.cs

示例10: TestRemoveClass_Namespace

        public void TestRemoveClass_Namespace() {
            string fooXml = @"package com.ABB.Example;
            class Foo {
                private int bar;
                public Foo() { bar = 42; }
                public int GetBar() { return bar; }
            }";
            LibSrcMLRunner run = new LibSrcMLRunner();
            string srcML = run.GenerateSrcMLFromString(fooXml, "Foo.java", Language.Java, new Collection<UInt32>() { }, false);
            var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.java");
            var beforeScope = CodeParser.ParseFileUnit(fooFileUnit);

            string bazXml = @"package com.ABB.Example;
            class Baz {
                public static int DoWork() { return 0; }
            }";
            LibSrcMLRunner runA = new LibSrcMLRunner();
            string srcMLA = runA.GenerateSrcMLFromString(bazXml, "Baz.java", Language.Java, new Collection<UInt32>() { }, false);
            var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Baz.java");
            var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit));

            Assert.AreEqual(1, afterScope.ChildStatements.OfType<NamespaceDefinition>().Count());

            afterScope.RemoveFile("Baz.java");

            DataAssert.StatementsAreEqual(beforeScope, afterScope);
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:27,代码来源:FileRemovalTests_Java.cs

示例11: TestConstructorMerge_Cpp

        public void TestConstructorMerge_Cpp() {
            string header_xml = @"class A { A(); };";

            string impl_xml = @"A::A() { }";

            LibSrcMLRunner runA = new LibSrcMLRunner();
            string srcMLA = runA.GenerateSrcMLFromString(header_xml, "A.h", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "A.h");
            LibSrcMLRunner runE = new LibSrcMLRunner();
            string srcMLE = runE.GenerateSrcMLFromString(impl_xml, "A.cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLE, "A.cpp");

            var headerScope = CodeParser[Language.CPlusPlus].ParseFileUnit(header);
            var implementationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(implementation);

            var globalScope = headerScope.Merge(implementationScope);

            Assert.AreEqual(1, globalScope.ChildStatements.Count());

            var typeA = globalScope.ChildStatements.First() as TypeDefinition;
            Assert.AreEqual("A", typeA.Name);
            Assert.AreEqual(1, typeA.ChildStatements.Count());
            Assert.AreEqual("A.h", typeA.PrimaryLocation.SourceFileName);

            var constructor = typeA.ChildStatements.First() as MethodDefinition;
            Assert.That(constructor.IsConstructor);
            Assert.IsFalse(constructor.IsDestructor);
            Assert.IsFalse(constructor.IsPartial);
            Assert.AreEqual(AccessModifier.Private, constructor.Accessibility);
            Assert.AreEqual("A.cpp", constructor.PrimaryLocation.SourceFileName);
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:31,代码来源:MergeTests.cs

示例12: TestGlobalStatement

 public void TestGlobalStatement() {
     var xml = @"char* bar = 'Hello, world!';
     int foo = 42;";
     LibSrcMLRunner run = new LibSrcMLRunner();
     string srcML = run.GenerateSrcMLFromString(xml, "Example.cpp", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
     var unit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Example.cpp");
     var globalScope = parser[Language.CPlusPlus].ParseFileUnit(unit);
     var actual = globalScope.GetStatementForLocation(new SourceLocation("Example.cpp", 2, 5));
     Assert.AreSame(globalScope.ChildStatements[0], actual);
 }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:10,代码来源:GetStatementTests.cs

示例13: TestContains_Reflexive

 public void TestContains_Reflexive() {
     var xml = @"class Foo {
         int Bar(){return 0;}
     }";
     LibSrcMLRunner run = new LibSrcMLRunner();
     string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection<UInt32>() { }, false);
     var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Class).First();
     var classLoc = new SrcMLLocation(classElement, "Foo.cs");
     Assert.IsTrue(classLoc.Contains(classLoc));
 }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:10,代码来源:SrcMLLocationTests.cs

示例14: TestCreateAliasesForFiles_ImportNamespace

        public void TestCreateAliasesForFiles_ImportNamespace() {
            string xml = @"import x . /*test */ y  /*test */ . z .* /*test*/;";
            //<import>import <name><name>x</name> <op:operator>.</op:operator> <comment type=""block"">/*test */</comment> <name>y</name>  <comment type=""block"">/*test */</comment> <op:operator>.</op:operator> <name>z</name></name> .* <comment type=""block"">/*test*/</comment>;</import>";
            LibSrcMLRunner runA = new LibSrcMLRunner();
            string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java");

            var globalScope = codeParser.ParseFileUnit(xmlElement);
            Assert.AreEqual(1, globalScope.ChildStatements.Count);

            var actual = globalScope.ChildStatements[0] as ImportStatement;
            Assert.IsNotNull(actual);
            Assert.AreEqual("x . y . z", actual.ImportedNamespace.ToString());
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:14,代码来源:JavaCodeParserTests.cs

示例15: TestCreateAliasesForFiles_ImportClass

        public void TestCreateAliasesForFiles_ImportClass() {
            string xml = @"import x.y.z;";
            LibSrcMLRunner runA = new LibSrcMLRunner();
            string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
            XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java");

            var globalScope = codeParser.ParseFileUnit(xmlElement);
            Assert.AreEqual(1, globalScope.ChildStatements.Count);

            var actual = globalScope.ChildStatements[0] as AliasStatement;
            Assert.IsNotNull(actual);
            Assert.AreEqual("z", actual.AliasName);
            Assert.AreEqual("x . y . z", actual.Target.ToString());
        }
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:14,代码来源:JavaCodeParserTests.cs


注:本文中的LibSrcMLRunner.GenerateSrcMLFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。