Defined a limit for code completion list entries PHPeclipsePlugin.MAX_PROPOSALS
authorkhartlage <khartlage>
Sat, 20 Sep 2003 14:59:02 +0000 (14:59 +0000)
committerkhartlage <khartlage>
Sat, 20 Sep 2003 14:59:02 +0000 (14:59 +0000)
Code completion shows available phpdoc in completion context
new icon for "define" integrated

13 files changed:
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/phpdoc/PHPDocUtil.java [new file with mode: 0644]
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/PHPUiImages.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/phpdoc/PHPDocCompletionProcessor.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/BuiltInEngine.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationEngine.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/DeclarationProposal.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/IdentifierEngine.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/template/TemplateEngine.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPIdentifierLocation.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPContentOutlinePage.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java
net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPTextHover.java

diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/phpdoc/PHPDocUtil.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/phpdoc/PHPDocUtil.java
new file mode 100644 (file)
index 0000000..59b8ca3
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * Created on 20.09.2003
+ *
+ * To change the template for this generated file go to
+ * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+ */
+package net.sourceforge.phpdt.internal.corext.phpdoc;
+
+import java.io.FileReader;
+import java.io.IOException;
+
+import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
+
+/**
+ * @author khartlage
+ *
+ * To change the template for this generated type comment go to
+ * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
+ */
+public class PHPDocUtil {
+       
+       /**
+        * Generate a PHPDoc hover text if possible
+        * 
+        * @param hoverInfoBuffer
+        * @param filename
+        * @param location
+        */
+  public static void appendPHPDoc(StringBuffer hoverInfoBuffer, String filename, PHPIdentifierLocation location) {
+    hoverInfoBuffer.append(location.toString());
+    hoverInfoBuffer.append('\n');
+    if (location.getPHPDocOffset() >= 0) {
+      FileReader phpdocFileReader;
+      try {
+        phpdocFileReader = new FileReader(filename);
+
+        char[] charArray = new char[location.getPHPDocLength()];
+        phpdocFileReader.skip(location.getPHPDocOffset());
+        phpdocFileReader.read(charArray, 0, location.getPHPDocLength());
+        PHPDocCharArrayCommentReader phpdocConverter = new PHPDocCharArrayCommentReader(charArray);
+        hoverInfoBuffer.append(phpdocConverter.getString());
+        hoverInfoBuffer.append('\n');
+      } catch (IOException e) {
+      }
+    }
+  }
+}
index b858d0b..651e9c0 100644 (file)
@@ -40,6 +40,7 @@ public class PHPUiImages {
        protected static final String CTOOL_PREFIX = "ctool16";
 
        public static final String IMG_CLASS = NAME_PREFIX + "class_obj.gif";
+       public static final String IMG_DEFINE = NAME_PREFIX + "define_obj.gif";
        public static final String IMG_BUILTIN = NAME_PREFIX + "builtin_obj.gif";
        public static final String IMG_FUN = NAME_PREFIX + "fun_obj.gif";
        public static final String IMG_INC = NAME_PREFIX + "impc_obj.gif";
@@ -59,6 +60,8 @@ public class PHPUiImages {
        
        public static final ImageDescriptor DESC_CLASS =
                createManaged(OBJ_PREFIX, IMG_CLASS);
+       public static final ImageDescriptor DESC_DEFINE =
+               createManaged(OBJ_PREFIX, IMG_DEFINE);
        public static final ImageDescriptor DESC_BUILTIN =
                createManaged(OBJ_PREFIX, IMG_BUILTIN);
        public static final ImageDescriptor DESC_FUN =
index 4a782fd..5f0d2be 100644 (file)
@@ -20,7 +20,6 @@ import org.eclipse.jface.text.contentassist.ICompletionProposal;
 import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
 import org.eclipse.jface.text.contentassist.IContextInformation;
 import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.ui.IEditorPart;
 
 /**
  * Simple PHPDoc completion processor.
index 5b43224..950765f 100644 (file)
@@ -11,6 +11,7 @@ import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContext
 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 org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -22,81 +23,85 @@ import org.eclipse.swt.graphics.Point;
 
 public class BuiltInEngine {
 
-       /** The context type. */
-       private ContextType fContextType;
-       /** The result proposals. */
-       private ArrayList fProposals= new ArrayList();
+  /** The context type. */
+  private ContextType fContextType;
+  /** The result proposals. */
+  private ArrayList fProposals = new ArrayList();
 
-       /**
-        * Creates the template engine for a particular context type.
-        * See <code>TemplateContext</code> for supported context types.
-        */
-       public BuiltInEngine(ContextType contextType) {
-       //      Assert.isNotNull(contextType);
-               fContextType= contextType;
-       }
+  /**
+   * Creates the template engine for a particular context type.
+   * See <code>TemplateContext</code> for supported context types.
+   */
+  public BuiltInEngine(ContextType contextType) {
+    // Assert.isNotNull(contextType);
+    fContextType = contextType;
+  }
 
-       /**
-        * Empties the collector.
-        * 
-        * @param viewer the text viewer  
-        * @param unit   the compilation unit (may be <code>null</code>)
-        */
-       public void reset() {
-               fProposals.clear();
-       }
+  /**
+   * Empties the collector.
+   * 
+   * @param viewer the text viewer  
+   * @param unit   the compilation unit (may be <code>null</code>)
+   */
+  public void reset() {
+    fProposals.clear();
+  }
 
-       /**
-        * Returns the array of matching templates.
-        */
-       public IPHPCompletionProposal[] getResults() {
-               return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]);
-       }
+  /**
+   * Returns the array of matching templates.
+   */
+  public IPHPCompletionProposal[] getResults() {
+    return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]);
+  }
 
-       /**
-        * Inspects the context of the compilation unit around <code>completionPosition</code>
-        * and feeds the collector with proposals.
-        * @param viewer the text viewer
-        * @param completionPosition the context position in the document of the text viewer
-        * @param compilationUnit the compilation unit (may be <code>null</code>)
-        */
-       public void complete(ITextViewer viewer, int completionPosition, Object[] identifiers)
+  /**
+   * Inspects the context of the compilation unit around <code>completionPosition</code>
+   * and feeds the collector with proposals.
+   * @param viewer the text viewer
+   * @param completionPosition the context position in the document of the text viewer
+   * @param compilationUnit the compilation unit (may be <code>null</code>)
+   */
+  public void complete(ITextViewer viewer, int completionPosition, Object[] identifiers)
   //,ICompilationUnit compilationUnit)
-       //hrows JavaModelException
-       {
-           IDocument document= viewer.getDocument();
-           
-               // prohibit recursion
-//             if (LinkedPositionManager.hasActiveManager(document))
-//                     return;
+  //hrows JavaModelException
+  {
+    IDocument document = viewer.getDocument();
 
-               if (!(fContextType instanceof CompilationUnitContextType))
-                       return;
-    Point selection= viewer.getSelectedRange();
+    // prohibit recursion
+    //         if (LinkedPositionManager.hasActiveManager(document))
+    //                 return;
+
+    if (!(fContextType instanceof CompilationUnitContextType))
+      return;
+    Point selection = viewer.getSelectedRange();
     // remember selected text
-    String selectedText= null;
+    String selectedText = null;
     if (selection.y != 0) {
       try {
-        selectedText= document.get(selection.x, selection.y);
-      } catch (BadLocationException e) {}
+        selectedText = document.get(selection.x, selection.y);
+      } catch (BadLocationException e) {
+      }
     }
-    
-    ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y);//mpilationUnit);
 
-               PHPUnitContext context= (PHPUnitContext) fContextType.createContext();
-               int start= context.getStart();
-               int end= context.getEnd();
-               IRegion region= new Region(start, end - start);
+    ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y); //mpilationUnit);
 
-//             Template[] templates= Templates.getInstance().getTemplates();
+    PHPUnitContext context = (PHPUnitContext) fContextType.createContext();
+    int start = context.getStart();
+    int end = context.getEnd();
+    IRegion region = new Region(start, end - start);
+
+    //         Template[] templates= Templates.getInstance().getTemplates();
     String identifier = null;
-               for (int i= 0; i != identifiers.length; i++) {
+    int maxProposals = PHPeclipsePlugin.MAX_PROPOSALS;
+    for (int i = 0; i != identifiers.length; i++) {
       identifier = (String) identifiers[i];
-                       if (context.canEvaluate(identifier)) {
-                               fProposals.add(new BuiltInProposal(identifier, context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_BUILTIN))); 
+      if (context.canEvaluate(identifier)) {
+        if (maxProposals-- < 0) {
+          return;
+        }
+        fProposals.add(new BuiltInProposal(identifier, context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_BUILTIN)));
       }
     }
-       }
+  }
 
 }
-
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));
+        }
       }
     }
 
index c448d44..41c9f61 100644 (file)
@@ -4,13 +4,16 @@
  */
 package net.sourceforge.phpdt.internal.ui.text.template;
 
+import net.sourceforge.phpdt.internal.corext.phpdoc.PHPDocUtil;
 import net.sourceforge.phpdt.internal.corext.template.TemplateContext;
 import net.sourceforge.phpdt.internal.corext.template.TemplateMessages;
 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.phpdt.internal.ui.text.link.LinkedPositionManager;
 import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
+import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.dialogs.MessageDialog;
@@ -32,10 +35,11 @@ import org.eclipse.swt.widgets.Shell;
 public class DeclarationProposal implements IPHPCompletionProposal {
 
   private final String fTemplate;
+  private final PHPIdentifierLocation fLocation;
   private final TemplateContext fContext;
   private final ITextViewer fViewer;
-  private final Image fImage_fun;
-  private final Image fImage_var;
+  //  private final Image fImage_fun;
+  //  private final Image fImage_var;
   private final IRegion fRegion;
 
   //private TemplateBuffer fTemplateBuffer;
@@ -48,17 +52,20 @@ public class DeclarationProposal implements IPHPCompletionProposal {
    * @param context   the context in which the template was requested.
    * @param image     the icon of the proposal.
    */
-  public DeclarationProposal(String template, TemplateContext context, IRegion region, ITextViewer viewer, Image image_fun, Image image_var) {
-    //         Assert.isNotNull(template);
-    //         Assert.isNotNull(context);
-    //         Assert.isNotNull(region);
-    //         Assert.isNotNull(viewer);
-
+  public DeclarationProposal(
+    String template,
+    PHPIdentifierLocation location,
+    TemplateContext context,
+    IRegion region,
+    ITextViewer viewer) {
+    //    Image image_fun,
+    //    Image image_var) {
     fTemplate = template;
+    fLocation = location;
     fContext = context;
     fViewer = viewer;
-       fImage_fun= image_fun;
-    fImage_var= image_var;
+    //    fImage_fun = image_fun;
+    //    fImage_var = image_var;
     fRegion = region;
   }
 
@@ -74,7 +81,7 @@ public class DeclarationProposal implements IPHPCompletionProposal {
       int end = fRegion.getOffset() + fRegion.getLength();
 
       // insert template string
-    //  String templateString = fTemplate; // fTemplateBuffer.getString();     
+      //  String templateString = fTemplate; // fTemplateBuffer.getString();   
       document.replace(start, end - start, fTemplate);
 
       // translate positions
@@ -94,8 +101,8 @@ public class DeclarationProposal implements IPHPCompletionProposal {
       //                       }
 
       LinkedPositionUI editor = new LinkedPositionUI(fViewer, manager);
-      editor.setFinalCaretOffset(fTemplate.length()+start);
-   //   editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start);
+      editor.setFinalCaretOffset(fTemplate.length() + start);
+      //   editor.setFinalCaretOffset(getCaretOffset(fTemplateBuffer) + start);
       editor.enter();
 
       fSelectedRegion = editor.getSelectedRegion();
@@ -110,17 +117,17 @@ public class DeclarationProposal implements IPHPCompletionProposal {
     //     }       
   }
 
-//  private static int getCaretOffset(TemplateBuffer buffer) {
-//    TemplatePosition[] variables = buffer.getVariables();
-//    for (int i = 0; i != variables.length; i++) {
-//      TemplatePosition variable = variables[i];
-//
-//      if (variable.getName().equals(JavaTemplateMessages.getString("GlobalVariables.variable.name.cursor"))) //$NON-NLS-1$
-//        return variable.getOffsets()[0];
-//    }
-//
-//    return buffer.getString().length();
-//  }
+  //  private static int getCaretOffset(TemplateBuffer buffer) {
+  //    TemplatePosition[] variables = buffer.getVariables();
+  //    for (int i = 0; i != variables.length; i++) {
+  //      TemplatePosition variable = variables[i];
+  //
+  //      if (variable.getName().equals(JavaTemplateMessages.getString("GlobalVariables.variable.name.cursor"))) //$NON-NLS-1$
+  //        return variable.getOffsets()[0];
+  //    }
+  //
+  //    return buffer.getString().length();
+  //  }
 
   /*
    * @see ICompletionProposal#getSelection(IDocument)
@@ -134,16 +141,11 @@ public class DeclarationProposal implements IPHPCompletionProposal {
    * @see ICompletionProposal#getAdditionalProposalInfo()
    */
   public String getAdditionalProposalInfo() {
-    //     try {
-    //                 if (fTemplateBuffer == null)
-    //                         fTemplateBuffer= fContext.evaluate(fTemplate);
-
-    return textToHTML(fTemplate); // fTemplateBuffer.getString());
-
-    //     } catch (CoreException e) {
-    //                 handleException(e);                 
-    //                 return null;
-    //     }
+    StringBuffer hoverInfoBuffer = new StringBuffer();
+    String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
+    String filename = workspaceLocation + fLocation.getFilename();
+    PHPDocUtil.appendPHPDoc(hoverInfoBuffer, filename, fLocation);
+    return textToHTML(hoverInfoBuffer.toString());
   }
 
   /*
@@ -158,10 +160,19 @@ public class DeclarationProposal implements IPHPCompletionProposal {
    * @see ICompletionProposal#getImage()
    */
   public Image getImage() {
-    if (fTemplate.charAt(0)=='$') {
-      return fImage_var;
+    switch (fLocation.getType()) {
+      case PHPIdentifierLocation.FUNCTION :
+        return PHPUiImages.get(PHPUiImages.IMG_FUN);
+                       case PHPIdentifierLocation.CLASS :
+                               return PHPUiImages.get(PHPUiImages.IMG_CLASS);
+                       case PHPIdentifierLocation.METHOD :
+                               return PHPUiImages.get(PHPUiImages.IMG_FUN);
+                       case PHPIdentifierLocation.DEFINE :
+                               return PHPUiImages.get(PHPUiImages.IMG_DEFINE);
+                       case PHPIdentifierLocation.VARIABLE :
+                               return PHPUiImages.get(PHPUiImages.IMG_VAR);
     }
-               return fImage_fun;
+    return PHPUiImages.get(PHPUiImages.IMG_FUN);
   }
 
   /*
index de2ce2e..570c0fa 100644 (file)
@@ -11,6 +11,7 @@ import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContext
 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 org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -88,9 +89,14 @@ public class IdentifierEngine {
 
     //         Template[] templates= Templates.getInstance().getTemplates();
     String identifier = null;
+    int maxProposals = PHPeclipsePlugin.MAX_PROPOSALS;
+
     for (int i = 0; i != identifiers.length; i++) {
       identifier = (String) identifiers[i];
       if (context.canEvaluate(identifier)) {
+        if (maxProposals-- < 0) {
+          return;
+        }
         fProposals.add(
           new IdentifierProposal(
             identifier,
index f315c61..11dee2d 100644 (file)
@@ -13,6 +13,7 @@ import net.sourceforge.phpdt.internal.corext.template.Templates;
 import net.sourceforge.phpdt.internal.corext.template.php.CompilationUnitContextType;
 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
 import net.sourceforge.phpdt.internal.ui.text.java.IPHPCompletionProposal;
+import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -24,77 +25,79 @@ import org.eclipse.swt.graphics.Point;
 
 public class TemplateEngine {
 
-       /** The context type. */
-       private ContextType fContextType;
-       /** The result proposals. */
-       private ArrayList fProposals= new ArrayList();
+  /** The context type. */
+  private ContextType fContextType;
+  /** The result proposals. */
+  private ArrayList fProposals = new ArrayList();
 
-       /**
-        * Creates the template engine for a particular context type.
-        * See <code>TemplateContext</code> for supported context types.
-        */
-       public TemplateEngine(ContextType contextType) {
-       //      Assert.isNotNull(contextType);
-               fContextType= contextType;
-       }
+  /**
+   * Creates the template engine for a particular context type.
+   * See <code>TemplateContext</code> for supported context types.
+   */
+  public TemplateEngine(ContextType contextType) {
+    // Assert.isNotNull(contextType);
+    fContextType = contextType;
+  }
 
-       /**
-        * Empties the collector.
-        * 
-        * @param viewer the text viewer  
-        * @param unit   the compilation unit (may be <code>null</code>)
-        */
-       public void reset() {
-               fProposals.clear();
-       }
+  /**
+   * Empties the collector.
+   * 
+   * @param viewer the text viewer  
+   * @param unit   the compilation unit (may be <code>null</code>)
+   */
+  public void reset() {
+    fProposals.clear();
+  }
 
-       /**
-        * Returns the array of matching templates.
-        */
-       public IPHPCompletionProposal[] getResults() {
-               return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]);
-       }
+  /**
+   * Returns the array of matching templates.
+   */
+  public IPHPCompletionProposal[] getResults() {
+    return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]);
+  }
 
-       /**
-        * Inspects the context of the compilation unit around <code>completionPosition</code>
-        * and feeds the collector with proposals.
-        * @param viewer the text viewer
-        * @param completionPosition the context position in the document of the text viewer
-        * @param compilationUnit the compilation unit (may be <code>null</code>)
-        */
-       public void complete(ITextViewer viewer, int completionPosition)
+  /**
+   * Inspects the context of the compilation unit around <code>completionPosition</code>
+   * and feeds the collector with proposals.
+   * @param viewer the text viewer
+   * @param completionPosition the context position in the document of the text viewer
+   * @param compilationUnit the compilation unit (may be <code>null</code>)
+   */
+  public void complete(ITextViewer viewer, int completionPosition)
   //,ICompilationUnit compilationUnit)
-       //hrows JavaModelException
-       {
-           IDocument document= viewer.getDocument();
-           
-               // prohibit recursion
-//             if (LinkedPositionManager.hasActiveManager(document))
-//                     return;
+  //hrows JavaModelException
+  {
+    IDocument document = viewer.getDocument();
 
-               if (!(fContextType instanceof CompilationUnitContextType))
-                       return;
-                       
-    Point selection= viewer.getSelectedRange();
+    if (!(fContextType instanceof CompilationUnitContextType))
+      return;
+
+    Point selection = viewer.getSelectedRange();
     // remember selected text
-    String selectedText= null;
+    String selectedText = null;
     if (selection.y != 0) {
       try {
-        selectedText= document.get(selection.x, selection.y);
-      } catch (BadLocationException e) {}
+        selectedText = document.get(selection.x, selection.y);
+      } catch (BadLocationException e) {
+      }
     }
-    
-               ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y);//mpilationUnit);
-               DocumentTemplateContext context= (DocumentTemplateContext) fContextType.createContext();
-               int start= context.getStart();
-               int end= context.getEnd();
-               IRegion region= new Region(start, end - start);
 
-               Template[] templates= Templates.getInstance().getTemplates();
-               for (int i= 0; i != templates.length; i++)
-                       if (context.canEvaluate(templates[i]))
-                               fProposals.add(new TemplateProposal(templates[i], context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_OBJS_TEMPLATE))); 
-       }
+    ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y); //mpilationUnit);
+    DocumentTemplateContext context = (DocumentTemplateContext) fContextType.createContext();
+    int start = context.getStart();
+    int end = context.getEnd();
+    IRegion region = new Region(start, end - start);
 
-}
+    Template[] templates = Templates.getInstance().getTemplates();
+    int maxProposals = PHPeclipsePlugin.MAX_PROPOSALS;
 
+    for (int i = 0; i != templates.length; i++)
+      if (context.canEvaluate(templates[i])) {
+        if (maxProposals-- < 0) {
+          return;
+        }
+        fProposals.add(new TemplateProposal(templates[i], context, region, viewer, PHPUiImages.get(PHPUiImages.IMG_OBJS_TEMPLATE)));
+      }
+  }
+
+}
index 8ab0b94..04d04fc 100644 (file)
@@ -84,6 +84,11 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
   /** General debug flag*/
   public static final boolean DEBUG = false;
 
+       /**
+        * The maximum number of allowed proposals by category
+        */
+       public final static int MAX_PROPOSALS = 200;
+       
   private static ExternalToolsPlugin externalTools;
 
   /**
@@ -126,14 +131,13 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon
   /** Windows NT  */
   private static final int WINDOWS_NT = 5;
   private PHPDocumentProvider fCompilationUnitDocumentProvider;
-  //Resource bundle.
-  //private ResourceBundle resourceBundle;
-
   private ImageDescriptorRegistry fImageDescriptorRegistry;
   private HashMap fIndexManagerMap = new HashMap();
 
   private JavaTextTools fJavaTextTools;
   private IFile fLastEditorFile = null;
+
   /**
    * The constructor.
    */
index e3ea468..43006a0 100644 (file)
@@ -109,7 +109,7 @@ public class PHPIdentifierLocation extends PHPIdentifier {
    * @see java.lang.Object#toString()
    */
   public String toString() {
-    return super.toString()+fFilename;
+    return super.toString()+"\n"+fFilename;
   }
 
 }
index 016372d..6d9d031 100644 (file)
@@ -21,13 +21,14 @@ import java.util.TreeSet;
 import net.sourceforge.phpdt.internal.compiler.parser.Outlineable;
 import net.sourceforge.phpdt.internal.compiler.parser.OutlineableWithChildren;
 import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo;
-import net.sourceforge.phpdt.internal.compiler.parser.PHPSegment;
-import net.sourceforge.phpdt.internal.compiler.parser.PHPSegmentWithChildren;
 import net.sourceforge.phpdt.internal.ui.viewsupport.ImageDescriptorRegistry;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 
 import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IPositionUpdater;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.jface.viewers.ITreeContentProvider;
index ac8fa19..16072a2 100644 (file)
@@ -32,7 +32,6 @@ import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.action.Action;
 import org.eclipse.jface.action.GroupMarker;
-import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.action.MenuManager;
 import org.eclipse.jface.action.Separator;
 import org.eclipse.jface.preference.IPreferenceStore;
index 032adf0..bdbe4d5 100644 (file)
@@ -16,7 +16,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Vector;
 
-import net.sourceforge.phpdt.internal.corext.phpdoc.PHPDocCharArrayCommentReader;
+import net.sourceforge.phpdt.internal.corext.phpdoc.PHPDocUtil;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.builder.IdentifierIndexManager;
 import net.sourceforge.phpeclipse.builder.PHPIdentifierLocation;
@@ -83,25 +83,27 @@ public class PHPTextHover implements ITextHover {
                 PHPIdentifierLocation location;
                 String filename;
                 FileReader phpdocFileReader;
-                PHPDocCharArrayCommentReader phpdocConverter;
+        //        PHPDocCharArrayCommentReader phpdocConverter;
                 StringBuffer hoverInfoBuffer = new StringBuffer();
                 String workspaceLocation = PHPeclipsePlugin.getWorkspace().getRoot().getLocation().toString();
                 //                boolean foundPHPdoc = false;
                 for (int i = 0; i < list.size(); i++) {
                   location = (PHPIdentifierLocation) list.get(i);
                                                                        filename = workspaceLocation + location.getFilename();
-                                                                       hoverInfoBuffer.append(location.toString());
-                                                                       hoverInfoBuffer.append('\n');
-                  if (location.getPHPDocOffset() >= 0) {
-                    //                    foundPHPdoc = true;
-                    phpdocFileReader = new FileReader(filename);
-                    char[] charArray = new char[location.getPHPDocLength()];
-                    phpdocFileReader.skip(location.getPHPDocOffset());
-                    phpdocFileReader.read(charArray, 0, location.getPHPDocLength());
-                    phpdocConverter = new PHPDocCharArrayCommentReader(charArray);
-                    hoverInfoBuffer.append(phpdocConverter.getString());
-                    hoverInfoBuffer.append('\n');
-                  }
+                  PHPDocUtil.appendPHPDoc(hoverInfoBuffer, filename, location);
+//                                                                     
+//                                                                     hoverInfoBuffer.append(location.toString());
+//                                                                     hoverInfoBuffer.append('\n');
+//                  if (location.getPHPDocOffset() >= 0) {
+//                    //                    foundPHPdoc = true;
+//                    phpdocFileReader = new FileReader(filename);
+//                    char[] charArray = new char[location.getPHPDocLength()];
+//                    phpdocFileReader.skip(location.getPHPDocOffset());
+//                    phpdocFileReader.read(charArray, 0, location.getPHPDocLength());
+//                    phpdocConverter = new PHPDocCharArrayCommentReader(charArray);
+//                    hoverInfoBuffer.append(phpdocConverter.getString());
+//                    hoverInfoBuffer.append('\n');
+//                  }
                 }
                 //                if (foundPHPdoc) {
                 hoverInfo = hoverInfoBuffer.toString();