private static ISearchDomain GetSearchDomain(IPsiModule module, IModuleReferenceResolveContext context) { IPsiServices psiServices = module.GetPsiServices(); ISearchDomain searchDomain = psiServices.SearchDomainFactory.CreateSearchDomain( module.GetPsiServices().Modules.GetModules() .Where(m => m.References(module, context) || module.References(m, context)) .Prepend(module)); return(searchDomain); }
private IMethod FindAssertionMethod([NotNull] string assertionMethodName, [NotNull] IExpressionType parameterType, [NotNull] IPsiModule module) { var symbolScope = module.GetPsiServices().Symbols.GetSymbolScope(module, true, true); IClass typeDecl = null; if (this.CachedAssertClassTypeName != null) { typeDecl = symbolScope.GetTypeElementByCLRName(this.CachedAssertClassTypeName) as IClass; } else { var candidates = symbolScope.GetElementsByShortName(AssertTypeName).OfType <IClass>().Where(c => c.CanBeVisibleToSolution()).ToArray(); if (candidates.Length == 1) { typeDecl = candidates[0]; } if (typeDecl != null) { this.CachedAssertClassTypeName = typeDecl.GetClrName(); } } return(typeDecl? .EnumerateMembers(assertionMethodName, true) .OfType <IMethod>() .FirstOrDefault(m => m.Parameters.Count > 1 && (m.Parameters[0].Type.IsOpenType || parameterType.IsImplicitlyConvertibleTo(m.Parameters[0].Type, module.GetTypeConversionRule())))); }
public ITypeElement GetTypeElement(IPsiModule psiModule, IClrTypeName clrTypeName) { var symbolCache = psiModule.GetPsiServices().Symbols; var symbolScope = symbolCache.GetSymbolScope(psiModule, UniversalModuleReferenceContext.Instance, withReferences: true, caseSensitive: true); return(symbolScope.GetTypeElementByCLRName(clrTypeName)); }
private ImplicitNullabilityConfiguration?ParseConfigurationFromAssemblyAttribute(IPsiModule psiModule) { var psiServices = psiModule.GetPsiServices(); // do not c'tor inject to avoid circular dependency var moduleAttributes = psiServices.Symbols.GetModuleAttributes(psiModule); return(AssemblyAttributeConfigurationTranslator.ParseAttributes(moduleAttributes)); }
private UnityColorTypes([NotNull] IPsiModule module) { var cache = module.GetPsiServices().Symbols.GetSymbolScope(module, true, true); UnityColorType = cache.GetTypeElementByCLRName(UnityColorTypeName); UnityColor32Type = cache.GetTypeElementByCLRName(UnityColor32TypeName); }
private static ISet <string> ResolveSuppressedHighlightingsByAssemblyAttributes([NotNull] IPsiModule module) { return(module.GetPsiServices() .Symbols.GetModuleAttributes(module) .GetAttributeInstances(SuppressAttributeName, false) .Where(IsValidAttributeInstance) .Select(inst => (string)inst.PositionParameter(1).ConstantValue.Value) .ToSet()); }
private static IClrDeclaredElement GetDeclaredNamespace([NotNull] FSharpEntity entity, IPsiModule psiModule) { Assertion.Assert(entity.IsNamespace, "entity.IsNamespace"); var name = entity.CompiledName; var containingName = entity.Namespace?.Value; var fullName = containingName != null ? containingName + "." + name : name; var symbolScope = psiModule.GetPsiServices().Symbols.GetSymbolScope(psiModule, true, true); return(symbolScope.GetElementsByQualifiedName(fullName).FirstOrDefault() as INamespace); }
private static bool ExecuteTransaction([NotNull] IPsiModule module, [NotNull] Action action) { IPsiTransactions transactions = module.GetPsiServices().Transactions; if (transactions.Current != null) { action(); return(true); } return(transactions.Execute("T4 Assembly Reference", action).Succeded); }
public bool IsTestProject(IPsiModule psiModule) { if (!_isMoqContainedByProjectName.TryGetValue(psiModule.DisplayName, out var isMoqContained)) { IReadOnlyList <IPsiModuleReference> references = psiModule.GetPsiServices().Modules.GetModuleReferences(psiModule); isMoqContained = references.Any(r => MoqReferenceNames.Contains(r.Module.Name)); _isMoqContainedByProjectName.Add(psiModule.DisplayName, isMoqContained); } return(isMoqContained); }
public static OneToListMap <string, IClass> GetAvailableModules([NotNull] IPsiModule module, [NotNull] ISearchDomain searchDomain, IModuleReferenceResolveContext contex, bool includingIntermediateControllers = false, ITypeElement baseClass = null) { ITypeElement[] typeElements; ITypeElement nancyModuleInterface = GetNancyModuleInterface(module, contex); if (baseClass != null) { if (baseClass.IsDescendantOf(nancyModuleInterface)) { typeElements = new[] { baseClass }; } else { return(new OneToListMap <string, IClass>(0)); } } else { typeElements = new[] { nancyModuleInterface }; } var found = new List <IClass>(); foreach (ITypeElement typeElement in typeElements.WhereNotNull()) { module.GetPsiServices() .Finder.FindInheritors(typeElement, searchDomain, found.ConsumeDeclaredElements(), NullProgressIndicator.Instance); } IEnumerable <IClass> classes = found.Where(@class => @class.GetAccessRights() == AccessRights.PUBLIC); if (!includingIntermediateControllers) { classes = classes.Where(@class => [email protected] && @class.ShortName.EndsWith(ModuleClassSuffix, StringComparison.OrdinalIgnoreCase)); } return(new OneToListMap <string, IClass>( classes.GroupBy(GetControllerName, (name, enumerable) => new KeyValuePair <string, IList <IClass> >(name, enumerable.ToList())), StringComparer.OrdinalIgnoreCase)); }
internal static ITypeElement GetTypeElement([NotNull] FSharpEntity entity, [NotNull] IPsiModule psiModule) { if (((FSharpSymbol)entity).DeclarationLocation == null || entity.IsByRef || entity.IsProvidedAndErased) { return(null); } if (!entity.IsFSharpAbbreviation) { var clrName = FSharpTypesUtil.GetClrName(entity); return(clrName != null ? TypeFactory.CreateTypeByCLRName(clrName, psiModule).GetTypeElement() : null); } var symbolScope = psiModule.GetPsiServices().Symbols.GetSymbolScope(psiModule, true, true); while (entity.IsFSharpAbbreviation) { // FCS returns Clr names for non-abbreviated types only, using fullname var typeElement = TryFindByNames(GetPossibleNames(entity), symbolScope); if (typeElement != null) { return(typeElement); } var abbreviatedType = entity.AbbreviatedType; if (!abbreviatedType.HasTypeDefinition) { return(null); } entity = entity.AbbreviatedType.TypeDefinition; } var name = FSharpTypesUtil.GetClrName(entity); return(name != null?TypeFactory.CreateTypeByCLRName(name, psiModule).GetTypeElement() : null); }
private static IEnumerable <ICSharpFile> GetAllCSharpFilesInProject(IPsiModule projectModule) { PsiManager psiManager = projectModule.GetPsiServices().PsiManager; return(projectModule.SourceFiles.SelectMany(f => psiManager.GetPsiFiles <CSharpLanguage>(f).OfType <ICSharpFile>())); }
public ITypeElement GetTypeElement(IPsiModule psiModule, IClrTypeName clrTypeName) { var symbolCache = psiModule.GetPsiServices().Symbols; var symbolScope = symbolCache.GetSymbolScope(psiModule, UniversalModuleReferenceContext.Instance, withReferences: true, caseSensitive: true); return symbolScope.GetTypeElementByCLRName(clrTypeName); }
public INamespace GetContainingNamespace() { return(myMethod.GetContainingType()?.GetContainingNamespace() ?? Module.GetPsiServices().Symbols.GetSymbolScope(LibrarySymbolScope.FULL, true).GlobalNamespace); }
public ImplicitNullabilityConfiguration EvaluateFor(IPsiModule psiModule) { var cache = psiModule.GetPsiServices().Caches.GetPsiCache <ConfigurationCache>(); return(cache.GetOrAdd(psiModule, CalculateConfiguration)); }
protected override void AnalyzePrimaryPsiModule(IPsiModule primaryPsiModule) { var psiServices = primaryPsiModule.GetPsiServices(); var symbolScope = psiServices.Symbols.GetSymbolScope(primaryPsiModule, true, true); var globalNamespace = symbolScope.GlobalNamespace; foreach (var te in FindTypeElements(globalNamespace, symbolScope)) { // ignore private and internal types if (!te.CanBeVisibleToSolution()) { continue; } // ignore types defined in solution if (!IsDefinedInDependency(te)) { continue; } // ignore types that are already processed var clrName = te.GetClrName().FullName; if (!_seenClrNames.Add(clrName)) { continue; } // see http://stackoverflow.com/questions/4603139/a-c-sharp-class-with-a-null-namespace var isMetaDataClass = "FXAssembly".Equals(clrName) || "ThisAssembly".Equals(clrName) || "AssemblyRef".Equals(clrName); if (isMetaDataClass) { continue; } // ignore private if (clrName.StartsWith("<PrivateImplementationDetails>")) { continue; } // ignore c++ impl details if (clrName.StartsWith("<CppImplementationDetails>")) { continue; } // ignore crt impl details if (clrName.StartsWith("<CrtImplementationDetails>")) { continue; } // ignore anonymous if (clrName.StartsWith("<>")) { continue; } // ignore gcroots if (clrName.StartsWith("gcroot<")) { continue; } // ignore global module if (clrName.Equals("<Module>")) { continue; } // ignore unnnamed type values if (clrName.Contains("<unnamed-type-value>")) { continue; } // ignore anonymous if (clrName.StartsWith("<")) { Console.WriteLine("Inspect: " + clrName); } Execute.WithExceptionCallback( () => { var ts = AnalyzeTypeElement(te); _cbTypeShape(ts); }, e => { Console.WriteLine("error: " + e.Message); Console.WriteLine(te); }); } }
public static JetBrains.UI.RichText.RichText ProcessCRef(string crefValue, PsiLanguageType languageType, IPsiModule psiModule, DeclaredElementPresenterStyle presenterStyle) { var element = psiModule == null ? null : XMLDocUtil.ResolveId(psiModule.GetPsiServices(), crefValue, psiModule, true); return(element == null || !element.IsValid() ? new JetBrains.UI.RichText.RichText(XmlDocPresenterUtil.ProcessCref(crefValue), XmlDocRichTextPresenterEx.ourCRefStyle) : DeclaredElementPresenter.Format(languageType, presenterStyle, element)); }