intial source from ttp://www.sf.net/projects/wdte
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.js.ui / src / net / sourceforge / phpeclipse / js / ui / internal / text / JSCompletionProcessor.java
diff --git a/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/text/JSCompletionProcessor.java b/archive/net.sourceforge.phpeclipse.js.ui/src/net/sourceforge/phpeclipse/js/ui/internal/text/JSCompletionProcessor.java
new file mode 100644 (file)
index 0000000..63aa64b
--- /dev/null
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2004 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials 
+ * are made available under the terms of the Common Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v10.html
+ * 
+ * Contributors:
+ *     IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package net.sourceforge.phpeclipse.js.ui.internal.text;
+
+import net.sourceforge.phpeclipse.ui.WebUI;
+import net.sourceforge.phpeclipse.ui.templates.template.BasicCompletionProcessor;
+import net.sourceforge.phpeclipse.ui.templates.template.JSContextType;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.templates.TemplateContextType;
+
+
+/**
+ * A completion processor for XML templates.
+ */
+public class JSCompletionProcessor extends BasicCompletionProcessor {
+  /**
+        * We watch for angular brackets since those are often part of XML
+        * templates.
+        */
+       protected String extractPrefix(ITextViewer viewer, int offset) {
+               IDocument document= viewer.getDocument();
+               int i= offset;
+               if (i > document.getLength())
+                       return ""; //$NON-NLS-1$
+               
+               try {
+                       while (i > 0) {
+                               char ch= document.getChar(i - 1);
+                               if (!Character.isJavaIdentifierPart(ch))
+                                       break;
+                               i--;
+                       }
+       
+                       return document.get(i, offset - i);
+               } catch (BadLocationException e) {
+                       return ""; //$NON-NLS-1$
+               }
+       }
+       /**
+        * Return the XML context type that is supported by this plugin. 
+        */
+       protected TemplateContextType getContextType(ITextViewer viewer, IRegion region) {
+               return WebUI.getDefault().getContextTypeRegistry().getContextType(JSContextType.JS_CONTEXT_TYPE);
+       }
+
+       
+}