Browse Source

Fix #580: EventHandler names suggested by code completion should include the variable name/expression.

pull/416/merge
Andreas Weizel 11 years ago
parent
commit
3a82e1a507
  1. 45
      src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

45
src/Libraries/NRefactory/ICSharpCode.NRefactory.CSharp/Completion/CSharpCompletionEngine.cs

@ -886,7 +886,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -886,7 +886,7 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
string parameterDefinition = AddDelegateHandlers(
wrapper,
delegateType,
optDelegateName: GuessEventHandlerMethodName(curTokenIndex)
optDelegateName: GuessEventHandlerMethodName(curTokenIndex, (currentType == null) ? null : currentType.Name)
);
}
@ -2584,10 +2584,49 @@ namespace ICSharpCode.NRefactory.CSharp.Completion @@ -2584,10 +2584,49 @@ namespace ICSharpCode.NRefactory.CSharp.Completion
}
}
public string GuessEventHandlerMethodName(int tokenIndex)
public string GuessEventHandlerMethodName(int tokenIndex, string surroundingTypeName)
{
var names = new List<string>();
string eventName = GetPreviousToken(ref tokenIndex, false);
string result = GetPreviousToken(ref tokenIndex, false);
return "Handle" + result;
if (result != ".") {
if (surroundingTypeName == null) {
eventName = "Handle" + eventName;
} else {
names.Add(surroundingTypeName);
}
}
while (result == ".") {
result = GetPreviousToken(ref tokenIndex, false);
if (result == "this") {
if (names.Count == 0) {
if (surroundingTypeName == null) {
eventName = "Handle" + eventName;
} else {
names.Add(surroundingTypeName);
}
}
} else if (result != null) {
string trimmedName = result.Trim();
if (trimmedName.Length == 0) {
break;
}
names.Insert(0, trimmedName);
}
result = GetPreviousToken(ref tokenIndex, false);
}
if (!string.IsNullOrEmpty(eventName)) {
names.Add(eventName);
}
result = String.Join("_", names.ToArray());
foreach (char ch in result) {
if (!char.IsLetterOrDigit(ch) && ch != '_') {
result = "";
break;
}
}
return result;
}
bool MatchDelegate(IType delegateType, IMethod method)

Loading…
Cancel
Save