Browse Source

Improve search strategies: use full name matching only if search term contains '.'

pull/728/merge
Siegfried Pammer 9 years ago
parent
commit
57c8346ce8
  1. 62
      ILSpy/SearchStrategies.cs

62
ILSpy/SearchStrategies.cs

@ -12,6 +12,7 @@ namespace ICSharpCode.ILSpy @@ -12,6 +12,7 @@ namespace ICSharpCode.ILSpy
{
protected string[] searchTerm;
protected Regex regex;
protected bool fullNameSearch;
protected AbstractSearchStrategy(params string[] terms)
{
@ -19,9 +20,12 @@ namespace ICSharpCode.ILSpy @@ -19,9 +20,12 @@ namespace ICSharpCode.ILSpy
var search = terms[0];
if (search.StartsWith("/", StringComparison.Ordinal) && search.Length > 4) {
var regexString = search.Substring(1, search.Length - 1);
fullNameSearch = search.Contains("\\.");
if (regexString.EndsWith("/", StringComparison.Ordinal))
regexString = regexString.Substring(0, regexString.Length - 1);
regex = SafeNewRegex(regexString);
} else {
fullNameSearch = search.Contains(".");
}
terms[0] = search;
@ -30,17 +34,38 @@ namespace ICSharpCode.ILSpy @@ -30,17 +34,38 @@ namespace ICSharpCode.ILSpy
searchTerm = terms;
}
protected bool IsMatch(string text)
protected virtual bool IsMatch(FieldDefinition field)
{
return false;
}
protected virtual bool IsMatch(PropertyDefinition property)
{
return false;
}
protected virtual bool IsMatch(EventDefinition ev)
{
return false;
}
protected virtual bool IsMatch(MethodDefinition m)
{
return false;
}
protected virtual bool MatchName(MemberReference m)
{
if (regex != null)
return regex.IsMatch(text);
if (regex != null) {
return regex.IsMatch(fullNameSearch ? GetLanguageSpecificFullName(m) : m.Name);
}
for (int i = 0; i < searchTerm.Length; ++i) {
// How to handle overlapping matches?
var term = searchTerm[i];
if (string.IsNullOrEmpty(term)) continue;
switch (term[0])
{
string text = term.Contains(".") ? GetLanguageSpecificFullName(m) : m.Name;
switch (term[0]) {
case '+': // must contain
term = term.Substring(1);
goto default;
@ -67,33 +92,6 @@ namespace ICSharpCode.ILSpy @@ -67,33 +92,6 @@ namespace ICSharpCode.ILSpy
return true;
}
protected virtual bool IsMatch(FieldDefinition field)
{
return false;
}
protected virtual bool IsMatch(PropertyDefinition property)
{
return false;
}
protected virtual bool IsMatch(EventDefinition ev)
{
return false;
}
protected virtual bool IsMatch(MethodDefinition m)
{
return false;
}
protected virtual bool MatchName(MemberReference m)
{
if (m.DeclaringType == null)
return IsMatch(m.Name);
return IsMatch(m.Name) || IsMatch(GetLanguageSpecificFullName(m));
}
string GetLanguageSpecificFullName(MemberReference m, string nestedTypeSeparator = ".", string memberSeparator = ".")
{
if (m.DeclaringType != null)

Loading…
Cancel
Save