Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsminto2005-07-22 16:21:16 +0000
committersminto2005-07-22 16:21:16 +0000
commitc45a08e78fecf52a8896fd71db77fbad0c2a7932 (patch)
tree6155dadf1a518add4eb9a11ab1d21551fe764b01 /org.eclipse.mylyn.tasks.core
parent515663b06c889aba73603d05a99005159447b433 (diff)
downloadorg.eclipse.mylyn.tasks-c45a08e78fecf52a8896fd71db77fbad0c2a7932.tar.gz
org.eclipse.mylyn.tasks-c45a08e78fecf52a8896fd71db77fbad0c2a7932.tar.xz
org.eclipse.mylyn.tasks-c45a08e78fecf52a8896fd71db77fbad0c2a7932.zip
fixed Bug #103866: Crtl-click in the code to navigate to bug
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
-rw-r--r--org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF8
-rw-r--r--org.eclipse.mylyn.tasks.core/plugin.xml4
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/java/BugzillaHyperLink.java42
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/java/BugzillaHyperLinkDetector.java154
4 files changed, 207 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
index 95ce39445..09f208b0d 100644
--- a/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.core/META-INF/MANIFEST.MF
@@ -14,7 +14,13 @@ Require-Bundle: org.eclipse.ui,
org.eclipse.jdt.core,
org.eclipse.ui.ide,
org.eclipse.core.resources,
- org.eclipse.mylar.tasklist
+ org.eclipse.mylar.tasklist,
+ org.eclipse.mylar.java,
+ org.eclipse.ui.workbench.texteditor,
+ org.eclipse.ui.editors,
+ org.eclipse.jface.text,
+ org.eclipse.jdt,
+ org.eclipse.jdt.ui
Eclipse-AutoStart: true
Export-Package: org.eclipse.mylar.bugs,
org.eclipse.mylar.bugs.search
diff --git a/org.eclipse.mylyn.tasks.core/plugin.xml b/org.eclipse.mylyn.tasks.core/plugin.xml
index e593c5e63..115a2aa0c 100644
--- a/org.eclipse.mylyn.tasks.core/plugin.xml
+++ b/org.eclipse.mylyn.tasks.core/plugin.xml
@@ -5,5 +5,9 @@
<extension
name="Mylar Bugzilla startup"
point="org.eclipse.ui.startup">
+ </extension>
+ <extension
+ point="org.eclipse.mylar.java.javaEditorContributor">
+ <hyperlinkDetector class="org.eclipse.mylar.bugs.java.BugzillaHyperLinkDetector"/>
</extension>
</plugin>
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/java/BugzillaHyperLink.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/java/BugzillaHyperLink.java
new file mode 100644
index 000000000..30ac1f90c
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/java/BugzillaHyperLink.java
@@ -0,0 +1,42 @@
+package org.eclipse.mylar.bugs.java;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylar.bugzilla.core.BugzillaPlugin;
+import org.eclipse.mylar.bugzilla.ui.BugzillaOpenStructure;
+import org.eclipse.mylar.bugzilla.ui.ViewBugzillaAction;
+
+public class BugzillaHyperLink implements IHyperlink {
+
+ private IRegion region;
+
+ private int id;
+
+ public BugzillaHyperLink(IRegion nlsKeyRegion, int id) {
+ this.region = nlsKeyRegion;
+ this.id = id;
+ }
+
+ public IRegion getHyperlinkRegion() {
+ return region;
+ }
+
+ public String getTypeLabel() {
+ return null;
+ }
+
+ public String getHyperlinkText() {
+ return null;
+ }
+
+ public void open() {
+ List<BugzillaOpenStructure> l = new ArrayList<BugzillaOpenStructure>(1);
+ l.add(new BugzillaOpenStructure(BugzillaPlugin.getDefault().getServerName(),id, -1));
+ new ViewBugzillaAction("Open Bug " + id, l).run(new NullProgressMonitor());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/java/BugzillaHyperLinkDetector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/java/BugzillaHyperLinkDetector.java
new file mode 100644
index 000000000..46eb77217
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/bugs/java/BugzillaHyperLinkDetector.java
@@ -0,0 +1,154 @@
+package org.eclipse.mylar.bugs.java;
+
+import java.util.List;
+
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.Comment;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.TextElement;
+import org.eclipse.jdt.internal.corext.dom.NodeFinder;
+import org.eclipse.jdt.internal.ui.JavaPlugin;
+import org.eclipse.jdt.internal.ui.javaeditor.ASTProvider;
+import org.eclipse.jdt.internal.ui.javaeditor.CompilationUnitEditor;
+import org.eclipse.jdt.internal.ui.javaeditor.IClassFileEditorInput;
+import org.eclipse.jdt.internal.ui.javaeditor.JavaEditor;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.hyperlink.IHyperlink;
+import org.eclipse.mylar.core.MylarPlugin;
+import org.eclipse.mylar.java.ui.editor.AbstractMylarHyperlinkDetector;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.texteditor.ITextEditor;
+/**
+ * @author Shawn Minto
+ *
+ */
+public class BugzillaHyperLinkDetector extends AbstractMylarHyperlinkDetector {
+
+
+ public BugzillaHyperLinkDetector() {
+ super();
+ }
+
+ @SuppressWarnings("unchecked")
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
+ ITextEditor textEditor = getEditor();
+ if (region == null || textEditor == null || canShowMultipleHyperlinks || !(textEditor instanceof JavaEditor))
+ return null;
+
+ IEditorSite site= textEditor.getEditorSite();
+ if (site == null)
+ return null;
+
+ IJavaElement javaElement= getInputJavaElement(textEditor);
+ if (javaElement == null)
+ return null;
+
+ CompilationUnit ast= JavaPlugin.getDefault().getASTProvider().getAST(javaElement, ASTProvider.WAIT_NO, null);
+ if (ast == null)
+ return null;
+
+ ASTNode node= NodeFinder.perform(ast, region.getOffset(), 1);
+
+ if (node == null || !(node instanceof TextElement || node instanceof Block))
+ return null;
+
+ String comment = null;
+ int commentStart = -1;
+
+ if(node instanceof TextElement){
+ TextElement element = (TextElement)node;
+ comment = element.getText();
+ commentStart = element.getStartPosition();
+ } else if(node instanceof Block){
+ Comment c = findComment(ast.getCommentList(), region.getOffset(), 1);
+ if(c != null){
+ try{
+ IDocument document= textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
+ String commentString = document.get(c.getStartPosition(), c.getLength());
+ comment = getStringFromComment(c, region.getOffset(), commentString);
+ commentStart = getLocationFromComment(c, comment, commentString) + c.getStartPosition();
+ } catch (BadLocationException e){
+ MylarPlugin.log(e, "Failed to get text for comment");
+ }
+ }
+ }
+
+ if(comment == null)
+ return null;
+
+ int startOffset= region.getOffset();
+ int endOffset= startOffset + region.getLength();
+
+ if(comment.toLowerCase().indexOf("bug") != -1){
+
+ int start = comment.toLowerCase().indexOf("bug");
+ int end = comment.indexOf(" ", start + 4);
+ if(end == -1)
+ end = comment.length();
+
+ int bugId = Integer.parseInt(comment.substring(start+4, end).trim());
+
+ start += commentStart;
+ end += commentStart;
+
+ if(startOffset >= start && endOffset <= end){
+ IRegion sregion= new Region(start, end);
+ return new IHyperlink[] {new BugzillaHyperLink(sregion, bugId)};
+ }
+ }
+ return null;
+ }
+
+ private int getLocationFromComment(Comment c, String commentLine, String commentString) {
+ if(commentLine == null){
+ return -1;
+ } else {
+ return commentString.indexOf(commentLine);
+ }
+ }
+
+ private String getStringFromComment(Comment comment, int desiredOffset, String commentString) {
+ String [] parts = commentString.split("\n");
+ if(parts.length > 1){
+ int offset = comment.getStartPosition();
+ for(String part: parts){
+ int newOffset = offset + part.length() + 1;
+ if(desiredOffset >= offset && desiredOffset <= newOffset){
+ return part;
+ }
+
+ }
+ } else {
+ return commentString;
+ }
+
+ return null;
+ }
+
+ private Comment findComment(List<Comment> commentList, int offset, int i) {
+ for(Comment comment: commentList){
+ if(comment.getStartPosition() <= offset && (comment.getStartPosition() + comment.getLength() >= offset + i)){
+ return comment;
+ }
+ }
+ return null;
+ }
+
+ private IJavaElement getInputJavaElement(ITextEditor editor) {
+ IEditorInput editorInput= editor.getEditorInput();
+ if (editorInput instanceof IClassFileEditorInput)
+ return ((IClassFileEditorInput)editorInput).getClassFile();
+
+ if (editor instanceof CompilationUnitEditor)
+ return JavaPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput);
+
+ return null;
+ }
+}

Back to the top