Browse Source

C# <-> VB.Net converters now convert comments.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@180 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 21 years ago
parent
commit
45bead5f28
  1. 4
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs
  2. 4
      src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs
  3. 3
      src/Libraries/NRefactory/Project/NRefactory.csproj
  4. 6
      src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs
  5. 13
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs
  6. 3
      src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs
  7. 13
      src/Libraries/NRefactory/Project/Src/Lexer/Special/BlankLine.cs
  8. 24
      src/Libraries/NRefactory/Project/Src/Lexer/Special/Comment.cs
  9. 74
      src/Libraries/NRefactory/Project/Src/Lexer/Special/ISpecial.cs
  10. 31
      src/Libraries/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs
  11. 25
      src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs
  12. 13
      src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialType.cs
  13. 2
      src/Libraries/NRefactory/Project/Src/Lexer/Special/TagComment.cs
  14. 9
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs
  15. 80
      src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs
  16. 30
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  17. 101
      src/Libraries/NRefactory/Project/Src/Output/CSharp/OutputFormatter.cs
  18. 14
      src/Libraries/NRefactory/Project/Src/Output/NodeInformVisitor.cs
  19. 118
      src/Libraries/NRefactory/Project/Src/Output/SpecialNodesInserter.cs
  20. 20
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputFormatter.cs
  21. 31
      src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs
  22. 834
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs
  23. 7
      src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG
  24. 7
      src/Main/Base/Project/Src/Commands/VBConverter/CSharpConvertBuffer.cs
  25. 10
      src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs
  26. 8
      src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

4
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Parser/Parser.cs

@ -64,7 +64,7 @@ namespace CSharpBinding.Parser @@ -64,7 +64,7 @@ namespace CSharpBinding.Parser
case "#endregion":
--deep;
if (deep == 0) {
cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), new DefaultRegion(directive.Start, new Point(nextDirective.End.X, nextDirective.End.Y))));
cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim(), new DefaultRegion(directive.StartPosition, nextDirective.EndPosition)));
goto end;
}
break;
@ -107,7 +107,7 @@ namespace CSharpBinding.Parser @@ -107,7 +107,7 @@ namespace CSharpBinding.Parser
return visitor.Cu;
}
void AddCommentTags(ICompilationUnit cu, ArrayList tagComments)
void AddCommentTags(ICompilationUnit cu, System.Collections.Generic.List<ICSharpCode.NRefactory.Parser.TagComment> tagComments)
{
foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments) {
DefaultRegion tagRegion = new DefaultRegion(tagComment.StartPosition.Y, tagComment.StartPosition.X);

4
src/AddIns/BackendBindings/VBNetBinding/Project/Src/Parser/Parser.cs

@ -76,7 +76,7 @@ namespace VBNetBinding.Parser @@ -76,7 +76,7 @@ namespace VBNetBinding.Parser
if (nextDirective.Arg.ToLower() == "region") {
--deep;
if (deep == 0) {
cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim('"'), new DefaultRegion(directive.Start, nextDirective.End)));
cu.FoldingRegions.Add(new FoldingRegion(directive.Arg.Trim('"'), new DefaultRegion(directive.StartPosition, nextDirective.EndPosition)));
goto end;
}
}
@ -119,7 +119,7 @@ namespace VBNetBinding.Parser @@ -119,7 +119,7 @@ namespace VBNetBinding.Parser
return visitor.Cu;
}
void AddCommentTags(ICompilationUnit cu, ArrayList tagComments)
void AddCommentTags(ICompilationUnit cu, System.Collections.Generic.List<ICSharpCode.NRefactory.Parser.TagComment> tagComments)
{
foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments)
{

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

@ -60,7 +60,6 @@ @@ -60,7 +60,6 @@
<Compile Include="Src\Lexer\Special\CommentType.cs" />
<Compile Include="Src\Lexer\Special\PreProcessingDirective.cs" />
<Compile Include="Src\Lexer\Special\SpecialTracker.cs" />
<Compile Include="Src\Lexer\Special\SpecialType.cs" />
<Compile Include="Src\Lexer\Special\TagComment.cs" />
<Compile Include="Src\Lexer\Token.cs" />
<Compile Include="Src\Lexer\VBNet\Keywords.cs" />
@ -184,6 +183,8 @@ @@ -184,6 +183,8 @@
<Compile Include="Src\Parser\Visitors\IASTVisitor.cs" />
<Compile Include="Src\Parser\Visitors\LookupTableVisitor.cs" />
<Compile Include="Src\Parser\AST\CSharp\Expressions\AnonymousMethodExpression.cs" />
<Compile Include="Src\Lexer\Special\ISpecial.cs" />
<Compile Include="Src\Output\SpecialNodesInserter.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Src\Lexer\CSharp\CSharpKeywordList.txt" />

6
src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs

@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.IO;
namespace ICSharpCode.NRefactory.Parser
@ -32,8 +33,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -32,8 +33,7 @@ namespace ICSharpCode.NRefactory.Parser
string[] specialCommentTags = null;
protected Hashtable specialCommentHash = null;
// protected List<TagComment> tagComments = new List<TagComment>();
protected ArrayList tagComments = new ArrayList();
protected List<TagComment> tagComments = new List<TagComment>();
protected StringBuilder sb = new StringBuilder();
protected SpecialTracker specialTracker = new SpecialTracker();
@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -49,7 +49,7 @@ namespace ICSharpCode.NRefactory.Parser
/// <summary>
/// Returns the comments that had been read and containing tag key words.
/// </summary>
public ArrayList TagComments {
public List<TagComment> TagComments {
get {
return tagComments;
}

13
src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs

@ -748,6 +748,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -748,6 +748,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
break;
}
sb.Append(ch);
if (specialCommentHash != null) {
if (Char.IsLetter(ch)) {
curWord.Append(ch);
@ -755,16 +756,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -755,16 +756,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
string tag = curWord.ToString();
curWord.Length = 0;
if (specialCommentHash.ContainsKey(tag)) {
Point p = new Point(col ,line);
Point p = new Point(col, line);
string comment = ReadToEOL();
tagComments.Add(new TagComment(tag, comment, p));
sb.Append(tag);
tagComments.Add(new TagComment(tag, comment, p, new Point(col, line)));
sb.Append(comment);
break;
}
}
}
sb.Append(ch);
}
return sb.ToString();
}
@ -773,7 +772,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -773,7 +772,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
{
specialTracker.StartComment(commentType, new Point(col, line));
specialTracker.AddString(ReadCommentToEOL());
specialTracker.FinishComment();
specialTracker.FinishComment(new Point(col, line));
}
void ReadMultiLineComment()
@ -793,12 +792,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp @@ -793,12 +792,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
if (ch == '*' && reader.Peek() == '/') {
reader.Read();
++col;
specialTracker.FinishComment();
specialTracker.FinishComment(new Point(col, line));
return;
}
specialTracker.AddChar(ch);
}
specialTracker.FinishComment();
specialTracker.FinishComment(new Point(col, line));
// Reached EOF before end of multiline comment.
errors.Error(line, col, String.Format("Reached EOF before the end of a multiline comment"));
}

3
src/Libraries/NRefactory/Project/Src/Lexer/ILexer.cs

@ -9,6 +9,7 @@ @@ -9,6 +9,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Parser
{
@ -46,7 +47,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -46,7 +47,7 @@ namespace ICSharpCode.NRefactory.Parser
/// <summary>
/// Returns the comments that had been read and containing tag key words.
/// </summary>
ArrayList TagComments {
List<TagComment> TagComments {
get;
}

13
src/Libraries/NRefactory/Project/Src/Lexer/Special/BlankLine.cs

@ -1,14 +1,17 @@ @@ -1,14 +1,17 @@
using System;
using System.Text;
using System.CodeDom;
using System.Collections;
using System.Drawing;
namespace ICSharpCode.NRefactory.Parser
{
public class BlankLine
public class BlankLine : AbstractSpecial
{
public BlankLine()
public BlankLine(Point point) : base(point)
{
}
public override object AcceptVisitor(ISpecialVisitor visitor, object data)
{
return visitor.Visit(this, data);
}
}
}

24
src/Libraries/NRefactory/Project/Src/Lexer/Special/Comment.cs

@ -6,11 +6,10 @@ using System.Drawing; @@ -6,11 +6,10 @@ using System.Drawing;
namespace ICSharpCode.NRefactory.Parser
{
public class Comment
public class Comment : AbstractSpecial
{
CommentType commentType;
string comment;
Point startPosition;
public CommentType CommentType {
get {
@ -30,27 +29,22 @@ namespace ICSharpCode.NRefactory.Parser @@ -30,27 +29,22 @@ namespace ICSharpCode.NRefactory.Parser
}
}
public Point StartPosition {
get {
return startPosition;
}
set {
startPosition = value;
}
}
public Comment(CommentType commentType, string comment, Point startPosition)
public Comment(CommentType commentType, string comment, Point startPosition, Point endPosition)
: base(startPosition, endPosition)
{
this.commentType = commentType;
this.comment = comment;
this.startPosition = startPosition;
}
public override string ToString()
{
return String.Format("[Comment: CommentType = {0}]",
CommentType);
return String.Format("[{0}: Type = {1}, Text = {2}, Start = {3}, End = {4}]",
GetType().Name, CommentType, CommentText, StartPosition, EndPosition);
}
public override object AcceptVisitor(ISpecialVisitor visitor, object data)
{
return visitor.Visit(this, data);
}
}
}

74
src/Libraries/NRefactory/Project/Src/Lexer/Special/ISpecial.cs

@ -0,0 +1,74 @@ @@ -0,0 +1,74 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 15.07.2005
* Time: 12:05
*/
using System;
using System.Drawing;
namespace ICSharpCode.NRefactory.Parser
{
/// <summary>
/// Interface for all specials.
/// </summary>
public interface ISpecial
{
Point StartPosition { get; }
Point EndPosition { get; }
object AcceptVisitor(ISpecialVisitor visitor, object data);
}
public interface ISpecialVisitor
{
object Visit(ISpecial special, object data);
object Visit(BlankLine special, object data);
object Visit(Comment special, object data);
object Visit(PreProcessingDirective special, object data);
}
public abstract class AbstractSpecial : ISpecial
{
public abstract object AcceptVisitor(ISpecialVisitor visitor, object data);
Point startPosition, endPosition;
public AbstractSpecial(Point position)
{
this.startPosition = position;
this.endPosition = position;
}
public AbstractSpecial(Point startPosition, Point endPosition)
{
this.startPosition = startPosition;
this.endPosition = endPosition;
}
public Point StartPosition {
get {
return startPosition;
}
set {
startPosition = value;
}
}
public Point EndPosition {
get {
return endPosition;
}
set {
endPosition = value;
}
}
public override string ToString()
{
return String.Format("[{0}: Start = {1}, End = {2}]",
GetType().Name, StartPosition, EndPosition);
}
}
}

31
src/Libraries/NRefactory/Project/Src/Lexer/Special/PreProcessingDirective.cs

@ -6,30 +6,10 @@ using System.Collections; @@ -6,30 +6,10 @@ using System.Collections;
namespace ICSharpCode.NRefactory.Parser
{
public class PreProcessingDirective
public class PreProcessingDirective : AbstractSpecial
{
string cmd;
string arg;
Point start;
Point end;
public Point Start {
get {
return start;
}
set {
start = value;
}
}
public Point End {
get {
return end;
}
set {
end = value;
}
}
public string Cmd {
get {
@ -48,6 +28,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -48,6 +28,7 @@ namespace ICSharpCode.NRefactory.Parser
arg = value;
}
}
public override string ToString()
{
return String.Format("[PreProcessingDirective: Cmd = {0}, Arg = {1}]",
@ -56,11 +37,15 @@ namespace ICSharpCode.NRefactory.Parser @@ -56,11 +37,15 @@ namespace ICSharpCode.NRefactory.Parser
}
public PreProcessingDirective(string cmd, string arg, Point start, Point end)
: base(start, end)
{
this.cmd = cmd;
this.arg = arg;
this.start = start;
this.end = end;
}
public override object AcceptVisitor(ISpecialVisitor visitor, object data)
{
return visitor.Visit(this, data);
}
}
}

25
src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialTracker.cs

@ -1,20 +1,20 @@ @@ -1,20 +1,20 @@
using System;
using System.Text;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
namespace ICSharpCode.NRefactory.Parser
{
public class SpecialTracker
{
ArrayList currentSpecials = new ArrayList();
List<ISpecial> currentSpecials = new List<ISpecial>();
CommentType currentCommentType;
StringBuilder sb = new StringBuilder();
Point startPosition;
public ArrayList CurrentSpecials {
public List<ISpecial> CurrentSpecials {
get {
return currentSpecials;
}
@ -22,19 +22,22 @@ namespace ICSharpCode.NRefactory.Parser @@ -22,19 +22,22 @@ namespace ICSharpCode.NRefactory.Parser
public void InformToken(int kind)
{
currentSpecials.Add(kind);
}
public ArrayList RetrieveSpecials()
/// <summary>
/// Gets the specials from the SpecialTracker and resets the lists.
/// </summary>
public List<ISpecial> RetrieveSpecials()
{
ArrayList tmp = currentSpecials;
currentSpecials = new ArrayList();
List<ISpecial> tmp = currentSpecials;
currentSpecials = new List<ISpecial>();
return tmp;
}
public void AddEndOfLine()
public void AddEndOfLine(Point point)
{
currentSpecials.Add(new BlankLine());
currentSpecials.Add(new BlankLine(point));
}
public void AddPreProcessingDirective(string cmd, string arg, Point start, Point end)
@ -60,9 +63,9 @@ namespace ICSharpCode.NRefactory.Parser @@ -60,9 +63,9 @@ namespace ICSharpCode.NRefactory.Parser
sb.Append(s);
}
public void FinishComment()
public void FinishComment(Point endPosition)
{
currentSpecials.Add(new Comment(currentCommentType, sb.ToString(), startPosition));
currentSpecials.Add(new Comment(currentCommentType, sb.ToString(), startPosition, endPosition));
}
}
}

13
src/Libraries/NRefactory/Project/Src/Lexer/Special/SpecialType.cs

@ -1,13 +0,0 @@ @@ -1,13 +0,0 @@
using System;
using System.Text;
using System.CodeDom;
using System.Collections;
namespace ICSharpCode.NRefactory.Parser
{
public enum SpecialType {
SingleLine,
Documentation,
Block
}
}

2
src/Libraries/NRefactory/Project/Src/Lexer/Special/TagComment.cs

@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.Parser @@ -22,7 +22,7 @@ namespace ICSharpCode.NRefactory.Parser
}
}
public TagComment(string tag, string comment, Point startPosition) : base(CommentType.SingleLine, comment, startPosition)
public TagComment(string tag, string comment, Point startPosition, Point endPosition) : base(CommentType.SingleLine, comment, startPosition, endPosition)
{
this.tag = tag;
}

9
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs

@ -83,6 +83,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -83,6 +83,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
if (ch == '_') {
if (reader.Peek() == -1) {
errors.Error(line, col, String.Format("No EOF expected after _"));
return new Token(Tokens.EOF);
}
++col;
if (!Char.IsWhiteSpace((char)reader.Peek())) {
@ -517,6 +518,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -517,6 +518,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
break;
}
sb.Append(ch);
if (specialCommentHash != null) {
if (Char.IsLetter(ch)) {
curWord.Append(ch);
@ -524,10 +526,9 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -524,10 +526,9 @@ namespace ICSharpCode.NRefactory.Parser.VB
string tag = curWord.ToString();
curWord.Length = 0;
if (specialCommentHash.ContainsKey(tag)) {
Point p = new Point(col ,line);
Point p = new Point(col, line);
string comment = ReadToEOL();
tagComments.Add(new TagComment(tag, comment, p));
sb.Append(tag);
tagComments.Add(new TagComment(tag, comment, p, new Point(col, line)));
sb.Append(comment);
break;
}
@ -535,7 +536,7 @@ namespace ICSharpCode.NRefactory.Parser.VB @@ -535,7 +536,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
}
}
specialTracker.AddString(sb.ToString());
specialTracker.FinishComment();
specialTracker.FinishComment(new Point(col, line));
}
Token ReadOperator(char ch)

80
src/Libraries/NRefactory/Project/Src/Output/AbstractOutputFormatter.cs

@ -19,12 +19,12 @@ using ICSharpCode.NRefactory.Parser.AST; @@ -19,12 +19,12 @@ using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.PrettyPrinter
{
/// <summary>
/// Description of VBNetOutputFormatter.
/// Base class of output formatters.
/// </summary>
public abstract class AbstractOutputFormatter
{
int indentationLevel = 0;
protected StringBuilder text = new StringBuilder();
StringBuilder text = new StringBuilder();
bool indent = true;
bool doNewLine = true;
@ -69,6 +69,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -69,6 +69,8 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
this.prettyPrintOptions = prettyPrintOptions;
}
bool isIndented = false;
public void Indent()
{
if (DoIndent) {
@ -85,6 +87,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -85,6 +87,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
++indent;
}
}
isIndented = true;
}
}
@ -93,52 +96,79 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -93,52 +96,79 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
text.Append(' ');
}
public void NewLine()
bool gotBlankLine = true;
ArrayList specialsText = new ArrayList();
public virtual void NewLine()
{
if (DoNewLine) {
text.Append(Environment.NewLine);
// gotBlankLine = true;
gotBlankLine = true;
isIndented = false;
WriteSpecials();
}
}
public virtual void EndFile()
{
WriteSpecials();
}
public void EndFile()
protected void WriteInNextNewLine(string text)
{
// while (this.token == null || this.token.kind > 0) {
// this.token = lexer.NextToken();
// PrintSpecials(token.kind);
// }
// PrintSpecials(-1);
// foreach (object o in lexer.SpecialTracker.CurrentSpecials) {
// Console.WriteLine(o);
// }
specialsText.Add(text);
if (gotBlankLine) {
WriteSpecials();
}
}
void WriteSpecials()
{
if (isIndented) {
foreach (string txt in specialsText) {
text.Append(txt);
text.Append(Environment.NewLine);
Indent();
}
} else {
foreach (string txt in specialsText) {
Indent();
text.Append(txt);
text.Append(Environment.NewLine);
}
isIndented = false;
}
specialsText.Clear();
}
public void PrintTokenList(ArrayList tokenList)
{
// ArrayList trackList = (ArrayList)tokenList.Clone();
// while (this.token == null || trackList.Count > 0) {
// this.token = lexer.NextToken();
//// PrintSpecials(this.token.kind);
// for (int i = 0; i < trackList.Count; ++i) {
// trackList.RemoveAt(i);
// break;
// }
// }
gotBlankLine = false;
foreach (int token in tokenList) {
PrintToken(token);
Space();
}
}
public abstract void PrintComment(Comment comment);
public virtual void PrintPreProcessingDirective(PreProcessingDirective directive)
{
WriteInNextNewLine(directive.Cmd + directive.Arg);
}
public abstract void PrintToken(int token);
protected void PrintToken(string text)
{
gotBlankLine = false;
this.text.Append(text);
}
public void PrintIdentifier(string identifier)
{
// this.token = lexer.NextToken();
// PrintSpecials(token.kind);
gotBlankLine = false;
text.Append(identifier);
}
}
}

30
src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs

@ -21,7 +21,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -21,7 +21,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public class CSharpOutputVisitor : IOutputASTVisitor
{
Errors errors = new Errors();
OutputFormatter outputFormatter;
CSharpOutputFormatter outputFormatter;
PrettyPrintOptions prettyPrintOptions = new PrettyPrintOptions();
NodeTracker nodeTracker;
// Stack<WithStatement> withExpressionStack = new Stack<WithStatement>();
@ -48,9 +48,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -48,9 +48,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
public CSharpOutputFormatter OutputFormatter {
get {
return outputFormatter;
}
}
public NodeTracker NodeTracker {
get {
return nodeTracker;
}
}
public CSharpOutputVisitor()
{
outputFormatter = new OutputFormatter(prettyPrintOptions);
outputFormatter = new CSharpOutputFormatter(prettyPrintOptions);
nodeTracker = new NodeTracker(this);
}
@ -63,7 +75,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -63,7 +75,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(CompilationUnit compilationUnit, object data)
{
compilationUnit.AcceptChildren(this, data);
nodeTracker.TrackedVisitChildren(compilationUnit, data);
outputFormatter.EndFile();
return null;
}
@ -243,7 +255,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -243,7 +255,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
public object Visit(UsingDeclaration usingDeclaration, object data)
{
foreach (Using u in usingDeclaration.Usings) {
u.AcceptVisitor(this, data);
nodeTracker.TrackedVisit(u, data);
}
return null;
}
@ -257,7 +269,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -257,7 +269,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.BeginBrace(this.prettyPrintOptions.NameSpaceBraceStyle);
namespaceDeclaration.AcceptChildren(this, data);
nodeTracker.TrackedVisitChildren(namespaceDeclaration, data);
outputFormatter.EndBrace();
@ -317,7 +329,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -317,7 +329,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
foreach (TemplateDefinition templateDefinition in typeDeclaration.Templates) {
templateDefinition.AcceptVisitor(this, data);
nodeTracker.TrackedVisit(templateDefinition, data);
}
switch (typeDeclaration.Type) {
@ -338,7 +350,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -338,7 +350,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
if (typeDeclaration.Type == Types.Enum) {
OutputEnumMembers(typeDeclaration, data);
} else {
typeDeclaration.AcceptChildren(this, data);
nodeTracker.TrackedVisitChildren(typeDeclaration, data);
}
outputFormatter.EndBrace();
@ -356,7 +368,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -356,7 +368,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
for (int i = 0; i < templateDefinition.Bases.Count; ++i) {
outputFormatter.Space();
templateDefinition.Bases[i].AcceptVisitor(this, data);
nodeTracker.TrackedVisit(templateDefinition.Bases[i], data);
if (i + 1 < templateDefinition.Bases.Count) {
PrintFormattedComma();
}
@ -865,7 +877,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -865,7 +877,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
Debug.Assert(yieldStatement.Statement != null);
outputFormatter.PrintIdentifier("yield");
outputFormatter.Space();
yieldStatement.Statement.AcceptVisitor(this, data);
nodeTracker.TrackedVisit(yieldStatement.Statement, data);
return null;
}

101
src/Libraries/NRefactory/Project/Src/Output/CSharp/OutputFormatter.cs

@ -26,10 +26,8 @@ using ICSharpCode.NRefactory.Parser.AST; @@ -26,10 +26,8 @@ using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.PrettyPrinter
{
public class OutputFormatter : AbstractOutputFormatter
public sealed class CSharpOutputFormatter : AbstractOutputFormatter
{
// Lexer lexer;
PrettyPrintOptions prettyPrintOptions;
bool emitSemicolon = true;
@ -43,91 +41,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -43,91 +41,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
// Token token;
public OutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
public CSharpOutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
{
this.prettyPrintOptions = prettyPrintOptions;
// lexer = new Lexer(new StringReader(originalSourceFile));
// token = lexer.NextToken();
// PrintSpecials(token.kind);
}
// bool gotBlankLine = false;
// int currentSpecial = 0;
// void PrintSpecials(int tokenKind)
// {
// if (currentSpecial >= lexer.SpecialTracker.CurrentSpecials.Count) {
// return;
// }
// object o = lexer.SpecialTracker.CurrentSpecials[currentSpecial++];
// if (o is Comment) {
//// Console.WriteLine("COMMENT " + o);
// Comment comment = (Comment)o;
// switch (comment.CommentType) {
// case CommentType.SingleLine:
// text.Append("//");
// text.Append(comment.CommentText);
// text.Append("\n");
// Indent();
// break;
// case CommentType.Documentation:
// text.Append("///");
// text.Append(comment.CommentText);
// text.Append("\n");
// Indent();
// break;
// case CommentType.Block:
// text.Append("/*");
// text.Append(comment.CommentText);
// text.Append("*/\n");
// Indent();
// break;
// }
// PrintSpecials(tokenKind);
// } else if (o is BlankLine) {
// if (!gotBlankLine) {
//// text.Append("\n");
//// Indent();
// }
// gotBlankLine = false;
// PrintSpecials(tokenKind);
// } else if (o is PreProcessingDirective) {
//// Console.WriteLine("PPD:" + o);
// text.Append("\n");
// PreProcessingDirective ppd = (PreProcessingDirective)o;
// text.Append(ppd.Cmd);
// if (ppd.Arg != null && ppd.Arg.Length > 0) {
// text.Append(" ");
// text.Append(ppd.Arg);
// }
// text.Append("\n");
// Indent();
// PrintSpecials(tokenKind);
// } else {
// int kind = (int)o;
//// Console.WriteLine(kind + " -- " + Tokens.GetTokenString(kind));
// if (kind != tokenKind) {
// PrintSpecials(tokenKind);
// }
// }
// }
public override void PrintToken(int token)
{
// Console.WriteLine("PRINT TOKEN:" + token);
if (token == Tokens.Semicolon && !EmitSemicolon) {
return;
}
// while (this.token == null || this.token.kind > 0) {
// this.token = lexer.NextToken();
//// PrintSpecials(this.token.kind);
// if (this.token.kind == token) {
// break;
// }
// }
text.Append(Tokens.GetTokenString(token));
// gotBlankLine = false;
PrintToken(Tokens.GetTokenString(token));
}
Stack braceStack = new Stack();
@ -136,7 +60,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -136,7 +60,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
switch (style) {
case BraceStyle.EndOfLine:
text.Append(" ");
Space();
PrintToken(Tokens.OpenCurlyBrace);
NewLine();
++IndentationLevel;
@ -194,12 +118,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -194,12 +118,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
public void BeginNode(INode node)
public override void PrintComment(Comment comment)
{
switch (comment.CommentType) {
case CommentType.Block:
PrintToken("/*");
PrintToken(comment.CommentText);
PrintToken("*/");
break;
case CommentType.Documentation:
WriteInNextNewLine("///" + comment.CommentText);
break;
default:
WriteInNextNewLine("//" + comment.CommentText);
break;
}
public void EndNode(INode node)
{
}
}
}

14
src/Libraries/NRefactory/Project/Src/Output/NodeInformVisitor.cs

@ -24,6 +24,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -24,6 +24,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{
IASTVisitor callVisitor;
public IASTVisitor CallVisitor {
get {
return callVisitor;
}
}
public NodeTracker(IASTVisitor callVisitor)
{
this.callVisitor = callVisitor;
@ -51,6 +57,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -51,6 +57,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return ret;
}
public object TrackedVisitChildren(INode node, object data)
{
foreach (INode child in node.Children) {
TrackedVisit(child, data);
}
return data;
}
public event InformNode NodeVisiting;
public event InformNode NodeVisited;
}

118
src/Libraries/NRefactory/Project/Src/Output/SpecialNodesInserter.cs

@ -0,0 +1,118 @@ @@ -0,0 +1,118 @@
/*
* Created by SharpDevelop.
* User: Daniel Grunwald
* Date: 15.07.2005
* Time: 12:29
*/
using System;
using System.Drawing;
using System.Collections.Generic;
using ICSharpCode.NRefactory.Parser;
using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.PrettyPrinter
{
public class SpecialOutputVisitor : ISpecialVisitor
{
AbstractOutputFormatter formatter;
public SpecialOutputVisitor(AbstractOutputFormatter formatter)
{
this.formatter = formatter;
}
public object Visit(ISpecial special, object data)
{
Console.WriteLine("Warning: SpecialOutputVisitor.Visit(ISpecial) called with " + special);
return data;
}
public object Visit(BlankLine special, object data)
{
formatter.NewLine();
return data;
}
public object Visit(Comment special, object data)
{
formatter.PrintComment(special);
return data;
}
public object Visit(PreProcessingDirective special, object data)
{
formatter.PrintPreProcessingDirective(special);
return data;
}
}
/// <summary>
/// This class inserts specials between INodes.
/// </summary>
public class SpecialNodesInserter
{
IEnumerator<ISpecial> enumerator;
SpecialOutputVisitor visitor;
bool available; // true when more specials are available
public SpecialNodesInserter(IEnumerable<ISpecial> specials, SpecialOutputVisitor visitor)
{
if (specials == null) throw new ArgumentNullException("specials");
if (visitor == null) throw new ArgumentNullException("visitor");
enumerator = specials.GetEnumerator();
this.visitor = visitor;
available = enumerator.MoveNext();
}
void WriteCurrent()
{
enumerator.Current.AcceptVisitor(visitor, null);
available = enumerator.MoveNext();
}
/// <summary>
/// Writes all specials up to the start position of the node.
/// </summary>
public void AcceptNodeStart(INode node)
{
Console.Write("Start node " + node.GetType().Name + ": ");
AcceptPoint(node.StartLocation);
}
/// <summary>
/// Writes all specials up to the end position of the node.
/// </summary>
public void AcceptNodeEnd(INode node)
{
Console.Write("End node " + node.GetType().Name + ": ");
AcceptPoint(node.EndLocation);
}
/// <summary>
/// Writes all specials up to the specified location.
/// </summary>
public void AcceptPoint(Point a)
{
Console.WriteLine(a.Y + ", " + a.X);
while (available) {
Point b = enumerator.Current.StartPosition;
if (b.Y < a.Y || (b.Y == a.Y && b.X <= a.X)) {
WriteCurrent();
} else {
break;
}
}
}
/// <summary>
/// Outputs all missing specials to the writer.
/// </summary>
public void Finish()
{
while (available) {
WriteCurrent();
}
}
}
}

20
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputFormatter.cs

@ -21,16 +21,30 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -21,16 +21,30 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
/// <summary>
/// Description of VBNetOutputFormatter.
/// </summary>
public class VBNetOutputFormatter : AbstractOutputFormatter
public sealed class VBNetOutputFormatter : AbstractOutputFormatter
{
public VBNetOutputFormatter(VBNetPrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
{
}
public override void PrintToken(int token)
{
text.Append(Tokens.GetTokenString(token));
PrintToken(Tokens.GetTokenString(token));
}
public override void PrintComment(Comment comment)
{
switch (comment.CommentType) {
case CommentType.Block:
WriteInNextNewLine("'" + comment.CommentText.Replace("\n", "\n'"));
break;
case CommentType.Documentation:
WriteInNextNewLine("'''" + comment.CommentText);
break;
default:
WriteInNextNewLine("'" + comment.CommentText);
break;
}
}
}
}

31
src/Libraries/NRefactory/Project/Src/Output/VBNet/VBNetOutputVisitor.cs

@ -1,6 +1,7 @@ @@ -1,6 +1,7 @@
using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using ICSharpCode.NRefactory.Parser;
@ -40,6 +41,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -40,6 +41,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
}
}
public NodeTracker NodeTracker {
get {
return nodeTracker;
}
}
public VBNetOutputFormatter OutputFormatter {
get {
return outputFormatter;
}
}
public VBNetOutputVisitor()
{
outputFormatter = new VBNetOutputFormatter(prettyPrintOptions);
@ -53,8 +66,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -53,8 +66,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return node.AcceptChildren(this, data);
}
public object Visit(CompilationUnit compilationUnit, object data) {
compilationUnit.AcceptChildren(this, data);
public object Visit(CompilationUnit compilationUnit, object data)
{
nodeTracker.TrackedVisitChildren(compilationUnit, data);
outputFormatter.EndFile();
return null;
}
@ -144,7 +158,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -144,7 +158,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Comma);
}
}
if ("assembly".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)
|| "module".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)) {
outputFormatter.PrintIdentifier(">");
} else {
outputFormatter.PrintIdentifier("> _");
}
outputFormatter.NewLine();
return null;
}
@ -217,7 +236,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -217,7 +236,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.NewLine();
++outputFormatter.IndentationLevel;
namespaceDeclaration.AcceptChildren(this, data);
nodeTracker.TrackedVisitChildren(namespaceDeclaration, data);
--outputFormatter.IndentationLevel;
outputFormatter.Indent();
@ -238,7 +257,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -238,7 +257,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
case Types.Interface:
return Tokens.Interface;
case Types.Struct:
// FixMe: This should be better in VBNetRefactory class because it is an AST transformation, but currently I'm too lazy
// FIXME: This should be better in VBNetRefactory class because it is an AST transformation, but currently I'm too lazy
if (TypeHasOnlyStaticMembers(typeDeclaration)) {
goto case Types.Class;
}
@ -286,7 +305,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -286,7 +305,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
TypeDeclaration oldType = currentType;
currentType = typeDeclaration;
typeDeclaration.AcceptChildren(this, data);
nodeTracker.TrackedVisitChildren(typeDeclaration, data);
currentType = oldType;
--outputFormatter.IndentationLevel;
@ -412,7 +431,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter @@ -412,7 +431,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.Space();
variableDeclaration.Initializer.AcceptVisitor(this, data);
nodeTracker.TrackedVisit(variableDeclaration.Initializer, data);
}
return null;
}

834
src/Libraries/NRefactory/Project/Src/Parser/CSharp/Parser.cs

File diff suppressed because it is too large Load Diff

7
src/Libraries/NRefactory/Project/Src/Parser/CSharp/cs.ATG

@ -1622,6 +1622,7 @@ Statement @@ -1622,6 +1622,7 @@ Statement
TypeReference type;
Expression expr;
Statement stmt;
Point startPos = la.Location;
.)
=
/*--- labeled statement: */
@ -1639,6 +1640,12 @@ Statement @@ -1639,6 +1640,12 @@ Statement
/* LL(1) confict: LocalVariableDecl *
* <-> StatementExpr *
* ident {"." ident} { "[" Expr ... */
(. if (stmt != null) {
stmt.StartLocation = startPos;
stmt.EndLocation = t.EndLocation;
}
.)
.
EmbeddedStatement<out Statement statement>

7
src/Main/Base/Project/Src/Commands/VBConverter/CSharpConvertBuffer.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
@ -42,7 +42,12 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -42,7 +42,12 @@ namespace ICSharpCode.SharpDevelop.Commands
return;
}
ICSharpCode.NRefactory.PrettyPrinter.CSharpOutputVisitor vbv = new ICSharpCode.NRefactory.PrettyPrinter.CSharpOutputVisitor();
SpecialNodesInserter sni = new SpecialNodesInserter(p.Lexer.SpecialTracker.CurrentSpecials,
new SpecialOutputVisitor(vbv.OutputFormatter));
vbv.NodeTracker.NodeVisiting += sni.AcceptNodeStart;
vbv.NodeTracker.NodeVisited += sni.AcceptNodeEnd;
vbv.Visit(p.CompilationUnit, null);
sni.Finish();
FileService.NewFile("Generated.CS", "C#", vbv.Text);

10
src/Main/Base/Project/Src/Commands/VBConverter/ConvertBuffer.cs

@ -1,4 +1,4 @@ @@ -1,4 +1,4 @@
// <file>
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
@ -41,9 +41,15 @@ namespace ICSharpCode.SharpDevelop.Commands @@ -41,9 +41,15 @@ namespace ICSharpCode.SharpDevelop.Commands
MessageService.ShowError("Correct source code errors first (only correct source code would convert).");
return;
}
ICSharpCode.NRefactory.PrettyPrinter.VBNetOutputVisitor vbv = new ICSharpCode.NRefactory.PrettyPrinter.VBNetOutputVisitor();
vbv.Visit(p.CompilationUnit, null);
SpecialNodesInserter sni = new SpecialNodesInserter(p.Lexer.SpecialTracker.CurrentSpecials,
new SpecialOutputVisitor(vbv.OutputFormatter));
vbv.NodeTracker.NodeVisiting += sni.AcceptNodeStart;
vbv.NodeTracker.NodeVisited += sni.AcceptNodeEnd;
vbv.Visit(p.CompilationUnit, null);
sni.Finish();
FileService.NewFile("Generated.VB", "VBNET", vbv.Text);
}

8
src/Main/Base/Project/Src/Services/RefactoringService/RefactoringService.cs

@ -88,13 +88,17 @@ namespace ICSharpCode.Core @@ -88,13 +88,17 @@ namespace ICSharpCode.Core
static void AddReferences(List<Reference> list, IClass parentClass, IMember member, string fileName, string fileContent)
{
string lowerFileContent = fileContent.ToLower();
if (lowerFileContent.IndexOf(parentClass.Name.ToLower()) < 0) return;
// The name of the class does not necessarily exist in the file if the name of a
// derived class exists.
//if (lowerFileContent.IndexOf(parentClass.Name.ToLower()) < 0) return;
string lowerMemberName;
if (member is IMethod && ((IMethod)member).IsConstructor)
lowerMemberName = parentClass.Name.ToLower();
else
lowerMemberName = member.Name.ToLower();
//Console.WriteLine(fileName + " / " + lowerMemberName);
int pos = -1;
IExpressionFinder expressionFinder = null;
while ((pos = lowerFileContent.IndexOf(lowerMemberName, pos + 1)) >= 0) {

Loading…
Cancel
Save