Browse Source

r7309@daniel-notebook (orig r3340): daniel | 2008-08-14 10:00:25 +0200

Fixed SD2-1430: Documentation comments not found when attributes are contained in #region.


git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3342 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 17 years ago
parent
commit
80340a7ee1
  1. 46
      src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs
  2. 1
      src/Main/ICSharpCode.SharpDevelop.Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/ICSharpCode.SharpDevelop.Dom.Tests.csproj
  3. 123
      src/Main/ICSharpCode.SharpDevelop.Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/NRefactoryAstConverterTests.cs

46
src/Main/ICSharpCode.SharpDevelop.Dom/Project/Src/NRefactoryResolver/NRefactoryASTConvertVisitor.cs

@ -7,7 +7,6 @@ @@ -7,7 +7,6 @@
// created on 04.08.2003 at 17:49
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
@ -94,11 +93,25 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -94,11 +93,25 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
List<string> lines = new List<string>();
int length = 0;
while (line > 0) {
string doku = GetDocumentationFromLine(--line);
if (doku == null)
line--;
string doku = null;
bool foundPreprocessing = false;
var specialsOnLine = GetSpecialsFromLine(line);
foreach (RefParser.ISpecial special in specialsOnLine) {
RefParser.Comment comment = special as RefParser.Comment;
if (comment != null && comment.CommentType == RefParser.CommentType.Documentation) {
doku = comment.CommentText;
break;
} else if (special is RefParser.PreprocessingDirective) {
foundPreprocessing = true;
}
}
if (doku == null && !foundPreprocessing)
break;
length += 2 + doku.Length;
lines.Add(doku);
if (doku != null) {
length += 2 + doku.Length;
lines.Add(doku);
}
}
StringBuilder b = new StringBuilder(length);
for (int i = lines.Count - 1; i >= 0; --i) {
@ -109,8 +122,20 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -109,8 +122,20 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
string GetDocumentationFromLine(int line)
{
if (specials == null) return null;
if (line < 0) return null;
foreach (RefParser.ISpecial special in GetSpecialsFromLine(line)) {
RefParser.Comment comment = special as RefParser.Comment;
if (comment != null && comment.CommentType == RefParser.CommentType.Documentation) {
return comment.CommentText;
}
}
return null;
}
IEnumerable<RefParser.ISpecial> GetSpecialsFromLine(int line)
{
List<RefParser.ISpecial> result = new List<RefParser.ISpecial>();
if (specials == null) return result;
if (line < 0) return result;
// specials is a sorted list: use interpolation search
int left = 0;
int right = specials.Count - 1;
@ -143,15 +168,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver @@ -143,15 +168,12 @@ namespace ICSharpCode.SharpDevelop.Dom.NRefactoryResolver
while (--m >= 0 && specials[m].StartPosition.Y == line);
// look at all specials in that line: find doku-comment
while (++m < specials.Count && specials[m].StartPosition.Y == line) {
RefParser.Comment comment = specials[m] as RefParser.Comment;
if (comment != null && comment.CommentType == RefParser.CommentType.Documentation) {
return comment.CommentText;
}
result.Add(specials[m]);
}
break;
}
}
return null;
return result;
}
public override object VisitCompilationUnit(AST.CompilationUnit compilationUnit, object data)

1
src/Main/ICSharpCode.SharpDevelop.Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/ICSharpCode.SharpDevelop.Dom.Tests.csproj

@ -45,6 +45,7 @@ @@ -45,6 +45,7 @@
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="CodeSnippetConverterTests.cs" />
<Compile Include="NRefactoryAstConverterTests.cs" />
<Compile Include="NRefactoryRefactoringProviderTests.cs" />
<Compile Include="NUnitHelpers\SyntaxHelpers.cs" />
<Compile Include="NUnitHelpers\Constraints.cs" />

123
src/Main/ICSharpCode.SharpDevelop.Dom/Tests/ICSharpCode.SharpDevelop.Dom.Tests/NRefactoryAstConverterTests.cs

@ -0,0 +1,123 @@ @@ -0,0 +1,123 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald"/>
// <version>$Revision$</version>
// </file>
using System;
using System.IO;
using ICSharpCode.NRefactory;
using ICSharpCode.SharpDevelop.Dom.NRefactoryResolver;
using NUnit.Framework;
namespace ICSharpCode.SharpDevelop.Dom.Tests
{
[TestFixture]
public class NRefactoryAstConverterTests
{
ICompilationUnit Parse(string code, SupportedLanguage language)
{
NRefactoryASTConvertVisitor visitor = new NRefactoryASTConvertVisitor(new DefaultProjectContent());
using (IParser p = ParserFactory.CreateParser(language, new StringReader(code))) {
p.ParseMethodBodies = false;
p.Parse();
visitor.Specials = p.Lexer.SpecialTracker.CurrentSpecials;
visitor.VisitCompilationUnit(p.CompilationUnit, null);
}
return visitor.Cu;
}
ICompilationUnit Parse(string code)
{
return Parse(code, SupportedLanguage.CSharp);
}
string SurroundWithSummaryTags(string text)
{
return " <summary>\r\n " + text + "\r\n </summary>\r\n";
}
[Test]
public void FindDocumentationComment()
{
ICompilationUnit cu = Parse(@"
using System;
namespace X
{
/// <summary>
/// This is the comment
/// </summary>
public class A
{
}
}
");
Assert.AreEqual(SurroundWithSummaryTags("This is the comment"), cu.Classes[0].Documentation);
}
[Test]
public void FindDocumentationCommentAboveAttribute()
{
ICompilationUnit cu = Parse(@"
using System;
namespace X
{
/// <summary>
/// This is the comment
/// </summary>
[SomeAttribute]
public class A
{
}
}
");
Assert.AreEqual(SurroundWithSummaryTags("This is the comment"), cu.Classes[0].Documentation);
}
[Test]
public void FindDocumentationCommentAboveAttribute2()
{
ICompilationUnit cu = Parse(@"
using System;
namespace X
{
/// <summary>
/// This is the comment
/// </summary>
[SomeAttribute] // a comment on the attribute
public class A
{
}
}
");
Assert.AreEqual(SurroundWithSummaryTags("This is the comment"), cu.Classes[0].Documentation);
}
[Test]
public void FindDocumentationCommentAboveAttributeInRegion()
{
ICompilationUnit cu = Parse(@"
using System;
namespace X
{
/// <summary>
/// This is the comment
/// </summary>
#region R
[SomeAttribute]
#endregion
public class A
{
}
}
");
Assert.AreEqual(SurroundWithSummaryTags("This is the comment"), cu.Classes[0].Documentation);
}
}
}
Loading…
Cancel
Save