bool IsAppropriateCallTarget(ExpectedTargetDetails expectedTargetDetails, IMember expectedTarget, IMember actualTarget) { if (expectedTarget.Equals(actualTarget)) { return(true); } if (expectedTargetDetails.CallOpCode == OpCode.CallVirt && actualTarget.IsOverride) { if (expectedTargetDetails.NeedsBoxingConversion && actualTarget.DeclaringType.IsReferenceType != true) { return(false); } foreach (var possibleTarget in InheritanceHelper.GetBaseMembers(actualTarget, false)) { if (expectedTarget.Equals(possibleTarget)) { return(true); } if (!possibleTarget.IsOverride) { break; } } } return(false); }
private static void DuplicateMemberReferencesAreEqual([NotNull] IMember originMember, [NotNull] IMember memberReferenceDuplicate) { originMember.RequiredNotNull(); memberReferenceDuplicate.RequiredNotNull(); Assert.True(originMember.Equals(memberReferenceDuplicate)); }
protected override void Run(object data) { Document doc = IdeApp.Workbench.ActiveDocument; if (doc == null || doc.FileName == FilePath.Null || IdeApp.ProjectOperations.CurrentSelectedSolution == null) { return; } ITextBuffer editor = doc.GetContent <ITextBuffer> (); if (editor == null) { return; } int line, column; editor.GetLineColumnFromPosition(editor.CursorPosition, out line, out column); ProjectDom ctx = doc.Dom; ResolveResult resolveResult; INode item; CurrentRefactoryOperationsHandler.GetItem(ctx, doc, editor, out resolveResult, out item); IMember eitem = resolveResult != null ? (resolveResult.CallingMember ?? resolveResult.CallingType) : null; string itemName = null; if (item is IMember) { itemName = ((IMember)item).Name; } if (item != null && eitem != null && (eitem.Equals(item) || (eitem.Name == itemName && !(eitem is IProperty) && !(eitem is IField) && !(eitem is IMethod)))) { item = eitem; eitem = null; } IType eclass = null; if (item is IType) { if (((IType)item).ClassType == ClassType.Interface) { eclass = CurrentRefactoryOperationsHandler.FindEnclosingClass(ctx, editor.Name, line, column); } else { eclass = (IType)item; } if (eitem is IMethod && ((IMethod)eitem).IsConstructor && eitem.DeclaringType.Equals(item)) { item = eitem; eitem = null; } } Refactorer refactorer = new Refactorer(ctx, doc.CompilationUnit, eclass, item, null); refactorer.GoToDeclaration(); }
static bool IsSameMember(IMember a, IMember b) { if (a == null || b == null) { return(false); } a = a.MemberDefinition; b = b.MemberDefinition; return(a.Equals(b)); }
bool IsAppropriateCallTarget(IMember expectedTarget, IMember actualTarget, bool isVirtCall) { if (expectedTarget.Equals(actualTarget)) { return(true); } if (isVirtCall && actualTarget.IsOverride) { foreach (var possibleTarget in InheritanceHelper.GetBaseMembers(actualTarget, false)) { if (expectedTarget.Equals(possibleTarget)) { return(true); } if (!possibleTarget.IsOverride) { break; } } } return(false); }
bool IsMemberMatch(IMember member, IMember referencedMember, bool isVirtualCall) { referencedMember = NormalizeMember(referencedMember); if (member.Equals(referencedMember)) return true; if (!isVirtualCall) return false; bool isInterfaceCall = referencedMember.DeclaringTypeDefinition != null && referencedMember.DeclaringTypeDefinition.Kind == TypeKind.Interface; if (FindCallsThroughVirtualBaseMethod && member.IsOverride && !WholeVirtualSlot && !isInterfaceCall) { // Test if 'member' overrides 'referencedMember': foreach (var baseMember in InheritanceHelper.GetBaseMembers(member, false)) { if (FindOnlySpecializedReferences) { if (baseMember.Equals(referencedMember)) return true; } else { if (baseMember.MemberDefinition.Equals(referencedMember)) return true; } if (!baseMember.IsOverride) break; } return false; } else if (FindCallsThroughInterface && isInterfaceCall) { // Test if 'member' implements 'referencedMember': if (FindOnlySpecializedReferences) { return member.ImplementedInterfaceMembers.Contains(referencedMember); } else { return member.ImplementedInterfaceMembers.Any(m => m.MemberDefinition.Equals(referencedMember)); } } return false; }
public IMember Resolve(ITypeResolveContext context) { IType declaringType = typeReference.Resolve(context); IMember interfaceMember = interfaceMemberReference.Resolve(context.WithCurrentTypeDefinition(declaringType.GetDefinition())); if (interfaceMember == null) { return(null); } IEnumerable <IMember> members; if (interfaceMember.SymbolKind == SymbolKind.Accessor) { members = declaringType.GetAccessors( m => m.IsExplicitInterfaceImplementation, GetMemberOptions.IgnoreInheritedMembers); } else { members = declaringType.GetMembers( m => m.SymbolKind == interfaceMember.SymbolKind && m.IsExplicitInterfaceImplementation, GetMemberOptions.IgnoreInheritedMembers); } return(members.FirstOrDefault(m => m.ImplementedInterfaceMembers.Count == 1 && interfaceMember.Equals(m.ImplementedInterfaceMembers[0]))); }
private void AddMissingAliases(TypeDeclaration typeDeclaration) { var type = this.Resolver.ResolveNode(typeDeclaration, null).Type; var interfaces = type.DirectBaseTypes.Where(t => t.Kind == TypeKind.Interface).ToArray(); var members = type.GetMembers(null, GetMemberOptions.IgnoreInheritedMembers).ToArray(); var baseTypes = type.GetNonInterfaceBaseTypes().ToArray().Reverse(); if (interfaces.Length > 0) { foreach (var baseInterface in interfaces) { var interfaceMembers = baseInterface.GetMembers().Where(m => m.DeclaringTypeDefinition.Kind == TypeKind.Interface); foreach (var interfaceMember in interfaceMembers) { var isDirectlyImplemented = members.Any(m => m.ImplementedInterfaceMembers.Contains(interfaceMember)); if (!isDirectlyImplemented) { foreach (var baseType in baseTypes) { //var derivedMember = InheritanceHelper.GetDerivedMember(interfaceMember, baseType.GetDefinition()); IMember derivedMember = null; IEnumerable <IMember> baseMembers; if (interfaceMember.SymbolKind == SymbolKind.Accessor) { baseMembers = baseType.GetAccessors(null, GetMemberOptions.IgnoreInheritedMembers).Where(m => m.Name == interfaceMember.Name && TypeComparer.Equals(m.ReturnType, interfaceMember.ReturnType)); } else { baseMembers = baseType.GetMembers(null, GetMemberOptions.IgnoreInheritedMembers).Where(m => m.Name == interfaceMember.Name && TypeComparer.Equals(m.ReturnType, interfaceMember.ReturnType)); } foreach (IMember baseMember in baseMembers) { if (baseMember.IsPrivate) { continue; } if (SignatureComparer.Ordinal.Equals(interfaceMember, baseMember)) { derivedMember = baseMember.Specialize(interfaceMember.Substitution); break; } } if (derivedMember != null && !derivedMember.ImplementedInterfaceMembers.Contains(interfaceMember) && !this.CurrentType.InstanceConfig.Alias.Any(a => typeDeclaration.Equals(a.Entity) && interfaceMember.Equals(a.InterfaceMember) && derivedMember.Equals(a.DerivedMember))) { this.CurrentType.InstanceConfig.Alias.Add(new TypeConfigItem { Entity = typeDeclaration, InterfaceMember = interfaceMember, DerivedMember = derivedMember }); break; } } } } } } }
public IMember Resolve(ITypeResolveContext context) { IMember interfaceMember = interfaceMemberReference.Resolve(context); if (interfaceMember == null) { return(null); } IType type = typeReference.Resolve(context); var members = type.GetMembers( m => m.EntityType == interfaceMember.EntityType && m.IsExplicitInterfaceImplementation, GetMemberOptions.IgnoreInheritedMembers); return(members.FirstOrDefault(m => m.InterfaceImplementations.Count == 1 && interfaceMember.Equals(m.InterfaceImplementations[0]))); }
private static void MemberDoesNotEqualNull([NotNull] IMember member) { member.RequiredNotNull(); Assert.False(member.Equals(null)); }
public IMember Resolve(ITypeResolveContext context) { IType declaringType = typeReference.Resolve(context); IMember interfaceMember = interfaceMemberReference.Resolve(context.WithCurrentTypeDefinition(declaringType.GetDefinition())); if (interfaceMember == null) { return(null); } var members = declaringType.GetMembers( m => m.EntityType == interfaceMember.EntityType && m.IsExplicitInterfaceImplementation, GetMemberOptions.IgnoreInheritedMembers); return(members.FirstOrDefault(m => m.ImplementedInterfaceMembers.Count == 1 && interfaceMember.Equals(m.ImplementedInterfaceMembers[0]))); }