*** empty log message ***
[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 import org.eclipse.jface.text.Position;
8
9 import java.util.ArrayList;
10 import java.util.List;
11
12 /**
13  * It's a php document.
14  * This class is an outlineable object
15  * It will contains html and php
16  * @author Matthieu Casanova
17  */
18 public class PHPDocument implements OutlineableWithChildren {
19
20   /**
21    * The nodes.
22    * It will include html nodes or php nodes
23    */
24   public AstNode[] nodes;
25
26   public char[] name;
27   /** The parent of the object. */
28   public Object parent;
29
30   /** The outlineable children (those will be in the node array too. */
31   private ArrayList children = new ArrayList();
32
33   private Position position;
34   /**
35    * Create the PHPDocument.
36    * @param parent the parent object (it should be null isn't it ?)
37    */
38   public PHPDocument(Object parent, char[] name) {
39     this.parent = parent;
40     this.name = name;
41     position = new Position(1,name.length);
42   }
43
44   /**
45    * Return the php document as String.
46    * @return  a string representation of the object.
47    */
48   public String toString() {
49     final StringBuffer buff = new StringBuffer();
50     AstNode node;
51     if (nodes != null) {
52       int i;
53       for (i = 0; i < nodes.length; i++) {
54         node = nodes[i];
55         if (node == null) {
56           break;
57         }
58         buff.append(node.toString(0));
59         buff.append("\n");
60       }
61     }
62     return buff.toString();
63   }
64
65   /**
66    * Add an outlineable object.
67    * @param o the new outlineable
68    * @return does the addition worked ?
69    */
70   public boolean add(Outlineable o) {
71     return children.add(o);
72   }
73
74   /**
75    * Return the outlineable at the index.
76    * @param index the index
77    * @return an outlineable object
78    */
79   public Outlineable get(int index) {
80     return (Outlineable) children.get(index);
81   }
82
83   /**
84    * The number of outlineable children.
85    * @return the number of children that are outlineable
86    */
87   public int size() {
88     return children.size();
89   }
90
91   /**
92    * This will return the image for the outline of the object.
93    * @return an image
94    */
95   public ImageDescriptor getImage() {
96     return PHPUiImages.DESC_CLASS;
97   }
98
99   /**
100    * Get the parent of the object.
101    * @return the parent of the object
102    */
103   public Object getParent() {
104     return parent;
105   }
106
107   public Position getPosition() {
108     return position;
109   }
110
111   public List getList() {
112     return children;
113   }
114 }