Browse Source

Repaired InsertCtorSnippetRefactoring.

pull/45/merge
Andreas Weizel 12 years ago
parent
commit
7d05d21306
  1. 7
      src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin
  2. 24
      src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/InsertCtorSnippetRefactoring.cs

7
src/AddIns/BackendBindings/CSharpBinding/Project/CSharpBinding.addin

@ -156,12 +156,7 @@
class="CSharpBinding.Refactoring.SearchForIssuesCommand"/> class="CSharpBinding.Refactoring.SearchForIssuesCommand"/>
</Path> </Path>
<Path name="/SharpDevelop/ViewContent/TextEditor/OverrideCompletionHandler"> <Path name="/SharpDevelop/ViewContent/AvalonEdit/SnippetElementProviders">
<Class id="toString" class="CSharpBinding.Refactoring.OverrideToStringMethodRefactoring" />
<!-- <Class id="equalsAndGetHashCode" class="CSharpBinding.Refactoring.OverrideEqualsGetHashCodeMethodsRefactoring" />-->
</Path>
<Path name="/SharpDevelop/ViewContent/TextEditor/SnippetElementProviders">
<Class id="ctor" class="CSharpBinding.Refactoring.InsertCtorSnippetRefactoring" /> <Class id="ctor" class="CSharpBinding.Refactoring.InsertCtorSnippetRefactoring" />
<!--<Class id="switch" class="CSharpBinding.Refactoring.SwitchSnippetProvider" /> <!--<Class id="switch" class="CSharpBinding.Refactoring.SwitchSnippetProvider" />
<Class id="propall" class="CSharpBinding.Refactoring.CreateProperties" />--> <Class id="propall" class="CSharpBinding.Refactoring.CreateProperties" />-->

24
src/AddIns/BackendBindings/CSharpBinding/Project/Src/Refactoring/InsertCtorSnippetRefactoring.cs

@ -54,9 +54,13 @@ namespace CSharpBinding.Refactoring
return null; return null;
var refactoringContext = SDRefactoringContext.Create(textEditor, CancellationToken.None); var refactoringContext = SDRefactoringContext.Create(textEditor, CancellationToken.None);
var resolvedCurrent = current.Resolve(refactoringContext.Resolver.TypeResolveContext); var typeResolveContext = refactoringContext.GetTypeResolveContext();
if (typeResolveContext == null) {
return null;
}
var resolvedCurrent = typeResolveContext.CurrentTypeDefinition;
List<PropertyOrFieldWrapper> parameters = CreateCtorParams(current, resolvedCurrent).ToList(); List<PropertyOrFieldWrapper> parameters = CreateCtorParams(resolvedCurrent).ToList();
if (!parameters.Any()) if (!parameters.Any())
return null; return null;
@ -71,21 +75,21 @@ namespace CSharpBinding.Refactoring
return dialog; return dialog;
} }
IEnumerable<PropertyOrFieldWrapper> CreateCtorParams(IUnresolvedTypeDefinition sourceType, IType resolvedSourceType) IEnumerable<PropertyOrFieldWrapper> CreateCtorParams(IType sourceType)
{ {
int i = 0; int i = 0;
foreach (var f in resolvedSourceType.GetFields().Where(field => !field.IsConst foreach (var f in sourceType.GetFields().Where(field => !field.IsConst
&& field.IsStatic == sourceType.IsStatic && field.IsStatic == sourceType.GetDefinition().IsStatic
&& field.ReturnType != null)) { && field.ReturnType != null)) {
yield return new PropertyOrFieldWrapper(f) { Index = i }; yield return new PropertyOrFieldWrapper(f) { Index = i };
i++; i++;
} }
foreach (var p in resolvedSourceType.GetProperties().Where(prop => prop.CanSet && !prop.IsIndexer foreach (var p in sourceType.GetProperties().Where(prop => prop.CanSet && !prop.IsIndexer
&& prop.IsAutoImplemented() && prop.IsAutoImplemented()
&& prop.IsStatic == sourceType.IsStatic && prop.IsStatic == sourceType.GetDefinition().IsStatic
&& prop.ReturnType != null)) { && prop.ReturnType != null)) {
yield return new PropertyOrFieldWrapper(p) { Index = i }; yield return new PropertyOrFieldWrapper(p) { Index = i };
i++; i++;
} }

Loading…
Cancel
Save