public BlockSyntax RenderMethodInfo(CodeRunBlockRenderingInfo methodRenderingInfo, BlockSyntax blockSyntax) { BlockStatementsWriter blockStatementsWriter = new BlockStatementsWriter(methodRenderingInfo); var newBlock = blockStatementsWriter.Visit(blockSyntax) as BlockSyntax; return(newBlock); }
internal static void RunBlockRenderTest(string testMethod, Dictionary <int, List <string> > renderingInfo, int expectedStatementCount, List <string> expectedStatementSubStrings) { MethodDeclarationSyntax methSyntax = Helpers.GetFirstMethodSyntax(testMethod); CodeRunnerBlockRenderer methSyntxWriter = CodeRunnerBlockRenderer.GetWriter(); CodeRunBlockRenderingInfo methodRenderingInfo = createRenderingInfoFromDict(renderingInfo); BlockSyntax newBlock = methSyntxWriter.RenderMethodInfo(methodRenderingInfo, methSyntax.Body); CheckExpectedStatements(expectedStatementCount, expectedStatementSubStrings, newBlock); }
public override SyntaxNode VisitMethodDeclaration(MethodDeclarationSyntax node) { int id = codeRunnerIds; HookedRenderInfoGenerator generator = new HookedRenderInfoGenerator(); CodeRunBlockRenderingInfo renderinfo = generator.CodeRunBlockRenderInfoForMethod(classInfo, id); CodeRunnerBlockRenderer renderer = CodeRunnerBlockRenderer.GetWriter(); var newBlock = renderer.RenderMethodInfo(renderinfo, node.Body); codeRunnerIds++; return(node.WithBody(newBlock)); //return base.VisitMethodDeclaration(node); }
public void TestMethodBlockGenerator() { HookedRenderInfoGenerator generator = new HookedRenderInfoGenerator(); ClassInfo classInfo = FactoryHelper.CreateClassInfo(); CodeRunnerInfo codeRunnerInfo = FactoryHelper.GenerateCodeRunnerInfo(); classInfo.AddCodeRunnerInfo(codeRunnerInfo, 0); int id = 0; CodeRunBlockRenderingInfo renderInfo = generator.CodeRunBlockRenderInfoForMethod(classInfo, id); Assert.IsTrue(renderInfo.renderingInfo[0][0].Contains("OnMethodEnter")); Assert.IsTrue(renderInfo.renderingInfo[0][1].Contains("LogLineRun")); Assert.IsTrue(renderInfo.renderingInfo[0][2].Contains("0")); }
public void TestLocalVarDeclarationHooks() { HookedRenderInfoGenerator generator = new HookedRenderInfoGenerator(); ClassInfo classInfo = TestCase.GetLocalVarAssignmentCode().ClassInfo; int id = 0; CodeRunBlockRenderingInfo renderInfo = generator.CodeRunBlockRenderInfoForMethod(classInfo, id); Assert.IsTrue(renderInfo.renderingInfo[0][0].Contains("OnMethodEnter")); Assert.IsTrue(renderInfo.renderingInfo[0][1].Contains("LogLineRun")); Assert.IsTrue(renderInfo.renderingInfo[0][2].Contains("0")); Assert.IsTrue(renderInfo.renderingInfo[0][3].Contains("LocalVarUpdate")); Assert.IsTrue(renderInfo.renderingInfo[0][3].Contains("localVar1")); Assert.IsTrue(renderInfo.renderingInfo[0][4].Contains("LogLineRun")); Assert.IsTrue(renderInfo.renderingInfo[0][5].Contains("1")); Assert.IsTrue(renderInfo.renderingInfo[0][6].Contains("LocalVarUpdate")); Assert.IsTrue(renderInfo.renderingInfo[0][6].Contains("localVar1")); }
public CodeRunBlockRenderingInfo CodeRunBlockRenderInfoForMethod(ClassInfo classInfo, int id) { var info = new CodeRunBlockRenderingInfo(); var methodInfo = classInfo.GetCodeRunnerInfo(id); // Initialize render block dictionaries foreach (int blockid in methodInfo.blockInfo.Keys) { info.renderingInfo[blockid] = new List <string>() { }; } // Add OnMethodHook if (shouldHookOnMethod()) { if (!info.renderingInfo.ContainsKey(0)) { info.renderingInfo[0] = new List <string>() { } } ; string methodStr = HookTemplates.MethodEnterHook(classInfo.RelativeFilePath, methodInfo.Name, methodInfo.IsStatic); info.renderingInfo[0].Add(methodStr); } // Add Field Initial Value Update Hooks if (methodInfo.IsConstructor && shouldHookFieldInits()) { if (!info.renderingInfo.ContainsKey(0)) { info.renderingInfo[0] = new List <string>() { } } ; foreach (var finfo in classInfo.FieldInfos.Values) { foreach (var fname in finfo.Names) { string hookexpr = HookTemplates.FieldUpdateHook(fname, classInfo.Name, FieldGenerator.GetPrefixedName(fname)); info.renderingInfo[0].Add(hookexpr); } } } var localVarsList = new List <string>() { }; // Hook local var declarations for method argument if (shouldHookLocalVarChange()) { if (!info.renderingInfo.ContainsKey(0)) { info.renderingInfo[0] = new List <string>() { } } ; foreach (var arg in methodInfo.Arguments) { if (arg.Name != "") { localVarsList.Add(arg.Name); string localHook = HookTemplates.LocalVarUpdateHook(arg.Name, ""); info.renderingInfo[0].Add(localHook); } } } // Add LineExecHooks foreach (int blockid in methodInfo.blockInfo.Keys) { var statInfos = methodInfo.blockInfo[blockid].StatementInfos; for (int i = 0; i < statInfos.Count; i++) { var statInfo = statInfos[i]; if (shouldHookLineExec()) { string likeHook = HookTemplates.LineExecHook(statInfo.LineNo, ""); info.renderingInfo[blockid].Add(likeHook); } // Add the cue for the original statement info.renderingInfo[blockid].Add(i.ToString()); if (shouldHookLocalVarChange()) { bool addLocalVarUpdater = false; if (statInfo.IsLocalVarDeclaration) { localVarsList.AddRange(statInfo.LocalVarNames); addLocalVarUpdater = true; } if (statInfo.IsLocalVarStateChanger) { if (localVarsList.Contains(statInfo.LocalVarNames[0])) { addLocalVarUpdater = true; } } if (addLocalVarUpdater) { foreach (string varName in statInfo.LocalVarNames) { string localHook = HookTemplates.LocalVarUpdateHook(varName, ""); info.renderingInfo[blockid].Add(localHook); } } } } // Add line hook for close brace of the block int closeLineNo = methodInfo.blockInfo[blockid].CloseBraceLineNo; if (closeLineNo != -1 && shouldHookLineExec()) { string closeBraceStr = HookTemplates.LineExecHook(closeLineNo, ""); info.renderingInfo[blockid].Add(closeBraceStr); } } return(info); }
public BlockStatementsWriter(CodeRunBlockRenderingInfo info) { this.info = info; }