예제 #1
0
        /// Action to be executed at completion of semantic analysis of a class declaration in the target project.
        /// <param name="context">context for a symbol action.</param>
        private static void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
        {
            // check for exclusion
            if (context.IsExcluded(DiagnosticIDs.DoNotUseCameraMain))
            {
                return;
            }

            markGraph.CheckClassDirty(context);

            // foreach monobehaviour update methods
            var mono = new MonoBehaviourInfo(context);

            mono.ForEachUpdateMethod((method) =>
            {
                Stack <SyntaxNode> callStack = new Stack <SyntaxNode>();
                var ret = markGraph.SearchMethod(context, method, callStack);

                // check if it equals to "UnityEngine.Camera.main"
                if (ret)
                {
                    var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotUseCameraMain,
                                                       (callStack.FirstOrDefault() ?? method).GetLocation(), callStack.SyntaxStackToString());
                    context.ReportDiagnostic(diagnostic);
                }
            });
        }
        /// Action to be executed at completion of semantic analysis of a class declaration in the target project.
        /// <param name="context">context for a symbol action.</param>
        private static void AnalyzeSyntax(SyntaxNodeAnalysisContext context)
        {
            // check for exclusion
            if (context.IsExcluded(DiagnosticIDs.DoNotNewContainerInUpdate))
            {
                return;
            }

            // check dirty classes in the cache
            markGraph.CheckClassDirty(context);

            // check from each Update method in a MonoBehaviour script(if it is)
            var mono = new MonoBehaviourInfo(context);

            mono.ForEachUpdateMethod((method) =>
            {
                Stack <SyntaxNode> callStack = new Stack <SyntaxNode>();
                var ret = markGraph.SearchMethod(context, method, callStack);
                if (ret)
                {
                    var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotNewContainerInUpdate,
                                                       (callStack.FirstOrDefault() ?? method).GetLocation(), callStack.SyntaxStackToString());
                    context.ReportDiagnostic(diagnostic);
                }
            });
        }
        public void AnalyzeClassSyntax(SyntaxNodeAnalysisContext context)
        {
            var monoBehaviourInfo = new MonoBehaviourInfo(context);

            var searched = new Dictionary <IMethodSymbol, bool>();

            _indirectCallers = new Dictionary <ExpressionSyntax, ExpressionSyntax>();

            monoBehaviourInfo.ForEachUpdateMethod((updateMethod) =>
            {
                //Debug.WriteLine("Found an update call! " + updateMethod);

                var findCalls = SearchForFindCalls(context, updateMethod, searched, true);

                foreach (var findCall in findCalls)
                {
                    if (!_indirectCallers.ContainsKey(findCall))
                    {
                        var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotUseFindMethodsInUpdate,
                                                           findCall.GetLocation(), findCall, monoBehaviourInfo.ClassName, updateMethod.Identifier);
                        context.ReportDiagnostic(diagnostic);
                    }
                    else
                    {
                        var endPoint = _indirectCallers[findCall];

                        var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotUseFindMethodsInUpdateRecursive,
                                                           findCall.GetLocation(), monoBehaviourInfo.ClassName, updateMethod.Identifier, findCall, endPoint);
                        context.ReportDiagnostic(diagnostic);
                    }
                }
            });
        }
예제 #4
0
        public void AnalyzeClassSyntax(SyntaxNodeAnalysisContext context)
        {
            var monoBehaviourInfo = new MonoBehaviourInfo(context);

            var searched = new Dictionary <ISymbol, bool>();

            _indirectCallers = new Dictionary <ExpressionSyntax, ExpressionSyntax>();

            monoBehaviourInfo.ForEachUpdateMethod((updateMethod) =>
            {
                //Debug.WriteLine("Found an update call! " + updateMethod);

                var results = SearchForTargetExpression(context, updateMethod, searched, true);

                foreach (var oneResult in results)
                {
                    if (!_indirectCallers.ContainsKey(oneResult))
                    {
                        var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotGCAllocnInUpdate,
                                                           oneResult.GetLocation(), oneResult, monoBehaviourInfo.ClassName, updateMethod.Identifier);
                        context.ReportDiagnostic(diagnostic);
                    }
                    else
                    {
                        var endPoint = _indirectCallers[oneResult];

                        var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotGCAllocnInUpdateRecursive,
                                                           oneResult.GetLocation(), monoBehaviourInfo.ClassName, updateMethod.Identifier, oneResult, endPoint);
                        context.ReportDiagnostic(diagnostic);
                    }
                }
            });
        }
예제 #5
0
        /// Action to be executed at completion of semantic analysis of a class declaration in the target project.
        /// <param name="context">context for a symbol action.</param>
        public static void AnalyzeClassSyntax(SyntaxNodeAnalysisContext context)
        {
            // check for exclusion
            if (context.IsExcluded(DiagnosticIDs.DoNotUseForEachInUpdate))
            {
                return;
            }

            var monoBehaviourInfo = new MonoBehaviourInfo(context);
            var searched          = new Dictionary <IMethodSymbol, bool>();

            /// iterate all Update methods in this MonoBehavior-derived class
            monoBehaviourInfo.ForEachUpdateMethod((updateMethod) =>
            {
                // iterate all "ForEach" methods in this "Update" method
                var forEachStatements = SearchForForEach(context, updateMethod, searched);
                foreach (var forEachStatement in forEachStatements)
                {
                    if (forEachStatement.IsExcluded(DiagnosticIDs.DoNotUseForEachInUpdate))
                    {
                        continue;
                    }

                    Debug.WriteLine("Found a bad call! " + forEachStatement);

                    // report a Diagnostic result
                    var location   = forEachStatement.ForEachKeyword.GetLocation();
                    var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotUseForEachInUpdate, location,
                                                       monoBehaviourInfo.ClassName, updateMethod.Identifier);
                    context.ReportDiagnostic(diagnostic);
                }
            });
        }
        public void AnalyzeClassSyntax(SyntaxNodeAnalysisContext context)
        {
            var monoBehaviourInfo = new MonoBehaviourInfo(context);

            monoBehaviourInfo.ForEachUpdateMethod((updateMethod) =>
            {
                SearchCameraMain(context, updateMethod);
                RecursiveMethodCrawler(context, updateMethod);
            });
        }
예제 #7
0
        public static void AnalyzeClassSyntax(SyntaxNodeAnalysisContext context)
        {
            var monoBehaviourInfo = new MonoBehaviourInfo(context);

            var searched = new Dictionary <IMethodSymbol, bool>();

            monoBehaviourInfo.ForEachUpdateMethod((updateMethod) =>
            {
                AnalyzeAssignmentNode(context, updateMethod);
                AnalyzeInvocationNode(context, updateMethod);
            });
        }
        private void AnalyzeMonoBehaviour(MonoBehaviourInfo monoBehaviour)
        {
            monoBehaviour.ForEachMonoBehaviourMethod(m =>
            {
                // from the method syntax, check if there is a body and if there are statements in it
                if (m.Body?.Statements.Count == 0)
                {
                    var methodName = m.Identifier.ValueText;

                    base.ReportDiagnostic(m.GetLocation(), monoBehaviour.ClassName, methodName);
                }
            });
        }
        /// Action to be executed at completion of semantic analysis of a class description in the target project.
        /// <param name="context">context for a symbol action.</param>
        public void AnalyzeClassSyntax(SyntaxNodeAnalysisContext context)
        {
            // check for exclusion
            if (context.IsExcluded(DiagnosticIDs.DoNotUseFindMethodsInUpdate))
            {
                return;
            }

            var monoBehaviourInfo = new MonoBehaviourInfo(context);
            var searched          = new Dictionary <IMethodSymbol, bool>();

            _indirectCallers = new Dictionary <ExpressionSyntax, ExpressionSyntax>();

            // iterate all "Update" functions in this class, if this class is a MonoBehavior-derived one
            monoBehaviourInfo.ForEachUpdateMethod((updateMethod) =>
            {
                // Debug.WriteLine("Found an update call! " + updateMethod);

                // iterate all "Find" functions in this "Update" function
                var findCalls = SearchForFindCalls(context, updateMethod, searched, true);
                foreach (var findCall in findCalls)
                {
                    // if this call is excluded, skip it
                    if (findCall.IsExcluded(DiagnosticIDs.DoNotUseFindMethodsInUpdate))
                    {
                        continue;
                    }

                    // if this is a "Find" method to be called directly in this method body
                    if (!_indirectCallers.ContainsKey(findCall))
                    {
                        // report a Diagnostic result
                        var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotUseFindMethodsInUpdate,
                                                           findCall.GetLocation(), findCall, monoBehaviourInfo.ClassName, updateMethod.Identifier);
                        context.ReportDiagnostic(diagnostic);
                    }
                    // if this is a "Find" method to be called within a user-defined method, which is called in this method body
                    // (here, we only care about "Find" methods in the first-level child methods, with all deeper child methods being ignored)
                    else
                    {
                        var endPoint = _indirectCallers[findCall];

                        // report a Diagnostic result
                        var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotUseFindMethodsInUpdateRecursive,
                                                           findCall.GetLocation(), monoBehaviourInfo.ClassName, updateMethod.Identifier, findCall,
                                                           endPoint);
                        context.ReportDiagnostic(diagnostic);
                    }
                }
            });
        }
예제 #10
0
        public static void AnalyzeClassSyntax(SyntaxNodeAnalysisContext context)
        {
            var monoBehaviourInfo = new MonoBehaviourInfo(context);

            var searched = new Dictionary <IMethodSymbol, bool>();

            monoBehaviourInfo.ForEachUpdateMethod((updateMethod) =>
            {
                var forEachStatements = SearchForForEach(context, updateMethod, searched);

                foreach (var forEachStatement in forEachStatements)
                {
                    Debug.WriteLine("Found a bad call! " + forEachStatement);

                    var location   = forEachStatement.ForEachKeyword.GetLocation();
                    var diagnostic = Diagnostic.Create(DiagnosticDescriptors.DoNotUseForEachInUpdate, location, monoBehaviourInfo.ClassName, updateMethod.Identifier);
                    context.ReportDiagnostic(diagnostic);
                }
            });
        }
예제 #11
0
        private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
        {
            var monoBehaviourInfo = new MonoBehaviourInfo();

            monoBehaviourInfo.IsStringMethod(DiagnosticDescriptors.DoNotUseStateName, "Animator", animatorStateNameMethods, context);
        }
예제 #12
0
        private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
        {
            var monoBehaviourInfo = new MonoBehaviourInfo();

            monoBehaviourInfo.IsStringMethod(DiagnosticDescriptors.DoNotUseStringPropertyNames, "Shader", shaderStringPropertyMethods, context);
        }