1) Fixed issue #828: Non initialized variable warnings doesn't work with variables...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / phpeditor / JavaSourceViewer.java
index e3e75ac..bb21a7e 100644 (file)
@@ -15,12 +15,16 @@ import java.util.ArrayList;
 
 import net.sourceforge.phpdt.internal.ui.text.SmartBackspaceManager;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
+import net.sourceforge.phpdt.ui.text.PHPSourceViewerConfiguration;
 
 import org.eclipse.jface.preference.IPreferenceStore;
 import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.text.Assert;
+//incastrix
+//import org.eclipse.jface.text.Assert;
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.jface.text.ITextPresentationListener;
 import org.eclipse.jface.text.information.IInformationPresenter;
+import org.eclipse.jface.text.reconciler.IReconciler;
 import org.eclipse.jface.text.source.IOverviewRuler;
 import org.eclipse.jface.text.source.IVerticalRuler;
 import org.eclipse.jface.text.source.SourceViewerConfiguration;
@@ -35,70 +39,85 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants;
 
+public class JavaSourceViewer extends ProjectionViewer implements
+               IPropertyChangeListener {
 
-
-public class JavaSourceViewer extends ProjectionViewer implements IPropertyChangeListener {
-    
-       /** 
+       /**
         * Text operation code for requesting the outline for the current input.
         */
-       public static final int SHOW_OUTLINE= 51;
+       public static final int SHOW_OUTLINE = 51;
 
        /**
-        * Text operation code for requesting the outline for the element at the current position.
+        * Text operation code for requesting the outline for the element at the
+        * current position.
         */
-       public static final int OPEN_STRUCTURE= 52;
+       public static final int OPEN_STRUCTURE = 52;
 
        /**
         * Text operation code for requesting the hierarchy for the current input.
         */
-       public static final int SHOW_HIERARCHY= 53;
+       public static final int SHOW_HIERARCHY = 53;
 
        private IInformationPresenter fOutlinePresenter;
+
        private IInformationPresenter fStructurePresenter;
-//     private IInformationPresenter fHierarchyPresenter;
+
+       // private IInformationPresenter fHierarchyPresenter;
 
        /**
         * This viewer's foreground color.
+        * 
         * @since 3.0
         */
        private Color fForegroundColor;
-       /** 
+
+       /**
         * The viewer's background color.
+        * 
         * @since 3.0
         */
        private Color fBackgroundColor;
+
        /**
         * This viewer's selection foreground color.
+        * 
         * @since 3.0
         */
        private Color fSelectionForegroundColor;
-       /** 
+
+       /**
         * The viewer's selection background color.
+        * 
         * @since 3.0
         */
        private Color fSelectionBackgroundColor;
+
        /**
         * The preference store.
         * 
         * @since 3.0
         */
        private IPreferenceStore fPreferenceStore;
+
        /**
         * Is this source viewer configured?
         * 
         * @since 3.0
         */
        private boolean fIsConfigured;
+
        /**
         * The backspace manager of this viewer.
         * 
         * @since 3.0
         */
        private SmartBackspaceManager fBackspaceManager;
-       
-       public JavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles, IPreferenceStore store) {
-               super(parent, verticalRuler, overviewRuler, showAnnotationsOverview, styles);
+
+       public JavaSourceViewer(Composite parent, IVerticalRuler verticalRuler,
+                       IOverviewRuler overviewRuler, boolean showAnnotationsOverview,
+                       int styles, IPreferenceStore store) {
+               super(parent, verticalRuler, overviewRuler, showAnnotationsOverview,
+                               styles);
                setPreferenceStore(store);
        }
 
@@ -106,17 +125,17 @@ public class JavaSourceViewer extends ProjectionViewer implements IPropertyChang
         * @see org.eclipse.jface.text.source.SourceViewer#createFormattingContext()
         * @since 3.0
         */
-//     public IFormattingContext createFormattingContext() {
-//
-//             IFormattingContext context= new CommentFormattingContext();
-//             Map map= new Hashtable(JavaCore.getOptions());
-//             
-//             context.storeToMap(PreferenceConstants.getPreferenceStore(), map, false);
-//             context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, map);
-//             
-//             return context;
-//     }
-
+       // public IFormattingContext createFormattingContext() {
+       //
+       // IFormattingContext context= new CommentFormattingContext();
+       // Map map= new Hashtable(JavaCore.getOptions());
+       //              
+       // context.storeToMap(PreferenceConstants.getPreferenceStore(), map, false);
+       // context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES,
+       // map);
+       //              
+       // return context;
+       // }
        /*
         * @see ITextOperationTarget#doOperation(int)
         */
@@ -125,23 +144,24 @@ public class JavaSourceViewer extends ProjectionViewer implements IPropertyChang
                        return;
 
                switch (operation) {
-                       case SHOW_OUTLINE:
-                               fOutlinePresenter.showInformation();
-                               return;
-                       case OPEN_STRUCTURE:
-                               fStructurePresenter.showInformation();
-                               return;
-                       case SHOW_HIERARCHY:
-//                             fHierarchyPresenter.showInformation();
-                               return; 
-                   case FORMAT:
-                     Point point = getSelectedRange();
-                     if (point.y==0) {
-                       setSelectedRange(0, getDocument().getLength());
-                     }
-                     break;
+               case SHOW_OUTLINE:
+                       fOutlinePresenter.showInformation();
+                       return;
+               case OPEN_STRUCTURE:
+                       fStructurePresenter.showInformation();
+                       return;
+               case SHOW_HIERARCHY:
+                       // fHierarchyPresenter.showInformation();
+                       return;
+               case FORMAT:
+                       Point point = getSelectedRange();
+                       if (point.y == 0) {
+                               // setSelectedRange(0, getDocument().getLength());
+                               revealRange(0, getDocument().getLength());
+                       }
+                       break;
                }
-               
+
                super.doOperation(operation);
        }
 
@@ -154,9 +174,9 @@ public class JavaSourceViewer extends ProjectionViewer implements IPropertyChang
                if (operation == OPEN_STRUCTURE)
                        return fStructurePresenter != null;
                if (operation == SHOW_HIERARCHY)
-//                     return fHierarchyPresenter != null;     
+                       // return fHierarchyPresenter != null;
                        return false;
-                       
+
                return super.canDoOperation(operation);
        }
 
@@ -166,104 +186,123 @@ public class JavaSourceViewer extends ProjectionViewer implements IPropertyChang
        public void configure(SourceViewerConfiguration configuration) {
                super.configure(configuration);
                if (configuration instanceof PHPSourceViewerConfiguration) {
-                       fOutlinePresenter= ((PHPSourceViewerConfiguration)configuration).getOutlinePresenter(this, false);
+                       fOutlinePresenter = ((PHPSourceViewerConfiguration) configuration)
+                                       .getOutlinePresenter(this, false);
                        fOutlinePresenter.install(this);
                }
                if (configuration instanceof PHPSourceViewerConfiguration) {
-                       fStructurePresenter= ((PHPSourceViewerConfiguration)configuration).getOutlinePresenter(this, true);
+                       fStructurePresenter = ((PHPSourceViewerConfiguration) configuration)
+                                       .getOutlinePresenter(this, true);
                        fStructurePresenter.install(this);
                }
                if (configuration instanceof PHPSourceViewerConfiguration) {
-//                     fHierarchyPresenter= ((PHPSourceViewerConfiguration)configuration).getHierarchyPresenter(this, true);
-//                     fHierarchyPresenter.install(this);
-            
+                       // fHierarchyPresenter=
+                       // ((PHPSourceViewerConfiguration)configuration).getHierarchyPresenter(this,
+                       // true);
+                       // fHierarchyPresenter.install(this);
+
                        if (fPreferenceStore != null) {
                                fPreferenceStore.addPropertyChangeListener(this);
                                initializeViewerColors();
                        }
                }
-               fIsConfigured= true;
+               fIsConfigured = true;
        }
-       
-    
+
        protected void initializeViewerColors() {
                if (fPreferenceStore != null) {
-                       
-                       StyledText styledText= getTextWidget();
-                       
+
+                       StyledText styledText = getTextWidget();
+
                        // ----------- foreground color --------------------
-                       Color color= fPreferenceStore.getBoolean(PreferenceConstants.EDITOR_FOREGROUND_DEFAULT_COLOR)
-                       ? null
-                       : createColor(fPreferenceStore, PreferenceConstants.EDITOR_FOREGROUND_COLOR, styledText.getDisplay());
+                       Color color = fPreferenceStore
+                                       .getBoolean(PreferenceConstants.EDITOR_FOREGROUND_DEFAULT_COLOR) ? null
+                                       : createColor(fPreferenceStore,
+                                                       PreferenceConstants.EDITOR_FOREGROUND_COLOR,
+                                                       styledText.getDisplay());
                        styledText.setForeground(color);
-                       
+
                        if (fForegroundColor != null)
                                fForegroundColor.dispose();
-                       
-                       fForegroundColor= color;
-                       
+
+                       fForegroundColor = color;
+
                        // ---------- background color ----------------------
-                       color= fPreferenceStore.getBoolean(PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR)
-                       ? null
-                       : createColor(fPreferenceStore, PreferenceConstants.EDITOR_BACKGROUND_COLOR, styledText.getDisplay());
+                       color = fPreferenceStore
+                                       .getBoolean(PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR) ? null
+                                       : createColor(fPreferenceStore,
+                                                       PreferenceConstants.EDITOR_BACKGROUND_COLOR,
+                                                       styledText.getDisplay());
                        styledText.setBackground(color);
-                       
+
                        if (fBackgroundColor != null)
                                fBackgroundColor.dispose();
-                       
-                       fBackgroundColor= color;
-                       
+
+                       fBackgroundColor = color;
+
                        // ----------- selection foreground color --------------------
-                       color= fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR)
-                               ? null
-                               : createColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR, styledText.getDisplay());
+                       color = fPreferenceStore
+                                       .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR) ? null
+                                       : createColor(
+                                                       fPreferenceStore,
+                                                       AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR,
+                                                       styledText.getDisplay());
                        styledText.setSelectionForeground(color);
-                               
+
                        if (fSelectionForegroundColor != null)
                                fSelectionForegroundColor.dispose();
-                       
-                       fSelectionForegroundColor= color;
-                       
+
+                       fSelectionForegroundColor = color;
+
                        // ---------- selection background color ----------------------
-                       color= fPreferenceStore.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR)
-                               ? null
-                               : createColor(fPreferenceStore, AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR, styledText.getDisplay());
+                       color = fPreferenceStore
+                                       .getBoolean(AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR) ? null
+                                       : createColor(
+                                                       fPreferenceStore,
+                                                       AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR,
+                                                       styledText.getDisplay());
                        styledText.setSelectionBackground(color);
-                               
+
                        if (fSelectionBackgroundColor != null)
                                fSelectionBackgroundColor.dispose();
-                               
-                       fSelectionBackgroundColor= color;
+
+                       fSelectionBackgroundColor = color;
                }
-    }
-
-    /**
-     * Creates a color from the information stored in the given preference store.
-     * Returns <code>null</code> if there is no such information available.
-     * 
-     * @param store the store to read from
-     * @param key the key used for the lookup in the preference store
-     * @param display the display used create the color
-     * @return the created color according to the specification in the preference store
-     * @since 3.0
-     */
-    private Color createColor(IPreferenceStore store, String key, Display display) {
-    
-        RGB rgb= null;      
-        
-        if (store.contains(key)) {
-            
-            if (store.isDefault(key))
-                rgb= PreferenceConverter.getDefaultColor(store, key);
-            else
-                rgb= PreferenceConverter.getColor(store, key);
-        
-            if (rgb != null)
-                return new Color(display, rgb);
-        }
-        
-        return null;
-    }
+       }
+
+       /**
+        * Creates a color from the information stored in the given preference
+        * store. Returns <code>null</code> if there is no such information
+        * available.
+        * 
+        * @param store
+        *            the store to read from
+        * @param key
+        *            the key used for the lookup in the preference store
+        * @param display
+        *            the display used create the color
+        * @return the created color according to the specification in the
+        *         preference store
+        * @since 3.0
+        */
+       private Color createColor(IPreferenceStore store, String key,
+                       Display display) {
+
+               RGB rgb = null;
+
+               if (store.contains(key)) {
+
+                       if (store.isDefault(key))
+                               rgb = PreferenceConverter.getDefaultColor(store, key);
+                       else
+                               rgb = PreferenceConverter.getColor(store, key);
+
+                       if (rgb != null)
+                               return new Color(display, rgb);
+               }
+
+               return null;
+       }
 
        /*
         * @see org.eclipse.jface.text.source.ISourceViewerExtension2#unconfigure()
@@ -271,40 +310,40 @@ public class JavaSourceViewer extends ProjectionViewer implements IPropertyChang
         */
        public void unconfigure() {
                if (fOutlinePresenter != null) {
-                       fOutlinePresenter.uninstall();  
-                       fOutlinePresenter= null;
+                       fOutlinePresenter.uninstall();
+                       fOutlinePresenter = null;
                }
                if (fStructurePresenter != null) {
                        fStructurePresenter.uninstall();
-                       fStructurePresenter= null;
+                       fStructurePresenter = null;
                }
-//             if (fHierarchyPresenter != null) {
-//                     fHierarchyPresenter.uninstall();
-//                     fHierarchyPresenter= null;
-//             }
+               // if (fHierarchyPresenter != null) {
+               // fHierarchyPresenter.uninstall();
+               // fHierarchyPresenter= null;
+               // }
                if (fForegroundColor != null) {
                        fForegroundColor.dispose();
-                       fForegroundColor= null;
+                       fForegroundColor = null;
                }
                if (fBackgroundColor != null) {
                        fBackgroundColor.dispose();
-                       fBackgroundColor= null;
+                       fBackgroundColor = null;
                }
                if (fPreferenceStore != null)
                        fPreferenceStore.removePropertyChangeListener(this);
-               
+
                super.unconfigure();
-               
-               fIsConfigured= false;
+
+               fIsConfigured = false;
        }
-       
+
        /*
         * @see org.eclipse.jface.text.source.SourceViewer#rememberSelection()
         */
        public Point rememberSelection() {
                return super.rememberSelection();
        }
-       
+
        /*
         * @see org.eclipse.jface.text.source.SourceViewer#restoreSelection()
         */
@@ -318,47 +357,54 @@ public class JavaSourceViewer extends ProjectionViewer implements IPropertyChang
        public void propertyChange(PropertyChangeEvent event) {
                String property = event.getProperty();
                if (PreferenceConstants.EDITOR_FOREGROUND_COLOR.equals(property)
-                               || PreferenceConstants.EDITOR_FOREGROUND_DEFAULT_COLOR.equals(property)
+                               || PreferenceConstants.EDITOR_FOREGROUND_DEFAULT_COLOR
+                                               .equals(property)
                                || PreferenceConstants.EDITOR_BACKGROUND_COLOR.equals(property)
-                               || PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR.equals(property)
-                               || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR.equals(property)
-                               || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR.equals(property)
-                               || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR.equals(property)
-                               || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR.equals(property))
-               {
+                               || PreferenceConstants.EDITOR_BACKGROUND_DEFAULT_COLOR
+                                               .equals(property)
+                               || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_COLOR
+                                               .equals(property)
+                               || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_FOREGROUND_DEFAULT_COLOR
+                                               .equals(property)
+                               || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_COLOR
+                                               .equals(property)
+                               || AbstractDecoratedTextEditorPreferenceConstants.EDITOR_SELECTION_BACKGROUND_DEFAULT_COLOR
+                                               .equals(property)) {
                        initializeViewerColors();
-               }               
+               }
        }
 
        /**
         * Sets the preference store on this viewer.
         * 
-        * @param store the preference store
+        * @param store
+        *            the preference store
         * 
         * @since 3.0
         */
        public void setPreferenceStore(IPreferenceStore store) {
                if (fIsConfigured && fPreferenceStore != null)
                        fPreferenceStore.removePropertyChangeListener(this);
-               
-               fPreferenceStore= store;
+
+               fPreferenceStore = store;
 
                if (fIsConfigured && fPreferenceStore != null) {
                        fPreferenceStore.addPropertyChangeListener(this);
                        initializeViewerColors();
                }
        }
-       
+
        /*
-        * @see org.eclipse.jface.text.source.SourceViewer#createControl(org.eclipse.swt.widgets.Composite, int)
+        * @see org.eclipse.jface.text.source.SourceViewer#createControl(org.eclipse.swt.widgets.Composite,
+        *      int)
         */
        protected void createControl(Composite parent, int styles) {
                super.createControl(parent, styles);
 
-               fBackspaceManager= new SmartBackspaceManager();
+               fBackspaceManager = new SmartBackspaceManager();
                fBackspaceManager.install(this);
        }
-       
+
        /**
         * Returns the backspace manager for this viewer.
         * 
@@ -369,36 +415,59 @@ public class JavaSourceViewer extends ProjectionViewer implements IPropertyChang
        public SmartBackspaceManager getBackspaceManager() {
                return fBackspaceManager;
        }
-       
+
        /*
         * @see org.eclipse.jface.text.source.SourceViewer#handleDispose()
         */
        protected void handleDispose() {
                if (fBackspaceManager != null) {
                        fBackspaceManager.uninstall();
-                       fBackspaceManager= null;
+                       fBackspaceManager = null;
                }
 
                super.handleDispose();
        }
-       
+
        /**
-        * Prepends the text presentation listener at the beginning of the viewer's 
-        * list of text presentation listeners.  If the listener is already registered 
-        * with the viewer this call moves the listener to the beginning of
-        * the list.
-        *
-        * @param listener the text presentation listener
+        * Prepends the text presentation listener at the beginning of the viewer's
+        * list of text presentation listeners. If the listener is already
+        * registered with the viewer this call moves the listener to the beginning
+        * of the list.
+        * 
+        * @param listener
+        *            the text presentation listener
         * @since 3.0
         */
-       public void prependTextPresentationListener(ITextPresentationListener listener) {
-               
+       public void prependTextPresentationListener(
+                       ITextPresentationListener listener) {
+
                Assert.isNotNull(listener);
 
                if (fTextPresentationListeners == null)
-                       fTextPresentationListeners= new ArrayList();
-               
+                       fTextPresentationListeners = new ArrayList();
+
                fTextPresentationListeners.remove(listener);
                fTextPresentationListeners.add(0, listener);
        }
+
+       /**
+        * Sets the given reconciler.
+        * 
+        * @param reconciler
+        *            the reconciler
+        * @since 3.0
+        */
+       void setReconciler(IReconciler reconciler) {
+               fReconciler = reconciler;
+       }
+
+       /**
+        * Returns the reconciler.
+        * 
+        * @return the reconciler or <code>null</code> if not set
+        * @since 3.0
+        */
+       Object getReconciler() {
+               return fReconciler;
+       }
 }