|
|
|
@ -117,7 +117,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -117,7 +117,7 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
{ |
|
|
|
|
return m.UnresolvedMember == method.UnresolvedMember; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<Tuple<IMember, bool>> CollectMembersToImplement(ITypeDefinition implementingType, IType interfaceType, bool explicitly, out bool interfaceMissing) |
|
|
|
|
{ |
|
|
|
|
//var def = interfaceType.GetDefinition();
|
|
|
|
@ -131,21 +131,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -131,21 +131,9 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
bool needsExplicitly = explicitly; |
|
|
|
|
alreadyImplemented = false; |
|
|
|
|
|
|
|
|
|
foreach (var cmet in implementingType.GetMembers ()) { |
|
|
|
|
alreadyImplemented |= cmet.ImplementedInterfaceMembers.Any(m => IsImplementation (m, ev)); |
|
|
|
|
|
|
|
|
|
if (CompareMembers(ev, cmet)) { |
|
|
|
|
if (!needsExplicitly && !cmet.ReturnType.Equals(ev.ReturnType)) |
|
|
|
|
needsExplicitly = true; |
|
|
|
|
else |
|
|
|
|
alreadyImplemented |= !needsExplicitly /*|| cmet.InterfaceImplementations.Any (impl => impl.InterfaceType.Equals (interfaceType))*/; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (toImplement.Where(t => t.Item1 is IEvent).Any(t => CompareMembers(ev, (IEvent)t.Item1))) |
|
|
|
|
needsExplicitly = true; |
|
|
|
|
var implementingMember = implementingType.GetInterfaceImplementation(ev); |
|
|
|
|
alreadyImplemented = (implementingMember != null) && |
|
|
|
|
(GetAccessibilityLevel(implementingMember) <= GetAccessibilityLevel(ev)); |
|
|
|
|
if (!alreadyImplemented) { |
|
|
|
|
toImplement.Add(new Tuple<IMember, bool>(ev, needsExplicitly)); |
|
|
|
|
} else { |
|
|
|
@ -160,17 +148,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -160,17 +148,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
continue; |
|
|
|
|
bool needsExplicitly = explicitly; |
|
|
|
|
alreadyImplemented = false; |
|
|
|
|
|
|
|
|
|
foreach (var cmet in implementingType.GetMethods ()) { |
|
|
|
|
alreadyImplemented |= cmet.ImplementedInterfaceMembers.Any(m => IsImplementation (m, method)); |
|
|
|
|
|
|
|
|
|
if (CompareMembers(method, cmet)) { |
|
|
|
|
if (!needsExplicitly && !cmet.ReturnType.Equals(method.ReturnType)) |
|
|
|
|
needsExplicitly = true; |
|
|
|
|
else |
|
|
|
|
alreadyImplemented |= !needsExplicitly /*|| cmet.InterfaceImplementations.Any (impl => impl.InterfaceType.Equals (interfaceType))*/; |
|
|
|
|
|
|
|
|
|
var implementingMethod = implementingType.GetInterfaceImplementation(method); |
|
|
|
|
alreadyImplemented = (implementingMethod != null) && |
|
|
|
|
(GetAccessibilityLevel(implementingMethod) <= GetAccessibilityLevel(method)); |
|
|
|
|
if (alreadyImplemented) { |
|
|
|
|
if (!needsExplicitly && !implementingMethod.ReturnType.Equals(method.ReturnType)) { |
|
|
|
|
needsExplicitly = true; |
|
|
|
|
alreadyImplemented = false; |
|
|
|
|
} else { |
|
|
|
|
alreadyImplemented = !needsExplicitly; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (toImplement.Where(t => t.Item1 is IMethod).Any(t => CompareMembers(method, (IMethod)t.Item1))) |
|
|
|
|
needsExplicitly = true; |
|
|
|
|
if (!alreadyImplemented) { |
|
|
|
@ -187,27 +177,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -187,27 +177,19 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
bool needsExplicitly = explicitly; |
|
|
|
|
alreadyImplemented = implementingType.GetMembers().Any(m => m.ImplementedInterfaceMembers.Any(im => IsImplementation (im, prop))); |
|
|
|
|
|
|
|
|
|
foreach (var t in implementingType.GetAllBaseTypeDefinitions ()) { |
|
|
|
|
if (t.Kind == TypeKind.Interface) { |
|
|
|
|
foreach (var cprop in t.Properties) { |
|
|
|
|
if (cprop.Name == prop.Name && cprop.IsShadowing) { |
|
|
|
|
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType)) |
|
|
|
|
needsExplicitly = true; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
continue; |
|
|
|
|
} |
|
|
|
|
foreach (var cprop in t.Properties) { |
|
|
|
|
if (cprop.Name == prop.Name) { |
|
|
|
|
if (!needsExplicitly && !cprop.ReturnType.Equals(prop.ReturnType)) |
|
|
|
|
needsExplicitly = true; |
|
|
|
|
else |
|
|
|
|
alreadyImplemented |= !needsExplicitly/* || cprop.InterfaceImplementations.Any (impl => impl.InterfaceType.Resolve (ctx).Equals (interfaceType))*/; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var implementingProp = implementingType.GetInterfaceImplementation(prop); |
|
|
|
|
alreadyImplemented = (implementingProp != null) && |
|
|
|
|
(GetAccessibilityLevel(implementingProp) <= GetAccessibilityLevel(prop)); |
|
|
|
|
if (alreadyImplemented) { |
|
|
|
|
if (!needsExplicitly && !implementingProp.ReturnType.Equals(prop.ReturnType)) { |
|
|
|
|
needsExplicitly = true; |
|
|
|
|
alreadyImplemented = false; |
|
|
|
|
} else { |
|
|
|
|
alreadyImplemented = !needsExplicitly; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (!alreadyImplemented) { |
|
|
|
|
toImplement.Add(new Tuple<IMember, bool>(prop, needsExplicitly)); |
|
|
|
|
} else { |
|
|
|
@ -217,6 +199,26 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
@@ -217,6 +199,26 @@ namespace ICSharpCode.NRefactory.CSharp.Refactoring
|
|
|
|
|
return toImplement; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static int GetAccessibilityLevel(IHasAccessibility member) |
|
|
|
|
{ |
|
|
|
|
if (member.Accessibility == Accessibility.None) |
|
|
|
|
return 0; |
|
|
|
|
if (member.IsPublic) |
|
|
|
|
return 1; |
|
|
|
|
if (member.IsInternal) |
|
|
|
|
return 2; |
|
|
|
|
if (member.IsProtectedOrInternal) |
|
|
|
|
return 3; |
|
|
|
|
if (member.IsProtectedAndInternal) |
|
|
|
|
return 4; |
|
|
|
|
if (member.IsProtected) |
|
|
|
|
return 5; |
|
|
|
|
if (member.IsPrivate) |
|
|
|
|
return 6; |
|
|
|
|
|
|
|
|
|
return 7; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
internal static bool CompareMembers(IMember interfaceMethod, IMember typeMethod) |
|
|
|
|
{ |
|
|
|
|
if (typeMethod.IsExplicitInterfaceImplementation) |
|
|
|
|