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

Collapse All | Expand All

(-)ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.java (+2 lines)
Lines 68-73 Link Here
68
	public static String OpenAction_multistatus_message;
68
	public static String OpenAction_multistatus_message;
69
	public static String OpenViewActionGroup_showInAction_label;
69
	public static String OpenViewActionGroup_showInAction_label;
70
	public static String OpenWithMenu_label;
70
	public static String OpenWithMenu_label;
71
	public static String OpenAction_error_text;
72
	public static String OpenAction_error_no_label_found_message;
71
73
72
	public static String RefactorMenu_label;
74
	public static String RefactorMenu_label;
73
	public static String SourceMenu_label;
75
	public static String SourceMenu_label;
(-)ui/org/eclipse/jdt/internal/ui/actions/ActionMessages.properties (+2 lines)
Lines 38-43 Link Here
38
OpenAction_multistatus_message=See details for editors that could not be opened.
38
OpenAction_multistatus_message=See details for editors that could not be opened.
39
OpenAction_error_messageBadSelection=Current text selection cannot be opened in an editor
39
OpenAction_error_messageBadSelection=Current text selection cannot be opened in an editor
40
OpenAction_error_problem_opening_editor=Problem opening editor for ''{0}'': ''{1}''
40
OpenAction_error_problem_opening_editor=Problem opening editor for ''{0}'': ''{1}''
41
OpenAction_error_text=Open Declaration
42
OpenAction_error_no_label_found_message=Could not find the target for label: ''{0}'' 
41
43
42
OpenSuperImplementationAction_label=Open S&uper Implementation
44
OpenSuperImplementationAction_label=Open S&uper Implementation
43
OpenSuperImplementationAction_tooltip=Open the Implementation in the Super Type
45
OpenSuperImplementationAction_tooltip=Open the Implementation in the Super Type
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlink.java (-5 / +8 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 15-20 Link Here
15
import org.eclipse.jface.viewers.StructuredSelection;
15
import org.eclipse.jface.viewers.StructuredSelection;
16
16
17
import org.eclipse.jface.text.IRegion;
17
import org.eclipse.jface.text.IRegion;
18
import org.eclipse.jface.text.TextSelection;
18
import org.eclipse.jface.text.hyperlink.IHyperlink;
19
import org.eclipse.jface.text.hyperlink.IHyperlink;
19
20
20
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IJavaElement;
Lines 43-56 Link Here
43
	 * 
44
	 * 
44
	 * @param region the region of the link
45
	 * @param region the region of the link
45
	 * @param openAction the action to use to open the java elements
46
	 * @param openAction the action to use to open the java elements
46
	 * @param element the java element to open
47
	 * @param element the java element to open or <code>null</code> if the element is a label
47
	 * @param qualify <code>true</code> if the hyperlink text should show a qualified name for
48
	 * @param qualify <code>true</code> if the hyperlink text should show a qualified name for
48
	 *            element.
49
	 *            element.
49
	 */
50
	 */
50
	public JavaElementHyperlink(IRegion region, SelectionDispatchAction openAction, IJavaElement element, boolean qualify) {
51
	public JavaElementHyperlink(IRegion region, SelectionDispatchAction openAction, IJavaElement element, boolean qualify) {
51
		Assert.isNotNull(openAction);
52
		Assert.isNotNull(openAction);
52
		Assert.isNotNull(region);
53
		Assert.isNotNull(region);
53
		Assert.isNotNull(element);
54
54
55
		fRegion= region;
55
		fRegion= region;
56
		fOpenAction= openAction;
56
		fOpenAction= openAction;
Lines 71-77 Link Here
71
	 * @since 3.1
71
	 * @since 3.1
72
	 */
72
	 */
73
	public void open() {
73
	public void open() {
74
		fOpenAction.run(new StructuredSelection(fElement));
74
		if (fElement != null)
75
			fOpenAction.run(new StructuredSelection(fElement));
76
		else
77
			fOpenAction.run(new TextSelection(fRegion.getOffset(), fRegion.getLength()));
75
	}
78
	}
76
79
77
	/*
80
	/*
Lines 87-93 Link Here
87
	 * @since 3.1
90
	 * @since 3.1
88
	 */
91
	 */
89
	public String getHyperlinkText() {
92
	public String getHyperlinkText() {
90
		if (fQualify) {
93
		if (fQualify && fElement != null) {
91
			String elementLabel= JavaElementLabels.getElementLabel(fElement, JavaElementLabels.ALL_POST_QUALIFIED);
94
			String elementLabel= JavaElementLabels.getElementLabel(fElement, JavaElementLabels.ALL_POST_QUALIFIED);
92
			return Messages.format(JavaEditorMessages.JavaElementHyperlink_hyperlinkText_qualified, new Object[] { elementLabel });
95
			return Messages.format(JavaEditorMessages.JavaElementHyperlink_hyperlinkText_qualified, new Object[] { elementLabel });
93
		} else {
96
		} else {
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkDeclaredTypeDetector.java (-1 / +1 lines)
Lines 38-44 Link Here
38
	 */
38
	 */
39
	protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
39
	protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
40
		try {
40
		try {
41
			if ((element.getElementType() == IJavaElement.FIELD || element.getElementType() == IJavaElement.LOCAL_VARIABLE) && !JavaModelUtil.isPrimitive(getTypeSignature(element))
41
			if (element != null && (element.getElementType() == IJavaElement.FIELD || element.getElementType() == IJavaElement.LOCAL_VARIABLE) && !JavaModelUtil.isPrimitive(getTypeSignature(element))
42
					&& SelectionConverter.canOperateOn(editor)) {
42
					&& SelectionConverter.canOperateOn(editor)) {
43
				return new JavaElementDeclaredTypeHyperlink(wordRegion, openAction, element, qualify);
43
				return new JavaElementDeclaredTypeHyperlink(wordRegion, openAction, element, qualify);
44
			}
44
			}
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkDetector.java (-3 / +39 lines)
Lines 26-33 Link Here
26
26
27
import org.eclipse.jdt.core.ICodeAssist;
27
import org.eclipse.jdt.core.ICodeAssist;
28
import org.eclipse.jdt.core.IJavaElement;
28
import org.eclipse.jdt.core.IJavaElement;
29
import org.eclipse.jdt.core.ITypeRoot;
29
import org.eclipse.jdt.core.JavaModelException;
30
import org.eclipse.jdt.core.JavaModelException;
31
import org.eclipse.jdt.core.dom.ASTNode;
32
import org.eclipse.jdt.core.dom.BreakStatement;
33
import org.eclipse.jdt.core.dom.CompilationUnit;
34
import org.eclipse.jdt.core.dom.ContinueStatement;
35
import org.eclipse.jdt.core.dom.NodeFinder;
36
import org.eclipse.jdt.core.dom.SimpleName;
30
37
38
import org.eclipse.jdt.ui.SharedASTProvider;
31
import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
39
import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
32
40
33
import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
41
import org.eclipse.jdt.internal.ui.text.JavaWordFinder;
Lines 67-74 Link Here
67
			if (isInheritDoc(document, wordRegion) && getClass() != JavaElementHyperlinkDetector.class)
75
			if (isInheritDoc(document, wordRegion) && getClass() != JavaElementHyperlinkDetector.class)
68
				return null;
76
				return null;
69
			
77
			
70
			IJavaElement[] elements= null;
78
			ASTNode labelNode= getBreakOrContinueLabelNode(input, region);
71
			elements= ((ICodeAssist) input).codeSelect(wordRegion.getOffset(), wordRegion.getLength());
79
			if (labelNode != null) {
80
				IHyperlink link= createHyperlink(wordRegion, (SelectionDispatchAction)openAction, null, false, null);
81
				return link != null ? new IHyperlink[] { link } : null;
82
			}
83
84
			IJavaElement[] elements= ((ICodeAssist) input).codeSelect(wordRegion.getOffset(), wordRegion.getLength());
72
			elements= selectOpenableElements(elements);
85
			elements= selectOpenableElements(elements);
73
			if (elements.length == 0)
86
			if (elements.length == 0)
74
				return null;
87
				return null;
Lines 117-123 Link Here
117
	 * 
130
	 * 
118
	 * @param wordRegion the region of the link
131
	 * @param wordRegion the region of the link
119
	 * @param openAction the action to use to open the java elements
132
	 * @param openAction the action to use to open the java elements
120
	 * @param element the java element to open
133
	 * @param element the java element to open or <code>null</code> if its a label
121
	 * @param qualify <code>true</code> if the hyperlink text should show a qualified name for
134
	 * @param qualify <code>true</code> if the hyperlink text should show a qualified name for
122
	 *            element
135
	 *            element
123
	 * @param editor the active java editor
136
	 * @param editor the active java editor
Lines 155-158 Link Here
155
		}
168
		}
156
		return (IJavaElement[]) result.toArray(new IJavaElement[result.size()]);
169
		return (IJavaElement[]) result.toArray(new IJavaElement[result.size()]);
157
	}
170
	}
171
172
	/**
173
	 * Gets the break/continue label node.
174
	 * 
175
	 * @param input the editor input
176
	 * @param region the region
177
	 * @return the break/continue label or <code>null</code> if none
178
	 * @since 3.7
179
	 */
180
	public static ASTNode getBreakOrContinueLabelNode(IJavaElement input, IRegion region) {
181
		CompilationUnit ast= SharedASTProvider.getAST((ITypeRoot)input, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
182
		if (ast == null)
183
			return null;
184
185
		ASTNode node= NodeFinder.perform(ast, region.getOffset(), region.getLength());
186
		if (node instanceof SimpleName) {
187
			SimpleName simpleName= (SimpleName)node;
188
			ASTNode parent= simpleName.getParent();
189
			if (parent instanceof ContinueStatement || parent instanceof BreakStatement)
190
				return simpleName;
191
		}
192
		return null;
193
	}
158
}
194
}
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkImplementationDetector.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
2
 * Copyright (c) 2010, 2011 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 33-39 Link Here
33
	 * @since 3.5
33
	 * @since 3.5
34
	 */
34
	 */
35
	protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
35
	protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
36
		if (element.getElementType() == IJavaElement.METHOD && SelectionConverter.canOperateOn(editor)) {
36
		if (element != null && element.getElementType() == IJavaElement.METHOD && SelectionConverter.canOperateOn(editor)) {
37
			return new JavaElementImplementationHyperlink(wordRegion, openAction, (IMethod)element, qualify, editor);
37
			return new JavaElementImplementationHyperlink(wordRegion, openAction, (IMethod)element, qualify, editor);
38
		}
38
		}
39
		return null;
39
		return null;
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkReturnTypeDetector.java (-1 / +1 lines)
Lines 37-43 Link Here
37
	 */
37
	 */
38
	protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
38
	protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
39
		try {
39
		try {
40
			if (element.getElementType() == IJavaElement.METHOD && !JavaModelUtil.isPrimitive(((IMethod)element).getReturnType()) && SelectionConverter.canOperateOn(editor)) {
40
			if (element != null && element.getElementType() == IJavaElement.METHOD && !JavaModelUtil.isPrimitive(((IMethod)element).getReturnType()) && SelectionConverter.canOperateOn(editor)) {
41
				return new JavaElementReturnTypeHyperlink(wordRegion, openAction, (IMethod)element, qualify);
41
				return new JavaElementReturnTypeHyperlink(wordRegion, openAction, (IMethod)element, qualify);
42
			}
42
			}
43
		} catch (JavaModelException e) {
43
		} catch (JavaModelException e) {
(-)ui/org/eclipse/jdt/internal/ui/javaeditor/JavaElementHyperlinkSuperImplementationDetector.java (-2 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2010 IBM Corporation and others.
2
 * Copyright (c) 2010, 2011 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 35-41 Link Here
35
	 * @since 3.7
35
	 * @since 3.7
36
	 */
36
	 */
37
	protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
37
	protected IHyperlink createHyperlink(IRegion wordRegion, SelectionDispatchAction openAction, IJavaElement element, boolean qualify, JavaEditor editor) {
38
		if (element.getElementType() == IJavaElement.METHOD && SelectionConverter.canOperateOn(editor) && isOverriddenMethod((IMethod)element)) {
38
		if (element != null && element.getElementType() == IJavaElement.METHOD && SelectionConverter.canOperateOn(editor) && isOverriddenMethod((IMethod)element)) {
39
			return new JavaElementSuperImplementationHyperlink(wordRegion, openAction, (IMethod)element, qualify);
39
			return new JavaElementSuperImplementationHyperlink(wordRegion, openAction, (IMethod)element, qualify);
40
		}
40
		}
41
		return null;
41
		return null;
(-)ui/org/eclipse/jdt/ui/actions/OpenAction.java (-1 / +51 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2010 IBM Corporation and others.
2
 * Copyright (c) 2000, 2011 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 15-20 Link Here
15
import java.util.Iterator;
15
import java.util.Iterator;
16
import java.util.List;
16
import java.util.List;
17
17
18
import org.eclipse.core.runtime.Assert;
18
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.CoreException;
19
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.IStatus;
20
import org.eclipse.core.runtime.MultiStatus;
21
import org.eclipse.core.runtime.MultiStatus;
Lines 23-32 Link Here
23
import org.eclipse.core.resources.IFile;
24
import org.eclipse.core.resources.IFile;
24
25
25
import org.eclipse.jface.dialogs.ErrorDialog;
26
import org.eclipse.jface.dialogs.ErrorDialog;
27
import org.eclipse.jface.dialogs.MessageDialog;
26
import org.eclipse.jface.util.OpenStrategy;
28
import org.eclipse.jface.util.OpenStrategy;
27
import org.eclipse.jface.viewers.IStructuredSelection;
29
import org.eclipse.jface.viewers.IStructuredSelection;
28
30
31
import org.eclipse.jface.text.IRegion;
29
import org.eclipse.jface.text.ITextSelection;
32
import org.eclipse.jface.text.ITextSelection;
33
import org.eclipse.jface.text.ITextViewer;
34
import org.eclipse.jface.text.Region;
35
import org.eclipse.jface.text.source.ISourceViewer;
30
36
31
import org.eclipse.ui.IEditorPart;
37
import org.eclipse.ui.IEditorPart;
32
import org.eclipse.ui.IWorkbenchSite;
38
import org.eclipse.ui.IWorkbenchSite;
Lines 37-49 Link Here
37
43
38
import org.eclipse.jdt.core.IJavaElement;
44
import org.eclipse.jdt.core.IJavaElement;
39
import org.eclipse.jdt.core.ISourceReference;
45
import org.eclipse.jdt.core.ISourceReference;
46
import org.eclipse.jdt.core.ITypeRoot;
40
import org.eclipse.jdt.core.JavaModelException;
47
import org.eclipse.jdt.core.JavaModelException;
48
import org.eclipse.jdt.core.dom.ASTNode;
49
import org.eclipse.jdt.core.dom.CompilationUnit;
41
50
42
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
51
import org.eclipse.jdt.internal.corext.util.JavaModelUtil;
43
import org.eclipse.jdt.internal.corext.util.Messages;
52
import org.eclipse.jdt.internal.corext.util.Messages;
44
53
45
import org.eclipse.jdt.ui.JavaElementLabels;
54
import org.eclipse.jdt.ui.JavaElementLabels;
46
import org.eclipse.jdt.ui.JavaUI;
55
import org.eclipse.jdt.ui.JavaUI;
56
import org.eclipse.jdt.ui.SharedASTProvider;
47
57
48
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
58
import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
49
import org.eclipse.jdt.internal.ui.JavaPlugin;
59
import org.eclipse.jdt.internal.ui.JavaPlugin;
Lines 52-57 Link Here
52
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
62
import org.eclipse.jdt.internal.ui.actions.SelectionConverter;
53
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
63
import org.eclipse.jdt.internal.ui.javaeditor.EditorUtility;
54
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
64
import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
65
import org.eclipse.jdt.internal.ui.javaeditor.JavaElementHyperlinkDetector;
66
import org.eclipse.jdt.internal.ui.search.BreakContinueTargetFinder;
67
import org.eclipse.jdt.internal.ui.search.IOccurrencesFinder.OccurrenceLocation;
55
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
68
import org.eclipse.jdt.internal.ui.util.ExceptionHandler;
56
69
57
70
Lines 135-140 Link Here
135
	 * Method declared on SelectionDispatchAction.
148
	 * Method declared on SelectionDispatchAction.
136
	 */
149
	 */
137
	public void run(ITextSelection selection) {
150
	public void run(ITextSelection selection) {
151
		IJavaElement input= EditorUtility.getEditorInputJavaElement(fEditor, false);
152
		if (input == null)
153
			return;
154
		IRegion region= new Region(selection.getOffset(), selection.getLength());
155
		ASTNode labelNode= JavaElementHyperlinkDetector.getBreakOrContinueLabelNode(input, region);
156
		ISourceViewer viewer= fEditor.getViewer();
157
		if (labelNode != null && viewer != null) {
158
			jumpToLabel(viewer, labelNode, (ITypeRoot)input);
159
			return;
160
		}
138
		try {
161
		try {
139
			IJavaElement[] elements= SelectionConverter.codeResolveForked(fEditor, false);
162
			IJavaElement[] elements= SelectionConverter.codeResolveForked(fEditor, false);
140
			elements= selectOpenableElements(elements);
163
			elements= selectOpenableElements(elements);
Lines 164-169 Link Here
164
	}
187
	}
165
188
166
	/**
189
	/**
190
	 * Jumps to the label of the break/continue statement.
191
	 * 
192
	 * @param viewer the text viewer
193
	 * @param labelNode the label node
194
	 * @param input the editor input
195
	 * @since 3.7
196
	 */
197
	private void jumpToLabel(ITextViewer viewer, ASTNode labelNode, ITypeRoot input) {
198
		Assert.isNotNull(input);
199
		CompilationUnit ast= SharedASTProvider.getAST(input, SharedASTProvider.WAIT_ACTIVE_ONLY, null);
200
		if (ast == null)
201
			return;
202
		BreakContinueTargetFinder finder= new BreakContinueTargetFinder();
203
		if (finder.initialize(ast, labelNode) == null) {
204
			OccurrenceLocation[] locations= finder.getOccurrences();
205
			if (locations != null) {
206
				OccurrenceLocation location= locations[0]; // the first location is the labeled statement target location
207
				viewer.setSelectedRange(location.getOffset(), location.getLength());
208
				return;
209
			}
210
		}
211
		MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
212
				ActionMessages.OpenAction_error_text,
213
				Messages.format(ActionMessages.OpenAction_error_no_label_found_message, labelNode.toString()));
214
	}
215
216
	/**
167
	 * Selects the openable elements out of the given ones.
217
	 * Selects the openable elements out of the given ones.
168
	 *
218
	 *
169
	 * @param elements the elements to filter
219
	 * @param elements the elements to filter

Return to bug 269112