Browse Source

Add IndexOf() method to ITextSource.

newNRvisualizers
Daniel Grunwald 14 years ago
parent
commit
8885484971
  1. 24
      ICSharpCode.Editor/ITextSource.cs
  2. 12
      ICSharpCode.Editor/ReadOnlyDocument.cs
  3. 12
      ICSharpCode.Editor/StringTextSource.cs
  4. 2
      ICSharpCode.NRefactory.Demo/CSDemo.cs
  5. 19
      ICSharpCode.NRefactory.Tests/CSharp/Resolver/LinqTests.cs

24
ICSharpCode.Editor/ITextSource.cs

@ -97,11 +97,31 @@ namespace ICSharpCode.Editor @@ -97,11 +97,31 @@ namespace ICSharpCode.Editor
/// Gets the index of the first occurrence of any character in the specified array.
/// </summary>
/// <param name="anyOf">Characters to search for</param>
/// <param name="startIndex">Start index of the search.</param>
/// <param name="startIndex">Start index of the area to search.</param>
/// <param name="count">Length of the area to search.</param>
/// <returns>The first index where any character was found; or -1 if no occurrence was found.</returns>
int IndexOfAny(char[] anyOf, int startIndex, int count);
/// <summary>
/// Gets the index of the first occurrence of the specified search text in this text source.
/// </summary>
/// <param name="searchText">The search text</param>
/// <param name="startIndex">Start index of the area to search.</param>
/// <param name="count">Length of the area to search.</param>
/// <param name="comparisonType">String comparison to use.</param>
/// <returns>The first index where the search term was found; or -1 if no occurrence was found.</returns>
int IndexOf(string searchText, int startIndex, int count, StringComparison comparisonType);
/// <summary>
/// Gets the index of the last occurrence of the specified search text in this text source.
/// </summary>
/// <param name="searchText">The search text</param>
/// <param name="startIndex">Start index of the area to search.</param>
/// <param name="count">Length of the area to search.</param>
/// <param name="comparisonType">String comparison to use.</param>
/// <returns>The last index where the search term was found; or -1 if no occurrence was found.</returns>
int LastIndexOf(string searchText, int startIndex, int count, StringComparison comparisonType);
/* What about:
void Insert (int offset, string value);
void Remove (int offset, int count);
@ -116,7 +136,7 @@ namespace ICSharpCode.Editor @@ -116,7 +136,7 @@ namespace ICSharpCode.Editor
IEnumerable<int> SearchBackward (string pattern, int startIndex);
IEnumerable<int> SearchBackwardIgnoreCase (string pattern, int startIndex);
*/
*/
}
/// <summary>

12
ICSharpCode.Editor/ReadOnlyDocument.cs

@ -327,6 +327,18 @@ namespace ICSharpCode.Editor @@ -327,6 +327,18 @@ namespace ICSharpCode.Editor
return textSource.IndexOfAny(anyOf, startIndex, count);
}
/// <inheritdoc/>
public int IndexOf(string searchText, int startIndex, int count, StringComparison comparisonType)
{
return textSource.IndexOf(searchText, startIndex, count, comparisonType);
}
/// <inheritdoc/>
public int LastIndexOf(string searchText, int startIndex, int count, StringComparison comparisonType)
{
return textSource.LastIndexOf(searchText, startIndex, count, comparisonType);
}
object IServiceProvider.GetService(Type serviceType)
{
return null;

12
ICSharpCode.Editor/StringTextSource.cs

@ -102,5 +102,17 @@ namespace ICSharpCode.Editor @@ -102,5 +102,17 @@ namespace ICSharpCode.Editor
{
return text.IndexOfAny(anyOf, startIndex, count);
}
/// <inheritdoc/>
public int IndexOf(string searchText, int startIndex, int count, StringComparison comparisonType)
{
return text.IndexOf(searchText, startIndex, count, comparisonType);
}
/// <inheritdoc/>
public int LastIndexOf(string searchText, int startIndex, int count, StringComparison comparisonType)
{
return text.LastIndexOf(searchText, startIndex, count, comparisonType);
}
}
}

2
ICSharpCode.NRefactory.Demo/CSDemo.cs

@ -225,7 +225,7 @@ namespace ICSharpCode.NRefactory.Demo @@ -225,7 +225,7 @@ namespace ICSharpCode.NRefactory.Demo
foreach (TreeNode t in c) {
AstNode node = t.Tag as AstNode;
if (node != null) {
ResolveResult rr = v.GetResolveResult(node);
ResolveResult rr = v.GetResolveResultIfResolved(node);
if (rr != null)
t.Text = GetNodeTitle(node) + " " + rr.ToString();
else

19
ICSharpCode.NRefactory.Tests/CSharp/Resolver/LinqTests.cs

@ -313,5 +313,24 @@ class XYZ @@ -313,5 +313,24 @@ class XYZ
Assert.AreEqual("GroupJoin", rr.Member.Name);
Assert.AreEqual("System.Int32", rr.Type.FullName);
}
[Test]
public void GroupWithQueryContinuation()
{
string program = @"using System; using System.Linq;
class TestClass
{
static void M(string[] args)
{
var query =
from w in ""one to three"".Split()
group w by w.Length into g
orderby g.Key descending
select new { g.Key, Count = g.Count(), Avg = g.Average ($w$ => w.Length) };
}
}";
var rr = Resolve<LocalResolveResult>(program);
Assert.AreEqual("System.String", rr.Type.FullName);
}
}
}

Loading…
Cancel
Save