Ejemplo n.º 1
0
 public Visitor(NRefactoryContext nrefactoryContext, Func<InvocationExpression, bool> verifier, Type systemType, string methodName)
 {
     this.nrefactoryContext = nrefactoryContext;
     this.verifier = verifier;
     this.systemType = systemType;
     this.methodName = methodName;
 }
Ejemplo n.º 2
0
        public override bool IsAchievementUnlocked(StatisAnalysisSession statisAnalysisSession)
        {
            // Return out if there are no files to check achievements in.
            if (!statisAnalysisSession.StaticAnalysisManifest.ChangedFiles.Any())
            {
                return(false);
            }

            // Obtain a session object and the codebase type declarations
            var nrefactorySession = statisAnalysisSession.GetSessionObjectOfType <NRefactorySession>();

            NRefactoryContext = new NRefactoryContext()
            {
                CodebaseDeclarations = nrefactorySession.GetCodebaseDeclarations(statisAnalysisSession.StaticAnalysisManifest),
                InvokedSystemTypes   = nrefactorySession.GetSystemInvocations(statisAnalysisSession.StaticAnalysisManifest)
            };

            // Have the concrete implementation create it's visitor
            var visitor = CreateVisitor(statisAnalysisSession);

            // Parse all files in the changed files collection for achievements
            foreach (var filename in statisAnalysisSession.StaticAnalysisManifest.ChangedFiles)
            {
                // Obtain a parser from the nrefactorySession.
                // This parser is shared context between all concrete achievement implementations.
                var compilationUnit = nrefactorySession.GetCompilationUnit(filename);

                // Pass concrete visitor into the AST created by the parser
                compilationUnit.AcceptVisitor(visitor, null);

                // Call OnParsingCompleted on the visitor to give it a last chance to unlock achievements.
                visitor.OnParsingCompleted();

                // Check if the visitor declared the concrete achievement as unlocked.
                if (visitor.IsAchievementUnlocked)
                {
                    AchievementCodeOrigin = visitor.CodeOrigin;
                    if (AchievementCodeOrigin != null)
                    {
                        AchievementCodeOrigin.FileName = filename;
                    }

                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 3
0
        public override bool IsAchievementUnlocked(StatisAnalysisSession statisAnalysisSession)
        {
            // Return out if there are no files to check achievements in.
            if (!statisAnalysisSession.StaticAnalysisManifest.ChangedFiles.Any())
            {
                return false;
            }

            // Obtain a session object and the codebase type declarations
            var nrefactorySession = statisAnalysisSession.GetSessionObjectOfType<NRefactorySession>();
            NRefactoryContext = new NRefactoryContext()
                                    {
                                        CodebaseDeclarations = nrefactorySession.GetCodebaseDeclarations(statisAnalysisSession.StaticAnalysisManifest),
                                        InvokedSystemTypes = nrefactorySession.GetSystemInvocations(statisAnalysisSession.StaticAnalysisManifest)
                                    };

            // Have the concrete implementation create it's visitor
            var visitor = CreateVisitor(statisAnalysisSession);

            // Parse all files in the changed files collection for achievements
            foreach (var filename in statisAnalysisSession.StaticAnalysisManifest.ChangedFiles)
            {
                // Obtain a parser from the nrefactorySession.
                // This parser is shared context between all concrete achievement implementations.
                var compilationUnit = nrefactorySession.GetCompilationUnit(filename);

                // Pass concrete visitor into the AST created by the parser
                compilationUnit.AcceptVisitor(visitor, null);

                // Call OnParsingCompleted on the visitor to give it a last chance to unlock achievements.
                visitor.OnParsingCompleted();

                // Check if the visitor declared the concrete achievement as unlocked.
                if (visitor.IsAchievementUnlocked)
                {
                    AchievementCodeOrigin = visitor.CodeOrigin;
                    if (AchievementCodeOrigin != null)
                    {
                        AchievementCodeOrigin.FileName = filename;
                    }

                    return true;
                }
            }

            return false;
        }