A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / template / BuiltInEngine.java
index 8aac30a..1ab738f 100644 (file)
@@ -21,93 +21,105 @@ import org.eclipse.jface.text.IRegion;
 import org.eclipse.jface.text.ITextViewer;
 import org.eclipse.jface.text.Region;
 import org.eclipse.swt.graphics.Point;
-//import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionManager;
 
 public class BuiltInEngine {
 
-  /** The context type. */
-  private JavaContextType fContextType;
-  /** The result proposals. */
-  private ArrayList fProposals = new ArrayList();
+       /** The context type. */
+       private JavaContextType fContextType;
 
-  /**
-   * Creates the template engine for a particular context type.
-   * See <code>TemplateContext</code> for supported context types.
-   */
-  public BuiltInEngine(JavaContextType contextType) {
-    // Assert.isNotNull(contextType);
-    fContextType = contextType;
-  }
+       /** The result proposals. */
+       private ArrayList fProposals = new ArrayList();
 
-  /**
-   * Empties the collector.
-   * 
-   * @param viewer the text viewer  
-   * @param unit   the compilation unit (may be <code>null</code>)
-   */
-  public void reset() {
-    fProposals.clear();
-  }
+       /**
+        * Creates the template engine for a particular context type. See
+        * <code>TemplateContext</code> for supported context types.
+        */
+       public BuiltInEngine(JavaContextType contextType) {
+               // Assert.isNotNull(contextType);
+               fContextType = contextType;
+       }
 
-  /**
-   * Returns the array of matching templates.
-   */
-  public IPHPCompletionProposal[] getResults() {
-    return (IPHPCompletionProposal[]) fProposals.toArray(new IPHPCompletionProposal[fProposals.size()]);
-  }
+       /**
+        * Empties the collector.
+        * 
+        * @param viewer
+        *            the text viewer
+        * @param unit
+        *            the compilation unit (may be <code>null</code>)
+        */
+       public void reset() {
+               fProposals.clear();
+       }
 
-  /**
-   * 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, ArrayList identifiers,ICompilationUnit compilationUnit)
-  //hrows JavaModelException
-  {
-    IDocument document = viewer.getDocument();
+       /**
+        * Returns the array of matching templates.
+        */
+       public IPHPCompletionProposal[] getResults() {
+               return (IPHPCompletionProposal[]) fProposals
+                               .toArray(new IPHPCompletionProposal[fProposals.size()]);
+       }
 
-    // prohibit recursion
-    //         if (LinkedPositionManager.hasActiveManager(document))
-    //                 return;
+       /**
+        * 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,
+                       ArrayList identifiers, ICompilationUnit compilationUnit)
+       // hrows JavaModelException
+       {
+               IDocument document = viewer.getDocument();
 
-    if (!(fContextType instanceof CompilationUnitContextType))
-      return;
-    Point selection = viewer.getSelectedRange();
-    // remember selected text
-    String selectedText = null;
-    if (selection.y != 0) {
-      try {
-        selectedText = document.get(selection.x, selection.y);
-      } catch (BadLocationException e) {
-      }
-    }
+               // prohibit recursion
+               // if (LinkedPositionManager.hasActiveManager(document))
+               // return;
 
-//    ((CompilationUnitContextType) fContextType).setContextParameters(document, completionPosition, selection.y); //mpilationUnit);
-//    JavaContext context = (JavaContext) fContextType.createContext();
-    JavaContext context = (JavaContext) fContextType.createContext(document, completionPosition,selection.y,compilationUnit);
-    context.setVariable("selection", selectedText); //$NON-NLS-1$
-    int start = context.getStart();
-    int end = context.getEnd();
-    IRegion region = new Region(start, end - start);
+               if (!(fContextType instanceof CompilationUnitContextType))
+                       return;
+               Point selection = viewer.getSelectedRange();
+               // remember selected text
+               String selectedText = null;
+               if (selection.y != 0) {
+                       try {
+                               selectedText = document.get(selection.x, selection.y);
+                       } catch (BadLocationException e) {
+                       }
+               }
 
-    //         Template[] templates= Templates.getInstance().getTemplates();
-    String identifier = null;
-    int maxProposals = PHPeclipsePlugin.MAX_PROPOSALS;
-    PHPElement element = null;
-    for (int i = 0; i != identifiers.size(); i++) {
-      element = (PHPElement) identifiers.get(i);
-      if (element instanceof PHPFunction) {
-        identifier = ((PHPFunction) element).getName();
-        if (context.canEvaluate(identifier)) {
-          if (maxProposals-- < 0) {
-            return;
-          }
-          fProposals.add(new BuiltInProposal(identifier, (PHPFunction) element, context, region, viewer));
-        }
-      }
-    }
-  }
+               // ((CompilationUnitContextType)
+               // fContextType).setContextParameters(document, completionPosition,
+               // selection.y); //mpilationUnit);
+               // JavaContext context = (JavaContext) fContextType.createContext();
+               JavaContext context = (JavaContext) fContextType.createContext(
+                               document, completionPosition, selection.y, compilationUnit);
+               context.setVariable("selection", selectedText); //$NON-NLS-1$
+               int start = context.getStart();
+               int end = context.getEnd();
+               IRegion region = new Region(start, end - start);
+
+               // Template[] templates= Templates.getInstance().getTemplates();
+               String identifier = null;
+               int maxProposals = PHPeclipsePlugin.MAX_PROPOSALS;
+               PHPElement element = null;
+               for (int i = 0; i != identifiers.size(); i++) {
+                       element = (PHPElement) identifiers.get(i);
+                       if (element instanceof PHPFunction) {
+                               identifier = ((PHPFunction) element).getName();
+                               if (context.canEvaluate(identifier)) {
+                                       if (maxProposals-- < 0) {
+                                               return;
+                                       }
+                                       fProposals.add(new BuiltInProposal(identifier,
+                                                       (PHPFunction) element, context, region, viewer));
+                               }
+                       }
+               }
+       }
 
 }