1 13 package org.eclipse.jdt.internal.junit.ui; 14 15 import org.eclipse.core.runtime.CoreException; 16 17 import org.eclipse.jface.text.BadLocationException; 18 import org.eclipse.jface.text.IDocument; 19 20 import org.eclipse.ui.PlatformUI; 21 import org.eclipse.ui.texteditor.ITextEditor; 22 23 import org.eclipse.jdt.core.IJavaElement; 24 import org.eclipse.jdt.core.IJavaProject; 25 26 29 public class OpenEditorAtLineAction extends OpenEditorAction { 30 31 private int fLineNumber; 32 33 public OpenEditorAtLineAction(TestRunnerViewPart testRunner, String cuName, String className, int line) { 34 super(testRunner, className); 35 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IJUnitHelpContextIds.OPENEDITORATLINE_ACTION); 36 fLineNumber= line; 37 } 38 39 protected void reveal(ITextEditor textEditor) { 40 if (fLineNumber >= 0) { 41 try { 42 IDocument document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput()); 43 textEditor.selectAndReveal(document.getLineOffset(fLineNumber-1), document.getLineLength(fLineNumber-1)); 44 } catch (BadLocationException x) { 45 } 47 } 48 } 49 50 protected IJavaElement findElement(IJavaProject project, String className) throws CoreException { 51 return findType(project, className); 52 } 53 54 } 55 | Popular Tags |