bug fix: HTML Context information should be show properlyfor completion processor
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / builder / IdentifierIndexManager.java
index b72d55d..1047779 100644 (file)
@@ -8,10 +8,13 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
+import java.util.SortedMap;
 import java.util.StringTokenizer;
+import java.util.TreeMap;
 
 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
 import net.sourceforge.phpdt.core.compiler.InvalidInputException;
@@ -88,6 +91,7 @@ public class IdentifierIndexManager {
 
     private void parseDeclarations(StringBuffer buf, boolean goBack) {
       char[] ident;
+                       char[] classVariable;
       int counter = 0;
       int phpdocOffset = -1;
       int phpdocLength = -1;
@@ -107,7 +111,9 @@ public class IdentifierIndexManager {
             getNextToken();
             if (fToken == TokenNameVariable) {
               ident = fScanner.getCurrentIdentifierSource();
-              addIdentifierInformation('v', ident, buf, phpdocOffset, phpdocLength);
+                                                       classVariable = new char[ident.length-1];
+                                                       System.arraycopy(ident, 1, classVariable, 0, ident.length-1);
+              addIdentifierInformation('v', classVariable, buf, phpdocOffset, phpdocLength);
               getNextToken();
             }
           } else if (fToken == TokenNamefunction) {
@@ -233,9 +239,22 @@ public class IdentifierIndexManager {
     }
   }
 
+       class StringComparator implements Comparator { 
+               public int compare(Object o1, Object o2) { 
+                       String s1 = (String)o1; 
+                       String s2 = (String)o2; 
+                       return s1.compareTo(s2); 
+               //      return s1.toUpperCase().compareTo(s2.toUpperCase()); 
+               }                                     
+               public boolean equals(Object o) { 
+                       String s = (String)o; 
+                       return compare(this, o)==0; 
+               } 
+       } 
+
   private HashMap fFileMap;
   private String fFilename;
-  private HashMap fIndentifierMap;
+  private TreeMap fIndentifierMap;
 
   public IdentifierIndexManager(String filename) {
     fFilename = filename;
@@ -402,7 +421,7 @@ public class IdentifierIndexManager {
    *
    */
   public void initialize() {
-    fIndentifierMap = new HashMap();
+    fIndentifierMap = new TreeMap(new StringComparator());
     fFileMap = new HashMap();
   }
 
@@ -533,9 +552,21 @@ public class IdentifierIndexManager {
         fileWriter.write(line + '\n');
       }
       fileWriter.close();
+    } catch (FileNotFoundException e) {
+       // ignore exception; project is deleted by user
     } catch (IOException e) {
       // TODO Auto-generated catch block
       e.printStackTrace();
     }
   }
+  
+  /**
+   * @param fromKey
+   * @param toKey
+   * @return
+   */
+  public SortedMap getIdentifierMap() {
+    return fIndentifierMap;
+  }
+
 }
\ No newline at end of file