1 11 package org.eclipse.jdt.internal.debug.ui.actions; 12 13 import org.eclipse.jdt.core.IJavaElement; 14 import org.eclipse.jdt.core.IMethod; 15 import org.eclipse.jdt.core.JavaModelException; 16 import org.eclipse.jdt.internal.debug.ui.EvaluationContextManager; 17 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; 18 import org.eclipse.jdt.internal.debug.ui.JavaWordFinder; 19 import org.eclipse.jface.text.IDocument; 20 import org.eclipse.jface.text.IRegion; 21 import org.eclipse.jface.text.ITextViewer; 22 import org.eclipse.jface.text.TextSelection; 23 import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector; 24 import org.eclipse.jface.text.hyperlink.IHyperlink; 25 import org.eclipse.ui.IEditorInput; 26 import org.eclipse.ui.texteditor.ITextEditor; 27 28 33 public class StepIntoSelectionHyperlinkDetector extends AbstractHyperlinkDetector { 34 35 38 class StepIntoSelectionHyperlink implements IHyperlink { 39 40 private IRegion fRegion = null; 41 42 46 public StepIntoSelectionHyperlink(IRegion region) { 47 fRegion = region; 48 } 49 52 public IRegion getHyperlinkRegion() { 53 return fRegion; 54 } 55 58 public String getHyperlinkText() { 59 return null; 60 } 61 64 public String getTypeLabel() { 65 return null; 66 } 67 70 public void open() { 71 StepIntoSelectionActionDelegate delegate = new StepIntoSelectionActionDelegate(); 72 delegate.init(JDIDebugUIPlugin.getActiveWorkbenchWindow()); 73 delegate.run(null); 74 } 75 76 } 77 78 81 public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { 82 ITextEditor editor = (ITextEditor) getAdapter(ITextEditor.class); 83 if(editor != null && !canShowMultipleHyperlinks && EvaluationContextManager.getEvaluationContext(JDIDebugUIPlugin.getActiveWorkbenchWindow()) != null) { 84 IEditorInput input = editor.getEditorInput(); 85 IJavaElement element = StepIntoSelectionUtils.getJavaElement(input); 86 int offset = region.getOffset(); 87 if(element != null) { 88 try { 89 IDocument document = editor.getDocumentProvider().getDocument(editor.getEditorInput()); 90 if(document != null) { 91 IRegion wregion = JavaWordFinder.findWord(document, offset); 92 if(wregion != null) { 93 IMethod method = StepIntoSelectionUtils.getMethod(new TextSelection(document, wregion.getOffset(), wregion.getLength()), element); 94 if (method != null) { 95 return new IHyperlink[] {new StepIntoSelectionHyperlink(wregion)}; 96 } 97 } 98 } 99 } 100 catch(JavaModelException jme) {JDIDebugUIPlugin.log(jme);} 101 } 102 } 103 return null; 104 } 105 } 106 | Popular Tags |