Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Pazderski2020-05-24 18:39:08 +0000
committerPaul Pazderski2020-06-30 15:59:58 +0000
commitf624f1e041e6e85acf4d750fd92b5d08c5cca71a (patch)
tree234d2999879c72e38b84221925faf0567a08121c
parent57d79764eaace00697da31d84379a04ff27042c0 (diff)
downloadeclipse.platform.debug-f624f1e041e6e85acf4d750fd92b5d08c5cca71a.tar.gz
eclipse.platform.debug-f624f1e041e6e85acf4d750fd92b5d08c5cca71a.tar.xz
eclipse.platform.debug-f624f1e041e6e85acf4d750fd92b5d08c5cca71a.zip
Bug 563752 - [console] FileLink with offset need line number which is
ignored FileLink can be created with offset+length or line number to be selected once the link is activated. All of those position parameters are optional and there is no reason to specify offset+length and line number on the same link. However before this commit the offset+length was ignored if no line number >= 0 was given. Change-Id: Iaf105bc25acaec064763ebe60abf7cdcc409b58c Signed-off-by: Paul Pazderski <paul-eclipse@ppazderski.de>
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java10
-rw-r--r--org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/FileLinkTests.java147
-rw-r--r--org.eclipse.debug.ui/ui/org/eclipse/debug/ui/console/FileLink.java21
3 files changed, 164 insertions, 14 deletions
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java
index 84c55755d..825625830 100644
--- a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/AutomatedSuite.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2019 IBM Corporation and others.
+ * Copyright (c) 2009, 2020 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
@@ -20,6 +20,7 @@ import org.eclipse.debug.tests.breakpoint.BreakpointTests;
import org.eclipse.debug.tests.console.ConsoleDocumentAdapterTests;
import org.eclipse.debug.tests.console.ConsoleManagerTests;
import org.eclipse.debug.tests.console.ConsoleTests;
+import org.eclipse.debug.tests.console.FileLinkTests;
import org.eclipse.debug.tests.console.IOConsoleFixedWidthTests;
import org.eclipse.debug.tests.console.IOConsoleTests;
import org.eclipse.debug.tests.console.InputStreamMonitorTests;
@@ -100,10 +101,10 @@ import org.junit.runners.Suite;
// Status handlers
StatusHandlerTests.class,
-
+
// Step filters
StepFiltersTests.class,
-
+
// Console view
ConsoleDocumentAdapterTests.class,
ConsoleManagerTests.class,
@@ -117,7 +118,8 @@ import org.junit.runners.Suite;
RuntimeProcessTests.class,
OutputStreamMonitorTests.class,
InputStreamMonitorTests.class,
-
+ FileLinkTests.class,
+
// Launch Groups
LaunchGroupTests.class,
})
diff --git a/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/FileLinkTests.java b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/FileLinkTests.java
new file mode 100644
index 000000000..9042f27b3
--- /dev/null
+++ b/org.eclipse.debug.tests/src/org/eclipse/debug/tests/console/FileLinkTests.java
@@ -0,0 +1,147 @@
+/*******************************************************************************
+ * Copyright (c) 2020 Paul Pazderski and others.
+ *
+ * This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *
+ * Contributors:
+ * Paul Pazderski - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.debug.tests.console;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.ByteArrayInputStream;
+import java.io.UnsupportedEncodingException;
+import java.util.UUID;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.debug.tests.AbstractDebugTest;
+import org.eclipse.debug.ui.console.FileLink;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.junit.Test;
+
+/**
+ * Tests for {@link FileLink}.
+ */
+public class FileLinkTests extends AbstractDebugTest {
+
+ private IProject testProject;
+ private IFile testFile;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ IWorkspace workspace = ResourcesPlugin.getWorkspace();
+ testProject = workspace.getRoot().getProject("FileLinkTest-" + UUID.randomUUID());
+ testProject.create(null);
+ testProject.open(null);
+ testFile = testProject.getFile("filelinktest.txt");
+ setTestContent("Test file\nSecond line");
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ if (testProject.exists()) {
+ testProject.delete(true, true, null);
+ }
+
+ super.tearDown();
+ }
+
+ private void setTestContent(String fileContent) throws UnsupportedEncodingException, CoreException {
+ ByteArrayInputStream data = new ByteArrayInputStream(fileContent.getBytes(testFile.getCharset()));
+ if (testFile.exists()) {
+ testFile.setContents(data, IResource.FORCE, null);
+ } else {
+ testFile.create(data, IResource.FORCE, null);
+ }
+ }
+
+ @Test
+ public void testFileLink() throws Exception {
+ FileLink link = new FileLink(testFile, null, -1, -1, -1);
+ link.linkActivated();
+ assertEquals(testFile.getName(), getActiveEditorFilename());
+ }
+
+ @Test
+ public void testFileLinkWithOffset() throws Exception {
+ FileLink link = new FileLink(testFile, null, 4, 0, -1);
+ link.linkActivated();
+ assertEquals(testFile.getName(), getActiveEditorFilename());
+ ITextSelection selection = getCurrentTextSelection();
+ assertNotNull("No selection.", selection);
+ assertEquals(4, selection.getOffset());
+ assertEquals(0, selection.getLength());
+ assertEquals(0, selection.getStartLine());
+ assertEquals(0, selection.getEndLine());
+ }
+
+ @Test
+ public void testFileLinkWithSelection() throws Exception {
+ FileLink link = new FileLink(testFile, null, 7, 5, -1);
+ link.linkActivated();
+ assertEquals(testFile.getName(), getActiveEditorFilename());
+ ITextSelection selection = getCurrentTextSelection();
+ assertNotNull("No selection.", selection);
+ assertEquals(7, selection.getOffset());
+ assertEquals(5, selection.getLength());
+ assertEquals(0, selection.getStartLine());
+ assertEquals(1, selection.getEndLine());
+
+ // if offset + length and line is specified the line should be ignored
+ link = new FileLink(testFile, null, 7, 5, 1);
+ link.linkActivated();
+ assertEquals(testFile.getName(), getActiveEditorFilename());
+ selection = getCurrentTextSelection();
+ assertNotNull("No selection.", selection);
+ assertEquals(7, selection.getOffset());
+ assertEquals(5, selection.getLength());
+ assertEquals(0, selection.getStartLine());
+ assertEquals(1, selection.getEndLine());
+ }
+
+ @Test
+ public void testFileLinkWithLine() throws Exception {
+ FileLink link = new FileLink(testFile, null, -1, -1, 2);
+ link.linkActivated();
+ assertEquals(testFile.getName(), getActiveEditorFilename());
+ ITextSelection selection = getCurrentTextSelection();
+ assertNotNull("No selection.", selection);
+ assertEquals(10, selection.getOffset());
+ assertEquals(11, selection.getLength());
+ assertEquals(1, selection.getStartLine());
+ assertEquals(1, selection.getEndLine());
+ }
+
+ private String getActiveEditorFilename() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ IEditorPart editor = window.getActivePage().getActiveEditor();
+ return editor != null ? editor.getEditorInput().getName() : null;
+ }
+
+ private ITextSelection getCurrentTextSelection() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ISelection selection = window.getSelectionService().getSelection();
+ if (selection instanceof ITextSelection) {
+ return (ITextSelection) selection;
+ }
+ return null;
+ }
+}
diff --git a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/console/FileLink.java b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/console/FileLink.java
index 04cf4febd..897526c27 100644
--- a/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/console/FileLink.java
+++ b/org.eclipse.debug.ui/ui/org/eclipse/debug/ui/console/FileLink.java
@@ -57,14 +57,15 @@ public class FileLink implements IConsoleHyperlink {
/**
* Constructs a hyperlink to the specified file.
*
- * @param file the file to open when activated
- * @param editorId the identifier of the editor to open the file in, or
- * <code>null</code> if the default editor should be used
- * @param fileOffset the offset in the file to select when activated, or -1
- * @param fileLength the length of text to select in the file when activated
- * or -1
- * @param fileLineNumber the line number to select in the file when
- * activated, or -1
+ * @param file the file to open when activated
+ * @param editorId the identifier of the editor to open the file in, or
+ * <code>null</code> if the default editor should be used
+ * @param fileOffset the offset in the file to select when activated, or -1
+ * @param fileLength the length of text to select in the file when activated
+ * or -1
+ * @param fileLineNumber the line number to select in the file when activated,
+ * or -1. First line number is 1. Only used if
+ * <em>fileOffset</em> is not set.
*/
public FileLink(IFile file, String editorId, int fileOffset, int fileLength, int fileLineNumber) {
fFile = file;
@@ -82,7 +83,7 @@ public class FileLink implements IConsoleHyperlink {
if (page != null) {
try {
IEditorPart editorPart = page.openEditor(new FileEditorInput(fFile), getEditorId() , true);
- if (fFileLineNumber > 0) {
+ if (fFileLineNumber > 0 || (fFileOffset >= 0 && fFileLength >= 0)) {
ITextEditor textEditor = null;
if (editorPart instanceof ITextEditor) {
textEditor = (ITextEditor) editorPart;
@@ -90,8 +91,8 @@ public class FileLink implements IConsoleHyperlink {
textEditor = editorPart.getAdapter(ITextEditor.class);
}
if (textEditor != null) {
- IEditorInput input = editorPart.getEditorInput();
if (fFileOffset < 0) {
+ IEditorInput input = editorPart.getEditorInput();
IDocumentProvider provider = textEditor.getDocumentProvider();
try {
provider.connect(input);

Back to the top