Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 107163 Details for
Bug 240441
[wikitext] specify implementation for Java resource
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
detecting Java resource
clipboard.txt (text/plain), 15.77 KB, created by
Jingwen 'Owen' Ou
on 2008-07-10 23:51:25 EDT
(
hide
)
Description:
detecting Java resource
Filename:
MIME Type:
Creator:
Jingwen 'Owen' Ou
Created:
2008-07-10 23:51:25 EDT
Size:
15.77 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.sandbox.ui >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/sandbox/org.eclipse.mylyn.sandbox.ui/plugin.xml,v >retrieving revision 1.87 >diff -u -r1.87 plugin.xml >--- plugin.xml 4 Jul 2008 18:29:40 -0000 1.87 >+++ plugin.xml 11 Jul 2008 03:50:53 -0000 >@@ -2,7 +2,8 @@ > <?eclipse version="3.0"?> > <plugin> > <extension-point id="taskEditorExtensions" name="Task Editor Extension" schema="schema/taskEditorExtensions.exsd"/> >- >+ <extension-point id="resourceHyperlinkExtensions" name="Resource Hyperlink Extension" schema="schema/resourceHyperlinkExtensions.exsd"/> >+ > <extension point="org.eclipse.ui.views"> > <category name="Experimental" id="org.eclipse.mylyn.sandbox"/> > </extension> >@@ -404,8 +405,40 @@ > </propertyTester> > </extension> > >- >- >+ <extension >+ point="org.eclipse.ui.workbench.texteditor.hyperlinkDetectors"> >+ <hyperlinkDetector >+ class="org.eclipse.mylyn.internal.sandbox.ui.hyperlinks.ResourceHyperlinkDetector" >+ id="org.eclipse.mylyn.sandbox.ui.hyperlinkDetector" >+ name="Resource Hyperlink Detector" >+ targetId="org.eclipse.ui.DefaultTextEditor"> >+ </hyperlinkDetector> >+ </extension> >+ >+ <extension >+ point="org.eclipse.mylyn.sandbox.ui.resourceHyperlinkExtensions"> >+ <resourceHyperlinkExtension >+ class="org.eclipse.mylyn.internal.sandbox.ui.hyperlinks.JavaResourceHyperlinkExtension" >+ fileType="java" >+ generatedPrefix="java class"> >+ </resourceHyperlinkExtension> >+ >+ <!-- >+ <resourceHyperlinkExtension >+ class="org.eclipse.mylyn.internal.sandbox.ui.hyperlinks.CppResourceHyperlinkExtension" >+ >+ fileType="cpp" >+ generatedPrefix="cpp class"> >+ >+ </resourceHyperlinkExtension> >+ <resourceHyperlinkExtension >+ class="org.eclipse.mylyn.internal.sandbox.ui.hyperlinks.UnknownResourceHyperlinkExtension" >+ fileType="unknown" >+ generatedPrefix="file"> >+ </resourceHyperlinkExtension> >+ --> >+ </extension> >+ > <!-- > <extension point="org.eclipse.mylyn.tasks.ui.presentations"> > <presentation >Index: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java >diff -N src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlink.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,126 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2007 Mylyn project committers and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.sandbox.ui.hyperlinks; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IProgressMonitor; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.core.runtime.jobs.Job; >+import org.eclipse.debug.ui.IDebugModelPresentation; >+import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin; >+import org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction; >+import org.eclipse.jface.dialogs.MessageDialog; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.hyperlink.IHyperlink; >+import org.eclipse.ui.IEditorInput; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.progress.UIJob; >+ >+/** >+ * Truncated class of JavaStackTraceFileHyperlink, open a hyperlink using OpenTypeAction >+ * >+ * @author Rob Elves >+ * @author Jingwe Ou >+ */ >+public class JavaResourceHyperlink implements IHyperlink { >+ >+ private final IRegion region; >+ >+ private final String typeName; >+ >+ public JavaResourceHyperlink(IRegion region, String typeName) { >+ this.region = region; >+ this.typeName = typeName; >+ } >+ >+ public IRegion getHyperlinkRegion() { >+ return region; >+ } >+ >+ public String getHyperlinkText() { >+ return "Open " + typeName; >+ } >+ >+ public String getTypeLabel() { >+ return null; >+ } >+ >+ public void open() { >+ startSourceSearch(typeName); >+ } >+ >+ /** >+ * Starts a search for the type with the given name. Reports back to 'searchCompleted(...)'. >+ * >+ * @param typeName >+ * the type to search for >+ */ >+ protected void startSourceSearch(final String typeName) { >+ Job search = new Job("Searching...") { >+ @Override >+ protected IStatus run(IProgressMonitor monitor) { >+ try { >+ // search for the type in the workspace >+ Object result = OpenTypeAction.findTypeInWorkspace(typeName); >+ searchCompleted(result, typeName, null); >+ } catch (CoreException e) { >+ searchCompleted(null, typeName, e.getStatus()); >+ } >+ return Status.OK_STATUS; >+ } >+ >+ }; >+ search.schedule(); >+ } >+ >+ protected void searchCompleted(final Object source, final String typeName, final IStatus status) { >+ UIJob job = new UIJob("link search complete") { //$NON-NLS-1$ >+ @Override >+ public IStatus runInUIThread(IProgressMonitor monitor) { >+ if (source == null) { >+ // did not find source >+ MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), >+ "Open Type", "Type could not be located."); >+ } else { >+ processSearchResult(source, typeName); >+ } >+ return Status.OK_STATUS; >+ } >+ }; >+ job.setSystem(true); >+ job.schedule(); >+ } >+ >+ /** >+ * The search succeeded with the given result >+ * >+ * @param source >+ * resolved source object for the search >+ * @param typeName >+ * type name searched for >+ */ >+ protected void processSearchResult(Object source, String typeName) { >+ IDebugModelPresentation presentation = JDIDebugUIPlugin.getDefault().getModelPresentation(); >+ IEditorInput editorInput = presentation.getEditorInput(source); >+ if (editorInput != null) { >+ String editorId = presentation.getEditorId(editorInput, source); >+ if (editorId != null) { >+ try { >+ PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().openEditor(editorInput, >+ editorId); >+ >+ } catch (CoreException e) { >+ MessageDialog.openInformation(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), >+ "Open Type", "Failed to open type."); >+ } >+ } >+ } >+ } >+} >Index: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlinkExtension.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlinkExtension.java >diff -N src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlinkExtension.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/JavaResourceHyperlinkExtension.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,41 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2007 Mylyn project committers and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.sandbox.ui.hyperlinks; >+ >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.jdt.internal.debug.ui.actions.OpenTypeAction; >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.hyperlink.IHyperlink; >+ >+/** >+ * @author Jingwen Ou >+ */ >+public class JavaResourceHyperlinkExtension extends AbstractResourceHyperlinkExtension { >+ >+ private static final String JAVA_PREFIX = "java\\sclass\\s"; >+ >+ @Override >+ protected String getReourceExpressions() { >+ return JAVA_PREFIX + DEFAULT_QUALIFIED_NAME; >+ } >+ >+ @Override >+ public boolean resourceExists(String resourceName) { >+ try { >+ return OpenTypeAction.findTypeInWorkspace(resourceName) != null; >+ } catch (CoreException e) { >+ return false; >+ } >+ } >+ >+ @Override >+ protected IHyperlink getHyperlink(IRegion region, String resourceName) { >+ return new JavaResourceHyperlink(region, resourceName); >+ } >+} >Index: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/AbstractResourceHyperlinkExtension.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/AbstractResourceHyperlinkExtension.java >diff -N src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/AbstractResourceHyperlinkExtension.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/AbstractResourceHyperlinkExtension.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,107 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2007 Mylyn project committers and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.sandbox.ui.hyperlinks; >+ >+import java.util.ArrayList; >+import java.util.regex.Matcher; >+import java.util.regex.Pattern; >+ >+import org.eclipse.jface.text.IRegion; >+import org.eclipse.jface.text.Region; >+import org.eclipse.jface.text.hyperlink.IHyperlink; >+ >+/** >+ * IResourceHyperlinkExtension with various helper methods >+ * >+ * @author Jingwen Ou >+ */ >+public abstract class AbstractResourceHyperlinkExtension implements IResourceHyperlinkExtension { >+ >+ protected static final String DEFAULT_QUALIFIED_NAME = "((\\w(\\w|\\.)*\\w)|\\w)"; >+ >+ /** >+ * detailed work done to extract a hyperlink >+ */ >+ protected IHyperlink extractHyperlink(int regionOffset, Matcher m) { >+ int start = -1; >+ >+ start = m.start(); >+ >+ int end = m.end(); >+ >+ if (end == -1) { >+ end = m.group().length(); >+ } >+ >+ try { >+ start += regionOffset; >+ end += regionOffset; >+ String resourceName = extractResourceName(m.group()); >+ >+ IRegion region = new Region(start, end - start); >+ return getHyperlink(region, resourceName); >+ >+ } catch (NumberFormatException e) { >+ return null; >+ } >+ } >+ >+ /** >+ * return correspondent IHyperlink, subclasses should implement >+ */ >+ protected abstract IHyperlink getHyperlink(IRegion region, String resourceName); >+ >+ /** >+ * extract the resource name for the matched text, can be overridden by subclasses >+ */ >+ protected String extractResourceName(String matchedText) { >+ return matchedText.substring(matchedText.lastIndexOf(" ") + 1); >+ } >+ >+ public IHyperlink[] findHyperlink(String text, int lineOffset, int regionOffset) { >+ ArrayList<IHyperlink> hyperlinksFound = new ArrayList<IHyperlink>(); >+ >+ Matcher m = getMatcherFor(text); >+ while (m.find()) { >+ if (lineOffset >= m.start() && lineOffset < m.end()) { >+ // ignore when resource does not exist >+ if (!resourceExists(extractResourceName(m.group()))) { >+ continue; >+ } >+ >+ IHyperlink link = extractHyperlink(regionOffset, m); >+ if (link != null) { >+ hyperlinksFound.add(link); >+ } >+ } >+ } >+ >+ if (hyperlinksFound.size() > 0) { >+ return hyperlinksFound.toArray(new IHyperlink[1]); >+ } >+ return null; >+ } >+ >+ /** >+ * get the Matcher for the to-be-matched text, can be overridden by subclasses >+ */ >+ protected Matcher getMatcherFor(String text) { >+ return Pattern.compile(getReourceExpressions(), Pattern.CASE_INSENSITIVE).matcher(text); >+ } >+ >+ /** >+ * get the resource's regular expressions, subclasses should implement >+ */ >+ protected abstract String getReourceExpressions(); >+ >+ /** >+ * whether the resource exists for a certain resource name, subclasses should implement >+ */ >+ public abstract boolean resourceExists(String resourceName); >+} >Index: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/ResourceHyperlinkDetector.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/ResourceHyperlinkDetector.java >diff -N src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/ResourceHyperlinkDetector.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/sandbox/ui/hyperlinks/ResourceHyperlinkDetector.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,68 @@ >+/******************************************************************************* >+ * Copyright (c) 2004, 2007 Mylyn project committers and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.sandbox.ui.hyperlinks; >+ >+import java.util.ArrayList; >+import java.util.Arrays; >+import java.util.List; >+ >+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.hyperlink.AbstractHyperlinkDetector; >+import org.eclipse.jface.text.hyperlink.IHyperlink; >+ >+/** >+ * Resource hyperlink detector, detecting format like < prefix > < qualified name >, examples are >+ * >+ * See java class foo.bar.Baz, it could be related; See cpp class Foo, it could be related; See file foo.txt, I left >+ * some notes there; See task 123, I put a comment there >+ * >+ * @author Jingwen Ou >+ */ >+public class ResourceHyperlinkDetector extends AbstractHyperlinkDetector { >+ >+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) { >+ try { >+ IDocument document = textViewer.getDocument(); >+ if (document == null) { >+ return null; >+ } >+ int offset = region.getOffset(); >+ >+ IRegion lineInfo = document.getLineInformationOfOffset(offset); >+ String line = document.get(lineInfo.getOffset(), lineInfo.getLength()); >+ if (line.length() == 0) { >+ return null; >+ } >+ >+ List<IHyperlink> hyperlinks = new ArrayList<IHyperlink>(); >+ detectHyperlinks(line, region.getOffset() - lineInfo.getOffset(), lineInfo.getOffset(), hyperlinks); >+ >+ if (hyperlinks.isEmpty()) { >+ return null; >+ } >+ return hyperlinks.toArray(new IHyperlink[hyperlinks.size()]); >+ >+ } catch (BadLocationException e) { >+ return null; >+ } >+ } >+ >+ private void detectHyperlinks(String line, int lineOffset, int regionOffset, List<IHyperlink> hyperlinks) { >+ for (IResourceHyperlinkExtension resourceHyperlinkExtension : ResourceHyperlinkExtensions.getResourceHyperlinkExtensions()) { >+ IHyperlink[] links = resourceHyperlinkExtension.findHyperlink(line, lineOffset, regionOffset); >+ if (links == null) { >+ continue; >+ } >+ hyperlinks.addAll(Arrays.asList(links)); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 240441
: 107163 |
107164
|
108124
|
108125
|
108289