misc changes
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / PHPSourceViewerConfiguration.java
index 038abd3..5ecde70 100644 (file)
@@ -13,19 +13,24 @@ package net.sourceforge.phpeclipse.phpeditor;
 import java.util.Vector;
 
 import net.sourceforge.phpdt.core.JavaCore;
+import net.sourceforge.phpdt.internal.ui.text.AbstractJavaScanner;
 import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
 import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter;
 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
 import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover;
+import net.sourceforge.phpdt.internal.ui.text.JavaCompositeReconcilingStrategy;
 import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider;
 import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl;
+import net.sourceforge.phpdt.internal.ui.text.JavaPresentationReconciler;
 import net.sourceforge.phpdt.internal.ui.text.JavaReconciler;
 import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy;
 import net.sourceforge.phpdt.internal.ui.text.java.JavaReconcilingStrategy;
+import net.sourceforge.phpdt.internal.ui.text.java.JavaStringAutoIndentStrategy;
 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor;
 import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverProxy;
 import net.sourceforge.phpdt.internal.ui.text.phpdoc.PHPDocCompletionProcessor;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
+import net.sourceforge.phpdt.ui.text.IColorManager;
 import net.sourceforge.phpdt.ui.text.JavaTextTools;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.phpeditor.html.HTMLFormattingStrategy;
@@ -34,7 +39,7 @@ import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor;
 import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector;
 import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider;
-import org.eclipse.core.resources.IFile;
+
 import org.eclipse.core.runtime.NullProgressMonitor;
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.text.DefaultAutoIndentStrategy;
@@ -67,10 +72,10 @@ import org.eclipse.jface.text.rules.Token;
 import org.eclipse.jface.text.source.IAnnotationHover;
 import org.eclipse.jface.text.source.ISourceViewer;
 import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.jface.util.PropertyChangeEvent;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.texteditor.ITextEditor;
 /**
  * Configuration for an <code>SourceViewer</code> which shows PHP code.
  */
@@ -91,7 +96,7 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
        // IPHPPartitionScannerConstants.HTML;
        //IDocument.DEFAULT_CONTENT_TYPE;
        private JavaTextTools fJavaTextTools;
-       private PHPEditor fEditor;
+       private ITextEditor fTextEditor;
        private ContentFormatter fFormatter;
        private HTMLFormattingStrategy fFormattingStrategy;
        /**
@@ -103,12 +108,78 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
                }
        };
        /**
+        * The document partitioning.
+        * @since 3.0
+        */
+       private String fDocumentPartitioning;
+       /**
+        * The Java source code scanner
+        * @since 3.0
+        */
+       private AbstractJavaScanner fCodeScanner;
+       /** 
+        * The Java multi-line comment scanner 
+        * @since 3.0
+        */
+       private AbstractJavaScanner fMultilineCommentScanner;
+       /**
+        * The Java single-line comment scanner
+        * @since 3.0
+        */
+       private AbstractJavaScanner fSinglelineCommentScanner;
+       /**
+        * The Java string scanner
+        * @since 3.0
+        */
+       private AbstractJavaScanner fStringScanner;
+       /**
+        * The Javadoc scanner
+        * @since 3.0
+        */
+       private AbstractJavaScanner fJavaDocScanner;
+       /**
+        * The preference store, can be read-only
+        * @since 3.0
+        */
+       private IPreferenceStore fPreferenceStore;
+       /**
+        * The color manager
+        * @since 3.0
+        */
+       private IColorManager fColorManager;
+       
+       /**
+        * Creates a new Java source viewer configuration for viewers in the given editor 
+        * using the given preference store, the color manager and the specified document partitioning.
+        * <p>
+        * Creates a Java source viewer configuration in the new setup without text tools. Clients are
+        * allowed to call {@link JavaSourceViewerConfiguration#handlePropertyChangeEvent(PropertyChangeEvent)}
+        * and disallowed to call {@link JavaSourceViewerConfiguration#getPreferenceStore()} on the resulting
+        * Java source viewer configuration.
+        * </p>
+        *
+        * @param colorManager the color manager
+        * @param preferenceStore the preference store, can be read-only
+        * @param editor the editor in which the configured viewer(s) will reside
+        * @param partitioning the document partitioning for this configuration
+        * @since 3.0
+        */
+       public PHPSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore preferenceStore, ITextEditor editor, String partitioning) {
+               fColorManager= colorManager;
+               fPreferenceStore= preferenceStore;
+               fTextEditor= editor;
+               fDocumentPartitioning= partitioning;
+               fJavaTextTools = PHPeclipsePlugin.getDefault().getJavaTextTools();
+//             initializeScanners();
+       }
+
+       /**
         * Default constructor.
         */
        public PHPSourceViewerConfiguration(JavaTextTools textTools,
                        PHPEditor editor) {
                fJavaTextTools = textTools;
-               fEditor = editor;
+               fTextEditor = editor;
        }
        /*
         * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer)
@@ -164,8 +235,8 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
        //  private String[] getPartitionManagingPositionCategories() {
        //    return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY };
        //  }
-       public PHPEditor getEditor() {
-               return fEditor;
+       public ITextEditor getEditor() {
+               return fTextEditor;
        }
        /**
         * Returns the preference store used by this configuration to initialize
@@ -203,6 +274,9 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
         */
        public IAutoIndentStrategy getAutoIndentStrategy(
                        ISourceViewer sourceViewer, String contentType) {
+               if (IPHPPartitions.PHP_STRING_DQ.equals(contentType))
+                       return new JavaStringAutoIndentStrategy(getConfiguredDocumentPartitioning(sourceViewer));
+
                return (IPHPPartitions.PHP_PARTITIONING.equals(contentType)
                                ? new PHPAutoIndentStrategy()
                                : new DefaultAutoIndentStrategy());
@@ -234,16 +308,34 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
        /*
         * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
         */
+       /*
+        * @see SourceViewerConfiguration#getReconciler(ISourceViewer)
+        */
        public IReconciler getReconciler(ISourceViewer sourceViewer) {
-               if (getEditor() != null && getEditor().isEditable()) {
-                       JavaReconciler reconciler = new JavaReconciler(getEditor(),
-                                       new JavaReconcilingStrategy(getEditor()), false);
+
+               final ITextEditor editor= getEditor();
+               if (editor != null && editor.isEditable()) {
+                       
+                       JavaCompositeReconcilingStrategy strategy= new JavaCompositeReconcilingStrategy(editor, getConfiguredDocumentPartitioning(sourceViewer));
+                       JavaReconciler reconciler= new JavaReconciler(editor, strategy, false);
+                       reconciler.setIsIncrementalReconciler(false);
                        reconciler.setProgressMonitor(new NullProgressMonitor());
                        reconciler.setDelay(500);
+
                        return reconciler;
                }
                return null;
        }
+//     public IReconciler getReconciler(ISourceViewer sourceViewer) {
+//             if (getEditor() != null && getEditor().isEditable()) {
+//                     JavaReconciler reconciler = new JavaReconciler(getEditor(),
+//                                     new JavaReconcilingStrategy(getEditor()), false);
+//                     reconciler.setProgressMonitor(new NullProgressMonitor());
+//                     reconciler.setDelay(500);
+//                     return reconciler;
+//             }
+//             return null;
+//     }
        /*
         * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer,
         *      String)
@@ -336,7 +428,7 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
                return new String[]{IPHPPartitions.HTML,
                                IPHPPartitions.HTML_MULTILINE_COMMENT,
                                IPHPPartitions.PHP_PARTITIONING,
-                               IPHPPartitions.PHP_MULTILINE_COMMENT,
+                               IPHPPartitions.PHP_PHPDOC_COMMENT,
                                IPHPPartitions.CSS,
                                IPHPPartitions.CSS_MULTILINE_COMMENT,
                                IPHPPartitions.JAVASCRIPT,
@@ -370,10 +462,10 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
                                IPHPPartitions.SMARTY);
                assistant.setContentAssistProcessor(processor,
                                IPHPPartitions.SMARTY_MULTILINE_COMMENT);
-               assistant.setContentAssistProcessor(new PHPCompletionProcessor(),
+               assistant.setContentAssistProcessor(new PHPCompletionProcessor(getEditor()),
                                IPHPPartitions.PHP_PARTITIONING);
                assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(),
-                               IPHPPartitions.PHP_MULTILINE_COMMENT);
+                               IPHPPartitions.PHP_PHPDOC_COMMENT);
                //    assistant.enableAutoActivation(true);
                //    assistant.setAutoActivationDelay(500);
                //    assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY);
@@ -453,7 +545,9 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
                // PHPEditorEnvironment.getPHPColorProvider();
                //    JavaColorManager provider =
                // PHPEditorEnvironment.getPHPColorProvider();
-               PresentationReconciler reconciler = new PresentationReconciler();
+               PresentationReconciler reconciler= new JavaPresentationReconciler();
+               reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
+
                DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner());
                reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
                reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
@@ -496,9 +590,9 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
                reconciler.setRepairer(dr, IPHPPartitions.PHP_PARTITIONING);
                dr = new DefaultDamagerRepairer(getPHPDocScanner());
                reconciler.setDamager(dr,
-                               IPHPPartitions.PHP_MULTILINE_COMMENT);
+                               IPHPPartitions.PHP_PHPDOC_COMMENT);
                reconciler.setRepairer(dr,
-                               IPHPPartitions.PHP_MULTILINE_COMMENT);
+                               IPHPPartitions.PHP_PHPDOC_COMMENT);
                return reconciler;
        }
        /*
@@ -624,7 +718,7 @@ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration {
                presenter.setInformationProvider(provider,
                                IPHPPartitions.PHP_PARTITIONING);
                presenter.setInformationProvider(provider,
-                               IPHPPartitions.PHP_MULTILINE_COMMENT);
+                               IPHPPartitions.PHP_PHPDOC_COMMENT);
                presenter.setInformationProvider(provider,
                                IPHPPartitions.SMARTY_MULTILINE_COMMENT);
                presenter.setInformationProvider(provider,