Browse Source

Added whitespace and text node.

They are needed anyways, now the ast should be theretically round-trip
complete.
newNRvisualizers
Mike Krüger 14 years ago
parent
commit
0cbca24882
  1. 30
      ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs
  2. 3
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs
  3. 94
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TextNode.cs
  4. 91
      ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/WhitespaceNode.cs
  5. 6
      ICSharpCode.NRefactory.CSharp/Ast/IAstVisitor.cs
  6. 20
      ICSharpCode.NRefactory.CSharp/Ast/ObservableAstVisitor.cs
  7. 2
      ICSharpCode.NRefactory.CSharp/Ast/Roles.cs
  8. 26
      ICSharpCode.NRefactory.CSharp/Formatter/GeneratedCodeSettings.cs
  9. 2
      ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj
  10. 10
      ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs
  11. 10
      ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs
  12. 10
      ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs

30
ICSharpCode.NRefactory.CSharp/Ast/DepthFirstAstVisitor.cs

@ -59,6 +59,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -59,6 +59,16 @@ namespace ICSharpCode.NRefactory.CSharp
VisitChildren(newLineNode);
}
public virtual void VisitWhitespace(WhitespaceNode whitespaceNode)
{
VisitChildren(whitespaceNode);
}
public virtual void VisitText(TextNode textNode)
{
VisitChildren(textNode);
}
public virtual void VisitDocumentationReference (DocumentationReference documentationReference)
{
VisitChildren (documentationReference);
@ -647,6 +657,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -647,6 +657,16 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren(newLineNode);
}
public virtual T VisitWhitespace(WhitespaceNode whitespaceNode)
{
return VisitChildren(whitespaceNode);
}
public virtual T VisitText(TextNode textNode)
{
return VisitChildren(textNode);
}
public virtual T VisitDocumentationReference (DocumentationReference documentationReference)
{
return VisitChildren (documentationReference);
@ -1235,6 +1255,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1235,6 +1255,16 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren(newLineNode, data);
}
public virtual S VisitWhitespace(WhitespaceNode whitespaceNode, T data)
{
return VisitChildren(whitespaceNode, data);
}
public virtual S VisitText(TextNode textNode, T data)
{
return VisitChildren(textNode, data);
}
public virtual S VisitDocumentationReference (DocumentationReference documentationReference, T data)
{
return VisitChildren (documentationReference, data);

3
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/NewLineNode.cs

@ -7,6 +7,9 @@ namespace ICSharpCode.NRefactory.CSharp @@ -7,6 +7,9 @@ namespace ICSharpCode.NRefactory.CSharp
Mac
}
/// <summary>
/// A New line node represents a line break in the text.
/// </summary>
public abstract class NewLineNode : AstNode
{
public override NodeType NodeType {

94
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/TextNode.cs

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
//
// TextNode.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// A text node contains text without syntactic or semantic information.
/// (non parseable part of a text)
/// </summary>
public class TextNode : AstNode
{
public override NodeType NodeType {
get {
return NodeType.Whitespace;
}
}
public string Text {
get;
set;
}
TextLocation startLocation;
public override TextLocation StartLocation {
get {
return startLocation;
}
}
TextLocation endLocation;
public override TextLocation EndLocation {
get {
return endLocation;
}
}
public TextNode(string text) : this (text, TextLocation.Empty, TextLocation.Empty)
{
}
public TextNode(string text, TextLocation startLocation, TextLocation endLocation)
{
this.Text = text;
this.startLocation = startLocation;
this.endLocation = endLocation;
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitText (this);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitText (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitText (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as TextNode;
return o != null && o.Text == Text;
}
}
}

91
ICSharpCode.NRefactory.CSharp/Ast/GeneralScope/WhitespaceNode.cs

@ -0,0 +1,91 @@ @@ -0,0 +1,91 @@
//
// WhitespaceNode.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
namespace ICSharpCode.NRefactory.CSharp
{
/// <summary>
/// A Whitespace node contains only whitespaces.
/// </summary>
public class WhitespaceNode : AstNode
{
public override NodeType NodeType {
get {
return NodeType.Whitespace;
}
}
public string WhiteSpaceText {
get;
set;
}
TextLocation startLocation;
public override TextLocation StartLocation {
get {
return startLocation;
}
}
public override TextLocation EndLocation {
get {
return new TextLocation (startLocation.Line, startLocation.Column + WhiteSpaceText.Length);
}
}
public WhitespaceNode(string whiteSpaceText) : this (whiteSpaceText, TextLocation.Empty)
{
}
public WhitespaceNode(string whiteSpaceText, TextLocation startLocation)
{
this.WhiteSpaceText = WhiteSpaceText;
this.startLocation = startLocation;
}
public override void AcceptVisitor(IAstVisitor visitor)
{
visitor.VisitWhitespace (this);
}
public override T AcceptVisitor<T>(IAstVisitor<T> visitor)
{
return visitor.VisitWhitespace (this);
}
public override S AcceptVisitor<T, S>(IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitWhitespace (this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
var o = other as WhitespaceNode;
return o != null && o.WhiteSpaceText == WhiteSpaceText;
}
}
}

6
ICSharpCode.NRefactory.CSharp/Ast/IAstVisitor.cs

@ -138,6 +138,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -138,6 +138,8 @@ namespace ICSharpCode.NRefactory.CSharp
void VisitComment(Comment comment);
void VisitNewLine(NewLineNode newLineNode);
void VisitWhitespace(WhitespaceNode whitespaceNode);
void VisitText(TextNode textNode);
void VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective);
void VisitDocumentationReference(DocumentationReference documentationReference);
@ -266,6 +268,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -266,6 +268,8 @@ namespace ICSharpCode.NRefactory.CSharp
S VisitPrimitiveType(PrimitiveType primitiveType);
S VisitComment(Comment comment);
S VisitWhitespace(WhitespaceNode whitespaceNode);
S VisitText(TextNode textNode);
S VisitNewLine(NewLineNode newLineNode);
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective);
S VisitDocumentationReference(DocumentationReference documentationReference);
@ -396,6 +400,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -396,6 +400,8 @@ namespace ICSharpCode.NRefactory.CSharp
S VisitComment(Comment comment, T data);
S VisitNewLine(NewLineNode newLineNode, T data);
S VisitWhitespace(WhitespaceNode whitespaceNode, T data);
S VisitText(TextNode textNode, T data);
S VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective, T data);
S VisitDocumentationReference(DocumentationReference documentationReference, T data);

20
ICSharpCode.NRefactory.CSharp/Ast/ObservableAstVisitor.cs

@ -71,6 +71,26 @@ namespace ICSharpCode.NRefactory.CSharp @@ -71,6 +71,26 @@ namespace ICSharpCode.NRefactory.CSharp
return VisitChildren(newLineNode, data);
}
public event Action<WhitespaceNode, T> WhitespaceVisited;
S IAstVisitor<T, S>.VisitWhitespace(WhitespaceNode whitespace, T data)
{
var handler = WhitespaceVisited;
if (handler != null)
handler(whitespace, data);
return VisitChildren(whitespace, data);
}
public event Action<TextNode, T> TextVisited;
S IAstVisitor<T, S>.VisitText(TextNode textNode, T data)
{
var handler = TextVisited;
if (handler != null)
handler(textNode, data);
return VisitChildren(textNode, data);
}
public event Action<PreProcessorDirective, T> PreProcessorDirectiveVisited;
S IAstVisitor<T, S>.VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective, T data)
{

2
ICSharpCode.NRefactory.CSharp/Ast/Roles.cs

@ -69,6 +69,8 @@ namespace ICSharpCode.NRefactory.CSharp @@ -69,6 +69,8 @@ namespace ICSharpCode.NRefactory.CSharp
public static readonly TokenRole DoubleColon = new TokenRole ("::");
public static readonly Role<Comment> Comment = new Role<Comment> ("Comment");
public static readonly Role<NewLineNode> NewLine = new Role<NewLineNode> ("NewLine");
public static readonly Role<WhitespaceNode> Whitespace = new Role<WhitespaceNode> ("Whitespace");
public static readonly Role<TextNode> Text = new Role<TextNode> ("Text");
public static readonly Role<PreProcessorDirective> PreProcessorDirective = new Role<PreProcessorDirective> ("PreProcessorDirective");
public static readonly Role<ErrorNode> Error = new Role<ErrorNode> ("Error");

26
ICSharpCode.NRefactory.CSharp/Formatter/GeneratedCodeSettings.cs

@ -1,3 +1,29 @@ @@ -1,3 +1,29 @@
//
// GeneratedCodeSettings.cs
//
// Author:
// Mike Krüger <mkrueger@xamarin.com>
//
// Copyright (c) 2012 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
using System;
using System.Collections.Generic;

2
ICSharpCode.NRefactory.CSharp/ICSharpCode.NRefactory.CSharp.csproj

@ -366,6 +366,8 @@ @@ -366,6 +366,8 @@
<Compile Include="Refactoring\CodeActions\SpecializedCodeAction.cs" />
<Compile Include="Formatter\GeneratedCodeSettings.cs" />
<Compile Include="Ast\GeneralScope\NewLineNode.cs" />
<Compile Include="Ast\GeneralScope\WhitespaceNode.cs" />
<Compile Include="Ast\GeneralScope\TextNode.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ICSharpCode.NRefactory\ICSharpCode.NRefactory.csproj">

10
ICSharpCode.NRefactory.CSharp/OutputVisitor/CSharpOutputVisitor.cs

@ -2384,6 +2384,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -2384,6 +2384,16 @@ namespace ICSharpCode.NRefactory.CSharp
formatter.EndNode(newLineNode);
}
public void VisitWhitespace(WhitespaceNode whitespaceNode)
{
// unused
}
public void VisitText(TextNode textNode)
{
// unused
}
public void VisitPreProcessorDirective(PreProcessorDirective preProcessorDirective)
{
formatter.StartNode(preProcessorDirective);

10
ICSharpCode.NRefactory.CSharp/OutputVisitor/CodeDomConvertVisitor.cs

@ -1250,6 +1250,16 @@ namespace ICSharpCode.NRefactory.CSharp @@ -1250,6 +1250,16 @@ namespace ICSharpCode.NRefactory.CSharp
throw new NotSupportedException();
}
CodeObject IAstVisitor<CodeObject>.VisitWhitespace(WhitespaceNode whitespaceNode)
{
throw new NotSupportedException();
}
CodeObject IAstVisitor<CodeObject>.VisitText(TextNode textNode)
{
throw new NotSupportedException();
}
CodeObject IAstVisitor<CodeObject>.VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective)
{
return new CodeComment ("#" + preProcessorDirective.Type.ToString ().ToLower ());

10
ICSharpCode.NRefactory.CSharp/Resolver/ResolveVisitor.cs

@ -3613,6 +3613,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver @@ -3613,6 +3613,16 @@ namespace ICSharpCode.NRefactory.CSharp.Resolver
{
return null;
}
ResolveResult IAstVisitor<ResolveResult>.VisitWhitespace(WhitespaceNode whitespaceNode)
{
return null;
}
ResolveResult IAstVisitor<ResolveResult>.VisitText(TextNode textNode)
{
return null;
}
ResolveResult IAstVisitor<ResolveResult>.VisitPreProcessorDirective (PreProcessorDirective preProcessorDirective)
{

Loading…
Cancel
Save