Browse Source

add support for comments

newNRvisualizers
Siegfried Pammer 14 years ago
parent
commit
d83c0e6d37
  1. 32
      ICSharpCode.NRefactory.VB/Ast/AstNode.cs
  2. 67
      ICSharpCode.NRefactory.VB/Ast/Comment.cs
  3. 1
      ICSharpCode.NRefactory.VB/IAstVisitor.cs
  4. 1
      ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj
  5. 4
      ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs
  6. 6
      ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs
  7. 10
      ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs
  8. 7
      ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

32
ICSharpCode.NRefactory.VB/Ast/AstNode.cs

@ -1,28 +1,5 @@ @@ -1,28 +1,5 @@
//
// AstNode.cs
//
// Author:
// Mike Krüger <mkrueger@novell.com>
//
// Copyright (c) 2009 Novell, Inc (http://www.novell.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.
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections;
@ -724,8 +701,5 @@ namespace ICSharpCode.NRefactory.VB @@ -724,8 +701,5 @@ namespace ICSharpCode.NRefactory.VB
}
}
public class Comment
{
}
}

67
ICSharpCode.NRefactory.VB/Ast/Comment.cs

@ -0,0 +1,67 @@ @@ -0,0 +1,67 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under MIT X11 license (for details please see \doc\license.txt)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using ICSharpCode.NRefactory.PatternMatching;
using ICSharpCode.NRefactory.VB.Ast;
namespace ICSharpCode.NRefactory.VB
{
public class Comment : AstNode
{
public bool IsDocumentationComment { get; set; }
public bool StartsLine {
get;
set;
}
public string Content {
get;
set;
}
AstLocation startLocation;
public override AstLocation StartLocation {
get {
return startLocation;
}
}
AstLocation endLocation;
public override AstLocation EndLocation {
get {
return endLocation;
}
}
public Comment (string content, bool isDocumentation = false)
{
this.IsDocumentationComment = isDocumentation;
this.Content = content;
}
public Comment (bool isDocumentation, AstLocation startLocation, AstLocation endLocation)
{
this.IsDocumentationComment = isDocumentation;
this.startLocation = startLocation;
this.endLocation = endLocation;
}
public override S AcceptVisitor<T, S> (IAstVisitor<T, S> visitor, T data)
{
return visitor.VisitComment(this, data);
}
protected internal override bool DoMatch(AstNode other, PatternMatching.Match match)
{
Comment o = other as Comment;
return o != null && this.IsDocumentationComment == o.IsDocumentationComment && MatchString(this.Content, o.Content);
}
}
}

1
ICSharpCode.NRefactory.VB/IAstVisitor.cs

@ -9,6 +9,7 @@ namespace ICSharpCode.NRefactory.VB { @@ -9,6 +9,7 @@ namespace ICSharpCode.NRefactory.VB {
public interface IAstVisitor<in T, out S>
{
S VisitBlockStatement(BlockStatement blockStatement, T data);
S VisitComment(Comment comment, T data);
S VisitCompilationUnit(CompilationUnit compilationUnit, T data);
S VisitPatternPlaceholder(AstNode placeholder, PatternMatching.Pattern pattern, T data);
S VisitTypeParameterDeclaration(TypeParameterDeclaration typeParameterDeclaration, T data);

1
ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj

@ -46,6 +46,7 @@ @@ -46,6 +46,7 @@
<Compile Include="Ast\AstLocation.cs" />
<Compile Include="Ast\AstNode.cs" />
<Compile Include="Ast\AstNodeCollection.cs" />
<Compile Include="Ast\Comment.cs" />
<Compile Include="Ast\Enums.cs" />
<Compile Include="Ast\Expressions\AddressOfExpression.cs" />
<Compile Include="Ast\Expressions\ArrayInitializerExpression.cs" />

4
ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs

@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.VB @@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.VB
/// <summary>
/// Writes an identifier.
/// If the identifier conflicts with a keyword, the output visitor will
/// call <c>WriteToken("@")</c> before calling WriteIdentifier().
/// call <c>WriteToken("[")</c> before and <c>WriteToken("]")</c> after calling WriteIdentifier().
/// </summary>
void WriteIdentifier(string identifier);
@ -35,5 +35,7 @@ namespace ICSharpCode.NRefactory.VB @@ -35,5 +35,7 @@ namespace ICSharpCode.NRefactory.VB
void Unindent();
void NewLine();
void WriteComment(bool isDocumentation, string content);
}
}

6
ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs

@ -1610,5 +1610,11 @@ namespace ICSharpCode.NRefactory.VB @@ -1610,5 +1610,11 @@ namespace ICSharpCode.NRefactory.VB
return EndNode(objectCreationExpression);
}
public object VisitComment(Comment comment, object data)
{
formatter.WriteComment(comment.IsDocumentationComment, comment.Content);
return null;
}
}
}

10
ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs

@ -79,5 +79,15 @@ namespace ICSharpCode.NRefactory.VB @@ -79,5 +79,15 @@ namespace ICSharpCode.NRefactory.VB
public virtual void EndNode(AstNode node)
{
}
public void WriteComment(bool isDocumentation, string content)
{
WriteIndentation();
if (isDocumentation)
textWriter.Write("'''");
else
textWriter.Write("'");
textWriter.WriteLine(content);
}
}
}

7
ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs

@ -1027,7 +1027,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors @@ -1027,7 +1027,12 @@ namespace ICSharpCode.NRefactory.VB.Visitors
public AstNode VisitComment(CSharp.Comment comment, object data)
{
throw new NotImplementedException();
var c = new Comment(comment.Content, comment.CommentType == CSharp.CommentType.Documentation);
if (comment.CommentType == CSharp.CommentType.MultiLine)
throw new NotImplementedException();
return EndNode(comment, c);
}
public AstNode VisitTypeParameterDeclaration(CSharp.TypeParameterDeclaration typeParameterDeclaration, object data)

Loading…
Cancel
Save