improved PHP parser
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / CompilationUnitStructureRequestor.java
index 8b9fcb0..a09a6c6 100644 (file)
  *******************************************************************************/
 package net.sourceforge.phpdt.internal.core;
 
+import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Stack;
 
+import net.sourceforge.phpdt.internal.core.ImportContainer;
+import net.sourceforge.phpdt.internal.core.ImportDeclaration;
+import net.sourceforge.phpdt.internal.core.ImportDeclarationElementInfo;
+import net.sourceforge.phpdt.internal.core.JavaElement;
+import net.sourceforge.phpdt.internal.core.JavaElementInfo;
+
 import net.sourceforge.phpdt.core.Flags;
 import net.sourceforge.phpdt.core.ICompilationUnit;
 import net.sourceforge.phpdt.core.IField;
@@ -36,17 +44,17 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
   /**
    * The handle to the compilation unit being parsed
    */
-  protected ICompilationUnit fUnit;
+  protected ICompilationUnit unit;
 
   /**
    * The info object for the compilation unit being parsed
    */
-  protected CompilationUnitElementInfo fUnitInfo;
+  protected CompilationUnitElementInfo unitInfo;
 
   /**
    * The import container info - null until created
    */
-  protected JavaElementInfo fImportContainerInfo = null;
+  protected JavaElementInfo importContainerInfo = null;
 
   /**
    * Hashtable of children elements of the compilation unit.
@@ -54,7 +62,7 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
    * the parser. Keys are handles, values are corresponding
    * info objects.
    */
-  protected Map fNewElements;
+  protected Map newElements;
 
   /**
    * Stack of parent scope info objects. The info on the
@@ -62,14 +70,14 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
    * For example, when we locate a method, the parent info object
    * will be the type the method is contained in.
    */
-  protected Stack fInfoStack;
+  protected Stack infoStack;
 
   /**
    * Stack of parent handles, corresponding to the info stack. We
    * keep both, since info objects do not have back pointers to
    * handles.
    */
-  protected Stack fHandleStack;
+  protected Stack handleStack;
 
   /**
    * The name of the source file being parsed.
@@ -126,29 +134,31 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
 
   protected CompilationUnitStructureRequestor(ICompilationUnit unit, CompilationUnitElementInfo unitInfo, Map newElements)
     throws JavaModelException {
-    this.fUnit = unit;
-    this.fUnitInfo = unitInfo;
-    this.fNewElements = newElements;
+    this.unit = unit;
+    this.unitInfo = unitInfo;
+    this.newElements = newElements;
     this.fSourceFileName = unit.getElementName().toCharArray();
   }
   /**
    * @see ISourceElementRequestor
    */
-  public void acceptImport(int declarationStart, int declarationEnd, char[] name, boolean onDemand) {
-       JavaElementInfo parentInfo = (JavaElementInfo) fInfoStack.peek();
-       JavaElement parentHandle= (JavaElement)fHandleStack.peek();
+  public void acceptImport(int declarationStart, int declarationEnd, char[] name, boolean onDemand)  {
+    //, int modifiers) {
+  
+       JavaElementInfo parentInfo = (JavaElementInfo) this.infoStack.peek();
+       JavaElement parentHandle= (JavaElement) this.handleStack.peek();
        if (!(parentHandle.getElementType() == IJavaElement.COMPILATION_UNIT)) {
                Assert.isTrue(false); // Should not happen
        }
-  
+
        ICompilationUnit parentCU= (ICompilationUnit)parentHandle;
        //create the import container and its info
-       ImportContainer importContainer= parentCU.getImportContainer();
-       if (fImportContainerInfo == null) {
-               fImportContainerInfo= new JavaElementInfo();
-               fImportContainerInfo.setIsStructureKnown(true);
+       ImportContainer importContainer= (ImportContainer)parentCU.getImportContainer();
+       if (this.importContainerInfo == null) {
+               this.importContainerInfo= new JavaElementInfo();
+               this.importContainerInfo.setIsStructureKnown(true);
                parentInfo.addChild(importContainer);
-               fNewElements.put(importContainer, fImportContainerInfo);
+               this.newElements.put(importContainer, this.importContainerInfo);
        }
        
        // tack on the '.*' if it is onDemand
@@ -160,16 +170,22 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
        }
        
        ImportDeclaration handle = new ImportDeclaration(importContainer, importName);
-//     ImportDeclaration handle = new ImportDeclaration(null, importName);
-//     resolveDuplicates(handle);
+       resolveDuplicates(handle);
        
-       SourceRefElementInfo info = new SourceRefElementInfo();
+       ImportDeclarationElementInfo info = new ImportDeclarationElementInfo();
        info.setSourceRangeStart(declarationStart);
        info.setSourceRangeEnd(declarationEnd);
-  
-       fImportContainerInfo.addChild(handle);
-       fNewElements.put(handle, info);
+//     info.setFlags(modifiers);
+       info.setName(name); // no trailing * if onDemand
+       info.setOnDemand(onDemand);
+
+       this.importContainerInfo.addChild(handle);
+       this.newElements.put(handle, info);
   }
+  /**
+   * @see ISourceElementRequestor
+   */
+  
   /*
    * Table of line separator position. This table is passed once at the end
    * of the parse action, so as to allow computation of normalized ranges.
@@ -246,10 +262,10 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
    * @see ISourceElementRequestor
    */
   public void enterCompilationUnit() {
-    fInfoStack = new Stack();
-    fHandleStack = new Stack();
-    fInfoStack.push(fUnitInfo);
-    fHandleStack.push(fUnit);
+    infoStack = new Stack();
+    handleStack = new Stack();
+    infoStack.push(unitInfo);
+    handleStack.push(unit);
   }
   /**
    * @see ISourceElementRequestor
@@ -282,8 +298,8 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
    */
   public void enterField(int declarationStart, int modifiers, char[] type, char[] name, int nameSourceStart, int nameSourceEnd) {
 
-    SourceTypeElementInfo parentInfo = (SourceTypeElementInfo) fInfoStack.peek();
-    JavaElement parentHandle = (JavaElement) fHandleStack.peek();
+    SourceTypeElementInfo parentInfo = (SourceTypeElementInfo) infoStack.peek();
+    JavaElement parentHandle = (JavaElement) handleStack.peek();
     IField handle = null;
 
     if (parentHandle.getElementType() == IJavaElement.TYPE) {
@@ -302,10 +318,10 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
     info.setTypeName(type);
 
     parentInfo.addChild(handle);
-    fNewElements.put(handle, info);
+    newElements.put(handle, info);
 
-    fInfoStack.push(info);
-    fHandleStack.push(handle);
+    infoStack.push(info);
+    handleStack.push(handle);
   }
   /**
    * @see ISourceElementRequestor
@@ -391,11 +407,11 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
     boolean isConstructor) {
     SourceTypeElementInfo parentInfo = null;
     try {
-      parentInfo = (SourceTypeElementInfo) fInfoStack.peek();
+      parentInfo = (SourceTypeElementInfo) infoStack.peek();
     } catch (ClassCastException e) {
       //                       parentInfo = null;
     }
-    JavaElement parentHandle = (JavaElement) fHandleStack.peek();
+    JavaElement parentHandle = (JavaElement) handleStack.peek();
     IMethod handle = null;
 
     // translate nulls to empty arrays
@@ -434,13 +450,13 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
     info.setExceptionTypeNames(exceptionTypes);
 
     if (parentInfo == null) {
-      fUnitInfo.addChild(handle);
+      unitInfo.addChild(handle);
     } else {
       parentInfo.addChild(handle);
     }
-    fNewElements.put(handle, info);
-    fInfoStack.push(info);
-    fHandleStack.push(handle);
+    newElements.put(handle, info);
+    infoStack.push(info);
+    handleStack.push(handle);
   }
   /**
    * Common processing for classes and interfaces.
@@ -457,8 +473,8 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
     char[] enclosingTypeName = null;
     char[] qualifiedName = null;
 
-    JavaElementInfo parentInfo = (JavaElementInfo) fInfoStack.peek();
-    JavaElement parentHandle = (JavaElement) fHandleStack.peek();
+    JavaElementInfo parentInfo = (JavaElementInfo) infoStack.peek();
+    JavaElement parentHandle = (JavaElement) handleStack.peek();
     IType handle = null;
     String nameString = new String(name);
 
@@ -498,10 +514,10 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
     // }
 
     parentInfo.addChild(handle);
-    fNewElements.put(handle, info);
+    newElements.put(handle, info);
 
-    fInfoStack.push(info);
-    fHandleStack.push(handle);
+    infoStack.push(info);
+    handleStack.push(handle);
 
   }
   /**
@@ -515,10 +531,10 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
    * @see ISourceElementRequestor
    */
   public void exitCompilationUnit(int declarationEnd) {
-    fUnitInfo.setSourceLength(declarationEnd + 1);
+    unitInfo.setSourceLength(declarationEnd + 1);
 
     // determine if there were any parsing errors
-    fUnitInfo.setIsStructureKnown(!this.hasSyntaxErrors);
+    unitInfo.setIsStructureKnown(!this.hasSyntaxErrors);
   }
   /**
    * @see ISourceElementRequestor
@@ -530,7 +546,7 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
    * @see ISourceElementRequestor
    */
   public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) {
-       SourceFieldElementInfo info = (SourceFieldElementInfo) fInfoStack.pop();
+       SourceFieldElementInfo info = (SourceFieldElementInfo) infoStack.pop();
        info.setSourceRangeEnd(declarationSourceEnd);
        
        // remember initializer source if field is a constant
@@ -538,7 +554,7 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
                int flags = info.flags;
                Object typeInfo;
                if (Flags.isStatic(flags) && Flags.isFinal(flags)
-                               || ((typeInfo = fInfoStack.peek()) instanceof SourceTypeElementInfo
+                               || ((typeInfo = infoStack.peek()) instanceof SourceTypeElementInfo
                                         && (Flags.isInterface(((SourceTypeElementInfo)typeInfo).flags)))) {
                        int length = declarationEnd - initializationStart;
                        if (length > 0) {
@@ -548,7 +564,7 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
                        }
                }
        }
-       fHandleStack.pop();
+       handleStack.pop();
   }
   /**
    * @see ISourceElementRequestor
@@ -566,9 +582,9 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
    * common processing for classes and interfaces
    */
   protected void exitMember(int declarationEnd) {
-    SourceRefElementInfo info = (SourceRefElementInfo) fInfoStack.pop();
+    SourceRefElementInfo info = (SourceRefElementInfo) infoStack.pop();
     info.setSourceRangeEnd(declarationEnd);
-    fHandleStack.pop();
+    handleStack.pop();
   }
   /**
    * @see ISourceElementRequestor
@@ -582,7 +598,7 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
    * of the handle being created until there is no conflict.
    */
   protected void resolveDuplicates(IJavaElement handle) {
-    while (fNewElements.containsKey(handle)) {
+    while (newElements.containsKey(handle)) {
       JavaElement h = (JavaElement) handle;
       h.setOccurrenceCount(h.getOccurrenceCount() + 1);
     }