In progress: [Issue 118] Add support for spell checking.

Spell checking in place. For now, it spells check the whole file. Need
to fix that.
diff --git a/com.google.eclipse.protobuf.ui/META-INF/MANIFEST.MF b/com.google.eclipse.protobuf.ui/META-INF/MANIFEST.MF
index 4fe1fde..2b47b55 100644
--- a/com.google.eclipse.protobuf.ui/META-INF/MANIFEST.MF
+++ b/com.google.eclipse.protobuf.ui/META-INF/MANIFEST.MF
@@ -19,8 +19,9 @@
  org.eclipse.core.resources,

  org.eclipse.core.filesystem;bundle-version="1.3.100",

  org.eclipse.compare.core;bundle-version="3.5.200"

-Import-Package: org.apache.log4j,

- org.apache.commons.logging

+Import-Package: org.apache.commons.logging,

+ org.apache.log4j,

+ org.eclipse.ui.texteditor.spelling

 Bundle-RequiredExecutionEnvironment: J2SE-1.5

 Export-Package: com.google.eclipse.protobuf.ui.contentassist.antlr

 Bundle-Activator: com.google.eclipse.protobuf.ui.internal.ProtobufActivator

diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
index 9d316c3..7e4698f 100644
--- a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/ProtobufUiModule.java
@@ -12,6 +12,7 @@
 import static org.eclipse.ui.PlatformUI.isWorkbenchRunning;
 
 import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
+import org.eclipse.jface.text.reconciler.IReconciler;
 import org.eclipse.ui.*;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -21,6 +22,7 @@
 import org.eclipse.xtext.ui.editor.model.XtextDocumentProvider;
 import org.eclipse.xtext.ui.editor.outline.actions.IOutlineContribution;
 import org.eclipse.xtext.ui.editor.preferences.*;
+import org.eclipse.xtext.ui.editor.quickfix.XtextQuickAssistProcessor;
 import org.eclipse.xtext.ui.editor.syntaxcoloring.*;
 
 import com.google.eclipse.protobuf.scoping.IFileUriResolver;
@@ -29,6 +31,7 @@
 import com.google.eclipse.protobuf.ui.editor.ProtobufUriEditorOpener;
 import com.google.eclipse.protobuf.ui.editor.hyperlinking.ProtobufHyperlinkDetector;
 import com.google.eclipse.protobuf.ui.editor.model.ProtobufDocumentProvider;
+import com.google.eclipse.protobuf.ui.editor.spelling.ProtobufReconciler;
 import com.google.eclipse.protobuf.ui.editor.syntaxcoloring.*;
 import com.google.eclipse.protobuf.ui.internal.ProtobufActivator;
 import com.google.eclipse.protobuf.ui.outline.*;
@@ -38,6 +41,7 @@
 import com.google.eclipse.protobuf.ui.preferences.pages.editor.save.SaveActionsPreferenceStoreInitializer;
 import com.google.eclipse.protobuf.ui.preferences.pages.general.GeneralPreferenceStoreInitializer;
 import com.google.eclipse.protobuf.ui.preferences.pages.paths.PathsPreferenceStoreInitializer;
+import com.google.eclipse.protobuf.ui.quickfix.ProtobufQuickAssistProcessor;
 import com.google.eclipse.protobuf.ui.scoping.FileUriResolver;
 import com.google.eclipse.protobuf.ui.validation.ValidateOnActivation;
 import com.google.inject.Binder;
@@ -61,56 +65,48 @@
     w.getPartService().addPartListener(new ValidateOnActivation());
   }
 
+  public Class<? extends IFileUriResolver> bindFileUriResolver() {
+    return FileUriResolver.class;
+  }
+
+  public Class<? extends IHighlightingConfiguration> bindHighlightingConfiguration() {
+    return HighlightingConfiguration.class;
+  }
+
   @Override public Class<? extends IContentOutlinePage> bindIContentOutlinePage() {
     return ProtobufOutlinePage.class;
   }
-
+  
   @Override public Class<? extends IHyperlinkDetector> bindIHyperlinkDetector() {
     return ProtobufHyperlinkDetector.class;
   }
-
+  
+  @Override public Class<? extends IReconciler> bindIReconciler() {
+    return ProtobufReconciler.class;
+  }
+  
   @Override public Class<? extends IXtextEditorCallback> bindIXtextEditorCallback() {
     return AutoAddNatureEditorCallback.class;
   }
-
-  /** {@inheritDoc} */
-  @Override public void configureToggleLinkWithEditorOutlineContribution(Binder binder) {
-    binder.bind(IOutlineContribution.class)
-          .annotatedWith(IOutlineContribution.LinkWithEditor.class)
-          .to(LinkWithEditor.class);
+  
+  public Class<? extends IEObjectDocumentationProvider> bindObjectDocumentationProvider() {
+    return ProtobufDocumentationProvider.class;
   }
 
-  public void configureGeneralSettingsPreferencesInitializer(Binder binder) {
-    configurePreferenceInitializer(binder, "generalPreferences", GeneralPreferenceStoreInitializer.class);
+  public Class<? extends IPreferenceStoreAccess> bindPreferenceStoreAccess() {
+    return PreferenceStoreAccess.class;
   }
 
-  public void configureCompilerPreferencesInitializer(Binder binder) {
-    configurePreferenceInitializer(binder, "compilerPreferences", CompilerPreferenceStoreInitializer.class);
+  public Class<? extends ISemanticHighlightingCalculator> bindSemanticHighlightingCalculator() {
+    return ProtobufSemanticHighlightingCalculator.class;
   }
 
-  public void configurePathsPreferencesInitializer(Binder binder) {
-    configurePreferenceInitializer(binder, "pathsPreferences", PathsPreferenceStoreInitializer.class);
+  public Class<? extends XtextDocumentProvider> bindXtextDocumentProvider() {
+    return ProtobufDocumentProvider.class;
   }
 
-  public void configureNumericTagPreferencesInitializer(Binder binder) {
-    configurePreferenceInitializer(binder, "numericTagPreferences", NumericTagPreferenceStoreInitializer.class);
-  }
-
-  public void configureSaveActionsPreferencesInitializer(Binder binder) {
-    configurePreferenceInitializer(binder, "saveActionsPreferences", SaveActionsPreferenceStoreInitializer.class);
-  }
-
-  private void configurePreferenceInitializer(Binder binder, String name,
-      Class<? extends IPreferenceStoreInitializer> initializerType) {
-    binder.bind(IPreferenceStoreInitializer.class).annotatedWith(named(name)).to(initializerType);
-  }
-
-  public void configureFileUriResolver(Binder binder) {
-    binder.bind(IFileUriResolver.class).to(FileUriResolver.class);
-  }
-
-  public void configureDocumentProvider(Binder binder) {
-    binder.bind(XtextDocumentProvider.class).to(ProtobufDocumentProvider.class);
+  public Class<? extends XtextQuickAssistProcessor> bindXtextQuickAssistProcessor(){
+    return ProtobufQuickAssistProcessor.class;
   }
 
   @Override public void configureLanguageSpecificURIEditorOpener(Binder binder) {
@@ -120,19 +116,22 @@
           .to(ProtobufUriEditorOpener.class);
   }
 
-  public void configureSemanticHighlightingCalculator(Binder binder) {
-    binder.bind(ISemanticHighlightingCalculator.class).to(ProtobufSemanticHighlightingCalculator.class);
+  public void configurePreferencesInitializers(Binder binder) {
+    configurePreferenceInitializer(binder, "compilerPreferences", CompilerPreferenceStoreInitializer.class);
+    configurePreferenceInitializer(binder, "generalPreferences", GeneralPreferenceStoreInitializer.class);
+    configurePreferenceInitializer(binder, "numericTagPreferences", NumericTagPreferenceStoreInitializer.class);
+    configurePreferenceInitializer(binder, "pathsPreferences", PathsPreferenceStoreInitializer.class);
+    configurePreferenceInitializer(binder, "saveActionsPreferences", SaveActionsPreferenceStoreInitializer.class);
   }
 
-  public void configurePreferenceStoreAccess(Binder binder) {
-    binder.bind(IPreferenceStoreAccess.class).to(PreferenceStoreAccess.class);
+  private void configurePreferenceInitializer(Binder binder, String name,
+      Class<? extends IPreferenceStoreInitializer> initializerType) {
+    binder.bind(IPreferenceStoreInitializer.class).annotatedWith(named(name)).to(initializerType);
   }
 
-  public void configureHighlightingConfiguration(Binder binder) {
-    binder.bind(IHighlightingConfiguration.class).to(HighlightingConfiguration.class);
-  }
-
-  public void configureEObjectDocumentationProvider(Binder binder) {
-    binder.bind(IEObjectDocumentationProvider.class).to(ProtobufDocumentationProvider.class);
+  @Override public void configureToggleLinkWithEditorOutlineContribution(Binder binder) {
+    binder.bind(IOutlineContribution.class)
+          .annotatedWith(IOutlineContribution.LinkWithEditor.class)
+          .to(LinkWithEditor.class);
   }
 }
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconcileStrategy.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconcileStrategy.java
new file mode 100644
index 0000000..25220b7
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconcileStrategy.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ * 
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * 
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.editor.spelling;
+
+import org.eclipse.jface.text.*;
+import org.eclipse.jface.text.reconciler.DirtyRegion;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.texteditor.spelling.*;
+import org.eclipse.xtext.ui.editor.reconciler.XtextDocumentReconcileStrategy;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufReconcileStrategy extends XtextDocumentReconcileStrategy {
+
+  private SpellingReconcileStrategy spellingStrategy;
+
+  @Override public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
+    super.reconcile(dirtyRegion, subRegion);
+    if (spellingStrategy == null) return;
+    spellingStrategy.reconcile(dirtyRegion, subRegion);
+  }
+
+  @Override public void reconcile(IRegion subRegion) {
+    super.reconcile(subRegion);
+    initialReconcile();
+  }
+
+  @Override public void setDocument(IDocument document) {
+    super.setDocument(document);
+    if (spellingStrategy == null) return;
+    spellingStrategy.setDocument(document);
+    initialReconcile();
+  }
+
+  private void initialReconcile() {
+    if (spellingStrategy == null) return;
+    spellingStrategy.initialReconcile();
+  }
+
+  void addSpellSupport(ISourceViewer viewer, SpellingService spellingService) {
+    if (spellingStrategy != null) return;
+    spellingStrategy = new SpellingReconcileStrategy(viewer, spellingService);
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconciler.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconciler.java
new file mode 100644
index 0000000..ba6496f
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/editor/spelling/ProtobufReconciler.java
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ * 
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * 
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.editor.spelling;
+
+import static org.eclipse.ui.editors.text.EditorsUI.getSpellingService;
+
+import com.google.inject.Inject;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.xtext.ui.editor.reconciler.XtextReconciler;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufReconciler extends XtextReconciler {
+
+  private boolean installed;
+
+  @Inject public ProtobufReconciler(ProtobufReconcileStrategy strategy) {
+    super(strategy);
+  }
+
+  @Override public void install(ITextViewer textViewer) {
+    if (installed) return;
+    super.install(textViewer);
+    if (textViewer instanceof ISourceViewer) {
+      ISourceViewer viewer = (ISourceViewer) textViewer;
+      ProtobufReconcileStrategy strategy = (ProtobufReconcileStrategy) getReconcilingStrategy("");
+      strategy.addSpellSupport(viewer, getSpellingService());
+    }
+    installed = true;
+  }
+}
diff --git a/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickAssistProcessor.java b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickAssistProcessor.java
new file mode 100644
index 0000000..15aa610
--- /dev/null
+++ b/com.google.eclipse.protobuf.ui/src/com/google/eclipse/protobuf/ui/quickfix/ProtobufQuickAssistProcessor.java
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2011 Google Inc.
+ * 
+ * All rights reserved. This program and the accompanying materials are made
+ * available under the terms of the Eclipse Public License v1.0 which
+ * accompanies this distribution, and is available at
+ * 
+ * http://www.eclipse.org/legal/epl-v10.html
+ */
+package com.google.eclipse.protobuf.ui.quickfix;
+
+import static java.util.Arrays.asList;
+
+import com.google.inject.Inject;
+
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext;
+import org.eclipse.ui.texteditor.spelling.SpellingCorrectionProcessor;
+import org.eclipse.xtext.ui.editor.quickfix.XtextQuickAssistProcessor;
+
+import java.util.*;
+
+/**
+ * @author alruiz@google.com (Alex Ruiz)
+ */
+public class ProtobufQuickAssistProcessor extends XtextQuickAssistProcessor {
+
+  @Inject private SpellingCorrectionProcessor spellingCorrectionProcessor;
+
+  @Override public ICompletionProposal[] computeQuickAssistProposals(IQuickAssistInvocationContext invocationContext) {
+    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
+    proposals.addAll(asList(spellingCorrectionProcessor.computeQuickAssistProposals(invocationContext)));
+    proposals.addAll(asList(super.computeQuickAssistProposals(invocationContext)));
+    return proposals.toArray(new ICompletionProposal[proposals.size()]);
+  }
+}