internal ResolveResult CreateResult(TypeReference typeReference) { return(CreateResult(NRefactoryResolver.ConvertTypeReference(typeReference))); }
ResolveResult ResolveMemberReference(ResolveResult result, MemberReferenceExpression memberReferenceExpression) { IType type = resolver.Dom.GetType(result.ResolvedType); if (type == null) { return(null); } //Console.WriteLine ("Resolve member: " + memberReferenceExpression.MemberName + " on " + type); List <IMember> member = new List <IMember> (); List <IType> accessibleExtTypes = DomType.GetAccessibleExtensionTypes(resolver.Dom, resolver.Unit); // Inheritance of extension methods is handled in DomType foreach (IMethod method in type.GetExtensionMethods(accessibleExtTypes, memberReferenceExpression.MemberName)) { member.Add(method); } bool includeProtected = true; foreach (IType curType in resolver.Dom.GetInheritanceTree(type)) { if (curType.ClassType == MonoDevelop.Projects.Dom.ClassType.Interface && type.ClassType != MonoDevelop.Projects.Dom.ClassType.Interface) { continue; } if (curType.IsAccessibleFrom(resolver.Dom, resolver.CallingType, resolver.CallingMember, includeProtected)) { foreach (IMember foundMember in curType.SearchMember(memberReferenceExpression.MemberName, true)) { if (foundMember.IsExplicitDeclaration) { continue; } if (result is BaseResolveResult && foundMember.IsAbstract) { continue; } member.Add(foundMember); } } } if (member.Count > 0) { if (member [0] is IMethod) { bool isStatic = result.StaticResolve; List <IMember> nonMethodMembers = new List <IMember> (); List <string> errors = new List <string> (); int typeParameterCount = 0; if (memberReferenceExpression.TypeArguments != null) { typeParameterCount = memberReferenceExpression.TypeArguments.Count; } for (int i = 0; i < member.Count; i++) { IMethod method = member [i] as IMethod; if (method == null) { nonMethodMembers.Add(member [i]); } if (!member [i].IsAccessibleFrom(resolver.Dom, type, resolver.CallingMember, includeProtected)) { errors.Add( MonoDevelop.Core.GettextCatalog.GetString("'{0}' is inaccessible due to its protection level.", ambience.GetString(method, OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics))); } if (method != null && !method.IsFinalizer && (method.IsExtension || method.WasExtended) /* && method.IsAccessibleFrom (resolver.Dom, type, resolver.CallingMember, true)*/) { continue; } if ((member [i].IsStatic ^ isStatic) || /* !member[i].IsAccessibleFrom (resolver.Dom, type, resolver.CallingMember, includeProtected) || */ (method != null && (method.IsFinalizer || typeParameterCount > 0 && method.TypeParameters.Count != typeParameterCount))) { member.RemoveAt(i); i--; } } if (member.Count == 0) { return(null); } result = new MethodResolveResult(member); ((MethodResolveResult)result).Type = type; ((MethodResolveResult)result).StaticUsage = isStatic; result.CallingType = resolver.CallingType; result.CallingMember = resolver.CallingMember; result.ResolveErrors.AddRange(errors); result.StaticResolve = isStatic; //result.UnresolvedType = result.ResolvedType = member[0].ReturnType; foreach (TypeReference typeReference in memberReferenceExpression.TypeArguments) { ((MethodResolveResult)result).AddGenericArgument(resolver.ResolveType(NRefactoryResolver.ConvertTypeReference(typeReference))); } ((MethodResolveResult)result).ResolveExtensionMethods(); if (nonMethodMembers.Count > 0) { MemberResolveResult baseResult = (MemberResolveResult)CreateResult(nonMethodMembers [0].DeclaringType.CompilationUnit, nonMethodMembers [0].ReturnType); baseResult.ResolvedMember = nonMethodMembers [0]; return(new CombinedMethodResolveResult(baseResult, (MethodResolveResult)result)); } //System.Console.WriteLine(result + "/" + result.ResolvedType); return(result); } if (member [0] is IType) { result = CreateResult(member [0].FullName); result.StaticResolve = true; } else { result = CreateResult(member [0].DeclaringType.CompilationUnit, member [0].ReturnType); ((MemberResolveResult)result).ResolvedMember = member [0]; } if (!member [0].IsAccessibleFrom(resolver.Dom, type, resolver.CallingMember, includeProtected)) { result.ResolveErrors.Add(string.Format(MonoDevelop.Core.GettextCatalog.GetString("'{0}' is inaccessible due to it's protection level."), ambience.GetString(member [0], OutputFlags.IncludeParameters | OutputFlags.IncludeGenerics))); } return(result); } return(new UnresolvedMemberResolveResult(result, memberReferenceExpression.MemberName) { CallingType = resolver.CallingType, CallingMember = resolver.CallingMember }); }
public override object VisitMemberReferenceExpression(MemberReferenceExpression memberReferenceExpression, object data) { if (memberReferenceExpression == null) { return(null); } ResolveResult result; if (String.IsNullOrEmpty(memberReferenceExpression.MemberName)) { if (memberReferenceExpression.TargetObject is TypeReferenceExpression) { result = CreateResult(((TypeReferenceExpression)memberReferenceExpression.TargetObject).TypeReference); result.StaticResolve = true; return(result); } // if (memberReferenceExpression.TargetObject is ThisReferenceExpression) { // result = CreateResult (((TypeReferenceExpression)memberReferenceExpression.TargetObject).TypeReference); // result.StaticResolve = true; // return result; // } // return memberReferenceExpression.TargetObject.AcceptVisitor(this, data); } result = memberReferenceExpression.TargetObject.AcceptVisitor(this, data) as ResolveResult; NamespaceResolveResult namespaceResult = result as NamespaceResolveResult; if (namespaceResult != null) { if (String.IsNullOrEmpty(memberReferenceExpression.MemberName)) { return(namespaceResult); } string fullName = namespaceResult.Namespace + "." + memberReferenceExpression.MemberName; if (resolver.Dom.NamespaceExists(fullName, true)) { return(new NamespaceResolveResult(fullName)); } DomReturnType searchType = new DomReturnType(fullName); if (memberReferenceExpression.TypeArguments != null) { foreach (TypeReference typeRef in memberReferenceExpression.TypeArguments) { searchType.AddTypeParameter(NRefactoryResolver.ConvertTypeReference(typeRef)); } } IType type = resolver.Dom.GetType(searchType); if (type != null) { result = CreateResult(this.resolver.Unit, new DomReturnType(type)); result.StaticResolve = true; return(result); } return(null); } if (result != null && result.ResolvedType != null) { foreach (ResolveResult innerResult in result.ResolveResults) { ResolveResult resolvedResult = ResolveMemberReference(innerResult, memberReferenceExpression); if (resolvedResult != null) { return(resolvedResult); } } } else { if (result != null) { MonoDevelop.Core.LoggingService.LogWarning("Couldn't resolve type " + result.ResolvedType); } } return(null); }
public override object VisitIdentifierExpression(IdentifierExpression identifierExpression, object data) { if (identifierExpression.TypeArguments != null && identifierExpression.TypeArguments.Count > 0) { if (resolver.CallingType != null) { foreach (var type in resolver.Dom.GetInheritanceTree(resolver.CallingType)) { IMethod possibleMethod = type.Methods.Where(m => m.Name == identifierExpression.Identifier && m.TypeParameters.Count == identifierExpression.TypeArguments.Count && m.IsAccessibleFrom(resolver.Dom, resolver.CallingType, resolver.CallingMember, true)).FirstOrDefault(); if (possibleMethod != null) { MethodResolveResult methodResolveResult = new MethodResolveResult(possibleMethod); methodResolveResult.CallingType = resolver.CallingType; methodResolveResult.CallingMember = resolver.CallingMember; identifierExpression.TypeArguments.ForEach(arg => methodResolveResult.AddGenericArgument(resolver.ResolveType(NRefactoryResolver.ConvertTypeReference(arg)))); methodResolveResult.ResolveExtensionMethods(); return(methodResolveResult); } } } TypeReference reference = new TypeReference(identifierExpression.Identifier); reference.GenericTypes.AddRange(identifierExpression.TypeArguments); ResolveResult result = CreateResult(reference); result.StaticResolve = true; return(result); } // Console.WriteLine ("visit id: " + identifierExpression.Identifier); var res = resolver.ResolveIdentifier(this, identifierExpression.Identifier.TrimEnd('.')); // Console.WriteLine ("result: " + res); return(res); }