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