1 /*******************************************************************************
2 * Copyright (c) 2000, 2010 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.ui.javadocexport;
13 import org.eclipse.core.filesystem.URIUtil;
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.Path;
18 import org.eclipse.core.resources.IFile;
19 import org.eclipse.core.resources.ResourcesPlugin;
21 import org.eclipse.jface.text.BadLocationException;
22 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.text.IRegion;
25 import org.eclipse.ui.IEditorPart;
26 import org.eclipse.ui.PartInitException;
27 import org.eclipse.ui.console.IHyperlink;
29 import org.eclipse.ui.texteditor.ITextEditor;
31 import org.eclipse.debug.ui.console.IConsole;
32 import org.eclipse.debug.ui.console.IConsoleLineTracker;
34 import org.eclipse.jdt.core.IJavaElement;
35 import org.eclipse.jdt.core.JavaCore;
36 import org.eclipse.jdt.core.JavaModelException;
38 import org.eclipse.jdt.ui.JavaUI;
40 import org.eclipse.jdt.internal.ui.JavaPlugin;
43 public class JavadocConsoleLineTracker implements IConsoleLineTracker {
45 private static class JavadocConsoleHyperLink implements IHyperlink {
47 private IPath fExternalPath;
48 private int fLineNumber;
50 public JavadocConsoleHyperLink(IPath externalPath, int lineNumber) {
51 fExternalPath= externalPath;
52 fLineNumber= lineNumber;
56 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkEntered()
58 public void linkEntered() {
62 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkExited()
64 public void linkExited() {
68 * @see org.eclipse.debug.ui.console.IConsoleHyperlink#linkActivated()
70 public void linkActivated() {
72 IFile[] files= ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(URIUtil.toURI(fExternalPath.makeAbsolute()));
73 if (files.length > 0) {
74 for (int i = 0; i < files.length; i++) {
76 IJavaElement element= JavaCore.create(curr);
77 if (element != null && element.exists()) {
78 IEditorPart part= JavaUI.openInEditor(element, true, false);
79 if (part instanceof ITextEditor) {
80 revealLine((ITextEditor) part, fLineNumber);
86 } catch (BadLocationException e) {
88 } catch (PartInitException e) {
90 } catch (JavaModelException e) {
95 private void revealLine(ITextEditor editor, int lineNumber) throws BadLocationException {
96 IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
97 IRegion region= document.getLineInformation(lineNumber - 1);
98 editor.selectAndReveal(region.getOffset(), 0);
104 private IConsole fConsole;
109 public JavadocConsoleLineTracker() {
113 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#init(org.eclipse.debug.ui.console.IConsole)
115 public void init(IConsole console) {
120 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#lineAppended(org.eclipse.jface.text.IRegion)
122 public void lineAppended(IRegion line) {
124 int offset = line.getOffset();
125 int length = line.getLength();
126 String text = fConsole.getDocument().get(offset, length);
128 int index1= text.indexOf(':');
135 int index2= text.indexOf(':', index1 + 1);
136 while ((index2 != -1) && (path == null)) {
137 if (index1 < index2) {
139 String substr= text.substring(index1 + 1, index2);
140 lineNumber= Integer.parseInt(substr);
141 path= Path.fromOSString(text.substring(0, index1));
142 } catch (NumberFormatException e) {
147 index2= text.indexOf(':', index1 + 1);
150 if (lineNumber != -1) {
151 JavadocConsoleHyperLink link= new JavadocConsoleHyperLink(path, lineNumber);
152 fConsole.addLink(link, line.getOffset(), index1);
155 } catch (BadLocationException e) {
163 * @see org.eclipse.debug.ui.console.IConsoleLineTracker#dispose()
165 public void dispose() {