コード例 #1
0
ファイル: StyleCopSettings.cs プロジェクト: icnocop/StyleCop
        /// <summary>
        /// Searches directories of the project items project file and the parents thereof to see 
        /// if a Settings file exists.
        /// </summary>
        /// <param name="projectItem">
        /// File being examined.
        /// </param>
        /// <returns>
        /// Path to the settings file.
        /// </returns>
        public string FindSettingsFilePath(IProjectItem projectItem)
        {
            StyleCopTrace.In(projectItem);

            string cacheKey = string.Format("{0}::{1}", "FindSettingsFilePath", projectItem.Location.FullPath.ToLowerInvariant());

            string settings;

            if (StringCache.TryGetValue(cacheKey, out settings))
            {
                StyleCopTrace.Out();

                return settings;
            }

            IProject projectFile = projectItem.GetProject();

            string result = this.FindSettingsFilePath(projectFile);

            // TODO: This is adding a watcher for settings.stylecop in the folder of the source file
            // This is creating a watcher for *ALL* source files that are monitored!
            this.AddWatcherForSettingsFile(projectItem.Location.FullPath);
            StringCache[cacheKey] = result;

            return StyleCopTrace.Out(result);
        }
コード例 #2
0
        /// <summary>
        /// Searches directories of the project items project file and the parents thereof to see
        /// if a Settings file exists.
        /// </summary>
        /// <param name="projectItem">
        /// File being examined.
        /// </param>
        /// <returns>
        /// Path to the settings file.
        /// </returns>
        private string FindSettingsFilePath(IProjectItem projectItem)
        {
            StyleCopTrace.In(projectItem);

            string cacheKey = projectItem.Location.FullPath.ToLowerInvariant();

            string settings;

            if (this.settingsFilePathForProjectFile.TryGetValue(cacheKey, out settings))
            {
                StyleCopTrace.Out();

                return(settings);
            }

            IProject projectFile = projectItem.GetProject();

            string result = this.FindSettingsFilePath(projectFile);

            // TODO: This makes no sense
            // We cache, per source file location, the location of the settings.stylecop file.
            // We only look for the settings.stylecop file at the project root folder and above.
            // But we add a file watcher at the source file location
            // this.AddWatcherForSettingsFile(projectItem.Location.FullPath);
            this.settingsFilePathForProjectFile[cacheKey] = result;

            return(StyleCopTrace.Out(result));
        }
コード例 #3
0
        public IList <IProjectItem> GetSharedProjectItemsInReferencedProjects(IProjectItem projectItem)
        {
            var project       = projectItem.GetProject().NotNull();
            var playerProject = mySolution
                                .GetProjectsByName(project.Name + PlayerProjectSuffix)
                                .SingleItem();

            if (playerProject == null)
            {
                return(EmptyList <IProjectItem> .InstanceList);
            }

            return(playerProject.FindProjectItemsByLocation(projectItem.Location).ToList());
        }
コード例 #4
0
        public ExpectedNamespaceAndNamespaceChecker CalculateCustomNamespace(IProjectItem projectItem, PsiLanguageType language)
        {
            var project = projectItem.GetProject().NotNull();

            if (!ShouldProvideCustomNamespace(project, projectItem, language))
            {
                return(new ExpectedNamespaceAndNamespaceChecker(null));
            }

            var namespaceFolderProperty = project.GetComponent <NamespaceFolderProperty>();

            return(new ExpectedNamespaceAndNamespaceChecker(CalculateNamespace(projectItem, language.LanguageService(),
                                                                               namespaceFolderProperty)));
        }
コード例 #5
0
        private static string CalculateNamespace([NotNull] IProjectItem item, LanguageService languageService,
                                                 NamespaceFolderProperty namespaceFolderProperty)
        {
            if (item.ParentFolder is IProject && item is IProjectFolder rootFolder)
            {
                return(CalculateNamespaceForProjectFromRootFolder(item.GetProject(), rootFolder, languageService));
            }

            var parentFolder = item.ParentFolder;

            if (parentFolder == null)
            {
                return(null);
            }

            var parentNamespace = CalculateNamespace(parentFolder, languageService, namespaceFolderProperty);

            if (parentNamespace == null)
            {
                return(null);
            }

            if (item is IProjectFolder folder)
            {
                var isNamespaceProvider = namespaceFolderProperty.GetNamespaceFolderProperty(folder);
                if (!isNamespaceProvider)
                {
                    return(parentNamespace);
                }
            }

            if (item is IProjectFile)
            {
                return(parentNamespace);
            }

            var suffix = NamespaceFolderUtil.MakeValidQualifiedName(item.Name, languageService);

            if (parentNamespace.Length > 0)
            {
                if (string.IsNullOrEmpty(suffix))
                {
                    return(parentNamespace);
                }
                return($"{parentNamespace}.{suffix}");
            }

            return(suffix);
        }
コード例 #6
0
        private static IProject GetProject([NotNull] ISymbolInfo info)
        {
            IPathDeclaredElement pathDeclaredElement = GetPathDeclaredElement(info);

            if (pathDeclaredElement == null)
            {
                return(null);
            }
            IProjectItem projectItem = pathDeclaredElement.GetProjectItem();

            if (projectItem == null)
            {
                return(null);
            }
            return(projectItem.GetProject());
        }
コード例 #7
0
ファイル: NancyUtil.cs プロジェクト: pil0t/Nancy.ReSharper
        public static FileSystemPath GetAreaFolder([CanBeNull] IProjectItem projectItem)
        {
            if (projectItem == null)
            {
                return(FileSystemPath.Empty);
            }
            IProjectFolder areasFolder = GetAreasFolder(projectItem.GetProject());

            if (areasFolder == null)
            {
                return(FileSystemPath.Empty);
            }
            return(areasFolder.GetSubItems()
                   .OfType <IProjectFolder>()
                   .Select(_ => _.Location)
                   .Where(area => area.IsPrefixOf(projectItem.Location))
                   .DefaultIfEmpty(areasFolder.Location)
                   .First());
        }
コード例 #8
0
        public IList <IProjectItem> GetProjectItemInSharedProjects(IProjectItem projectItem)
        {
            var playerProject = projectItem.GetProject().NotNull();

            if (!playerProject.Name.EndsWith(PlayerProjectSuffix)) // todo: check that define `UNITY_EDITOR` is not be present
            {
                return(EmptyList <IProjectItem> .InstanceList);
            }

            var originalProject = mySolution
                                  .GetProjectsByName(playerProject.Name.RemoveEnd(PlayerProjectSuffix))
                                  .SingleItem();

            if (originalProject == null)
            {
                return(EmptyList <IProjectItem> .InstanceList);
            }

            return(originalProject.FindProjectItemsByLocation(projectItem.Location).ToList());
        }
コード例 #9
0
        /// <summary>
        /// Searches directories of the project items project file and the parents thereof to see
        /// if a Settings file exists.
        /// </summary>
        /// <param name="projectItem">
        /// File being examined.
        /// </param>
        /// <returns>
        /// Path to the settings file.
        /// </returns>
        public string FindSettingsFilePath(IProjectItem projectItem)
        {
            StyleCopTrace.In(projectItem);

            string cacheKey = string.Format("{0}::{1}", "FindSettingsFilePath", projectItem.Location.FullPath.ToLowerInvariant());

            string settings;

            if (StringCache.TryGetValue(cacheKey, out settings))
            {
                StyleCopTrace.Out();

                return(settings);
            }

            IProject projectFile = projectItem.GetProject();

            string result = this.FindSettingsFilePath(projectFile);

            StringCache[cacheKey] = result;

            return(StyleCopTrace.Out(result));
        }
コード例 #10
0
        /// <summary>
        /// Searches directories of the project items project file and the parents thereof to see if a Settings file exists.
        /// </summary>
        /// <param name="projectItem">
        /// File being examined. 
        /// </param>
        /// <returns>
        /// Path to the settings file. 
        /// </returns>
        public string FindSettingsFilePath(IProjectItem projectItem)
        {
            StyleCopTrace.In(projectItem);

            string cacheKey = string.Format("{0}::{1}", "FindSettingsFilePath", projectItem.Location.FullPath.ToLowerInvariant());

            string settings;

            if (StringCache.TryGetValue(cacheKey, out settings))
            {
                StyleCopTrace.Out();

                return settings;
            }

            IProject projectFile = projectItem.GetProject();

            string result = this.FindSettingsFilePath(projectFile);

            StringCache[cacheKey] = result;

            return StyleCopTrace.Out(result);
        }
コード例 #11
0
        /// <summary>
        /// Searches directories of the project items project file and the parents thereof to see 
        /// if a Settings file exists.
        /// </summary>
        /// <param name="projectItem">
        /// File being examined.
        /// </param>
        /// <returns>
        /// Path to the settings file.
        /// </returns>
        private string FindSettingsFilePath(IProjectItem projectItem)
        {
            StyleCopTrace.In(projectItem);

            string cacheKey = projectItem.Location.FullPath.ToLowerInvariant();

            string settings;

            if (this.settingsFilePathForProjectFile.TryGetValue(cacheKey, out settings))
            {
                StyleCopTrace.Out();

                return settings;
            }

            IProject projectFile = projectItem.GetProject();

            string result = this.FindSettingsFilePath(projectFile);

            // TODO: This makes no sense
            // We cache, per source file location, the location of the settings.stylecop file.
            // We only look for the settings.stylecop file at the project root folder and above.
            // But we add a file watcher at the source file location
            // this.AddWatcherForSettingsFile(projectItem.Location.FullPath);
            this.settingsFilePathForProjectFile[cacheKey] = result;

            return StyleCopTrace.Out(result);
        }