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 108124 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]
a patch with better comments and renaming getResourceExpressions()
clipboard.txt (text/plain), 11.52 KB, created by
Jingwen 'Owen' Ou
on 2008-07-22 15:51:02 EDT
(
hide
)
Description:
a patch with better comments and renaming getResourceExpressions()
Filename:
MIME Type:
Creator:
Jingwen 'Owen' Ou
Created:
2008-07-22 15:51:02 EDT
Size:
11.52 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.sandbox.ui >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 getResourceExpressions() { >+ return JAVA_PREFIX + DEFAULT_QUALIFIED_NAME; >+ } >+ >+ @Override >+ protected boolean isResourceExists(String resourceName) { >+ try { >+ return OpenTypeAction.findTypeInWorkspace(resourceName) != null; >+ } catch (CoreException e) { >+ return false; >+ } >+ } >+ >+ @Override >+ protected IHyperlink createHyperlinkInstance(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,130 @@ >+/******************************************************************************* >+ * 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; >+ >+/** >+ * An IResourceHyperlinkExtension implementation with various helper methods. Subclasses may choose to extend it instead >+ * of IResourceHyperlinkExtension. >+ * >+ * It matches text that is in the form of <prefix> <qualified name>. >+ * >+ * @author Jingwen Ou >+ */ >+public abstract class AbstractResourceHyperlinkExtension implements IResourceHyperlinkExtension { >+ >+ /** >+ * A regular expression matching class name, e.g. org.eclipse.mylyn.ITask or foo. Subclasses may use it as a default >+ * qualified name. >+ */ >+ protected static final String DEFAULT_QUALIFIED_NAME = "((\\w(\\w|\\.)*\\w)|\\w)"; >+ >+ /** >+ * Extracts a IHyperlink from current region offset. >+ */ >+ private IHyperlink extractHyperlink(int regionOffset, Matcher m) { >+ int 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 createHyperlinkInstance(region, resourceName); >+ >+ } catch (NumberFormatException e) { >+ return null; >+ } >+ } >+ >+ /** >+ * Extracts the resource name from the matched text. Subclasses may choose to override it for customized name >+ * extracting mechanism. The default implementation is to extract the last block of the matched text, e.g. the >+ * "foo.bar" from "java class foo.bar". >+ * >+ * @param matchedText >+ * the matched text using the regular expression defined in getResourceExpressions >+ */ >+ 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 (!isResourceExists(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; >+ } >+ >+ /** >+ * Creates correspondent IHyperlink instance for this resource. Subclasses should override. >+ * >+ * @param region >+ * the region of the hyperlink >+ * @param resourceName >+ * the found resource name >+ * >+ * @return the correspondent IHyperlink instance for this resouce >+ */ >+ protected abstract IHyperlink createHyperlinkInstance(IRegion region, String resourceName); >+ >+ /** >+ * Gets the Matcher for the to-be-matched text. Default flag is Pattern.CASE_INSENSITIVE. >+ */ >+ private Matcher getMatcherFor(String text) { >+ return Pattern.compile(getResourceExpressions(), Pattern.CASE_INSENSITIVE).matcher(text); >+ } >+ >+ /** >+ * Gets the resource's regular expressions. Subclasses should override. >+ * >+ * @return the regular expression of matching current resource. For example, matching "java class org.foo.bar". >+ */ >+ protected abstract String getResourceExpressions(); >+ >+ /** >+ * Indicate whether the current resource exists. Subclasses should override. >+ * >+ * @param resourceName >+ * the name of the resource to be tested >+ * @return if the resource exists >+ */ >+ protected abstract boolean isResourceExists(String resourceName); >+}
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