- added include declarations to Outline view
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / core / CompilationUnitStructureRequestor.java
index ce3680d..2e24f0c 100644 (file)
@@ -13,8 +13,10 @@ package net.sourceforge.phpdt.internal.core;
 import java.util.Map;
 import java.util.Stack;
 
+import net.sourceforge.phpdt.core.Flags;
 import net.sourceforge.phpdt.core.ICompilationUnit;
 import net.sourceforge.phpdt.core.IField;
+import net.sourceforge.phpdt.core.IImportContainer;
 import net.sourceforge.phpdt.core.IJavaElement;
 import net.sourceforge.phpdt.core.IMethod;
 import net.sourceforge.phpdt.core.IType;
@@ -133,41 +135,42 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
   /**
    * @see ISourceElementRequestor
    */
-  //public void acceptImport(int declarationStart, int declarationEnd, char[] name, boolean onDemand) {
-  //   JavaElementInfo parentInfo = (JavaElementInfo) fInfoStack.peek();
-  //   JavaElement parentHandle= (JavaElement)fHandleStack.peek();
-  //   if (!(parentHandle.getElementType() == IJavaElement.COMPILATION_UNIT)) {
-  //           Assert.isTrue(false); // Should not happen
-  //   }
-  //
-  //   ICompilationUnit parentCU= (ICompilationUnit)parentHandle;
-  //   //create the import container and its info
-  //   IImportContainer importContainer= parentCU.getImportContainer();
-  //   if (fImportContainerInfo == null) {
-  //           fImportContainerInfo= new JavaElementInfo();
-  //           fImportContainerInfo.setIsStructureKnown(true);
-  //           parentInfo.addChild(importContainer);
-  //           fNewElements.put(importContainer, fImportContainerInfo);
-  //   }
-  //   
-  //   // tack on the '.*' if it is onDemand
-  //   String importName;
-  //   if (onDemand) {
-  //           importName= new String(name) + ".*"; //$NON-NLS-1$
-  //   } else {
-  //           importName= new String(name);
-  //   }
-  //   
-  //   ImportDeclaration handle = new ImportDeclaration(importContainer, importName);
-  //   resolveDuplicates(handle);
-  //   
-  //   SourceRefElementInfo info = new SourceRefElementInfo();
-  //   info.setSourceRangeStart(declarationStart);
-  //   info.setSourceRangeEnd(declarationEnd);
-  //
-  //   fImportContainerInfo.addChild(handle);
-  //   fNewElements.put(handle, info);
-  //}
+  public void acceptImport(int declarationStart, int declarationEnd, char[] name, boolean onDemand) {
+       JavaElementInfo parentInfo = (JavaElementInfo) fInfoStack.peek();
+       JavaElement parentHandle= (JavaElement)fHandleStack.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);
+               parentInfo.addChild(importContainer);
+               fNewElements.put(importContainer, fImportContainerInfo);
+       }
+       
+       // tack on the '.*' if it is onDemand
+       String importName;
+       if (onDemand) {
+               importName= new String(name) + ".*"; //$NON-NLS-1$
+       } else {
+               importName= new String(name);
+       }
+       
+       ImportDeclaration handle = new ImportDeclaration(importContainer, importName);
+//     ImportDeclaration handle = new ImportDeclaration(null, importName);
+//     resolveDuplicates(handle);
+       
+       SourceRefElementInfo info = new SourceRefElementInfo();
+       info.setSourceRangeStart(declarationStart);
+       info.setSourceRangeEnd(declarationEnd);
+  
+       fImportContainerInfo.addChild(handle);
+       fNewElements.put(handle, info);
+  }
   /*
    * 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.
@@ -274,6 +277,7 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
       exceptionTypes,
       true);
   }
+
   /**
    * @see ISourceElementRequestor
    */
@@ -284,7 +288,7 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
     IField handle = null;
 
     if (parentHandle.getElementType() == IJavaElement.TYPE) {
-      handle = new SourceField((IType) parentHandle, new String(name));
+      handle = new SourceField(parentHandle, new String(name));
     } else {
       Assert.isTrue(false); // Should not happen
     }
@@ -407,15 +411,15 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
     }
 
     String[] parameterTypeSigs = convertTypeNamesToSigs(parameterTypes);
-    if (parentHandle.getElementType() == IJavaElement.TYPE) {
-      handle = new SourceMethod((IType) parentHandle, new String(name), parameterTypeSigs);
-    } else if (parentHandle.getElementType() == IJavaElement.COMPILATION_UNIT) {
-      handle = new SourceMethod((ICompilationUnit) parentHandle, name==null?"":new String(name), parameterTypeSigs);
-    } else {
-      Assert.isTrue(false); // Should not happen
-    }
-    resolveDuplicates(handle);
-
+    // TODO : jsurfer changed
+//     if (parentHandle.getElementType() == IJavaElement.TYPE) {
+               handle = new SourceMethod(parentHandle, new String(name), parameterTypeSigs);
+//     }
+//     else {
+//             Assert.isTrue(false); // Should not happen
+//     }
+       resolveDuplicates(handle);
+       
     SourceMethodElementInfo info = new SourceMethodElementInfo();
     info.setSourceRangeStart(declarationStart);
     int flags = modifiers;
@@ -523,30 +527,30 @@ public class CompilationUnitStructureRequestor extends ReferenceInfoAdapter impl
   public void exitConstructor(int declarationEnd) {
     exitMember(declarationEnd);
   }
-  ///**
-  // * @see ISourceElementRequestor
-  // */
-  //public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) {
-  //   SourceFieldElementInfo info = (SourceFieldElementInfo) fInfoStack.pop();
-  //   info.setSourceRangeEnd(declarationSourceEnd);
-  //   
-  //   // remember initializer source if field is a constant
-  //   if (initializationStart != -1) {
-  //           int flags = info.flags;
-  //           Object typeInfo;
-  //           if (Flags.isStatic(flags) && Flags.isFinal(flags)
-  //                           || ((typeInfo = fInfoStack.peek()) instanceof SourceTypeElementInfo
-  //                                    && (Flags.isInterface(((SourceTypeElementInfo)typeInfo).flags)))) {
-  //                   int length = declarationEnd - initializationStart;
-  //                   if (length > 0) {
-  //                           char[] initializer = new char[length];
-  //                           System.arraycopy(this.parser.scanner.source, initializationStart, initializer, 0, length);
-  //                           info.initializationSource = initializer;
-  //                   }
-  //           }
-  //   }
-  //   fHandleStack.pop();
-  //}
+  /**
+   * @see ISourceElementRequestor
+   */
+  public void exitField(int initializationStart, int declarationEnd, int declarationSourceEnd) {
+       SourceFieldElementInfo info = (SourceFieldElementInfo) fInfoStack.pop();
+       info.setSourceRangeEnd(declarationSourceEnd);
+       
+       // remember initializer source if field is a constant
+       if (initializationStart != -1) {
+               int flags = info.flags;
+               Object typeInfo;
+               if (Flags.isStatic(flags) && Flags.isFinal(flags)
+                               || ((typeInfo = fInfoStack.peek()) instanceof SourceTypeElementInfo
+                                        && (Flags.isInterface(((SourceTypeElementInfo)typeInfo).flags)))) {
+                       int length = declarationEnd - initializationStart;
+                       if (length > 0) {
+                               char[] initializer = new char[length];
+                               System.arraycopy(this.parser.scanner.source, initializationStart, initializer, 0, length);
+                               info.initializationSource = initializer;
+                       }
+               }
+       }
+       fHandleStack.pop();
+  }
   /**
    * @see ISourceElementRequestor
    */