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 |