misc
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / Compiler.java
index 922ef27..ea02cbb 100644 (file)
@@ -12,6 +12,7 @@ package net.sourceforge.phpdt.internal.compiler;
 import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Map;
+
 import net.sourceforge.phpdt.core.compiler.IProblem;
 import net.sourceforge.phpdt.internal.compiler.env.IBinaryType;
 import net.sourceforge.phpdt.internal.compiler.env.ICompilationUnit;
@@ -29,6 +30,7 @@ import net.sourceforge.phpdt.internal.compiler.problem.ProblemSeverities;
 import net.sourceforge.phpdt.internal.compiler.util.Util;
 import net.sourceforge.phpeclipse.internal.compiler.ast.CompilationUnitDeclaration;
 import net.sourceforge.phpeclipse.internal.compiler.ast.TypeDeclaration;
+
 public class Compiler implements ITypeRequestor, ProblemSeverities {
   public UnitParser parser;
   public ICompilerRequestor requestor;
@@ -41,7 +43,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 = true;
+  public static boolean DEBUG = false;
   public int parseThreshold = -1;
   // number of initial units parsed at once (-1: none)
   /*
@@ -491,6 +493,72 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
     //         if (DebugRequestor != null) DebugRequestor.reset();
   }
   /**
+        * Internal API used to resolve a given compilation unit. Can run a subset of the compilation process
+        */
+       public CompilationUnitDeclaration resolve(
+                       CompilationUnitDeclaration unit, 
+                       ICompilationUnit sourceUnit, 
+                       boolean verifyMethods,
+                       boolean analyzeCode) {
+                               
+               try {
+                       if (unit == null) {
+                               // build and record parsed units
+                               parseThreshold = 0; // will request a full parse
+                               beginToCompile(new ICompilationUnit[] { sourceUnit });
+                               // process all units (some more could be injected in the loop by the lookup environment)
+                               unit = unitsToProcess[0];
+                       } else {
+                               // initial type binding creation
+                               lookupEnvironment.buildTypeBindings(unit);
+
+                               // binding resolution
+                               lookupEnvironment.completeTypeBindings();
+                       }
+                       // TODO : jsurfer check this
+//                     this.parser.getMethodBodies(unit);
+                       getMethodBodies(unit, 0);
+                       
+                       if (unit.scope != null) {
+                               // fault in fields & methods
+                               unit.scope.faultInTypes();
+                               if (unit.scope != null && verifyMethods) {
+                                       // http://dev.eclipse.org/bugs/show_bug.cgi?id=23117
+                                       // verify inherited methods
+                                       unit.scope.verifyMethods(lookupEnvironment.methodVerifier());
+                               }
+                               // type checking
+                               unit.resolve();         
+
+                               // flow analysis
+//                             if (analyzeCode) unit.analyseCode();
+               
+                               // code generation
+//                             if (generateCode) unit.generateCode();
+                       }
+                       if (unitsToProcess != null) unitsToProcess[0] = null; // release reference to processed unit declaration
+                       requestor.acceptResult(unit.compilationResult.tagAsAccepted());
+                       return unit;
+               } catch (AbortCompilation e) {
+                       this.handleInternalException(e, unit);
+                       return unit == null ? unitsToProcess[0] : unit;
+               } catch (Error e) {
+                       this.handleInternalException(e, unit, null);
+                       throw e; // rethrow
+               } catch (RuntimeException e) {
+                       this.handleInternalException(e, unit, null);
+                       throw e; // rethrow
+               } finally {
+                       // No reset is performed there anymore since,
+                       // within the CodeAssist (or related tools),
+                       // the compiler may be called *after* a call
+                       // to this resolve(...) method. And such a call
+                       // needs to have a compiler with a non-empty
+                       // environment.
+                       // this.reset();
+               }
+       }
+  /**
    * Internal API used to resolve a given compilation unit. Can run a subset of
    * the compilation process
    */
@@ -544,4 +612,5 @@ public class Compiler implements ITypeRequestor, ProblemSeverities {
       // this.reset();
     }
   }
+
 }