First try for AST structure. A lot of things to change
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / PHPDocument.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
4 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
5 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
6 import org.eclipse.jface.resource.ImageDescriptor;
7
8 import java.util.ArrayList;
9
10 /**
11  * It's a php document.
12  * It will contains html and php
13  * @author Matthieu Casanova
14  */
15 public class PHPDocument implements OutlineableWithChildren {
16
17   /**
18    * The nodes.
19    * It will include html nodes or php nodes
20    */
21   public AstNode[] nodes;
22
23   /** The parent of the object */
24   public Object parent;
25
26   /** The outlineable children (those will be in the node array too. */
27   private ArrayList children = new ArrayList();
28
29   /**
30    * Create the PHPDocument.
31    */
32   public PHPDocument(Object parent) {
33     this.parent = parent;
34   }
35
36   /**
37    * Return the php document as String.
38    * @return  a string representation of the object.
39    */
40   public String toString() {
41     final StringBuffer buff = new StringBuffer();
42     AstNode node;
43     int i;
44     for (i = 0; i < nodes.length; i++) {
45       node = nodes[i];
46       if (node == null) {
47         break;
48       }
49       buff.append(node);
50     }
51     return buff.toString();
52   }
53
54   /**
55    * Add an outlineable object.
56    * @param o the new outlineable
57    * @return does the addition worked ?
58    */
59   public boolean add(Outlineable o) {
60     return children.add(o);
61   }
62
63   /**
64    * Return the outlineable at the index.
65    * @param index the index
66    * @return an outlineable object
67    */
68   public Outlineable get(int index) {
69     return (Outlineable) children.get(index);
70   }
71
72   /**
73    * The number of outlineable children
74    * @return
75    */
76   public int size() {
77     return children.size();
78   }
79
80   /**
81    * This will return the image for the outline of the object.
82    * @return an image
83    */
84   public ImageDescriptor getImage() {
85     return PHPUiImages.DESC_CLASS;
86   }
87
88   public Object getParent() {
89     return parent;
90   }
91 }