| author | Steffen Pingel | 2012-01-25 06:51:54 (EST) |
|---|---|---|
| committer | Steffen Pingel | 2012-01-25 06:51:54 (EST) |
| commit | 1bf05488095c5e08f24693df9795f17ff529d19c (patch) (side-by-side diff) | |
| tree | b1262ba2cc439831a0cc102b916e892a9ea4aa90 | |
| parent | 77b27ed8d525c7f83677544a349bea967f5286bf (diff) | |
| download | org.eclipse.mylyn.tasks-1bf05488095c5e08f24693df9795f17ff529d19c.zip org.eclipse.mylyn.tasks-1bf05488095c5e08f24693df9795f17ff529d19c.tar.gz org.eclipse.mylyn.tasks-1bf05488095c5e08f24693df9795f17ff529d19c.tar.bz2 | |
NEW - bug 369598: NPE when expanding comments in the task editor
https://bugs.eclipse.org/bugs/show_bug.cgi?id=369598
Change-Id: I97af196aef52b58b4c0aae77e934fcf6913ecfb2
3 files changed, 76 insertions, 2 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java index 5586fe6..7656462 100644 --- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java @@ -30,6 +30,7 @@ import org.eclipse.mylyn.tasks.tests.ui.TaskRelationHyperlinkDetectorTest; import org.eclipse.mylyn.tasks.tests.ui.editor.AttachmentTableLabelProviderTest; import org.eclipse.mylyn.tasks.tests.ui.editor.EditorUtilTest; import org.eclipse.mylyn.tasks.tests.ui.editor.PlanningPartTest; +import org.eclipse.mylyn.tasks.tests.ui.editor.RegionComparatorTest; import org.eclipse.mylyn.tasks.tests.ui.editor.RepositoryCompletionProcessorTest; import org.eclipse.mylyn.tasks.tests.ui.editor.TaskEditorPartDescriptorTest; import org.eclipse.mylyn.tasks.tests.ui.editor.TaskMigratorTest; @@ -115,6 +116,7 @@ public class AllTasksTests { //suite.addTestSuite(QueryExportImportTest.class); //suite.addTestSuite(BackgroundSaveTest.class); suite.addTestSuite(MultipleTaskHyperlinkDetectorTest.class); + suite.addTestSuite(RegionComparatorTest.class); return suite; } diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RegionComparatorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RegionComparatorTest.java new file mode 100644 index 0000000..970de1b --- a/dev/null +++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/RegionComparatorTest.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2012 Tasktop Technologies. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Tasktop Technologies - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.tasks.tests.ui.editor; + +import junit.framework.TestCase; + +import org.eclipse.jface.text.Region; +import org.eclipse.mylyn.internal.tasks.ui.editors.AbstractHyperlinkTextPresentationManager.RegionComparator; + +/** + * @author Steffen Pingel + */ +public class RegionComparatorTest extends TestCase { + + RegionComparator comparator = new RegionComparator(); + + public void testCompareToEquals() { + Region r1 = new Region(0, 10); + Region r2 = new Region(0, 10); + assertEquals(r1, r2); + assertEquals(0, comparator.compare(r1, r2)); + } + + public void testCompareToSameLength() { + Region r1 = new Region(0, 10); + Region r2 = new Region(1, 10); + assertFalse(r1.equals(r2)); + assertEquals(-1, comparator.compare(r1, r2)); + assertEquals(1, comparator.compare(r2, r1)); + } + + public void testCompareToNested() { + Region r1 = new Region(0, 10); + Region r2 = new Region(1, 8); + assertEquals(-1, comparator.compare(r1, r2)); + assertEquals(1, comparator.compare(r2, r1)); + } + + public void testCompareToOverlapping() { + Region r1 = new Region(0, 10); + Region r2 = new Region(1, 12); + assertEquals(-1, comparator.compare(r1, r2)); + assertEquals(1, comparator.compare(r2, r1)); + + r2 = new Region(1, 9); + assertEquals(-1, comparator.compare(r1, r2)); + assertEquals(1, comparator.compare(r2, r1)); + } + + public void testCompareToSameOffset() { + Region r1 = new Region(5, 8); + Region r2 = new Region(5, 10); + assertFalse(r1.equals(r2)); + assertEquals(-1, comparator.compare(r1, r2)); + assertEquals(1, comparator.compare(r2, r1)); + } + +} diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractHyperlinkTextPresentationManager.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractHyperlinkTextPresentationManager.java index b8960cc..00e4e73 100644 --- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractHyperlinkTextPresentationManager.java +++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AbstractHyperlinkTextPresentationManager.java @@ -35,7 +35,10 @@ import org.eclipse.swt.custom.StyleRange; */ public abstract class AbstractHyperlinkTextPresentationManager { - private static class RegionComparator implements Comparator<IRegion> { + /** + * Regions with a lower offset and a shorter length are ordered before other regions. + */ + public static class RegionComparator implements Comparator<IRegion> { public int compare(IRegion o1, IRegion o2) { if (o1 == o2) { @@ -47,8 +50,10 @@ public abstract class AbstractHyperlinkTextPresentationManager { return 1; } else if (o1.getLength() < o2.getLength()) { return -1; - } else { + } else if (o1.getLength() > o2.getLength()) { return 1; + } else { + return 0; } } |

