a7b452696bad82fc2f16a5cf3d85feb57914db35
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / phpparser / PHPSegmentWithChildren.java
1 package net.sourceforge.phpeclipse.phpeditor.phpparser;
2
3 import java.util.List;
4 import java.util.ArrayList;
5
6 /**
7  * An abstract PHPSegment that can have children.
8  * @author khartlage, Matthieu Casanova
9  */
10 public abstract class PHPSegmentWithChildren extends PHPSegment {
11   private ArrayList children;
12
13   /**
14    * Create a PHPSegment that can have children (class or functions).
15    * @param parent the parent object (it should be a php class)
16    * @param name the name of the function
17    * @param index where the function is in the file
18    */
19   public PHPSegmentWithChildren(Object parent, String name, int index) {
20     super(parent, name, index);
21     children = new ArrayList();
22   }
23
24   public List getList( ) {
25     return children;
26   }
27
28   /**
29    * Appends the specified PHPSegment declaration
30    *
31    * @param o function declaration to be appended to this list.
32    * @return <tt>true</tt> (as per the general contract of Collection.add).
33    */
34   public boolean add(PHPSegment o) {
35     return children.add(o);
36   }
37
38   /**
39    * Returns the PHPSegment declaration at the specified position in this list.
40    *
41    * @param  index index of function declaration to return.
42    * @return the function declaration at the specified position in this list.
43    * @throws    java.lang.IndexOutOfBoundsException if index is out of range <tt>(index
44    *      &lt; 0 || index &gt;= size())</tt>.
45    */
46   public PHPSegment get(int index) {
47     return (PHPSegment) children.get(index);
48   }
49
50   /**
51      * Returns the number of declarations in this list.
52      *
53      * @return  the number of declarations in this list.
54      */
55   public int size() {
56     return children.size();
57   }
58 }