A massive organize imports and formatting of the sources using default Eclipse code...
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / ui / text / java / hover / AnnotationExpandHover.java
index f8cea73..581517a 100644 (file)
@@ -18,13 +18,7 @@ import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.viewers.IDoubleClickListener;
+import net.sourceforge.phpdt.internal.ui.text.java.hover.AnnotationExpansionControl.AnnotationHoverInput;
 
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.IDocument;
@@ -46,26 +40,32 @@ import org.eclipse.jface.text.source.ISourceViewer;
 import org.eclipse.jface.text.source.IVerticalRulerListener;
 import org.eclipse.jface.text.source.LineRange;
 import org.eclipse.jface.text.source.VerticalRulerEvent;
-
-import net.sourceforge.phpdt.internal.ui.text.java.hover.AnnotationExpansionControl.AnnotationHoverInput;
-
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.StyledText;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
 
 /**
- * This class got moved here form Platform Text since it was not used there
- * and caused discouraged access warnings. It will be moved down again once
+ * This class got moved here form Platform Text since it was not used there and
+ * caused discouraged access warnings. It will be moved down again once
  * annotation roll-over support is provided by Platform Text.
- *   
+ * 
  * @since 3.2
  */
-public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHoverExtension {
+public class AnnotationExpandHover implements IAnnotationHover,
+               IAnnotationHoverExtension {
 
-       private class InformationControlCreator implements IInformationControlCreator, IInformationControlCreatorExtension {
+       private class InformationControlCreator implements
+                       IInformationControlCreator, IInformationControlCreatorExtension {
 
                /*
                 * @see org.eclipse.jface.text.IInformationControlCreator#createInformationControl(org.eclipse.swt.widgets.Shell)
                 */
                public IInformationControl createInformationControl(Shell parent) {
-                       return new AnnotationExpansionControl(parent, SWT.NONE, fAnnotationAccess);
+                       return new AnnotationExpansionControl(parent, SWT.NONE,
+                                       fAnnotationAccess);
                }
 
                /*
@@ -100,35 +100,42 @@ public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHover
                }
 
                /*
-                * @see org.eclipse.jface.text.source.IVerticalRulerListener#annotationContextMenuAboutToShow(org.eclipse.jface.text.source.VerticalRulerEvent, org.eclipse.swt.widgets.Menu)
+                * @see org.eclipse.jface.text.source.IVerticalRulerListener#annotationContextMenuAboutToShow(org.eclipse.jface.text.source.VerticalRulerEvent,
+                *      org.eclipse.swt.widgets.Menu)
                 */
-               public void annotationContextMenuAboutToShow(VerticalRulerEvent event, Menu menu) {
+               public void annotationContextMenuAboutToShow(VerticalRulerEvent event,
+                               Menu menu) {
                        fCompositeRuler.fireAnnotationContextMenuAboutToShow(event, menu);
                }
        }
 
+       private final IInformationControlCreator fgCreator = new InformationControlCreator();
+
+       protected final IVerticalRulerListener fgListener = new VerticalRulerListener();
 
-       private final IInformationControlCreator fgCreator= new InformationControlCreator();
-       protected final IVerticalRulerListener fgListener= new VerticalRulerListener();
        protected CompositeRuler fCompositeRuler;
+
        protected IDoubleClickListener fDblClickListener;
+
        protected IAnnotationAccess fAnnotationAccess;
 
        /**
         * Creates a new hover instance.
-        *
+        * 
         * @param ruler
         * @param access
         * @param doubleClickListener
         */
-       public AnnotationExpandHover(CompositeRuler ruler, IAnnotationAccess access, IDoubleClickListener doubleClickListener) {
-               fCompositeRuler= ruler;
-               fAnnotationAccess= access;
-               fDblClickListener= doubleClickListener;
+       public AnnotationExpandHover(CompositeRuler ruler,
+                       IAnnotationAccess access, IDoubleClickListener doubleClickListener) {
+               fCompositeRuler = ruler;
+               fAnnotationAccess = access;
+               fDblClickListener = doubleClickListener;
        }
 
        /*
-        * @see org.eclipse.jface.text.source.IAnnotationHover#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, int)
+        * @see org.eclipse.jface.text.source.IAnnotationHover#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer,
+        *      int)
         */
        public String getHoverInfo(ISourceViewer sourceViewer, int line) {
                // we don't have any sensible return value as text
@@ -136,24 +143,25 @@ public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHover
        }
 
        protected Object getHoverInfoForLine(ISourceViewer viewer, int line) {
-               IAnnotationModel model= viewer.getAnnotationModel();
-               IDocument document= viewer.getDocument();
+               IAnnotationModel model = viewer.getAnnotationModel();
+               IDocument document = viewer.getDocument();
 
                if (model == null)
                        return null;
 
-               List exact= new ArrayList();
-               HashMap messagesAtPosition= new HashMap();
+               List exact = new ArrayList();
+               HashMap messagesAtPosition = new HashMap();
 
-               Iterator e= model.getAnnotationIterator();
+               Iterator e = model.getAnnotationIterator();
                while (e.hasNext()) {
-                       Annotation annotation= (Annotation) e.next();
-                       Position position= model.getPosition(annotation);
+                       Annotation annotation = (Annotation) e.next();
+                       Position position = model.getPosition(annotation);
                        if (position == null)
                                continue;
 
                        if (compareRulerLine(position, document, line) == 1) {
-                               if (isDuplicateMessage(messagesAtPosition, position, annotation.getText()))
+                               if (isDuplicateMessage(messagesAtPosition, position, annotation
+                                               .getText()))
                                        continue;
 
                                exact.add(annotation);
@@ -168,13 +176,13 @@ public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHover
                if (exact.size() > 0)
                        setLastRulerMouseLocation(viewer, line);
 
-               AnnotationHoverInput input= new AnnotationHoverInput();
-               input.fAnnotations= (Annotation[]) exact.toArray(new Annotation[0]);
-               input.fViewer= viewer;
-               input.fRulerInfo= fCompositeRuler;
-               input.fAnnotationListener= fgListener;
-               input.fDoubleClickListener= fDblClickListener;
-               input.model= model;
+               AnnotationHoverInput input = new AnnotationHoverInput();
+               input.fAnnotations = (Annotation[]) exact.toArray(new Annotation[0]);
+               input.fViewer = viewer;
+               input.fRulerInfo = fCompositeRuler;
+               input.fAnnotationListener = fgListener;
+               input.fDoubleClickListener = fDblClickListener;
+               input.model = model;
 
                return input;
        }
@@ -183,14 +191,15 @@ public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHover
                class AnnotationComparator implements Comparator {
 
                        /*
-                        * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
+                        * @see java.util.Comparator#compare(java.lang.Object,
+                        *      java.lang.Object)
                         */
                        public int compare(Object o1, Object o2) {
-                               Annotation a1= (Annotation) o1;
-                               Annotation a2= (Annotation) o2;
+                               Annotation a1 = (Annotation) o1;
+                               Annotation a2 = (Annotation) o2;
 
-                               Position p1= model.getPosition(a1);
-                               Position p2= model.getPosition(a2);
+                               Position p1 = model.getPosition(a1);
+                               Position p2 = model.getPosition(a2);
 
                                // annotation order:
                                // primary order: by position in line
@@ -207,28 +216,29 @@ public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHover
 
        protected int getOrder(Annotation annotation) {
                if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
-                       IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
+                       IAnnotationAccessExtension extension = (IAnnotationAccessExtension) fAnnotationAccess;
                        return extension.getLayer(annotation);
                }
                return IAnnotationAccessExtension.DEFAULT_LAYER;
        }
 
-       protected boolean isDuplicateMessage(Map messagesAtPosition, Position position, String message) {
+       protected boolean isDuplicateMessage(Map messagesAtPosition,
+                       Position position, String message) {
                if (message == null)
                        return false;
-               
+
                if (messagesAtPosition.containsKey(position)) {
-                       Object value= messagesAtPosition.get(position);
+                       Object value = messagesAtPosition.get(position);
                        if (message == null || message.equals(value))
                                return true;
 
                        if (value instanceof List) {
-                               List messages= (List)value;
-                               if  (messages.contains(message))
+                               List messages = (List) value;
+                               if (messages.contains(message))
                                        return true;
                                messages.add(message);
                        } else {
-                               ArrayList messages= new ArrayList();
+                               ArrayList messages = new ArrayList();
                                messages.add(value);
                                messages.add(message);
                                messagesAtPosition.put(position, messages);
@@ -241,17 +251,23 @@ public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHover
        protected void setLastRulerMouseLocation(ISourceViewer viewer, int line) {
                // set last mouse activity in order to get the correct context menu
                if (fCompositeRuler != null) {
-                       StyledText st= viewer.getTextWidget();
+                       StyledText st = viewer.getTextWidget();
                        if (st != null && !st.isDisposed()) {
                                if (viewer instanceof ITextViewerExtension5) {
-                                       int widgetLine= ((ITextViewerExtension5)viewer).modelLine2WidgetLine(line);
-                                       Point loc= st.getLocationAtOffset(st.getOffsetAtLine(widgetLine));
-                                       fCompositeRuler.setLocationOfLastMouseButtonActivity(0, loc.y);
+                                       int widgetLine = ((ITextViewerExtension5) viewer)
+                                                       .modelLine2WidgetLine(line);
+                                       Point loc = st.getLocationAtOffset(st
+                                                       .getOffsetAtLine(widgetLine));
+                                       fCompositeRuler.setLocationOfLastMouseButtonActivity(0,
+                                                       loc.y);
                                } else if (viewer instanceof TextViewer) {
                                        // TODO remove once TextViewer implements the extension
-                                       int widgetLine= ((TextViewer)viewer).modelLine2WidgetLine(line);
-                                       Point loc= st.getLocationAtOffset(st.getOffsetAtLine(widgetLine));
-                                       fCompositeRuler.setLocationOfLastMouseButtonActivity(0, loc.y);
+                                       int widgetLine = ((TextViewer) viewer)
+                                                       .modelLine2WidgetLine(line);
+                                       Point loc = st.getLocationAtOffset(st
+                                                       .getOffsetAtLine(widgetLine));
+                                       fCompositeRuler.setLocationOfLastMouseButtonActivity(0,
+                                                       loc.y);
                                }
                        }
                }
@@ -259,20 +275,27 @@ public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHover
 
        /**
         * Returns the distance to the ruler line.
-        *
-        * @param position the position
-        * @param document the document
-        * @param line the line number
+        * 
+        * @param position
+        *            the position
+        * @param document
+        *            the document
+        * @param line
+        *            the line number
         * @return the distance to the ruler line
         */
-       protected int compareRulerLine(Position position, IDocument document, int line) {
+       protected int compareRulerLine(Position position, IDocument document,
+                       int line) {
 
                if (position.getOffset() > -1 && position.getLength() > -1) {
                        try {
-                               int firstLine= document.getLineOfOffset(position.getOffset());
+                               int firstLine = document.getLineOfOffset(position.getOffset());
                                if (line == firstLine)
                                        return 1;
-                               if (firstLine <= line && line <= document.getLineOfOffset(position.getOffset() + position.getLength()))
+                               if (firstLine <= line
+                                               && line <= document.getLineOfOffset(position
+                                                               .getOffset()
+                                                               + position.getLength()))
                                        return 2;
                        } catch (BadLocationException x) {
                        }
@@ -289,14 +312,17 @@ public class AnnotationExpandHover implements IAnnotationHover, IAnnotationHover
        }
 
        /*
-        * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, org.eclipse.jface.text.source.ILineRange, int)
+        * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer,
+        *      org.eclipse.jface.text.source.ILineRange, int)
         */
-       public Object getHoverInfo(ISourceViewer sourceViewer, ILineRange lineRange, int visibleLines) {
+       public Object getHoverInfo(ISourceViewer sourceViewer,
+                       ILineRange lineRange, int visibleLines) {
                return getHoverInfoForLine(sourceViewer, lineRange.getStartLine());
        }
 
        /*
-        * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverLineRange(org.eclipse.jface.text.source.ISourceViewer, int)
+        * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverLineRange(org.eclipse.jface.text.source.ISourceViewer,
+        *      int)
         */
        public ILineRange getHoverLineRange(ISourceViewer viewer, int lineNumber) {
                return new LineRange(lineNumber, 1);