Browse Source

- XmlAttribute renamed to XmlAttributeExpression (avoid conflict with System.Xml)

- finished conversion of XML literals

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/branches/vbnet@6045 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
pull/1/head
Siegfried Pammer 16 years ago
parent
commit
2da0781942
  1. 2
      src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs
  2. 2
      src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs
  3. 3
      src/Libraries/NRefactory/Project/NRefactory.csproj
  4. 9
      src/Libraries/NRefactory/Project/Src/Ast/Generated.cs
  5. 2
      src/Libraries/NRefactory/Project/Src/IAstVisitor.cs
  6. 2
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs
  7. 2
      src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG
  8. 14
      src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs
  9. 8
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs
  10. 12
      src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs
  11. 12
      src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs
  12. 4
      src/Libraries/NRefactory/Project/Src/Visitors/NotImplementedAstVisitor.cs
  13. 119
      src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs
  14. 103
      src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs
  15. 3
      src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs
  16. 55
      src/Libraries/NRefactory/Test/Parser/Expressions/XmlExpressionTests.cs

2
src/AddIns/BackendBindings/Boo/NRefactoryToBooConverter/Project/ConvertVisitor.cs

@ -265,7 +265,7 @@ namespace NRefactoryToBooConverter @@ -265,7 +265,7 @@ namespace NRefactoryToBooConverter
throw new NotImplementedException();
}
public object VisitXmlAttribute(XmlAttribute xmlAttribute, object data)
public object VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data)
{
throw new NotImplementedException();
}

2
src/Libraries/NRefactory/NRefactoryASTGenerator/AST/Expressions.cs

@ -431,7 +431,7 @@ namespace NRefactoryASTGenerator.Ast @@ -431,7 +431,7 @@ namespace NRefactoryASTGenerator.Ast
}
[IncludeBoolProperty("IsLiteralValue", "return expressionValue.IsNull;")]
class XmlAttribute : XmlExpression {
class XmlAttributeExpression : XmlExpression {
string name;
string literalValue;
bool useDoubleQuotes;

3
src/Libraries/NRefactory/Project/NRefactory.csproj

@ -55,6 +55,9 @@ @@ -55,6 +55,9 @@
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
<Reference Include="System.Xml" />
<Reference Include="System.Xml.Linq">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Src\Parser\VBNet\Experimental\ExpressionFinder.cs" />

9
src/Libraries/NRefactory/Project/Src/Ast/Generated.cs

@ -5458,7 +5458,7 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L @@ -5458,7 +5458,7 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L
}
}
public class XmlAttribute : XmlExpression {
public class XmlAttributeExpression : XmlExpression {
string name;
@ -5505,7 +5505,7 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L @@ -5505,7 +5505,7 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L
}
}
public XmlAttribute() {
public XmlAttributeExpression() {
name = "";
literalValue = "";
expressionValue = Expression.Null;
@ -5518,11 +5518,12 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L @@ -5518,11 +5518,12 @@ public UsingDeclaration(string @namespace, TypeReference alias) { usings = new L
}
public override object AcceptVisitor(IAstVisitor visitor, object data) {
return visitor.VisitXmlAttribute(this, data);
return visitor.VisitXmlAttributeExpression(this, data);
}
public override string ToString() {
return string.Format("[XmlAttribute Name={0} LiteralValue={1} UseDoubleQuotes={2} ExpressionValue={3}]", Name, LiteralValue, UseDoubleQuotes, ExpressionValue);
return string.Format("[XmlAttributeExpression Name={0} LiteralValue={1} UseDoubleQuotes={2} ExpressionV" +
"alue={3}]", Name, LiteralValue, UseDoubleQuotes, ExpressionValue);
}
}

2
src/Libraries/NRefactory/Project/Src/IAstVisitor.cs

@ -261,7 +261,7 @@ namespace ICSharpCode.NRefactory { @@ -261,7 +261,7 @@ namespace ICSharpCode.NRefactory {
object VisitWithStatement(WithStatement withStatement, object data);
object VisitXmlAttribute(XmlAttribute xmlAttribute, object data);
object VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data);
object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data);

2
src/Libraries/NRefactory/Project/Src/Parser/VBNet/Parser.cs

@ -4794,7 +4794,7 @@ out expressionValue); @@ -4794,7 +4794,7 @@ out expressionValue);
} else SynErr(290);
#line 1847 "VBNET.ATG"
attrs.Add(new XmlAttribute() { Name = name, ExpressionValue = expressionValue, LiteralValue = literalValue, UseDoubleQuotes = useDoubleQuotes, StartLocation = start, EndLocation = t.EndLocation });
attrs.Add(new XmlAttributeExpression() { Name = name, ExpressionValue = expressionValue, LiteralValue = literalValue, UseDoubleQuotes = useDoubleQuotes, StartLocation = start, EndLocation = t.EndLocation });
} else if (la.kind == 12) {
lexer.NextToken();

2
src/Libraries/NRefactory/Project/Src/Parser/VBNet/VBNET.ATG

@ -1844,7 +1844,7 @@ XmlAttribute<List<XmlExpression> attrs> @@ -1844,7 +1844,7 @@ XmlAttribute<List<XmlExpression> attrs>
Identifier (. string name = t.val; .) "="
(. string literalValue = null; Expression expressionValue = null; bool useDoubleQuotes = false; .)
( LiteralString (. literalValue = t.literalValue.ToString(); useDoubleQuotes = t.val[0] == '"'; .) | XmlStartInlineVB Expr<out expressionValue> XmlEndInlineVB )
(. attrs.Add(new XmlAttribute() { Name = name, ExpressionValue = expressionValue, LiteralValue = literalValue, UseDoubleQuotes = useDoubleQuotes, StartLocation = start, EndLocation = t.EndLocation }); .)
(. attrs.Add(new XmlAttributeExpression() { Name = name, ExpressionValue = expressionValue, LiteralValue = literalValue, UseDoubleQuotes = useDoubleQuotes, StartLocation = start, EndLocation = t.EndLocation }); .)
|
XmlStartInlineVB (. Expression innerExpression; .) Expr<out innerExpression> XmlEndInlineVB
(. attrs.Add(new XmlEmbeddedExpression() { InlineVBExpression = innerExpression, StartLocation = start, EndLocation = t.EndLocation }); .)

14
src/Libraries/NRefactory/Project/Src/PrettyPrinter/VBNet/VBNetOutputVisitor.cs

@ -3188,22 +3188,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -3188,22 +3188,22 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return null;
}
public override object TrackedVisitXmlAttribute(XmlAttribute xmlAttribute, object data)
public override object TrackedVisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data)
{
outputFormatter.PrintText(xmlAttribute.Name);
outputFormatter.PrintText(xmlAttributeExpression.Name);
outputFormatter.PrintToken(Tokens.Assign);
if (xmlAttribute.IsLiteralValue) {
if (xmlAttribute.UseDoubleQuotes)
if (xmlAttributeExpression.IsLiteralValue) {
if (xmlAttributeExpression.UseDoubleQuotes)
outputFormatter.PrintText("\"");
else
outputFormatter.PrintText("'");
outputFormatter.PrintText(xmlAttribute.LiteralValue);
if (xmlAttribute.UseDoubleQuotes)
outputFormatter.PrintText(xmlAttributeExpression.LiteralValue);
if (xmlAttributeExpression.UseDoubleQuotes)
outputFormatter.PrintText("\"");
else
outputFormatter.PrintText("'");
} else
xmlAttribute.ExpressionValue.AcceptVisitor(this, data);
xmlAttributeExpression.ExpressionValue.AcceptVisitor(this, data);
return null;
}

8
src/Libraries/NRefactory/Project/Src/Visitors/AbstractASTVisitor.cs

@ -1251,10 +1251,10 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1251,10 +1251,10 @@ namespace ICSharpCode.NRefactory.Visitors {
return withStatement.Body.AcceptVisitor(this, data);
}
public virtual object VisitXmlAttribute(XmlAttribute xmlAttribute, object data) {
Debug.Assert((xmlAttribute != null));
Debug.Assert((xmlAttribute.ExpressionValue != null));
return xmlAttribute.ExpressionValue.AcceptVisitor(this, data);
public virtual object VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data) {
Debug.Assert((xmlAttributeExpression != null));
Debug.Assert((xmlAttributeExpression.ExpressionValue != null));
return xmlAttributeExpression.ExpressionValue.AcceptVisitor(this, data);
}
public virtual object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data) {

12
src/Libraries/NRefactory/Project/Src/Visitors/AbstractAstTransformer.cs

@ -2244,12 +2244,12 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -2244,12 +2244,12 @@ namespace ICSharpCode.NRefactory.Visitors {
return null;
}
public virtual object VisitXmlAttribute(XmlAttribute xmlAttribute, object data) {
Debug.Assert((xmlAttribute != null));
Debug.Assert((xmlAttribute.ExpressionValue != null));
nodeStack.Push(xmlAttribute.ExpressionValue);
xmlAttribute.ExpressionValue.AcceptVisitor(this, data);
xmlAttribute.ExpressionValue = ((Expression)(nodeStack.Pop()));
public virtual object VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data) {
Debug.Assert((xmlAttributeExpression != null));
Debug.Assert((xmlAttributeExpression.ExpressionValue != null));
nodeStack.Push(xmlAttributeExpression.ExpressionValue);
xmlAttributeExpression.ExpressionValue.AcceptVisitor(this, data);
xmlAttributeExpression.ExpressionValue = ((Expression)(nodeStack.Pop()));
return null;
}

12
src/Libraries/NRefactory/Project/Src/Visitors/NodeTrackingAstVisitor.cs

@ -892,10 +892,10 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -892,10 +892,10 @@ namespace ICSharpCode.NRefactory.Visitors {
return result;
}
public sealed override object VisitXmlAttribute(XmlAttribute xmlAttribute, object data) {
this.BeginVisit(xmlAttribute);
object result = this.TrackedVisitXmlAttribute(xmlAttribute, data);
this.EndVisit(xmlAttribute);
public sealed override object VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data) {
this.BeginVisit(xmlAttributeExpression);
object result = this.TrackedVisitXmlAttributeExpression(xmlAttributeExpression, data);
this.EndVisit(xmlAttributeExpression);
return result;
}
@ -1433,8 +1433,8 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -1433,8 +1433,8 @@ namespace ICSharpCode.NRefactory.Visitors {
return base.VisitWithStatement(withStatement, data);
}
public virtual object TrackedVisitXmlAttribute(XmlAttribute xmlAttribute, object data) {
return base.VisitXmlAttribute(xmlAttribute, data);
public virtual object TrackedVisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data) {
return base.VisitXmlAttributeExpression(xmlAttributeExpression, data);
}
public virtual object TrackedVisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data) {

4
src/Libraries/NRefactory/Project/Src/Visitors/NotImplementedAstVisitor.cs

@ -510,8 +510,8 @@ namespace ICSharpCode.NRefactory.Visitors { @@ -510,8 +510,8 @@ namespace ICSharpCode.NRefactory.Visitors {
throw new global::System.NotImplementedException("WithStatement");
}
public virtual object VisitXmlAttribute(XmlAttribute xmlAttribute, object data) {
throw new global::System.NotImplementedException("XmlAttribute");
public virtual object VisitXmlAttributeExpression(XmlAttributeExpression xmlAttributeExpression, object data) {
throw new global::System.NotImplementedException("XmlAttributeExpression");
}
public virtual object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data) {

119
src/Libraries/NRefactory/Project/Src/Visitors/VBNetConstructsConvertVisitor.cs

@ -5,11 +5,15 @@ @@ -5,11 +5,15 @@
// <version>$Revision$</version>
// </file>
using ICSharpCode.NRefactory.AstBuilder;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;
using ICSharpCode.NRefactory.Ast;
using ICSharpCode.NRefactory.AstBuilder;
using Attribute = ICSharpCode.NRefactory.Ast.Attribute;
namespace ICSharpCode.NRefactory.Visitors
@ -29,6 +33,7 @@ namespace ICSharpCode.NRefactory.Visitors @@ -29,6 +33,7 @@ namespace ICSharpCode.NRefactory.Visitors
// Array creation => add 1 to upper bound to get array length
// Comparison with empty string literal -> string.IsNullOrEmpty
// Add default value to local variable declarations without initializer
// XML literals -> XLinq
/// <summary>
/// Specifies whether the "Add default value to local variable declarations without initializer"
@ -524,5 +529,117 @@ namespace ICSharpCode.NRefactory.Visitors @@ -524,5 +529,117 @@ namespace ICSharpCode.NRefactory.Visitors
OptionStrict = optionDeclaration.OptionValue;
return base.VisitOptionDeclaration(optionDeclaration, data);
}
public override object VisitXmlContentExpression(XmlContentExpression xmlContentExpression, object data)
{
ObjectCreateExpression newNode = ConvertXmlContentExpression(xmlContentExpression);
if (newNode == null)
return base.VisitXmlContentExpression(xmlContentExpression, data);
ReplaceCurrentNode(newNode);
return base.VisitObjectCreateExpression(newNode, data);
}
ObjectCreateExpression ConvertXmlContentExpression(XmlContentExpression xmlContentExpression)
{
ObjectCreateExpression newNode = null;
switch (xmlContentExpression.Type) {
case XmlContentType.Comment:
newNode = new ObjectCreateExpression(new TypeReference("XComment"), Expressions(xmlContentExpression.Content));
break;
case XmlContentType.Text:
newNode = new ObjectCreateExpression(new TypeReference("XText"), Expressions(xmlContentExpression.Content));
break;
case XmlContentType.CData:
newNode = new ObjectCreateExpression(new TypeReference("XCData"), Expressions(xmlContentExpression.Content));
break;
case XmlContentType.ProcessingInstruction:
string content = xmlContentExpression.Content.Trim();
if (content.StartsWith("xml", StringComparison.OrdinalIgnoreCase)) {
XDeclaration decl;
try {
decl = XDocument.Parse("<?" + content + "?><Dummy />").Declaration;
} catch (XmlException) {
decl = new XDeclaration(null, null, null);
}
newNode = new ObjectCreateExpression(new TypeReference("XDeclaration"), Expressions(decl.Version, decl.Encoding, decl.Standalone));
} else {
string target = content.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault() ?? "";
string piData = content.IndexOf(' ') > -1 ? content.Substring(content.IndexOf(' ')) : "";
newNode = new ObjectCreateExpression(new TypeReference("XProcessingInstruction"), Expressions(target, piData));
}
break;
default:
throw new Exception("Invalid value for XmlContentType");
}
return newNode;
}
public override object VisitXmlDocumentExpression(XmlDocumentExpression xmlDocumentExpression, object data)
{
var newNode = new ObjectCreateExpression(new TypeReference("XDocument"), null);
foreach (XmlExpression expr in xmlDocumentExpression.Expressions)
newNode.Parameters.Add(ConvertXmlExpression(expr));
ReplaceCurrentNode(newNode);
return base.VisitObjectCreateExpression(newNode, data);
}
public override object VisitXmlElementExpression(XmlElementExpression xmlElementExpression, object data)
{
ObjectCreateExpression newNode = ConvertXmlElementExpression(xmlElementExpression);
ReplaceCurrentNode(newNode);
return base.VisitObjectCreateExpression(newNode, data);
}
ObjectCreateExpression ConvertXmlElementExpression(XmlElementExpression xmlElementExpression)
{
var newNode = new ObjectCreateExpression(new TypeReference("XElement"), xmlElementExpression.NameIsExpression ? new List<Expression> { xmlElementExpression.NameExpression } : Expressions(xmlElementExpression.XmlName));
foreach (XmlExpression attr in xmlElementExpression.Attributes) {
if (attr is XmlAttributeExpression) {
var a = attr as XmlAttributeExpression;
newNode.Parameters.Add(new ObjectCreateExpression(new TypeReference("XAttribute"), new List<Expression> {
new PrimitiveExpression(a.Name),
a.IsLiteralValue ? new PrimitiveExpression(a.LiteralValue) : a.ExpressionValue
}));
} else if (attr is XmlEmbeddedExpression) {
newNode.Parameters.Add((attr as XmlEmbeddedExpression).InlineVBExpression);
}
}
foreach (XmlExpression expr in xmlElementExpression.Children) {
XmlContentExpression c = expr as XmlContentExpression;
// skip whitespace text
if (!(expr is XmlContentExpression && c.Type == XmlContentType.Text && string.IsNullOrWhiteSpace(c.Content)))
newNode.Parameters.Add(ConvertXmlExpression(expr));
}
return newNode;
}
Expression ConvertXmlExpression(XmlExpression expr)
{
if (expr is XmlElementExpression)
return ConvertXmlElementExpression(expr as XmlElementExpression);
else if (expr is XmlContentExpression)
return ConvertXmlContentExpression(expr as XmlContentExpression);
else if (expr is XmlEmbeddedExpression)
return (expr as XmlEmbeddedExpression).InlineVBExpression;
throw new Exception();
}
List<Expression> Expressions(params string[] exprs)
{
return new List<Expression>(exprs.Select(expr => new PrimitiveExpression(expr)));
}
}
}

103
src/Libraries/NRefactory/Test/Output/CSharp/VBNetToCSharpConverterTest.cs

@ -779,18 +779,117 @@ static bool InitStaticVariableHelper(Microsoft.VisualBasic.CompilerServices.Stat @@ -779,18 +779,117 @@ static bool InitStaticVariableHelper(Microsoft.VisualBasic.CompilerServices.Stat
TestStatement("Dim x As Integer = CInt(obj)", "int x = Convert.ToInt32(obj);");
}
[Test, Ignore]
[Test]
public void XmlElement()
{
TestStatement("Dim xml = <Test />",
@"var xml = new XElement(""Test"");");
}
[Test, Ignore]
[Test]
public void XmlElement2()
{
TestStatement(@"Dim xml = <Test name=""test"" name2=<%= testVal %> />",
@"var xml = new XElement(""Test"", new XAttribute(""name"", ""test""), new XAttribute(""name2"", testVal));");
}
[Test]
public void XmlElement3()
{
TestStatement(@"Dim xml = <Test name=""test"" name2=<%= testVal %> <%= testVal2 %> />",
@"var xml = new XElement(""Test"", new XAttribute(""name"", ""test""), new XAttribute(""name2"", testVal), testVal2);");
}
[Test]
public void XmlNestedElement()
{
TestStatement("Dim xml = <Test> <Test2 /> </Test>",
@"var xml = new XElement(""Test"", new XElement(""Test2""));");
}
[Test]
public void XmlNestedElement2()
{
TestStatement("Dim xml = <Test> <Test2 /> hello </Test>",
@"var xml = new XElement(""Test"", new XElement(""Test2""), new XText("" hello ""));");
}
[Test]
public void XmlNestedElement3()
{
TestStatement("Dim xml = <Test> <Test2 a='b' /> hello </Test>",
@"var xml = new XElement(""Test"", new XElement(""Test2"", new XAttribute(""a"", ""b"")), new XText("" hello ""));");
}
[Test]
public void XmlNestedElement4()
{
TestStatement("Dim xml = <Test> <Test2 a='b' /> hello \t<![CDATA[any & <>]]></Test>",
@"var xml = new XElement(""Test"", new XElement(""Test2"", new XAttribute(""a"", ""b"")), new XText("" hello \t""), new XCData(""any & <>""));");
}
[Test]
public void XmlComment()
{
TestStatement("Dim xml = <!-- test -->",
@"var xml = new XComment("" test "");");
}
[Test]
public void XmlCData()
{
TestStatement("Dim xml = <![CDATA[any & <> char]]>",
@"var xml = new XCData(""any & <> char"");");
}
[Test]
public void XmlProcessingInstruction()
{
TestStatement("Dim xml = <?target testcontent?>",
@"var xml = new XProcessingInstruction(""target"", "" testcontent"");");
}
[Test]
public void XmlDocumentTest()
{
TestStatement(@"Dim xml = <?xml version=""1.0""?><!-- test --><Data a='true'><A/></Data><!-- test -->",
@"var xml = new XDocument(new XDeclaration(""1.0"", null, null), new XComment("" test ""), new XElement(""Data"", new XAttribute(""a"", ""true""), new XElement(""A"")), new XComment("" test ""));");
}
[Test]
public void XmlDocumentTest2()
{
TestStatement(@"Dim xml = <?xml?><!-- test --><Data a='true'><A/></Data><!-- test -->",
@"var xml = new XDocument(new XDeclaration(null, null, null), new XComment("" test ""), new XElement(""Data"", new XAttribute(""a"", ""true""), new XElement(""A"")), new XComment("" test ""));");
}
[Test]
public void XmlDocumentTest3()
{
TestStatement(@"Dim xml = <?xml version=""1.0"" encoding=""utf-8""?><!-- test --><Data a='true'><A/></Data><!-- test -->",
@"var xml = new XDocument(new XDeclaration(""1.0"", ""utf-8"", null), new XComment("" test ""), new XElement(""Data"", new XAttribute(""a"", ""true""), new XElement(""A"")), new XComment("" test ""));");
}
[Test]
public void XmlDocumentTest4()
{
TestStatement(@"Dim xml = <?xml version=""1.0"" encoding=""utf-8"" standalone=""yes""?><!-- test --><Data a='true'><A <%= content %> /></Data><!-- test -->",
@"var xml = new XDocument(new XDeclaration(""1.0"", ""utf-8"", ""yes""), new XComment("" test ""), new XElement(""Data"", new XAttribute(""a"", ""true""), new XElement(""A"", content)), new XComment("" test ""));");
}
[Test]
public void XmlEmbeddedExpression()
{
TestStatement(@"Dim xml = <<%= name %>>Test</>",
@"var xml = new XElement(name, new XText(""Test""));");
}
[Test]
public void XmlEmbeddedExpression2()
{
TestStatement(@"Dim xml = <<%= name %>><%= content %></>",
@"var xml = new XElement(name, content);");
}
}
}

3
src/Libraries/NRefactory/Test/Output/VBNet/VBNetOutputTest.cs

@ -598,7 +598,8 @@ End Using"); @@ -598,7 +598,8 @@ End Using");
[Test]
public void XmlSimple()
{
TestExpression("<?xml?><!-- test -->\n" +
TestExpression("<?xml?>\n" +
"<!-- test -->\n" +
"<Test>\n" +
" <A />\n" +
" <B test='a' <%= test %> />\n" +

55
src/Libraries/NRefactory/Test/Parser/Expressions/XmlExpressionTests.cs

@ -73,8 +73,8 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -73,8 +73,8 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual("Test", element.XmlName);
Assert.IsNotEmpty(element.Attributes);
Assert.AreEqual(1, element.Attributes.Count);
Assert.IsTrue(element.Attributes[0] is XmlAttribute);
XmlAttribute attribute = element.Attributes[0] as XmlAttribute;
Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression);
XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression;
Assert.AreEqual("id", attribute.Name);
Assert.IsTrue(attribute.IsLiteralValue);
Assert.IsTrue(attribute.ExpressionValue.IsNull);
@ -94,8 +94,8 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -94,8 +94,8 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.IsNotEmpty(element.Attributes);
Assert.AreEqual(3, element.Attributes.Count);
Assert.IsTrue(element.Attributes[0] is XmlAttribute);
XmlAttribute attribute = element.Attributes[0] as XmlAttribute;
Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression);
XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression;
Assert.AreEqual("id", attribute.Name);
Assert.IsTrue(attribute.IsLiteralValue);
Assert.IsTrue(attribute.ExpressionValue.IsNull);
@ -103,8 +103,8 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -103,8 +103,8 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(new Location(7,1), attribute.StartLocation);
Assert.AreEqual(new Location(13,1), attribute.EndLocation);
Assert.IsTrue(element.Attributes[1] is XmlAttribute);
XmlAttribute attribute2 = element.Attributes[1] as XmlAttribute;
Assert.IsTrue(element.Attributes[1] is XmlAttributeExpression);
XmlAttributeExpression attribute2 = element.Attributes[1] as XmlAttributeExpression;
Assert.AreEqual("name", attribute2.Name);
Assert.IsFalse(attribute2.IsLiteralValue);
Assert.IsFalse(attribute2.ExpressionValue.IsNull);
@ -140,16 +140,16 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -140,16 +140,16 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public void VBNetElementWithAttributeTest()
{
XmlElementExpression element = ParseUtilVBNet.ParseExpression<XmlElementExpression>("<Test id='0'>\n" +
" <Item />\n" +
" <Item />\n" +
"</Test>");
" <Item />\n" +
" <Item />\n" +
"</Test>");
Assert.IsFalse(element.NameIsExpression);
Assert.AreEqual("Test", element.XmlName);
Assert.IsNotEmpty(element.Attributes);
Assert.AreEqual(1, element.Attributes.Count);
Assert.IsTrue(element.Attributes[0] is XmlAttribute);
XmlAttribute attribute = element.Attributes[0] as XmlAttribute;
Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression);
XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression;
Assert.AreEqual("id", attribute.Name);
Assert.IsTrue(attribute.IsLiteralValue);
Assert.IsTrue(attribute.ExpressionValue.IsNull);
@ -175,18 +175,18 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -175,18 +175,18 @@ namespace ICSharpCode.NRefactory.Tests.Ast
public void VBNetElementWithMixedContentTest()
{
XmlElementExpression element = ParseUtilVBNet.ParseExpression<XmlElementExpression>("<Test id='0'>\n" +
" <!-- test -->\n" +
" <Item />\n" +
" <Item />\n" +
" <![CDATA[<cdata> section]]>\n" +
"</Test>");
" <!-- test -->\n" +
" <Item />\n" +
" <Item />\n" +
" <![CDATA[<cdata> section]]>\n" +
"</Test>");
Assert.IsFalse(element.NameIsExpression);
Assert.AreEqual("Test", element.XmlName);
Assert.IsNotEmpty(element.Attributes);
Assert.AreEqual(1, element.Attributes.Count);
Assert.IsTrue(element.Attributes[0] is XmlAttribute);
XmlAttribute attribute = element.Attributes[0] as XmlAttribute;
Assert.IsTrue(element.Attributes[0] is XmlAttributeExpression);
XmlAttributeExpression attribute = element.Attributes[0] as XmlAttributeExpression;
Assert.AreEqual("id", attribute.Name);
Assert.IsTrue(attribute.IsLiteralValue);
Assert.IsTrue(attribute.ExpressionValue.IsNull);
@ -212,16 +212,29 @@ namespace ICSharpCode.NRefactory.Tests.Ast @@ -212,16 +212,29 @@ namespace ICSharpCode.NRefactory.Tests.Ast
Assert.AreEqual(new Location(8,6), element.EndLocation);
}
[Test]
public void VBNetElementWithMixedContentTest2()
{
XmlElementExpression element = ParseUtilVBNet.ParseExpression<XmlElementExpression>("<Test> aaaa </Test>");
Assert.IsFalse(element.NameIsExpression);
Assert.AreEqual("Test", element.XmlName);
Assert.IsNotEmpty(element.Children);
Assert.AreEqual(1, element.Children.Count);
CheckContent(element.Children[0], " aaaa ", XmlContentType.Text, new Location(7,1), new Location(14,1));
}
[Test]
public void VBNetProcessingInstructionAndCommentAtEndTest()
{
XmlDocumentExpression document = ParseUtilVBNet.ParseExpression<XmlDocumentExpression>("<Test />\n" +
"<!-- test -->\n" +
"<?target some text?>");
"<!-- test -->\n" +
"<?target some text?>");
Assert.IsNotEmpty(document.Expressions);
Assert.AreEqual(3, document.Expressions.Count);
CheckElement(document.Expressions[0], "Test", new Location(1,1), new Location(9,1));
CheckElement(document.Expressions[0], "Test", new Location(1,1), new Location(9,1));
CheckContent(document.Expressions[1], " test ", XmlContentType.Comment, new Location(1,2), new Location(14,2));
CheckContent(document.Expressions[2], "target some text", XmlContentType.ProcessingInstruction, new Location(1,3), new Location(21,3));
}

Loading…
Cancel
Save