From 15cec52ad38181940353e48acfb6d6a61add27fe Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Fri, 8 Jan 2016 14:42:08 -0500 Subject: [PATCH 01/17] A lot of modifications to parser code to handle new format. LIT and OP have been removed. POS has had a tag added to its namespace; the position tag. --- .../CPlusPlusCodeParserTests.cs | 385 +++++++----------- ABB.SrcML.Data/AbstractCodeParser.cs | 23 +- ABB.SrcML.Data/LiteralUse.cs | 2 +- ABB.SrcML/AbstractDocument.cs | 2 +- ABB.SrcML/Namespaces/OP.cs | 12 +- ABB.SrcML/Namespaces/POS.cs | 6 +- ABB.SrcML/Namespaces/SRC.cs | 12 + ABB.SrcML/Src2SrcMLRunner.cs | 2 +- ABB.SrcML/SrcMLFile.cs | 2 +- ABB.SrcML/SrcMLGenerator.cs | 4 +- ABB.SrcML/SrcMLNamespaces.cs | 2 +- 11 files changed, 200 insertions(+), 252 deletions(-) diff --git a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs index f4c5721..59b9559 100644 --- a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs +++ b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs @@ -17,29 +17,25 @@ using System.Linq; using System.Xml.Linq; -namespace ABB.SrcML.Data.Test -{ +namespace ABB.SrcML.Data.Test { [TestFixture] [Category("Build")] - public class CPlusPlusCodeParserTests - { + public class CPlusPlusCodeParserTests { private AbstractCodeParser codeParser; private SrcMLFileUnitSetup fileSetup; [TestFixtureSetUp] - public void ClassSetup() - { + public void ClassSetup() { codeParser = new CPlusPlusCodeParser(); fileSetup = new SrcMLFileUnitSetup(Language.CPlusPlus); } [Test] - public void TestCreateTypeDefinitions_Class() - { + public void TestCreateTypeDefinitions_Class() { string xml = "class A { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -54,11 +50,10 @@ public void TestCreateTypeDefinitions_Class() } [Test] - public void TestCreateTypeDefinitions_ClassDeclaration() - { + public void TestCreateTypeDefinitions_ClassDeclaration() { string xml = "class A;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -73,14 +68,13 @@ public void TestCreateTypeDefinitions_ClassDeclaration() } [Test] - public void TestClassWithDeclaredVariable() - { + public void TestClassWithDeclaredVariable() { string xml = "class A {" + " int a;" + "};"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -102,14 +96,13 @@ public void TestClassWithDeclaredVariable() [Test] - public void TestFreeStandingBlock() - { - string xml = "{" + - " int foo = 42;" + - " MethodCall(foo);" + - "}"; + public void TestFreeStandingBlock() { + string xml = @"{ + int foo = 42; + MethodCall(foo); + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -126,11 +119,10 @@ public void TestFreeStandingBlock() } [Test] - public void TestExternStatement_Single() - { + public void TestExternStatement_Single() { string xml = "extern \"C\" int MyGlobalVar;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -144,14 +136,13 @@ public void TestExternStatement_Single() } [Test] - public void TestExternStatement_Block() - { + public void TestExternStatement_Block() { string xml = "extern \"C\" {" + " int globalVar1;" + " int globalVar2;" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -165,15 +156,14 @@ public void TestExternStatement_Block() } [Test] - public void TestConstructor_CallToSelf() - { + public void TestConstructor_CallToSelf() { string xml = "class MyClass {" + "public:" + " MyClass() : MyClass(0) { } " + " MyClass(int foo) { } " + "};"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(unit); @@ -194,8 +184,7 @@ public void TestConstructor_CallToSelf() } [Test] - public void TestConstructor_CallToSuperClass() - { + public void TestConstructor_CallToSuperClass() { string xml = "class SuperClass {" + "public:" + "SuperClass(int foo) { } }; " + @@ -203,7 +192,7 @@ public void TestConstructor_CallToSuperClass() "public:" + "SubClass(int foo) : SuperClass(foo) { } };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(unit); @@ -222,8 +211,7 @@ public void TestConstructor_CallToSuperClass() } [Test] - public void TestConstructor_InitializeBuiltinTypeField() - { + public void TestConstructor_InitializeBuiltinTypeField() { //"test.h" string xml = "class Quux" + "{" + @@ -232,7 +220,7 @@ public void TestConstructor_InitializeBuiltinTypeField() " Quux() : _my_int(5) { }" + "};"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -252,8 +240,7 @@ public void TestConstructor_InitializeBuiltinTypeField() } [Test] - public void TestConstructor_InitializeField() - { + public void TestConstructor_InitializeField() { //"test.h" string xml = "class Foo" + "{" + @@ -267,7 +254,7 @@ public void TestConstructor_InitializeField() " Bar() : baz(42) { }" + "};"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -283,12 +270,11 @@ public void TestConstructor_InitializeField() } [Test] - public void TestCreateAliasesForFiles_ImportClass() - { + public void TestCreateAliasesForFiles_ImportClass() { string xml = "using A::Foo;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -302,12 +288,11 @@ public void TestCreateAliasesForFiles_ImportClass() } [Test] - public void TestCreateAliasesForFiles_ImportNamespace() - { + public void TestCreateAliasesForFiles_ImportNamespace() { string xml = "using namespace x::y::z;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -320,12 +305,11 @@ public void TestCreateAliasesForFiles_ImportNamespace() [Test] [Category("SrcMLUpdate")] - public void TestCreateAliasesForFiles_TypeAlias() - { + public void TestCreateAliasesForFiles_TypeAlias() { string xml = "using x = foo::bar::baz;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -338,8 +322,7 @@ public void TestCreateAliasesForFiles_TypeAlias() } [Test] - public void TestGetImports() - { + public void TestGetImports() { //A.cpp string xmlA = "namespace x {" + " namespace y {" + @@ -347,7 +330,7 @@ public void TestGetImports() " }" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp @@ -355,7 +338,7 @@ public void TestGetImports() "foo = 17;"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -376,15 +359,14 @@ public void TestGetImports() } [Test] - public void TestGetImports_NestedImportNamespace() - { + public void TestGetImports_NestedImportNamespace() { string xml = "using namespace x::y::z;" + "if(bar) {" + " using namespace std;" + " foo = 17;" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -398,15 +380,14 @@ public void TestGetImports_NestedImportNamespace() } [Test] - public void TestGetAliases_NestedImportClass() - { + public void TestGetAliases_NestedImportClass() { //A.cpp string xmlA = "namespace B {" + " class Bar {}" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp @@ -417,7 +398,7 @@ public void TestGetAliases_NestedImportClass() "}"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -442,15 +423,14 @@ public void TestGetAliases_NestedImportClass() [Test] [Category("SrcMLUpdate")] - public void TestGetAliases_NestedTypeAlias() - { + public void TestGetAliases_NestedTypeAlias() { string xml = "using namespace x::y::z;" + "if(bar) {" + " using x = foo::bar::baz;" + " foo = 17;" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -466,8 +446,7 @@ public void TestGetAliases_NestedTypeAlias() } [Test] - public void TestImport_NameResolution() - { + public void TestImport_NameResolution() { //A.cpp string xmlA = "using namespace Foo::Bar;" + // @@ -482,7 +461,7 @@ public void TestImport_NameResolution() "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp @@ -495,7 +474,7 @@ public void TestImport_NameResolution() "}"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -520,34 +499,33 @@ public void TestImport_NameResolution() } [Test] - public void TestAlias_NameResolution_ImportType() - { + public void TestAlias_NameResolution_ImportType() { //A.cpp - string xmlA = "namespace Foo {" + - " namespace Bar {" + - " class Baz {" + - " public:" + - " static void DoTheThing() { }" + - " }" + - "}"; + string xmlA = @"namespace Foo { + namespace Bar { + class Baz { + public: + static void DoTheThing() { } + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "using Foo::Bar::Baz;" + - "namespace A {" + - " class B {" + - " public:" + - " B() {" + - " Baz::DoTheThing();" + - " }" + - " }" + - "}"; + string xmlB = @"using Foo::Bar::Baz; + namespace A { + class B { + public: + B() { + Baz::DoTheThing(); + } + } + }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -570,8 +548,7 @@ public void TestAlias_NameResolution_ImportType() [Test] [Category("SrcMLUpdate")] - public void TestAlias_NameResolution_TypeAlias() - { + public void TestAlias_NameResolution_TypeAlias() { //A.cpp string xmlA = "namespace Foo {" + " namespace Bar {" + @@ -581,7 +558,7 @@ public void TestAlias_NameResolution_TypeAlias() " }" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp @@ -595,7 +572,7 @@ public void TestAlias_NameResolution_TypeAlias() " }" + "}"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cpp"); @@ -617,12 +594,11 @@ public void TestAlias_NameResolution_TypeAlias() } [Test] - public void TestCreateTypeDefinition_ClassInNamespace() - { + public void TestCreateTypeDefinition_ClassInNamespace() { string xml = "namespace A { class B { }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLB = runA.GenerateSrcMLFromString(xml, "B.h", Language.CSharp, new Collection() { }, false); + string srcMLB = runA.GenerateSrcMLFromString(xml, "B.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.h"); @@ -637,14 +613,13 @@ public void TestCreateTypeDefinition_ClassInNamespace() } [Test] - public void TestCreateTypeDefinition_ClassWithMethodDeclaration() - { + public void TestCreateTypeDefinition_ClassWithMethodDeclaration() { string xml = " class A {" + " public:" + " int foo(int a); };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -661,14 +636,13 @@ public void TestCreateTypeDefinition_ClassWithMethodDeclaration() } [Test] - public void TestCreateTypeDefinition_StaticMethod() - { + public void TestCreateTypeDefinition_StaticMethod() { string xml = "class Example {" + "public:" + " static int Example::Foo(int bar) { return bar+1; }" + "};"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLstatic_method = runA.GenerateSrcMLFromString(xml, "static_method.h", Language.CSharp, new Collection() { }, false); + string srcMLstatic_method = runA.GenerateSrcMLFromString(xml, "static_method.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLstatic_method, "static_method.h"); var globalScope = codeParser.ParseFileUnit(fileUnit); @@ -684,12 +658,11 @@ public void TestCreateTypeDefinition_StaticMethod() [Test] - public void TestCreateTypeDefinitions_ClassInFunction() - { + public void TestCreateTypeDefinitions_ClassInFunction() { string xml = "int main() { class A { }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLmain = runA.GenerateSrcMLFromString(xml, "main.cpp", Language.CSharp, new Collection() { }, false); + string srcMLmain = runA.GenerateSrcMLFromString(xml, "main.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLmain, "main.cpp"); var mainMethod = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as MethodDefinition; @@ -703,12 +676,11 @@ public void TestCreateTypeDefinitions_ClassInFunction() } [Test] - public void TestCreateTypeDefinitions_ClassWithInnerClass() - { + public void TestCreateTypeDefinitions_ClassWithInnerClass() { string xml = "class A { class B { }; };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -723,12 +695,11 @@ public void TestCreateTypeDefinitions_ClassWithInnerClass() } [Test] - public void TestCreateTypeDefinitions_ClassWithParents() - { + public void TestCreateTypeDefinitions_ClassWithParents() { string xml = "class A : B,C,D { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -744,19 +715,17 @@ public void TestCreateTypeDefinitions_ClassWithParents() var tests = Enumerable.Zip(new[] { "B", "C", "D" }, parentNames, (e, a) => e == a ); - foreach (var parentMatchesExpected in tests) - { + foreach (var parentMatchesExpected in tests) { Assert.That(parentMatchesExpected); } } [Test] - public void TestCreateTypeDefinitions_ClassWithQualifiedParent() - { + public void TestCreateTypeDefinitions_ClassWithQualifiedParent() { string xml = "class D : A::B::C { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLD = runA.GenerateSrcMLFromString(xml, "D.h", Language.CSharp, new Collection() { }, false); + string srcMLD = runA.GenerateSrcMLFromString(xml, "D.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLD, "D.h"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -778,12 +747,11 @@ public void TestCreateTypeDefinitions_ClassWithQualifiedParent() } [Test] - public void TestCreateTypeDefinitions_InnerClassWithNamespace() - { + public void TestCreateTypeDefinitions_InnerClassWithNamespace() { string xml = "namespace A { class B { class C { }; }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -804,12 +772,11 @@ public void TestCreateTypeDefinitions_InnerClassWithNamespace() } [Test] - public void TestCreateTypeDefinitions_Struct() - { + public void TestCreateTypeDefinitions_Struct() { string xml = "struct A { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -821,13 +788,12 @@ public void TestCreateTypeDefinitions_Struct() } [Test] - public void TestCreateTypeDefinitions_Union() - { + public void TestCreateTypeDefinitions_Union() { string xml = " union A { int a; char b;" + "};"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var actual = codeParser.ParseFileUnit(xmlElement).ChildStatements.First() as TypeDefinition; @@ -837,12 +803,11 @@ public void TestCreateTypeDefinitions_Union() } [Test] - public void TestGenericVariableDeclaration() - { + public void TestGenericVariableDeclaration() { string xml = "vector a;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -858,12 +823,11 @@ public void TestGenericVariableDeclaration() } [Test] - public void TestGenericVariableDeclarationWithPrefix() - { + public void TestGenericVariableDeclarationWithPrefix() { string xml = "std::vector a;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -881,11 +845,10 @@ public void TestGenericVariableDeclarationWithPrefix() } [Test] - public void TestMethodCallCreation_LengthyCallingExpression() - { + public void TestMethodCallCreation_LengthyCallingExpression() { string xml = "a->b.Foo();"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -915,8 +878,7 @@ public void TestMethodCallCreation_LengthyCallingExpression() } [Test] - public void TestMergeWithUsing() - { + public void TestMergeWithUsing() { string headerXml = " namespace A { class B { void Foo(); }; }"; @@ -963,8 +925,7 @@ public void TestMergeWithUsing() } [Test] - public void TestMethodCallCreation_WithConflictingMethodNames() - { + public void TestMethodCallCreation_WithConflictingMethodNames() { //# A.h string a_xml = "class A {" + " B b;" + @@ -1007,8 +968,7 @@ public void TestMethodCallCreation_WithConflictingMethodNames() } [Test] - public void TestMethodCallCreation_WithThisKeyword() - { + public void TestMethodCallCreation_WithThisKeyword() { string a_xml = "class A {" + " void Bar() { }" + " class B {" + @@ -1038,8 +998,7 @@ public void TestMethodCallCreation_WithThisKeyword() } [Test] - public void TestMethodCallCreation_GlobalFunction() - { + public void TestMethodCallCreation_GlobalFunction() { string xml = "void foo(int a) { printf(a); }" + "int main() {" + " foo(5);" + @@ -1047,7 +1006,7 @@ public void TestMethodCallCreation_GlobalFunction() "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1069,8 +1028,7 @@ public void TestMethodCallCreation_GlobalFunction() } [Test] - public void TestMethodCallCreation_CallGlobalNamespace() - { + public void TestMethodCallCreation_CallGlobalNamespace() { string xml = "void Foo() {" + " std::cout<<\"global::Foo\"<() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1117,8 +1075,7 @@ public void TestMethodCallCreation_CallGlobalNamespace() } [Test] - public void TestMethodCallFindMatches() - { + public void TestMethodCallFindMatches() { string headerXml = " # A.h class A { int context;" + " public:" + " A(); };"; @@ -1165,20 +1122,16 @@ orderby namedChild.Name } [Test] - public void TestMethodCallFindMatches_WithArguments() - { - string headerXml = " # A.h class A { int context;" + - " public:" + - " A(int value); };"; + public void TestMethodCallFindMatches_WithArguments() { + string headerXml = @"class A { int context; + public: + A(int value); };"; - string implementationXml = " # A.cpp #include \"A.h\"" + - " A: :A(int value) { context = value;" + - " }"; + string implementationXml = "#include \"A.h\" A: :A(int value) { context = value;}"; - string mainXml = " # main.cpp #include \"A.h\" int main() { int startingState = 0; A *a = new" + - " A(startingState); return startingState; }"; + string mainXml = "#include \"A.h\" int main() { int startingState = 0; A *a = new A(startingState); return startingState; }"; var headerElement = fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h"); @@ -1213,13 +1166,12 @@ orderby namedChild.Name } [Test] - public void TestMethodCallMatchToParameter() - { + public void TestMethodCallMatchToParameter() { string xml = "void CallFoo(B b) { b.Foo(); }" + "class B { void Foo() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1241,12 +1193,11 @@ public void TestMethodCallMatchToParameter() } [Test] - public void TestMethodDefinition_ReturnType() - { + public void TestMethodDefinition_ReturnType() { string xml = "int Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1263,12 +1214,11 @@ public void TestMethodDefinition_ReturnType() } [Test] - public void TestMethodDefinition_ReturnTypeAndSpecifier() - { + public void TestMethodDefinition_ReturnTypeAndSpecifier() { string xml = "static int Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1282,12 +1232,11 @@ public void TestMethodDefinition_ReturnTypeAndSpecifier() } [Test] - public void TestMethodDefinition_Parameters() - { + public void TestMethodDefinition_Parameters() { string xml = "int Foo(int bar, char baz) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1302,12 +1251,11 @@ public void TestMethodDefinition_Parameters() } [Test] - public void TestMethodDefinition_VoidParameter() - { + public void TestMethodDefinition_VoidParameter() { string xml = "void Foo(void) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1320,12 +1268,11 @@ public void TestMethodDefinition_VoidParameter() } [Test] - public void TestMethodDefinition_FunctionPointerParameter() - { + public void TestMethodDefinition_FunctionPointerParameter() { string xml = "int Foo(char bar, int (*pInit)(Quux *theQuux)) {}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1340,12 +1287,11 @@ public void TestMethodDefinition_FunctionPointerParameter() } [Test] - public void TestMethodDefinition_VoidReturn() - { + public void TestMethodDefinition_VoidReturn() { string xml = "void Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); @@ -1358,8 +1304,7 @@ public void TestMethodDefinition_VoidReturn() } [Test] - public void TestMethodDefinition_DefaultArguments() - { + public void TestMethodDefinition_DefaultArguments() { string xml = "void foo(int a = 0);" + "int main() {" + " foo();" + @@ -1369,7 +1314,7 @@ public void TestMethodDefinition_DefaultArguments() "void foo(int a) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(unit).Merge(new NamespaceDefinition()); @@ -1392,8 +1337,7 @@ public void TestMethodDefinition_DefaultArguments() } [Test] - public void TestTwoVariableDeclarations() - { + public void TestTwoVariableDeclarations() { string testXml = "int a,b;"; var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cpp"); @@ -1411,8 +1355,7 @@ public void TestTwoVariableDeclarations() } [Test] - public void TestThreeVariableDeclarations() - { + public void TestThreeVariableDeclarations() { string testXml = "int a,b,c;"; var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cpp"); @@ -1431,8 +1374,7 @@ public void TestThreeVariableDeclarations() } [Test] - public void TestVariablesWithSpecifiers() - { + public void TestVariablesWithSpecifiers() { string testXml = "const int A;" + "static int B;" + "static const Foo C;" + @@ -1468,15 +1410,14 @@ public void TestVariablesWithSpecifiers() } [Test] - public void TestLiteralUse() - { + public void TestLiteralUse() { string xml = "a = 17;" + "foo = watermelon" + "if(true) { " + " c = 'h';" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -1507,8 +1448,7 @@ public void TestLiteralUse() } [Test] - public void TestIfElse() - { + public void TestIfElse() { string xml = "if(a==b) {" + " i = 17;" + "} else {" + @@ -1516,7 +1456,7 @@ public void TestIfElse() " ReportError();" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -1530,8 +1470,7 @@ public void TestIfElse() } [Test] - public void TestIfElseIf() - { + public void TestIfElseIf() { string xml = "if(a==b) {" + " i = 17;" + "} else if(a==c) {" + @@ -1541,7 +1480,7 @@ public void TestIfElseIf() " ReportError();" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1562,11 +1501,10 @@ public void TestIfElseIf() } [Test] - public void TestEmptyStatement() - { + public void TestEmptyStatement() { string xml = ";"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h"); @@ -1579,11 +1517,10 @@ public void TestEmptyStatement() } [Test] - public void TestVariableUse_Index() - { + public void TestVariableUse_Index() { string xml = "foo.bar[17];"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CSharp, new Collection() { }, false); + string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLa, "a.cpp"); @@ -1608,15 +1545,14 @@ public void TestVariableUse_Index() } [Test] - public void TestResolveVariable_Field() - { + public void TestResolveVariable_Field() { string xml = "class A {" + "public:" + " int Foo;" + " A() { Foo = 42; }" + "};"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1630,8 +1566,7 @@ public void TestResolveVariable_Field() } [Test] - public void TestResolveVariable_FieldInParent() - { + public void TestResolveVariable_FieldInParent() { string xml = "class B {" + "public:" + " int Foo;" + @@ -1642,7 +1577,7 @@ public void TestResolveVariable_FieldInParent() "};"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1656,15 +1591,14 @@ public void TestResolveVariable_FieldInParent() } [Test] - public void TestResolveVariable_Global() - { + public void TestResolveVariable_Global() { string xml = "int Foo;" + "int Bar() {" + " Foo = 17;" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1678,8 +1612,7 @@ public void TestResolveVariable_Global() } [Test] - public void TestResolveVariable_VarInNamespace() - { + public void TestResolveVariable_VarInNamespace() { string xml = "namespace A {" + " int Foo;" + " int Bar() {" + @@ -1688,7 +1621,7 @@ public void TestResolveVariable_VarInNamespace() "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1702,8 +1635,7 @@ public void TestResolveVariable_VarInNamespace() } [Test] - public void TestResolveVariable_Masking() - { + public void TestResolveVariable_Masking() { string xml = "int foo = 17;" + "int main(int argc, char** argv)" + "{" + @@ -1714,7 +1646,7 @@ public void TestResolveVariable_Masking() "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1737,8 +1669,7 @@ public void TestResolveVariable_Masking() } [Test] - public void TestVariableDeclaredInCallingObjectWithParentClass() - { + public void TestVariableDeclaredInCallingObjectWithParentClass() { string a_xml = "class A { B b; };"; string b_xml = "class B { void Foo() { } };"; @@ -1787,8 +1718,7 @@ public void TestVariableDeclaredInCallingObjectWithParentClass() } [Test] - public void TestResolveArrayVariable_Local() - { + public void TestResolveArrayVariable_Local() { string xml = "int Foo() {" + " if(MethodCall()) {" + " int* bar = malloc(SIZE);" + @@ -1796,7 +1726,7 @@ public void TestResolveArrayVariable_Local() " }" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CSharp, new Collection() { }, false); + string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLa, "a.cpp"); @@ -1812,8 +1742,7 @@ public void TestResolveArrayVariable_Local() } [Test] - public void TestResolveArrayVariable_Field() - { + public void TestResolveArrayVariable_Field() { string xml = "class A {" + "public:" + " char* Foo;" + @@ -1823,7 +1752,7 @@ public void TestResolveArrayVariable_Field() " }" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1837,8 +1766,7 @@ public void TestResolveArrayVariable_Field() } [Test] - public void TestResolveCallOnArrayVariable() - { + public void TestResolveCallOnArrayVariable() { //#include string xml = "const int SIZE = 5;" + "class Foo {" + @@ -1855,7 +1783,7 @@ public void TestResolveCallOnArrayVariable() " return 0;" + "}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); @@ -1873,8 +1801,7 @@ public void TestResolveCallOnArrayVariable() } [Test] - public void TestTypeUseForOtherNamespace() - { + public void TestTypeUseForOtherNamespace() { string c_xml = "namespace A {" + " namespace B {" + " class C {" + diff --git a/ABB.SrcML.Data/AbstractCodeParser.cs b/ABB.SrcML.Data/AbstractCodeParser.cs index f9c2cf5..fe22727 100644 --- a/ABB.SrcML.Data/AbstractCodeParser.cs +++ b/ABB.SrcML.Data/AbstractCodeParser.cs @@ -1122,15 +1122,17 @@ protected virtual Expression ParseExpression(XElement element, ParserContext con exp = ParseNameUseElement(element, context); } else if(element.Name == SRC.Type) { exp = ParseTypeUseElement(element, context); - } else if(element.Name == OP.Operator) { + } else if(element.Name == SRC.Operator) { exp = ParseOperatorElement(element, context); } else if(element.Name == SRC.Call) { exp = ParseCallElement(element, context); - } else if(element.Name == LIT.Literal) { + } else if(element.Name == SRC.Literal) { exp = ParseLiteralElement(element, context); } else if(element.Name == SRC.Comment) { //skip - } else if(element.Name == SRC.Class && ParserLanguage == Language.Java) { + } else if (element.Name == POS.Position) { + //skip + } else if (element.Name == SRC.Class && ParserLanguage == Language.Java) { //anonymous class, skip //TODO: add parsing for anonymous classes in Java } else if(element.Name.Namespace == CPP.NS) { @@ -1336,8 +1338,9 @@ protected virtual Expression ParseNameUseElement(XElement nameElement, ParserCon return ParseVariableUse(nameElement, context); } - if(nameElement.HasElements) { - return ParseExpression(nameElement.Elements(), context); + var eleList = nameElement.Elements();//need to always generate this now? Is there a better way? + if (eleList.Count() > 1) { //position is always in name, so check to see if there's something more here. + return ParseExpression(eleList, context); } //no children @@ -1353,14 +1356,14 @@ protected virtual Expression ParseNameUseElement(XElement nameElement, ParserCon /// /// Creates an OperatorUse object from the given operator element. /// - /// The OP.Operator element to parse. + /// The SRC.Operator element to parse. /// The parser context to use. /// An OperatorUse corresponding to . protected virtual OperatorUse ParseOperatorElement(XElement operatorElement, ParserContext context) { if(operatorElement == null) throw new ArgumentNullException("operatorElement"); - if(operatorElement.Name != OP.Operator) - throw new ArgumentException("should be an OP.Operator", "operatorElement"); + if(operatorElement.Name != SRC.Operator) + throw new ArgumentException("should be an SRC.Operator", "operatorElement"); if(context == null) throw new ArgumentNullException("context"); @@ -1521,7 +1524,7 @@ protected virtual Expression ParseCallElement(XElement callElement, ParserContex } //check if this is a call to a constructor - if(callElement.ElementsBeforeSelf().Any(e => e.Name == OP.Operator && e.Value == "new")) { + if(callElement.ElementsBeforeSelf().Any(e => e.Name == SRC.Operator && e.Value == "new")) { mc.IsConstructor = true; } var parentElement = callElement.Parent; @@ -1566,7 +1569,7 @@ protected virtual Expression ParseCallElement(XElement callElement, ParserContex protected virtual LiteralUse ParseLiteralElement(XElement literalElement, ParserContext context) { if(literalElement == null) throw new ArgumentNullException("literalElement"); - if(literalElement.Name != LIT.Literal) + if(literalElement.Name != SRC.Literal) throw new ArgumentException("Must be a LIT.Literal element", "literalElement"); if(context == null) throw new ArgumentNullException("context"); diff --git a/ABB.SrcML.Data/LiteralUse.cs b/ABB.SrcML.Data/LiteralUse.cs index 20a98df..70762dc 100644 --- a/ABB.SrcML.Data/LiteralUse.cs +++ b/ABB.SrcML.Data/LiteralUse.cs @@ -45,7 +45,7 @@ public class LiteralUse : Expression { public static LiteralKind GetLiteralKind(XElement literalElement) { if(literalElement == null) throw new ArgumentNullException("literalElement"); - if(literalElement.Name != LIT.Literal) + if(literalElement.Name != SRC.Literal) throw new ArgumentException("should be of type LIT.Literal", "literalElement"); var typeAttribute = literalElement.Attribute("type"); diff --git a/ABB.SrcML/AbstractDocument.cs b/ABB.SrcML/AbstractDocument.cs index 65ec4fc..20027b0 100644 --- a/ABB.SrcML/AbstractDocument.cs +++ b/ABB.SrcML/AbstractDocument.cs @@ -115,7 +115,7 @@ public static void WriteXmlnsAttributes(XmlWriter writer) writer.WriteAttributeString("xmlns", CPP.Prefix, null, CPP.NS.NamespaceName); writer.WriteAttributeString("xmlns", LIT.Prefix, null, LIT.NS.NamespaceName); - writer.WriteAttributeString("xmlns", OP.Prefix, null, OP.NS.NamespaceName); + writer.WriteAttributeString("xmlns", SRC.Prefix, null, SRC.NS.NamespaceName); writer.WriteAttributeString("xmlns", POS.Prefix, null, POS.NS.NamespaceName); writer.WriteAttributeString("xmlns", TYPE.Prefix, null, TYPE.NS.NamespaceName); } diff --git a/ABB.SrcML/Namespaces/OP.cs b/ABB.SrcML/Namespaces/OP.cs index 9fe0fd7..c31a424 100644 --- a/ABB.SrcML/Namespaces/OP.cs +++ b/ABB.SrcML/Namespaces/OP.cs @@ -13,16 +13,17 @@ using System.Collections.Generic; using System.Linq; using System.Xml.Linq; - +///DEPRECATED. Check SRC.cs for operator. namespace ABB.SrcML { + /* /// /// The operator namespace marks up operators ('-<', '.', '+', '-') with the Operator element. /// - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "OP")] - public sealed class OP + [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SRC")] + public sealed class SRC { - private OP() + private SRC() { } @@ -33,7 +34,7 @@ private OP() public static readonly XNamespace NS = "http://www.sdml.info/srcML/operator"; /// - /// XMLNS prefix for the SrcML OP namespace + /// XMLNS prefix for the SrcML SRC namespace /// public const string Prefix = "op"; @@ -48,4 +49,5 @@ private OP() /// public static readonly XName Operator = NS + "operator"; } + */ } diff --git a/ABB.SrcML/Namespaces/POS.cs b/ABB.SrcML/Namespaces/POS.cs index b3dc481..821fb58 100644 --- a/ABB.SrcML/Namespaces/POS.cs +++ b/ABB.SrcML/Namespaces/POS.cs @@ -34,7 +34,7 @@ private POS() public static readonly XNamespace NS = "http://www.srcML.org/srcML/position"; /// - /// XMLNS prefix for the SrcML OP namespace + /// XMLNS prefix for the SrcML SRC namespace /// public const string Prefix = "pos"; @@ -53,5 +53,9 @@ private POS() /// public static readonly XName Column = NS + "column"; + /// + /// Position tag + /// + public static readonly XName Position = NS + "position"; } } diff --git a/ABB.SrcML/Namespaces/SRC.cs b/ABB.SrcML/Namespaces/SRC.cs index f8cd6f2..deb9b92 100644 --- a/ABB.SrcML/Namespaces/SRC.cs +++ b/ABB.SrcML/Namespaces/SRC.cs @@ -53,7 +53,19 @@ public static class SRC { /// /// TODO document comment attributes. public static readonly XName Comment = NS + "comment"; + + // Operator + /// + /// markup for the operator tag + /// + + public static readonly XName Operator = NS + "operator"; + // Literal + /// + /// markup for the literal tag + /// + public static readonly XName Literal = NS + "literal"; // access specifiers /// /// markup for the public access specifier. diff --git a/ABB.SrcML/Src2SrcMLRunner.cs b/ABB.SrcML/Src2SrcMLRunner.cs index 0a38d4b..523d06f 100644 --- a/ABB.SrcML/Src2SrcMLRunner.cs +++ b/ABB.SrcML/Src2SrcMLRunner.cs @@ -43,7 +43,7 @@ public Src2SrcMLRunner() /// /// The application directory. public Src2SrcMLRunner(string applicationDirectory) - : this(applicationDirectory, new[] {LIT.ArgumentLabel, OP.ArgumentLabel, TYPE.ArgumentLabel, POS.ArgumentLabel}) {} + : this(applicationDirectory, new[] {LIT.ArgumentLabel, TYPE.ArgumentLabel, POS.ArgumentLabel}) {} /// /// Initializes a new instance of the class. diff --git a/ABB.SrcML/SrcMLFile.cs b/ABB.SrcML/SrcMLFile.cs index 0ff349f..b802b92 100644 --- a/ABB.SrcML/SrcMLFile.cs +++ b/ABB.SrcML/SrcMLFile.cs @@ -143,7 +143,7 @@ public static void WriteXmlnsAttributes(XmlWriter writer) { writer.WriteAttributeString("xmlns", CPP.Prefix, null, CPP.NS.NamespaceName); writer.WriteAttributeString("xmlns", LIT.Prefix, null, LIT.NS.NamespaceName); - writer.WriteAttributeString("xmlns", OP.Prefix, null, OP.NS.NamespaceName); + writer.WriteAttributeString("xmlns", SRC.Prefix, null, SRC.NS.NamespaceName); writer.WriteAttributeString("xmlns", POS.Prefix, null, POS.NS.NamespaceName); writer.WriteAttributeString("xmlns", TYPE.Prefix, null, TYPE.NS.NamespaceName); } diff --git a/ABB.SrcML/SrcMLGenerator.cs b/ABB.SrcML/SrcMLGenerator.cs index c11ac23..4b81fe3 100644 --- a/ABB.SrcML/SrcMLGenerator.cs +++ b/ABB.SrcML/SrcMLGenerator.cs @@ -66,7 +66,7 @@ public IEnumerable SupportedLanguages { /// public SrcMLGenerator() : base() { defaultExecutable = new Src2SrcMLRunner2(); - defaultArguments = new[] { LIT.ArgumentLabel, OP.ArgumentLabel, POS.ArgumentLabel, TYPE.ArgumentLabel }; + defaultArguments = new[] { LIT.ArgumentLabel, POS.ArgumentLabel, TYPE.ArgumentLabel }; nonDefaultExecutables = new Dictionary(); nonDefaultArguments = new Dictionary(); DetectNonDefaultExecutables(); @@ -76,7 +76,7 @@ public SrcMLGenerator() : base() { /// Creates a new SrcMLGenerator /// /// The directory containing the default srcml executables to use. - public SrcMLGenerator(string defaultExecutableDirectory) : this(defaultExecutableDirectory, new[] { LIT.ArgumentLabel, OP.ArgumentLabel, POS.ArgumentLabel, TYPE.ArgumentLabel }) { } + public SrcMLGenerator(string defaultExecutableDirectory) : this(defaultExecutableDirectory, new[] { LIT.ArgumentLabel, POS.ArgumentLabel, TYPE.ArgumentLabel }) { } /// /// Creates a new SrcMLGenerator diff --git a/ABB.SrcML/SrcMLNamespaces.cs b/ABB.SrcML/SrcMLNamespaces.cs index 364986c..ff9cd89 100644 --- a/ABB.SrcML/SrcMLNamespaces.cs +++ b/ABB.SrcML/SrcMLNamespaces.cs @@ -23,7 +23,7 @@ public class SrcMLNamespaces { static SrcMLNamespaces() { nsManager.AddNamespace(CPP.Prefix, CPP.NS.NamespaceName); nsManager.AddNamespace(LIT.Prefix, LIT.NS.NamespaceName); - nsManager.AddNamespace(OP.Prefix, OP.NS.NamespaceName); + nsManager.AddNamespace(SRC.Prefix, SRC.NS.NamespaceName); nsManager.AddNamespace(POS.Prefix, POS.NS.NamespaceName); nsManager.AddNamespace(SRC.Prefix, SRC.NS.NamespaceName); nsManager.AddNamespace(TYPE.Prefix, TYPE.NS.NamespaceName); From 03021832a968b07e5341549d731ba777764185b8 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Wed, 13 Jan 2016 18:02:44 -0500 Subject: [PATCH 02/17] Changes to abstract code parser and several unit tests. Mostly removing some of the bad parts of the auto transformation I wrote to convert the unit tests (there're still more to remove) and a lot of changing things in the parser or in DSes the parser uses so that it expects the new version of srcML. Most CPP tests passing at this point. --- .../CPlusPlusCodeParserTests.cs | 260 ++++++++++-------- ABB.SrcML.Data/AbstractCodeParser.cs | 24 +- ABB.SrcML.Data/CPlusPlusCodeParser.cs | 9 +- ABB.SrcML/Namespaces/SRC.cs | 7 +- ABB.SrcML/SrcMLRunner.cs | 2 +- .../SyntacticCategoryTest.cs | 2 +- 6 files changed, 179 insertions(+), 125 deletions(-) diff --git a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs index 59b9559..c2ccb1a 100644 --- a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs +++ b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs @@ -137,10 +137,7 @@ public void TestExternStatement_Single() { [Test] public void TestExternStatement_Block() { - string xml = "extern \"C\" {" + - " int globalVar1;" + - " int globalVar2;" + - "}"; + string xml = "extern \"C\" {\n int globalVar1; \nint globalVar2;}"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -157,11 +154,11 @@ public void TestExternStatement_Block() { [Test] public void TestConstructor_CallToSelf() { - string xml = "class MyClass {" + - "public:" + - " MyClass() : MyClass(0) { } " + - " MyClass(int foo) { } " + - "};"; + string xml = @"class MyClass { + public: + MyClass() : MyClass(0) { } + MyClass(int foo) { } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -424,11 +421,11 @@ public void TestGetAliases_NestedImportClass() { [Test] [Category("SrcMLUpdate")] public void TestGetAliases_NestedTypeAlias() { - string xml = "using namespace x::y::z;" + - "if(bar) {" + - " using x = foo::bar::baz;" + - " foo = 17;" + - "}"; + string xml = @"using namespace x::y::z; + if(bar) { + using x = foo::bar::baz; + foo = 17; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -439,6 +436,7 @@ public void TestGetAliases_NestedTypeAlias() { Assert.IsNotNull(foo); var aliases = foo.GetAliases().ToList(); Assert.AreEqual(1, aliases.Count); + string b = aliases[0].Target.ToString(); Assert.AreEqual("foo :: bar :: baz", aliases[0].Target.ToString()); Assert.AreEqual("x", aliases[0].AliasName); var imports = foo.GetImports().ToList(); @@ -550,27 +548,27 @@ class B { [Category("SrcMLUpdate")] public void TestAlias_NameResolution_TypeAlias() { //A.cpp - string xmlA = "namespace Foo {" + - " namespace Bar {" + - " class Baz {" + - " public:" + - " static void DoTheThing() { }" + - " }" + - "}"; + string xmlA = @"namespace Foo { + namespace Bar { + class Baz { + public: + static void DoTheThing() { } + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "using X = Foo::Bar::Baz;" + - "namespace A {" + - " class B {" + - " public:" + - " B() {" + - " X::DoTheThing();" + - " }" + - " }" + - "}"; + string xmlB = @"using X = Foo::Bar::Baz; + namespace A { + class B { + public: + B() { + X::DoTheThing(); + } + } + }"; LibSrcMLRunner runB = new LibSrcMLRunner(); string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -789,8 +787,7 @@ public void TestCreateTypeDefinitions_Struct() { [Test] public void TestCreateTypeDefinitions_Union() { - string xml = " union A { int a; char b;" + - "};"; + string xml = @" union A { int a; char b; };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -881,13 +878,16 @@ public void TestMethodCallCreation_LengthyCallingExpression() { public void TestMergeWithUsing() { string headerXml = " namespace A { class B { void Foo(); }; }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(headerXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - string implementationXml = "using namespace A;" + - "void B::Foo() { }"; + string implementationXml = @"using namespace A; void B::Foo() { }"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestc = runB.GenerateSrcMLFromString(implementationXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var headerScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h")); - var implementationScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(implementationXml, "A.cpp")); + var headerScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h")); + var implementationScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "A.cpp")); var globalScope = headerScope.Merge(implementationScope); Assert.AreEqual(1, globalScope.ChildStatements.OfType().Count()); @@ -905,8 +905,8 @@ public void TestMergeWithUsing() { Assert.AreEqual(0, methodFoo.ChildStatements.Count); Assert.AreEqual(2, methodFoo.Locations.Count); - headerScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h")); - implementationScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(implementationXml, "A.cpp")); + headerScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h")); + implementationScope = codeParser.ParseFileUnit(fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "A.cpp")); var globalScope_implementationFirst = implementationScope.Merge(headerScope); @@ -933,6 +933,8 @@ public void TestMethodCallCreation_WithConflictingMethodNames() { " bool Contains() { b.Contains(); }" + "};"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(a_xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); //# B.h string b_xml = "class B {" + @@ -940,9 +942,12 @@ public void TestMethodCallCreation_WithConflictingMethodNames() { " bool Contains() { return true; }" + "};"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestb = runB.GenerateSrcMLFromString(b_xml, "B.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + - var fileUnitA = fileSetup.GetFileUnitForXmlSnippet(a_xml, "A.h"); - var fileUnitB = fileSetup.GetFileUnitForXmlSnippet(b_xml, "B.h"); + var fileUnitA = fileSetup.GetFileUnitForXmlSnippet(srcMLtestb, "A.h"); + var fileUnitB = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "B.h"); var scopeForA = codeParser.ParseFileUnit(fileUnitA); var scopeForB = codeParser.ParseFileUnit(fileUnitB); @@ -969,16 +974,18 @@ public void TestMethodCallCreation_WithConflictingMethodNames() { [Test] public void TestMethodCallCreation_WithThisKeyword() { - string a_xml = "class A {" + - " void Bar() { }" + - " class B {" + - " int a;" + - " void Foo() { this->Bar(); }" + - " void Bar() { return this->a; }" + - " };" + - "};"; - - var fileUnit = fileSetup.GetFileUnitForXmlSnippet(a_xml, "A.cpp"); + string a_xml = @"class A { + void Bar() { } + class B { + int a; + void Foo() { this->Bar(); } + void Bar() { return this->a; } + }; + };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(a_xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var fileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.cpp"); var globalScope = codeParser.ParseFileUnit(fileUnit); var aDotBar = globalScope.GetNamedChildren("A").First().GetNamedChildren("Bar").FirstOrDefault(); @@ -1076,20 +1083,27 @@ public void TestMethodCallCreation_CallGlobalNamespace() { [Test] public void TestMethodCallFindMatches() { - string headerXml = " # A.h class A { int context;" + - " public:" + - " A(); };"; + string headerXml = @"class A { int context; + public: + A(); };"; - string implementationXml = " # A.cpp #include \"A.h\"" + - " A: :A() {" + - " }"; + string implementationXml = "#include \"A.h\" A: :A() {}"; - string mainXml = " # main.cpp #include \"A.h\" int main() { A a = A(); return 0; }"; + string mainXml = "#include \"A.h\" int main() { A a = A(); return 0; }"; - var headerElement = fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h"); - var implementationElement = fileSetup.GetFileUnitForXmlSnippet(implementationXml, "A.cpp"); - var mainElement = fileSetup.GetFileUnitForXmlSnippet(mainXml, "main.cpp"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(headerXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestb = runB.GenerateSrcMLFromString(implementationXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + LibSrcMLRunner runC = new LibSrcMLRunner(); + string srcMLtestc = runC.GenerateSrcMLFromString(mainXml, "main.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var headerElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h"); + var implementationElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtestb, "A.cpp"); + var mainElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "main.cpp"); var header = codeParser.ParseFileUnit(headerElement); var implementation = codeParser.ParseFileUnit(implementationElement); @@ -1127,16 +1141,22 @@ public void TestMethodCallFindMatches_WithArguments() { public: A(int value); };"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(headerXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); string implementationXml = "#include \"A.h\" A: :A(int value) { context = value;}"; + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestb = runB.GenerateSrcMLFromString(implementationXml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); string mainXml = "#include \"A.h\" int main() { int startingState = 0; A *a = new A(startingState); return startingState; }"; + LibSrcMLRunner runC = new LibSrcMLRunner(); + string srcMLtestc = runC.GenerateSrcMLFromString(mainXml, "main.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var headerElement = fileSetup.GetFileUnitForXmlSnippet(headerXml, "A.h"); - var implementationElement = fileSetup.GetFileUnitForXmlSnippet(implementationXml, "A.cpp"); - var mainElement = fileSetup.GetFileUnitForXmlSnippet(mainXml, "main.cpp"); + var headerElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h"); + var implementationElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtestb, "A.cpp"); + var mainElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "main.cpp"); var header = codeParser.ParseFileUnit(headerElement); var implementation = codeParser.ParseFileUnit(implementationElement); @@ -1340,7 +1360,10 @@ public void TestMethodDefinition_DefaultArguments() { public void TestTwoVariableDeclarations() { string testXml = "int a,b;"; - var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cpp"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(testUnit); @@ -1357,7 +1380,10 @@ public void TestTwoVariableDeclarations() { [Test] public void TestThreeVariableDeclarations() { string testXml = "int a,b,c;"; - var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cpp"); + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(testUnit); @@ -1379,7 +1405,10 @@ public void TestVariablesWithSpecifiers() { "static int B;" + "static const Foo C;" + "extern Foo D;"; - var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cpp"); + + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.cpp"); var globalScope = codeParser.ParseFileUnit(testUnit); Assert.AreEqual(4, globalScope.ChildStatements.Count); @@ -1411,11 +1440,7 @@ public void TestVariablesWithSpecifiers() { [Test] public void TestLiteralUse() { - string xml = "a = 17;" + - "foo = watermelon" + - "if(true) { " + - " c = 'h';" + - "}"; + string xml = "a = 17; foo = \"watermelon\"; if(true) { c = 'h';}"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1468,17 +1493,19 @@ public void TestIfElse() { Assert.AreEqual(1, ifStmt.ChildStatements.Count); Assert.AreEqual(2, ifStmt.ElseStatements.Count); } - + /// + /// Test is testing for proper nesting of else and if in srcML archive. + /// [Test] public void TestIfElseIf() { - string xml = "if(a==b) {" + - " i = 17;" + - "} else if(a==c) {" + - " i = 42;" + - " foo();" + - "} else {" + - " ReportError();" + - "}"; + string xml = @"if(a==b) { + i = 17; + } else if(a==c) { + i = 42; + foo(); + } else { + ReportError(); + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1490,14 +1517,14 @@ public void TestIfElseIf() { Assert.IsNull(ifStmt.Content); Assert.IsNotNull(ifStmt.Condition); Assert.AreEqual(1, ifStmt.ChildStatements.Count); - Assert.AreEqual(1, ifStmt.ElseStatements.Count); + Assert.AreEqual(2, ifStmt.ElseStatements.Count); var ifStmt2 = ifStmt.ElseStatements.First() as IfStatement; Assert.IsNotNull(ifStmt2); Assert.IsNull(ifStmt2.Content); Assert.IsNotNull(ifStmt2.Condition); Assert.AreEqual(2, ifStmt2.ChildStatements.Count); - Assert.AreEqual(1, ifStmt2.ElseStatements.Count); + Assert.AreEqual(0, ifStmt2.ElseStatements.Count); } [Test] @@ -1676,15 +1703,27 @@ public void TestVariableDeclaredInCallingObjectWithParentClass() { string c_xml = "class C : A { };"; - string d_xml = "class D {" + - " C c;" + - " void Bar() { c.b.Foo(); }" + - "};"; + string d_xml = @"class D { + C c; + void Bar() { c.b.Foo(); } + };"; + + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLtesta = runA.GenerateSrcMLFromString(a_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + LibSrcMLRunner runB = new LibSrcMLRunner(); + string srcMLtestb = runB.GenerateSrcMLFromString(b_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - var aUnit = fileSetup.GetFileUnitForXmlSnippet(a_xml, "A.h"); - var bUnit = fileSetup.GetFileUnitForXmlSnippet(b_xml, "B.h"); - var cUnit = fileSetup.GetFileUnitForXmlSnippet(c_xml, "C.h"); - var dUnit = fileSetup.GetFileUnitForXmlSnippet(d_xml, "D.h"); + LibSrcMLRunner runC = new LibSrcMLRunner(); + string srcMLtestc = runC.GenerateSrcMLFromString(c_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + LibSrcMLRunner runD = new LibSrcMLRunner(); + string srcMLtestd = runD.GenerateSrcMLFromString(d_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + + var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.h"); + var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestb, "B.h"); + var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "C.h"); + var dUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestd, "D.h"); var globalScope = codeParser.ParseFileUnit(aUnit); globalScope = globalScope.Merge(codeParser.ParseFileUnit(bUnit)); @@ -1802,27 +1841,32 @@ public void TestResolveCallOnArrayVariable() { [Test] public void TestTypeUseForOtherNamespace() { - string c_xml = "namespace A {" + - " namespace B {" + - " class C {" + - " int Foo() { }" + - " };" + - " }" + - "}"; + string c_xml = @"namespace A { + namespace B { + class C { + int Foo() { } + }; + } + }"; - string e_xml = "using namespace A::B;" + - "namespace D {" + - " class E {" + - " void main() {" + - " C c = new C();" + - " c.Foo();" + - " }" + - " };" + - "}"; + string e_xml = @"using namespace A::B; + namespace D { + class E { + void main() { + C c = new C(); + c.Foo(); + } + }; + }"; + + LibSrcMLRunner runC = new LibSrcMLRunner(); + string srcMLtestc= runC.GenerateSrcMLFromString(c_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "C.cpp"); - var cUnit = fileSetup.GetFileUnitForXmlSnippet(c_xml, "C.cpp"); - var eUnit = fileSetup.GetFileUnitForXmlSnippet(e_xml, "E.cpp"); + LibSrcMLRunner runE = new LibSrcMLRunner(); + string srcMLteste = runE.GenerateSrcMLFromString(e_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var eUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLteste, "E.cpp"); NamespaceDefinition globalScope = codeParser.ParseFileUnit(cUnit); globalScope = globalScope.Merge(codeParser.ParseFileUnit(eUnit)); diff --git a/ABB.SrcML.Data/AbstractCodeParser.cs b/ABB.SrcML.Data/AbstractCodeParser.cs index fe22727..0b760db 100644 --- a/ABB.SrcML.Data/AbstractCodeParser.cs +++ b/ABB.SrcML.Data/AbstractCodeParser.cs @@ -205,13 +205,18 @@ protected virtual Statement ParseStatement(XElement element, ParserContext conte stmt = ParseEmptyStatementElement(element, context); } else if(element.Name == SRC.Lock) { stmt = ParseLockElement(element, context); - } else if(element.Name == SRC.Comment) { + } else if(element.Name == POS.Position) { + // do nothing. we are ignoring position (for now) + } else if (element.Name == SRC.Using) { + ; + } else if (element.Name == SRC.Comment) { // do nothing. we are ignoring comments - } else if(element.Name == SRC.Package) { + } else if (element.Name == SRC.Package) { //do nothing. This is already handled in JavaCodeParser.ParseUnitElement() } else if(element.Name.Namespace == CPP.NS) { //do nothing. skip any cpp preprocessor macros } else if(NotImplementedStatements.Contains(element.Name)) { + ; //do nothing. These are known and we're skipping them for now. } else { LogUnknown(element, context, "ParseStatement"); @@ -364,7 +369,7 @@ protected virtual IfStatement ParseIfElement(XElement ifElement, ParserContext c ifStmt.AddChildStatement(ParseStatement(thenChild, context)); } } - } else if(ifChild.Name == SRC.Else) { + } else if(ifChild.Name == SRC.ElseIf || ifChild.Name == SRC.Else) { //add the else statements foreach(var elseChild in ifChild.Elements()) { if(elseChild.Name == SRC.Block) { @@ -1022,7 +1027,7 @@ protected virtual ExternStatement ParseExternElement(XElement externElement, Par es.AddLocation(context.CreateLocation(externElement)); foreach(var exChild in externElement.Elements()) { - if(exChild.Name == LIT.Literal) { + if(exChild.Name == SRC.Literal) { es.LinkageType = exChild.Value; } else if(exChild.Name == SRC.Block) { //add children from block @@ -1263,7 +1268,7 @@ protected virtual Expression ParseExpressionElement(XElement expElement, ParserC /// A VariableDeclaration object corresponding to the given element. protected virtual VariableDeclaration ParseDeclarationElement(XElement declElement, ParserContext context) { //TODO: can/should this handle function_decls as well as decls? ParseParameterElement may pass in a function_decl - + //NOTE: When the declaration is using f = bla this won't work because there is no decl on the inside. Fix. if(declElement == null) throw new ArgumentNullException("declElement"); if(!(declElement.Name == SRC.Declaration || declElement.Name == SRC.FunctionDeclaration)) @@ -1424,8 +1429,8 @@ protected virtual TypeUse ParseTypeUseElement(XElement typeUseElement, ParserCon if(argumentListElement != null) { typeArguments = from argument in argumentListElement.Elements(SRC.Argument) - where argument.Elements(SRC.Name).Any() - select ParseTypeUseElement(argument.Element(SRC.Name), context); + where argument.Descendants(SRC.Name).Any() + select ParseTypeUseElement(argument.Descendants(SRC.Name).First(), context); // if this is a generic type use and there is a prefix (A::B::C) then the last name // element will actually be the first child of lastNameElement if(prefix != null) { @@ -1499,8 +1504,9 @@ protected virtual Expression ParseCallElement(XElement callElement, ParserContex //parse the name element for the call var nameElement = callElement.Element(SRC.Name); + var position = nameElement.Element(POS.Position); if(nameElement != null) { - if(!nameElement.HasElements) { + if(position != null) { methodNameElement = nameElement; } else { methodNameElement = nameElement.Elements(SRC.Name).Last(); @@ -1852,7 +1858,7 @@ protected virtual IEnumerable GetChildExpressions(XElement element) { if(element == null) throw new ArgumentNullException("element"); - return element.Elements().Where(e => e.Name == SRC.Expression || e.Name == SRC.Declaration || e.Name == SRC.FunctionDeclaration); + return element.Elements().Where(e => e.Name == SRC.Expression || e.Name == SRC.Declaration || e.Name == SRC.FunctionDeclaration || e.Name == SRC.Type); } /// diff --git a/ABB.SrcML.Data/CPlusPlusCodeParser.cs b/ABB.SrcML.Data/CPlusPlusCodeParser.cs index b63d069..630660d 100644 --- a/ABB.SrcML.Data/CPlusPlusCodeParser.cs +++ b/ABB.SrcML.Data/CPlusPlusCodeParser.cs @@ -281,15 +281,13 @@ protected override Statement ParseAliasElement(XElement aliasElement, ParserCont throw new ArgumentNullException("context"); Statement stmt = null; - bool containsNamespaceKeyword = (from textNode in GetTextNodes(aliasElement) - where textNode.Value.Contains("namespace") - select textNode).Any(); - if(containsNamespaceKeyword) { + var namespaceElement = aliasElement.Element(SRC.Namespace); + if(namespaceElement != null) { //import statement var import = new ImportStatement() {ProgrammingLanguage = ParserLanguage}; import.AddLocation(context.CreateLocation(aliasElement)); - var nameElement = aliasElement.Element(SRC.Name); + var nameElement = namespaceElement.Element(SRC.Name); if(nameElement != null) { import.ImportedNamespace = ParseNameUseElement(nameElement, context); } @@ -300,6 +298,7 @@ where textNode.Value.Contains("namespace") var alias = new AliasStatement() {ProgrammingLanguage = ParserLanguage}; alias.AddLocation(context.CreateLocation(aliasElement)); + //TODO: Make sure that using descendant is correct for nameElement var nameElement = aliasElement.Element(SRC.Name); var initElement = aliasElement.Element(SRC.Init); if(initElement != null) { diff --git a/ABB.SrcML/Namespaces/SRC.cs b/ABB.SrcML/Namespaces/SRC.cs index deb9b92..e989b87 100644 --- a/ABB.SrcML/Namespaces/SRC.cs +++ b/ABB.SrcML/Namespaces/SRC.cs @@ -208,6 +208,11 @@ public static class SRC { /// public static readonly XName Else = NS + "else"; + /// + /// markup for the else if tag + /// + public static readonly XName ElseIf = NS + "elseif"; + // while statement /// /// markup for the while tag @@ -363,7 +368,7 @@ public static class SRC { /// /// markup for the member_list tag /// - public static readonly XName MemberList = NS + "member_list"; + public static readonly XName MemberList = NS + "member_init_list"; /// /// markup for the constructor_decl tag diff --git a/ABB.SrcML/SrcMLRunner.cs b/ABB.SrcML/SrcMLRunner.cs index 03259ed..4aea4d4 100644 --- a/ABB.SrcML/SrcMLRunner.cs +++ b/ABB.SrcML/SrcMLRunner.cs @@ -106,7 +106,7 @@ public SrcMLRunner(string applicationDirectory, string executableName, IEnumerab /// The application directory. /// Name of the executable. public SrcMLRunner(string applicationDirectory, string executableName) - : this(applicationDirectory, executableName, new[] { LIT.ArgumentLabel, OP.ArgumentLabel, TYPE.ArgumentLabel }) + : this(applicationDirectory, executableName, new[] { LIT.ArgumentLabel, TYPE.ArgumentLabel }) { } diff --git a/VisualStudio/SDML.SrcMLVSAddin.SyntaticCategory.Test/SyntacticCategoryTest.cs b/VisualStudio/SDML.SrcMLVSAddin.SyntaticCategory.Test/SyntacticCategoryTest.cs index 72303fe..14c4e02 100644 --- a/VisualStudio/SDML.SrcMLVSAddin.SyntaticCategory.Test/SyntacticCategoryTest.cs +++ b/VisualStudio/SDML.SrcMLVSAddin.SyntaticCategory.Test/SyntacticCategoryTest.cs @@ -32,7 +32,7 @@ public class SyntacticCategoryTest { public IEnumerable QueryForNew(XElement element) { - var uses = from use in element.Descendants(OP.Operator) + var uses = from use in element.Descendants(SRC.Operator) where use.Value == "new" select use; return uses; From 9336b0934a71168f025444da5baa95a22a0b6231 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Wed, 13 Jan 2016 18:03:01 -0500 Subject: [PATCH 03/17] asdsadas --- SrcML.NET.sln | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/SrcML.NET.sln b/SrcML.NET.sln index 829aa8d..af07c0b 100644 --- a/SrcML.NET.sln +++ b/SrcML.NET.sln @@ -68,6 +68,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ABB.SrcML.Data.Test", "ABB. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibSrcMLWrapper", "LibSrcMLWrapper\LibSrcMLWrapper.vcxproj", "{5A139FFE-60CB-4C14-B565-73009393B47A}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{03CFF097-ECA2-423F-842E-16D4C7F5DCD0}" + ProjectSection(SolutionItems) = preProject + .nuget\packages.config = .nuget\packages.config + EndProjectSection +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU From 382e5e8b6695fdfc96a0544d0095a140b5a5ba42 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Wed, 13 Jan 2016 18:03:28 -0500 Subject: [PATCH 04/17] Revert "asdsadas" This reverts commit 9336b0934a71168f025444da5baa95a22a0b6231. --- SrcML.NET.sln | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SrcML.NET.sln b/SrcML.NET.sln index af07c0b..829aa8d 100644 --- a/SrcML.NET.sln +++ b/SrcML.NET.sln @@ -68,11 +68,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ABB.SrcML.Data.Test", "ABB. EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "LibSrcMLWrapper", "LibSrcMLWrapper\LibSrcMLWrapper.vcxproj", "{5A139FFE-60CB-4C14-B565-73009393B47A}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{03CFF097-ECA2-423F-842E-16D4C7F5DCD0}" - ProjectSection(SolutionItems) = preProject - .nuget\packages.config = .nuget\packages.config - EndProjectSection -EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU From b831578f76bb4c0f8bda709dc7d76cc715131b78 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Mon, 18 Jan 2016 18:26:41 -0500 Subject: [PATCH 05/17] C++ parser tests mostly pass. 4 of them don't-- will probably skip for now and finish c#/java then come back --- .../CPlusPlusCodeParserTests.cs | 504 +++++++++--------- 1 file changed, 252 insertions(+), 252 deletions(-) diff --git a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs index c2ccb1a..9b0aac3 100644 --- a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs +++ b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs @@ -33,7 +33,7 @@ public void ClassSetup() { [Test] public void TestCreateTypeDefinitions_Class() { - string xml = "class A { };"; + string xml = @"class A { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -51,7 +51,7 @@ public void TestCreateTypeDefinitions_Class() { [Test] public void TestCreateTypeDefinitions_ClassDeclaration() { - string xml = "class A;"; + string xml = @"class A;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -69,9 +69,9 @@ public void TestCreateTypeDefinitions_ClassDeclaration() { [Test] public void TestClassWithDeclaredVariable() { - string xml = "class A {" + - " int a;" + - "};"; + string xml = @"class A { + int a; + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -182,20 +182,20 @@ public void TestConstructor_CallToSelf() { [Test] public void TestConstructor_CallToSuperClass() { - string xml = "class SuperClass {" + - "public:" + - "SuperClass(int foo) { } }; " + - "class SubClass : public SuperClass {" + - "public:" + - "SubClass(int foo) : SuperClass(foo) { } };"; + string xml = @"class SuperClass { + public: + SuperClass(int foo) { } }; + class SubClass : public SuperClass { + public: + SubClass(int foo) : SuperClass(foo) { } };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(unit); - var calledConstructor = globalScope.GetDescendants().First(m => m.Name == "SuperClass" && m.IsConstructor); - var subClassConstructor = globalScope.GetDescendants().First(m => m.Name == "SubClass" && m.IsConstructor); + var calledConstructor = globalScope.GetDescendants().First(m => m.Name == @"SuperClass" && m.IsConstructor); + var subClassConstructor = globalScope.GetDescendants().First(m => m.Name == @"SubClass" && m.IsConstructor); Assert.IsNotNull(subClassConstructor); Assert.IsNotNull(calledConstructor); Assert.AreEqual(1, subClassConstructor.ConstructorInitializers.Count); @@ -210,12 +210,12 @@ public void TestConstructor_CallToSuperClass() { [Test] public void TestConstructor_InitializeBuiltinTypeField() { //"test.h" - string xml = "class Quux" + - "{" + - " int _my_int;" + - "public:" + - " Quux() : _my_int(5) { }" + - "};"; + string xml = @"class Quux + { + int _my_int; + public: + Quux() : _my_int(5) { } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -239,25 +239,25 @@ public void TestConstructor_InitializeBuiltinTypeField() { [Test] public void TestConstructor_InitializeField() { //"test.h" - string xml = "class Foo" + - "{" + - "public:" + - " Foo(int a) { }" + - "};" + - "class Bar" + - "{" + - " Foo baz;" + - "public:" + - " Bar() : baz(42) { }" + - "};"; + string xml = @"class Foo + { + public: + Foo(int a) { } + }; + class Bar + { + Foo baz; + public: + Bar() : baz(42) { } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); - var fooConstructor = globalScope.GetDescendants().First(m => m.Name == "Foo" && m.IsConstructor); - var barConstructor = globalScope.GetDescendants().First(m => m.Name == "Bar" && m.IsConstructor); + var fooConstructor = globalScope.GetDescendants().First(m => m.Name == @"Foo" && m.IsConstructor); + var barConstructor = globalScope.GetDescendants().First(m => m.Name == @"Bar" && m.IsConstructor); Assert.AreEqual(1, barConstructor.ConstructorInitializers.Count); var fieldCall = barConstructor.ConstructorInitializers[0]; Assert.IsNotNull(fieldCall); @@ -268,7 +268,7 @@ public void TestConstructor_InitializeField() { [Test] public void TestCreateAliasesForFiles_ImportClass() { - string xml = "using A::Foo;"; + string xml = @"using A::Foo;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -286,7 +286,7 @@ public void TestCreateAliasesForFiles_ImportClass() { [Test] public void TestCreateAliasesForFiles_ImportNamespace() { - string xml = "using namespace x::y::z;"; + string xml = @"using namespace x::y::z;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -303,7 +303,7 @@ public void TestCreateAliasesForFiles_ImportNamespace() { [Test] [Category("SrcMLUpdate")] public void TestCreateAliasesForFiles_TypeAlias() { - string xml = "using x = foo::bar::baz;"; + string xml = @"using x = foo::bar::baz;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -321,18 +321,18 @@ public void TestCreateAliasesForFiles_TypeAlias() { [Test] public void TestGetImports() { //A.cpp - string xmlA = "namespace x {" + - " namespace y {" + - " namespace z {}" + - " }" + - "}"; + string xmlA = @"namespace x { + namespace y { + namespace z {} + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "using namespace x::y::z;" + - "foo = 17;"; + string xmlB = @"using namespace x::y::z; + foo = 17;"; LibSrcMLRunner runB = new LibSrcMLRunner(); string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -343,32 +343,32 @@ public void TestGetImports() { var scopeB = codeParser.ParseFileUnit(xmlElementB); var globalScope = scopeA.Merge(scopeB); Assert.AreEqual(3, globalScope.ChildStatements.Count); - var foo = globalScope.ChildStatements[2].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "foo"); + var foo = globalScope.ChildStatements[2].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"foo"); Assert.IsNotNull(foo); var imports = foo.GetImports().ToList(); Assert.AreEqual(1, imports.Count); Assert.AreEqual("x :: y :: z", imports[0].ImportedNamespace.ToString()); - var zDef = globalScope.GetDescendants().FirstOrDefault(ns => ns.Name == "z"); + var zDef = globalScope.GetDescendants().FirstOrDefault(ns => ns.Name == @"z"); Assert.IsNotNull(zDef); - var zUse = imports[0].ImportedNamespace.GetDescendantsAndSelf().First(n => n.Name == "z"); + var zUse = imports[0].ImportedNamespace.GetDescendantsAndSelf().First(n => n.Name == @"z"); Assert.AreSame(zDef, zUse.FindMatches().FirstOrDefault()); } [Test] public void TestGetImports_NestedImportNamespace() { - string xml = "using namespace x::y::z;" + - "if(bar) {" + - " using namespace std;" + - " foo = 17;" + - "}"; + string xml = @"using namespace x::y::z; + if(bar) { + using namespace std; + foo = 17; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); - var foo = globalScope.ChildStatements[1].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "foo"); + var foo = globalScope.ChildStatements[1].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"foo"); Assert.IsNotNull(foo); var imports = foo.GetImports().ToList(); Assert.AreEqual(2, imports.Count); @@ -379,20 +379,20 @@ public void TestGetImports_NestedImportNamespace() { [Test] public void TestGetAliases_NestedImportClass() { //A.cpp - string xmlA = "namespace B {" + - " class Bar {}" + - "}"; + string xmlA = @"namespace B { + class Bar {} + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "using namespace x::y::z;" + - "if(bar) {" + - " using B::Bar;" + - " foo = 17;" + - "}"; + string xmlB = @"using namespace x::y::z; + if(bar) { + using B::Bar; + foo = 17; + }"; LibSrcMLRunner runB = new LibSrcMLRunner(); string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -402,7 +402,7 @@ public void TestGetAliases_NestedImportClass() { var scopeA = codeParser.ParseFileUnit(xmlElementA); var scopeB = codeParser.ParseFileUnit(xmlElementB); var globalScope = scopeA.Merge(scopeB); - var foo = globalScope.ChildStatements[2].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "foo"); + var foo = globalScope.ChildStatements[2].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"foo"); Assert.IsNotNull(foo); var aliases = foo.GetAliases().ToList(); Assert.AreEqual(1, aliases.Count); @@ -412,9 +412,9 @@ public void TestGetAliases_NestedImportClass() { Assert.AreEqual(1, imports.Count); Assert.AreEqual("x :: y :: z", imports[0].ImportedNamespace.ToString()); - var barDef = globalScope.GetDescendants().FirstOrDefault(ns => ns.Name == "Bar"); + var barDef = globalScope.GetDescendants().FirstOrDefault(ns => ns.Name == @"Bar"); Assert.IsNotNull(barDef); - var barUse = aliases[0].Target.GetDescendantsAndSelf().First(n => n.Name == "Bar"); + var barUse = aliases[0].Target.GetDescendantsAndSelf().First(n => n.Name == @"Bar"); Assert.AreSame(barDef, barUse.FindMatches().FirstOrDefault()); } @@ -432,7 +432,7 @@ public void TestGetAliases_NestedTypeAlias() { XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); - var foo = globalScope.ChildStatements[1].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "foo"); + var foo = globalScope.ChildStatements[1].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"foo"); Assert.IsNotNull(foo); var aliases = foo.GetAliases().ToList(); Assert.AreEqual(1, aliases.Count); @@ -446,30 +446,30 @@ public void TestGetAliases_NestedTypeAlias() { [Test] public void TestImport_NameResolution() { //A.cpp - string xmlA = "using namespace Foo::Bar;" + + string xmlA = @"using namespace Foo::Bar; // - "namespace A {" + - " class Robot {" + - " public: " + - " Baz GetThingy() { " + - " Baz* b = new Baz();" + - " return *b;" + - " }" + - " }" + - "}"; + namespace A { + class Robot { + public: + Baz GetThingy() { + Baz* b = new Baz(); + return *b; + } + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); //B.cpp - string xmlB = "namespace Foo {" + - " namespace Bar {" + - " class Baz {" + - " public:" + - " Baz() { }" + - " }" + - "}"; + string xmlB = @"namespace Foo { + namespace Bar { + class Baz { + public: + Baz() { } + } + }"; LibSrcMLRunner runB = new LibSrcMLRunner(); string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -481,17 +481,17 @@ public void TestImport_NameResolution() { var globalScope = scopeA.Merge(scopeB); Assert.AreEqual(3, globalScope.ChildStatements.Count); - var baz = globalScope.GetDescendants().FirstOrDefault(t => t.Name == "Baz"); + var baz = globalScope.GetDescendants().FirstOrDefault(t => t.Name == @"Baz"); Assert.IsNotNull(baz); - var thingy = globalScope.GetDescendants().FirstOrDefault(m => m.Name == "GetThingy"); + var thingy = globalScope.GetDescendants().FirstOrDefault(m => m.Name == @"GetThingy"); Assert.IsNotNull(thingy); var thingyTypes = thingy.ReturnType.FindMatches().ToList(); Assert.AreEqual(1, thingyTypes.Count); Assert.AreSame(baz, thingyTypes[0]); var bazDef = baz.GetNamedChildren("Baz").First(); - var bazCall = thingy.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(mc => mc.Name == "Baz"); + var bazCall = thingy.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(mc => mc.Name == @"Baz"); Assert.IsNotNull(bazCall); Assert.AreSame(bazDef, bazCall.FindMatches().FirstOrDefault()); } @@ -532,11 +532,11 @@ class B { var globalScope = scopeA.Merge(scopeB); Assert.AreEqual(3, globalScope.ChildStatements.Count); - var thingDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == "DoTheThing"); + var thingDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == @"DoTheThing"); Assert.IsNotNull(thingDef); Assert.AreEqual("Baz", ((TypeDefinition)thingDef.ParentStatement).Name); - var bDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == "B"); + var bDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == @"B"); Assert.IsNotNull(bDef); Assert.AreEqual(1, bDef.ChildStatements.Count); var thingCall = bDef.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(); @@ -579,11 +579,11 @@ class B { var globalScope = scopeA.Merge(scopeB); Assert.AreEqual(3, globalScope.ChildStatements.Count); - var thingDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == "DoTheThing"); + var thingDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == @"DoTheThing"); Assert.IsNotNull(thingDef); Assert.AreEqual("Baz", ((TypeDefinition)thingDef.ParentStatement).Name); - var bDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == "B"); + var bDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == @"B"); Assert.IsNotNull(bDef); Assert.AreEqual(1, bDef.ChildStatements.Count); var thingCall = bDef.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(); @@ -593,7 +593,7 @@ class B { [Test] public void TestCreateTypeDefinition_ClassInNamespace() { - string xml = "namespace A { class B { }; }"; + string xml = @"namespace A { class B { }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLB = runA.GenerateSrcMLFromString(xml, "B.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -612,9 +612,9 @@ public void TestCreateTypeDefinition_ClassInNamespace() { [Test] public void TestCreateTypeDefinition_ClassWithMethodDeclaration() { - string xml = " class A {" + - " public:" + - " int foo(int a); };"; + string xml = @" class A { + public: + int foo(int a); };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -635,10 +635,10 @@ public void TestCreateTypeDefinition_ClassWithMethodDeclaration() { [Test] public void TestCreateTypeDefinition_StaticMethod() { - string xml = "class Example {" + - "public:" + - " static int Example::Foo(int bar) { return bar+1; }" + - "};"; + string xml = @"class Example { + public: + static int Example::Foo(int bar) { return bar+1; } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLstatic_method = runA.GenerateSrcMLFromString(xml, "static_method.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -657,7 +657,7 @@ public void TestCreateTypeDefinition_StaticMethod() { [Test] public void TestCreateTypeDefinitions_ClassInFunction() { - string xml = "int main() { class A { }; }"; + string xml = @"int main() { class A { }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLmain = runA.GenerateSrcMLFromString(xml, "main.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -675,7 +675,7 @@ public void TestCreateTypeDefinitions_ClassInFunction() { [Test] public void TestCreateTypeDefinitions_ClassWithInnerClass() { - string xml = "class A { class B { }; };"; + string xml = @"class A { class B { }; };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -694,7 +694,7 @@ public void TestCreateTypeDefinitions_ClassWithInnerClass() { [Test] public void TestCreateTypeDefinitions_ClassWithParents() { - string xml = "class A : B,C,D { };"; + string xml = @"class A : B,C,D { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -720,7 +720,7 @@ public void TestCreateTypeDefinitions_ClassWithParents() { [Test] public void TestCreateTypeDefinitions_ClassWithQualifiedParent() { - string xml = "class D : A::B::C { }"; + string xml = @"class D : A::B::C { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLD = runA.GenerateSrcMLFromString(xml, "D.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -746,7 +746,7 @@ public void TestCreateTypeDefinitions_ClassWithQualifiedParent() { [Test] public void TestCreateTypeDefinitions_InnerClassWithNamespace() { - string xml = "namespace A { class B { class C { }; }; }"; + string xml = @"namespace A { class B { class C { }; }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -771,7 +771,7 @@ public void TestCreateTypeDefinitions_InnerClassWithNamespace() { [Test] public void TestCreateTypeDefinitions_Struct() { - string xml = "struct A { };"; + string xml = @"struct A { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -801,7 +801,7 @@ public void TestCreateTypeDefinitions_Union() { [Test] public void TestGenericVariableDeclaration() { - string xml = "vector a;"; + string xml = @"vector a;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -821,7 +821,7 @@ public void TestGenericVariableDeclaration() { [Test] public void TestGenericVariableDeclarationWithPrefix() { - string xml = "std::vector a;"; + string xml = @"std::vector a;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -843,7 +843,7 @@ public void TestGenericVariableDeclarationWithPrefix() { [Test] public void TestMethodCallCreation_LengthyCallingExpression() { - string xml = "a->b.Foo();"; + string xml = @"a->b.Foo();"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -876,7 +876,7 @@ public void TestMethodCallCreation_LengthyCallingExpression() { [Test] public void TestMergeWithUsing() { - string headerXml = " namespace A { class B { void Foo(); }; }"; + string headerXml = @" namespace A { class B { void Foo(); }; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtesta = runA.GenerateSrcMLFromString(headerXml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -892,11 +892,11 @@ public void TestMergeWithUsing() { var globalScope = headerScope.Merge(implementationScope); Assert.AreEqual(1, globalScope.ChildStatements.OfType().Count()); - var namespaceA = globalScope.GetDescendants().FirstOrDefault(n => n.Name == "A"); + var namespaceA = globalScope.GetDescendants().FirstOrDefault(n => n.Name == @"A"); Assert.IsNotNull(namespaceA); Assert.AreEqual(1, namespaceA.ChildStatements.Count); - var typeB = namespaceA.GetDescendants().FirstOrDefault(t => t.Name == "B"); + var typeB = namespaceA.GetDescendants().FirstOrDefault(t => t.Name == @"B"); Assert.IsNotNull(typeB); Assert.AreEqual(1, typeB.ChildStatements.Count); @@ -910,11 +910,11 @@ public void TestMergeWithUsing() { var globalScope_implementationFirst = implementationScope.Merge(headerScope); - namespaceA = globalScope_implementationFirst.GetDescendants().FirstOrDefault(n => n.Name == "A"); + namespaceA = globalScope_implementationFirst.GetDescendants().FirstOrDefault(n => n.Name == @"A"); Assert.IsNotNull(namespaceA); Assert.AreEqual(1, namespaceA.ChildStatements.Count); - typeB = namespaceA.GetDescendants().FirstOrDefault(t => t.Name == "B"); + typeB = namespaceA.GetDescendants().FirstOrDefault(t => t.Name == @"B"); Assert.IsNotNull(typeB); Assert.AreEqual(1, typeB.ChildStatements.Count); @@ -927,20 +927,20 @@ public void TestMergeWithUsing() { [Test] public void TestMethodCallCreation_WithConflictingMethodNames() { //# A.h - string a_xml = "class A {" + - " B b;" + - "public:" + - " bool Contains() { b.Contains(); }" + - "};"; + string a_xml = @"class A { + B b; + public: + bool Contains() { b.Contains(); } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtesta = runA.GenerateSrcMLFromString(a_xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); //# B.h - string b_xml = "class B {" + - "public:" + - " bool Contains() { return true; }" + - "};"; + string b_xml = @"class B { + public: + bool Contains() { return true; } + };"; LibSrcMLRunner runB = new LibSrcMLRunner(); string srcMLtestb = runB.GenerateSrcMLFromString(b_xml, "B.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -954,9 +954,9 @@ public void TestMethodCallCreation_WithConflictingMethodNames() { var globalScope = scopeForA.Merge(scopeForB); Assert.AreEqual(2, globalScope.ChildStatements.Count); - var classA = globalScope.GetDescendants().FirstOrDefault(t => t.Name == "A"); + var classA = globalScope.GetDescendants().FirstOrDefault(t => t.Name == @"A"); Assert.IsNotNull(classA); - var classB = globalScope.GetDescendants().FirstOrDefault(t => t.Name == "B"); + var classB = globalScope.GetDescendants().FirstOrDefault(t => t.Name == @"B"); Assert.IsNotNull(classB); var aDotContains = classA.GetNamedChildren("Contains").FirstOrDefault(); @@ -990,7 +990,7 @@ class B { var aDotBar = globalScope.GetNamedChildren("A").First().GetNamedChildren("Bar").FirstOrDefault(); Assert.IsNotNull(aDotBar); - var classB = globalScope.GetDescendants().FirstOrDefault(t => t.Name == "B"); + var classB = globalScope.GetDescendants().FirstOrDefault(t => t.Name == @"B"); Assert.IsNotNull(classB); var aDotBDotFoo = classB.GetNamedChildren("Foo").FirstOrDefault(); Assert.IsNotNull(aDotBDotFoo); @@ -1006,11 +1006,11 @@ class B { [Test] public void TestMethodCallCreation_GlobalFunction() { - string xml = "void foo(int a) { printf(a); }" + - "int main() {" + - " foo(5);" + - " return 0;" + - "}"; + string xml = @"void foo(int a) { printf(a); } + int main() { + foo(5); + return 0; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1036,20 +1036,20 @@ public void TestMethodCallCreation_GlobalFunction() { [Test] public void TestMethodCallCreation_CallGlobalNamespace() { - string xml = "void Foo() {" + - " std::cout<<\"global::Foo\"<() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1187,8 +1187,8 @@ orderby namedChild.Name [Test] public void TestMethodCallMatchToParameter() { - string xml = "void CallFoo(B b) { b.Foo(); }" + - "class B { void Foo() { } }"; + string xml = @"void CallFoo(B b) { b.Foo(); } + class B { void Foo() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1214,7 +1214,7 @@ public void TestMethodCallMatchToParameter() { [Test] public void TestMethodDefinition_ReturnType() { - string xml = "int Foo() { }"; + string xml = @"int Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1235,7 +1235,7 @@ public void TestMethodDefinition_ReturnType() { [Test] public void TestMethodDefinition_ReturnTypeAndSpecifier() { - string xml = "static int Foo() { }"; + string xml = @"static int Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1253,7 +1253,7 @@ public void TestMethodDefinition_ReturnTypeAndSpecifier() { [Test] public void TestMethodDefinition_Parameters() { - string xml = "int Foo(int bar, char baz) { }"; + string xml = @"int Foo(int bar, char baz) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1272,7 +1272,7 @@ public void TestMethodDefinition_Parameters() { [Test] public void TestMethodDefinition_VoidParameter() { - string xml = "void Foo(void) { }"; + string xml = @"void Foo(void) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1281,7 +1281,7 @@ public void TestMethodDefinition_VoidParameter() { var testScope = codeParser.ParseFileUnit(testUnit); - var method = testScope.GetDescendants().FirstOrDefault(m => m.Name == "Foo"); + var method = testScope.GetDescendants().FirstOrDefault(m => m.Name == @"Foo"); Assert.IsNotNull(method, "could not find the test method"); Assert.AreEqual(0, method.Parameters.Count); @@ -1289,7 +1289,7 @@ public void TestMethodDefinition_VoidParameter() { [Test] public void TestMethodDefinition_FunctionPointerParameter() { - string xml = "int Foo(char bar, int (*pInit)(Quux *theQuux)) {}"; + string xml = @"int Foo(char bar, int (*pInit)(Quux *theQuux)) {}"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1308,7 +1308,7 @@ public void TestMethodDefinition_FunctionPointerParameter() { [Test] public void TestMethodDefinition_VoidReturn() { - string xml = "void Foo() { }"; + string xml = @"void Foo() { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1317,7 +1317,7 @@ public void TestMethodDefinition_VoidReturn() { var testScope = codeParser.ParseFileUnit(testUnit); - var method = testScope.GetDescendants().FirstOrDefault(m => m.Name == "Foo"); + var method = testScope.GetDescendants().FirstOrDefault(m => m.Name == @"Foo"); Assert.IsNotNull(method, "could not find the test method"); Assert.AreEqual("Foo", method.Name); Assert.IsNull(method.ReturnType, "return type should be null"); @@ -1325,13 +1325,13 @@ public void TestMethodDefinition_VoidReturn() { [Test] public void TestMethodDefinition_DefaultArguments() { - string xml = "void foo(int a = 0);" + - "int main() {" + - " foo();" + - " foo(5);" + - " return 0;" + - "}" + - "void foo(int a) { }"; + string xml = @"void foo(int a = 0); + int main() { + foo(); + foo(5); + return 0; + } + void foo(int a) { }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1358,7 +1358,7 @@ public void TestMethodDefinition_DefaultArguments() { [Test] public void TestTwoVariableDeclarations() { - string testXml = "int a,b;"; + string testXml = @"int a,b;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1379,7 +1379,7 @@ public void TestTwoVariableDeclarations() { [Test] public void TestThreeVariableDeclarations() { - string testXml = "int a,b,c;"; + string testXml = @"int a,b,c;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1401,10 +1401,10 @@ public void TestThreeVariableDeclarations() { [Test] public void TestVariablesWithSpecifiers() { - string testXml = "const int A;" + - "static int B;" + - "static const Foo C;" + - "extern Foo D;"; + string testXml = @"const int A; + static int B; + static const Foo C; + extern Foo D;"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtest = runA.GenerateSrcMLFromString(testXml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1474,12 +1474,12 @@ public void TestLiteralUse() { [Test] public void TestIfElse() { - string xml = "if(a==b) {" + - " i = 17;" + - "} else {" + - " i = 42;" + - " ReportError();" + - "}"; + string xml = @"if(a==b) { + i = 17; + } else { + i = 42; + ReportError(); + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1529,7 +1529,7 @@ public void TestIfElseIf() { [Test] public void TestEmptyStatement() { - string xml = ";"; + string xml = @";"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1545,7 +1545,7 @@ public void TestEmptyStatement() { [Test] public void TestVariableUse_Index() { - string xml = "foo.bar[17];"; + string xml = @"foo.bar[17];"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1573,11 +1573,11 @@ public void TestVariableUse_Index() { [Test] public void TestResolveVariable_Field() { - string xml = "class A {" + - "public:" + - " int Foo;" + - " A() { Foo = 42; }" + - "};"; + string xml = @"class A { + public: + int Foo; + A() { Foo = 42; } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1585,23 +1585,23 @@ public void TestResolveVariable_Field() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("A").First().GetNamedChildren("Foo").First(); - var aConstructor = globalScope.GetDescendants().First(m => m.Name == "A"); + var aConstructor = globalScope.GetDescendants().First(m => m.Name == @"A"); Assert.AreEqual(1, aConstructor.ChildStatements.Count); - var fooUse = aConstructor.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); + var fooUse = aConstructor.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } [Test] public void TestResolveVariable_FieldInParent() { - string xml = "class B {" + - "public:" + - " int Foo;" + - "};" + - "class A : public B {" + - "public:" + - " A() { Foo = 42; }" + - "};"; + string xml = @"class B { + public: + int Foo; + }; + class A : public B { + public: + A() { Foo = 42; } + };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1610,19 +1610,19 @@ public void TestResolveVariable_FieldInParent() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("B").First().GetNamedChildren("Foo").First(); - var aConstructor = globalScope.GetDescendants().First(m => m.Name == "A"); + var aConstructor = globalScope.GetDescendants().First(m => m.Name == @"A"); Assert.AreEqual(1, aConstructor.ChildStatements.Count); - var fooUse = aConstructor.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); + var fooUse = aConstructor.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } [Test] public void TestResolveVariable_Global() { - string xml = "int Foo;" + - "int Bar() {" + - " Foo = 17;" + - "}"; + string xml = @"int Foo; + int Bar() { + Foo = 17; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1631,21 +1631,21 @@ public void TestResolveVariable_Global() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("Foo").First(); - var bar = globalScope.GetDescendants().First(m => m.Name == "Bar"); + var bar = globalScope.GetDescendants().First(m => m.Name == @"Bar"); Assert.AreEqual(1, bar.ChildStatements.Count); - var fooUse = bar.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); + var fooUse = bar.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } [Test] public void TestResolveVariable_VarInNamespace() { - string xml = "namespace A {" + - " int Foo;" + - " int Bar() {" + - " Foo = 17;" + - " }" + - "}"; + string xml = @"namespace A { + int Foo; + int Bar() { + Foo = 17; + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1654,23 +1654,23 @@ public void TestResolveVariable_VarInNamespace() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("A").First().GetNamedChildren("Foo").First(); - var bar = globalScope.GetDescendants().First(m => m.Name == "Bar"); + var bar = globalScope.GetDescendants().First(m => m.Name == @"Bar"); Assert.AreEqual(1, bar.ChildStatements.Count); - var fooUse = bar.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); + var fooUse = bar.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } [Test] public void TestResolveVariable_Masking() { - string xml = "int foo = 17;" + - "int main(int argc, char** argv)" + - "{" + - " std::cout<() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1683,13 +1683,13 @@ public void TestResolveVariable_Masking() { var main = globalScope.GetNamedChildren("main").First(); Assert.AreEqual(4, main.ChildStatements.Count); - var globalFooUse = main.ChildStatements[0].Content.GetDescendantsAndSelf().First(n => n.Name == "foo"); + var globalFooUse = main.ChildStatements[0].Content.GetDescendantsAndSelf().First(n => n.Name == @"foo"); var globalFooUseMatches = globalFooUse.FindMatches().ToList(); Assert.AreEqual(1, globalFooUseMatches.Count); Assert.AreSame(globalFoo, globalFooUseMatches[0]); var localFoo = main.GetNamedChildren("foo").First(); - var localFooUse = main.ChildStatements[2].Content.GetDescendantsAndSelf().First(n => n.Name == "foo"); + var localFooUse = main.ChildStatements[2].Content.GetDescendantsAndSelf().First(n => n.Name == @"foo"); var localFooUseMatches = localFooUse.FindMatches().ToList(); Assert.AreEqual(1, localFooUseMatches.Count); Assert.AreSame(localFoo, localFooUseMatches[0]); @@ -1697,11 +1697,11 @@ public void TestResolveVariable_Masking() { [Test] public void TestVariableDeclaredInCallingObjectWithParentClass() { - string a_xml = "class A { B b; };"; + string a_xml = @"class A { B b; };"; - string b_xml = "class B { void Foo() { } };"; + string b_xml = @"class B { void Foo() { } };"; - string c_xml = "class C : A { };"; + string c_xml = @"class C : A { };"; string d_xml = @"class D { C c; @@ -1758,12 +1758,12 @@ public void TestVariableDeclaredInCallingObjectWithParentClass() { [Test] public void TestResolveArrayVariable_Local() { - string xml = "int Foo() {" + - " if(MethodCall()) {" + - " int* bar = malloc(SIZE);" + - " bar[0] = 42;" + - " }" + - "}"; + string xml = @"int Foo() { + if(MethodCall()) { + int* bar = malloc(SIZE); + bar[0] = 42; + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLa = runA.GenerateSrcMLFromString(xml, "a.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1773,23 +1773,23 @@ public void TestResolveArrayVariable_Local() { var ifStmt = globalScope.GetDescendants().First(); Assert.AreEqual(2, ifStmt.ChildStatements.Count()); - var barDecl = ifStmt.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(v => v.Name == "bar"); + var barDecl = ifStmt.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(v => v.Name == @"bar"); Assert.IsNotNull(barDecl); - var barUse = ifStmt.ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "bar"); + var barUse = ifStmt.ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"bar"); Assert.IsNotNull(barUse); Assert.AreSame(barDecl, barUse.FindMatches().FirstOrDefault()); } [Test] public void TestResolveArrayVariable_Field() { - string xml = "class A {" + - "public:" + - " char* Foo;" + - " A() { " + - " Foo = malloc(SIZE);" + - " Foo[17] = 'x';" + - " }" + - "}"; + string xml = @"class A { + public: + char* Foo; + A() { + Foo = malloc(SIZE); + Foo[17] = 'x'; + } + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); @@ -1797,9 +1797,9 @@ public void TestResolveArrayVariable_Field() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("A").First().GetNamedChildren("Foo").First(); - var aConstructor = globalScope.GetDescendants().First(m => m.Name == "A"); + var aConstructor = globalScope.GetDescendants().First(m => m.Name == @"A"); Assert.AreEqual(2, aConstructor.ChildStatements.Count); - var fooUse = aConstructor.ChildStatements[1].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); + var fooUse = aConstructor.ChildStatements[1].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } @@ -1807,33 +1807,33 @@ public void TestResolveArrayVariable_Field() { [Test] public void TestResolveCallOnArrayVariable() { //#include - string xml = "const int SIZE = 5;" + - "class Foo {" + - "public:" + - " int GetNum() { return 42; }" + - "};" + - "class Bar {" + - "public:" + - " Foo FooArray[SIZE];" + - "};" + - "int main(int argc, char** argv) {" + - " Bar myBar;" + - " std::cout<< myBar.FooArray[0].GetNum() << std::endl;" + - " return 0;" + - "}"; + string xml = @"const int SIZE = 5; + class Foo { + public: + int GetNum() { return 42; } + }; + class Bar { + public: + Foo FooArray[SIZE]; + }; + int main(int argc, char** argv) { + Bar myBar; + std::cout<< myBar.FooArray[0].GetNum() << std::endl; + return 0; + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); - var getNum = globalScope.GetDescendants().FirstOrDefault(m => m.Name == "GetNum"); + var getNum = globalScope.GetDescendants().FirstOrDefault(m => m.Name == @"GetNum"); Assert.IsNotNull(getNum); - var main = globalScope.GetDescendants().FirstOrDefault(m => m.Name == "main"); + var main = globalScope.GetDescendants().FirstOrDefault(m => m.Name == @"main"); Assert.IsNotNull(main); Assert.AreEqual(3, main.ChildStatements.Count); - var getNumCall = main.ChildStatements[1].Content.GetDescendantsAndSelf().First(mc => mc.Name == "GetNum"); + var getNumCall = main.ChildStatements[1].Content.GetDescendantsAndSelf().First(mc => mc.Name == @"GetNum"); var matches = getNumCall.FindMatches().ToList(); Assert.AreEqual(1, matches.Count); Assert.AreSame(getNum, matches.First()); @@ -1871,8 +1871,8 @@ void main() { NamespaceDefinition globalScope = codeParser.ParseFileUnit(cUnit); globalScope = globalScope.Merge(codeParser.ParseFileUnit(eUnit)); - var typeC = globalScope.GetDescendants().Where(t => t.Name == "C").FirstOrDefault(); - var typeE = globalScope.GetDescendants().Where(t => t.Name == "E").FirstOrDefault(); + var typeC = globalScope.GetDescendants().Where(t => t.Name == @"C").FirstOrDefault(); + var typeE = globalScope.GetDescendants().Where(t => t.Name == @"E").FirstOrDefault(); var mainMethod = typeE.ChildStatements.OfType().FirstOrDefault(); Assert.IsNotNull(mainMethod, "is not a method definition"); From c26041d1e9c461921aefb273e3b7cfc4101183b9 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Mon, 18 Jan 2016 18:38:53 -0500 Subject: [PATCH 06/17] Transformation introduced silly syntax. Not really a bug but removing anyway. --- .../CPlusPlusCodeParserTests.cs | 98 +++++++++---------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs index 9b0aac3..6471be4 100644 --- a/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs +++ b/ABB.SrcML.Data.Test/CPlusPlusCodeParserTests.cs @@ -194,8 +194,8 @@ class SubClass : public SuperClass { var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(unit); - var calledConstructor = globalScope.GetDescendants().First(m => m.Name == @"SuperClass" && m.IsConstructor); - var subClassConstructor = globalScope.GetDescendants().First(m => m.Name == @"SubClass" && m.IsConstructor); + var calledConstructor = globalScope.GetDescendants().First(m => m.Name == "SuperClass" && m.IsConstructor); + var subClassConstructor = globalScope.GetDescendants().First(m => m.Name == "SubClass" && m.IsConstructor); Assert.IsNotNull(subClassConstructor); Assert.IsNotNull(calledConstructor); Assert.AreEqual(1, subClassConstructor.ConstructorInitializers.Count); @@ -256,8 +256,8 @@ class Bar XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLtest, "test.h"); var globalScope = codeParser.ParseFileUnit(xmlElement); - var fooConstructor = globalScope.GetDescendants().First(m => m.Name == @"Foo" && m.IsConstructor); - var barConstructor = globalScope.GetDescendants().First(m => m.Name == @"Bar" && m.IsConstructor); + var fooConstructor = globalScope.GetDescendants().First(m => m.Name == "Foo" && m.IsConstructor); + var barConstructor = globalScope.GetDescendants().First(m => m.Name == "Bar" && m.IsConstructor); Assert.AreEqual(1, barConstructor.ConstructorInitializers.Count); var fieldCall = barConstructor.ConstructorInitializers[0]; Assert.IsNotNull(fieldCall); @@ -343,15 +343,15 @@ namespace z {} var scopeB = codeParser.ParseFileUnit(xmlElementB); var globalScope = scopeA.Merge(scopeB); Assert.AreEqual(3, globalScope.ChildStatements.Count); - var foo = globalScope.ChildStatements[2].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"foo"); + var foo = globalScope.ChildStatements[2].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "foo"); Assert.IsNotNull(foo); var imports = foo.GetImports().ToList(); Assert.AreEqual(1, imports.Count); Assert.AreEqual("x :: y :: z", imports[0].ImportedNamespace.ToString()); - var zDef = globalScope.GetDescendants().FirstOrDefault(ns => ns.Name == @"z"); + var zDef = globalScope.GetDescendants().FirstOrDefault(ns => ns.Name == "z"); Assert.IsNotNull(zDef); - var zUse = imports[0].ImportedNamespace.GetDescendantsAndSelf().First(n => n.Name == @"z"); + var zUse = imports[0].ImportedNamespace.GetDescendantsAndSelf().First(n => n.Name == "z"); Assert.AreSame(zDef, zUse.FindMatches().FirstOrDefault()); } @@ -368,7 +368,7 @@ public void TestGetImports_NestedImportNamespace() { XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); - var foo = globalScope.ChildStatements[1].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"foo"); + var foo = globalScope.ChildStatements[1].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "foo"); Assert.IsNotNull(foo); var imports = foo.GetImports().ToList(); Assert.AreEqual(2, imports.Count); @@ -402,7 +402,7 @@ class Bar {} var scopeA = codeParser.ParseFileUnit(xmlElementA); var scopeB = codeParser.ParseFileUnit(xmlElementB); var globalScope = scopeA.Merge(scopeB); - var foo = globalScope.ChildStatements[2].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"foo"); + var foo = globalScope.ChildStatements[2].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "foo"); Assert.IsNotNull(foo); var aliases = foo.GetAliases().ToList(); Assert.AreEqual(1, aliases.Count); @@ -412,9 +412,9 @@ class Bar {} Assert.AreEqual(1, imports.Count); Assert.AreEqual("x :: y :: z", imports[0].ImportedNamespace.ToString()); - var barDef = globalScope.GetDescendants().FirstOrDefault(ns => ns.Name == @"Bar"); + var barDef = globalScope.GetDescendants().FirstOrDefault(ns => ns.Name == "Bar"); Assert.IsNotNull(barDef); - var barUse = aliases[0].Target.GetDescendantsAndSelf().First(n => n.Name == @"Bar"); + var barUse = aliases[0].Target.GetDescendantsAndSelf().First(n => n.Name == "Bar"); Assert.AreSame(barDef, barUse.FindMatches().FirstOrDefault()); } @@ -432,7 +432,7 @@ public void TestGetAliases_NestedTypeAlias() { XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); - var foo = globalScope.ChildStatements[1].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"foo"); + var foo = globalScope.ChildStatements[1].ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "foo"); Assert.IsNotNull(foo); var aliases = foo.GetAliases().ToList(); Assert.AreEqual(1, aliases.Count); @@ -481,17 +481,17 @@ class Baz { var globalScope = scopeA.Merge(scopeB); Assert.AreEqual(3, globalScope.ChildStatements.Count); - var baz = globalScope.GetDescendants().FirstOrDefault(t => t.Name == @"Baz"); + var baz = globalScope.GetDescendants().FirstOrDefault(t => t.Name == "Baz"); Assert.IsNotNull(baz); - var thingy = globalScope.GetDescendants().FirstOrDefault(m => m.Name == @"GetThingy"); + var thingy = globalScope.GetDescendants().FirstOrDefault(m => m.Name == "GetThingy"); Assert.IsNotNull(thingy); var thingyTypes = thingy.ReturnType.FindMatches().ToList(); Assert.AreEqual(1, thingyTypes.Count); Assert.AreSame(baz, thingyTypes[0]); var bazDef = baz.GetNamedChildren("Baz").First(); - var bazCall = thingy.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(mc => mc.Name == @"Baz"); + var bazCall = thingy.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(mc => mc.Name == "Baz"); Assert.IsNotNull(bazCall); Assert.AreSame(bazDef, bazCall.FindMatches().FirstOrDefault()); } @@ -532,11 +532,11 @@ class B { var globalScope = scopeA.Merge(scopeB); Assert.AreEqual(3, globalScope.ChildStatements.Count); - var thingDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == @"DoTheThing"); + var thingDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == "DoTheThing"); Assert.IsNotNull(thingDef); Assert.AreEqual("Baz", ((TypeDefinition)thingDef.ParentStatement).Name); - var bDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == @"B"); + var bDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == "B"); Assert.IsNotNull(bDef); Assert.AreEqual(1, bDef.ChildStatements.Count); var thingCall = bDef.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(); @@ -579,11 +579,11 @@ class B { var globalScope = scopeA.Merge(scopeB); Assert.AreEqual(3, globalScope.ChildStatements.Count); - var thingDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == @"DoTheThing"); + var thingDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == "DoTheThing"); Assert.IsNotNull(thingDef); Assert.AreEqual("Baz", ((TypeDefinition)thingDef.ParentStatement).Name); - var bDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == @"B"); + var bDef = globalScope.GetDescendants().FirstOrDefault(md => md.Name == "B"); Assert.IsNotNull(bDef); Assert.AreEqual(1, bDef.ChildStatements.Count); var thingCall = bDef.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(); @@ -892,11 +892,11 @@ public void TestMergeWithUsing() { var globalScope = headerScope.Merge(implementationScope); Assert.AreEqual(1, globalScope.ChildStatements.OfType().Count()); - var namespaceA = globalScope.GetDescendants().FirstOrDefault(n => n.Name == @"A"); + var namespaceA = globalScope.GetDescendants().FirstOrDefault(n => n.Name == "A"); Assert.IsNotNull(namespaceA); Assert.AreEqual(1, namespaceA.ChildStatements.Count); - var typeB = namespaceA.GetDescendants().FirstOrDefault(t => t.Name == @"B"); + var typeB = namespaceA.GetDescendants().FirstOrDefault(t => t.Name == "B"); Assert.IsNotNull(typeB); Assert.AreEqual(1, typeB.ChildStatements.Count); @@ -910,11 +910,11 @@ public void TestMergeWithUsing() { var globalScope_implementationFirst = implementationScope.Merge(headerScope); - namespaceA = globalScope_implementationFirst.GetDescendants().FirstOrDefault(n => n.Name == @"A"); + namespaceA = globalScope_implementationFirst.GetDescendants().FirstOrDefault(n => n.Name == "A"); Assert.IsNotNull(namespaceA); Assert.AreEqual(1, namespaceA.ChildStatements.Count); - typeB = namespaceA.GetDescendants().FirstOrDefault(t => t.Name == @"B"); + typeB = namespaceA.GetDescendants().FirstOrDefault(t => t.Name == "B"); Assert.IsNotNull(typeB); Assert.AreEqual(1, typeB.ChildStatements.Count); @@ -954,9 +954,9 @@ public void TestMethodCallCreation_WithConflictingMethodNames() { var globalScope = scopeForA.Merge(scopeForB); Assert.AreEqual(2, globalScope.ChildStatements.Count); - var classA = globalScope.GetDescendants().FirstOrDefault(t => t.Name == @"A"); + var classA = globalScope.GetDescendants().FirstOrDefault(t => t.Name == "A"); Assert.IsNotNull(classA); - var classB = globalScope.GetDescendants().FirstOrDefault(t => t.Name == @"B"); + var classB = globalScope.GetDescendants().FirstOrDefault(t => t.Name == "B"); Assert.IsNotNull(classB); var aDotContains = classA.GetNamedChildren("Contains").FirstOrDefault(); @@ -984,13 +984,13 @@ class B { };"; LibSrcMLRunner runA = new LibSrcMLRunner(); string srcMLtesta = runA.GenerateSrcMLFromString(a_xml, "A.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); - + var fileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtesta, "A.cpp"); var globalScope = codeParser.ParseFileUnit(fileUnit); var aDotBar = globalScope.GetNamedChildren("A").First().GetNamedChildren("Bar").FirstOrDefault(); Assert.IsNotNull(aDotBar); - var classB = globalScope.GetDescendants().FirstOrDefault(t => t.Name == @"B"); + var classB = globalScope.GetDescendants().FirstOrDefault(t => t.Name == "B"); Assert.IsNotNull(classB); var aDotBDotFoo = classB.GetNamedChildren("Foo").FirstOrDefault(); Assert.IsNotNull(aDotBDotFoo); @@ -1281,7 +1281,7 @@ public void TestMethodDefinition_VoidParameter() { var testScope = codeParser.ParseFileUnit(testUnit); - var method = testScope.GetDescendants().FirstOrDefault(m => m.Name == @"Foo"); + var method = testScope.GetDescendants().FirstOrDefault(m => m.Name == "Foo"); Assert.IsNotNull(method, "could not find the test method"); Assert.AreEqual(0, method.Parameters.Count); @@ -1317,7 +1317,7 @@ public void TestMethodDefinition_VoidReturn() { var testScope = codeParser.ParseFileUnit(testUnit); - var method = testScope.GetDescendants().FirstOrDefault(m => m.Name == @"Foo"); + var method = testScope.GetDescendants().FirstOrDefault(m => m.Name == "Foo"); Assert.IsNotNull(method, "could not find the test method"); Assert.AreEqual("Foo", method.Name); Assert.IsNull(method.ReturnType, "return type should be null"); @@ -1585,9 +1585,9 @@ public void TestResolveVariable_Field() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("A").First().GetNamedChildren("Foo").First(); - var aConstructor = globalScope.GetDescendants().First(m => m.Name == @"A"); + var aConstructor = globalScope.GetDescendants().First(m => m.Name == "A"); Assert.AreEqual(1, aConstructor.ChildStatements.Count); - var fooUse = aConstructor.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); + var fooUse = aConstructor.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } @@ -1610,9 +1610,9 @@ class A : public B { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("B").First().GetNamedChildren("Foo").First(); - var aConstructor = globalScope.GetDescendants().First(m => m.Name == @"A"); + var aConstructor = globalScope.GetDescendants().First(m => m.Name == "A"); Assert.AreEqual(1, aConstructor.ChildStatements.Count); - var fooUse = aConstructor.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); + var fooUse = aConstructor.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } @@ -1631,9 +1631,9 @@ int Bar() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("Foo").First(); - var bar = globalScope.GetDescendants().First(m => m.Name == @"Bar"); + var bar = globalScope.GetDescendants().First(m => m.Name == "Bar"); Assert.AreEqual(1, bar.ChildStatements.Count); - var fooUse = bar.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); + var fooUse = bar.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } @@ -1654,9 +1654,9 @@ int Bar() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("A").First().GetNamedChildren("Foo").First(); - var bar = globalScope.GetDescendants().First(m => m.Name == @"Bar"); + var bar = globalScope.GetDescendants().First(m => m.Name == "Bar"); Assert.AreEqual(1, bar.ChildStatements.Count); - var fooUse = bar.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); + var fooUse = bar.ChildStatements[0].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } @@ -1683,13 +1683,13 @@ int main(int argc, char** argv) var main = globalScope.GetNamedChildren("main").First(); Assert.AreEqual(4, main.ChildStatements.Count); - var globalFooUse = main.ChildStatements[0].Content.GetDescendantsAndSelf().First(n => n.Name == @"foo"); + var globalFooUse = main.ChildStatements[0].Content.GetDescendantsAndSelf().First(n => n.Name == "foo"); var globalFooUseMatches = globalFooUse.FindMatches().ToList(); Assert.AreEqual(1, globalFooUseMatches.Count); Assert.AreSame(globalFoo, globalFooUseMatches[0]); var localFoo = main.GetNamedChildren("foo").First(); - var localFooUse = main.ChildStatements[2].Content.GetDescendantsAndSelf().First(n => n.Name == @"foo"); + var localFooUse = main.ChildStatements[2].Content.GetDescendantsAndSelf().First(n => n.Name == "foo"); var localFooUseMatches = localFooUse.FindMatches().ToList(); Assert.AreEqual(1, localFooUseMatches.Count); Assert.AreSame(localFoo, localFooUseMatches[0]); @@ -1773,9 +1773,9 @@ public void TestResolveArrayVariable_Local() { var ifStmt = globalScope.GetDescendants().First(); Assert.AreEqual(2, ifStmt.ChildStatements.Count()); - var barDecl = ifStmt.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(v => v.Name == @"bar"); + var barDecl = ifStmt.ChildStatements[0].Content.GetDescendantsAndSelf().FirstOrDefault(v => v.Name == "bar"); Assert.IsNotNull(barDecl); - var barUse = ifStmt.ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == @"bar"); + var barUse = ifStmt.ChildStatements[1].Content.GetDescendantsAndSelf().FirstOrDefault(n => n.Name == "bar"); Assert.IsNotNull(barUse); Assert.AreSame(barDecl, barUse.FindMatches().FirstOrDefault()); } @@ -1797,9 +1797,9 @@ public void TestResolveArrayVariable_Field() { var globalScope = codeParser.ParseFileUnit(xmlElement); var fooDecl = globalScope.GetNamedChildren("A").First().GetNamedChildren("Foo").First(); - var aConstructor = globalScope.GetDescendants().First(m => m.Name == @"A"); + var aConstructor = globalScope.GetDescendants().First(m => m.Name == "A"); Assert.AreEqual(2, aConstructor.ChildStatements.Count); - var fooUse = aConstructor.ChildStatements[1].Content.GetDescendants().FirstOrDefault(n => n.Name == @"Foo"); + var fooUse = aConstructor.ChildStatements[1].Content.GetDescendants().FirstOrDefault(n => n.Name == "Foo"); Assert.IsNotNull(fooUse); Assert.AreSame(fooDecl, fooUse.FindMatches().FirstOrDefault()); } @@ -1827,13 +1827,13 @@ int main(int argc, char** argv) { XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp"); var globalScope = codeParser.ParseFileUnit(xmlElement); - var getNum = globalScope.GetDescendants().FirstOrDefault(m => m.Name == @"GetNum"); + var getNum = globalScope.GetDescendants().FirstOrDefault(m => m.Name == "GetNum"); Assert.IsNotNull(getNum); - var main = globalScope.GetDescendants().FirstOrDefault(m => m.Name == @"main"); + var main = globalScope.GetDescendants().FirstOrDefault(m => m.Name == "main"); Assert.IsNotNull(main); Assert.AreEqual(3, main.ChildStatements.Count); - var getNumCall = main.ChildStatements[1].Content.GetDescendantsAndSelf().First(mc => mc.Name == @"GetNum"); + var getNumCall = main.ChildStatements[1].Content.GetDescendantsAndSelf().First(mc => mc.Name == "GetNum"); var matches = getNumCall.FindMatches().ToList(); Assert.AreEqual(1, matches.Count); Assert.AreSame(getNum, matches.First()); @@ -1860,7 +1860,7 @@ void main() { }"; LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLtestc= runC.GenerateSrcMLFromString(c_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + string srcMLtestc = runC.GenerateSrcMLFromString(c_xml, "test.cpp", Language.CPlusPlus, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLtestc, "C.cpp"); @@ -1871,8 +1871,8 @@ void main() { NamespaceDefinition globalScope = codeParser.ParseFileUnit(cUnit); globalScope = globalScope.Merge(codeParser.ParseFileUnit(eUnit)); - var typeC = globalScope.GetDescendants().Where(t => t.Name == @"C").FirstOrDefault(); - var typeE = globalScope.GetDescendants().Where(t => t.Name == @"E").FirstOrDefault(); + var typeC = globalScope.GetDescendants().Where(t => t.Name == "C").FirstOrDefault(); + var typeE = globalScope.GetDescendants().Where(t => t.Name == "E").FirstOrDefault(); var mainMethod = typeE.ChildStatements.OfType().FirstOrDefault(); Assert.IsNotNull(mainMethod, "is not a method definition"); From 45b242826562626b30c2fb73436a05d3fd8da7b0 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Tue, 26 Jan 2016 18:01:11 -0500 Subject: [PATCH 07/17] C# tests all pass with the exception of 4. Will look at those tomorrow. --- ABB.SrcML.Data.Test/CSharpCodeParserTests.cs | 460 +++++++------------ ABB.SrcML.Data/AbstractCodeParser.cs | 66 +-- ABB.SrcML.Data/CPlusPlusCodeParser.cs | 36 ++ ABB.SrcML.Data/CSharpCodeParser.cs | 68 ++- ABB.SrcML.Data/InterfaceDefinition.cs | 13 + ABB.SrcML.Data/JavaCodeParser.cs | 35 +- ABB.SrcML.Data/NameUse.cs | 2 +- ABB.SrcML.Data/XNameMaps.cs | 1 + ABB.SrcML.Test/ABB.SrcML.Test.csproj | 8 + ABB.SrcML.Test/SrcMLFileTest.cs | 2 +- ABB.SrcML/Namespaces/SRC.cs | 12 + 11 files changed, 362 insertions(+), 341 deletions(-) create mode 100644 ABB.SrcML.Data/InterfaceDefinition.cs diff --git a/ABB.SrcML.Data.Test/CSharpCodeParserTests.cs b/ABB.SrcML.Data.Test/CSharpCodeParserTests.cs index 1718f88..c4c768d 100644 --- a/ABB.SrcML.Data.Test/CSharpCodeParserTests.cs +++ b/ABB.SrcML.Data.Test/CSharpCodeParserTests.cs @@ -16,26 +16,22 @@ using ABB.SrcML; using System.Collections.ObjectModel; using System; -namespace ABB.SrcML.Data.Test -{ +namespace ABB.SrcML.Data.Test { [TestFixture] [Category("Build")] - public class CSharpCodeParserTests - { + public class CSharpCodeParserTests { private CSharpCodeParser codeParser; private SrcMLFileUnitSetup fileSetup; [TestFixtureSetUp] - public void ClassSetup() - { + public void ClassSetup() { codeParser = new CSharpCodeParser(); fileSetup = new SrcMLFileUnitSetup(Language.CSharp); } [Test] - public void TestNamespace() - { + public void TestNamespace() { //namespace A { // public class foo { } //} @@ -43,7 +39,7 @@ public void TestNamespace() public class foo { } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcML, "A.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -56,8 +52,7 @@ public class foo { } } [Test] - public void TestCallToGenericMethod() - { + public void TestCallToGenericMethod() { //namespace A { // public class B { // void Foo(T t) { } @@ -71,7 +66,7 @@ void Foo(T t) { } } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(code, "A.cs", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(code, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcML, "A.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -89,8 +84,7 @@ void Foo(T t) { } } [Test] - public void TestCallToGrandparent() - { + public void TestCallToGrandparent() { //namespace A { // public class B { public void Foo() { } } // public class C : B { } @@ -103,7 +97,7 @@ public class D : C { public void Bar() { Foo() } } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var scope = codeParser.ParseFileUnit(unit); @@ -120,8 +114,7 @@ public class D : C { public void Bar() { Foo() } } } [Test] - public void TestMethodCallToParentOfCallingObject() - { + public void TestMethodCallToParentOfCallingObject() { //class A { void Foo() { } } string axml = @"class A { void Foo() { } }"; @@ -136,19 +129,19 @@ public void TestMethodCallToParentOfCallingObject() //} string cxml = @"class C { private B b; - void main() + void main() { b.Foo(); } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); NamespaceDefinition globalScope = codeParser.ParseFileUnit(aUnit); @@ -182,8 +175,7 @@ void main() [Test] [Category("Todo")] - public void TestCallWithTypeParameters() - { + public void TestCallWithTypeParameters() { //namespace A { // public interface IOdb { // int Query(); @@ -200,18 +192,18 @@ public void TestCallWithTypeParameters() var xml = @"namespace A { public interface IOdb { int Query(); - int QueryT(); + int Query(); } public class Test { public IOdb Open() { } void Test1() { IOdb odb = Open(); - var query = odb.QueryFoo(); + var query = odb.Query(); } } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var scope = codeParser.ParseFileUnit(unit); @@ -231,8 +223,7 @@ void Test1() { } [Test] - public void TestCallConstructor() - { + public void TestCallConstructor() { //class Foo { // public Foo() { } //} @@ -240,10 +231,13 @@ public void TestCallConstructor() // Foo myFoo = new Foo(); //} string xml = @"class Foo { - public Foo() { } -}"; + public Foo() { } + } + class Bar { + Foo myFoo = new Foo(); + }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -257,18 +251,17 @@ public Foo() { } } [Test] - public void TestConstructorWithBaseKeyword() - { + public void TestConstructorWithBaseKeyword() { // B.cs namespace A { class B { public B() { } } } string bxml = @"namespace A { class B { public B() { } } }"; // C.cs namespace A { class C : B { public C() : base() { } } } string cxml = @"namespace A { class C : B { public C() : base() { } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -288,8 +281,7 @@ public void TestConstructorWithBaseKeyword() } [Test] - public void TestConstructorWithThisKeyword() - { + public void TestConstructorWithThisKeyword() { // B.cs //namespace A { // class B { @@ -306,7 +298,7 @@ public B(int i) { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var globalScope = codeParser.ParseFileUnit(bUnit); @@ -324,12 +316,11 @@ public B(int i) { } } [Test] - public void TestCreateAliasesForFiles_UsingNamespace() - { + public void TestCreateAliasesForFiles_UsingNamespace() { // using x.y.z; string xml = @"using x.y.z;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -341,12 +332,11 @@ public void TestCreateAliasesForFiles_UsingNamespace() } [Test] - public void TestCreateAliasesForFiles_UsingAlias() - { + public void TestCreateAliasesForFiles_UsingAlias() { // using x = Foo.Bar.Baz; string xml = @"using x = Foo.Bar.Baz;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -359,13 +349,12 @@ public void TestCreateAliasesForFiles_UsingAlias() } [Test] - public void TestGetImports() - { + public void TestGetImports() { //B.cs //namespace x.y.z {} string xmlB = @"namespace x.y.z {}"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); //A.cs //using x.y.z; @@ -373,7 +362,7 @@ public void TestGetImports() string xmlA = @"using x.y.z; foo = 17;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -395,13 +384,12 @@ public void TestGetImports() } [Test] - public void TestGetImports_NestedImportNamespace() - { + public void TestGetImports_NestedImportNamespace() { //A.cs //namespace bar.baz {} string xmlA = @"namespace bar.baz {}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); //B.cs //using x.y.z; @@ -415,7 +403,7 @@ public void TestGetImports_NestedImportNamespace() foo = 17; }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -437,15 +425,14 @@ public void TestGetImports_NestedImportNamespace() } [Test] - public void TestGetImports_SeparateFiles() - { + public void TestGetImports_SeparateFiles() { //A.cs //using x.y.z; //Foo = 17; string xmlA = @"using x.y.z; Foo = 17;"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); //B.cs //using a.b.howdy; @@ -453,7 +440,7 @@ public void TestGetImports_SeparateFiles() string xmlB = @"using a.b.howdy; Bar();"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -475,8 +462,7 @@ public void TestGetImports_SeparateFiles() } [Test] - public void TestGetAliases_NestedUsingAlias() - { + public void TestGetAliases_NestedUsingAlias() { //A.cs //namespace bar { // class baz {} @@ -485,7 +471,7 @@ public void TestGetAliases_NestedUsingAlias() class baz {} }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); //B.cs //using x.y.z; @@ -499,7 +485,7 @@ class baz {} foo = 17; }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runA.GenerateSrcMLFromString(xmlB, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runA.GenerateSrcMLFromString(xmlB, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "A.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -523,8 +509,7 @@ class baz {} } [Test] - public void TestImport_NameResolution() - { + public void TestImport_NameResolution() { //A.cs //using Foo.Bar; // @@ -540,7 +525,7 @@ public class Robot { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); //B.cs //namespace Foo.Bar { @@ -554,7 +539,7 @@ public Baz() { } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -578,32 +563,16 @@ public Baz() { } } [Test] - public void TestAlias_NameResolution() - { - //A.cs - //namespace Foo.Bar { - // public class Baz { - // public static void DoTheThing() { }; - // } - //} + public void TestAlias_NameResolution() { string xmlA = @"namespace Foo.Bar { public class Baz { public static void DoTheThing() { }; } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xmlA, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementA = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); - //B.cs - //using Baz = Foo.Bar.Baz; - //namespace A { - // public class B { - // public B() { - // Baz.DoTheThing(); - // } - // } - //} string xmlB = @"using Baz = Foo.Bar.Baz; namespace A { public class B { @@ -613,7 +582,7 @@ public B() { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xmlB, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElementB = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scopeA = codeParser.ParseFileUnit(xmlElementA); @@ -636,14 +605,13 @@ public B() { [Test] [Category("SrcMLUpdate")] - public void TestUsingBlock_SingleDecl() - { + public void TestUsingBlock_SingleDecl() { //using(var f = File.Open("out.txt")) { // ; //} string xml = "using(var f = File.Open(\"out.txt\")) {;}"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -662,12 +630,11 @@ public void TestUsingBlock_SingleDecl() [Test] [Category("SrcMLUpdate")] - public void TestUsingBlock_MultipleDecl() - { + public void TestUsingBlock_MultipleDecl() { // using(Foo a = new Foo(1), b = new Foo(2)) { ; } string xml = @"using(Foo a = new Foo(1), b = new Foo(2)) { ; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -689,12 +656,11 @@ public void TestUsingBlock_MultipleDecl() [Test] [Category("SrcMLUpdate")] - public void TestUsingBlock_Expression() - { + public void TestUsingBlock_Expression() { //using(bar = new Foo()) { ; } string xml = @"using(bar = new Foo()) { ; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -722,8 +688,7 @@ public void TestUsingBlock_Expression() } [Test] - public void TestCreateTypeDefinition_Class() - { + public void TestCreateTypeDefinition_Class() { ////Foo.cs //public class Foo { // public int bar; @@ -732,7 +697,7 @@ public void TestCreateTypeDefinition_Class() public int bar; }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -751,8 +716,7 @@ public void TestCreateTypeDefinition_Class() } [Test] - public void TestCreateTypeDefinition_ClassWithParent() - { + public void TestCreateTypeDefinition_ClassWithParent() { ////Foo.cs //public class Foo : Baz { // public int bar; @@ -761,7 +725,7 @@ public void TestCreateTypeDefinition_ClassWithParent() public int bar; }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -776,8 +740,7 @@ public void TestCreateTypeDefinition_ClassWithParent() } [Test] - public void TestCreateTypeDefinition_ClassWithQualifiedParent() - { + public void TestCreateTypeDefinition_ClassWithQualifiedParent() { ////Foo.cs //public class Foo : Baz, System.IDisposable { // public int bar; @@ -786,7 +749,7 @@ public void TestCreateTypeDefinition_ClassWithQualifiedParent() public int bar; }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -803,8 +766,7 @@ public void TestCreateTypeDefinition_ClassWithQualifiedParent() } [Test] - public void TestCreateTypeDefinition_CompoundNamespace() - { + public void TestCreateTypeDefinition_CompoundNamespace() { ////Foo.cs //namespace Example.Level2.Level3 { // public class Foo { @@ -817,7 +779,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -841,8 +803,7 @@ public class Foo { } [Test] - public void TestCreateTypeDefinition_Interface() - { + public void TestCreateTypeDefinition_Interface() { ////Foo.cs //public interface Foo { // public int GetBar(); @@ -851,12 +812,12 @@ public void TestCreateTypeDefinition_Interface() public int GetBar(); }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); Assert.AreEqual(1, globalScope.ChildStatements.Count()); - var foo = globalScope.ChildStatements.First() as TypeDefinition; + var foo = globalScope.ChildStatements.First() as TypeDefinition; Assert.IsNotNull(foo); Assert.AreEqual("Foo", foo.Name); Assert.AreEqual(TypeKind.Interface, foo.Kind); @@ -864,8 +825,7 @@ public void TestCreateTypeDefinition_Interface() } [Test] - public void TestCreateTypeDefinition_Namespace() - { + public void TestCreateTypeDefinition_Namespace() { ////Foo.cs //namespace Example { // public class Foo { @@ -878,7 +838,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -894,8 +854,7 @@ public class Foo { } [Test] - public void TestCreateTypeDefinition_NestedCompoundNamespace() - { + public void TestCreateTypeDefinition_NestedCompoundNamespace() { ////Foo.cs //namespace Watermelon { // namespace Example.Level2.Level3 { @@ -912,7 +871,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -940,8 +899,7 @@ public class Foo { } [Test] - public void TestCreateTypeDefinition_Struct() - { + public void TestCreateTypeDefinition_Struct() { ////Foo.cs //public struct Foo { // public int bar; @@ -950,7 +908,7 @@ public void TestCreateTypeDefinition_Struct() public int bar; }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var fooFileUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(fooFileUnit); @@ -963,8 +921,7 @@ public void TestCreateTypeDefinition_Struct() } [Test] - public void TestCreateTypeDefinitions_ClassWithInnerClass() - { + public void TestCreateTypeDefinitions_ClassWithInnerClass() { ////A.cs //class A { // class B {} @@ -973,7 +930,7 @@ public void TestCreateTypeDefinitions_ClassWithInnerClass() class B {} }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -990,8 +947,7 @@ class B {} } [Test] - public void TestCreateTypeDefinitions_InnerClassWithNamespace() - { + public void TestCreateTypeDefinitions_InnerClassWithNamespace() { ////A.cs //namespace Foo { // class A { @@ -1004,7 +960,7 @@ class B {} } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1028,18 +984,17 @@ class B {} } [Test] - public void TestDeclarationWithTypeVarFromConstructor() - { + public void TestDeclarationWithTypeVarFromConstructor() { // B.cs namespace A { class B { public B() { }; } } string bxml = @"namespace A { class B { public B() { }; } }"; // C.cs namespace A { class C { void main() { var b = new B(); } } } string cxml = @"namespace A { class C { void main() { var b = new B(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); var cScope = codeParser.ParseFileUnit(cUnit); @@ -1058,18 +1013,17 @@ public void TestDeclarationWithTypeVarFromConstructor() } [Test] - public void TestDeclarationWithTypeVarFromImplicitConstructor() - { + public void TestDeclarationWithTypeVarFromImplicitConstructor() { // B.cs namespace A { class B { } } string bxml = @"namespace A { class B { } }"; // C.cs namespace A { class C { void main() { var b = new B(); } } } string cxml = @"namespace A { class C { void main() { var b = new B(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); var cScope = codeParser.ParseFileUnit(cUnit); @@ -1088,8 +1042,7 @@ public void TestDeclarationWithTypeVarFromImplicitConstructor() } [Test] - public void TestDeclarationWithTypeVarFromMethod() - { + public void TestDeclarationWithTypeVarFromMethod() { //namespace A { // class B { // public static void main() { var b = getB(); } @@ -1103,7 +1056,7 @@ class B { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1120,8 +1073,7 @@ class B { } [Test] - public void TestDeclarationWithTypeVarInForeach() - { + public void TestDeclarationWithTypeVarInForeach() { //class Foo { // int[] GetInts() { // return new[] {1, 2, 3, 4}; @@ -1143,7 +1095,7 @@ int main() { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1155,8 +1107,7 @@ int main() { } [Test] - public void TestFieldCreation() - { + public void TestFieldCreation() { //// A.cs //class A { // public int Foo; @@ -1165,7 +1116,7 @@ public void TestFieldCreation() public int Foo; }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1181,8 +1132,7 @@ public void TestFieldCreation() } [Test] - public void TestFindParentType() - { + public void TestFindParentType() { // namespace A { class B : C { } } string bxml = @"namespace A { class B : C { } }"; @@ -1190,10 +1140,10 @@ public void TestFindParentType() string cxml = @"namespace A { class C { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runD = new LibSrcMLRunner(); - string srcMLD = runD.GenerateSrcMLFromString(cxml, "D.cs", Language.CSharp, new Collection() { }, false); + string srcMLD = runD.GenerateSrcMLFromString(cxml, "D.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLD, "D.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1211,8 +1161,7 @@ public void TestFindParentType() } [Test] - public void TestFindQualifiedParentType() - { + public void TestFindQualifiedParentType() { // namespace A { class B : C.D { } } string bxml = @"A { class B : C.D { } }"; @@ -1220,10 +1169,10 @@ public void TestFindQualifiedParentType() string dxml = @"namespace C { class D { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runD = new LibSrcMLRunner(); - string srcMLD = runD.GenerateSrcMLFromString(dxml, "D.cs", Language.CSharp, new Collection() { }, false); + string srcMLD = runD.GenerateSrcMLFromString(dxml, "D.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var dUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLD, "D.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1241,13 +1190,12 @@ public void TestFindQualifiedParentType() } [Test] - public void TestGenericType() - { + public void TestGenericType() { //public class B { } var xml = @"public class B { }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var scope = codeParser.ParseFileUnit(unit); @@ -1257,13 +1205,12 @@ public void TestGenericType() } [Test] - public void TestGenericVariableDeclaration() - { + public void TestGenericVariableDeclaration() { //Dictionary map; - string xml = @"Dictionary<string,int> map;"; + string xml = @"Dictionary map;"; LibSrcMLRunner runt = new LibSrcMLRunner(); - string srcMLt = runt.GenerateSrcMLFromString(xml, "test.cs", Language.CSharp, new Collection() { }, false); + string srcMLt = runt.GenerateSrcMLFromString(xml, "test.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLt, "test.cs"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1279,13 +1226,11 @@ public void TestGenericVariableDeclaration() } [Test] - public void TestGenericVariableDeclarationWithPrefix() - { - //System.Collection.Dictionary map; - string xml = @"Dictionary map;"; + public void TestGenericVariableDeclarationWithPrefix() { + string xml = @"System.Collection.Dictionary map;"; LibSrcMLRunner runt = new LibSrcMLRunner(); - string srcMLt = runt.GenerateSrcMLFromString(xml, "test.cs", Language.CSharp, new Collection() { }, false); + string srcMLt = runt.GenerateSrcMLFromString(xml, "test.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLt, "test.cs"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1305,31 +1250,24 @@ public void TestGenericVariableDeclarationWithPrefix() } [Test] - public void TestGetAccessModifierForMethod_InternalProtected() - { - //namespace Example { - // public class Foo { - // internal protected bool Bar() { return true; } - // } - //} + public void TestGetAccessModifierForMethod_InternalProtected() { string xml = @"namespace Example { public class Foo { internal protected bool Bar() { return true; } } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); var method = globalScope.GetDescendants().First(); - + //The specifier isn't in type anymore so it doesn't parse correctly. Assert.AreEqual(AccessModifier.ProtectedInternal, method.Accessibility); } [Test] - public void TestGetAccessModifierForMethod_None() - { + public void TestGetAccessModifierForMethod_None() { //namespace Example { // public class Foo { // bool Bar() { return true; } @@ -1341,7 +1279,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1351,8 +1289,7 @@ public class Foo { } [Test] - public void TestGetAccessModifierForMethod_Normal() - { + public void TestGetAccessModifierForMethod_Normal() { //namespace Example { // public class Foo { // public bool Bar() { return true; } @@ -1364,7 +1301,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1374,8 +1311,7 @@ public class Foo { } [Test] - public void TestGetAccessModifierForMethod_ProtectedInternal() - { + public void TestGetAccessModifierForMethod_ProtectedInternal() { //namespace Example { // public class Foo { // protected internal bool Bar() { return true; } @@ -1387,7 +1323,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1397,8 +1333,7 @@ public class Foo { } [Test] - public void TestGetAccessModifierForMethod_ProtectedInternalStatic() - { + public void TestGetAccessModifierForMethod_ProtectedInternalStatic() { //namespace Example { // public class Foo { // protected static internal bool Bar() { return true; } @@ -1410,7 +1345,7 @@ public class Foo { } }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1420,8 +1355,7 @@ public class Foo { } [Test] - public void TestGetAccessModifierForType_InternalProtected() - { + public void TestGetAccessModifierForType_InternalProtected() { //namespace Example { // internal protected class Foo {} //} @@ -1429,7 +1363,7 @@ public void TestGetAccessModifierForType_InternalProtected() internal protected class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1439,8 +1373,7 @@ internal protected class Foo {} } [Test] - public void TestGetAccessModifierForType_None() - { + public void TestGetAccessModifierForType_None() { //namespace Example { // class Foo {} //} @@ -1448,7 +1381,7 @@ public void TestGetAccessModifierForType_None() class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1458,8 +1391,7 @@ class Foo {} } [Test] - public void TestGetAccessModifierForType_Normal() - { + public void TestGetAccessModifierForType_Normal() { //namespace Example { // public class Foo {} //} @@ -1467,7 +1399,7 @@ public void TestGetAccessModifierForType_Normal() public class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1477,8 +1409,7 @@ public class Foo {} } [Test] - public void TestGetAccessModifierForType_ProtectedInternal() - { + public void TestGetAccessModifierForType_ProtectedInternal() { //namespace Example { // protected internal class Foo {} //} @@ -1486,7 +1417,7 @@ public void TestGetAccessModifierForType_ProtectedInternal() protected internal class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1496,8 +1427,7 @@ protected internal class Foo {} } [Test] - public void TestGetAccessModifierForType_ProtectedInternalStatic() - { + public void TestGetAccessModifierForType_ProtectedInternalStatic() { //namespace Example { // protected static internal class Foo {} //} @@ -1505,7 +1435,7 @@ public void TestGetAccessModifierForType_ProtectedInternalStatic() protected static internal class Foo {} }"; LibSrcMLRunner runo = new LibSrcMLRunner(); - string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { }, false); + string srcMLo = runo.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLo, "Foo.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1515,18 +1445,17 @@ protected static internal class Foo {} } [Test] - public void TestMethodCallWithBaseKeyword() - { + public void TestMethodCallWithBaseKeyword() { // B.cs namespace A { class B { public virtual void Foo() { } } } string bxml = @"namespace A { class B { public virtual void Foo() { } } }"; // C.cs namespace A { class C : B { public override void Foo() { base.Foo(); } } } string cxml = @"namespace A { class C : B { public override void Foo() { base.Foo(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1547,13 +1476,12 @@ public void TestMethodCallWithBaseKeyword() } [Test] - public void TestMethodDefinitionWithReturnType() - { + public void TestMethodDefinitionWithReturnType() { //int Foo() { } string xml = @"int Foo() { }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcML, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1565,13 +1493,12 @@ public void TestMethodDefinitionWithReturnType() } [Test] - public void TestMethodDefinitionWithReturnTypeAndWithSpecifier() - { + public void TestMethodDefinitionWithReturnTypeAndWithSpecifier() { //static int Foo() { } string xml = @"static int Foo() { }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcML, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1583,13 +1510,12 @@ public void TestMethodDefinitionWithReturnTypeAndWithSpecifier() } [Test] - public void TestMethodDefinitionWithVoidReturn() - { + public void TestMethodDefinitionWithVoidReturn() { //void Foo() { } string xml = @"void Foo() { }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "test.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcML, "test.cpp"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1602,13 +1528,12 @@ public void TestMethodDefinitionWithVoidReturn() [Test] - public void TestProperty() - { + public void TestProperty() { // namespace A { class B { int Foo { get; set; } } } string xml = @"namespace A { class B { int Foo { get; set; } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); var testScope = codeParser.ParseFileUnit(testUnit); @@ -1627,29 +1552,13 @@ public void TestProperty() } [Test] - public void TestPropertyAsCallingObject() - { - // B.cs - //namespace A { - // class B { - // C Foo { get; set; } - // } - //} + public void TestPropertyAsCallingObject() { string bxml = @"namespace A { class B { C Foo { get; set; } } }"; - // C.cs - //namespace A { - // class C { - // static void main() { - // B b = new B(); - // b.Foo.Bar(); - // } - // void Bar() { } - // } - //} + string cxml = @"namespace A { class C { static void main() { @@ -1661,10 +1570,10 @@ void Bar() { } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); var cScope = codeParser.ParseFileUnit(cUnit); @@ -1688,18 +1597,17 @@ void Bar() { } } [Test] - public void TestStaticMethodCall() - { + public void TestStaticMethodCall() { //namespace A { public class B { public static void Bar() { } } } var bxml = @"namespace A { public class B { public static void Bar() { } } }"; //namespace A { public class C { public void Foo() { B.Bar(); } } } var cxml = @"namespace A { public class C { public void Foo() { B.Bar(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1719,18 +1627,17 @@ public void TestStaticMethodCall() } [Test] - public void TestStaticMethodCallInDifferentNamespace() - { + public void TestStaticMethodCallInDifferentNamespace() { //namespace A { public class B { public static void Bar() { } } } var bxml = @"namespace A { public class B { public static void Bar() { } } }"; //namespace C { public class D { public void Foo() { A.B.Bar(); } } } var dxml = @"namespace C { public class D { public void Foo() { A.B.Bar(); } } }"; LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(dxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(dxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var dUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var bScope = codeParser.ParseFileUnit(bUnit); @@ -1750,8 +1657,7 @@ public void TestStaticMethodCallInDifferentNamespace() } [Test] - public void TestVariablesWithSpecifiers() - { + public void TestVariablesWithSpecifiers() { //static int A; //public const int B; //public static readonly Foo C; @@ -1759,10 +1665,10 @@ public void TestVariablesWithSpecifiers() string testXml = @"static int A; public const int B; public static readonly Foo C; - volatile int D;"; + volatile int D;"; LibSrcMLRunner runt = new LibSrcMLRunner(); - string srcMLt = runt.GenerateSrcMLFromString(testXml, "test.cs", Language.CSharp, new Collection() { }, false); - var testUnit = fileSetup.GetFileUnitForXmlSnippet(testXml, "test.cs"); + string srcMLt = runt.GenerateSrcMLFromString(testXml, "test.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + var testUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLt, "test.cs"); var globalScope = codeParser.ParseFileUnit(testUnit); Assert.AreEqual(4, globalScope.ChildStatements.Count); @@ -1793,8 +1699,7 @@ public void TestVariablesWithSpecifiers() } [Test] - public void TestStaticInstanceVariable() - { + public void TestStaticInstanceVariable() { //namespace A { // class B { // public static B Instance { get; set; } @@ -1812,7 +1717,7 @@ public void Bar() { } class C { public void Foo() { B.Instance.Bar(); } } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1829,8 +1734,7 @@ class C { public void Foo() { B.Instance.Bar(); } } } [Test] - public void TestStaticInstanceVariableInDifferentNamespace() - { + public void TestStaticInstanceVariableInDifferentNamespace() { //namespace A { // class B { // public static B Instance { get; set; } @@ -1857,10 +1761,10 @@ class D { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var aScope = codeParser.ParseFileUnit(aUnit); var cScope = codeParser.ParseFileUnit(cUnit); @@ -1878,8 +1782,7 @@ class D { } [Test] - public void TestCallAsCallingObject() - { + public void TestCallAsCallingObject() { //namespace A { // public class B { // void main() { @@ -1907,7 +1810,7 @@ void Bar() { } } }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcML = run.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcML = run.GenerateSrcMLFromString(xml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var unit = fileSetup.GetFileUnitForXmlSnippet(srcML, "B.cs"); var globalScope = codeParser.ParseFileUnit(unit); @@ -1929,8 +1832,7 @@ void Bar() { } } [Test] - public void TestResolveVariable_Field() - { + public void TestResolveVariable_Field() { //class A { // public int Foo; // public A() { @@ -1944,7 +1846,7 @@ public A() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1957,8 +1859,7 @@ public A() { } [Test] - public void TestResolveVariable_FieldInParent() - { + public void TestResolveVariable_FieldInParent() { //class B { // public int Foo; //} @@ -1976,7 +1877,7 @@ public A() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -1989,8 +1890,7 @@ public A() { } [Test] - public void TestCallingVariableDeclaredInParentClass() - { + public void TestCallingVariableDeclaredInParentClass() { //class A { void Foo() { } } string axml = @"class A { void Foo() { } }"; @@ -2001,13 +1901,13 @@ public void TestCallingVariableDeclaredInParentClass() string cxml = @"class C : B { void Bar() { a.Foo(); } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); var globalScope = codeParser.ParseFileUnit(aUnit); @@ -2036,8 +1936,7 @@ public void TestCallingVariableDeclaredInParentClass() } [Test] - public void TestVariableDeclaredInCallingObjectWithParentClass() - { + public void TestVariableDeclaredInCallingObjectWithParentClass() { //class A { B b; } string axml = @"class A { B b; }"; @@ -2057,16 +1956,16 @@ public void TestVariableDeclaredInCallingObjectWithParentClass() }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(axml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var aUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); LibSrcMLRunner runB = new LibSrcMLRunner(); - string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { }, false); + string srcMLB = runB.GenerateSrcMLFromString(bxml, "B.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var bUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLB, "B.cs"); LibSrcMLRunner runC = new LibSrcMLRunner(); - string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { }, false); + string srcMLC = runC.GenerateSrcMLFromString(cxml, "C.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cs"); LibSrcMLRunner runD = new LibSrcMLRunner(); - string srcMLD = runD.GenerateSrcMLFromString(dxml, "D.cs", Language.CSharp, new Collection() { }, false); + string srcMLD = runD.GenerateSrcMLFromString(dxml, "D.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var dUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLD, "D.cs"); var globalScope = codeParser.ParseFileUnit(aUnit); @@ -2101,8 +2000,7 @@ public void TestVariableDeclaredInCallingObjectWithParentClass() } [Test] - public void TestResolveArrayVariable_Property() - { + public void TestResolveArrayVariable_Property() { //class Foo { // Collection Parameters { get; set; } // void DoWork() { @@ -2116,7 +2014,7 @@ void DoWork() { } }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); @@ -2130,8 +2028,7 @@ void DoWork() { } [Test] - public void TestTypeUseForOtherNamespace() - { + public void TestTypeUseForOtherNamespace() { //namespace A.B { // class C { // int Foo() { } @@ -2163,10 +2060,10 @@ void main() { }"; LibSrcMLRunner run = new LibSrcMLRunner(); - string srcMLC = run.GenerateSrcMLFromString(cxml, "C.cpp", Language.CSharp, new Collection() { }, false); + string srcMLC = run.GenerateSrcMLFromString(cxml, "C.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var cUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLC, "C.cpp"); LibSrcMLRunner runE = new LibSrcMLRunner(); - string srcMLE = runE.GenerateSrcMLFromString(exml, "E.cpp", Language.CSharp, new Collection() { }, false); + string srcMLE = runE.GenerateSrcMLFromString(exml, "E.cpp", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var eUnit = fileSetup.GetFileUnitForXmlSnippet(srcMLE, "E.cpp"); NamespaceDefinition globalScope = codeParser.ParseFileUnit(cUnit); @@ -2199,8 +2096,7 @@ void main() { } [Test] - public void TestLockStatement() - { + public void TestLockStatement() { //lock(myVar) { // myVar.DoFoo(); //} @@ -2208,7 +2104,7 @@ public void TestLockStatement() myVar.DoFoo(); }"; LibSrcMLRunner runA = new LibSrcMLRunner(); - string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { }, false); + string srcMLA = runA.GenerateSrcMLFromString(xml, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); var xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cs"); var globalScope = codeParser.ParseFileUnit(xmlElement); diff --git a/ABB.SrcML.Data/AbstractCodeParser.cs b/ABB.SrcML.Data/AbstractCodeParser.cs index 0b760db..321ccfb 100644 --- a/ABB.SrcML.Data/AbstractCodeParser.cs +++ b/ABB.SrcML.Data/AbstractCodeParser.cs @@ -195,9 +195,11 @@ protected virtual Statement ParseStatement(XElement element, ParserContext conte stmt = ParseTryElement(element, context); } else if(element.Name == SRC.ExpressionStatement) { stmt = ParseExpressionStatementElement(element, context); - } else if(element.Name == SRC.DeclarationStatement) { + } else if(element.Name == SRC.Property) { + stmt = ParseDeclarationStatementElement(element, context); + } else if (element.Name == SRC.DeclarationStatement) { stmt = ParseDeclarationStatementElement(element, context); - } else if(element.Name == SRC.Block) { + } else if (element.Name == SRC.Block) { stmt = ParseBlockElement(element, context); } else if(element.Name == SRC.Extern) { stmt = ParseExternElement(element, context); @@ -206,10 +208,15 @@ protected virtual Statement ParseStatement(XElement element, ParserContext conte } else if(element.Name == SRC.Lock) { stmt = ParseLockElement(element, context); } else if(element.Name == POS.Position) { - // do nothing. we are ignoring position (for now) + // do nothing. we are ignoring position (for now; current method of getting line num seems to still work) } else if (element.Name == SRC.Using) { - ; - } else if (element.Name == SRC.Comment) { + // do nothing for now. + } else if (element.Name == SRC.Using_Stmt) { + stmt = ParseUsingBlockElement(element, context); + } else if (element.Name == SRC.Interface) { + stmt = ParseInterfaceElement(element, context); + } + else if (element.Name == SRC.Comment) { // do nothing. we are ignoring comments } else if (element.Name == SRC.Package) { //do nothing. This is already handled in JavaCodeParser.ParseUnitElement() @@ -624,6 +631,14 @@ protected virtual CaseStatement ParseCaseElement(XElement caseElement, ParserCon return caseStmt; } + /// + /// + /// + /// + /// + /// + protected abstract UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context); + /// /// Creates a object for . /// @@ -884,22 +899,7 @@ protected virtual Statement ParseExpressionStatementElement(XElement stmtElement /// The context to use. /// A corresponding to . /// The return type is so that subclasses can return another type, as necessary. - protected virtual Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context) { - if(stmtElement == null) - throw new ArgumentNullException("stmtElement"); - if(stmtElement.Name != SRC.DeclarationStatement) - throw new ArgumentException("Must be a SRC.DeclarationStatement element", "stmtElement"); - if(context == null) - throw new ArgumentNullException("context"); - - var stmt = new DeclarationStatement() { - ProgrammingLanguage = ParserLanguage, - Content = ParseExpression(GetChildExpressions(stmtElement), context) - }; - stmt.AddLocation(context.CreateLocation(stmtElement)); - - return stmt; - } + protected abstract Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context); /// @@ -1040,7 +1040,13 @@ protected virtual ExternStatement ParseExternElement(XElement externElement, Par return es; } - + /// + /// + /// + /// + /// + /// + protected abstract InterfaceDefinition ParseInterfaceElement(XElement interfaceElement, ParserContext context); /// /// Creates an empty Statement object from the given SRC.EmptyStatement element. /// @@ -1263,16 +1269,16 @@ protected virtual Expression ParseExpressionElement(XElement expElement, ParserC /// /// Creates a variable declaration object from the given declaration element /// - /// The SRC.Declaration element to parse. + /// The SRC.Declaration element to parse. /// The parser context. /// A VariableDeclaration object corresponding to the given element. protected virtual VariableDeclaration ParseDeclarationElement(XElement declElement, ParserContext context) { //TODO: can/should this handle function_decls as well as decls? ParseParameterElement may pass in a function_decl //NOTE: When the declaration is using f = bla this won't work because there is no decl on the inside. Fix. if(declElement == null) - throw new ArgumentNullException("declElement"); + throw new ArgumentNullException("propertyElement"); if(!(declElement.Name == SRC.Declaration || declElement.Name == SRC.FunctionDeclaration)) - throw new ArgumentException("Must be a SRC.Declaration or SRC.FunctionDeclaration element", "declElement"); + throw new ArgumentException("Must be a SRC.Declaration or SRC.FunctionDeclaration element", "propertyElement"); if(context == null) throw new ArgumentNullException("context"); @@ -1289,9 +1295,8 @@ protected virtual VariableDeclaration ParseDeclarationElement(XElement declEleme var typeElement = declElement.Element(SRC.Type); if(typeElement != null && typeElement.Attribute("ref") == null) { varDecl.VariableType = ParseTypeUseElement(typeElement, context); - varDecl.Accessibility = GetAccessModifierFromTypeUseElement(typeElement); + varDecl.Accessibility = GetAccessModifier(declElement); } - var initElement = declElement.Element(SRC.Init); if(initElement != null) { var expElement = GetFirstChildExpression(initElement); @@ -1654,12 +1659,7 @@ protected virtual AccessModifier GetAccessModifierForMethod(XElement methodEleme throw new ArgumentNullException("methodElement"); if(!MethodElementNames.Contains(methodElement.Name)) throw new ArgumentException(string.Format("Not a valid methodElement: {0}", methodElement.Name), "methodElement"); - - var specifierContainer = methodElement.Element(SRC.Type); - if(null == specifierContainer) { - specifierContainer = methodElement; - } - return GetAccessModifier(specifierContainer); + return GetAccessModifier(methodElement); } /// diff --git a/ABB.SrcML.Data/CPlusPlusCodeParser.cs b/ABB.SrcML.Data/CPlusPlusCodeParser.cs index 630660d..3197607 100644 --- a/ABB.SrcML.Data/CPlusPlusCodeParser.cs +++ b/ABB.SrcML.Data/CPlusPlusCodeParser.cs @@ -221,7 +221,20 @@ protected override NamespaceDefinition ParseNamespaceElement(XElement namespaceE return nd; } + protected override InterfaceDefinition ParseInterfaceElement(XElement interfaceElement, ParserContext context) { + if (interfaceElement == null) + throw new ArgumentNullException("interfaceElement"); + if (context == null) + throw new ArgumentNullException("context"); + + var nameElement = interfaceElement.Element(SRC.Name); + var namespaceName = nameElement != null ? nameElement.Value : string.Empty; + ParseBlockElement(interfaceElement.Element(SRC.Block), context); + + return new InterfaceDefinition(); + } + protected override UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) { return new UsingBlockStatement(); } /// /// Parses an element corresponding to a type definition and creates a TypeDefinition object /// @@ -265,7 +278,30 @@ protected override TypeDefinition ParseTypeElement(XElement typeElement, ParserC return typeDefinition; } + /// + /// Creates a object for . + /// The expression contained within will be parsed and placed in + /// Statement.Content. + /// + /// The SRC.DeclarationStatement element to parse. + /// The context to use. + /// A corresponding to . + /// The return type is so that subclasses can return another type, as necessary. + protected override Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context) { + if (stmtElement == null) + throw new ArgumentNullException("stmtElement"); + if (stmtElement.Name != SRC.DeclarationStatement && stmtElement.Name != SRC.Property) + throw new ArgumentException("Must be a SRC.DeclarationStatement or SRC.Property element", "stmtElement"); + if (context == null) + throw new ArgumentNullException("context"); + var stmt = new DeclarationStatement() { + ProgrammingLanguage = ParserLanguage, + Content = ParseExpression(GetChildExpressions(stmtElement), context) + }; + stmt.AddLocation(context.CreateLocation(stmtElement)); + return stmt; + } /// /// Parses the given and creates an ImportStatement or AliasStatement from it. /// diff --git a/ABB.SrcML.Data/CSharpCodeParser.cs b/ABB.SrcML.Data/CSharpCodeParser.cs index ff3e2f3..3f6c1dd 100644 --- a/ABB.SrcML.Data/CSharpCodeParser.cs +++ b/ABB.SrcML.Data/CSharpCodeParser.cs @@ -26,7 +26,7 @@ public class CSharpCodeParser : AbstractCodeParser { /// public CSharpCodeParser() : base() { - this.TypeElementNames = new HashSet { SRC.Class, SRC.Enum, SRC.Struct }; //SRC.Interface? + this.TypeElementNames = new HashSet { SRC.Class, SRC.Enum, SRC.Struct, SRC.Interface }; this.AliasElementName = SRC.Using; //TODO: what else needs to be set here? } @@ -144,6 +144,28 @@ protected override string GetTypeForNumberLiteral(string literalValue) { protected override string GetTypeForStringLiteral(string literalValue) { return "string"; } + /// + /// + /// + /// + /// + /// + protected override InterfaceDefinition ParseInterfaceElement(XElement interfaceElement, ParserContext context) { + if (interfaceElement == null) + throw new ArgumentNullException("interfaceElement"); + if (context == null) + throw new ArgumentNullException("context"); + + InterfaceDefinition iDef = new InterfaceDefinition(); + + var nameElement = interfaceElement.Element(SRC.Name); + var blockElement = interfaceElement.Element(SRC.Block); + iDef.Name = nameElement.Value; + iDef.Accessibility = GetAccessModifier(interfaceElement); + TypeDefinition t = ParseTypeElement(interfaceElement, context); + iDef.AddChildStatement(t); + return iDef; + } /// /// Parses a C# namespace block @@ -245,10 +267,10 @@ protected override Statement ParseAliasElement(XElement aliasElement, ParserCont /// The SRC.Using element to parse. /// The parser context to use. /// A UsingBlockStatement created from the given usingElement. - protected virtual UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) { + protected override UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) { if(usingElement == null) throw new ArgumentNullException("usingElement"); - if(usingElement.Name != SRC.Using) + if(usingElement.Name != SRC.Using_Stmt) throw new ArgumentException("Must be a SRC.Using element", "usingElement"); if(context == null) throw new ArgumentNullException("context"); @@ -310,43 +332,43 @@ protected override TypeDefinition ParseTypeElement(XElement typeElement, ParserC protected override Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context) { if(stmtElement == null) throw new ArgumentNullException("stmtElement"); - if(stmtElement.Name != SRC.DeclarationStatement) + if (stmtElement.Name != SRC.DeclarationStatement && stmtElement.Name != SRC.Property) throw new ArgumentException("Must be a SRC.DeclarationStatement element", "stmtElement"); if(context == null) throw new ArgumentNullException("context"); //first check if this is a property and parse accordingly - var declElement = stmtElement.Element(SRC.Declaration); - if(declElement != null) { - var blockElement = declElement.Element(SRC.Block); - if(blockElement != null) { - //this is a property - return ParsePropertyDeclarationElement(declElement, context); - } + if (stmtElement.Name == SRC.Property) { + return ParsePropertyDeclarationElement(stmtElement, context); + } else { + var stmt = new DeclarationStatement() { + ProgrammingLanguage = ParserLanguage, + Content = ParseExpression(GetChildExpressions(stmtElement), context) + }; + stmt.AddLocation(context.CreateLocation(stmtElement)); + return stmt; } - //otherwise, parse as base: - return base.ParseDeclarationStatementElement(stmtElement, context); } /// - /// Creates a object for . + /// Creates a object for . /// - /// The SRC.Declaration element to parse. This must be a declaration of a property. + /// The SRC.Declaration element to parse. This must be a declaration of a property. /// The context to use. - /// A corresponding to . - protected virtual PropertyDefinition ParsePropertyDeclarationElement(XElement declElement, ParserContext context) { - if(declElement == null) - throw new ArgumentNullException("declElement"); - if(declElement.Name != SRC.Declaration) - throw new ArgumentException("Must be a SRC.Declaration element", "declElement"); + /// A corresponding to . + protected virtual PropertyDefinition ParsePropertyDeclarationElement(XElement propertyElement, ParserContext context) { + if(propertyElement == null) + throw new ArgumentNullException("propertyElement"); + if(propertyElement.Name != SRC.Property) + throw new ArgumentException("Must be a SRC.Property element", "propertyElement"); if(context == null) throw new ArgumentNullException("context"); var propertyDef = new PropertyDefinition {ProgrammingLanguage = ParserLanguage}; - propertyDef.AddLocation(context.CreateLocation(declElement)); + propertyDef.AddLocation(context.CreateLocation(propertyElement)); - foreach(var child in declElement.Elements()) { + foreach(var child in propertyElement.Elements()) { if(child.Name == SRC.Type) { propertyDef.Accessibility = GetAccessModifierFromTypeUseElement(child); propertyDef.ReturnType = ParseTypeUseElement(child, context); diff --git a/ABB.SrcML.Data/InterfaceDefinition.cs b/ABB.SrcML.Data/InterfaceDefinition.cs new file mode 100644 index 0000000..1f786d3 --- /dev/null +++ b/ABB.SrcML.Data/InterfaceDefinition.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; + +namespace ABB.SrcML.Data { + [DebuggerTypeProxy(typeof(StatementDebugView))] + public class InterfaceDefinition : NamedScope { + /// The XML name for InterfaceDefinition. + public new const string XmlName = "Interface"; + } +} diff --git a/ABB.SrcML.Data/JavaCodeParser.cs b/ABB.SrcML.Data/JavaCodeParser.cs index a43f3a3..2c71b30 100644 --- a/ABB.SrcML.Data/JavaCodeParser.cs +++ b/ABB.SrcML.Data/JavaCodeParser.cs @@ -40,6 +40,7 @@ public override Language ParserLanguage { } + /// /// Gets the parent type from a java type /// @@ -94,7 +95,16 @@ protected override string GetTypeForNumberLiteral(string literalValue) { protected override string GetTypeForStringLiteral(string literalValue) { throw new NotImplementedException(); } - + /// + /// + /// + /// + /// + /// + protected override InterfaceDefinition ParseInterfaceElement(XElement interfaceElement, ParserContext context) { + return new InterfaceDefinition(); + } + protected override UsingBlockStatement ParseUsingBlockElement(XElement usingElement, ParserContext context) { return new UsingBlockStatement(); } /// /// Creates a NamespaceDefinition object from the given Java package element. /// This will create a NamespaceDefinition for each component of the name, e.g. com.java.foo.bar, and link them as children of each other. @@ -222,7 +232,30 @@ protected override ConditionBlockStatement ParseForElement(XElement forElement, return foreachStmt; } + /// + /// Creates a object for . + /// The expression contained within will be parsed and placed in + /// Statement.Content. + /// + /// The SRC.DeclarationStatement element to parse. + /// The context to use. + /// A corresponding to . + /// The return type is so that subclasses can return another type, as necessary. + protected override Statement ParseDeclarationStatementElement(XElement stmtElement, ParserContext context) { + if (stmtElement == null) + throw new ArgumentNullException("stmtElement"); + if (stmtElement.Name != SRC.DeclarationStatement && stmtElement.Name != SRC.Property) + throw new ArgumentException("Must be a SRC.DeclarationStatement or SRC.Property element", "stmtElement"); + if (context == null) + throw new ArgumentNullException("context"); + var stmt = new DeclarationStatement() { + ProgrammingLanguage = ParserLanguage, + Content = ParseExpression(GetChildExpressions(stmtElement), context) + }; + stmt.AddLocation(context.CreateLocation(stmtElement)); + return stmt; + } /// /// Parses the given and creates an ImportStatement or AliasStatement from it. /// diff --git a/ABB.SrcML.Data/NameUse.cs b/ABB.SrcML.Data/NameUse.cs index aca1ba6..19ad271 100644 --- a/ABB.SrcML.Data/NameUse.cs +++ b/ABB.SrcML.Data/NameUse.cs @@ -319,7 +319,7 @@ protected IEnumerable GetCallingScope() { scopes.Add((NamedScope)match); } } - return scopes; + if (scopes.Count == 0) return null; else return scopes; } diff --git a/ABB.SrcML.Data/XNameMaps.cs b/ABB.SrcML.Data/XNameMaps.cs index a19f610..1fde8a1 100644 --- a/ABB.SrcML.Data/XNameMaps.cs +++ b/ABB.SrcML.Data/XNameMaps.cs @@ -36,6 +36,7 @@ public static TypeKind GetKindForXElement(XElement typeElement) { var map = new Dictionary() { { SRC.Struct, TypeKind.Struct }, { SRC.StructDeclaration, TypeKind.Struct }, + { SRC.Interface, TypeKind.Interface}, { SRC.Class, TypeKind.Class }, { SRC.ClassDeclaration, TypeKind.Class }, { SRC.Union, TypeKind.Union }, diff --git a/ABB.SrcML.Test/ABB.SrcML.Test.csproj b/ABB.SrcML.Test/ABB.SrcML.Test.csproj index 7eadaf7..deb4ae9 100644 --- a/ABB.SrcML.Test/ABB.SrcML.Test.csproj +++ b/ABB.SrcML.Test/ABB.SrcML.Test.csproj @@ -14,6 +14,7 @@ v4.0 512 ..\ + true true @@ -96,6 +97,13 @@ + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + + + + + + + TestPassed + + \ No newline at end of file diff --git a/TestInputs/function_def.xml b/TestInputs/function_def.xml index 246fbd9..ced6495 100644 --- a/TestInputs/function_def.xml +++ b/TestInputs/function_def.xml @@ -1,5 +1,5 @@ -#include <iostream> +#include <iostream> char* MyFunction(int foo) { if(foo > 0) { @@ -10,7 +10,7 @@ } int main(int argc, char* argv[]) { - std::cout<<MyFunction(42); + int foo = 17; return 0; } From d822854e58d8352491ad5a559688b238f27192f9 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Mon, 8 Feb 2016 18:06:38 -0500 Subject: [PATCH 16/17] These tests weren't in srcml.data but I converted them anyway. --- ABB.SrcML.Test/SrcMLElementTests.cs | 80 ++++++++++++++++------------- 1 file changed, 43 insertions(+), 37 deletions(-) diff --git a/ABB.SrcML.Test/SrcMLElementTests.cs b/ABB.SrcML.Test/SrcMLElementTests.cs index 8eba71f..01b8052 100644 --- a/ABB.SrcML.Test/SrcMLElementTests.cs +++ b/ABB.SrcML.Test/SrcMLElementTests.cs @@ -17,6 +17,7 @@ using System.Xml.Linq; using NUnit.Framework; using ABB.SrcML; +using System.Collections.ObjectModel; namespace ABB.SrcML.Test { /// @@ -32,9 +33,9 @@ public void ClassSetup() { //construct the necessary srcML wrapper unit tags XmlNamespaceManager xnm = SrcML.NamespaceManager; StringBuilder namespaceDecls = new StringBuilder(); - foreach(string prefix in xnm) { - if(prefix != string.Empty && !prefix.StartsWith("xml", StringComparison.OrdinalIgnoreCase)) { - if(prefix.Equals("src", StringComparison.OrdinalIgnoreCase)) { + foreach (string prefix in xnm) { + if (prefix != string.Empty && !prefix.StartsWith("xml", StringComparison.OrdinalIgnoreCase)) { + if (prefix.Equals("src", StringComparison.OrdinalIgnoreCase)) { namespaceDecls.AppendFormat("xmlns=\"{0}\" ", xnm.LookupNamespace(prefix)); } else { namespaceDecls.AppendFormat("xmlns:{0}=\"{1}\" ", prefix, xnm.LookupNamespace(prefix)); @@ -46,52 +47,57 @@ public void ClassSetup() { [Test] public void TestGetMethodSignature_Normal() { - string testSrcML = @"char* MyClass::foo(int bar) { - if(bar > GetNumber()) { - return ""Hello, world!""; - } else { - return ""Goodbye cruel world!""; - } -}"; - XElement xml = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace); - - string actual = SrcMLElement.GetMethodSignature(xml.Element(SRC.Function)); + string testSrcML = @"char* MyClass::foo(int bar) { + if(bar > GetNumber()) { + return 'Hello, world!'; + } else { + return 'Goodbye cruel world!'; + }"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(testSrcML, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + XElement xml = XElement.Parse(srcMLA, LoadOptions.PreserveWhitespace); + + string actual = SrcMLElement.GetMethodSignature(xml.Descendants(SRC.Function).First()); string expected = "char* MyClass::foo(int bar)"; Assert.AreEqual(expected, actual); } [Test] public void TestGetMethodSignature_Whitespace() { - string testSrcML = @"char* MyClass::foo( - int bar, - int baz, - float xyzzy) -{ - if(bar > GetNumber()) { - return ""Hello, world!""; - } else { - return ""Goodbye cruel world!""; - } -}"; - XElement xml = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace); - - string actual = SrcMLElement.GetMethodSignature(xml.Element(SRC.Function)); + string testSrcML = @"char* MyClass::foo( + int bar, + int baz, + float xyzzy) +{ + if(bar > GetNumber()) { + return 'Hello, world!'; + } else { + return 'Goodbye cruel world!'; + } +}"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(testSrcML, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + XElement xml = XElement.Parse(srcMLA, LoadOptions.PreserveWhitespace); + + string actual = SrcMLElement.GetMethodSignature(xml.Descendants(SRC.Function).First()); string expected = "char* MyClass::foo( int bar, int baz, float xyzzy)"; Assert.AreEqual(expected, actual); } [Test] public void TestGetMethodSignature_InitializerList() { - string testSrcML = @"MyClass::MyClass(int bar) : _capacity(15), _len(0) { - if(bar > GetNumber()) { - return ""Hello, world!""; - } else { - return ""Goodbye cruel world!""; - } -}"; - XElement xml = XElement.Parse(string.Format(srcMLFormat, testSrcML), LoadOptions.PreserveWhitespace); - - string actual = SrcMLElement.GetMethodSignature(xml.Element(SRC.Constructor)); + string testSrcML = @"MyClass::MyClass(int bar) : _capacity(15), _len(0) { + if(bar > GetNumber()) { + return 'Hello, world!'; + } else { + return 'Goodbye cruel world!'; + } +}"; + LibSrcMLRunner runA = new LibSrcMLRunner(); + string srcMLA = runA.GenerateSrcMLFromString(testSrcML, "A.cs", Language.CSharp, new Collection() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false); + XElement xml = XElement.Parse(srcMLA, LoadOptions.PreserveWhitespace); + + string actual = SrcMLElement.GetMethodSignature(xml.Descendants(SRC.Constructor).First()); string expected = "MyClass::MyClass(int bar)"; Assert.AreEqual(expected, actual); } From 2666c11de9ad9cd342283a3673611b2a6708f3e4 Mon Sep 17 00:00:00 2001 From: Christian Newman Date: Wed, 10 Feb 2016 15:19:38 -0500 Subject: [PATCH 17/17] I started swapping tests in this file but then realized it's the generator tests for the other srcml generator. Not sure if this should happen or not. --- ABB.SrcML.Test/SrcMLGeneratorTests.cs | 29 ++++++++++++++++++--------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/ABB.SrcML.Test/SrcMLGeneratorTests.cs b/ABB.SrcML.Test/SrcMLGeneratorTests.cs index 667685c..3bace4d 100644 --- a/ABB.SrcML.Test/SrcMLGeneratorTests.cs +++ b/ABB.SrcML.Test/SrcMLGeneratorTests.cs @@ -18,6 +18,7 @@ using ABB.SrcML; using System.Xml.Linq; using ABB.SrcML.Utilities; +using System.Collections.ObjectModel; namespace ABB.SrcML.Test { [TestFixture] @@ -90,13 +91,15 @@ public void DifferentLanguageTest() { } [Test, Category("SrcMLUpdate")] - public void TestStrangeEncodings([Values(@"badPathTest\BadPath™\badPathTest.c", @"srcmltest\fooBody.c")] string sourceFileName) + public void TestStrangeEncodings([Values(@"badPathTest\BadPath™\badPathTest.c", @"srcmltest\foo.c")] string sourceFileName) { - var xmlFileName = Path.Combine("srcml_xml", Path.GetFileName(Path.ChangeExtension(sourceFileName, ".xml"))); - generator.GenerateSrcMLFromFile(sourceFileName, xmlFileName, Language.C); - Console.WriteLine("FILE: {0}", sourceFileName); - var doc = new SrcMLFile(xmlFileName); + LibSrcMLRunner runner = new LibSrcMLRunner(); + runner.GenerateSrcMLFromFile(sourceFileName, "output", Language.C, new Collection { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary { }); + + Assert.IsTrue(File.Exists("output0.xml")); + SrcMLFile doc = new SrcMLFile("output0.xml"); //Test failing because this can't read the unit? Assert.IsNotNull(doc); + } [Test] @@ -139,7 +142,9 @@ public void SingleFileTest() { [Test] public void MultipleFilesTest() { - var doc = generator.GenerateSrcMLFileFromFiles(new string[] { "srcmltest\\foo.c", "srcmltest\\bar.c" }, "srcml_xml\\multiplefile.xml"); + LibSrcMLRunner runner = new LibSrcMLRunner(); + runner.GenerateSrcMLFromFiles(new string[] { "srcmltest\\foo.c", "srcmltest\\bar.c" }, "output", Language.CPlusPlus, new Collection { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary { }); + SrcMLFile doc = new SrcMLFile("output0.xml"); Assert.IsNotNull(doc); var files = doc.FileUnits.ToList(); @@ -162,7 +167,9 @@ where ele.Attribute("filename").Value == file1 /// [Test] public void MultipleFilesTest_DifferentDirectories() { - var doc = generator.GenerateSrcMLFileFromFiles(new string[] { "srcmltest\\foo.c", "srcmltest\\bar.c", "..\\..\\TestInputs\\baz.cpp" }, "srcml_xml\\multiplefile.xml"); + LibSrcMLRunner runner = new LibSrcMLRunner(); + runner.GenerateSrcMLFromFiles(new string[] { "srcmltest\\foo.c", "srcmltest\\bar.c", "..\\..\\TestInputs\\baz.cpp" }, "output", Language.CPlusPlus, new Collection { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary { }); + SrcMLFile doc = new SrcMLFile("output0.xml"); Assert.IsNotNull(doc); var files = doc.FileUnits.ToList(); @@ -180,11 +187,11 @@ where ele.Attribute("filename").Value == file2 select ele); Assert.AreEqual("srcmltest\\bar.c", f2.FirstOrDefault().Attribute("filename").Value); - string file3 = "\\..\\TestInputs\\baz.cpp"; + string file3 = "..\\..\\TestInputs\\baz.cpp"; var f3 = (from ele in files where ele.Attribute("filename").Value == file3 select ele); - Assert.AreEqual("\\..\\TestInputs\\baz.cpp", f3.FirstOrDefault().Attribute("filename").Value); + Assert.AreEqual("..\\..\\TestInputs\\baz.cpp", f3.FirstOrDefault().Attribute("filename").Value); } [Test] @@ -267,7 +274,9 @@ public void TestGenerateSrcMLFromFile_NonDefaultExtension() { [Test] public void TestGenerateSrcMLFromFiles_NonDefaultExtension() { - var doc = generator.GenerateSrcMLFileFromFiles(new[] {@"srcmltest\File with spaces.cpp", @"srcmltest\CSHARP.cs", @"srcmltest\foo.c"}, @"srcml_xml\multiple_files_csharp.xml"); + LibSrcMLRunner runner = new LibSrcMLRunner(); + runner.GenerateSrcMLFromFiles(new[] {@"srcmltest\File with spaces.cpp", @"srcmltest\CSHARP.cs", @"srcmltest\foo.c"}, "output", Language.CPlusPlus, new Collection { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary { }); + SrcMLFile doc = new SrcMLFile("output0.xml"); Assert.IsNotNull(doc); Assert.AreEqual(3, doc.FileUnits.Count()); }