1 16 package com.google.gwt.dev.generator.ast; 17 18 import java.util.List ; 19 20 23 public class ForLoop implements Statements { 24 25 private final StatementsList body; 26 27 private final String initializer; 28 29 private String label; 30 31 private final String step; 32 33 private final String test; 34 35 39 public ForLoop(String initializer, String test, String step) { 40 this(initializer, test, step, null); 41 } 42 43 52 public ForLoop(String initializer, String test, String step, 53 Statements statements) { 54 this.initializer = initializer; 55 this.test = test; 56 this.step = step; 57 this.body = new StatementsList(); 58 59 if (statements != null) { 60 body.getStatements().add(statements); 61 } 62 } 63 64 public List getStatements() { 65 return body.getStatements(); 66 } 67 68 public void setLabel(String label) { 69 this.label = label; 70 } 71 72 public String toCode() { 73 String loop = "for ( " + initializer + "; " + test + "; " + step + " ) {\n" 74 + body.toCode() + "\n" + "}\n"; 75 76 return label != null ? label + ": " + loop : loop; 77 } 78 } 79 | Popular Tags |