92dccf08bf1af1c34de660cf66367e71fbbf1af2
[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
28   /** The parent of the object. */
29   public Object parent;
30
31   /** The outlineable children (those will be in the node array too. */
32   private ArrayList children = new ArrayList();
33
34   private Position position;
35   /**
36    * Create the PHPDocument.
37    * @param parent the parent object (it should be null isn't it ?)
38    */
39   public PHPDocument(final Object parent,
40                      final char[] name) {
41     this.parent = parent;
42     this.name = name;
43     position = new Position(1,name.length);
44   }
45
46   /**
47    * Return the php document as String.
48    * @return  a string representation of the object.
49    */
50   public String toString() {
51     final StringBuffer buff = new StringBuffer();
52     AstNode node;
53     if (nodes != null) {
54       int i;
55       for (i = 0; i < nodes.length; i++) {
56         node = nodes[i];
57         if (node == null) {
58           break;
59         }
60         buff.append(node.toString(0));
61         if (node instanceof HTMLCode) {
62           buff.append("\n");//$NON-NLS-1$
63         } else {
64           buff.append(";\n");//$NON-NLS-1$
65         }
66       }
67     }
68     return buff.toString();
69   }
70
71   /**
72    * Add an outlineable object.
73    * @param o the new outlineable
74    * @return does the addition worked ?
75    */
76   public boolean add(final Outlineable o) {
77     return children.add(o);
78   }
79
80   /**
81    * Return the outlineable at the index.
82    * @param index the index
83    * @return an outlineable object
84    */
85   public Outlineable get(final int index) {
86     return (Outlineable) children.get(index);
87   }
88
89   /**
90    * The number of outlineable children.
91    * @return the number of children that are outlineable
92    */
93   public int size() {
94     return children.size();
95   }
96
97   /**
98    * This will return the image for the outline of the object.
99    * @return an image
100    */
101   public ImageDescriptor getImage() {
102     return PHPUiImages.DESC_CLASS;
103   }
104
105   /**
106    * Get the parent of the object.
107    * @return the parent of the object
108    */
109   public Object getParent() {
110     return parent;
111   }
112
113   public Position getPosition() {
114     return position;
115   }
116
117   public List getList() {
118     return children;
119   }
120 }