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