Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 237974 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.xml (+9 lines)
Lines 23-27 Link Here
23
	        menubarPath="org.eclipse.jdt.junit.ResultView"/>
23
	        menubarPath="org.eclipse.jdt.junit.ResultView"/>
24
      </viewerContribution>
24
      </viewerContribution>
25
   </extension>
25
   </extension>
26
   <extension
27
         point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors">
28
      <hyperlinkDetector
29
            class="org.eclipse.mylyn.internal.java.tasks.JavaClassHyperlinkDetector"
30
            id="org.eclipse.mylyn.java.hyperlink.detector.java"
31
            name="Java Class "
32
            targetId="org.eclipse.ui.DefaultTextEditor">
33
      </hyperlinkDetector>
34
   </extension>
26
   
35
   
27
</plugin>
36
</plugin>
(-)src/org/eclipse/mylyn/internal/java/tasks/JavaClassHyperlinkDetector.java (+74 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers 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
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.java.tasks;
10
11
import java.util.ArrayList;
12
import java.util.List;
13
import java.util.regex.Matcher;
14
import java.util.regex.Pattern;
15
16
import org.eclipse.jface.text.BadLocationException;
17
import org.eclipse.jface.text.IDocument;
18
import org.eclipse.jface.text.IRegion;
19
import org.eclipse.jface.text.ITextViewer;
20
import org.eclipse.jface.text.Region;
21
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
22
import org.eclipse.jface.text.hyperlink.IHyperlink;
23
24
/**
25
 * Java Class Hyperlink Dectector, e.g. detecting org.eclipse.mylyn.internal.java.tasks.JavaClassHyperlinkDetector
26
 * 
27
 * @author Jingwen Ou
28
 */
29
public class JavaClassHyperlinkDetector extends AbstractHyperlinkDetector {
30
31
	private static final Pattern javaClassPattern = Pattern.compile("(\\w+\\.)+\\w+", Pattern.CASE_INSENSITIVE);
32
33
	public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
34
		List<IHyperlink> hyperLinks = new ArrayList<IHyperlink>();
35
36
		try {
37
			IDocument document = textViewer.getDocument();
38
			if (document == null) {
39
				return null;
40
			}
41
			int offset = region.getOffset();
42
43
			IRegion lineInfo = document.getLineInformationOfOffset(offset);
44
			String line = document.get(lineInfo.getOffset(), lineInfo.getLength());
45
46
			Matcher m = javaClassPattern.matcher(line);
47
48
			while (m.find()) {
49
				// check if its a URL hyperlink
50
				if (lineInfo.getOffset() + m.start() - 1 >= 0
51
						&& document.get(lineInfo.getOffset() + m.start() - 1, 1).equalsIgnoreCase("/")) {
52
					continue;
53
				}
54
55
				IRegion urlRegion = new Region(lineInfo.getOffset() + m.start(), m.end() - m.start());
56
				hyperLinks.add(new JavaClassFileHyperlink(urlRegion, m.group()));
57
			}
58
59
		} catch (BadLocationException e) {
60
			return null;
61
		}
62
63
		return hyperLinks.size() > 0 ? hyperLinks.toArray(new IHyperlink[hyperLinks.size()]) : null;
64
	}
65
66
	public static void main(String str[]) {
67
		Pattern javaClassPattern = Pattern.compile("\\s(\\w+\\.)+\\w+", Pattern.CASE_INSENSITIVE);
68
		Matcher m = javaClassPattern.matcher(" http:// www.eclipse// \n ww.dd ff.");
69
		while (m.find()) {
70
			System.out.println(m.group());
71
		}
72
	}
73
74
}
(-)src/org/eclipse/mylyn/internal/java/tasks/JavaClassFileHyperlink.java (+25 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 Mylyn project committers 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
7
 *******************************************************************************/
8
9
package org.eclipse.mylyn.internal.java.tasks;
10
11
import org.eclipse.jface.text.IRegion;
12
13
public class JavaClassFileHyperlink extends JavaStackTraceFileHyperlink {
14
	private final String traceLine;
15
16
	public JavaClassFileHyperlink(IRegion region, String traceLine) {
17
		super(region, traceLine);
18
		this.traceLine = traceLine;
19
	}
20
21
	@Override
22
	public void open() {
23
		startSourceSearch(traceLine, 0);
24
	}
25
}

Return to bug 237974