示例#1
0
        /// <summary>
        /// This method provides a <see cref="IDaemonStageProcess"/> instance which is assigned to highlighting a single document.
        /// </summary>
        /// <param name="process">
        /// Current Daemon Process.
        /// </param>
        /// <param name="settingsStore">
        /// The settingsStore store to use.
        /// </param>
        /// <param name="processKind">
        /// The process kind.
        /// </param>
        /// <param name="file">
        /// The file to analyze.
        /// </param>
        /// ///
        /// <returns>
        /// The current <see cref="IDaemonStageProcess"/>.
        /// </returns>
        protected override IDaemonStageProcess CreateProcess(
            IDaemonProcess process, IContextBoundSettingsStore settingsStore, DaemonProcessKind processKind, ICSharpFile file)
        {
            StyleCopTrace.In(process, settingsStore, processKind, file);

            if (process == null)
            {
                throw new ArgumentNullException("process");
            }

            try
            {
                if (processKind == DaemonProcessKind.OTHER)
                {
                    StyleCopTrace.Info("ProcessKind Other.");
                    StyleCopTrace.Out();
                    return(null);
                }

                if (!this.IsAnalysisEnabled(settingsStore, file))
                {
                    StyleCopTrace.Info("Analysis disabled.");
                    StyleCopTrace.Out();
                    return(null);
                }

                if (!this.IsSupported(process.SourceFile))
                {
                    StyleCopTrace.Info("File type not supported.");
                    StyleCopTrace.Out();
                    return(null);
                }

                if (!this.FileIsValid(file))
                {
                    StyleCopTrace.Info("Source file not valid.");
                    StyleCopTrace.Out();
                    return(null);
                }

                if (!settingsStore.GetValue <StyleCopOptionsSettingsKey, bool>(key => key.AnalyzeReadOnlyFiles))
                {
                    if (process.SourceFile.Properties.IsNonUserFile)
                    {
                        StyleCopTrace.Info("Not analysing non user files.");
                        StyleCopTrace.Out();
                        return(null);
                    }
                }

                IDaemon daemon = file.GetSolution().GetComponent <IDaemon>();

                return(StyleCopTrace.Out(new StyleCopStageProcess(this.lifetime, this.apiPool, daemon, process, this.threading, file)));
            }
            catch (JetBrains.Application.Progress.ProcessCancelledException)
            {
                return(null);
            }
        }
示例#2
0
        private HashSet <IDeclaration> FindHotRootMethods([NotNull] ICSharpFile file, [NotNull] IPsiSourceFile sourceFile)
        {
            var api    = file.GetSolution().GetComponent <UnityApi>();
            var result = new HashSet <IDeclaration>();

            var descendantsEnumerator = file.Descendants();

            while (descendantsEnumerator.MoveNext())
            {
                switch (descendantsEnumerator.Current)
                {
                case IClassLikeDeclaration classLikeDeclaration:
                    var declaredSymbol = classLikeDeclaration.DeclaredElement;
                    if (declaredSymbol == null ||
                        !declaredSymbol.GetAllSuperTypes().Any(t => t.GetClrName().Equals(KnownTypes.MonoBehaviour)))
                    {
                        descendantsEnumerator.SkipThisNode();
                    }

                    break;

                case IMethodDeclaration methodDeclaration:
                    // check that method is hot and add it to container
                    var declaredElement = methodDeclaration.DeclaredElement;
                    if (declaredElement == null)
                    {
                        break;
                    }
                    var name = declaredElement.ShortName;
                    if (ourKnownHotMonoBehaviourMethods.Contains(name) && api.IsEventFunction(declaredElement))
                    {
                        result.Add(methodDeclaration);
                    }
                    break;

                case IInvocationExpression invocationExpression:
                    // we should find 'StartCoroutine' method, because passed symbol will be hot too
                    var reference = (invocationExpression.InvokedExpression as IReferenceExpression)?.Reference;
                    if (reference == null)
                    {
                        break;
                    }

                    var info = reference.Resolve();
                    if (info.ResolveErrorType != ResolveErrorType.OK)
                    {
                        break;
                    }

                    declaredElement = info.DeclaredElement as IMethod;
                    if (declaredElement == null)
                    {
                        break;
                    }

                    var containingType = declaredElement.GetContainingType();

                    if (containingType == null || containingType.GetClrName().Equals(KnownTypes.MonoBehaviour) &&
                        declaredElement.ShortName.Equals("StartCoroutine"))
                    {
                        var arguments = invocationExpression.Arguments;
                        if (arguments.Count == 0 || arguments.Count > 2)
                        {
                            break;
                        }

                        var firstArgument = arguments[0].Value;
                        if (firstArgument == null)
                        {
                            break;
                        }

                        var coroutineMethodDeclaration = ExtractMethodDeclarationFromStartCoroutine(firstArgument);
                        if (coroutineMethodDeclaration == null)
                        {
                            break;
                        }

                        var declarations = coroutineMethodDeclaration.GetDeclarationsIn(sourceFile).Where(t => t.GetSourceFile() == sourceFile);
                        foreach (var declaration in declarations)
                        {
                            result.Add(declaration);
                        }
                    }

                    break;
                }
            }

            return(result);
        }
示例#3
0
        /// <summary>
        /// This method provides a <see cref="IDaemonStageProcess"/> instance which is assigned to highlighting a single document.
        /// </summary>
        /// <param name="process">
        /// Current Daemon Process.
        /// </param>
        /// <param name="settingsStore">
        /// The settingsStore store to use.
        /// </param>
        /// <param name="processKind">
        /// The process kind.
        /// </param>
        /// <param name="file">
        /// The file to analyze.
        /// </param>
        /// /// 
        /// <returns>
        /// The current <see cref="IDaemonStageProcess"/>.
        /// </returns>
        protected override IDaemonStageProcess CreateProcess(
            IDaemonProcess process, IContextBoundSettingsStore settingsStore, DaemonProcessKind processKind, ICSharpFile file)
        {
            StyleCopTrace.In(process, settingsStore, processKind, file);

            if (process == null)
            {
                throw new ArgumentNullException("process");
            }

            try
            {
                if (processKind == DaemonProcessKind.OTHER)
                {
                    StyleCopTrace.Info("ProcessKind Other.");
                    StyleCopTrace.Out();
                    return null;
                }

                if (!settingsStore.GetValue<StyleCopOptionsSettingsKey, bool>(key => key.AnalysisEnabled))
                {
                    StyleCopTrace.Info("Analysis disabled.");
                    StyleCopTrace.Out();
                    return null;
                }

                if (!this.IsSupported(process.SourceFile))
                {
                    StyleCopTrace.Info("File type not supported.");
                    StyleCopTrace.Out();
                    return null;
                }

                if (!this.FileIsValid(file))
                {
                    StyleCopTrace.Info("Source file not valid.");
                    StyleCopTrace.Out();
                    return null;
                }

                if (!settingsStore.GetValue<StyleCopOptionsSettingsKey, bool>(key => key.AnalyzeReadOnlyFiles))
                {
                    if (process.SourceFile.Properties.IsNonUserFile)
                    {
                        StyleCopTrace.Info("Not analysing non user files.");
                        StyleCopTrace.Out();
                        return null;
                    }
                }

                IDaemon daemon = file.GetSolution().GetComponent<IDaemon>();

                return StyleCopTrace.Out(new StyleCopStageProcess(this.lifetime, this.apiPool, daemon, process, this.threading, file));
            }
            catch (JetBrains.Application.Progress.ProcessCancelledException)
            {
                return null;
            }
        }
示例#4
0
 /// <summary>
 /// Returns a config object exposing the current config settings for this file.
 /// </summary>
 /// <param name="lifetime">
 /// The lifetime of the settings for the configuration.
 /// </param>
 /// <param name="file">
 /// The file to get the config for.
 /// </param>
 /// <returns>
 /// The configuration for the given file.
 /// </returns>
 private static DocumentationRulesConfiguration GetDocumentationRulesConfig(Lifetime lifetime, ICSharpFile file)
 {
     // TODO: We shouldn't have to resort to service locator!
     var api = file.GetSolution().GetComponent<StyleCopApiPool>().GetInstance(lifetime);
     return new DocumentationRulesConfiguration(api.Settings, file.GetSourceFile());
 }