View | Details | Raw Unified | Return to bug 372588 | Differences between
and this patch

Collapse All | Expand All

(-)a/org.eclipse.jdt.junit.core/.gitignore (+1 lines)
Added Link Here
1
/bin/
(-)a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestCaseElement.java (-2 / +81 lines)
Lines 7-13 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Xavier Coulon <xcoulon@redhat.com> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512 - [JUnit] test method name cut off before (
10
 *     Xavier Coulon <xcoulon@redhat.com> 
11
 *         - [JUnit] test method name cut off before '(' - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512
12
 *         - [JUnit] Add "Link with Editor" to JUnit view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=372588 
11
 *******************************************************************************/
13
 *******************************************************************************/
12
14
13
package org.eclipse.jdt.internal.junit.model;
15
package org.eclipse.jdt.internal.junit.model;
Lines 15-29 Link Here
15
import org.eclipse.jdt.junit.model.ITestCaseElement;
17
import org.eclipse.jdt.junit.model.ITestCaseElement;
16
18
17
import org.eclipse.core.runtime.Assert;
19
import org.eclipse.core.runtime.Assert;
20
import org.eclipse.core.runtime.IAdaptable;
18
21
22
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IMethod;
24
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.JavaModelException;
19
26
20
public class TestCaseElement extends TestElement implements ITestCaseElement {
27
import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
28
29
/**
30
 * 
31
 * @since 3.7 implements {@link IAdaptable}
32
 */
33
public class TestCaseElement extends TestElement implements ITestCaseElement, IAdaptable {
34
35
	private IMethod fJavaMethod= null;
36
37
	private boolean fJavaMethodResolved= false;
21
38
22
	private boolean fIgnored;
39
	private boolean fIgnored;
23
40
24
	public TestCaseElement(TestSuiteElement parent, String id, String testName) {
41
	public TestCaseElement(TestSuiteElement parent, String id, String testName) {
25
		super(parent, id, testName);
42
		super(parent, id, testName);
26
		Assert.isNotNull(parent);
43
		Assert.isNotNull(parent);
44
	}
45
46
	/**
47
	 * @return the name of the Java Method associated with this {@link TestCaseElement}, ie, it
48
	 *         returns the valid java identifier part of the name (in particular, it removes the
49
	 *         brackets suffix for Parameterized JUnit tests).
50
	 * 
51
	 * 
52
	 */
53
	private String getJavaTestMethodName() {
54
		String testMethodName= getTestMethodName();
55
		for (int i= 0; i < testMethodName.length(); i++) {
56
			if (!Character.isJavaIdentifierPart(testMethodName.charAt(i))) {
57
				return testMethodName.substring(0, i);
58
			}
59
		}
60
		return testMethodName;
27
	}
61
	}
28
62
29
	/**
63
	/**
Lines 41-46 Link Here
41
		if (index > 0)
75
		if (index > 0)
42
			return testName.substring(0, index);
76
			return testName.substring(0, index);
43
		return testName;
77
		return testName;
78
	}
79
80
	/**
81
	 * Finds and returns the {@link IMethod} associated with this {@link TestCaseElement}.
82
	 * 
83
	 * @return the corresponding Java method element or null if not found.
84
	 * @since 3.7
85
	 */
86
	public IMethod getJavaMethod() {
87
		if (!fJavaMethodResolved) {
88
			try {
89
				final IType type= getJavaType();
90
				if (type != null) {
91
					final IMethod[] methods= type.getMethods();
92
					String testMethodName= getJavaTestMethodName();
93
					for (int i= 0; i < methods.length; i++) {
94
						if (methods[i].getElementName().equals(testMethodName)) {
95
							fJavaMethod= methods[i];
96
							return methods[i];
97
						}
98
					}
99
				}
100
				return null;
101
			} catch (JavaModelException e) {
102
				JUnitCorePlugin.log(e);
103
			} finally {
104
				fJavaMethodResolved= true;
105
			}
106
		}
107
		return fJavaMethod;
44
	}
108
	}
45
109
46
	/**
110
	/**
Lines 73-76 Link Here
73
	public String toString() {
137
	public String toString() {
74
		return "TestCase: " + getTestClassName() + "." + getTestMethodName() + " : " + super.toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
138
		return "TestCase: " + getTestClassName() + "." + getTestMethodName() + " : " + super.toString(); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
75
	}
139
	}
140
141
	/**
142
	 * Provides support for converting this {@link TestCaseElement} into an {@link IMethod} when the
143
	 * given adapter class is {@link IJavaElement}.
144
	 * 
145
	 * @param adapter the class in which this {@link TestCaseElement} should be adapted.
146
	 * @return an object in the request type, or null if it could not be adapted.
147
	 * @since 3.7
148
	 */
149
	public Object getAdapter(Class adapter) {
150
		if (adapter != null && adapter.equals(IJavaElement.class)) {
151
			return getJavaMethod();
152
		}
153
		return null;
154
	}
76
}
155
}
(-)a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestElement.java (-1 / +31 lines)
Lines 9-15 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak (brockj@tpg.com.au)
10
 *     Brock Janiczak (brockj@tpg.com.au)
11
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102236: [JUnit] display execution time next to each test
11
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102236: [JUnit] display execution time next to each test
12
 *     Xavier Coulon <xcoulon@redhat.com> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512 - [JUnit] test method name cut off before (
12
 *     Xavier Coulon <xcoulon@redhat.com> 
13
 *         - [JUnit] test method name cut off before '(' - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512
14
 *         - [JUnit] Add "Link with Editor" to JUnit view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=372588 
13
 *******************************************************************************/
15
 *******************************************************************************/
14
16
15
package org.eclipse.jdt.internal.junit.model;
17
package org.eclipse.jdt.internal.junit.model;
Lines 19-24 Link Here
19
import org.eclipse.jdt.junit.model.ITestRunSession;
21
import org.eclipse.jdt.junit.model.ITestRunSession;
20
22
21
import org.eclipse.core.runtime.Assert;
23
import org.eclipse.core.runtime.Assert;
24
25
import org.eclipse.jdt.core.IType;
26
import org.eclipse.jdt.core.JavaModelException;
27
28
import org.eclipse.jdt.internal.junit.JUnitCorePlugin;
22
29
23
30
24
public abstract class TestElement implements ITestElement {
31
public abstract class TestElement implements ITestElement {
Lines 175-180 Link Here
175
182
176
	private boolean fAssumptionFailed;
183
	private boolean fAssumptionFailed;
177
184
185
	private IType fJavaType= null;
186
187
	private boolean fJavaTypeResolved= false;
188
178
	/**
189
	/**
179
	 * Running time in seconds. Contents depend on the current {@link #getProgressState()}:
190
	 * Running time in seconds. Contents depend on the current {@link #getProgressState()}:
180
	 * <ul>
191
	 * <ul>
Lines 324-329 Link Here
324
		return extractClassName(getTestName());
335
		return extractClassName(getTestName());
325
	}
336
	}
326
337
338
	/**
339
	 * @return the Java {@link IType} associated with this {@link TestElement}.
340
	 * @since 3.7
341
	 */
342
	public IType getJavaType() {
343
		if (!fJavaTypeResolved) {
344
			try {
345
				fJavaType= getTestRunSession().getLaunchedProject().findType(getClassName());
346
			} catch (JavaModelException e) {
347
				JUnitCorePlugin.log(e);
348
			} finally {
349
				fJavaTypeResolved= true;
350
			}
351
		}
352
		return fJavaType;
353
	}
354
355
356
327
	private static String extractClassName(String testNameString) {
357
	private static String extractClassName(String testNameString) {
328
		testNameString= extractRawClassName(testNameString);
358
		testNameString= extractRawClassName(testNameString);
329
		testNameString= testNameString.replace('$', '.'); // see bug 178503
359
		testNameString= testNameString.replace('$', '.'); // see bug 178503
(-)a/org.eclipse.jdt.junit.core/src/org/eclipse/jdt/internal/junit/model/TestSuiteElement.java (-2 / +71 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2014 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Xavier Coulon <xcoulon@redhat.com> -  [JUnit] Add "Link with Editor" to JUnit view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=372588
10
 *******************************************************************************/
11
 *******************************************************************************/
11
12
12
package org.eclipse.jdt.internal.junit.model;
13
package org.eclipse.jdt.internal.junit.model;
Lines 17-24 Link Here
17
import org.eclipse.jdt.junit.model.ITestElement;
18
import org.eclipse.jdt.junit.model.ITestElement;
18
import org.eclipse.jdt.junit.model.ITestSuiteElement;
19
import org.eclipse.jdt.junit.model.ITestSuiteElement;
19
20
21
import org.eclipse.core.runtime.IAdaptable;
20
22
21
public class TestSuiteElement extends TestElement implements ITestSuiteElement {
23
import org.eclipse.jdt.core.IJavaElement;
24
import org.eclipse.jdt.core.IMethod;
25
import org.eclipse.jdt.core.IType;
26
27
28
public class TestSuiteElement extends TestElement implements ITestSuiteElement, IAdaptable {
29
30
	private IJavaElement fJavaElement= null;
31
32
	private boolean fJavaElementResolved= false;
22
33
23
	private List/*<TestElement>*/ fChildren;
34
	private List/*<TestElement>*/ fChildren;
24
	private Status fChildrenStatus;
35
	private Status fChildrenStatus;
Lines 151-154 Link Here
151
		return "TestSuite: " + getSuiteTypeName() + " : " + super.toString() + " (" + fChildren.size() + ")";   //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
162
		return "TestSuite: " + getSuiteTypeName() + " : " + super.toString() + " (" + fChildren.size() + ")";   //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
152
	}
163
	}
153
164
165
	/**
166
	 * Provides support for converting this {@link TestSuiteElement} into an {@link IType} (or an
167
	 * {@link IMethod} when this {@link TestSuiteElement} matches a JUnit Parameterized Test) when
168
	 * the given adapter class is {@link IJavaElement}.
169
	 * 
170
	 * @param adapter the class in which this {@link TestSuiteElement} should be adapted.
171
	 * @return an object in the request type, or null if it could not be adapted.
172
	 * @since 3.7
173
	 */
174
	public Object getAdapter(Class adapter) {
175
		if (adapter != null && adapter.equals(IJavaElement.class)) {
176
			return getJavaElement();
177
		}
178
		return null;
179
	}
180
181
	/**
182
	 * Returns the closest {@link IJavaElement} for the given {@link TestSuiteElement}, including
183
	 * with a work-around for Parameterized tests by looking at the child elements: if there's only
184
	 * one, return its Java {@link IMethod}. Otherwise, return the {@link IType}
185
	 * 
186
	 * @return the {@link IJavaElement} found for this {@link TestSuiteElement}.
187
	 * 
188
	 * @since 3.7
189
	 * @see TestElement#getJavaType()
190
	 */
191
	public IJavaElement getJavaElement() {
192
		if (!fJavaElementResolved) {
193
			// whatever happens, let's consider that the Java Type has been resolved, to make sure we don't come back here again for this TestSuitElement.
194
			fJavaElementResolved= true;
195
			fJavaElement= super.getJavaType();
196
			if (fJavaElement == null) {
197
				if (getChildren().length == 1 && getChildren()[0] instanceof TestCaseElement) {
198
					fJavaElement= ((TestCaseElement)getChildren()[0]).getJavaMethod();
199
				}
200
			}
201
		}
202
		return fJavaElement;
203
	}
204
205
	/**
206
	 * Returns the {@link IType} associated with the given {@link TestSuiteElement}, or uses the
207
	 * work-around in {@link TestSuiteElement#getJavaElement()} to retrieve the {@link IType}
208
	 * associated with the single child {@link TestCaseElement} if this {@link TestSuiteElement}
209
	 * matches a Parameterized JUnit Test.
210
	 * 
211
	 * @since 3.7
212
	 * @see TestElement#getJavaType()
213
	 */
214
	public IType getJavaType() {
215
		final IType javaType= super.getJavaType();
216
		if (javaType != null) {
217
			return javaType;
218
		} else if (getJavaElement() != null) {
219
			return (IType)fJavaElement.getAncestor(IJavaElement.TYPE);
220
		}
221
		return null;
222
	}
154
}
223
}
(-)a/org.eclipse.jdt.junit/.gitignore (+1 lines)
Added Link Here
1
/bin/
(-)a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestRunnerViewPart.java (-4 / +140 lines)
Lines 16-21 Link Here
16
 *     Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Rerun failed first does not work with JUnit4 - https://bugs.eclipse.org/bugs/show_bug.cgi?id=140392
16
 *     Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Rerun failed first does not work with JUnit4 - https://bugs.eclipse.org/bugs/show_bug.cgi?id=140392
17
 *     Thirumala Reddy Mutchukota <thirumala@google.com> - [JUnit] Avoid rerun test launch on UI thread - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411841
17
 *     Thirumala Reddy Mutchukota <thirumala@google.com> - [JUnit] Avoid rerun test launch on UI thread - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411841
18
 *     Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Add a monospace font option for the junit results view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411794
18
 *     Andrew Eisenberg <andrew@eisenberg.as> - [JUnit] Add a monospace font option for the junit results view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=411794
19
 *     Xavier Coulon <xcoulon@redhat.com> -  [JUnit] Add "Link with Editor" to JUnit view - https://bugs.eclipse.org/bugs/show_bug.cgi?id=372588
19
 *******************************************************************************/
20
 *******************************************************************************/
20
package org.eclipse.jdt.internal.junit.ui;
21
package org.eclipse.jdt.internal.junit.ui;
21
22
Lines 36-41 Link Here
36
import java.util.Iterator;
37
import java.util.Iterator;
37
import java.util.List;
38
import java.util.List;
38
39
40
import org.eclipse.jdt.junit.model.ITestElement.ProgressState;
39
import org.eclipse.jdt.junit.model.ITestElement.Result;
41
import org.eclipse.jdt.junit.model.ITestElement.Result;
40
42
41
import org.eclipse.swt.SWT;
43
import org.eclipse.swt.SWT;
Lines 96-101 Link Here
96
import org.eclipse.jface.dialogs.MessageDialog;
98
import org.eclipse.jface.dialogs.MessageDialog;
97
import org.eclipse.jface.operation.IRunnableWithProgress;
99
import org.eclipse.jface.operation.IRunnableWithProgress;
98
import org.eclipse.jface.resource.ImageDescriptor;
100
import org.eclipse.jface.resource.ImageDescriptor;
101
import org.eclipse.jface.viewers.ISelection;
99
102
100
import org.eclipse.ui.IActionBars;
103
import org.eclipse.ui.IActionBars;
101
import org.eclipse.ui.IEditorActionBarContributor;
104
import org.eclipse.ui.IEditorActionBarContributor;
Lines 149-154 Link Here
149
152
150
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
153
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
151
154
155
import org.eclipse.jdt.internal.ui.JavaPluginImages;
156
import org.eclipse.jdt.internal.ui.actions.AbstractToggleLinkingAction;
157
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
152
import org.eclipse.jdt.internal.ui.viewsupport.ViewHistory;
158
import org.eclipse.jdt.internal.ui.viewsupport.ViewHistory;
153
159
154
/**
160
/**
Lines 210-215 Link Here
210
	private Action fPreviousAction;
216
	private Action fPreviousAction;
211
217
212
	private StopAction fStopAction;
218
	private StopAction fStopAction;
219
	private LinkWithEditorAction fLinkWithEditorAction;
213
	private JUnitCopyAction fCopyAction;
220
	private JUnitCopyAction fCopyAction;
214
	private Action fPasteAction;
221
	private Action fPasteAction;
215
222
Lines 320-331 Link Here
320
	public static final Object FAMILY_JUNIT_RUN = new Object();
327
	public static final Object FAMILY_JUNIT_RUN = new Object();
321
328
322
	private IPartListener2 fPartListener= new IPartListener2() {
329
	private IPartListener2 fPartListener= new IPartListener2() {
323
		public void partActivated(IWorkbenchPartReference ref) { }
330
324
		public void partBroughtToTop(IWorkbenchPartReference ref) { }
331
		public void partActivated(IWorkbenchPartReference ref) {
332
		}
333
334
		public void partBroughtToTop(IWorkbenchPartReference ref) {
335
			updateTestViewerSelection(ref);
336
		}
337
325
		public void partInputChanged(IWorkbenchPartReference ref) { }
338
		public void partInputChanged(IWorkbenchPartReference ref) { }
326
		public void partClosed(IWorkbenchPartReference ref) { }
339
		public void partClosed(IWorkbenchPartReference ref) { }
327
		public void partDeactivated(IWorkbenchPartReference ref) { }
340
		public void partDeactivated(IWorkbenchPartReference ref) { }
328
		public void partOpened(IWorkbenchPartReference ref) { }
341
342
		public void partOpened(IWorkbenchPartReference ref) {
343
			updateTestViewerSelection(ref);
344
		}
329
345
330
		public void partVisible(IWorkbenchPartReference ref) {
346
		public void partVisible(IWorkbenchPartReference ref) {
331
			if (getSite().getId().equals(ref.getId())) {
347
			if (getSite().getId().equals(ref.getId())) {
Lines 336-341 Link Here
336
		public void partHidden(IWorkbenchPartReference ref) {
352
		public void partHidden(IWorkbenchPartReference ref) {
337
			if (getSite().getId().equals(ref.getId())) {
353
			if (getSite().getId().equals(ref.getId())) {
338
				fPartIsVisible= false;
354
				fPartIsVisible= false;
355
			}
356
		}
357
358
		private void updateTestViewerSelection(IWorkbenchPartReference ref) {
359
			final IWorkbenchPart part= ref.getPart(false);
360
			if (part instanceof JavaEditor && fLinkWithEditorAction.isChecked()) {
361
				final ISelection selection= ((JavaEditor) part).getSelectionProvider().getSelection();
362
				fTestViewer.selectionChanged(part, selection);
339
			}
363
			}
340
		}
364
		}
341
	};
365
	};
Lines 899-904 Link Here
899
		}
923
		}
900
	}
924
	}
901
925
926
	/**
927
	 * This action toggles whether this {@link TestRunnerViewPart} links its selection to the active
928
	 * editor.
929
	 *
930
	 */
931
	private class LinkWithEditorAction extends AbstractToggleLinkingAction {
932
933
		/** Image to use when the sync is on.*/
934
		private static final String SYNCED_GIF= "synced.gif"; //$NON-NLS-1$
935
		
936
		/** Image to use when the sync is broken.*/
937
		private static final String SYNC_BROKEN_GIF= "sync_broken.gif"; //$NON-NLS-1$
938
		
939
		/**
940
		 * Default image when the action is created (as defined in the constructor of the
941
		 * superclass).
942
		 */
943
		private String fIconName= SYNCED_GIF;
944
		
945
		LinkWithEditorAction() {
946
			super();
947
			// enable by default
948
			setChecked(true);
949
		}
950
951
		@Override
952
		public void run() {
953
			setLinkingWithEditorActive(isChecked());
954
		}
955
		
956
		/**
957
		 * Updates the Link image with a "normal link" image if parameter is true, or a
958
		 * "broken link" image otherwise
959
		 * 
960
		 * @param isInSync the state of synchronization
961
		 */
962
		public void updateLinkImage(boolean isInSync) {
963
			fIconName= isInSync ? SYNCED_GIF : SYNC_BROKEN_GIF;
964
			JavaPluginImages.setLocalImageDescriptors(this, fIconName);
965
		}
966
967
	}
968
969
	/**
970
	 * @return {@code true} if the {@link LinkWithEditorAction} is checked, {@code false} otherwise.
971
	 * @since 3.8
972
	 */
973
	public boolean isLinkWithEditorActive() {
974
		return fLinkWithEditorAction.isChecked();
975
	}
976
977
	/**
978
	 * @return the {@link ProgressState} of the current {@link TestRunSession}, or
979
	 *         {@link ProgressState#NOT_STARTED} if there's no {@link TestRunSession} yet.
980
	 * @since 3.8
981
	 */
982
	public ProgressState getCurrentProgressState() {
983
		if (fTestRunSession == null) {
984
			return ProgressState.NOT_STARTED;
985
		}
986
		return fTestRunSession.getProgressState();
987
	}
988
989
902
	private class RerunLastAction extends Action {
990
	private class RerunLastAction extends Action {
903
		public RerunLastAction() {
991
		public RerunLastAction() {
904
			setText(JUnitMessages.TestRunnerViewPart_rerunaction_label);
992
			setText(JUnitMessages.TestRunnerViewPart_rerunaction_label);
Lines 1200-1205 Link Here
1200
		}
1288
		}
1201
	}
1289
	}
1202
1290
1291
	/**
1292
	 * Activate the 'Link with Editor' in the current {@link IWorkbenchPage}. (The
1293
	 * {@link TestViewer} will respond to {@link ISelection} changes.)
1294
	 * 
1295
	 * @param active boolean to indicate if the link with editor is active ({@code true}) or not (
1296
	 *            {@code false})
1297
	 * 
1298
	 * @since 3.8
1299
	 */
1300
	public void setLinkingWithEditorActive(final boolean active) {
1301
		if (active) {
1302
			getSite().getPage().addPostSelectionListener(fTestViewer);
1303
			fTestViewer.setSelection(getSite().getPage().getActiveEditor());
1304
		} else {
1305
			getSite().getPage().removePostSelectionListener(fTestViewer);
1306
			// force the icon to 'synced' mode
1307
			setLinkingWithEditorInSync(true);
1308
		}
1309
	}
1310
1311
	/**
1312
	 * Updates the Link image with a "normal link" image if parameter is true, or a "broken link"
1313
	 * image otherwise
1314
	 * 
1315
	 * @param isInSync the state of synchronization
1316
	 * 
1317
	 * @since 3.8
1318
	 */
1319
	public void setLinkingWithEditorInSync(final boolean isInSync) {
1320
		fLinkWithEditorAction.updateLinkImage(isInSync);
1321
	}
1322
1203
	private void startUpdateJobs() {
1323
	private void startUpdateJobs() {
1204
		postSyncProcessChanges();
1324
		postSyncProcessChanges();
1205
1325
Lines 1245-1251 Link Here
1245
		boolean hasErrorsOrFailures= hasErrorsOrFailures();
1365
		boolean hasErrorsOrFailures= hasErrorsOrFailures();
1246
		fNextAction.setEnabled(hasErrorsOrFailures);
1366
		fNextAction.setEnabled(hasErrorsOrFailures);
1247
		fPreviousAction.setEnabled(hasErrorsOrFailures);
1367
		fPreviousAction.setEnabled(hasErrorsOrFailures);
1248
1368
		fLinkWithEditorAction.setEnabled(fTestRunSession != null);
1249
		fTestViewer.processChangesInUI();
1369
		fTestViewer.processChangesInUI();
1250
	}
1370
	}
1251
1371
Lines 1512-1517 Link Here
1512
				stopUpdateJobs();
1632
				stopUpdateJobs();
1513
1633
1514
				fStopAction.setEnabled(fTestRunSession.isKeptAlive());
1634
				fStopAction.setEnabled(fTestRunSession.isKeptAlive());
1635
				// if "Link with Editor" is active, register the listener
1636
				if (isLinkWithEditorActive()) {
1637
					getSite().getPage().addPostSelectionListener(fTestViewer);
1638
					fTestViewer.setSelection(getSite().getPage().getActiveEditor());
1639
				}
1640
1515
				fTestViewer.expandFirstLevel();
1641
				fTestViewer.expandFirstLevel();
1516
			}
1642
			}
1517
		}
1643
		}
Lines 1579-1584 Link Here
1579
		if (fFailureTrace != null) {
1705
		if (fFailureTrace != null) {
1580
			fFailureTrace.dispose();
1706
			fFailureTrace.dispose();
1581
		}
1707
		}
1708
		getSite().getPage().removePostSelectionListener(fTestViewer);
1582
	}
1709
	}
1583
1710
1584
	private void disposeImages() {
1711
	private void disposeImages() {
Lines 1783-1788 Link Here
1783
		if (!testRunSessions.isEmpty()) {
1910
		if (!testRunSessions.isEmpty()) {
1784
			fTestRunSessionListener.sessionAdded(testRunSessions.get(0));
1911
			fTestRunSessionListener.sessionAdded(testRunSessions.get(0));
1785
		}
1912
		}
1913
		fLinkWithEditorAction.setChecked(true);
1914
		setLinkingWithEditorActive(true);
1915
		setLinkingWithEditorInSync(true);
1786
	}
1916
	}
1787
1917
1788
	private void addDropAdapter(Composite parent) {
1918
	private void addDropAdapter(Composite parent) {
Lines 1887-1892 Link Here
1887
		fStopAction= new StopAction();
2017
		fStopAction= new StopAction();
1888
		fStopAction.setEnabled(false);
2018
		fStopAction.setEnabled(false);
1889
2019
2020
		fLinkWithEditorAction= new LinkWithEditorAction();
2021
		fLinkWithEditorAction.setChecked(false);
2022
		fLinkWithEditorAction.setEnabled(false);
2023
1890
		fRerunLastTestAction= new RerunLastAction();
2024
		fRerunLastTestAction= new RerunLastAction();
1891
		IHandlerService handlerService= getSite().getWorkbenchWindow().getService(IHandlerService.class);
2025
		IHandlerService handlerService= getSite().getWorkbenchWindow().getService(IHandlerService.class);
1892
		IHandler handler = new AbstractHandler() {
2026
		IHandler handler = new AbstractHandler() {
Lines 1937-1942 Link Here
1937
		toolBar.add(fRerunFailedFirstAction);
2071
		toolBar.add(fRerunFailedFirstAction);
1938
		toolBar.add(fStopAction);
2072
		toolBar.add(fStopAction);
1939
		toolBar.add(fViewHistory.createHistoryDropDownAction());
2073
		toolBar.add(fViewHistory.createHistoryDropDownAction());
2074
		toolBar.add(new Separator());
2075
		toolBar.add(fLinkWithEditorAction);
1940
2076
1941
2077
1942
		viewMenu.add(fShowTestHierarchyAction);
2078
		viewMenu.add(fShowTestHierarchyAction);
(-)a/org.eclipse.jdt.junit/src/org/eclipse/jdt/internal/junit/ui/TestViewer.java (-4 / +310 lines)
Lines 9-16 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Brock Janiczak (brockj@tpg.com.au)
10
 *     Brock Janiczak (brockj@tpg.com.au)
11
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102236: [JUnit] display execution time next to each test
11
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102236: [JUnit] display execution time next to each test
12
 *     Xavier Coulon <xcoulon@redhat.com> - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512 - [JUnit] test method name cut off before (
12
 *     Xavier Coulon <xcoulon@redhat.com>
13
13
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512 - [JUnit] test method name cut off before (
14
 *         - https://bugs.eclipse.org/bugs/show_bug.cgi?id=372588 - [JUnit] Add "Link with Editor" to JUnit view
14
 *******************************************************************************/
15
 *******************************************************************************/
15
16
16
package org.eclipse.jdt.internal.junit.ui;
17
package org.eclipse.jdt.internal.junit.ui;
Lines 23-29 Link Here
23
import java.util.List;
24
import java.util.List;
24
import java.util.ListIterator;
25
import java.util.ListIterator;
25
26
27
import org.eclipse.jdt.junit.model.ITestCaseElement;
26
import org.eclipse.jdt.junit.model.ITestElement;
28
import org.eclipse.jdt.junit.model.ITestElement;
29
import org.eclipse.jdt.junit.model.ITestElement.ProgressState;
30
import org.eclipse.jdt.junit.model.ITestElementContainer;
31
import org.eclipse.jdt.junit.model.ITestSuiteElement;
27
32
28
import org.eclipse.swt.SWT;
33
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.dnd.Clipboard;
34
import org.eclipse.swt.dnd.Clipboard;
Lines 42-49 Link Here
42
import org.eclipse.jface.action.MenuManager;
47
import org.eclipse.jface.action.MenuManager;
43
import org.eclipse.jface.action.Separator;
48
import org.eclipse.jface.action.Separator;
44
import org.eclipse.jface.viewers.AbstractTreeViewer;
49
import org.eclipse.jface.viewers.AbstractTreeViewer;
50
import org.eclipse.jface.viewers.ISelection;
45
import org.eclipse.jface.viewers.ISelectionChangedListener;
51
import org.eclipse.jface.viewers.ISelectionChangedListener;
46
import org.eclipse.jface.viewers.IStructuredSelection;
52
import org.eclipse.jface.viewers.IStructuredSelection;
53
import org.eclipse.jface.viewers.ITreeSelection;
47
import org.eclipse.jface.viewers.SelectionChangedEvent;
54
import org.eclipse.jface.viewers.SelectionChangedEvent;
48
import org.eclipse.jface.viewers.StructuredSelection;
55
import org.eclipse.jface.viewers.StructuredSelection;
49
import org.eclipse.jface.viewers.StructuredViewer;
56
import org.eclipse.jface.viewers.StructuredViewer;
Lines 52-64 Link Here
52
import org.eclipse.jface.viewers.Viewer;
59
import org.eclipse.jface.viewers.Viewer;
53
import org.eclipse.jface.viewers.ViewerFilter;
60
import org.eclipse.jface.viewers.ViewerFilter;
54
61
62
import org.eclipse.jface.text.ITextSelection;
63
64
import org.eclipse.ui.IEditorPart;
65
import org.eclipse.ui.ISelectionListener;
55
import org.eclipse.ui.IWorkbenchActionConstants;
66
import org.eclipse.ui.IWorkbenchActionConstants;
67
import org.eclipse.ui.IWorkbenchPart;
68
import org.eclipse.ui.PartInitException;
56
import org.eclipse.ui.part.PageBook;
69
import org.eclipse.ui.part.PageBook;
57
70
58
import org.eclipse.debug.core.ILaunchConfiguration;
71
import org.eclipse.debug.core.ILaunchConfiguration;
59
import org.eclipse.debug.core.ILaunchManager;
72
import org.eclipse.debug.core.ILaunchManager;
60
73
74
import org.eclipse.jdt.core.IClassFile;
75
import org.eclipse.jdt.core.ICompilationUnit;
76
import org.eclipse.jdt.core.IJavaElement;
61
import org.eclipse.jdt.core.IJavaProject;
77
import org.eclipse.jdt.core.IJavaProject;
78
import org.eclipse.jdt.core.IMethod;
62
import org.eclipse.jdt.core.IType;
79
import org.eclipse.jdt.core.IType;
63
import org.eclipse.jdt.core.JavaModelException;
80
import org.eclipse.jdt.core.JavaModelException;
64
81
Lines 72-82 Link Here
72
89
73
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
90
import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
74
91
92
import org.eclipse.jdt.ui.JavaUI;
93
94
import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
95
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
96
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
75
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
97
import org.eclipse.jdt.internal.ui.viewsupport.ColoringLabelProvider;
76
import org.eclipse.jdt.internal.ui.viewsupport.SelectionProviderMediator;
98
import org.eclipse.jdt.internal.ui.viewsupport.SelectionProviderMediator;
77
99
78
100
79
public class TestViewer {
101
public class TestViewer implements ISelectionListener {
80
	private final class TestSelectionListener implements ISelectionChangedListener {
102
	private final class TestSelectionListener implements ISelectionChangedListener {
81
		public void selectionChanged(SelectionChangedEvent event) {
103
		public void selectionChanged(SelectionChangedEvent event) {
82
			handleSelected();
104
			handleSelected();
Lines 343-348 Link Here
343
			testElement= (TestElement) selection.getFirstElement();
365
			testElement= (TestElement) selection.getFirstElement();
344
		}
366
		}
345
		fTestRunnerPart.handleTestSelected(testElement);
367
		fTestRunnerPart.handleTestSelected(testElement);
368
		// if LinkWithEditor is active, reveal the JavaEditor and select the java type or method
369
		// matching the selected test element, even if the JavaEditor is opened by not active.
370
		if (fTestRunnerPart.isLinkWithEditorActive()) {
371
			handleTestElementSelected(testElement);
372
		}
346
	}
373
	}
347
374
348
	public synchronized void setShowTime(boolean showTime) {
375
	public synchronized void setShowTime(boolean showTime) {
Lines 609-614 Link Here
609
			fTreeViewer.reveal(current);
636
			fTreeViewer.reveal(current);
610
	}
637
	}
611
638
639
	/**
640
	 * Sets the current selection from the given {@link IEditorPart} (if it is a
641
	 * {@link CompilationUnitEditor}) and its selection.
642
	 * 
643
	 * @param editor the selected Java Element in the active Compilation Unit Editor
644
	 * 
645
	 * @since 3.8
646
	 */
647
	public void setSelection(final IEditorPart editor) {
648
		if (editor != null) {
649
			final IJavaElement selectedJavaElement= getSelectedJavaElementInEditor(editor);
650
			setSelection(selectedJavaElement);
651
		}
652
	}
653
	
654
	/**
655
	 * Sets the current selection from the given {@link IJavaElement} if it matches an
656
	 * {@link ITestCaseElement} and updates the LinkWithEditorAction image in the associated
657
	 * {@link TestRunnerViewPart}.
658
	 * 
659
	 * @param activeJavaElement the selected Java Element (or null) in the active
660
	 *            {@link IWorkbenchPart}
661
	 * 
662
	 */
663
	private void setSelection(final IJavaElement activeJavaElement) {
664
		final ITestElement activeTestCaseElement= findClosestTestElement(activeJavaElement, getCurrentViewerSelection());
665
		if (activeTestCaseElement != null) {
666
			// update the current selection in the viewer if it does not match with the java element selected in the given part (if it's not the parent TestViewerPart)
667
			final Object currentSelection= getCurrentViewerSelection();
668
			if (!activeTestCaseElement.equals(currentSelection)) {
669
				final IStructuredSelection selection= new StructuredSelection(activeTestCaseElement);
670
				fSelectionProvider.setSelection(selection, true);
671
			}
672
			// ensure link with editor is in 'synced' mode
673
			fTestRunnerPart.setLinkingWithEditorInSync(true);
674
		}
675
		else {
676
			// selection is out-of-sync: show a different icon on the button.
677
			fTestRunnerPart.setLinkingWithEditorInSync(false);
678
		}
679
	}
680
681
	/**
682
	 * @return the current selection in the JUnit Viewer (provided by the underlying selection
683
	 *         provider), or {@code null} if the kind of selection is not an {@link ITreeSelection}
684
	 *         nor an {@link IStructuredSelection}.
685
	 */
686
	private Object getCurrentViewerSelection() {
687
		final ISelection currentSelection= fSelectionProvider.getSelection();
688
		if (currentSelection instanceof ITreeSelection) {
689
			return ((ITreeSelection)currentSelection).getFirstElement();
690
		} else if (currentSelection instanceof IStructuredSelection) {
691
			return ((IStructuredSelection)currentSelection).getFirstElement();
692
		}
693
		return null;
694
	}
695
696
	/**
697
	 * Finds the closest {@link ITestElement} from the given {@link IJavaElement}
698
	 * 
699
	 * @param javaElement the java element associated with the {@link ITestElement} to find.
700
	 * @param currentSelection the current selection in the TestViewer
701
	 * @return the {@link ITestElement} or null if it could not be found.
702
	 */
703
	private ITestElement findClosestTestElement(final IJavaElement javaElement, final Object currentSelection) {
704
		// skip if JUnit is still running or if no Java element was selected
705
		if (fTestRunnerPart.getCurrentProgressState() != ProgressState.COMPLETED || javaElement == null) {
706
			return null;
707
		}
708
		final ITestElement currentTestElement= (ITestElement) currentSelection;
709
		// if the current selection already matches the given java element
710
		if ((currentSelection instanceof TestCaseElement && ((TestCaseElement) currentSelection).getJavaMethod() != null && ((TestCaseElement) currentSelection).getJavaMethod().equals(
711
				javaElement))
712
				|| (currentSelection instanceof TestSuiteElement && ((TestSuiteElement) currentSelection).getJavaType() != null && ((TestSuiteElement) currentSelection).getJavaType().equals(
713
						javaElement))) {
714
			return currentTestElement;
715
		}
716
		// if current selection is a TestCaseElement / Java method, move to the parent
717
		ITestElementContainer currentElementContainer= fTestRunSession;
718
		if (currentTestElement instanceof ITestElementContainer) {
719
			currentElementContainer= (ITestElementContainer) currentTestElement;
720
		} else if (currentTestElement != null) {
721
			currentElementContainer= currentTestElement.getParentContainer();
722
		}
723
		// now, look in the current test container, or move to parent container until root
724
		while (currentElementContainer != null) {
725
			switch (javaElement.getElementType()) {
726
				case IJavaElement.METHOD:
727
					final ITestCaseElement resultTestCaseElement= findTestCaseElement(currentElementContainer, (IMethod) javaElement);
728
					if (resultTestCaseElement != null) {
729
						return resultTestCaseElement;
730
					}
731
					break;
732
				case IJavaElement.TYPE:
733
					final ITestSuiteElement resultTestSuiteElement= findTestSuiteElement(currentElementContainer, (IType) javaElement);
734
					if (resultTestSuiteElement != null) {
735
						return resultTestSuiteElement;
736
					}
737
					break;
738
				default:
739
					// no result will be provided if the user selects anything else, including package declaration, imports and fields.
740
					break;
741
			}
742
			currentElementContainer= currentElementContainer.getParentContainer();
743
		}
744
		return null;
745
	}
746
747
	/**
748
	 * Finds the {@link ITestCaseElement} with the given test class name and test method name in the
749
	 * given {@link ITestSuiteElement}
750
	 * 
751
	 * @param parentElement the parent Test Suite
752
	 * @param javaMethod the java method corresponding to the {@link ITestCaseElement} to find
753
	 * 
754
	 * @return the {@link ITestCaseElement} or null if it could not be found.
755
	 */
756
	private ITestCaseElement findTestCaseElement(final ITestElementContainer parentElement, final IMethod javaMethod) {
757
		final IType javaType= (IType) javaMethod.getAncestor(IJavaElement.TYPE);
758
		final String testClassName= javaType.getFullyQualifiedName();
759
		final String testMethodName= javaMethod.getElementName();
760
		for (ITestElement childElement : parentElement.getChildren()) {
761
			if (childElement instanceof ITestCaseElement) {
762
				final TestCaseElement testCaseElement= (TestCaseElement)childElement;
763
				if (testCaseElement.getJavaType() != null && testCaseElement.getJavaType().getFullyQualifiedName().equals(testClassName) && testCaseElement.getJavaMethod() != null
764
						&& testCaseElement.getJavaMethod() != null && testCaseElement.getJavaMethod().getElementName().equals(testMethodName)) {
765
					return testCaseElement;
766
				}
767
			} else if (childElement instanceof ITestSuiteElement) {
768
				final ITestCaseElement localResult= findTestCaseElement((ITestSuiteElement) childElement, javaMethod);
769
				if (localResult != null) {
770
					return localResult;
771
				}
772
			}
773
		}
774
		return null;
775
	}
776
777
	/**
778
	 * Finds the {@link ITestSuiteElement} with the given test class name in the given
779
	 * {@link ITestSuiteElement}
780
	 * 
781
	 * @param parentElement the parent Test Suite
782
	 * @param javaType the Java type corresponding to the {@link ITestSuiteElement} to find
783
	 * 
784
	 * @return the {@link ITestSuiteElement} or null if it could not be found.
785
	 */
786
	private ITestSuiteElement findTestSuiteElement(final ITestElementContainer parentElement, final IType javaType) {
787
		final String testClassName= javaType.getFullyQualifiedName();
788
		if (parentElement instanceof ITestSuiteElement && ((ITestSuiteElement) parentElement).getSuiteTypeName().equals(testClassName)) {
789
			return (ITestSuiteElement) parentElement;
790
		}
791
		for (ITestElement childElement : parentElement.getChildren()) {
792
			if (childElement instanceof ITestSuiteElement) {
793
				final ITestSuiteElement childTestSuite= (ITestSuiteElement)childElement;
794
				if (childTestSuite.getSuiteTypeName().equals(testClassName)) {
795
					return childTestSuite;
796
				}
797
				final ITestSuiteElement matchingNestedTestSuiteElement= findTestSuiteElement(childTestSuite, javaType);
798
				if (matchingNestedTestSuiteElement != null) {
799
					return matchingNestedTestSuiteElement;
800
				}
801
			}
802
		}
803
		return null;
804
	}
805
612
	public void selectFirstFailure() {
806
	public void selectFirstFailure() {
613
		TestCaseElement firstFailure= getNextChildFailure(fTestRunSession.getTestRoot(), true);
807
		TestCaseElement firstFailure= getNextChildFailure(fTestRunSession.getTestRoot(), true);
614
		if (firstFailure != null)
808
		if (firstFailure != null)
Lines 722-726 Link Here
722
		fTreeViewer.expandToLevel(2);
916
		fTreeViewer.expandToLevel(2);
723
	}
917
	}
724
918
725
}
919
	/**
920
	 * Reacts to a selection change in the active {@link IWorkbenchPart} (or when another part
921
	 * received the focus).
922
	 * 
923
	 * @param part the {@link IWorkbenchPart} in which the selection change occurred
924
	 * @param selection the selection in the given part
925
	 * @since 3.8
926
	 */
927
	public void selectionChanged(IWorkbenchPart part, ISelection selection) {
928
		if (part instanceof IEditorPart) {
929
			setSelection((IEditorPart)part);
930
		}
931
		// any ITreeSelection (eg: Project Explorer, Package Explorer, Content Outline) should be considered, too.
932
		else if (selection instanceof ITreeSelection) {
933
			final ITreeSelection treeSelection= (ITreeSelection) selection;
934
			if (treeSelection.size() == 1) {
935
				setSelection((IJavaElement) treeSelection.getFirstElement());
936
			}
937
		}
938
	}
726
939
940
	/**
941
	 * @return the selected {@link IJavaElement} in the current editor if it is a {@link CompilationUnitEditor}, null otherwise.
942
	 * @param editor the editor
943
	 */
944
	private IJavaElement getSelectedJavaElementInEditor(final IEditorPart editor) {
945
		if (editor instanceof JavaEditor) {
946
			final JavaEditor javaEditor= (JavaEditor) editor;
947
			try {
948
				final IJavaElement inputJavaElement= JavaUI.getEditorInputJavaElement(editor.getEditorInput());
949
				// when the editor is opened on a .class file, not a .java source file
950
				if (inputJavaElement.getElementType() == IJavaElement.CLASS_FILE) {
951
					final IClassFile classFile= (IClassFile) inputJavaElement;
952
					return classFile.getType();
953
				}
954
				final ITextSelection selection= (ITextSelection) javaEditor.getSelectionProvider().getSelection();
955
				final ICompilationUnit compilationUnit= (ICompilationUnit)inputJavaElement.getAncestor(IJavaElement.COMPILATION_UNIT);
956
				final IJavaElement selectedElement= compilationUnit.getElementAt(selection.getOffset());
957
				return selectedElement;
958
			} catch (JavaModelException e) {
959
				JUnitPlugin.log(e);
960
			}
961
		}
962
		return null;
963
	}
964
965
	/**
966
	 * Handles the case when a {@link TestCaseElement} has been selected, unless there's a
967
	 * {@link TestRunSession} in progress.
968
	 * 
969
	 * @param testElement the new selected {@link TestCaseElement}
970
	 */
971
	private void handleTestElementSelected(final ITestElement testElement) {
972
		if (fTestRunnerPart.getCurrentProgressState().equals(ProgressState.RUNNING)) {
973
			return;
974
		}
975
		if (testElement instanceof TestCaseElement) {
976
			final IMethod selectedMethod= ((TestCaseElement)testElement).getJavaMethod();
977
			handleJavaElementSelected(selectedMethod);
978
		} else if (testElement instanceof TestSuiteElement) {
979
			final IJavaElement selectedElement= ((TestSuiteElement)testElement).getJavaElement();
980
			handleJavaElementSelected(selectedElement);
981
		}
982
	}
983
984
	/**
985
	 * Reveals the given {@link IJavaElement} in its associated Editor if this later is already
986
	 * open, and sets the "Link with Editor" button state accordingly.
987
	 * 
988
	 * @param selectedJavaElement the selected {@link IJavaElement} in the {@link TestViewer} that
989
	 *            should be revealed in its Java Editor.
990
	 */
991
	private void handleJavaElementSelected(final IJavaElement selectedJavaElement) {
992
		// skip if there's no editor open (yet)
993
		if (fTestRunnerPart.getSite().getPage().getActiveEditor() == null) {
994
			return;
995
		}
996
		try {
997
			final IEditorPart editor= EditorUtility.isOpenInEditor(selectedJavaElement);
998
			if (selectedJavaElement != null && editor != null && editor instanceof JavaEditor) {
999
				final JavaEditor javaEditor= (JavaEditor)editor;
1000
				final ITextSelection javaEditorSelection= (ITextSelection)javaEditor.getSelectionProvider().getSelection();
1001
				final IEditorPart selectedMethodEditor= EditorUtility.isOpenInEditor(selectedJavaElement);
1002
				// checks if the editor is already open or not
1003
				if (selectedMethodEditor != null) {
1004
					// Retrieve the current active editor
1005
					final IEditorPart activeEditor= fTestRunnerPart.getSite().getPage().getActiveEditor();
1006
					// open the required editor if it is not the active one
1007
					if (!selectedMethodEditor.equals(activeEditor)) {
1008
						EditorUtility.openInEditor(selectedJavaElement, false);
1009
					}
1010
					// retrieve the current java element (unless the associated compilation unit cannot be retrieved)
1011
					final ICompilationUnit compilationUnit= (ICompilationUnit)selectedJavaElement.getAncestor(IJavaElement.COMPILATION_UNIT);
1012
					fTestRunnerPart.setLinkingWithEditorInSync(true);
1013
					if (compilationUnit != null) {
1014
						final IJavaElement javaEditorSelectedElement= compilationUnit.getElementAt(javaEditorSelection.getOffset());
1015
						// force to reveal the selected element in case where the editor was not active
1016
						if (!selectedMethodEditor.equals(activeEditor) || !selectedJavaElement.equals(javaEditorSelectedElement)) {
1017
							EditorUtility.revealInEditor(selectedMethodEditor, selectedJavaElement);
1018
						}
1019
					}
1020
					return;
1021
				}
1022
			}
1023
		} catch (JavaModelException e) {
1024
			JUnitPlugin.log(e);
1025
		} catch (PartInitException e) {
1026
			// occurs if the editor could not be opened or the input element is not valid Status code
1027
			JUnitPlugin.log(e);
1028
		}
1029
		fTestRunnerPart.setLinkingWithEditorInSync(false);
1030
	}
1031
1032
}
(-)a/org.eclipse.jdt.junit/src/org/eclipse/jdt/junit/launcher/JUnitLaunchConfigurationTab.java (-2 / +2 lines)
Lines 697-703 Link Here
697
			String superclassName= type.getSuperclassName();
697
			String superclassName= type.getSuperclassName();
698
			if (superclassName != null) {
698
			if (superclassName != null) {
699
				int pos= superclassName.indexOf('<');
699
				int pos= superclassName.indexOf('<');
700
				if (pos != -1) 
700
				if (pos != -1)
701
					superclassName= superclassName.substring(0, pos);
701
					superclassName= superclassName.substring(0, pos);
702
				String[][] resolvedSupertype= type.resolveType(superclassName);
702
				String[][] resolvedSupertype= type.resolveType(superclassName);
703
				if (resolvedSupertype != null && resolvedSupertype.length > 0) {
703
				if (resolvedSupertype != null && resolvedSupertype.length > 0) {
Lines 1123-1129 Link Here
1123
			IEditorPart part = page.getActiveEditor();
1123
			IEditorPart part = page.getActiveEditor();
1124
			if (part != null) {
1124
			if (part != null) {
1125
				IEditorInput input = part.getEditorInput();
1125
				IEditorInput input = part.getEditorInput();
1126
				return input.getAdapter(IJavaElement.class);
1126
				return (IJavaElement) input.getAdapter(IJavaElement.class);
1127
			}
1127
			}
1128
		}
1128
		}
1129
		return null;
1129
		return null;
(-)a/org.eclipse.jdt.ui/.gitignore (+1 lines)
Line 1 Link Here
1
/bin-jar-in-jar-loader/
1
/bin-jar-in-jar-loader/
2
/bin/

Return to bug 372588