improved PHP parser
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / internal / compiler / ast / CompilationUnitDeclaration.java
index b21bac7..53274a0 100644 (file)
@@ -9,15 +9,13 @@
  *     IBM Corporation - initial API and implementation
  *******************************************************************************/
 package net.sourceforge.phpeclipse.internal.compiler.ast;
-
 import java.util.ArrayList;
 
 import net.sourceforge.phpdt.core.compiler.CharOperation;
+import net.sourceforge.phpdt.internal.compiler.ASTVisitor;
 import net.sourceforge.phpdt.internal.compiler.CompilationResult;
-import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
 import net.sourceforge.phpdt.internal.compiler.impl.ReferenceContext;
 import net.sourceforge.phpdt.internal.compiler.lookup.CompilationUnitScope;
-import net.sourceforge.phpdt.internal.compiler.lookup.ImportBinding;
 import net.sourceforge.phpdt.internal.compiler.lookup.LocalTypeBinding;
 import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilationUnit;
 import net.sourceforge.phpdt.internal.compiler.problem.AbortMethod;
@@ -25,12 +23,13 @@ import net.sourceforge.phpdt.internal.compiler.problem.AbortType;
 import net.sourceforge.phpdt.internal.compiler.problem.ProblemReporter;
 import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
 
-public class CompilationUnitDeclaration extends AstNode implements ProblemSeverities, ReferenceContext {
+public class CompilationUnitDeclaration extends ASTNode implements ProblemSeverities, ReferenceContext {
 
   public ImportReference currentPackage;
   public ImportReference[] imports;
   //  public TypeDeclaration[] types;
   public ArrayList types;
+  
   //public char[][] name;
   public int[][] comments;
 
@@ -53,7 +52,6 @@ public class CompilationUnitDeclaration extends AstNode implements ProblemSeveri
     //by definition of a compilation unit....
     sourceStart = 0;
     sourceEnd = sourceLength - 1;
-
   }
 
   /*
@@ -223,7 +221,26 @@ public class CompilationUnitDeclaration extends AstNode implements ProblemSeveri
   public boolean hasErrors() {
     return this.ignoreFurtherInvestigation;
   }
-
+       public StringBuffer print(int indent, StringBuffer output) {
+
+               if (currentPackage != null) {
+                       printIndent(indent, output).append("package "); //$NON-NLS-1$
+                       currentPackage.print(0, output, false).append(";\n"); //$NON-NLS-1$
+               }
+               if (imports != null)
+                       for (int i = 0; i < imports.length; i++) {
+                               printIndent(indent, output).append("import "); //$NON-NLS-1$
+                               imports[i].print(0, output).append(";\n"); //$NON-NLS-1$ 
+                       }
+
+               if (types != null) {
+                       for (int i = 0; i < types.size(); i++) {
+                               ((ASTNode)types.get(i)).print(indent, output).append("\n"); //$NON-NLS-1$
+                       }
+               }
+               return output;
+       }
+       
   /*
    * Force inner local types to update their innerclass emulation
    */
@@ -289,17 +306,17 @@ public class CompilationUnitDeclaration extends AstNode implements ProblemSeveri
 
     if (imports != null)
       for (int i = 0; i < imports.length; i++) {
-        s += tabString(tab) + "import " + imports[i].toString() + ";\n"; //$NON-NLS-1$ //$NON-NLS-2$
+        s += tabString(tab) + "include " + imports[i].toString() + ";\n"; //$NON-NLS-1$ //$NON-NLS-2$
       };
 
     if (types != null)
       for (int i = 0; i < types.size(); i++) {
-        s += ((AstNode) types.get(i)).toString(tab) + "\n"; //$NON-NLS-1$
+        s += ((ASTNode) types.get(i)).toString(tab) + "\n"; //$NON-NLS-1$
       }
     return s;
   }
 
-  public void traverse(IAbstractSyntaxTreeVisitor visitor, CompilationUnitScope scope) {
+  public void traverse(ASTVisitor visitor, CompilationUnitScope scope) {
 
     if (ignoreFurtherInvestigation)
       return;