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;
23 public MethodDeclaration[] methods;
25 public MethodDeclaration constructor;
28 * Tell if the class has a constructor.
31 public boolean hasConstructor() {
32 return constructor != null;
35 public String toString(int tab) {
37 return tabString(tab) + toStringHeader() + toStringBody(tab);
40 public String toStringBody(int tab) {
41 final StringBuffer buff = new StringBuffer(" {");//$NON-NLS-1$
43 for (int fieldI = 0; fieldI < fields.length; fieldI++) {
44 if (fields[fieldI] != null) {
45 buff.append("\n"); //$NON-NLS-1$
46 buff.append(fields[fieldI].toString(tab + 1));
47 buff.append(";");//$NON-NLS-1$
51 if (methods != null) {
52 for (int i = 0; i < methods.length; i++) {
53 if (methods[i] != null) {
54 buff.append("\n");//$NON-NLS-1$
55 buff.append(methods[i].toString(tab + 1));
59 buff.append("\n").append(tabString(tab)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
60 return buff.toString();
63 public String toStringHeader() {
64 final StringBuffer buff = new StringBuffer("class").append(name);
65 if (superclass != null) {
66 buff.append(" extends "); //$NON-NLS-1$
67 buff.append(superclass);
69 return buff.toString();