*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / Class.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 /**
4  * This class is my Class declaration for php.
5  * It is similar to org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
6  * It directly extends AstNode because a class cannot appear anywhere in php
7  * @author Matthieu Casanova
8  */
9 public class Class extends AstNode {
10
11   /** The name of the class. */
12   public char[] name;
13   /** The superclass. */
14   public char[] superclass;
15   /** The fields of the class. */
16   public VariableDeclaration[] fields;
17
18   public int declarationSourceStart;
19   public int declarationSourceEnd;
20   public int bodyStart;
21   public int bodyEnd;
22   /** The methods of the class. */
23   public MethodDeclaration[] methods;
24   /** The constructor of the class. */
25   public MethodDeclaration constructor;
26
27   /**
28    * Tell if the class has a constructor.
29    * @return a boolean
30    */
31   public boolean hasConstructor() {
32     return constructor != null;
33   }
34
35   /**
36    * Return the class as String.
37    * @param tab how many tabs before the class
38    * @return the code of this class into String
39    */
40   public String toString(int tab) {
41     return tabString(tab) + toStringHeader() + toStringBody(tab);
42   }
43
44   /**
45    * Return the body of the class as String
46    * @param tab how many tabs before the body of the class
47    * @return the body as String
48    */
49   public String toStringBody(int tab) {
50     final StringBuffer buff = new StringBuffer(" {");//$NON-NLS-1$
51     if (fields != null) {
52       for (int fieldI = 0; fieldI < fields.length; fieldI++) {
53         if (fields[fieldI] != null) {
54           buff.append("\n"); //$NON-NLS-1$
55           buff.append(fields[fieldI].toString(tab + 1));
56           buff.append(";");//$NON-NLS-1$
57         }
58       }
59     }
60     if (methods != null) {
61       for (int i = 0; i < methods.length; i++) {
62         if (methods[i] != null) {
63           buff.append("\n");//$NON-NLS-1$
64           buff.append(methods[i].toString(tab + 1));
65         }
66       }
67     }
68     buff.append("\n").append(tabString(tab)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
69     return buff.toString();
70   }
71
72   /**
73    * Return the header of the class as String.
74    * @return the header of the class
75    */
76   public String toStringHeader() {
77     final StringBuffer buff = new StringBuffer("class").append(name);//$NON-NLS-1$
78     if (superclass != null) {
79       buff.append(" extends "); //$NON-NLS-1$
80       buff.append(superclass);
81     }
82     return buff.toString();
83   }
84 }