|
From: <caw...@us...> - 2007-02-26 18:57:03
|
Revision: 2042
http://svn.sourceforge.net/rubyeclipse/?rev=2042&view=rev
Author: cawilliams
Date: 2007-02-26 10:56:47 -0800 (Mon, 26 Feb 2007)
Log Message:
-----------
add the RubyHyperLink stuff into plugin.xml to enable it. Clean up the code. Make the underlying code like the F3 - Go to Declaration stuff...
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/OpenActionUtil.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyHyperLinkDetector.java
Modified: trunk/org.rubypeople.rdt.ui/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.ui/plugin.xml 2007-02-26 16:23:47 UTC (rev 2041)
+++ trunk/org.rubypeople.rdt.ui/plugin.xml 2007-02-26 18:56:47 UTC (rev 2042)
@@ -939,5 +939,12 @@
contentMergeViewerId="org.rubypeople.rdt.internal.ui.RubyMergeViewer"
contentTypeId="org.rubypeople.rdt.core.rubySource"/>
</extension>
+
+ <extension
+ point="org.rubypeople.rdt.ui.hyperlinkProvider">
+ <hyperlinkProvider
+ class="org.rubypeople.rdt.internal.ui.text.hyperlinks.RubyElementsHyperlinkProvider">
+ </hyperlinkProvider>
+ </extension>
</plugin>
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/OpenActionUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/OpenActionUtil.java 2007-02-26 16:23:47 UTC (rev 2041)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/OpenActionUtil.java 2007-02-26 18:56:47 UTC (rev 2042)
@@ -9,7 +9,6 @@
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.ui.rubyeditor.EditorUtility;
import org.rubypeople.rdt.ui.RubyElementLabelProvider;
-import org.rubypeople.rdt.ui.RubyElementLabels;
public class OpenActionUtil {
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java 2007-02-26 16:23:47 UTC (rev 2041)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java 2007-02-26 18:56:47 UTC (rev 2042)
@@ -59,15 +59,19 @@
}
public static IRubyElement[] codeResolve(IRubyElement input, ITextSelection selection) throws RubyModelException {
+ return codeResolve(input, selection.getOffset(), selection.getLength());
+ }
+
+ public static IRubyElement[] codeResolve(IRubyElement input, int offset, int length) throws RubyModelException {
if (input instanceof ICodeAssist) {
if (input instanceof IRubyScript) {
RubyModelUtil.reconcile((IRubyScript) input);
}
- IRubyElement[] elements= ((ICodeAssist)input).codeSelect(selection.getOffset(), selection.getLength());
+ IRubyElement[] elements= ((ICodeAssist)input).codeSelect(offset, length);
if (elements != null && elements.length > 0)
return elements;
}
return EMPTY_RESULT;
-}
+ }
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java 2007-02-26 16:23:47 UTC (rev 2041)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyElementsHyperlinkProvider.java 2007-02-26 18:56:47 UTC (rev 2042)
@@ -1,125 +1,76 @@
package org.rubypeople.rdt.internal.ui.text.hyperlinks;
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.ide.IDE;
import org.jruby.ast.Node;
-import org.rubypeople.rdt.core.IMember;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
-import org.rubypeople.rdt.core.ISourceRange;
import org.rubypeople.rdt.core.RubyModelException;
-import org.rubypeople.rdt.internal.codeassist.SelectionEngine;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.actions.OpenActionUtil;
+import org.rubypeople.rdt.internal.ui.actions.SelectionConverter;
import org.rubypeople.rdt.internal.ui.text.RubyWordFinder;
import org.rubypeople.rdt.ui.IWorkingCopyManager;
import org.rubypeople.rdt.ui.text.hyperlinks.IHyperlinkProvider;
public class RubyElementsHyperlinkProvider implements IHyperlinkProvider {
- public RubyElementsHyperlinkProvider (){}
+ public RubyElementsHyperlinkProvider() {}
- class RubyElementsHyperlink implements IHyperlink {
- private IRegion fRegion;
- private final IEditorInput fEditorInput;
- private final IRubyElement[] fElements;
+ class RubyElementsHyperlink implements IHyperlink {
+ private IRegion fRegion;
+ private final IRubyElement[] fElements;
- public RubyElementsHyperlink(IEditorInput editorInput, IRegion region, String symbol, IRubyElement[] elements) {
- this.fEditorInput = editorInput;
-// fRegion = new Region(region.getOffset(), 5);
- fRegion = region;
- this.fElements = elements;
- }
+ public RubyElementsHyperlink(IRegion region, IRubyElement[] elements) {
+ fRegion = region;
+ this.fElements = elements;
+ }
- public IRegion getHyperlinkRegion() {
- return fRegion;
- }
+ public IRegion getHyperlinkRegion() {
+ return fRegion;
+ }
- public String getHyperlinkText() {
- // TODO Auto-generated method stub
- return null;
- }
+ public String getHyperlinkText() {
+ // TODO Auto-generated method stub
+ return null;
+ }
- public String getTypeLabel() {
- // TODO Auto-generated method stub
- return null;
- }
+ public String getTypeLabel() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+ public void open() {
+ try {
+ // FIXME Check for first element which is an instanceof of
+ // IMember, don't just try to access the first element!
+ if (fElements != null && fElements.length > 0) {
+ OpenActionUtil.open(fElements[0], true);
+ }
+ } catch (PartInitException e) {
+ RubyPlugin.log(e);
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ }
+ }
+ }
- public void open() {
- try {
- // FIXME Check for first element which is an instanceof of IMember, don't just try to access the first element!
- if(fElements != null && fElements.length > 0){
- ISourceRange sourceRange = ((IMember) fElements[0]).getSourceRange();
- IFile file = null;
- if (fEditorInput instanceof IFileEditorInput) {
- IFileEditorInput fileInput = (IFileEditorInput) fEditorInput;
- file = fileInput.getFile();
- }
- openFileAndLocation(sourceRange, file);
- }
- } catch (PartInitException e) {
- RubyPlugin.log(e);
- } catch (RubyModelException e) {
- RubyPlugin.log(e);
- } catch (CoreException e) {
- RubyPlugin.log(e);
- }
- }
-
- private void openFileAndLocation(ISourceRange sourceRange, IFile file)
- throws PartInitException, CoreException {
- if (file == null) {
- return;
- }
- if (sourceRange == null) {
- return;
- }
- IEditorPart editorPart = IDE.openEditor(PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow().getActivePage(), file, true);
-
- IMarker mark = file.createMarker(IMarker.TEXT);
- mark.setAttribute(IMarker.CHAR_START, sourceRange.getOffset());
- mark.setAttribute(IMarker.CHAR_END, sourceRange.getOffset()
- + sourceRange.getLength());
- IDE.gotoMarker(editorPart, mark);
- mark.delete();
- IDE.gotoMarker(editorPart, mark);
- }
-
- }
-
-
- public IHyperlink getHyperlink(IEditorInput input, ITextViewer textViewer, Node node,
- IRegion region, boolean canShowMultipleHyperlinks) {
- IRegion newRegion = RubyWordFinder.findWord(textViewer.getDocument(), region.getOffset());
- try {
- String symbol = textViewer.getDocument().get(newRegion.getOffset(), newRegion.getLength());
- // Let's see if this is a RubyElement
- SelectionEngine engine = new SelectionEngine();
- IWorkingCopyManager manager = RubyPlugin.getDefault().getWorkingCopyManager();
- IRubyScript script = manager.getWorkingCopy(input);
- IRubyElement[] elements = engine.select(script, newRegion.getOffset(), newRegion.getOffset() + newRegion.getLength());
- if(elements == null){
- return null;
- }
- if(elements.length > 0){
- // TODO: check if it's a RubyElement, if not, return null
- return new RubyElementsHyperlink(input, newRegion, symbol, elements);
- }
- return null;
- } catch (Exception e) {
- RubyPlugin.log(e);
- }
- return null;
- }
+ public IHyperlink getHyperlink(IEditorInput input, ITextViewer textViewer, Node node, IRegion region, boolean canShowMultipleHyperlinks) {
+ IRegion newRegion = RubyWordFinder.findWord(textViewer.getDocument(), region.getOffset());
+ try {
+ IWorkingCopyManager manager = RubyPlugin.getDefault().getWorkingCopyManager();
+ IRubyScript script = manager.getWorkingCopy(input);
+ IRubyElement[] elements = SelectionConverter.codeResolve(script, newRegion.getOffset(), newRegion.getLength());
+ if (elements == null || elements.length == 0) {
+ return null;
+ }
+ return new RubyElementsHyperlink(newRegion, elements);
+ } catch (Exception e) {
+ RubyPlugin.log(e);
+ }
+ return null;
+ }
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyHyperLinkDetector.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyHyperLinkDetector.java 2007-02-26 16:23:47 UTC (rev 2041)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/hyperlinks/RubyHyperLinkDetector.java 2007-02-26 18:56:47 UTC (rev 2042)
@@ -26,106 +26,85 @@
public class RubyHyperLinkDetector implements IHyperlinkDetector {
- public static final String RDT_UI_NAMESPACE = "org.rubypeople.rdt.ui";
- public static final String RDT_UI_HYPERLINKPROVIDER = "hyperlinkProvider";
+ public static final String RDT_UI_NAMESPACE = "org.rubypeople.rdt.ui";
+ public static final String RDT_UI_HYPERLINKPROVIDER = "hyperlinkProvider";
+ private List fExtensions;
+ private final IEditorInput fEditorInput;
- private List fExtensions;
- private final IEditorInput fEditorInput;
+ public RubyHyperLinkDetector(IEditorInput editorInput) {
+ this.fEditorInput = editorInput;
+ }
+ private IExtensionPoint[] getExtensionPoints() {
+ IExtensionRegistry reg = Platform.getExtensionRegistry();
+ return reg.getExtensionPoints(RDT_UI_NAMESPACE);
+ }
- public RubyHyperLinkDetector(IEditorInput editorInput) {
- this.fEditorInput = editorInput;
- }
+ private List initExtensions() {
+ if (fExtensions != null)
+ return fExtensions;
+ fExtensions = new ArrayList();
+ IExtensionPoint[] points = getExtensionPoints();
+ // TODO: Look for textProvider!
+ IExtensionPoint point = getExtensionPoint(points);
+ if (point != null) {
+ IExtension[] exts = point.getExtensions();
+ for (int i = 0; i < exts.length; i++) {
+ IConfigurationElement[] elem = exts[i].getConfigurationElements();
+ String attrs[] = elem[0].getAttributeNames();
+ try {
+ Object tempProv = elem[0].createExecutableExtension("class");
+ if (tempProv instanceof IHyperlinkProvider) {
+ IHyperlinkProvider prov = (IHyperlinkProvider) tempProv;
+ fExtensions.add(prov);
+ }
+ } catch (Exception e) {
+ RubyPlugin.log(e);
+ }
+ }
+ }
+ return fExtensions;
+ }
- private List initExtensions() {
- if(fExtensions == null){
- fExtensions = new ArrayList();
- IExtensionRegistry reg = Platform.getExtensionRegistry();
- IExtensionPoint[] points = reg.getExtensionPoints(RDT_UI_NAMESPACE);
- // TODO: Look for textProvider!
- IExtensionPoint point = null;
+ private IExtensionPoint getExtensionPoint(IExtensionPoint[] points) {
+ for (int i = 0; i < points.length; i++) {
+ IExtensionPoint currentPoint = points[i];
+ String uniqueIdentifier = currentPoint.getUniqueIdentifier();
+ if (uniqueIdentifier.endsWith(RDT_UI_HYPERLINKPROVIDER)) {
+ return currentPoint;
+ }
+ }
+ return null;
+ }
- if(points != null){
- for (int i = 0; i < points.length; i++) {
- IExtensionPoint currentPoint = points[i];
- String uniqueIdentifier = currentPoint.getUniqueIdentifier();
- if(uniqueIdentifier.endsWith(RDT_UI_HYPERLINKPROVIDER)){
- point = currentPoint;
- break;
- }
- }
+ public IHyperlink[] detectHyperlinks(ITextViewer textViewer, IRegion region, boolean canShowMultipleHyperlinks) {
+ IRegion newRegion = region;
+ List extensions = initExtensions();
+ // first ask the extensions
+ if (extensions.size() > 0) {
+ SelectionEngine engine = new SelectionEngine();
+ IWorkingCopyManager manager = RubyPlugin.getDefault().getWorkingCopyManager();
+ IRubyScript script = manager.getWorkingCopy(fEditorInput);
+ RubyParser parser = new RubyParser();
+ try {
+ Node root = parser.parse((IFile) script.getResource(), new StringReader(script.getSource()));
+ for (int i = 0; i < extensions.size(); i++) {
+ IHyperlinkProvider currentProvider = (IHyperlinkProvider) extensions.get(i);
+ IHyperlink link = currentProvider.getHyperlink(fEditorInput, textViewer, root, newRegion, true);
+ // TODO: either do that or query all HyperlinkProviders and
+ // return a list of hyperlinks?
+ if (link != null) {
+ return new IHyperlink[] { link };
+ }
+ }
+ } catch (RubyModelException e) {
+ RubyPlugin.log(e);
+ }
+ }
- if(point != null){
- IExtension[] exts = point.getExtensions();
+ return null;
- IHyperlinkProvider prov = null;
+ }
- for (int i = 0; i < exts.length; i++) {
- IConfigurationElement[] elem = exts[i].getConfigurationElements();
- String attrs[] = elem[0].getAttributeNames();
- try {
- Object tempProv = elem[0].createExecutableExtension("class");
- if (tempProv instanceof IHyperlinkProvider) {
- prov = (IHyperlinkProvider) tempProv;
- fExtensions.add(prov);
- }
-// }
- } catch (Exception e) {
- RubyPlugin.log(e);
- }
-
- }
- }
- }
-
- }
- return fExtensions;
-
- }
-
-
-
- public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
- IRegion region, boolean canShowMultipleHyperlinks) {
- String symbol = "";
- IRegion newRegion = region;
-// newRegion = RubyWordFinder.findWord(textViewer.getDocument(), region.getOffset());
-// try {
-// symbol = textViewer.getDocument().get(newRegion.getOffset(), newRegion.getLength());
-// } catch (BadLocationException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-// System.out.println("Symbol:" + symbol);
-// return new IHyperlink[]{new RubyHyperLinkDetector(fEditorInput, newRegion, symbol)};
-
- List extensions = initExtensions();
-// final String symbol = textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
- // first ask the extensions
- if(extensions.size() > 0){
- SelectionEngine engine = new SelectionEngine();
- IWorkingCopyManager manager = RubyPlugin.getDefault().getWorkingCopyManager();
- IRubyScript script = manager.getWorkingCopy(fEditorInput);
- RubyParser parser = new RubyParser();
- try {
- Node root = parser.parse((IFile) script.getResource(),new StringReader(script.getSource()));
- // IRubyElement[] elements = engine.select(script, newRegion.getOffset(), newRegion.getOffset() + newRegion.getLength());
- for(int i=0; i< extensions.size(); i++){
- IHyperlinkProvider currentProvider = (IHyperlinkProvider) extensions.get(i);
- IHyperlink link = currentProvider.getHyperlink(fEditorInput, textViewer, root, newRegion, true);
- // TODO: either do that or query all HyperlinkProviders and return a list of hyperlinks?
- if(link != null){
- return new IHyperlink[]{link};
- }
- }
- } catch (RubyModelException e) {
- RubyPlugin.log(e);
- }
- }
-
- return null;
-
- }
-
}
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|