X-Git-Url: http://secure.phpeclipse.com diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java index 25fc716..9c5bf07 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/ast/ClassDeclaration.java @@ -3,10 +3,12 @@ package net.sourceforge.phpdt.internal.compiler.ast; import net.sourceforge.phpdt.internal.compiler.parser.Outlineable; import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren; import net.sourceforge.phpdt.internal.ui.PHPUiImages; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.text.Position; import java.util.ArrayList; -import java.util.Enumeration; +import java.util.List; /** @@ -27,7 +29,7 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr public int bodyStart; public int bodyEnd; /** The methods of the class. */ - private ArrayList methods = new ArrayList(); + private final ArrayList methods = new ArrayList(); /** The constructor of the class. */ public MethodDeclaration constructor; /** The fields of the class. */ @@ -37,6 +39,7 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr /** The outlineable children (those will be in the node array too. */ private ArrayList children = new ArrayList(); + private Position position; /** * Create a class giving starting and ending offset * @param sourceStart starting offset @@ -51,9 +54,10 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr this.parent = parent; this.name = name; this.superclass = superclass; + position = new Position(sourceStart, name.length); } - /** + /** * Create a class giving starting and ending offset * @param sourceStart starting offset * @param sourceEnd ending offset @@ -65,17 +69,18 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr super(sourceStart, sourceEnd); this.parent = parent; this.name = name; + position = new Position(sourceStart, name.length); } - public void addMethod(MethodDeclaration method) { - method.add(method); - children.add(method); + public void add(MethodDeclaration method) { + methods.add(method); + add(method); if (method.name.equals(name)) { constructor = method; } } - public void addVariable(FieldDeclaration var) { + public void add(FieldDeclaration var) { for (int i = 0; i < var.vars.length; i++) { VariableDeclaration c = var.vars[i]; children.add(c); @@ -83,6 +88,10 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr fields.add(var); } + public boolean add(Outlineable o) { + return children.add(o); + } + /** * Tell if the class has a constructor. * @return a boolean @@ -115,12 +124,10 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr buff.append(";");//$NON-NLS-1$ } } - if (methods != null) { - for (int i = 0; i < methods.size(); i++) { - MethodDeclaration o = (MethodDeclaration) methods.get(i); - buff.append("\n");//$NON-NLS-1$ - buff.append(o.toString(tab + 1)); - } + for (int i = 0; i < methods.size(); i++) { + MethodDeclaration o = (MethodDeclaration) methods.get(i); + buff.append("\n");//$NON-NLS-1$ + buff.append(o.toString(tab + 1)); } buff.append("\n").append(tabString(tab)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$ return buff.toString(); @@ -131,7 +138,7 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr * @return the header of the class */ public String toStringHeader() { - final StringBuffer buff = new StringBuffer("class").append(name);//$NON-NLS-1$ + final StringBuffer buff = new StringBuffer("class ").append(name);//$NON-NLS-1$ if (superclass != null) { buff.append(" extends "); //$NON-NLS-1$ buff.append(superclass); @@ -151,15 +158,29 @@ public class ClassDeclaration extends Statement implements OutlineableWithChildr return parent; } - public boolean add(Outlineable o) { - return children.add(o); - } - public Outlineable get(int index) { return (Outlineable) children.get(index); } public int size() { + PHPeclipsePlugin.log(1,"class size : "+children.size()); return children.size(); } + + public String toString() { + final StringBuffer buff = new StringBuffer(new String(name));//$NON-NLS-1$ + if (superclass != null) { + buff.append(":"); //$NON-NLS-1$ + buff.append(superclass); + } + return buff.toString(); + } + + public Position getPosition() { + return position; + } + + public List getList() { + return children; + } }