Defined a limit for code completion list entries PHPeclipsePlugin.MAX_PROPOSALS
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / template / DeclarationEngine.java
index 56e309e..0483613 100644 (file)
@@ -11,8 +11,9 @@ import java.util.SortedMap;
 import net.sourceforge.phpdt.internal.corext.template.ContextType;
 import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType;
 import net.sourceforge.phpdt.internal.corext.template.php.PHPUnitContext;
-import net.sourceforge.phpdt.internal.ui.PHPUiImages;
 import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
 
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -86,25 +87,26 @@ public class DeclarationEngine {
     PHPUnitContext context = (PHPUnitContext) fContextType.createContext();
     int start = context.getStart();
     int end = context.getEnd();
-               String prefix = context.getKey();
+    String prefix = context.getKey();
     IRegion region = new Region(start, end - start);
 
     String identifier = null;
-    
-    SortedMap subMap = map.subMap(prefix,prefix+'\255');
-    Iterator iter = subMap.keySet().iterator();
 
+    SortedMap subMap = map.subMap(prefix, prefix + '\255');
+    Iterator iter = subMap.keySet().iterator();
+    PHPIdentifierLocation location;
+    ArrayList list;
+    int maxProposals = PHPeclipsePlugin.MAX_PROPOSALS;
     while (iter.hasNext()) {
       identifier = (String) iter.next();
       if (context.canEvaluate(identifier)) {
-        fProposals.add(
-          new DeclarationProposal(
-            identifier,
-            context,
-            region,
-            viewer,
-            PHPUiImages.get(PHPUiImages.IMG_FUN),
-            PHPUiImages.get(PHPUiImages.IMG_VAR)));
+        list = (ArrayList) subMap.get(identifier);
+        for (int i = 0; i < list.size(); i++) {
+          if (maxProposals-- < 0) {
+            return;
+          }
+          fProposals.add(new DeclarationProposal(identifier, (PHPIdentifierLocation) list.get(i), context, region, viewer));
+        }
       }
     }