public override ResolveResultWithInfo ResolveWithoutCache() { ISymbolTable table = this.GetReferenceSymbolTable(true); IList <DeclaredElementInstance> elements = new List <DeclaredElementInstance>(); { IList <ISymbolInfo> infos = table.GetSymbolInfos(this.GetName()); foreach (ISymbolInfo info in infos) { var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE); elements.Add(element); } } if (elements.Count == 0) { var ruleName = this.myOwner as Prefix; // Unresolved namespaces creation if (ruleName != null) { elements = new List <DeclaredElementInstance> { new DeclaredElementInstance( new UnresolvedNamespacePrefixDeclaredElement( ruleName.GetSourceFile(), this.GetName(), this.myOwner.GetPsiServices())) }; } } return(new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements), ResolveErrorType.OK)); }
public override ResolveResultWithInfo ResolveWithoutCache() { ISymbolTable table = GetReferenceSymbolTable(true); IList <DeclaredElementInstance> elements = new List <DeclaredElementInstance>(); { IList <ISymbolInfo> infos = table.GetSymbolInfos(GetName()); foreach (ISymbolInfo info in infos) { var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE); elements.Add(element); } } if (elements.Count == 0) { var ruleName = myOwner as RuleName; if (PsiTreeUtil.HasParent <InterfacesDefinition>(myOwner) && (ruleName != null)) { elements = new List <DeclaredElementInstance> { new DeclaredElementInstance(new UnresolvedRuleInterfacesDeclaredElement(ruleName.GetSourceFile(), GetName(), myOwner.GetPsiServices())) }; } } return(new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements), ResolveErrorType.OK)); }
public void ProcessMembers(CSharpCodeCompletionContext context, GroupedItemsCollector collector, ISymbolTable symbols) { symbols.ForAllSymbolInfos(symbol => { var member = symbol.GetDeclaredElement() as ITypeMember; if (member != null && member.GetElementType() == ExpectedMemberType) { string nameArgument = string.Format("\"{0}\"", symbol.ShortName); var declaredElementInstance = new DeclaredElementInstance <ITypeMember>((ITypeMember)symbol.GetDeclaredElement(), symbol.GetSubstitution()); if (!IncludeSymbol(declaredElementInstance)) { return; } IList <string> arguments = new List <string>(); if (IncludeNameArgument) { arguments.Add(nameArgument); } if (NeedsBindingFlags(member)) { arguments.Add(GetExpectedBindingFlags(member).GetFullString()); } if (ShouldProvideMemberSpecificArguments(symbols.GetSymbolInfos(member.ShortName))) //additional arguments needs to be provided { ProvideMemberSpecificArguments(declaredElementInstance, arguments, NeedsBindingFlags(member)); } ReflectionMemberLookupItem lookupItem; if (member is IMethod && ((IMethod)member).TypeParameters.Count != 0) { lookupItem = new ReflectionGenericMethodLookupItem(symbol.ShortName, declaredElementInstance, context, context.BasicContext.LookupItemsOwner); } else { lookupItem = new ReflectionMemberLookupItem(symbol.ShortName, string.Join(", ", arguments.ToArray()), declaredElementInstance, context, context.BasicContext.LookupItemsOwner); } lookupItem.InitializeRanges(context.CompletionRanges, context.BasicContext); lookupItem.OrderingString = string.Format("__A_MEMBER_{0}", symbol.ShortName); // collector.AddToTop(lookupItem); } }); }
public static bool IsForeachEnumeratorPatternMember(IDeclaredElement declaredElement) { var method = declaredElement as IMethod; if (method != null) { // GetEnumerator if (method.ShortName == "GetEnumerator" && method.Parameters.Count == 0 && !method.IsStatic && method.TypeParameters.Count == 0 && !method.IsExplicitImplementation && method.GetAccessRights() == AccessRights.PUBLIC) { return(true); } if (IsForeachMoveNextMethodCandidate(method)) { ITypeElement containingType = method.GetContainingType(); if (containingType != null) { ISymbolTable symbolTable = ResolveUtil.GetSymbolTableByTypeElement(containingType, SymbolTableMode.FULL, containingType.Module); if ( symbolTable.GetSymbolInfos("Current").Any( symbolInfo => IsForeachCurrentPropertyCandidate(symbolInfo.GetDeclaredElement() as IProperty))) { return(true); } } } } var property = declaredElement as IProperty; if (property != null) { if (IsForeachCurrentPropertyCandidate(property)) { ITypeElement containingType = property.GetContainingType(); if (containingType != null) { ISymbolTable symbolTable = ResolveUtil.GetSymbolTableByTypeElement(containingType, SymbolTableMode.FULL, containingType.Module); if ( symbolTable.GetSymbolInfos("MoveNext").Any( symbolInfo => IsForeachMoveNextMethodCandidate(symbolInfo.GetDeclaredElement() as IMethod))) { return(true); } } } } return(false); }
public override ResolveResultWithInfo ResolveWithoutCache() { ISymbolTable table = GetReferenceSymbolTable(true); IList <DeclaredElementInstance> elements = new List <DeclaredElementInstance>(); { IList <ISymbolInfo> infos = table.GetSymbolInfos(GetName()); foreach (ISymbolInfo info in infos) { var element = new DeclaredElementInstance(info.GetDeclaredElement(), EmptySubstitution.INSTANCE); elements.Add(element); } } return(new ResolveResultWithInfo(ResolveResultFactory.CreateResolveResultFinaly(elements), ResolveErrorType.OK)); }
private static IEnumerable GetChildren(ITypeElement typeElement, bool instanceVisible) { // Obtain language service for the type PsiLanguageType language = PresentationUtil.GetPresentationLanguage(typeElement); if (language.IsNullOrUnknown()) { return(Enumerable.Empty <DeclaredElementEnvoy <ITypeMember> >()); } LanguageService languageService = language.LanguageService(); if (languageService == null) { return(Enumerable.Empty <DeclaredElementEnvoy <ITypeMember> >()); } // Get symbol table for the typeElement and filter it with OverriddenFilter // This filter removes all but leaf members for override chains ISymbolTable symbolTable = TypeFactory.CreateType(typeElement).GetSymbolTable(typeElement.Module); symbolTable = symbolTable.Filter(OverriddenFilter.INSTANCE); // Obtain ITypeElement for System.Object // We don't want ToString(), GetHashCode(), GetType() and Equals() to pollute tree view ITypeElement objectType = typeElement.Module.GetPredefinedType(typeElement.ResolveContext).Object.GetTypeElement(); var children = new List <DeclaredElementEnvoy <ITypeMember> >(); foreach (string name in symbolTable.Names()) { foreach (ISymbolInfo info in symbolTable.GetSymbolInfos(name)) { // Select all ITypeMembers from symbol table var member = info.GetDeclaredElement() as ITypeMember; if (member == null) { continue; } // Checks that member is visible in language. For example, get_Property() member is not visible in C# if (!languageService.IsTypeMemberVisible(member)) { continue; } // Do not show members of System.Object // This doesn't hide respective overrides, though if (Equals(member.GetContainingType(), objectType)) { continue; } // Checks that member is not "synthetic". Synthetic members are generated by ReSharper to support // generative languages, like ASP.NET if (member.IsSynthetic()) { continue; } // Checks if member should be displayed according to its accessibility AccessibilityDomain.AccessibilityDomainType access = member.AccessibilityDomain.DomainType; if (access == AccessibilityDomain.AccessibilityDomainType.PRIVATE) { continue; } // If we want only instance members, filter further if (instanceVisible) { // Don't show nested types if (member is ITypeElement) { continue; } // Don't show constructors if (member is IConstructor) { continue; } // hide static, protected and "protected internal" members if (member.IsStatic) { continue; } if (access == AccessibilityDomain.AccessibilityDomainType.PROTECTED) { continue; } if (access == AccessibilityDomain.AccessibilityDomainType.PROTECTED_AND_INTERNAL) { continue; } } // It passed all filters! Create an envoy and add to collection children.Add(new DeclaredElementEnvoy <ITypeMember>(member)); } } return(children); }