本文整理汇总了C#中LibSrcMLRunner类的典型用法代码示例。如果您正苦于以下问题:C# LibSrcMLRunner类的具体用法?C# LibSrcMLRunner怎么用?C# LibSrcMLRunner使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LibSrcMLRunner类属于命名空间,在下文中一共展示了LibSrcMLRunner类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: TestCppBuiltIns_WithSingleWord
public void TestCppBuiltIns_WithSingleWord() {
// #a.cpp TYPE a; TYPE b;
string xmlFormat = @"{0} a; {0} b;";
foreach(var builtIn in new string[] { "char", "short", "int", "long", "bool", "float", "double", "wchar_t" }) {
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(String.Format(xmlFormat, builtIn), "a.cpp", Language.CPlusPlus, new Collection<UInt32>() { }, false);
var aXml = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "a.cpp");
var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(aXml);
var variables = from stmt in globalScope.GetDescendants()
from declaration in stmt.GetExpressions().OfType<VariableDeclaration>()
select declaration;
var variableA = variables.FirstOrDefault();
var variableB = variables.LastOrDefault();
Assert.AreEqual("a", variableA.Name);
Assert.AreEqual("b", variableB.Name);
Assert.AreEqual(builtIn, variableA.VariableType.Name);
var typeOfA = variableA.VariableType.FindMatches().First();
var typeOfB = variableB.VariableType.FindMatches().First();
Assert.AreSame(typeOfA, typeOfB);
}
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:27,代码来源:BuiltInTypeFactoryTests.cs
示例2: TestGetCallsTo_Simple
public void TestGetCallsTo_Simple() {
string xml = @"void foo() {
printf('Hello');
}
int main() {
foo();
return 0;
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "Foo.cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.cpp");
var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(xmlElement);
var fooMethod = globalScope.GetNamedChildren<MethodDefinition>("foo").First();
var mainMethod = globalScope.GetNamedChildren<MethodDefinition>("main").First();
Assert.That(mainMethod.ContainsCallTo(fooMethod));
var fooCalls = mainMethod.GetCallsTo(fooMethod, true).ToList();
Assert.AreEqual(1, fooCalls.Count);
var expectedFooCall = mainMethod.FindExpressions<MethodCall>(true).First(mc => mc.Name == "foo");
Assert.AreSame(expectedFooCall, fooCalls[0]);
var callsToFoo = fooMethod.GetCallsToSelf().ToList();
Assert.AreEqual(1, callsToFoo.Count);
Assert.AreSame(expectedFooCall, callsToFoo[0]);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:28,代码来源:StatementExtensionTests.cs
示例3: TestCppBuiltIns_WithDoubleWord
public void TestCppBuiltIns_WithDoubleWord() {
// #a.cpp #example: "unsigned int a;"; MODIFIER TYPE a; MODIFIER TYPE b;
string xmlFormat = @"{0} {1} a; {0} {1} b;";
foreach(var builtInModifier in new string[] { "unsigned", "signed", "long" }) {
foreach(var builtIn in new string[] { "int", "double" }) {
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(String.Format(xmlFormat, builtInModifier, builtIn), "a.cpp", Language.CPlusPlus, new Collection<UInt32>() { }, false);
var aXml = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "a.cpp");
var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(aXml);
var variables = from stmt in globalScope.GetDescendants()
from declaration in stmt.GetExpressions().OfType<VariableDeclaration>()
select declaration;
var variableA = variables.FirstOrDefault();
var variableB = variables.LastOrDefault();
Assert.AreEqual("a", variableA.Name);
Assert.AreEqual("b", variableB.Name);
Assert.AreEqual(String.Format("{0} {1}", builtInModifier, builtIn), variableA.VariableType.Name, "TODO: Fix compound types");
var typeOfA = variableA.VariableType.FindMatches().First();
var typeOfB = variableB.VariableType.FindMatches().First();
Assert.AreSame(typeOfA, typeOfB);
}
}
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:27,代码来源:BuiltInTypeFactoryTests.cs
示例4: TestField
public void TestField(Language lang) {
string xml = @"class A {
int Foo;
Bar baz;
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "test.code", lang, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var xmlElement = fileSetup[lang].GetFileUnitForXmlSnippet(srcML, "test.code");
var globalScope = codeParsers[lang].ParseFileUnit(xmlElement);
var declStmts = globalScope.GetDescendantsAndSelf<DeclarationStatement>().ToList();
Assert.AreEqual(2, declStmts.Count);
var foo = declStmts[0].Content.GetDescendantsAndSelf<VariableDeclaration>().FirstOrDefault();
Assert.IsNotNull(foo);
Assert.AreEqual("Foo", foo.Name);
Assert.AreEqual("int", foo.VariableType.Name);
Assert.AreEqual(AccessModifier.None, foo.Accessibility);
var baz = declStmts[1].Content.GetDescendantsAndSelf<VariableDeclaration>().FirstOrDefault();
Assert.IsNotNull(baz);
Assert.AreEqual("baz", baz.Name);
Assert.AreEqual("Bar", baz.VariableType.Name);
Assert.AreEqual(AccessModifier.None, baz.Accessibility);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:26,代码来源:CodeParserTests.cs
示例5: TestRemoveClass_Namespace
public void TestRemoveClass_Namespace() {
string fooXml = @"package com.ABB.Example;
class Foo {
private int bar;
public Foo() { bar = 42; }
public int GetBar() { return bar; }
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(fooXml, "Foo.java", Language.Java, new Collection<UInt32>() { }, false);
var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.java");
var beforeScope = CodeParser.ParseFileUnit(fooFileUnit);
string bazXml = @"package com.ABB.Example;
class Baz {
public static int DoWork() { return 0; }
}";
LibSrcMLRunner runA = new LibSrcMLRunner();
string srcMLA = runA.GenerateSrcMLFromString(bazXml, "Baz.java", Language.Java, new Collection<UInt32>() { }, false);
var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Baz.java");
var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit));
Assert.AreEqual(1, afterScope.ChildStatements.OfType<NamespaceDefinition>().Count());
afterScope.RemoveFile("Baz.java");
DataAssert.StatementsAreEqual(beforeScope, afterScope);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:27,代码来源:FileRemovalTests_Java.cs
示例6: TestRemoveMethodFromClass
public void TestRemoveMethodFromClass() {
string cppXml = @"int Foo::Add(int b) {
return this->a + b;
}";
LibSrcMLRunner runA = new LibSrcMLRunner();
string srcMLA = runA.GenerateSrcMLFromString(cppXml, "A.cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var cppFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A.cpp");
string hXml = @"class Foo {
public:
int a;
int Add(int b);
};";
LibSrcMLRunner runB = new LibSrcMLRunner();
string srcMLB = runB.GenerateSrcMLFromString(hXml, "A.h", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var hFileunit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLB, "A.h");
var beforeScope = CodeParser.ParseFileUnit(hFileunit);
var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(cppFileUnit));
Assert.AreEqual(1, afterScope.ChildStatements.Count());
Assert.IsNotNull(afterScope.ChildStatements.First() as TypeDefinition);
afterScope.RemoveFile("A.cpp");
DataAssert.StatementsAreEqual(beforeScope, afterScope);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:29,代码来源:FileRemovalTests_Cpp.cs
示例7: TestGetCallsTo_Multiple
public void TestGetCallsTo_Multiple() {
string xml = @"void star() { }
void bar() { star(); }
void foo() {
bar();
if(0) bar();
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "Foo.cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var unit = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Foo.cpp");
var globalScope = CodeParser[Language.CPlusPlus].ParseFileUnit(unit);
var methodFoo = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "foo");
var methodBar = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "bar");
var methodStar = globalScope.GetDescendants<MethodDefinition>().First(md => md.Name == "star");
Assert.That(methodFoo.ContainsCallTo(methodBar));
Assert.AreEqual(2, methodFoo.GetCallsTo(methodBar, true).Count());
Assert.That(methodBar.ContainsCallTo(methodStar));
Assert.AreEqual(1, methodBar.GetCallsTo(methodStar, true).Count());
Assert.IsFalse(methodFoo.ContainsCallTo(methodStar));
Assert.IsFalse(methodBar.ContainsCallTo(methodFoo));
Assert.IsFalse(methodStar.ContainsCallTo(methodFoo));
Assert.IsFalse(methodStar.ContainsCallTo(methodBar));
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:32,代码来源:StatementExtensionTests.cs
示例8: TestConstructorMerge_Cpp
public void TestConstructorMerge_Cpp() {
string header_xml = @"class A { A(); };";
string impl_xml = @"A::A() { }";
LibSrcMLRunner runA = new LibSrcMLRunner();
string srcMLA = runA.GenerateSrcMLFromString(header_xml, "A.h", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var header = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLA, "A.h");
LibSrcMLRunner runE = new LibSrcMLRunner();
string srcMLE = runE.GenerateSrcMLFromString(impl_xml, "A.cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var implementation = FileUnitSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcMLE, "A.cpp");
var headerScope = CodeParser[Language.CPlusPlus].ParseFileUnit(header);
var implementationScope = CodeParser[Language.CPlusPlus].ParseFileUnit(implementation);
var globalScope = headerScope.Merge(implementationScope);
Assert.AreEqual(1, globalScope.ChildStatements.Count());
var typeA = globalScope.ChildStatements.First() as TypeDefinition;
Assert.AreEqual("A", typeA.Name);
Assert.AreEqual(1, typeA.ChildStatements.Count());
Assert.AreEqual("A.h", typeA.PrimaryLocation.SourceFileName);
var constructor = typeA.ChildStatements.First() as MethodDefinition;
Assert.That(constructor.IsConstructor);
Assert.IsFalse(constructor.IsDestructor);
Assert.IsFalse(constructor.IsPartial);
Assert.AreEqual(AccessModifier.Private, constructor.Accessibility);
Assert.AreEqual("A.cpp", constructor.PrimaryLocation.SourceFileName);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:31,代码来源:MergeTests.cs
示例9: TestDataFileNameMap
public void TestDataFileNameMap(bool compressionEnabled) {
//I'm not exactly sure what this test is testing for, but the way files are named by the library
//is not playing well with this test. Seems like it wants a specific file extension. Some decision
//will have to be made about how to handle this problem. Does the library need to generate names differently?
//Or maybe this test should be different?
var generator = new DataGenerator();
var mapping = new DataFileNameMapping(TEST_DIRECTORY, compressionEnabled);
var sourcePath = @"..\..\TestInputs\function_def.cpp";
var srcmlPath = @"..\..\TestInputs\function_def.xml";
var mappedPath = mapping.GetTargetPath(sourcePath);
var actualExtension = Path.GetExtension(mappedPath);
var expectedExtension = (compressionEnabled ? XmlSerialization.DEFAULT_COMPRESSED_EXTENSION : XmlSerialization.DEFAULT_EXTENSION);
StringAssert.AreEqualIgnoringCase(expectedExtension, actualExtension);
//generator.Generate(srcmlPath, mappedPath);
LibSrcMLRunner runner = new LibSrcMLRunner();
runner.GenerateSrcMLFromFile(srcmlPath, mappedPath, Language.CPlusPlus, new Collection<uint> { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary<string, Language> { });
Assert.That(File.Exists(mappedPath), String.Format("Could not generate {0}", mappedPath));
var data = XmlSerialization.Load(mappedPath, compressionEnabled);
Assert.IsNotNull(data, String.Format("Could not load data from {0}. It should {1}be compressed", mappedPath, compressionEnabled ? String.Empty : "not "));
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:26,代码来源:DataFileNameMappingTests.cs
示例10: TestRemoveClass_Global
public void TestRemoveClass_Global() {
string fooXml = @"class Foo {
private int bar;
public Foo() { bar = 42; }
public int GetBar() { return bar; }
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(fooXml, "Foo.cs", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var fooFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs");
var beforeScope = CodeParser.ParseFileUnit(fooFileUnit);
string bazXml = @"class Baz {
public static int DoWork() { return 0; }
}";
LibSrcMLRunner runA = new LibSrcMLRunner();
string srcMLA = runA.GenerateSrcMLFromString(bazXml, "Baz.cs", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var bazFileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "Baz.cs");
var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(bazFileUnit));
Assert.AreEqual(0, afterScope.ChildStatements.OfType<NamespaceDefinition>().Count());
Assert.AreEqual(2, afterScope.ChildStatements.OfType<TypeDefinition>().Count());
afterScope.RemoveFile("Baz.cs");
DataAssert.StatementsAreEqual(beforeScope, afterScope);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:26,代码来源:FileRemovalTests_CSharp.cs
示例11: TestRemovePartialClass
public void TestRemovePartialClass() {
string a1Xml = @"public partial class A {
public int Execute() {
return 0;
}
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(a1Xml, "A1.cs", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var a1FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcML, "A1.cs");
var beforeScope = CodeParser.ParseFileUnit(a1FileUnit);
string a2Xml = @"public partial class A {
private bool Foo() {
return true;
}
}";
LibSrcMLRunner runA = new LibSrcMLRunner();
string srcMLA = runA.GenerateSrcMLFromString(a2Xml, "A2.cs", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var a2FileUnit = FileUnitSetup.GetFileUnitForXmlSnippet(srcMLA, "A2.cs");
var afterScope = beforeScope.Merge(CodeParser.ParseFileUnit(a2FileUnit));
Assert.AreEqual(1, afterScope.ChildStatements.Count());
var typeA = afterScope.ChildStatements.First() as TypeDefinition;
Assert.IsNotNull(typeA);
Assert.AreEqual(2, typeA.ChildStatements.OfType<MethodDefinition>().Count());
Assert.IsTrue(typeA.ChildStatements.OfType<MethodDefinition>().Any(m => m.Name == "Execute"));
Assert.IsTrue(typeA.ChildStatements.OfType<MethodDefinition>().Any(m => m.Name == "Foo"));
afterScope.RemoveFile("A2.cs");
DataAssert.StatementsAreEqual(beforeScope, afterScope);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:32,代码来源:FileRemovalTests_CSharp.cs
示例12: TestCreateTypeDefinition_ClassInPackage
public void TestCreateTypeDefinition_ClassInPackage() {
string xml = @"package A.B.C;
public class D { }";
LibSrcMLRunner runD = new LibSrcMLRunner();
string srcMLA = runD.GenerateSrcMLFromString(xml, "D.java", Language.Java, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "D.java");
var globalScope = codeParser.ParseFileUnit(xmlElement);
Assert.IsTrue(globalScope.IsGlobal);
Assert.AreEqual(1, globalScope.ChildStatements.Count());
var packageA = globalScope.ChildStatements.First() as NamespaceDefinition;
Assert.IsNotNull(packageA);
Assert.AreEqual("A", packageA.Name);
Assert.IsFalse(packageA.IsGlobal);
Assert.AreEqual(1, packageA.ChildStatements.Count());
var packageAB = packageA.ChildStatements.First() as NamespaceDefinition;
Assert.IsNotNull(packageAB);
Assert.AreEqual("B", packageAB.Name);
Assert.IsFalse(packageAB.IsGlobal);
Assert.AreEqual(1, packageAB.ChildStatements.Count());
var packageABC = packageAB.ChildStatements.First() as NamespaceDefinition;
Assert.IsNotNull(packageABC);
Assert.AreEqual("C", packageABC.Name);
Assert.IsFalse(packageABC.IsGlobal);
Assert.AreEqual(1, packageABC.ChildStatements.Count());
var typeD = packageABC.ChildStatements.First() as TypeDefinition;
Assert.IsNotNull(typeD, "Type D is not a type definition");
Assert.AreEqual("D", typeD.Name);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:33,代码来源:JavaCodeParserTests.cs
示例13: TestGlobalStatement
public void TestGlobalStatement() {
var xml = @"char* bar = 'Hello, world!';
int foo = 42;";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "Example.cpp", Language.CSharp, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
var unit = fileSetup[Language.CPlusPlus].GetFileUnitForXmlSnippet(srcML, "Example.cpp");
var globalScope = parser[Language.CPlusPlus].ParseFileUnit(unit);
var actual = globalScope.GetStatementForLocation(new SourceLocation("Example.cpp", 2, 5));
Assert.AreSame(globalScope.ChildStatements[0], actual);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:10,代码来源:GetStatementTests.cs
示例14: TestContains_Reflexive
public void TestContains_Reflexive() {
var xml = @"class Foo {
int Bar(){return 0;}
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection<UInt32>() { }, false);
var classElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Class).First();
var classLoc = new SrcMLLocation(classElement, "Foo.cs");
Assert.IsTrue(classLoc.Contains(classLoc));
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:10,代码来源:SrcMLLocationTests.cs
示例15: TestContains_TwoLevel
public void TestContains_TwoLevel() {
var xml = @"namespace Example {
class Foo {
int Bar(){return 0;}
}
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "Example.cs", Language.CSharp, new Collection<UInt32>() { }, false);
var namespaceElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Example.cs").Element(SRC.Namespace);
var methodElement = namespaceElement.Descendants(SRC.Function).First();
var namespaceLoc = new SrcMLLocation(namespaceElement, "Example.cs");
var methodLoc = new SrcMLLocation(methodElement, "Example.cs");
Assert.IsTrue(namespaceLoc.Contains(methodLoc));
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:14,代码来源:SrcMLLocationTests.cs
示例16: TestCreateAliasesForFiles_ImportClass
public void TestCreateAliasesForFiles_ImportClass() {
string xml = @"import x.y.z;";
LibSrcMLRunner runA = new LibSrcMLRunner();
string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java");
var globalScope = codeParser.ParseFileUnit(xmlElement);
Assert.AreEqual(1, globalScope.ChildStatements.Count);
var actual = globalScope.ChildStatements[0] as AliasStatement;
Assert.IsNotNull(actual);
Assert.AreEqual("z", actual.AliasName);
Assert.AreEqual("x . y . z", actual.Target.ToString());
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:14,代码来源:JavaCodeParserTests.cs
示例17: TestCreateAliasesForFiles_ImportNamespace
public void TestCreateAliasesForFiles_ImportNamespace() {
string xml = @"import x . /*test */ y /*test */ . z .* /*test*/;";
//<import>import <name><name>x</name> <op:operator>.</op:operator> <comment type=""block"">/*test */</comment> <name>y</name> <comment type=""block"">/*test */</comment> <op:operator>.</op:operator> <name>z</name></name> .* <comment type=""block"">/*test*/</comment>;</import>";
LibSrcMLRunner runA = new LibSrcMLRunner();
string srcMLA = runA.GenerateSrcMLFromString(xml, "A.java", Language.Java, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.java");
var globalScope = codeParser.ParseFileUnit(xmlElement);
Assert.AreEqual(1, globalScope.ChildStatements.Count);
var actual = globalScope.ChildStatements[0] as ImportStatement;
Assert.IsNotNull(actual);
Assert.AreEqual("x . y . z", actual.ImportedNamespace.ToString());
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:14,代码来源:JavaCodeParserTests.cs
示例18: TestRoundTrip
public void TestRoundTrip(string sourceFileName, bool compressOutput) {
var sourceFilePath = Path.Combine(TestInputPath, sourceFileName);
var destFilePath = Path.Combine(TestInputPath, DefaultInputName);
LibSrcMLRunner runner = new LibSrcMLRunner();
runner.GenerateSrcMLFromFile(sourceFilePath, destFilePath + ".cpp", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, new Dictionary<string, Language>() { });
Assert.That(File.Exists(destFilePath + ".cpp0.xml"));
var fileUnit = SrcMLElement.Load(destFilePath + ".cpp0.xml");
var dataGenerator = new DataGenerator();
var nsd = dataGenerator.Parse(fileUnit.Element(SRC.Unit)) as NamespaceDefinition;
XmlSerialization.WriteElement(nsd, DefaultOutputName, compressOutput);
var nsdFromFile = XmlSerialization.Load(DefaultOutputName, compressOutput) as NamespaceDefinition;
DataAssert.StatementsAreEqual(nsd, nsdFromFile);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:16,代码来源:SerializationTests.cs
示例19: TestContains_Sibling
public void TestContains_Sibling() {
var xml = @"class Foo {
string Bar(){
string a = 'Hello, world!';
return a;
}
int Baz(){ return 0; }
}";
LibSrcMLRunner run = new LibSrcMLRunner();
string srcML = run.GenerateSrcMLFromString(xml, "Foo.cs", Language.CSharp, new Collection<UInt32>() { }, false);
var methodElement = fileUnitSetup.GetFileUnitForXmlSnippet(srcML, "Foo.cs").Descendants(SRC.Function).First();
var declElement = methodElement.Descendants(SRC.DeclarationStatement).First();
var methodLoc = new SrcMLLocation(methodElement, "Foo.cs");
var declLoc = new SrcMLLocation(declElement, "Foo.cs");
Assert.IsTrue(methodLoc.Contains(declLoc));
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:16,代码来源:SrcMLLocationTests.cs
示例20: TestCreateTypeDefinitions_ClassDeclaration
public void TestCreateTypeDefinitions_ClassDeclaration() {
string xml = @"class A;";
LibSrcMLRunner runA = new LibSrcMLRunner();
string srcMLA = runA.GenerateSrcMLFromString(xml, "A.h", Language.CPlusPlus, new Collection<UInt32>() { LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_POSITION }, false);
XElement xmlElement = fileSetup.GetFileUnitForXmlSnippet(srcMLA, "A.h");
var globalScope = codeParser.ParseFileUnit(xmlElement);
var actual = globalScope.ChildStatements.First() as TypeDefinition;
Assert.IsNotNull(actual);
Assert.AreEqual("A", actual.Name);
Assert.AreEqual(TypeKind.Class, actual.Kind);
Assert.That(globalScope.IsGlobal);
Assert.AreSame(globalScope, actual.ParentStatement);
}
开发者ID:cnewman,项目名称:SrcML.NET,代码行数:16,代码来源:CPlusPlusCodeParserTests.cs
注:本文中的LibSrcMLRunner类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论