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