public RichTextBlock GetElementDescription(IDeclaredElement element, DeclaredElementDescriptionStyle style, PsiLanguageType language, IPsiModule module = null) { if (!element.IsFromUnityProject()) return null; var method = element as IMethod; if (method != null) { var eventFunction = myUnityApi.GetUnityEventFunction(method); if (eventFunction?.Description != null) return new RichTextBlock(eventFunction.Description); } var parameter = element as IParameter; var owner = parameter?.ContainingParametersOwner as IMethod; if (owner != null) { var eventFunction = myUnityApi.GetUnityEventFunction(owner); var eventFunctionParameter = eventFunction?.GetParameter(parameter.ShortName); if (eventFunctionParameter?.Description != null) return new RichTextBlock(eventFunctionParameter.Description); } return null; }
protected override bool CanBeAnnotated(IDeclaredElement declaredElement, ITreeNode context, IPsiModule module) { var method = declaredElement as IMethod; if (method != null && IsAvailableForType(method.ReturnType, context)) { return true; } var parameter = declaredElement as IParameter; if (parameter != null && IsAvailableForType(parameter.Type, context)) { return true; } var property = declaredElement as IProperty; if (property != null && IsAvailableForType(property.Type, context)) { return true; } var delegateType = declaredElement as IDelegate; if (delegateType != null && IsAvailableForType(delegateType.InvokeMethod.ReturnType, context)) { return true; } var field = declaredElement as IField; if (field != null && IsAvailableForType(field.Type, context)) { return true; } return false; }
private PsiElementFactoryImpl([NotNull] IPsiModule module, [NotNull] ISolution solution) { myModule = module; Solution = solution; Solution.GetPsiServices(); myLanguageService = (PsiLanguageService)PsiLanguage.Instance.LanguageService(); }
private NTriplesElementFactoryImpl([NotNull] IPsiModule module, [NotNull] ISolution solution) { this.myModule = module; this.Solution = solution; this.Solution.GetPsiServices(); this.myLanguageService = (NTriplesLanguageService)NTriplesLanguage.Instance.LanguageService(); }
public T4OutsideSolutionSourceFile(IProjectFileExtensions projectFileExtensions, PsiProjectFileTypeCoordinator projectFileTypeCoordinator, IPsiModule module, FileSystemPath path, Func<PsiSourceFileFromPath, bool> validityCheck, Func<PsiSourceFileFromPath, IPsiSourceFileProperties> propertiesFactory, DocumentManager documentManager, IModuleReferenceResolveContext resolveContext) : base(projectFileExtensions, projectFileTypeCoordinator, module, path, validityCheck, propertiesFactory, documentManager, resolveContext) { }
// This is the ReSharper 8.1 version public RichTextBlock GetElementDescription(IDeclaredElement element, DeclaredElementDescriptionStyle style, PsiLanguageType language, IPsiModule module) { var attribute = element as IHtmlAttributeDeclaredElement; if (attribute == null) return null; var attributeDescription = GetAttributeDescription(attribute.ShortName); var block = new RichTextBlock(); var typeDescription = new RichText(htmlDescriptionsCache.GetDescriptionForHtmlValueType(attribute.ValueType)); if (style.IntendedDescriptionPlacement == DescriptionPlacement.AFTER_NAME && (style.ShowSummary || style.ShowFullDescription)) block.SplitAndAdd(typeDescription); string description = null; if (style.ShowSummary && attributeDescription != null) description = attributeDescription.Summary; else if (style.ShowFullDescription && attributeDescription != null) description = attributeDescription.Description; if (!string.IsNullOrEmpty(description)) block.SplitAndAdd(description); if (style.IntendedDescriptionPlacement == DescriptionPlacement.ON_THE_NEW_LINE && (style.ShowSummary || style.ShowFullDescription)) { // TODO: Perhaps we should show Value: Expression for attributes that take an Angular expression, etc typeDescription.Prepend("Value: "); block.SplitAndAdd(typeDescription); } return block; }
public static IDeclaredType CreateTypeByCLRName(string typeName, IPsiModule psiModule, IModuleReferenceResolveContext moduleReferenceResolveContext) { #if R10 return TypeFactory.CreateTypeByCLRName(typeName, psiModule); #else return TypeFactory.CreateTypeByCLRName(typeName, psiModule, moduleReferenceResolveContext); #endif }
internal static ConstantValue CreateStringValue(string p, IPsiModule psiModule, UniversalModuleReferenceContext universalModuleReferenceContext) { #if R10 return ClrConstantValueFactory.CreateStringValue(p, psiModule); #else return ClrConstantValueFactory.CreateStringValue(p, psiModule, universalModuleReferenceContext); #endif }
public bool CanReferenceModule(IPsiModule module, IPsiModule moduleToReference) { var t4PsiModule = module as T4PsiModule; if (t4PsiModule == null || !t4PsiModule.IsValid() || moduleToReference == null) return false; var assembly = moduleToReference.ContainingProjectModule as IAssembly; return assembly != null && assembly.PlatformID != null && assembly.PlatformID.Identifier == _environment.PlatformID.Identifier; }
protected override bool CanBeAnnotated(IDeclaredElement declaredElement, ITreeNode context, IPsiModule module) { var method = declaredElement as IMethod; return method != null && (!method.ReturnType.IsVoid() || method.Parameters.Any(parameter => parameter.AssertNotNull().Kind == ParameterKind.OUTPUT)) && method.Parameters.All(parameter => parameter.AssertNotNull().Kind != ParameterKind.REFERENCE); }
public T4OutsideSolutionSourceFileManager([NotNull] Lifetime lifetime, [NotNull] IProjectFileExtensions projectFileExtensions, [NotNull] PsiProjectFileTypeCoordinator psiProjectFileTypeCoordinator, [NotNull] DocumentManager documentManager, [NotNull] ISolution solution) { _projectFileExtensions = projectFileExtensions; _psiProjectFileTypeCoordinator = psiProjectFileTypeCoordinator; _documentManager = documentManager; _psiModule = new PsiModuleOnFileSystemPaths(solution, "T4OutsideSolution", TargetFrameworkId.Default); lifetime.AddDispose(_sourceFiles); }
protected ContextActionExecutorBase(ICSharpStatement statement) { Contract.Requires(statement != null); _psiModule = statement.GetPsiModule(); _psiServices = statement.GetPsiServices(); _factory = CSharpElementFactory.GetInstance(statement); _currentFile = (ICSharpFile)statement.GetContainingFile(); }
protected override bool CanBeAnnotated(IDeclaredElement declaredElement, ITreeNode context, IPsiModule module) { var parameter = declaredElement as IParameter; return parameter != null && (parameter.Type.IsGenericIEnumerable() || parameter.Type.IsImplicitlyConvertibleTo( new DeclaredTypeFromCLRName(PredefinedType.MULTICAST_DELEGATE_FQN, module), context.GetTypeConversionRule())); }
public PropertyConverter(CSharpElementFactory factory, IPsiModule psiModule, IClassDeclaration classDeclaration) { Argument.IsNotNull(() => factory); Argument.IsNotNull(() => psiModule); Argument.IsNotNull(() => classDeclaration); _factory = factory; _psiModule = psiModule; _classDeclaration = classDeclaration; }
protected override bool CanBeAnnotated(IDeclaredElement declaredElement, ITreeNode context, IPsiModule module) { var method = declaredElement as IMethod; if (method != null) { return method.ReturnType.IsGenericIEnumerable() && method.Parameters.Any(p => p.AssertNotNull().Type.IsGenericIEnumerable()); } return false; }
public static UnityColorTypes GetInstance(IPsiModule module) { var unityColorTypes = module.GetData(ourColorTypesKey); if (unityColorTypes == null) { unityColorTypes = new UnityColorTypes(module); module.PutData(ourColorTypesKey, unityColorTypes); } return unityColorTypes; }
public static bool TryGetTypeElement(string typeName, IPsiModule psiModule, IModuleReferenceResolveContext moduleReferenceResolveContext, out ITypeElement typeElement) { typeElement = null; var typeByClrName = CreateTypeByCLRName(typeName, psiModule, moduleReferenceResolveContext); if (typeByClrName != null) { typeElement = typeByClrName.GetTypeElement(); } return typeElement != null; }
private void InvalidateReferencingModules(IPsiModule psiModule) { using (CompilationContextCookie.GetOrCreate(psiModule.GetContextFromModule())) { var resolveContext = CompilationContextCookie.GetContext(); foreach (var psiModuleReference in PsiModules.GetReverseModuleReferences(psiModule, resolveContext)) { if (myPsiModules.TryGetValue(psiModuleReference.Module, out var moduleSymbols)) { moduleSymbols.Invalidate(); } } } }
public bool CanReferenceModule(IPsiModule module, IPsiModule moduleToReference) { if (!IsProjectModule(module) || !IsAssemblyModule(moduleToReference)) return false; Logger.LogMessage(LoggingLevel.VERBOSE, "[NUGET PLUGIN] Checking if module '{0}' is a nuget package", moduleToReference.DisplayName); var assemblyLocations = GetAllAssemblyLocations(moduleToReference); var canReference = module.GetSolution().GetComponent<NuGetApi>().AreAnyAssemblyFilesNuGetPackages(assemblyLocations); Logger.LogMessage(LoggingLevel.VERBOSE, "[NUGET PLUGIN] Module '{0}' is {1}a nuget package", moduleToReference.DisplayName, canReference ? string.Empty : "NOT "); return canReference; }
public IEnumerable <SpecflowStepInfo> GetStepAccessibleForModule(IPsiModule module, GherkinStepKind stepKind) { foreach (var(stepSourceFile, stepDefinitions) in _mergeData.StepsDefinitionsPerFiles) { if (!ReferenceEquals(module, stepSourceFile.PsiModule) && !module.References(stepSourceFile.PsiModule)) { continue; } foreach (var stepDefinitionInfo in stepDefinitions.Where(s => s.StepKind == stepKind)) { yield return(stepDefinitionInfo); } } }
protected ContextActionExecutorBase(ICSharpContextActionDataProvider provider) { Contract.Requires(provider != null); _factory = provider.ElementFactory; Contract.Assert(provider.SelectedElement != null, "Can't create executor if SelectedElement is null"); _currentFile = (ICSharpFile)provider.SelectedElement.GetContainingFile(); _psiServices = provider.PsiServices; _psiModule = provider.PsiModule; }
private ISymbolTable GetReferenceSymbolTable(ISolution solution, IPsiModule psiModule, AssetMethodData assetMethodData, string assetGuid) { var targetType = AssetUtils.GetTypeElementFromScriptAssetGuid(solution, assetGuid); if (targetType == null) { return(EmptySymbolTable.INSTANCE); } var symbolTable = ResolveUtil.GetSymbolTableByTypeElement(targetType, SymbolTableMode.FULL, psiModule); return(symbolTable.Filter(assetMethodData.MethodName, IsMethodFilter.INSTANCE, OverriddenFilter.INSTANCE, new ExactNameFilter(assetMethodData.MethodName), new StaticFilter(new NonStaticAccessContext(null)), new EventHandlerSymbolFilter(assetMethodData.Mode, assetMethodData.Type, targetType.Module))); }
public void Execute(Action <DaemonStageResult> action) { var consumer = new DefaultHighlightingConsumer(this, _settingsStore); IPsiModule module = _file.GetPsiModule(); ResXSettings settings = _settingsStore.GetKey <ResXSettings>(SettingsOptimization.OptimizeDefault); IAttributesSet moduleAttributes = _file.GetSolution().GetPsiServices().Symbols.GetModuleAttributes(module); string defaultResXDic = "en-US"; IList <IAttributeInstance> attributes = moduleAttributes .GetAttributeInstances(new ClrTypeName(typeof(NeutralResourcesLanguageAttribute).FullName), false); if (attributes != null && attributes.Count > 0 && attributes[0].PositionParameter(0).ConstantValue.Value != null) { defaultResXDic = attributes[0].PositionParameter(0).ConstantValue.Value.ToString(); } ISpellChecker checker = SpellCheckManager.GetSpellChecker(_settingsStore, _file, defaultResXDic); if (checker != null) { foreach (IXmlToken token in getStringsToCheck()) { WordLexer lexer = new WordLexer(token.GetText()); lexer.Start(); while (lexer.TokenType != null) { if (SpellCheckUtil.ShouldSpellCheck(lexer.TokenText, settings.CompiledWordsToIgnore) && !checker.TestWord(lexer.TokenText, false)) { DocumentRange docRange = token.GetDocumentRange(); TextRange textRange = new TextRange(docRange.TextRange.StartOffset + lexer.TokenStart, docRange.TextRange.StartOffset + lexer.TokenEnd); DocumentRange range = new DocumentRange(docRange.Document, textRange); ResXSpellHighlighting highlighting = new ResXSpellHighlighting(lexer.TokenText, _file, checker, range, _settingsStore); consumer.AddHighlighting(highlighting, range); } lexer.Advance(); } } } action(new DaemonStageResult(consumer.Highlightings)); }
public UnityYamlAssetPsiSourceFile([NotNull] IProjectFile projectFile, [NotNull] IProjectFileExtensions projectFileExtensions, [NotNull] PsiProjectFileTypeCoordinator projectFileTypeCoordinator, [NotNull] IPsiModule module, FileSystemPath path, [NotNull] Func <PsiSourceFileFromPath, IPsiSourceFileProperties> propertiesFactory, [NotNull] DocumentManager documentManager, [NotNull] IModuleReferenceResolveContext resolveContext) : base(projectFileExtensions, projectFileTypeCoordinator, module, path, JetFunc <PsiSourceFileFromPath> .True, propertiesFactory, documentManager, resolveContext) { #if RIDER ProjectFile = projectFile; #endif }
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)); }
public static Pair<ITypeElement, ITypeMember>? PropertyFromColorElement(ITypeElement qualifierType, IColorElement colorElement, IPsiModule module) { var colorName = UnityNamedColors.GetColorName(colorElement.RGBColor); if (string.IsNullOrEmpty(colorName)) return null; var unityColorType = GetInstance(module).UnityColorType; if (unityColorType == null || !unityColorType.Equals(qualifierType)) return null; var colorProperties = GetStaticColorProperties(unityColorType); var propertyTypeMember = colorProperties.FirstOrDefault(p => p.ShortName == colorName); if (propertyTypeMember == null) return null; return Pair.Of(unityColorType, propertyTypeMember); }
public T4OutsideSolutionSourceFileManager( [NotNull] Lifetime lifetime, [NotNull] IProjectFileExtensions projectFileExtensions, [NotNull] PsiProjectFileTypeCoordinator psiProjectFileTypeCoordinator, [NotNull] DocumentManager documentManager, [NotNull] ISolution solution, [NotNull] T4Environment t4Environment, [NotNull] IFileSystemTracker fileSystemTracker) { _projectFileExtensions = projectFileExtensions; _psiProjectFileTypeCoordinator = psiProjectFileTypeCoordinator; _documentManager = documentManager; _psiModule = new PsiModuleOnFileSystemPaths(solution, "T4OutsideSolution", t4Environment.TargetFrameworkId, fileSystemTracker, lifetime); lifetime.AddDispose(_sourceFiles); }
/// <summary> /// Swap object creation to built in type. /// </summary> /// <param name="objectCreationExpressionNode"> /// The object creation expression node. /// </param> private static void SwapObjectCreationToBuiltInType(IObjectCreationExpression objectCreationExpressionNode) { IPsiModule project = objectCreationExpressionNode.GetPsiModule(); using (WriteLockCookie.Create(true)) { IObjectCreationExpression tmpExpression = (IObjectCreationExpression) CSharpElementFactory.GetInstance(project).CreateExpression("new $0?()", new object[] { objectCreationExpressionNode.Type() }); if (tmpExpression != null) { objectCreationExpressionNode.SetCreatedTypeUsage(tmpExpression.CreatedTypeUsage); } } }
public AddAttributeAction(IMultipleFieldDeclaration multipleFieldDeclaration, [CanBeNull] IFieldDeclaration selectedFieldDeclaration, IClrTypeName attributeTypeName, [NotNull] AttributeValue[] attributeValues, bool isLayoutAttribute, IPsiModule module, CSharpElementFactory elementFactory) { myMultipleFieldDeclaration = multipleFieldDeclaration; mySelectedFieldDeclaration = selectedFieldDeclaration; myAttributeTypeName = attributeTypeName; myAttributeValues = attributeValues; myIsLayoutAttribute = isLayoutAttribute; myModule = module; myElementFactory = elementFactory; }
public static IType GetType([NotNull] FSharpType fsType, [NotNull] ITypeMemberDeclaration methodDeclaration, [NotNull] IList <ITypeParameter> methodTypeParams, [NotNull] IPsiModule psiModule, bool isFromReturn) { var typeParametersFromType = GetOuterTypeParameters(methodDeclaration); var typeParamsFromContext = typeParametersFromType.Prepend(methodTypeParams).ToIList(); try { return(GetType(fsType, typeParamsFromContext, psiModule, true, isFromReturn)); } catch (ErrorLogger.UnresolvedPathReferenceNoRange) { return(TypeFactory.CreateUnknownType(psiModule)); } }
public T4PsiProjectFile( [NotNull] IPsiModule psiModule, [NotNull] IProjectFile projectFile, [NotNull] Func <IProjectFile, IPsiSourceFile, IPsiSourceFileProperties> propertiesProvider, [NotNull] Func <IProjectFile, IPsiSourceFile, bool> validityChecks, DocumentManager documentManager, [NotNull] IModuleReferenceResolveContext resolveContext ) : base(psiModule, projectFile, propertiesProvider, validityChecks, documentManager, resolveContext ) { }
public override IParser CreateParser(ILexer lexer, IPsiModule module, IPsiSourceFile sourceFile) { if (sourceFile == null) { Logger.Warn("Creating parser for null sourceFile"); return(new T4Parser(lexer, null, null)); } var projectFile = sourceFile.ToProjectFile(); var solution = sourceFile.GetSolution(); var graph = solution.GetComponent <IT4FileDependencyGraph>(); var rootSourceFile = graph.FindBestRoot(projectFile).ToSourceFile().NotNull(); var rootLexer = GetPrimaryLexerFactory().CreateLexer(rootSourceFile.Document.Buffer); return(new T4Parser(rootLexer, rootSourceFile, sourceFile)); }
public override IParser CreateParser(ILexer lexer, IPsiModule module, IPsiSourceFile sourceFile) { if (sourceFile == null) { Logger.Warn("Creating parser for null sourceFile"); return(new T4Parser(lexer, null, null, T4DocumentLexerSelector.Instance)); } var solution = sourceFile.GetSolution(); var graph = solution.GetComponent <IT4FileDependencyGraph>(); var rootSourceFile = graph.FindBestRoot(sourceFile).NotNull(); var selector = new T4DelegatingLexerSelector(lexer, sourceFile, T4DocumentLexerSelector.Instance); var rootLexer = selector.SelectLexer(rootSourceFile); return(new T4Parser(rootLexer, rootSourceFile, sourceFile, selector)); }
public static void AddAttribute([CanBeNull] IFieldDeclaration fieldDeclaration, IClrTypeName attributeTypeName, IPsiModule psiModule, CSharpElementFactory elementFactory) { if (fieldDeclaration == null) { return; } var typeElement = TypeFactory.CreateTypeByCLRName(attributeTypeName, psiModule).GetTypeElement(); if (typeElement != null) { var attribute = elementFactory.CreateAttribute(typeElement); fieldDeclaration.AddAttributeAfter(attribute, null); } }
internal bool CanReferenceModule([NotNull] IPsiModule module, [CanBeNull] IPsiModule moduleToReference) { if (!IsProjectModule(module) || !IsAssemblyModule(moduleToReference)) { return(false); } return(true); /* * //Logger.LogMessage(LoggingLevel.VERBOSE, "[PAKET PLUGIN] Checking if module '{0}' is a paket package", moduleToReference.DisplayName); * var assemblyLocations = GetAllAssemblyLocations(moduleToReference); * var canReference = module.GetSolution().GetComponent<PaketApi>().AreAnyAssemblyFilesPaketPackages(assemblyLocations); * //Logger.LogMessage(LoggingLevel.VERBOSE, "[PAKET PLUGIN] Module '{0}' is {1}a paket package", moduleToReference.DisplayName, canReference ? string.Empty : "NOT "); * return canReference; */ }
// This is the ReSharper 8.1 version public RichTextBlock GetElementDescription(IDeclaredElement element, DeclaredElementDescriptionStyle style, PsiLanguageType language, IPsiModule module) { var attribute = element as IHtmlAttributeDeclaredElement; if (attribute == null) { return(null); } var attributeDescription = GetAttributeDescription(attribute.ShortName); var block = new RichTextBlock(); var typeDescription = new RichText(htmlDescriptionsCache.GetDescriptionForHtmlValueType(attribute.ValueType)); if (style.IntendedDescriptionPlacement == DescriptionPlacement.AFTER_NAME && (style.ShowSummary || style.ShowFullDescription)) { block.SplitAndAdd(typeDescription); } string description = null; if (style.ShowSummary && attributeDescription != null) { description = attributeDescription.Summary; } else if (style.ShowFullDescription && attributeDescription != null) { description = attributeDescription.Description; } if (!string.IsNullOrEmpty(description)) { block.SplitAndAdd(description); } if (style.IntendedDescriptionPlacement == DescriptionPlacement.ON_THE_NEW_LINE && (style.ShowSummary || style.ShowFullDescription)) { // TODO: Perhaps we should show Value: Expression for attributes that take an Angular expression, etc typeDescription.Prepend("Value: "); block.SplitAndAdd(typeDescription); } return(block); }
private RichText TryGetDescription( [NotNull] IDeclaredElement element, [CanBeNull] XmlNode xmlDoc, [NotNull] IPsiModule psiModule, [NotNull] PsiLanguageType languageType) { RichText richText = TryPresentDocNode(xmlDoc, "summary", languageType, psiModule); if (richText != null) { return(richText); } return(_declaredElementDescriptionPresenter .GetDeclaredElementDescription(element, DeclaredElementDescriptionStyle.NO_OBSOLETE_SUMMARY_STYLE, languageType, psiModule) ?.RichText); }
private BulbActionBase GetActionToExtractAndApplyToSingleField( IMultipleFieldDeclaration multipleFieldDeclaration, IFieldDeclaration selectedFieldDeclaration, IPsiModule module, CSharpElementFactory elementFactory, IAttribute existingAttribute) { if (existingAttribute != null) { return(new RemoveAttributeAction(multipleFieldDeclaration, selectedFieldDeclaration, existingAttribute)); } var attributeValues = GetAttributeValues(module, selectedFieldDeclaration); return(new AddAttributeAction(multipleFieldDeclaration, selectedFieldDeclaration, AttributeTypeName, attributeValues, IsLayoutAttribute, module, elementFactory)); }
private IAttribute CreateFormerlySerializedAsAttribute(IPsiModule module) { var elementFactory = CSharpElementFactory.GetInstance(module); var attributeType = TypeFactory.CreateTypeByCLRName(KnownTypes.FormerlySerializedAsAttribute, module); var attributeTypeElement = attributeType.GetTypeElement(); if (attributeTypeElement == null) { return(null); } return(elementFactory.CreateAttribute(attributeTypeElement, new[] { new AttributeValue(new ConstantValue(OldName, module)) }, EmptyArray <Pair <string, AttributeValue> > .Instance)); }
public T4OutsideSolutionSourceFileManager( Lifetime lifetime, [NotNull] IProjectFileExtensions projectFileExtensions, [NotNull] PsiProjectFileTypeCoordinator psiProjectFileTypeCoordinator, [NotNull] DocumentManager documentManager, [NotNull] ISolution solution, [NotNull] T4Environment t4Environment, [NotNull] IFileSystemTracker fileSystemTracker ) { _projectFileExtensions = projectFileExtensions; _psiProjectFileTypeCoordinator = psiProjectFileTypeCoordinator; _documentManager = documentManager; _sourceFiles = new StrongToWeakDictionary <FileSystemPath, IPsiSourceFile>(lifetime); _psiModule = new PsiModuleOnFileSystemPaths(solution, "T4OutsideSolution", Guid.NewGuid().ToString(), t4Environment.TargetFrameworkId, fileSystemTracker, lifetime); lifetime.OnTermination(_sourceFiles); }
public IDeclaredType GetByClrTypeName(IClrTypeName typeName, IPsiModule module) { var type = module.GetPredefinedType().TryGetType(typeName, NullableAnnotation.Unknown); if (type != null) { return(type); } // Make sure the type is still valid before handing it out. It might be invalid if the module used to create // it has been changed type = myTypes.AddOrUpdate(typeName, name => TypeFactory.CreateTypeByCLRName(name, module), (name, existingValue) => existingValue.Module.IsValid() ? existingValue : TypeFactory.CreateTypeByCLRName(name, module)); return(type); }
private static IList<FileSystemPath> GetAllAssemblyLocations(IPsiModule psiModule) { var projectModelAssembly = psiModule.ContainingProjectModule as IAssembly; if (projectModelAssembly == null) return EmptyList<FileSystemPath>.InstanceList; // ReSharper maintains a list of unique assemblies, and each assembly keeps a track of // all of the file copies of itself that the solution knows about. This list of file // locations includes sources for references (including NuGet packages), but can also // include outputs, e.g. if CopyLocal is set to True. The IAssemblyPsiModule.Assembly.Location // returns back the file location of the first copy of the assembly, but the order of // the list is undefined - it is entirely possible to get back a file location in a bin\Debug // folder. This doesn't help us when trying to add NuGet references - we need to look // at all of the locations to try and find the NuGet package location. So we use the // ProjectModel instead of the PSI, and get all file locations of the IAssembly return projectModelAssembly.GetFiles().Select(f => f.Location).ToList(); }
private static RichText TryPresentDocNode( [CanBeNull] XmlNode xmlDoc, [NotNull] string nodeName, [NotNull] PsiLanguageType languageType, [NotNull] IPsiModule psiModule) { XmlNode returnsNode = xmlDoc?.SelectSingleNode(nodeName); if (returnsNode == null || !returnsNode.HasChildNodes) { return(null); } var richText = XmlDocRichTextPresenter.Run(returnsNode, false, languageType, psiModule).RichText; return(richText.IsNullOrEmpty() ? null : richText); }
private static IFSharpDeclaration GetActivePatternDeclaration([NotNull] FSharpActivePatternCase activePatternCase, [NotNull] IPsiModule psiModule, IFSharpReferenceOwner referenceOwnerToken) { var activePattern = activePatternCase.Group; var declaringEntity = activePattern.DeclaringEntity?.Value; if (declaringEntity != null) { var patternName = activePattern.PatternName(); var typeElement = GetTypeElement(declaringEntity, psiModule); var patternElement = typeElement.EnumerateMembers(patternName, true).FirstOrDefault(); return(patternElement?.GetDeclarations().FirstOrDefault() as IFSharpDeclaration); } var patternId = FindNode <IActivePatternId>(activePatternCase.DeclarationLocation, referenceOwnerToken); return(patternId?.GetContainingNode <IFSharpDeclaration>()); }
private IdentifierTooltipContent TryPresentColorized([NotNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings) { PsiLanguageType languageType = info.File.Language; IDeclaredElement element = info.DeclaredElement; IPsiModule psiModule = info.File.GetPsiModule(); RichText identifierText = _colorizerPresenter.TryPresent( new DeclaredElementInstance(element, info.Substitution), PresenterOptions.ForToolTip(settings), languageType, settings.GetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled)); if (identifierText == null || identifierText.IsEmpty) { return(null); } var identifierContent = new IdentifierTooltipContent(identifierText, info.SourceRange) { Description = TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.NO_OBSOLETE_SUMMARY_STYLE), }; if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon)) { identifierContent.Icon = TryGetIcon(element); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowObsolete)) { identifierContent.Obsolete = TryRemoveObsoletePrefix(TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.OBSOLETE_DESCRIPTION)); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowExceptions)) { identifierContent.Exceptions.AddRange(GetExceptions(element, languageType, psiModule, info.File.GetResolveContext())); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowOverloadCount)) { identifierContent.OverloadCount = TryGetOverloadCountCount(element as IFunction, info.Reference, languageType); } return(identifierContent); }
private BulbActionBase GetActionToApplyToEntireFieldDeclaration( IMultipleFieldDeclaration multipleFieldDeclaration, IFieldDeclaration selectedFieldDeclaration, IPsiModule module, CSharpElementFactory elementFactory, IAttribute existingAttribute) { // Don't pass selectedFieldDeclaration to the actions, as we're applying the action to all fields // We only have selectedFieldDeclaration to get default attribute values, and even that's not actually used if (existingAttribute != null) { return(new RemoveAttributeAction(multipleFieldDeclaration, null, existingAttribute)); } var attributeValues = GetAttributeValues(module, selectedFieldDeclaration); return(new AddAttributeAction(multipleFieldDeclaration, null, AttributeTypeName, attributeValues, IsLayoutAttribute, module, elementFactory)); }
private void InvalidateReferencingModules(IPsiModule psiModule) { if (PsiModulesCaches.IsEmpty()) { return; } // todo: reuse FcsProjectProvider references using (CompilationContextCookie.GetOrCreate(psiModule.GetContextFromModule())) { var resolveContext = CompilationContextCookie.GetContext(); foreach (var psiModuleReference in PsiModules.GetReverseModuleReferences(psiModule, resolveContext)) { if (PsiModulesCaches.TryGetValue(psiModuleReference.Module, out var moduleSymbols)) { moduleSymbols.Invalidate(); } } } }
private static IList <FileSystemPath> GetAllAssemblyLocations(IPsiModule psiModule) { var projectModelAssembly = psiModule.ContainingProjectModule as IAssembly; if (projectModelAssembly == null) { return(EmptyList <FileSystemPath> .InstanceList); } // ReSharper maintains a list of unique assemblies, and each assembly keeps a track of // all of the file copies of itself that the solution knows about. This list of file // locations includes sources for references (including NuGet packages), but can also // include outputs, e.g. if CopyLocal is set to True. The IAssemblyPsiModule.Assembly.Location // returns back the file location of the first copy of the assembly, but the order of // the list is undefined - it is entirely possible to get back a file location in a bin\Debug // folder. This doesn't help us when trying to add NuGet references - we need to look // at all of the locations to try and find the NuGet package location. So we use the // ProjectModel instead of the PSI, and get all file locations of the IAssembly return(projectModelAssembly.GetFiles().Select(f => f.Location).ToList()); }
public IEnumerable <AvailableBindingClass> GetBindingTypes(IPsiModule module) { foreach (var(fullClassName, sourceFile) in _mergeData.SpecflowBindingTypes.SelectMany(e => e.Value.Select(v => (fullClassName: e.Key, sourceFile: v)))) { if (!module.Equals(sourceFile.PsiModule) && !module.References(sourceFile.PsiModule)) { continue; } yield return(new AvailableBindingClass(sourceFile, fullClassName)); } // Since we cannot know when cache are built if a partial class in a given file has an attribute or not. // This is due to the fact that `DeclaredElement` are resolved using cache and we cannot depends ond cache when building a cache. // The check need to be done at this time. foreach (var(fullClassName, sourceFile) in _mergeData.PotentialSpecflowBindingTypes.SelectMany(e => e.Value.Select(v => (fullClassName: e.Key, sourceFile: v)))) { if (!module.Equals(sourceFile.PsiModule) && !module.References(sourceFile.PsiModule)) { continue; } var type = CSharpTypeFactory.CreateType(fullClassName, sourceFile.PsiModule); if (!(type is DeclaredTypeFromCLRName declaredTypeFromClrName)) { continue; } var resolveResult = declaredTypeFromClrName.Resolve(); if (!resolveResult.IsValid()) { continue; } if (!(resolveResult.DeclaredElement is IClass @class)) { continue; } if (@class.GetAttributeInstances(AttributesSource.Self).All(x => x.GetAttributeType().GetClrName().FullName != "TechTalk.SpecFlow.BindingAttribute")) { continue; } yield return(new AvailableBindingClass(sourceFile, fullClassName)); } }
// ReSharper 7.1 public bool ReferenceModule(IPsiModule module, IPsiModule moduleToReference) { if (!IsProjectModule(module) || !IsAssemblyModule(moduleToReference)) { return(false); } var assemblyLocations = GetAllAssemblyLocations(moduleToReference); var projectModule = (IProjectPsiModule)module; string packageLocation; var handled = nuget.InstallNuGetPackageFromAssemblyFiles(assemblyLocations, projectModule.Project, out packageLocation); if (handled) { Hacks.PokeReSharpersAssemblyReferences(module, assemblyLocations, packageLocation, projectModule); Hacks.HandleFailureToReference(packageLocation, textControlManager, shellLocks); } return(handled); }
public T4OutsideSolutionSourceFile( IProjectFileExtensions projectFileExtensions, PsiProjectFileTypeCoordinator projectFileTypeCoordinator, IPsiModule module, FileSystemPath path, Func <PsiSourceFileFromPath, bool> validityCheck, Func <PsiSourceFileFromPath, IPsiSourceFileProperties> propertiesFactory, DocumentManager documentManager, IModuleReferenceResolveContext resolveContext ) : base( projectFileExtensions, projectFileTypeCoordinator, module, path, validityCheck, propertiesFactory, documentManager, resolveContext ) { }
protected sealed override Func<CSharpElementFactory, IAttribute> CreateAttributeFactoryIfAvailable( IAttributesOwnerDeclaration attributesOwnerDeclaration, IPsiModule module, out IAttribute attributeToRemove) { var attributeType = attributesOwnerDeclaration.GetPsiServices() .GetComponent<CodeAnnotationsConfiguration>() .GetAttributeTypeForElement(attributesOwnerDeclaration, AnnotationAttributeTypeName); if (attributeType != null && CanBeAnnotated(attributesOwnerDeclaration.DeclaredElement, attributesOwnerDeclaration, module)) { attributeToRemove = TryGetAttributeToReplace(attributesOwnerDeclaration); return factory => { Debug.Assert(factory != null); return factory.CreateAttribute(attributeType); }; } attributeToRemove = null; return null; }
private static bool CheckSingleType(PredefinedType predefinedType, IPsiModule psiModule, IType type, ITypeConversionRule conversionRule, IType typeInDeclaration) { if (!type.IsGenericOrNonIEnumerable()) { if (!type.IsSubtypeOf(predefinedType.Array)) return true; IDeclaredType scalarType = type.GetScalarType(); return scalarType != null && scalarType.IsImplicitlyConvertibleTo(typeInDeclaration, conversionRule); } IDeclaredType ienumerableOf = CollectionTypeUtil.CreateIEnumerableOf(psiModule, typeInDeclaration); return ienumerableOf == null || type.IsImplicitlyConvertibleTo(ienumerableOf, conversionRule); }
public override IParser CreateParser(ILexer lexer, IPsiModule module, IPsiSourceFile sourceFile) { return new Parser(lexer, sourceFile); }
/// <summary> /// Creates a parser for a given PSI source file. /// </summary> /// <param name="lexer">The lexer that the parser will use.</param> /// <param name="module">The module owning the source file.</param> /// <param name="sourceFile">The source file.</param> /// <returns>A T4 parser that operates onto <paramref name="lexer"/>.</returns> public override IParser CreateParser(ILexer lexer, IPsiModule module, IPsiSourceFile sourceFile) { return new T4Parser(_t4Environment, _directiveInfoManager, lexer, sourceFile); }
public bool ReferenceModuleWithType(IPsiModule module, ITypeElement typeToReference, IModuleReferenceResolveContext resolveContext) { return ReferenceModuleWithType(module, typeToReference); }
public bool CanReferenceModule(IPsiModule module, IPsiModule moduleToReference, IModuleReferenceResolveContext context) { return CanReferenceModule(module, moduleToReference); }
/// <summary> /// Creates an ICSharpArgument for them argument passed in. /// </summary> /// <param name="psiModule"> /// The PsiModule to use. /// </param> /// <param name="argument"> /// The argument to create. /// </param> /// <returns> /// An instance of ICSharpArgument. /// </returns> public static ICSharpArgument CreateConstructorArgumentValueExpression(IPsiModule psiModule, string argument) { CSharpElementFactory factory = CSharpElementFactory.GetInstance(psiModule); return factory.CreateArgument(ParameterKind.VALUE, factory.CreateExpression("$0", new object[] { "\"" + argument + "\"" })); }
public bool ReferenceModule(IPsiModule module, IPsiModule moduleToReference) { return moduleReferencer.ReferenceModule(module, moduleToReference); }
public bool ReferenceModuleWithType(IPsiModule module, ITypeElement typeToReference) { return ReferenceModule(module, typeToReference.Module); }