Added "Task Tags" functionality (TODO,...)
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / Compiler.java
index a8f006c..922ef27 100644 (file)
@@ -17,6 +17,7 @@ import net.sourceforge.phpdt.internal.compiler.env.IBinaryType;
 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
 import net.sourceforge.phpdt.internal.compiler.env.INameEnvironment;
 import net.sourceforge.phpdt.internal.compiler.env.ISourceType;
+import net.sourceforge.phpdt.internal.compiler.impl.CompilerOptions;
 import net.sourceforge.phpdt.internal.compiler.impl.ITypeRequestor;
 import net.sourceforge.phpdt.internal.compiler.lookup.LookupEnvironment;
 import net.sourceforge.phpdt.internal.compiler.lookup.PackageBinding;
@@ -31,7 +32,7 @@ import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
 public class Compiler implements ITypeRequestor, ProblemSeverities {
   public UnitParser parser;
   public ICompilerRequestor requestor;
-  //   public CompilerOptions options;
+  public CompilerOptions options;
   public ProblemReporter problemReporter;
   // management of unit to be processed
   //public CompilationUnitResult currentCompilationUnitResult;
@@ -40,7 +41,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
   // name lookup
   public LookupEnvironment lookupEnvironment;
   // ONCE STABILIZED, THESE SHOULD RETURN TO A FINAL FIELD
-  public static boolean DEBUG = false;
+  public static boolean DEBUG = true;
   public int parseThreshold = -1;
   // number of initial units parsed at once (-1: none)
   /*
@@ -92,11 +93,11 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
    *            problems, the compiler will gather them all and hand them back
    *            as part of the compilation unit result.
    */
-  public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy, 
-  //           Map settings,
-      final ICompilerRequestor requestor, IProblemFactory problemFactory) {
+  public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy,
+      Map settings, final ICompilerRequestor requestor,
+      IProblemFactory problemFactory) {
     // create a problem handler given a handling policy
-    //         this.options = new CompilerOptions(settings);
+    this.options = new CompilerOptions(settings);
     // wrap requestor in DebugRequestor if one is specified
     //         if(DebugRequestor == null) {
     this.requestor = requestor;
@@ -110,8 +111,8 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
     //                         }
     //                 };
     //         }
-    this.problemReporter = new ProblemReporter(policy, problemFactory);//this.options,
-                                                                       // problemFactory);
+    this.problemReporter = new ProblemReporter(policy, this.options,
+        problemFactory);
     this.lookupEnvironment = new LookupEnvironment(this, problemReporter,
         environment); //options, problemReporter, environment);
     this.parser = new UnitParser(problemReporter);
@@ -164,12 +165,11 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
    *            literals or leave them as they are in the source. If you put
    *            true, "Hello" + " world" will be converted to "Hello world".
    */
-  public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy, 
-  //           Map settings,
-      final ICompilerRequestor requestor, IProblemFactory problemFactory,
-      boolean parseLiteralExpressionsAsConstants) {
+  public Compiler(INameEnvironment environment, IErrorHandlingPolicy policy,
+      Map settings, final ICompilerRequestor requestor,
+      IProblemFactory problemFactory, boolean parseLiteralExpressionsAsConstants) {
     // create a problem handler given a handling policy
-    //         this.options = new CompilerOptions(settings);
+    this.options = new CompilerOptions(settings);
     // wrap requestor in DebugRequestor if one is specified
     //         if(DebugRequestor == null) {
     this.requestor = requestor;
@@ -183,9 +183,8 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
     //                         }
     //                 };
     //         }
-    this.problemReporter = new ProblemReporter(policy, problemFactory);//,
-                                                                       // this.options,
-                                                                       // problemFactory);
+    this.problemReporter = new ProblemReporter(policy, this.options,
+        problemFactory);
     this.lookupEnvironment = new LookupEnvironment(this, problemReporter,
         environment);//options, problemReporter, environment);
     this.parser = new UnitParser(problemReporter);
@@ -206,7 +205,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
     // Switch the current policy and compilation result for this unit to the
     // requested one.
     CompilationResult unitResult = new CompilationResult(sourceUnit,
-        totalUnits, totalUnits, 10); //this.options.maxProblemsPerUnit);
+        totalUnits, totalUnits, this.options.maxProblemsPerUnit);
     try {
       // diet parsing for large collection of unit
       CompilationUnitDeclaration parsedUnit;
@@ -215,16 +214,11 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
       } else {
         parsedUnit = parser.dietParse(sourceUnit, unitResult);
       }
-      //                       if (options.verbose) {
-      //                               String count = String.valueOf(totalUnits + 1);
-      //                               System.out.println(
-      //                                       Util.bind(
-      //                                               "compilation.request" , //$NON-NLS-1$
-      //                                               new String[] {
-      //                                                       count,
-      //                                                       count,
-      //                                                       new String(sourceUnit.getFileName())}));
-      //                       }
+      if (options.verbose) {
+        String count = String.valueOf(totalUnits + 1);
+        System.out.println(Util.bind("compilation.request", //$NON-NLS-1$
+            new String[]{count, count, new String(sourceUnit.getFileName())}));
+      }
       // initial type binding creation
       lookupEnvironment.buildTypeBindings(parsedUnit);
       this.addCompilationUnit(sourceUnit, parsedUnit);
@@ -274,7 +268,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
     for (int i = 0; i < maxUnits; i++) {
       CompilationUnitDeclaration parsedUnit;
       CompilationResult unitResult = new CompilationResult(sourceUnits[i], i,
-          maxUnits, 10);//, this.options.maxProblemsPerUnit);
+          maxUnits, this.options.maxProblemsPerUnit);
       try {
         // diet parsing for large collection of units
         if (totalUnits < parseThreshold) {
@@ -282,17 +276,13 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
         } else {
           parsedUnit = parser.dietParse(sourceUnits[i], unitResult);
         }
-        //                             if (options.verbose) {
-        //                                     System.out.println(
-        //                                             Util.bind(
-        //                                                     "compilation.request" , //$NON-NLS-1$
-        //                                                     new String[] {
-        //                                                             String.valueOf(i + 1),
-        //                                                             String.valueOf(maxUnits),
-        //                                                             new String(sourceUnits[i].getFileName())}));
-        //                             }
+        if (options.verbose) {
+          System.out.println(Util.bind("compilation.request", //$NON-NLS-1$
+              new String[]{String.valueOf(i + 1), String.valueOf(maxUnits),
+                  new String(sourceUnits[i].getFileName())}));
+        }
         // initial type binding creation
-//        lookupEnvironment.buildTypeBindings(parsedUnit);
+        //        lookupEnvironment.buildTypeBindings(parsedUnit);
         this.addCompilationUnit(sourceUnits[i], parsedUnit);
         //} catch (AbortCompilationUnit e) {
         //requestor.acceptResult(unitResult.tagAsAccepted());
@@ -318,30 +308,24 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
       for (; i < totalUnits; i++) {
         unit = unitsToProcess[i];
         try {
-          //                                   if (options.verbose)
-          //                                           System.out.println(
-          //                                                   Util.bind(
-          //                                                           "compilation.process" , //$NON-NLS-1$
-          //                                                           new String[] {
-          //                                                                   String.valueOf(i + 1),
-          //                                                                   String.valueOf(totalUnits),
-          //                                                                   new String(unitsToProcess[i].getFileName())}));
+          if (options.verbose)
+            System.out.println(Util.bind("compilation.process", //$NON-NLS-1$
+                new String[]{String.valueOf(i + 1), String.valueOf(totalUnits),
+                    new String(unitsToProcess[i].getFileName())}));
           process(unit, i);
         } finally {
           // cleanup compilation unit result
           unit.cleanUp();
-          //                                   if (options.verbose)
-          //                                           System.out.println(Util.bind("compilation.done", //$NON-NLS-1$
-          //                                   new String[] {
-          //                                           String.valueOf(i + 1),
-          //                                           String.valueOf(totalUnits),
-          //                                           new String(unitsToProcess[i].getFileName())}));
+          if (options.verbose)
+            System.out.println(Util.bind("compilation.done", //$NON-NLS-1$
+                new String[]{String.valueOf(i + 1), String.valueOf(totalUnits),
+                    new String(unitsToProcess[i].getFileName())}));
         }
         unitsToProcess[i] = null; // release reference to processed unit
-                                  // declaration
+        // declaration
         requestor.acceptResult(unit.compilationResult.tagAsAccepted());
       }
-    } catch (AbortCompilation e) {
+    } catch (AbortCompilation e) { 
       this.handleInternalException(e, unit);
     } catch (Error e) {
       this.handleInternalException(e, unit, null);
@@ -482,12 +466,12 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
    */
   public void process(CompilationUnitDeclaration unit, int i) {
     getMethodBodies(unit, i);
-    // fault in fields & methods  
-    if (unit.scope != null)  
+    // fault in fields & methods
+    if (unit.scope != null)
       unit.scope.faultInTypes();
     // verify inherited methods
-//    if (unit.scope != null)
-//      unit.scope.verifyMethods(lookupEnvironment.methodVerifier());
+    //    if (unit.scope != null)
+    //      unit.scope.verifyMethods(lookupEnvironment.methodVerifier());
     // type checking
     unit.resolve();
     // flow analysis
@@ -538,7 +522,7 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
         //                             if (generateCode) unit.generateCode();
       }
       unitsToProcess[0] = null; // release reference to processed unit
-                                // declaration
+      // declaration
       requestor.acceptResult(unit.compilationResult.tagAsAccepted());
       return unit;
     } catch (AbortCompilation e) {