private CodeForeachStatement CreateRegisterModelForeach(string className, string registerType) { CodeForeachStatement loop = new CodeForeachStatement(NewVariable(registerType, registerType.ToLower()), NewFieldReferenceType(className, $"{registerType.ToUpper()}S")); CodeMethodInvokeExpression registerModels = NewMethodInvokeVar($"(({SourceCodeLocator.ModelInterface(Modname, Organization).ClassName}) {registerType.ToLower()})", "registerModels"); CodeConditionStatement ifStatement = new CodeConditionStatement( new CodeSnippetExpression($"{registerType.ToLower()} instanceof {SourceCodeLocator.ModelInterface(Modname, Organization).ClassName}"), new CodeExpressionStatement(registerModels) ); loop.Statements.Add(ifStatement); return(loop); }
public void GenerateForEachLoop() { CodeForeachStatement forEach = new CodeForeachStatement(new CodeVariableDeclarationStatement(typeof(int), "integer"), new CodeTypeReferenceExpression("someList")); string code = GenerateStatement(TestContext, forEach); Assert.IsTrue(code.Contains("for (int integer : someList) {"), code); forEach = new CodeForeachStatement(new CodeVariableDeclarationStatement("Block", "block"), new CodeFieldReferenceExpression(new CodeTypeReferenceExpression("ModBlocks"), "BLOCKS")); code = GenerateStatement(TestContext, forEach); Assert.IsTrue(code.Contains("for (Block block : ModBlocks.BLOCKS) {"), code); }
public int VisitForeach(CodeForeachStatement f) { Analyze(this.path, f.Statements); return(0); }
public CodeStatement Foreach(CodeExpression exp, CodeExpression list, Action xlatLoopBody) { var c = new CodeForeachStatement(exp, list); Scope.Add(c); var old = Scope; Scope = c.Statements; xlatLoopBody(); Scope = old; return c; }