Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Block.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import java.util.List;
4
5 /**
6  * A Block.
7  * {
8  * statements
9  * }.
10  * @author Matthieu Casanova
11  */
12 public class Block extends Statement {
13
14   /** An array of statements inside the block. */
15   public Statement[] statements;
16
17   /**
18    * Create a block.
19    * @param statements the statements
20    * @param sourceStart starting offset
21    * @param sourceEnd ending offset
22    */
23   public Block(final Statement[] statements,
24                final int sourceStart,
25                final int sourceEnd) {
26     super(sourceStart, sourceEnd);
27     this.statements = statements;
28   }
29
30   /**
31    * tell if the block is empty.
32    * @return the block is empty if there are no statements in it
33    */
34   public boolean isEmptyBlock() {
35     return statements == null;
36   }
37
38   /**
39    * Return the block as String.
40    * @param tab how many tabs
41    * @return the string representation of the block
42    */
43   public String toString(final int tab) {
44     final String s = AstNode.tabString(tab);
45     final StringBuffer buff = new StringBuffer(s);
46     buff.append("{\n"); //$NON-NLS-1$
47     if (this.statements != null) {
48       for (int i = 0; i < statements.length; i++) {
49         buff.append(statements[i].toString(tab + 1)).append(";\n");//$NON-NLS-1$
50       }
51     }
52     buff.append("}\n"); //$NON-NLS-1$
53     return buff.toString();
54   }
55
56   /**
57    * Get the variables from outside (parameters, globals ...)
58    */
59   public void getOutsideVariable(final List list) {
60     for (int i = 0; i < statements.length; i++) {
61       statements[i].getOutsideVariable(list);
62     }
63   }
64
65   /**
66    * get the modified variables.
67    */
68   public void getModifiedVariable(final List list) {
69     for (int i = 0; i < statements.length; i++) {
70       statements[i].getModifiedVariable(list);
71     }
72   }
73
74   /**
75    * Get the variables used.
76    */
77   public void getUsedVariable(final List list) {
78     for (int i = 0; i < statements.length; i++) {
79       statements[i].getUsedVariable(list);
80     }
81   }
82 }