Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 5810bb5

Browse files
committed
Fix #529: CC item creating an event handler has confusing name 'HandleHandleClick'
Because EventCreationCompletionData uses a new SDRefactoringContext with a different compilation, import the delegateType into the new compilation so that CreateShortType() works as expected.
1 parent 0787040 commit 5810bb5

1 file changed

Lines changed: 13 additions & 31 deletions

File tree

src/AddIns/BackendBindings/CSharpBinding/Project/Src/Completion/EventCreationCompletionData.cs

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System;
2020
using System.Linq;
2121
using System.Threading;
22+
using System.Windows.Controls;
2223
using ICSharpCode.SharpDevelop;
2324
using CSharpBinding.Parser;
2425
using CSharpBinding.Refactoring;
@@ -35,46 +36,27 @@ namespace CSharpBinding.Completion
3536
/// </summary>
3637
class EventCreationCompletionData : CompletionData
3738
{
38-
IEvent eventDefinition;
39-
string varName;
40-
IType delegateType;
41-
string parameterList;
42-
IUnresolvedMember callingMember;
43-
IUnresolvedTypeDefinition declaringType;
44-
CSharpResolver contextAtCaret;
39+
readonly string handlerName;
40+
readonly ITypeReference delegateTypeReference;
41+
readonly bool isStatic;
4542

46-
public EventCreationCompletionData(string varName, IType delegateType, IEvent evt, string parameterList, IUnresolvedMember callingMember, IUnresolvedTypeDefinition declaringType, CSharpResolver contextAtCaret)
43+
public EventCreationCompletionData(string handlerName, IType delegateType, IEvent evt, string parameterList, IUnresolvedMember callingMember, IUnresolvedTypeDefinition declaringType, CSharpResolver contextAtCaret)
4744
{
48-
if (string.IsNullOrEmpty(varName)) {
49-
this.DisplayText = "<Create handler for " + (evt != null ? evt.Name : "") + ">";
45+
if (string.IsNullOrEmpty(handlerName)) {
46+
handlerName = (evt != null ? evt.Name : "Handle");
5047
}
51-
else {
52-
this.DisplayText = "Handle" + char.ToUpper(varName[0]) + varName.Substring(1) + (evt != null ? evt.Name : "");
53-
}
54-
55-
this.varName = varName;
56-
this.eventDefinition = evt;
57-
this.delegateType = delegateType;
58-
this.parameterList = parameterList;
59-
this.callingMember = callingMember;
60-
this.declaringType = declaringType;
61-
this.contextAtCaret = contextAtCaret;
48+
this.handlerName = handlerName;
49+
this.DisplayText = "<Create " + handlerName + ">";
50+
this.delegateTypeReference = delegateType.ToTypeReference();
51+
this.isStatic = callingMember != null && callingMember.IsStatic;
6252
}
6353

6454
public override void Complete(CompletionContext context)
6555
{
66-
var invokeSignature = delegateType.GetMethods(m => m.Name == "Invoke").Single();
6756
var refactoringContext = SDRefactoringContext.Create(context.Editor, CancellationToken.None);
57+
var delegateType = delegateTypeReference.Resolve(refactoringContext.Compilation);
58+
var invokeSignature = delegateType.GetMethods(m => m.Name == "Invoke").Single();
6859
var builder = refactoringContext.CreateTypeSystemAstBuilder();
69-
string handlerName;
70-
bool isStatic;
71-
if (eventDefinition != null) {
72-
handlerName = eventDefinition.Name;
73-
isStatic = eventDefinition.IsStatic;
74-
} else {
75-
handlerName = varName;
76-
isStatic = callingMember.IsStatic;
77-
}
7860

7961
var throwStatement = new ThrowStatement();
8062
var decl = new MethodDeclaration {

0 commit comments

Comments
 (0)