1 package net.sourceforge.phpdt.internal.compiler.ast;
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
9 public class Class extends AstNode {
11 /** The name of the class. */
13 /** The superclass. */
14 public char[] superclass;
15 /** The fields of the class. */
16 public VariableDeclaration[] fields;
18 public int declarationSourceStart;
19 public int declarationSourceEnd;
22 /** The methods of the class. */
23 public MethodDeclaration[] methods;
24 /** The constructor of the class. */
25 public MethodDeclaration constructor;
28 * Tell if the class has a constructor.
31 public boolean hasConstructor() {
32 return constructor != null;
36 * Return the class as String.
37 * @param tab how many tabs before the class
38 * @return the code of this class into String
40 public String toString(int tab) {
41 return tabString(tab) + toStringHeader() + toStringBody(tab);
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
49 public String toStringBody(int tab) {
50 final StringBuffer buff = new StringBuffer(" {");//$NON-NLS-1$
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$
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));
68 buff.append("\n").append(tabString(tab)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
69 return buff.toString();
73 * Return the header of the class as String.
74 * @return the header of the class
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);
82 return buff.toString();