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. 36
      src/Libraries/NRefactory/Project/Src/Output/CSharp/CSharpOutputVisitor.cs
  17. 103
      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. 35
      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
case "#endregion": case "#endregion":
--deep; --deep;
if (deep == 0) { 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; goto end;
} }
break; break;
@ -107,7 +107,7 @@ namespace CSharpBinding.Parser
return visitor.Cu; 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) { foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments) {
DefaultRegion tagRegion = new DefaultRegion(tagComment.StartPosition.Y, tagComment.StartPosition.X); 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
if (nextDirective.Arg.ToLower() == "region") { if (nextDirective.Arg.ToLower() == "region") {
--deep; --deep;
if (deep == 0) { 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; goto end;
} }
} }
@ -119,7 +119,7 @@ namespace VBNetBinding.Parser
return visitor.Cu; 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) foreach (ICSharpCode.NRefactory.Parser.TagComment tagComment in tagComments)
{ {

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

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

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

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

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

@ -748,6 +748,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
break; break;
} }
sb.Append(ch);
if (specialCommentHash != null) { if (specialCommentHash != null) {
if (Char.IsLetter(ch)) { if (Char.IsLetter(ch)) {
curWord.Append(ch); curWord.Append(ch);
@ -755,16 +756,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
string tag = curWord.ToString(); string tag = curWord.ToString();
curWord.Length = 0; curWord.Length = 0;
if (specialCommentHash.ContainsKey(tag)) { if (specialCommentHash.ContainsKey(tag)) {
Point p = new Point(col ,line); Point p = new Point(col, line);
string comment = ReadToEOL(); string comment = ReadToEOL();
tagComments.Add(new TagComment(tag, comment, p)); tagComments.Add(new TagComment(tag, comment, p, new Point(col, line)));
sb.Append(tag);
sb.Append(comment); sb.Append(comment);
break; break;
} }
} }
} }
sb.Append(ch);
} }
return sb.ToString(); return sb.ToString();
} }
@ -773,7 +772,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
{ {
specialTracker.StartComment(commentType, new Point(col, line)); specialTracker.StartComment(commentType, new Point(col, line));
specialTracker.AddString(ReadCommentToEOL()); specialTracker.AddString(ReadCommentToEOL());
specialTracker.FinishComment(); specialTracker.FinishComment(new Point(col, line));
} }
void ReadMultiLineComment() void ReadMultiLineComment()
@ -793,12 +792,12 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
if (ch == '*' && reader.Peek() == '/') { if (ch == '*' && reader.Peek() == '/') {
reader.Read(); reader.Read();
++col; ++col;
specialTracker.FinishComment(); specialTracker.FinishComment(new Point(col, line));
return; return;
} }
specialTracker.AddChar(ch); specialTracker.AddChar(ch);
} }
specialTracker.FinishComment(); specialTracker.FinishComment(new Point(col, line));
// Reached EOF before end of multiline comment. // Reached EOF before end of multiline comment.
errors.Error(line, col, String.Format("Reached EOF before the end of a 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 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic;
namespace ICSharpCode.NRefactory.Parser namespace ICSharpCode.NRefactory.Parser
{ {
@ -46,7 +47,7 @@ namespace ICSharpCode.NRefactory.Parser
/// <summary> /// <summary>
/// Returns the comments that had been read and containing tag key words. /// Returns the comments that had been read and containing tag key words.
/// </summary> /// </summary>
ArrayList TagComments { List<TagComment> TagComments {
get; get;
} }

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

@ -1,14 +1,17 @@
using System; using System;
using System.Text; using System.Drawing;
using System.CodeDom;
using System.Collections;
namespace ICSharpCode.NRefactory.Parser 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;
namespace ICSharpCode.NRefactory.Parser namespace ICSharpCode.NRefactory.Parser
{ {
public class Comment public class Comment : AbstractSpecial
{ {
CommentType commentType; CommentType commentType;
string comment; string comment;
Point startPosition;
public CommentType CommentType { public CommentType CommentType {
get { get {
@ -30,27 +29,22 @@ namespace ICSharpCode.NRefactory.Parser
} }
} }
public Point StartPosition { public Comment(CommentType commentType, string comment, Point startPosition, Point endPosition)
get { : base(startPosition, endPosition)
return startPosition;
}
set {
startPosition = value;
}
}
public Comment(CommentType commentType, string comment, Point startPosition)
{ {
this.commentType = commentType; this.commentType = commentType;
this.comment = comment; this.comment = comment;
this.startPosition = startPosition;
} }
public override string ToString() public override string ToString()
{ {
return String.Format("[Comment: CommentType = {0}]", return String.Format("[{0}: Type = {1}, Text = {2}, Start = {3}, End = {4}]",
CommentType); 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 @@
/*
* 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;
namespace ICSharpCode.NRefactory.Parser namespace ICSharpCode.NRefactory.Parser
{ {
public class PreProcessingDirective public class PreProcessingDirective : AbstractSpecial
{ {
string cmd; string cmd;
string arg; 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 { public string Cmd {
get { get {
@ -48,6 +28,7 @@ namespace ICSharpCode.NRefactory.Parser
arg = value; arg = value;
} }
} }
public override string ToString() public override string ToString()
{ {
return String.Format("[PreProcessingDirective: Cmd = {0}, Arg = {1}]", return String.Format("[PreProcessingDirective: Cmd = {0}, Arg = {1}]",
@ -56,11 +37,15 @@ namespace ICSharpCode.NRefactory.Parser
} }
public PreProcessingDirective(string cmd, string arg, Point start, Point end) public PreProcessingDirective(string cmd, string arg, Point start, Point end)
: base(start, end)
{ {
this.cmd = cmd; this.cmd = cmd;
this.arg = arg; 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 @@
using System; using System;
using System.Text; using System.Text;
using System.CodeDom; using System.CodeDom;
using System.Collections; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
namespace ICSharpCode.NRefactory.Parser namespace ICSharpCode.NRefactory.Parser
{ {
public class SpecialTracker public class SpecialTracker
{ {
ArrayList currentSpecials = new ArrayList(); List<ISpecial> currentSpecials = new List<ISpecial>();
CommentType currentCommentType; CommentType currentCommentType;
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
Point startPosition; Point startPosition;
public ArrayList CurrentSpecials { public List<ISpecial> CurrentSpecials {
get { get {
return currentSpecials; return currentSpecials;
} }
@ -22,19 +22,22 @@ namespace ICSharpCode.NRefactory.Parser
public void InformToken(int kind) 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; List<ISpecial> tmp = currentSpecials;
currentSpecials = new ArrayList(); currentSpecials = new List<ISpecial>();
return tmp; 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) public void AddPreProcessingDirective(string cmd, string arg, Point start, Point end)
@ -60,9 +63,9 @@ namespace ICSharpCode.NRefactory.Parser
sb.Append(s); 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 @@
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
} }
} }
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; this.tag = tag;
} }

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

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

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

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

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

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

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

@ -26,10 +26,8 @@ using ICSharpCode.NRefactory.Parser.AST;
namespace ICSharpCode.NRefactory.PrettyPrinter namespace ICSharpCode.NRefactory.PrettyPrinter
{ {
public class OutputFormatter : AbstractOutputFormatter public sealed class CSharpOutputFormatter : AbstractOutputFormatter
{ {
// Lexer lexer;
PrettyPrintOptions prettyPrintOptions; PrettyPrintOptions prettyPrintOptions;
bool emitSemicolon = true; bool emitSemicolon = true;
@ -43,91 +41,17 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
} }
// Token token; public CSharpOutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
public OutputFormatter(PrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
{ {
this.prettyPrintOptions = 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) public override void PrintToken(int token)
{ {
// Console.WriteLine("PRINT TOKEN:" + token);
if (token == Tokens.Semicolon && !EmitSemicolon) { if (token == Tokens.Semicolon && !EmitSemicolon) {
return; return;
} }
// while (this.token == null || this.token.kind > 0) { PrintToken(Tokens.GetTokenString(token));
// this.token = lexer.NextToken();
//// PrintSpecials(this.token.kind);
// if (this.token.kind == token) {
// break;
// }
// }
text.Append(Tokens.GetTokenString(token));
// gotBlankLine = false;
} }
Stack braceStack = new Stack(); Stack braceStack = new Stack();
@ -136,7 +60,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{ {
switch (style) { switch (style) {
case BraceStyle.EndOfLine: case BraceStyle.EndOfLine:
text.Append(" "); Space();
PrintToken(Tokens.OpenCurlyBrace); PrintToken(Tokens.OpenCurlyBrace);
NewLine(); NewLine();
++IndentationLevel; ++IndentationLevel;
@ -194,12 +118,21 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
} }
public void BeginNode(INode node) public override void PrintComment(Comment comment)
{
}
public void EndNode(INode node)
{ {
switch (comment.CommentType) {
case CommentType.Block:
PrintToken("/*");
PrintToken(comment.CommentText);
PrintToken("*/");
break;
case CommentType.Documentation:
WriteInNextNewLine("///" + comment.CommentText);
break;
default:
WriteInNextNewLine("//" + comment.CommentText);
break;
}
} }
} }
} }

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

@ -24,6 +24,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
{ {
IASTVisitor callVisitor; IASTVisitor callVisitor;
public IASTVisitor CallVisitor {
get {
return callVisitor;
}
}
public NodeTracker(IASTVisitor callVisitor) public NodeTracker(IASTVisitor callVisitor)
{ {
this.callVisitor = callVisitor; this.callVisitor = callVisitor;
@ -51,6 +57,14 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return ret; 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 NodeVisiting;
public event InformNode NodeVisited; public event InformNode NodeVisited;
} }

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

@ -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
/// <summary> /// <summary>
/// Description of VBNetOutputFormatter. /// Description of VBNetOutputFormatter.
/// </summary> /// </summary>
public class VBNetOutputFormatter : AbstractOutputFormatter public sealed class VBNetOutputFormatter : AbstractOutputFormatter
{ {
public VBNetOutputFormatter(VBNetPrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions) public VBNetOutputFormatter(VBNetPrettyPrintOptions prettyPrintOptions) : base(prettyPrintOptions)
{ {
} }
public override void PrintToken(int token) 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;
}
} }
} }
} }

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

@ -1,6 +1,7 @@
using System; using System;
using System.Text; using System.Text;
using System.Collections; using System.Collections;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using ICSharpCode.NRefactory.Parser; using ICSharpCode.NRefactory.Parser;
@ -40,6 +41,18 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
} }
} }
public NodeTracker NodeTracker {
get {
return nodeTracker;
}
}
public VBNetOutputFormatter OutputFormatter {
get {
return outputFormatter;
}
}
public VBNetOutputVisitor() public VBNetOutputVisitor()
{ {
outputFormatter = new VBNetOutputFormatter(prettyPrintOptions); outputFormatter = new VBNetOutputFormatter(prettyPrintOptions);
@ -53,8 +66,9 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
return node.AcceptChildren(this, data); return node.AcceptChildren(this, data);
} }
public object Visit(CompilationUnit compilationUnit, object data) { public object Visit(CompilationUnit compilationUnit, object data)
compilationUnit.AcceptChildren(this, data); {
nodeTracker.TrackedVisitChildren(compilationUnit, data);
outputFormatter.EndFile(); outputFormatter.EndFile();
return null; return null;
} }
@ -144,7 +158,12 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.PrintToken(Tokens.Comma); outputFormatter.PrintToken(Tokens.Comma);
} }
} }
outputFormatter.PrintIdentifier("> _"); if ("assembly".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)
|| "module".Equals(attributeSection.AttributeTarget, StringComparison.InvariantCultureIgnoreCase)) {
outputFormatter.PrintIdentifier(">");
} else {
outputFormatter.PrintIdentifier("> _");
}
outputFormatter.NewLine(); outputFormatter.NewLine();
return null; return null;
} }
@ -217,7 +236,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.NewLine(); outputFormatter.NewLine();
++outputFormatter.IndentationLevel; ++outputFormatter.IndentationLevel;
namespaceDeclaration.AcceptChildren(this, data); nodeTracker.TrackedVisitChildren(namespaceDeclaration, data);
--outputFormatter.IndentationLevel; --outputFormatter.IndentationLevel;
outputFormatter.Indent(); outputFormatter.Indent();
@ -238,7 +257,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
case Types.Interface: case Types.Interface:
return Tokens.Interface; return Tokens.Interface;
case Types.Struct: 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)) { if (TypeHasOnlyStaticMembers(typeDeclaration)) {
goto case Types.Class; goto case Types.Class;
} }
@ -286,7 +305,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
TypeDeclaration oldType = currentType; TypeDeclaration oldType = currentType;
currentType = typeDeclaration; currentType = typeDeclaration;
typeDeclaration.AcceptChildren(this, data); nodeTracker.TrackedVisitChildren(typeDeclaration, data);
currentType = oldType; currentType = oldType;
--outputFormatter.IndentationLevel; --outputFormatter.IndentationLevel;
@ -412,7 +431,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
outputFormatter.Space(); outputFormatter.Space();
outputFormatter.PrintToken(Tokens.Assign); outputFormatter.PrintToken(Tokens.Assign);
outputFormatter.Space(); outputFormatter.Space();
variableDeclaration.Initializer.AcceptVisitor(this, data); nodeTracker.TrackedVisit(variableDeclaration.Initializer, data);
} }
return null; return null;
} }
@ -649,7 +668,7 @@ namespace ICSharpCode.NRefactory.PrettyPrinter
OutputModifier(methodDeclaration.Modifier); OutputModifier(methodDeclaration.Modifier);
bool isSub = methodDeclaration.TypeReference.IsNull || bool isSub = methodDeclaration.TypeReference.IsNull ||
methodDeclaration.TypeReference.SystemType == "System.Void"; methodDeclaration.TypeReference.SystemType == "System.Void";
if (isSub) { if (isSub) {
outputFormatter.PrintToken(Tokens.Sub); outputFormatter.PrintToken(Tokens.Sub);

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

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

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

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

@ -1,4 +1,4 @@
// <file> // <file>
// <copyright see="prj:///doc/copyright.txt"/> // <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/> // <license see="prj:///doc/license.txt"/>
// <owner name="Mike Krüger" email="mike@icsharpcode.net"/> // <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
@ -41,9 +41,15 @@ namespace ICSharpCode.SharpDevelop.Commands
MessageService.ShowError("Correct source code errors first (only correct source code would convert)."); MessageService.ShowError("Correct source code errors first (only correct source code would convert).");
return; return;
} }
ICSharpCode.NRefactory.PrettyPrinter.VBNetOutputVisitor vbv = new ICSharpCode.NRefactory.PrettyPrinter.VBNetOutputVisitor(); 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); FileService.NewFile("Generated.VB", "VBNET", vbv.Text);
} }

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

@ -88,13 +88,17 @@ namespace ICSharpCode.Core
static void AddReferences(List<Reference> list, IClass parentClass, IMember member, string fileName, string fileContent) static void AddReferences(List<Reference> list, IClass parentClass, IMember member, string fileName, string fileContent)
{ {
string lowerFileContent = fileContent.ToLower(); 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; string lowerMemberName;
if (member is IMethod && ((IMethod)member).IsConstructor) if (member is IMethod && ((IMethod)member).IsConstructor)
lowerMemberName = parentClass.Name.ToLower(); lowerMemberName = parentClass.Name.ToLower();
else else
lowerMemberName = member.Name.ToLower(); lowerMemberName = member.Name.ToLower();
//Console.WriteLine(fileName + " / " + lowerMemberName);
int pos = -1; int pos = -1;
IExpressionFinder expressionFinder = null; IExpressionFinder expressionFinder = null;
while ((pos = lowerFileContent.IndexOf(lowerMemberName, pos + 1)) >= 0) { while ((pos = lowerFileContent.IndexOf(lowerMemberName, pos + 1)) >= 0) {

Loading…
Cancel
Save