Changes:
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / AstNode.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import java.util.List;
4
5 /**
6  * It will be the mother of our own ast tree for php just like the ast tree of Eclipse.
7  * @author Matthieu Casanova
8  */
9 public abstract class AstNode {
10
11   /** Starting and ending position of the node in the sources. */
12   public int sourceStart, sourceEnd;
13
14   /**
15    * Create a node giving starting and ending offset
16    * @param sourceStart starting offset
17    * @param sourceEnd ending offset
18    */
19   public AstNode(final int sourceStart, final int sourceEnd) {
20     this.sourceStart = sourceStart;
21     this.sourceEnd = sourceEnd;
22   }
23
24   /**
25    * Add some tabulations.
26    * @param tab the number of tabulations
27    * @return a String containing some spaces
28    */
29   public static String tabString(final int tab) {
30     final StringBuffer s = new StringBuffer(2 * tab);
31     for (int i = tab; i > 0; i--) {
32       s.append("  "); //$NON-NLS-1$
33     }
34     return s.toString();
35   }
36
37   /**
38    * Return the object into String.
39    * It should be overriden
40    * @return a String
41    */
42   public String toString() {
43     return "****" + super.toString() + "****";  //$NON-NLS-2$ //$NON-NLS-1$
44   }
45
46   /**
47    * Return the object into String.
48    * @param tab how many tabs (not used here
49    * @return a String
50    */
51   public abstract String toString(int tab);
52
53   /**
54    * Get the variables from outside (parameters, globals ...)
55    */
56   public abstract void getOutsideVariable(List list);
57
58   /**
59    * get the modified variables.
60    */
61   public abstract void getModifiedVariable(List list);
62
63   /**
64    * Get the variables used.
65    */
66   public abstract void getUsedVariable(List list);
67
68   /**
69    * This method will analyze the code.
70    * by default it will do nothing
71    */
72   public void analyzeCode() {
73   }
74
75   /**
76    * Check if the array array contains the object o
77    * @param array an array
78    * @param o an obejct
79    * @return true if the array contained the object o
80    */
81   public boolean arrayContains(Object[] array, Object o) {
82     for (int i = 0; i < array.length; i++) {
83       if (array[i].equals(o)) {
84         return true;
85       }
86     }
87     return false;
88   }
89 }