Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[pdt-dev] Spellcheck patch

Hello!

I suggest the patch, which enables spellchecking in strings and comments of the php content.

Best regards,
Iljas
### Eclipse Workspace Patch 1.0
#P org.eclipse.php.ui
Index: plugin.xml
===================================================================
RCS file: /cvsroot/tools/org.eclipse.pdt/plugins/org.eclipse.php.ui/plugin.xml,v
retrieving revision 1.270
diff -u -r1.270 plugin.xml
--- plugin.xml	25 Oct 2011 03:00:05 -0000	1.270
+++ plugin.xml	24 Mar 2012 18:55:40 -0000
@@ -746,6 +746,12 @@
 			<adapter type="org.eclipse.core.resources.IResource" />
 		</factory>
 		-->
+		<factory
+			adaptableType="org.eclipse.php.internal.core.documentModel.DOMModelForPHP"
+			class="org.eclipse.php.internal.ui.spelling.SpellcheckDelegateAdapterFactory">
+			<adapter
+            	type="org.eclipse.wst.sse.ui.internal.spelling.ISpellcheckDelegate"/>
+		</factory>
 	</extension>
 
 	<!-- Editor actionsets -->
Index: src/org/eclipse/php/internal/ui/spelling/SpellcheckDelegateAdapterFactory.java
===================================================================
RCS file: src/org/eclipse/php/internal/ui/spelling/SpellcheckDelegateAdapterFactory.java
diff -N src/org/eclipse/php/internal/ui/spelling/SpellcheckDelegateAdapterFactory.java
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/org/eclipse/php/internal/ui/spelling/SpellcheckDelegateAdapterFactory.java	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,116 @@
+package org.eclipse.php.internal.ui.spelling;
+
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.php.internal.core.documentModel.DOMModelForPHP;
+import org.eclipse.php.internal.core.documentModel.parser.regions.IPhpScriptRegion;
+import org.eclipse.php.internal.core.documentModel.partitioner.PHPPartitionTypes;
+import org.eclipse.wst.sse.core.internal.provisional.IStructuredModel;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
+import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocumentRegion;
+import org.eclipse.wst.sse.core.internal.provisional.text.ITextRegion;
+import org.eclipse.wst.sse.core.internal.text.BasicStructuredDocument;
+import org.eclipse.wst.sse.ui.internal.spelling.ISpellcheckDelegate;
+import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
+
+// this file content is taken from org.eclipse.wst.xml.ui.internal.spelling.SpellcheckDelegateAdapterFactory
+// and org.eclipse.php.internal.core.format.PHPHeuristicScanner
+
+/**
+ * An <code>IAdapterFactory</code> to adapt an <code>IDOMModel</code> to a
+ * <code>ISpellcheckDelegate</code>.
+ */
+@SuppressWarnings("restriction")
+public class SpellcheckDelegateAdapterFactory implements IAdapterFactory {
+	/**
+	 * This list of classes this factory adapts to.
+	 */
+	private static final Class[] ADAPTER_LIST = new Class[] { ISpellcheckDelegate.class };
+
+	/**
+	 * The <code>ISpellcheckDelegate</code> this factory adapts to
+	 */
+	private static final ISpellcheckDelegate DELEGATE = new PHPSpellcheckDelegate();
+
+	/**
+	 * Implementation of <code>ISpellcheckDelegate</code> for XML type
+	 * documents.
+	 */
+	private static class PHPSpellcheckDelegate implements ISpellcheckDelegate {
+
+		/**
+		 * If the region in the given <code>model</code> at the given
+		 * <code>offset</code> is a <code>Comment</code> region then it should
+		 * be spell checked, otherwise it should not.
+		 * 
+		 * @see org.eclipse.wst.sse.ui.internal.spelling.ISpellcheckDelegate#shouldSpellcheck(org.eclipse.wst.sse.core.internal.provisional.IndexedRegion)
+		 */
+		public boolean shouldSpellcheck(int offset, IStructuredModel model) {
+			boolean shouldSpellcheck = false;
+
+			if (model instanceof DOMModelForPHP) {
+				IStructuredDocument doc = ((DOMModelForPHP) model)
+						.getStructuredDocument();
+				if (doc instanceof BasicStructuredDocument) {
+					IStructuredDocumentRegion sdRegion = ((BasicStructuredDocument) doc)
+							.getRegionAtCharacterOffset(offset);
+					ITextRegion textRegion = sdRegion
+							.getRegionAtCharacterOffset(offset);
+					try {
+						if (textRegion instanceof IPhpScriptRegion) {
+							IPhpScriptRegion phpReg = (IPhpScriptRegion) textRegion;
+							String partition = phpReg.getPartition(offset
+									- sdRegion.getStart());
+							if (partition
+									.equals(PHPPartitionTypes.PHP_QUOTED_STRING)
+									|| partition
+											.equals(PHPPartitionTypes.PHP_COMMENT)
+									|| partition
+											.equals(PHPPartitionTypes.PHP_SINGLE_LINE_COMMENT)
+									|| partition
+											.equals(PHPPartitionTypes.PHP_MULTI_LINE_COMMENT)
+									|| partition
+											.equals(PHPPartitionTypes.PHP_DOC)) {
+								shouldSpellcheck = true;
+							}
+						}
+					} catch (BadLocationException e) {
+
+					}
+
+				}
+
+			}
+
+			return shouldSpellcheck;
+		}
+
+	}
+
+	/**
+	 * Adapts <code>IDOMModel</code> to <code>ISpellcheckDelegate</code>.
+	 * 
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapter(java.lang.Object,
+	 *      java.lang.Class)
+	 */
+	public Object getAdapter(Object adaptableObject, Class adapterType) {
+		ISpellcheckDelegate decision = null;
+
+		if (adaptableObject instanceof IDOMModel
+				&& ISpellcheckDelegate.class.equals(adapterType)) {
+			decision = DELEGATE;
+		}
+
+		return decision;
+	}
+
+	/**
+	 * This adapter only adapts to <code>ISpellcheckDelegate</code>
+	 * 
+	 * @see org.eclipse.core.runtime.IAdapterFactory#getAdapterList()
+	 */
+	public Class[] getAdapterList() {
+		return ADAPTER_LIST;
+	}
+
+}

Back to the top