diff --git a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs index 2fd9aa9248..70ede3eaed 100644 --- a/ICSharpCode.NRefactory.VB/Ast/AstNode.cs +++ b/ICSharpCode.NRefactory.VB/Ast/AstNode.cs @@ -1,28 +1,5 @@ -// -// AstNode.cs -// -// Author: -// Mike Krüger -// -// 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 } } - public class Comment - { - - } + } diff --git a/ICSharpCode.NRefactory.VB/Ast/Comment.cs b/ICSharpCode.NRefactory.VB/Ast/Comment.cs new file mode 100644 index 0000000000..ee8f6b3853 --- /dev/null +++ b/ICSharpCode.NRefactory.VB/Ast/Comment.cs @@ -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 (IAstVisitor 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); + } + } +} diff --git a/ICSharpCode.NRefactory.VB/IAstVisitor.cs b/ICSharpCode.NRefactory.VB/IAstVisitor.cs index f6b5a23367..a9f6d64b54 100644 --- a/ICSharpCode.NRefactory.VB/IAstVisitor.cs +++ b/ICSharpCode.NRefactory.VB/IAstVisitor.cs @@ -9,6 +9,7 @@ namespace ICSharpCode.NRefactory.VB { public interface IAstVisitor { 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); diff --git a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj index a257a082bb..cbb8483124 100644 --- a/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj +++ b/ICSharpCode.NRefactory.VB/ICSharpCode.NRefactory.VB.csproj @@ -46,6 +46,7 @@ + diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs index a544eb0d00..2d8d991a85 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/IOutputFormatter.cs @@ -16,7 +16,7 @@ namespace ICSharpCode.NRefactory.VB /// /// Writes an identifier. /// If the identifier conflicts with a keyword, the output visitor will - /// call WriteToken("@") before calling WriteIdentifier(). + /// call WriteToken("[") before and WriteToken("]") after calling WriteIdentifier(). /// void WriteIdentifier(string identifier); @@ -35,5 +35,7 @@ namespace ICSharpCode.NRefactory.VB void Unindent(); void NewLine(); + + void WriteComment(bool isDocumentation, string content); } } diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs index 430093ba4e..ff378b376b 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/OutputVisitor.cs @@ -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; + } } } diff --git a/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs b/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs index cc2df64ed0..933e966959 100644 --- a/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs +++ b/ICSharpCode.NRefactory.VB/OutputVisitor/TextWriterOutputFormatter.cs @@ -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); + } } } diff --git a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs index 1f4fa1b246..680b88ce74 100644 --- a/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs +++ b/ICSharpCode.NRefactory.VB/Visitors/CSharpToVBConverterVisitor.cs @@ -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)