diff options
author | Frank Becker | 2016-01-07 21:15:39 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2016-01-14 17:53:47 +0000 |
commit | abc094afe6ea58a45e1ebdeee09c13a2a79ec38a (patch) | |
tree | 2522ab8c286f1cb8137276f16548f115809cd0c7 | |
parent | 43b0a1d218872d346e2304145d92556e794d475f (diff) | |
download | org.eclipse.mylyn.reviews-abc094afe6ea58a45e1ebdeee09c13a2a79ec38a.tar.gz org.eclipse.mylyn.reviews-abc094afe6ea58a45e1ebdeee09c13a2a79ec38a.tar.xz org.eclipse.mylyn.reviews-abc094afe6ea58a45e1ebdeee09c13a2a79ec38a.zip |
484709: Neon M4: Java Problem: The return type is incompatible with
IAnnotationModel.getAnnotationIterator()
Change-Id: I72d8867c0ad7b5d0e577ce74cca6f9618cf28d8f
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=484709
Signed-off-by: Frank Becker <eclipse@frank-becker.de>
11 files changed, 217 insertions, 129 deletions
diff --git a/org.eclipse.mylyn.reviews.tests/src/org/eclipse/mylyn/reviews/tests/ui/ReviewAnnotationModelTest.java b/org.eclipse.mylyn.reviews.tests/src/org/eclipse/mylyn/reviews/tests/ui/ReviewAnnotationModelTest.java index f70d3ff4e..d3a28a4f8 100644 --- a/org.eclipse.mylyn.reviews.tests/src/org/eclipse/mylyn/reviews/tests/ui/ReviewAnnotationModelTest.java +++ b/org.eclipse.mylyn.reviews.tests/src/org/eclipse/mylyn/reviews/tests/ui/ReviewAnnotationModelTest.java @@ -16,13 +16,11 @@ import java.sql.Timestamp; import java.util.Date; import java.util.Iterator; -import junit.framework.TestCase; - import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.common.notify.impl.NotificationImpl; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; -import org.eclipse.mylyn.internal.reviews.ui.annotations.CommentAnnotation; +import org.eclipse.jface.text.source.Annotation; import org.eclipse.mylyn.internal.reviews.ui.annotations.ReviewAnnotationModel; import org.eclipse.mylyn.reviews.core.model.IComment; import org.eclipse.mylyn.reviews.core.model.ILineLocation; @@ -33,6 +31,8 @@ import org.eclipse.mylyn.reviews.core.model.IReviewsFactory; import org.eclipse.mylyn.reviews.core.model.IUser; import org.eclipse.mylyn.reviews.tests.util.MockReviewBehavior; +import junit.framework.TestCase; + /** * @author Leo Dos Santos * @author Guy Perron @@ -66,7 +66,7 @@ public class ReviewAnnotationModelTest extends TestCase { } public void testConnect() { - Iterator<CommentAnnotation> iter = model.getAnnotationIterator(); + Iterator<Annotation> iter = model.getAnnotationIterator(); assertEquals(1, getCount(iter)); model.disconnect(doc); @@ -79,7 +79,7 @@ public class ReviewAnnotationModelTest extends TestCase { } public void testNotifyChanged() { - Iterator<CommentAnnotation> iter = model.getAnnotationIterator(); + Iterator<Annotation> iter = model.getAnnotationIterator(); assertEquals(1, getCount(iter)); // Comments sometimes come in with Dates and sometimes with Timestamps, @@ -106,7 +106,7 @@ public class ReviewAnnotationModelTest extends TestCase { } - private int getCount(Iterator<CommentAnnotation> iter) { + private int getCount(Iterator<Annotation> iter) { int count = 0; while (iter.hasNext()) { count++; diff --git a/org.eclipse.mylyn.reviews.ui/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.mylyn.reviews.ui/.settings/org.eclipse.jdt.ui.prefs index ae5a08748..e77fc074f 100644 --- a/org.eclipse.mylyn.reviews.ui/.settings/org.eclipse.jdt.ui.prefs +++ b/org.eclipse.mylyn.reviews.ui/.settings/org.eclipse.jdt.ui.prefs @@ -1,4 +1,61 @@ -#Wed Mar 02 16:00:03 PST 2011 +cleanup.add_default_serial_version_id=true +cleanup.add_generated_serial_version_id=false +cleanup.add_missing_annotations=true +cleanup.add_missing_deprecated_annotations=true +cleanup.add_missing_methods=false +cleanup.add_missing_nls_tags=false +cleanup.add_missing_override_annotations=true +cleanup.add_missing_override_annotations_interface_methods=true +cleanup.add_serial_version_id=false +cleanup.always_use_blocks=true +cleanup.always_use_parentheses_in_expressions=false +cleanup.always_use_this_for_non_static_field_access=false +cleanup.always_use_this_for_non_static_method_access=false +cleanup.convert_functional_interfaces=false +cleanup.convert_to_enhanced_for_loop=false +cleanup.correct_indentation=false +cleanup.format_source_code=false +cleanup.format_source_code_changes_only=false +cleanup.insert_inferred_type_arguments=false +cleanup.make_local_variable_final=true +cleanup.make_parameters_final=false +cleanup.make_private_fields_final=true +cleanup.make_type_abstract_if_missing_method=false +cleanup.make_variable_declarations_final=false +cleanup.never_use_blocks=false +cleanup.never_use_parentheses_in_expressions=true +cleanup.organize_imports=false +cleanup.qualify_static_field_accesses_with_declaring_class=false +cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true +cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true +cleanup.qualify_static_member_accesses_with_declaring_class=true +cleanup.qualify_static_method_accesses_with_declaring_class=false +cleanup.remove_private_constructors=true +cleanup.remove_redundant_type_arguments=true +cleanup.remove_trailing_whitespaces=false +cleanup.remove_trailing_whitespaces_all=true +cleanup.remove_trailing_whitespaces_ignore_empty=false +cleanup.remove_unnecessary_casts=false +cleanup.remove_unnecessary_nls_tags=true +cleanup.remove_unused_imports=true +cleanup.remove_unused_local_variables=false +cleanup.remove_unused_private_fields=true +cleanup.remove_unused_private_members=false +cleanup.remove_unused_private_methods=true +cleanup.remove_unused_private_types=true +cleanup.sort_members=false +cleanup.sort_members_all=false +cleanup.use_anonymous_class_creation=false +cleanup.use_blocks=false +cleanup.use_blocks_only_for_return_and_throw=false +cleanup.use_lambda=true +cleanup.use_parentheses_in_expressions=false +cleanup.use_this_for_non_static_field_access=false +cleanup.use_this_for_non_static_field_access_only_if_necessary=true +cleanup.use_this_for_non_static_method_access=false +cleanup.use_this_for_non_static_method_access_only_if_necessary=true +cleanup.use_type_arguments=false +cleanup_profile=_Mylyn cleanup_settings_version=2 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true @@ -18,18 +75,22 @@ sp_cleanup.add_missing_deprecated_annotations=true sp_cleanup.add_missing_methods=false sp_cleanup.add_missing_nls_tags=false sp_cleanup.add_missing_override_annotations=true +sp_cleanup.add_missing_override_annotations_interface_methods=false sp_cleanup.add_serial_version_id=false sp_cleanup.always_use_blocks=true sp_cleanup.always_use_parentheses_in_expressions=false sp_cleanup.always_use_this_for_non_static_field_access=false sp_cleanup.always_use_this_for_non_static_method_access=false +sp_cleanup.convert_functional_interfaces=false sp_cleanup.convert_to_enhanced_for_loop=true sp_cleanup.correct_indentation=true sp_cleanup.format_source_code=true sp_cleanup.format_source_code_changes_only=false +sp_cleanup.insert_inferred_type_arguments=false sp_cleanup.make_local_variable_final=false sp_cleanup.make_parameters_final=false sp_cleanup.make_private_fields_final=true +sp_cleanup.make_type_abstract_if_missing_method=false sp_cleanup.make_variable_declarations_final=true sp_cleanup.never_use_blocks=false sp_cleanup.never_use_parentheses_in_expressions=true @@ -41,10 +102,11 @@ sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class= sp_cleanup.qualify_static_member_accesses_with_declaring_class=true sp_cleanup.qualify_static_method_accesses_with_declaring_class=false sp_cleanup.remove_private_constructors=true +sp_cleanup.remove_redundant_type_arguments=false sp_cleanup.remove_trailing_whitespaces=true sp_cleanup.remove_trailing_whitespaces_all=true sp_cleanup.remove_trailing_whitespaces_ignore_empty=false -sp_cleanup.remove_unnecessary_casts=true +sp_cleanup.remove_unnecessary_casts=false sp_cleanup.remove_unnecessary_nls_tags=true sp_cleanup.remove_unused_imports=false sp_cleanup.remove_unused_local_variables=false @@ -54,10 +116,13 @@ sp_cleanup.remove_unused_private_methods=true sp_cleanup.remove_unused_private_types=true sp_cleanup.sort_members=false sp_cleanup.sort_members_all=false +sp_cleanup.use_anonymous_class_creation=false sp_cleanup.use_blocks=true sp_cleanup.use_blocks_only_for_return_and_throw=false +sp_cleanup.use_lambda=false sp_cleanup.use_parentheses_in_expressions=false sp_cleanup.use_this_for_non_static_field_access=false sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true sp_cleanup.use_this_for_non_static_method_access=false sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true +sp_cleanup.use_type_arguments=false diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentAnnotationHover.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentAnnotationHover.java index 0cc7363f4..a6e3de396 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentAnnotationHover.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentAnnotationHover.java @@ -56,7 +56,7 @@ import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; /** * Class to determine the annotations to show the hover for. This class delegates to a parent hover if it exists. - * + * * @author Shawn Minto */ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHoverExtension, IAnnotationHoverExtension2 { @@ -83,7 +83,7 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove if (commentAnnotations.size() > 0) { if (commentAnnotations.size() == 1) { - CommentAnnotation annotation = commentAnnotations.get(0); + Annotation annotation = commentAnnotations.get(0); String message = annotation.getText(); if (message != null && message.trim().length() > 0) { return formatSingleMessage(message); @@ -92,7 +92,7 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove } else { List<String> messages = new ArrayList<String>(); - for (CommentAnnotation annotation : commentAnnotations) { + for (Annotation annotation : commentAnnotations) { String message = annotation.getText(); if (message != null && message.trim().length() > 0) { messages.add(message.trim()); @@ -145,26 +145,25 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove IDocument document = viewer.getDocument(); int lowestStart = Integer.MAX_VALUE; int highestEnd = 0; - for (Annotation a : commentAnnotations) { - if (a instanceof CommentAnnotation) { - Position p = ((CommentAnnotation) a).getPosition(); - try { - - int start = document.getLineOfOffset(p.offset); - int end = document.getLineOfOffset(p.offset + p.length); - - if (start < lowestStart) { - lowestStart = start; - } - - if (end > highestEnd) { - highestEnd = end; - } - } catch (BadLocationException e) { - // ignore + for (CommentAnnotation a : commentAnnotations) { + Position p = a.getPosition(); + try { + + int start = document.getLineOfOffset(p.offset); + int end = document.getLineOfOffset(p.offset + p.length); + + if (start < lowestStart) { + lowestStart = start; } + + if (end > highestEnd) { + highestEnd = end; + } + } catch (BadLocationException e) { + // ignore } } + if (lowestStart != Integer.MAX_VALUE) { return new LineRange(lowestStart, highestEnd - lowestStart); } else { @@ -188,7 +187,8 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove protected String formatMultipleMessages(List<String> messages) { StringBuffer buffer = new StringBuffer(); HTMLPrinter.addPageProlog(buffer); - HTMLPrinter.addParagraph(buffer, HTMLPrinter.convertToHTMLContent(Messages.CommentAnnotationHover_Multiple_comments)); + HTMLPrinter.addParagraph(buffer, + HTMLPrinter.convertToHTMLContent(Messages.CommentAnnotationHover_Multiple_comments)); HTMLPrinter.startBulletList(buffer); for (String message : messages) { @@ -262,7 +262,8 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove continue; } - if (includeAnnotation(annotation, position, commentAnnotations) && annotation instanceof CommentAnnotation) { + if (includeAnnotation(annotation, position, commentAnnotations) + && annotation instanceof CommentAnnotation) { commentAnnotations.add((CommentAnnotation) annotation); } } @@ -272,7 +273,7 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove /** * Tries to make an annotation hover focusable (or "sticky"). - * + * * @return <code>true</code> if successful, <code>false</code> otherwise */ public static boolean makeAnnotationHoverFocusable() { @@ -320,7 +321,8 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove // hover region: the beginning of the concerned line to place the control right over the line IDocument document = currentSourceViewer.getDocument(); int offset = document.getLineOffset(line); - String partitioning = new TextSourceViewerConfiguration().getConfiguredDocumentPartitioning(currentSourceViewer); + String partitioning = new TextSourceViewerConfiguration() + .getConfiguredDocumentPartitioning(currentSourceViewer); String contentType = TextUtilities.getContentType(document, partitioning, offset, true); IInformationControlCreator controlCreator = null; @@ -348,8 +350,8 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove fInformationPresenter.showInformation(); // remove our own handler as F2 focus handler - ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService( - ICommandService.class); + ICommandService commandService = (ICommandService) PlatformUI.getWorkbench() + .getService(ICommandService.class); Command showInfoCommand = commandService.getCommand(ITextEditorActionDefinitionIds.SHOW_INFORMATION); showInfoCommand.setHandler(null); @@ -364,11 +366,11 @@ public class CommentAnnotationHover implements IAnnotationHover, IAnnotationHove /** * Information provider used to present focusable information shells. - * + * * @since 3.3 */ - private static final class InformationProvider implements IInformationProvider, IInformationProviderExtension, - IInformationProviderExtension2 { + private static final class InformationProvider + implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 { private final IRegion fHoverRegion; diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentAnnotationHoverInput.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentAnnotationHoverInput.java index 5c3337c9d..38c8d0230 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentAnnotationHoverInput.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentAnnotationHoverInput.java @@ -17,7 +17,7 @@ import org.eclipse.mylyn.reviews.ui.ReviewBehavior; /** * Data model to represent the annotations that we need to display in the hover. - * + * * @author Shawn Minto */ public class CommentAnnotationHoverInput { diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentInformationControl.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentInformationControl.java index ca8cee8f3..886640a70 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentInformationControl.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentInformationControl.java @@ -31,10 +31,12 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Shell; +import com.google.common.collect.Iterables; + /** * A custom control to display on hover, or delegates to the default control to display if we aren't dealing with a * CrucibleCommentAnnotation. - * + * * @author sminto */ public class CommentInformationControl extends DefaultInformationControl implements IInformationControlExtension2 { @@ -85,7 +87,7 @@ public class CommentInformationControl extends DefaultInformationControl impleme } Set<IComment> comments = new HashSet<IComment>(); - for (CommentAnnotation annotation : annotations) { + for (CommentAnnotation annotation : Iterables.filter(annotations, CommentAnnotation.class)) { comments.addAll(getUnreadComments(annotation.getComment())); } diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java index d6332f9b6..edb0e4132 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/CommentPopupDialog.java @@ -51,7 +51,7 @@ import com.google.common.collect.FluentIterable; /** * Popup to show the information about the annotation in - * + * * @author Shawn Minto * @author Guy Perron */ @@ -92,7 +92,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Creates a dialog that displays review comments associated to a line in a given file - * + * * @param parent * the parent shell of the dialog * @param shellStyle @@ -146,7 +146,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Closes the dialog - * + * * @param force * true if the dialog should close under all conditions, false if the dialog should check for edited text * in the editor @@ -164,7 +164,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Disposes the dialog - * + * * @param force * true if the dialog should be disposed under all conditions, false if the dialog should check for * edited text in the editor @@ -180,7 +180,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Checks if there are any changes in the comment editor text - * + * * @return true if there is a change with the editor text, false otherwise */ public boolean hasEdits() { @@ -206,7 +206,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Computes the maximum width of the dialog - * + * * @return a {@link Point} containing the max width of the dialog and its default height */ public Point computeSizeHint() { @@ -236,7 +236,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Checks to see if the active shell is the shell of this dialog - * + * * @return true if the active shell is the dialog's shell, false otherwise */ public boolean isFocusControl() { @@ -297,7 +297,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Sets the dialog's shell to a position in the monitor (constrained by the size of the user's monitor) - * + * * @param location * the desired location to place the dialog */ @@ -351,7 +351,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Sets the size of the dialog's shell and scrolled composite. The height must be at least minimum height. - * + * * @param width * the width in pixels * @param height @@ -371,7 +371,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Initializes the comment dialog with the comments (and review item/line range if it wasn't provided on * construction) from the {@link CommentAnnotationHoverInput} provided - * + * * @param input * the input of the comment dialog */ @@ -442,12 +442,13 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList if (isCommentNavigator) { InlineCommentEditor.addToEditMap(reviewItem.getId(), range.getStartLine()); } + } } /** * Helper method to return all of the {@link Section} in the dialog's scrolled composite - * + * * @return the list of {@link Section} that are children of the dialog's scrolled composite */ protected List<Section> getScrolledCompositeSections() { @@ -463,7 +464,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Adds a mouse listener to the {@link Control} provided and its children - * + * * @param c * the {@link Control} and its {@link Control} children that you want to add mouse listeners to * @param listener @@ -483,7 +484,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Given a {@link Control}, it attempts to find parent {@link Section} recursively - * + * * @param c * the {@link Control} that you want to find the parent {@link Section} of * @return the parent {@link Section} or null if it can't be found @@ -501,7 +502,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Creates a mouse down {@link MouseAdapter} to add the comment editor to the dialog. It will attempt to get the * comment associated with the {@link Control} you clicked on. - * + * * @return the {@link MouseAdapter} that can invoke the comment editor on mouse down events */ private MouseAdapter createAddCommentEditorListener() { @@ -532,7 +533,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Creates a mouse down {@link MouseAdapter} to remove the comment editor - * + * * @return the {@link MouseAdapter} that can remove the comment editor on mouse down events */ private MouseAdapter createRemoveCommentEditorListener() { @@ -548,7 +549,7 @@ public class CommentPopupDialog extends PopupDialog implements IReviewActionList /** * Helper method to get the last comment draft in the dialog's comment list - * + * * @return the last {@link IComment} in the comment list if there is at least one draft in the comment list or null * otherwise */ diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/ReviewAnnotationModel.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/ReviewAnnotationModel.java index b9e542249..c87e747fe 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/ReviewAnnotationModel.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/annotations/ReviewAnnotationModel.java @@ -43,9 +43,11 @@ import org.eclipse.mylyn.reviews.core.model.ILocation; import org.eclipse.mylyn.reviews.core.model.IReviewItem; import org.eclipse.mylyn.reviews.ui.ReviewBehavior; +import com.google.common.collect.Iterables; + /** * A model for review annotations. - * + * * @author Shawn Minto * @author Steffen Pingel * @author Guy Perron @@ -54,7 +56,7 @@ public class ReviewAnnotationModel implements IAnnotationModel { private final Set<IAnnotationModelListener> annotationModelListeners = new HashSet<IAnnotationModelListener>(2); - private final Set<CommentAnnotation> annotations = new LinkedHashSet<CommentAnnotation>(); + private final Set<Annotation> annotations = new LinkedHashSet<Annotation>(); private ReviewBehavior behavior; @@ -122,9 +124,11 @@ public class ReviewAnnotationModel implements IAnnotationModel { this.document = document; connectItem(); - for (CommentAnnotation commentAnnotation : annotations) { + for (Annotation commentAnnotation : annotations) { try { - document.addPosition(commentAnnotation.getPosition()); + if (commentAnnotation instanceof CommentAnnotation) { + document.addPosition(((CommentAnnotation) commentAnnotation).getPosition()); + } } catch (BadLocationException e) { StatusHandler.log(new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, e.getMessage(), e)); } @@ -135,8 +139,10 @@ public class ReviewAnnotationModel implements IAnnotationModel { } public void disconnect(IDocument document) { - for (CommentAnnotation commentAnnotation : annotations) { - document.removePosition(commentAnnotation.getPosition()); + for (Annotation commentAnnotation : annotations) { + if (commentAnnotation instanceof CommentAnnotation) { + document.removePosition(((CommentAnnotation) commentAnnotation).getPosition()); + } } document.removeDocumentListener(documentListener); @@ -151,7 +157,7 @@ public class ReviewAnnotationModel implements IAnnotationModel { clear(); } - public Iterator<CommentAnnotation> getAnnotationIterator() { + public Iterator<Annotation> getAnnotationIterator() { return annotations.iterator(); } @@ -160,7 +166,7 @@ public class ReviewAnnotationModel implements IAnnotationModel { */ public List<CommentAnnotation> getAnnotationsForOffset(int offset) { List<CommentAnnotation> result = new ArrayList<CommentAnnotation>(); - for (CommentAnnotation annotation : this.annotations) { + for (CommentAnnotation annotation : Iterables.filter(this.annotations, CommentAnnotation.class)) { if (annotation.getPosition().offset <= offset && (annotation.getPosition().length + annotation.getPosition().offset) >= offset) { result.add(annotation); @@ -180,8 +186,8 @@ public class ReviewAnnotationModel implements IAnnotationModel { /** * Returns the first annotation that this knows about for the given offset in the document */ - public CommentAnnotation getFirstAnnotationForOffset(int offset) { - for (CommentAnnotation annotation : annotations) { + public Annotation getFirstAnnotationForOffset(int offset) { + for (CommentAnnotation annotation : Iterables.filter(annotations, CommentAnnotation.class)) { if (annotation.getPosition().offset <= offset && (annotation.getPosition().length + annotation.getPosition().offset) >= offset) { return annotation; @@ -253,8 +259,8 @@ public class ReviewAnnotationModel implements IAnnotationModel { event.annotationRemoved(ca); } catch (BadLocationException e) { - StatusHandler.log(new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, - "Unable to remove annotation.", e)); //$NON-NLS-1$ + StatusHandler.log( + new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, "Unable to remove annotation.", e)); //$NON-NLS-1$ } } } @@ -266,16 +272,16 @@ public class ReviewAnnotationModel implements IAnnotationModel { if (location instanceof ILineLocation) { try { CommentAnnotation oldCa = createCommentAnnotation(document, oldcomment, (ILineLocation) location); - CommentAnnotation ca = new CommentAnnotation(oldCa.getPosition().offset, - oldCa.getPosition().length, comment); + CommentAnnotation ca = new CommentAnnotation(oldCa.getPosition().offset, oldCa.getPosition().length, + comment); annotations.remove(oldCa); annotations.add(ca); event.annotationRemoved(oldCa); event.annotationChanged(ca); } catch (BadLocationException e) { - StatusHandler.log(new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, - "Unable to modify annotation.", e)); //$NON-NLS-1$ + StatusHandler.log( + new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, "Unable to modify annotation.", e)); //$NON-NLS-1$ } } } @@ -304,8 +310,10 @@ public class ReviewAnnotationModel implements IAnnotationModel { } protected void clear(AnnotationModelEvent event) { - for (CommentAnnotation commentAnnotation : annotations) { - event.annotationRemoved(commentAnnotation, commentAnnotation.getPosition()); + for (Annotation commentAnnotation : annotations) { + if (commentAnnotation instanceof CommentAnnotation) { + event.annotationRemoved(commentAnnotation, ((CommentAnnotation) commentAnnotation).getPosition()); + } } annotations.clear(); } diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java index ff6c066fe..05d43a96d 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareAnnotationSupport.java @@ -56,7 +56,7 @@ import org.eclipse.ui.texteditor.AbstractTextEditor; /** * Manages annotation models for compare viewers. - * + * * @author Thomas Ehrnhoefer * @author Steffen Pingel * @author Guy Perron @@ -72,7 +72,8 @@ public class ReviewCompareAnnotationSupport { private CommentPopupDialog commentPopupDialog = null; public static ReviewCompareAnnotationSupport getAnnotationSupport(Viewer contentViewer) { - ReviewCompareAnnotationSupport support = (ReviewCompareAnnotationSupport) contentViewer.getData(KEY_ANNOTAION_SUPPORT); + ReviewCompareAnnotationSupport support = (ReviewCompareAnnotationSupport) contentViewer + .getData(KEY_ANNOTAION_SUPPORT); if (support == null) { support = new ReviewCompareAnnotationSupport(contentViewer); contentViewer.setData(KEY_ANNOTAION_SUPPORT, support); @@ -178,7 +179,7 @@ public class ReviewCompareAnnotationSupport { /** * Jumps to the next annotation according to the given direction. - * + * * @param direction * the search direction * @return the selected annotation or <code>null</code> if none @@ -207,7 +208,8 @@ public class ReviewCompareAnnotationSupport { nextRightPosition.length = 1; currentLeftOffset = getLineOffset(leftAnnotationModel, currentLeftOffset); - if (calculateNextAnnotation(direction, nextLeftPosition, nextRightPosition, currentLeftOffset) == LEFT_SIDE) { + if (calculateNextAnnotation(direction, nextLeftPosition, nextRightPosition, + currentLeftOffset) == LEFT_SIDE) { return leftAnnotation; } else { return rightAnnotation; @@ -303,7 +305,8 @@ public class ReviewCompareAnnotationSupport { return RIGHT_SIDE; } - public void moveToAnnotation(MergeSourceViewer adjacentViewer, MergeSourceViewer annotationViewer, Position position) { + public void moveToAnnotation(MergeSourceViewer adjacentViewer, MergeSourceViewer annotationViewer, + Position position) { adjacentViewer.getSourceViewer().revealRange(position.offset, position.length); adjacentViewer.getSourceViewer().setSelectedRange(position.offset, position.length); selectAndReveal(annotationViewer, position); @@ -329,10 +332,9 @@ public class ReviewCompareAnnotationSupport { commentPopupDialog.dispose(false); commentPopupDialog = null; } - commentPopupDialog = new CommentPopupDialog(ReviewsUiPlugin.getDefault() - .getWorkbench() - .getActiveWorkbenchWindow() - .getShell(), SWT.NO_FOCUS | SWT.ON_TOP, reviewitem, range, true); + commentPopupDialog = new CommentPopupDialog( + ReviewsUiPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell(), + SWT.NO_FOCUS | SWT.ON_TOP, reviewitem, range, true); CommentAnnotationHoverInput input = new CommentAnnotationHoverInput(comments, ((ReviewAnnotationModel) srcViewer.getAnnotationModel()).getBehavior()); commentPopupDialog.create(); @@ -461,7 +463,7 @@ public class ReviewCompareAnnotationSupport { /** * Returns the annotation closest to the given range respecting the given direction. If an annotation is found, the * annotations current position is copied into the provided annotation position. - * + * * @param viewer * the viewer * @param direction @@ -497,20 +499,20 @@ public class ReviewCompareAnnotationSupport { int endOfDocument = document.getLength(); int distance = Integer.MAX_VALUE; - Iterator<CommentAnnotation> e = annotationModel.getAnnotationIterator(); + Iterator<Annotation> e = annotationModel.getAnnotationIterator(); while (e.hasNext()) { - CommentAnnotation a = e.next(); + Annotation a = e.next(); - Position p = a.getPosition(); + Position p = a instanceof CommentAnnotation ? ((CommentAnnotation) a).getPosition() : null; if (p == null) { continue; } - if (direction == Direction.FORWARDS && p.offset == offset || direction == Direction.BACKWARDS - && p.offset + p.getLength() == offset + length) {// || p.includes(offset)) { - if (containingAnnotation == null - || (direction == Direction.FORWARDS && p.length >= containingAnnotationPosition.length || direction == Direction.BACKWARDS - && p.length >= containingAnnotationPosition.length)) { + if (direction == Direction.FORWARDS && p.offset == offset + || direction == Direction.BACKWARDS && p.offset + p.getLength() == offset + length) {// || p.includes(offset)) { + if (containingAnnotation == null || (direction == Direction.FORWARDS + && p.length >= containingAnnotationPosition.length + || direction == Direction.BACKWARDS && p.length >= containingAnnotationPosition.length)) { containingAnnotation = a; containingAnnotationPosition = p; currentAnnotation = p.length == length; @@ -524,8 +526,8 @@ public class ReviewCompareAnnotationSupport { currentDistance = endOfDocument + currentDistance; } - if (currentDistance < distance || currentDistance == distance - && p.length < nextAnnotationPosition.length) { + if (currentDistance < distance + || currentDistance == distance && p.length < nextAnnotationPosition.length) { distance = currentDistance; nextAnnotation = a; nextAnnotationPosition = p; @@ -536,8 +538,8 @@ public class ReviewCompareAnnotationSupport { currentDistance = endOfDocument + currentDistance; } - if (currentDistance < distance || currentDistance == distance - && p.length < nextAnnotationPosition.length) { + if (currentDistance < distance + || currentDistance == distance && p.length < nextAnnotationPosition.length) { distance = currentDistance; nextAnnotation = a; nextAnnotationPosition = p; diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareInputListener.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareInputListener.java index dfbf9a231..3a19d19fa 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareInputListener.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/compare/ReviewCompareInputListener.java @@ -26,6 +26,7 @@ import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextInputListener; import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.TextViewer; +import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.AnnotationBarHoverManager; import org.eclipse.jface.text.source.CompositeRuler; import org.eclipse.jface.text.source.IAnnotationAccess; @@ -90,23 +91,26 @@ class ReviewCompareInputListener implements ITextInputListener, IReviewCompareSo public void lineGetBackground(LineBackgroundEvent event) { int lineNr = styledText.getLineAtOffset(event.lineOffset) + 1; - Iterator<CommentAnnotation> it = annotationModel.getAnnotationIterator(); + Iterator<Annotation> it = annotationModel.getAnnotationIterator(); while (it.hasNext()) { - CommentAnnotation annotation = it.next(); + Annotation annotation = it.next(); int startLine; int endLine; - IComment comment = annotation.getComment(); - //TODO This code assumes that we have one comment per annotation. That won't work for r4E. - if (comment.getLocations().size() == 1) { - ILocation location = comment.getLocations().get(0); - if (location instanceof ILineLocation) { - ILineLocation lineLocation = (ILineLocation) location; - startLine = lineLocation.getRangeMin(); - endLine = lineLocation.getRangeMax(); - if (lineNr >= startLine && lineNr <= endLine) { - AnnotationPreference pref = new AnnotationPreferenceLookup().getAnnotationPreference(annotation); - if (pref.getHighlightPreferenceValue()) { - event.lineBackground = colorCommented; + if (annotation instanceof CommentAnnotation) { + IComment comment = ((CommentAnnotation) annotation).getComment(); + //TODO This code assumes that we have one comment per annotation. That won't work for r4E. + if (comment.getLocations().size() == 1) { + ILocation location = comment.getLocations().get(0); + if (location instanceof ILineLocation) { + ILineLocation lineLocation = (ILineLocation) location; + startLine = lineLocation.getRangeMin(); + endLine = lineLocation.getRangeMax(); + if (lineNr >= startLine && lineNr <= endLine) { + AnnotationPreference pref = new AnnotationPreferenceLookup() + .getAnnotationPreference(annotation); + if (pref.getHighlightPreferenceValue()) { + event.lineBackground = colorCommented; + } } } } @@ -117,7 +121,7 @@ class ReviewCompareInputListener implements ITextInputListener, IReviewCompareSo /** * Galileo hack to deal with slaveDocuments (when clicking on java structure elements). The styledText will not * contain the whole text anymore, so our line numbering is off - * + * * @param event * @return */ @@ -170,7 +174,8 @@ class ReviewCompareInputListener implements ITextInputListener, IReviewCompareSo } AnnotationPreferenceLookup lookup = EditorsUI.getAnnotationPreferenceLookup(); - final AnnotationPreference commentedPref = lookup.getAnnotationPreference(CommentAnnotation.COMMENT_ANNOTATION_ID); + final AnnotationPreference commentedPref = lookup + .getAnnotationPreference(CommentAnnotation.COMMENT_ANNOTATION_ID); updateCommentedColor(commentedPref, store); @@ -321,8 +326,8 @@ class ReviewCompareInputListener implements ITextInputListener, IReviewCompareSo createOverviewRuler(newInput, sourceViewerClazz); createHighlighting(sourceViewerClazz); } catch (Throwable t) { - StatusHandler.log(new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, - "Error attaching annotation model", t)); //$NON-NLS-1$ + StatusHandler.log( + new Status(IStatus.ERROR, ReviewsUiPlugin.PLUGIN_ID, "Error attaching annotation model", t)); //$NON-NLS-1$ } //} } @@ -345,8 +350,8 @@ class ReviewCompareInputListener implements ITextInputListener, IReviewCompareSo // mergeSourceViewer.addTextAction(addGeneralCommentAction); } - private void createHighlighting(Class<SourceViewer> sourceViewerClazz) throws IllegalArgumentException, - IllegalAccessException, SecurityException, NoSuchFieldException { + private void createHighlighting(Class<SourceViewer> sourceViewerClazz) + throws IllegalArgumentException, IllegalAccessException, SecurityException, NoSuchFieldException { // TODO this could use some performance tweaks final StyledText styledText = sourceViewer.getTextWidget(); styledText.addLineBackgroundListener(new ColoringLineBackgroundListener(styledText)); @@ -364,8 +369,8 @@ class ReviewCompareInputListener implements ITextInputListener, IReviewCompareSo sourceViewer.setOverviewRulerAnnotationHover(new CommentAnnotationHover(null)); - OverviewRuler ruler = new OverviewRuler(new DefaultMarkerAnnotationAccess(), 15, EditorsPlugin.getDefault() - .getSharedTextColors()); + OverviewRuler ruler = new OverviewRuler(new DefaultMarkerAnnotationAccess(), 15, + EditorsPlugin.getDefault().getSharedTextColors()); Field compositeField = sourceViewerClazz.getDeclaredField("fComposite"); //$NON-NLS-1$ compositeField.setAccessible(true); diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/ruler/CommentAnnotationRulerColumn.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/ruler/CommentAnnotationRulerColumn.java index 5f28db432..3643949a0 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/ruler/CommentAnnotationRulerColumn.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/ruler/CommentAnnotationRulerColumn.java @@ -161,7 +161,8 @@ public class CommentAnnotationRulerColumn extends AbstractRulerColumn implements } AnnotationPreferenceLookup lookup = EditorsUI.getAnnotationPreferenceLookup(); - final AnnotationPreference commentedPref = lookup.getAnnotationPreference(CommentAnnotation.COMMENT_ANNOTATION_ID); + final AnnotationPreference commentedPref = lookup + .getAnnotationPreference(CommentAnnotation.COMMENT_ANNOTATION_ID); updateCommentedColor(commentedPref, store); diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/ruler/CommentAnnotationRulerHover.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/ruler/CommentAnnotationRulerHover.java index c4534a7cf..42c35b613 100644 --- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/ruler/CommentAnnotationRulerHover.java +++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/ruler/CommentAnnotationRulerHover.java @@ -59,8 +59,8 @@ import org.eclipse.ui.commands.ICommandService; import org.eclipse.ui.editors.text.TextSourceViewerConfiguration; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; -public class CommentAnnotationRulerHover implements IAnnotationHover, IAnnotationHoverExtension, - IAnnotationHoverExtension2 { +public class CommentAnnotationRulerHover + implements IAnnotationHover, IAnnotationHoverExtension, IAnnotationHoverExtension2 { private final IInformationControlCreator informationControlCreator = new CommentInformationControlCreator(); @@ -238,7 +238,8 @@ public class CommentAnnotationRulerHover implements IAnnotationHover, IAnnotatio continue; } - if (includeAnnotation(annotation, position, commentAnnotations) && annotation instanceof CommentAnnotation) { + if (includeAnnotation(annotation, position, commentAnnotations) + && annotation instanceof CommentAnnotation) { commentAnnotations.add((CommentAnnotation) annotation); } } @@ -248,7 +249,7 @@ public class CommentAnnotationRulerHover implements IAnnotationHover, IAnnotatio /** * Tries to make an annotation hover focusable (or "sticky"). - * + * * @return <code>true</code> if successful, <code>false</code> otherwise */ public static boolean makeAnnotationHoverFocusable() { @@ -296,7 +297,8 @@ public class CommentAnnotationRulerHover implements IAnnotationHover, IAnnotatio // hover region: the beginning of the concerned line to place the control right over the line IDocument document = currentSourceViewer.getDocument(); int offset = document.getLineOffset(line); - String partitioning = new TextSourceViewerConfiguration().getConfiguredDocumentPartitioning(currentSourceViewer); + String partitioning = new TextSourceViewerConfiguration() + .getConfiguredDocumentPartitioning(currentSourceViewer); String contentType = TextUtilities.getContentType(document, partitioning, offset, true); IInformationControlCreator controlCreator = null; @@ -324,8 +326,8 @@ public class CommentAnnotationRulerHover implements IAnnotationHover, IAnnotatio fInformationPresenter.showInformation(); // remove our own handler as F2 focus handler - ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService( - ICommandService.class); + ICommandService commandService = (ICommandService) PlatformUI.getWorkbench() + .getService(ICommandService.class); Command showInfoCommand = commandService.getCommand(ITextEditorActionDefinitionIds.SHOW_INFORMATION); showInfoCommand.setHandler(null); @@ -340,11 +342,11 @@ public class CommentAnnotationRulerHover implements IAnnotationHover, IAnnotatio /** * Information provider used to present focusable information shells. - * + * * @since 3.3 */ - private static final class InformationProvider implements IInformationProvider, IInformationProviderExtension, - IInformationProviderExtension2 { + private static final class InformationProvider + implements IInformationProvider, IInformationProviderExtension, IInformationProviderExtension2 { private final IRegion fHoverRegion; |