--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * An abstract variable declaration.
+ * @author Matthieu Casanova
+ */
+public class AbstractVariableDeclaration extends AstNode {
+ /** The name of the variable. */
+ public char[] name;
+
+ /**
+ * Get the name of the field as String.
+ * @return the name of the String
+ */
+ public String name() {
+ return String.valueOf(name);
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * An argument declaration.
+ * @author Matthieu Casanova
+ */
+public class ArgumentDeclaration extends VariableDeclaration {
+
+ public boolean reference;
+ /**
+ * Create an argument.
+ * @param initialization the initialization
+ * @param name the name
+ * @param sourceStart the start point
+ * @param sourceEnd the end point
+ */
+ public ArgumentDeclaration(Expression initialization,
+ char[] name,
+ int sourceStart,
+ int sourceEnd,
+ boolean reference) {
+ super(initialization,name, sourceStart, sourceEnd);
+ this.reference = reference;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * It will be the mother of our own ast tree for php just like the ast tree of Eclipse.
+ * @author Matthieu Casanova
+ */
+public abstract class AstNode {
+
+ public int sourceStart, sourceEnd;
+
+ /**
+ * Add some tabulations.
+ * @param tab the number of tabulations
+ * @return a String containing some spaces
+ */
+ public static String tabString(int tab) {
+ StringBuffer s = new StringBuffer();
+ for (int i = tab; i > 0; i--)
+ s.append(" "); //$NON-NLS-1$
+ return s.toString();
+ }
+
+ public String toString() {
+ return toString(0);
+ }
+
+ public String toString(int tab) {
+ return "****" + super.toString() + "****"; //$NON-NLS-2$ //$NON-NLS-1$
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A Block is
+ * {
+ * statements
+ * }.
+ * @author Matthieu Casanova
+ */
+public class Block extends Statement {
+ public Statement[] statements;
+
+ public boolean isEmptyBlock() {
+ return statements == null;
+ }
+
+ public String toString(int tab) {
+ final String s = tabString(tab);
+ final StringBuffer buff = new StringBuffer(s);
+ if (this.statements == null) {
+ buff.append("{\n"); //$NON-NLS-1$
+ buff.append(s);
+ buff.append("}"); //$NON-NLS-1$
+ return s;
+ }
+ buff.append("{\n"); //$NON-NLS-1$
+ buff.append(this.toStringStatements(tab));
+ buff.append(s);
+ buff.append("}"); //$NON-NLS-1$
+ return s;
+ }
+
+ public String toStringStatements(int tab) {
+ if (this.statements == null)
+ return ""; //$NON-NLS-1$
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0; i < statements.length; i++) {
+ buffer.append(statements[i].toString(tab + 1));
+ if (statements[i] instanceof Block) {
+ buffer.append("\n"); //$NON-NLS-1$
+ } else {
+ buffer.append(";\n"); //$NON-NLS-1$
+ }
+ }
+ return buffer.toString();
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * This class is my Class declaration for php.
+ * It is similar to org.eclipse.jdt.internal.compiler.ast.TypeDeclaration
+ * It directly extends AstNode because a class cannot appear anywhere in php
+ * @author Matthieu Casanova
+ */
+public class Class extends AstNode {
+
+ /** The name of the class. */
+ public char[] name;
+ /** The superclass. */
+ public char[] superclass;
+ /** The fields of the class. */
+ public VariableDeclaration[] fields;
+
+ public int declarationSourceStart;
+ public int declarationSourceEnd;
+ public int bodyStart;
+ public int bodyEnd;
+
+ public MethodDeclaration[] methods;
+
+ public MethodDeclaration constructor;
+
+ /**
+ * Tell if the class has a constructor.
+ * @return a boolean
+ */
+ public boolean hasConstructor() {
+ return constructor != null;
+ }
+
+ public String toString(int tab) {
+
+ return tabString(tab) + toStringHeader() + toStringBody(tab);
+ }
+
+ public String toStringBody(int tab) {
+ final StringBuffer buff = new StringBuffer(" {");//$NON-NLS-1$
+ if (fields != null) {
+ for (int fieldI = 0; fieldI < fields.length; fieldI++) {
+ if (fields[fieldI] != null) {
+ buff.append("\n"); //$NON-NLS-1$
+ buff.append(fields[fieldI].toString(tab + 1));
+ buff.append(";");//$NON-NLS-1$
+ }
+ }
+ }
+ if (methods != null) {
+ for (int i = 0; i < methods.length; i++) {
+ if (methods[i] != null) {
+ buff.append("\n");//$NON-NLS-1$
+ buff.append(methods[i].toString(tab + 1));
+ }
+ }
+ }
+ buff.append("\n").append(tabString(tab)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
+ return buff.toString();
+ }
+
+ public String toStringHeader() {
+ final StringBuffer buff = new StringBuffer("class").append(name);
+ if (superclass != null) {
+ buff.append(" extends "); //$NON-NLS-1$
+ buff.append(superclass);
+ }
+ return buff.toString();
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * An expression.
+ * @author Matthieu Casanova
+ */
+public class Expression extends AstNode {
+
+ public String toString(int tab) {
+ String s = tabString(tab);
+ return s + toStringExpression(tab);
+ }
+
+ //Subclass re-define toStringExpression
+//This method is abstract and should never be called
+//but we provide some code that is running.....just in case
+//of developpement time (while every thing is not built)
+ public String toStringExpression() {
+ return super.toString(0);
+ }
+
+ public String toStringExpression(int tab) {
+ // default is regular toString expression (qualified allocation expressions redifine this method)
+ return this.toStringExpression();
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A Method declaration.
+ * @author Matthieu Casanova
+ */
+public class MethodDeclaration extends Statement {
+
+ public char[] name;
+ public ArgumentDeclaration[] arguments;
+ public Statement[] statements;
+ public int bodyStart;
+ public int bodyEnd = -1;
+ public boolean isConstructor;
+
+ /**
+ * Return method into String, with a number of tabs
+ * @param tab the number of tabs
+ * @return the String containing the method
+ */
+ public String toString(int tab) {
+ String s = tabString(tab);
+ StringBuffer buff = new StringBuffer(s);
+ buff.append(name).append("(");//$NON-NLS-1$
+
+ if (arguments != null) {
+ for (int i = 0; i < arguments.length; i++) {
+ buff.append(arguments[i].toString(0));
+ if (i != (arguments.length - 1)) {
+ buff.append(", "); //$NON-NLS-1$
+ }
+ }
+ }
+ buff.append(")"); //$NON-NLS-1$
+
+ s += toStringStatements(tab + 1);
+ return s;
+ }
+
+ /**
+ * Return the statements of the method into Strings
+ * @param tab the number of tabs
+ * @return the String containing the statements
+ */
+ public String toStringStatements(int tab) {
+ StringBuffer buff = new StringBuffer(" {"); //$NON-NLS-1$
+ if (statements != null) {
+ for (int i = 0; i < statements.length; i++) {
+ buff.append("\n").append(statements[i].toString(tab)); //$NON-NLS-1$
+ if (!(statements[i] instanceof Block)) {
+ buff.append(";"); //$NON-NLS-1$
+ }
+ }
+ }
+ buff.append("\n").append(tabString(tab == 0 ? 0 : tab - 1)).append("}"); //$NON-NLS-2$ //$NON-NLS-1$
+ return buff.toString();
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A Statement.
+ * @author Matthieu Casanova
+ */
+public class Statement extends AstNode {
+
+ public Statement() {
+ }
+
+ public boolean isEmptyBlock() {
+ return false;
+ }
+}
--- /dev/null
+package net.sourceforge.phpdt.internal.compiler.ast;
+
+/**
+ * A variable declaration.
+ * @author Matthieu Casanova
+ */
+public class VariableDeclaration extends AbstractVariableDeclaration {
+
+ /** The value for variable initialization. */
+ public Expression initialization;
+
+ /**
+ * Create a variable.
+ * @param initialization the initialization
+ * @param name the name
+ * @param sourceStart the start point
+ * @param sourceEnd the end point
+ */
+ public VariableDeclaration(Expression initialization,
+ char[] name,
+ int sourceStart,
+ int sourceEnd) {
+ this.initialization = initialization;
+ this.name = name;
+ //due to some declaration like
+ // int x, y = 3, z , x ;
+ //the sourceStart and the sourceEnd is ONLY on the name
+ this.sourceStart = sourceStart;
+ this.sourceEnd = sourceEnd;
+ }
+
+ public String toString(int tab) {
+ String s = tabString(tab);
+ if (initialization != null) {
+ s += " = " + initialization.toStringExpression(tab); //$NON-NLS-1$
+ }
+ return s;
+ }
+}