You can subscribe to this list here.
| 2005 |
Jan
|
Feb
|
Mar
(41) |
Apr
(9) |
May
|
Jun
|
Jul
(39) |
Aug
(38) |
Sep
(135) |
Oct
(220) |
Nov
(75) |
Dec
(74) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2006 |
Jan
(44) |
Feb
(160) |
Mar
(49) |
Apr
(69) |
May
(40) |
Jun
(52) |
Jul
(47) |
Aug
(51) |
Sep
(19) |
Oct
(22) |
Nov
(36) |
Dec
(76) |
| 2007 |
Jan
(154) |
Feb
(165) |
Mar
(186) |
Apr
(143) |
May
(175) |
Jun
(133) |
Jul
(203) |
Aug
(177) |
Sep
(136) |
Oct
|
Nov
|
Dec
|
|
From: <caw...@us...> - 2007-06-11 17:35:12
|
Revision: 2597
http://svn.sourceforge.net/rubyeclipse/?rev=2597&view=rev
Author: cawilliams
Date: 2007-06-11 10:35:10 -0700 (Mon, 11 Jun 2007)
Log Message:
-----------
add tests and code to fix Trac #4326
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/formatter/FormatTestData.xml
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/formatter/TC_CodeFormatter.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java 2007-06-11 16:23:39 UTC (rev 2596)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/formatter/OldCodeFormatter.java 2007-06-11 17:35:10 UTC (rev 2597)
@@ -8,6 +8,7 @@
import org.eclipse.core.runtime.Platform;
import org.eclipse.text.edits.ReplaceEdit;
import org.eclipse.text.edits.TextEdit;
+import org.jruby.ast.NextNode;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.formatter.CodeFormatter;
import org.rubypeople.rdt.core.formatter.DefaultCodeFormatterConstants;
@@ -316,6 +317,10 @@
}
if (lastBlockMarker != null) {
+ if (!lastBlockMarker.getKeyword().equals("begin") && newBlockMarker.getKeyword().equals("rescue")) {
+ // we have a rescue modifier?
+ continue;
+ }
lastBlockMarker.setNext(newBlockMarker);
}
lastBlockMarker = newBlockMarker;
Modified: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/formatter/FormatTestData.xml
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/formatter/FormatTestData.xml 2007-06-11 16:23:39 UTC (rev 2596)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/formatter/FormatTestData.xml 2007-06-11 17:35:10 UTC (rev 2597)
@@ -633,7 +633,48 @@
</part>
</test>
+<test ID="RescueModifier">
+<part>
+<assertionMessage>Rescue Modifier</assertionMessage>
+<unformatted>
+class A
+ var = do_something rescue nil
+foo
+end
+</unformatted>
+<formatted>
+class A
+ var = do_something rescue nil
+ foo
+end
+</formatted>
+</part>
+<part>
+<assertionMessage>Rescue Modifier With Previous Block</assertionMessage>
+<unformatted>
+class A
+ begin
+do_something
+ rescue
+yeah
+ end
+ var = do_something rescue nil
+foo
+end
+</unformatted>
+<formatted>
+class A
+ begin
+ do_something
+ rescue
+ yeah
+ end
+ var = do_something rescue nil
+ foo
+end
+</formatted>
+</part>
+</test>
-
</tests>
Modified: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/formatter/TC_CodeFormatter.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/formatter/TC_CodeFormatter.java 2007-06-11 16:23:39 UTC (rev 2596)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/formatter/TC_CodeFormatter.java 2007-06-11 17:35:10 UTC (rev 2597)
@@ -132,4 +132,8 @@
this.doTest("NegativeIndentation");
}
+ public void testRescueModifier() {
+ doTest("RescueModifier");
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-11 16:23:40
|
Revision: 2596
http://svn.sourceforge.net/rubyeclipse/?rev=2596&view=rev
Author: cawilliams
Date: 2007-06-11 09:23:39 -0700 (Mon, 11 Jun 2007)
Log Message:
-----------
only mark name of method when we have other sorts (besidess line count) of complexity errors
Modified Paths:
--------------
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java 2007-06-11 16:22:28 UTC (rev 2595)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java 2007-06-11 16:23:39 UTC (rev 2596)
@@ -107,13 +107,13 @@
public void exitDefnNode(DefnNode iVisited) {
if (returnCount > maxReturns) {
- createProblem(iVisited.getPosition(), "Too many explicit returns: " + returnCount);
+ createProblem(iVisited.getNameNode().getPosition(), "Too many explicit returns: " + returnCount);
}
if (branchCount > maxBranches) {
- createProblem(iVisited.getPosition(), "Too many branches: " + branchCount);
+ createProblem(iVisited.getNameNode().getPosition(), "Too many branches: " + branchCount);
}
if (locals.size() > maxLocals) {
- createProblem(iVisited.getPosition(), "Too many local variables: " + locals.size());
+ createProblem(iVisited.getNameNode().getPosition(), "Too many local variables: " + locals.size());
}
returnCount = 0;
branchCount = 0;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-11 16:22:29
|
Revision: 2595
http://svn.sourceforge.net/rubyeclipse/?rev=2595&view=rev
Author: cawilliams
Date: 2007-06-11 09:22:28 -0700 (Mon, 11 Jun 2007)
Log Message:
-----------
fix Trac ticket #4599, #4365
Modified Paths:
--------------
trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/RubyRedPreferenceInitializer.java
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java 2007-06-08 00:26:05 UTC (rev 2594)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java 2007-06-11 16:22:28 UTC (rev 2595)
@@ -3,16 +3,25 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Iterator;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.core.runtime.preferences.DefaultScope;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.IPreferencesService;
+import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;
+import org.rubypeople.rdt.internal.core.RubyModelManager.EclipsePreferencesListener;
import org.rubypeople.rdt.internal.launching.LaunchingPlugin;
import org.rubypeople.rdt.internal.ui.IRubyStatusConstants;
@@ -29,6 +38,14 @@
// The plug-in ID
public static final String PLUGIN_ID = "com.aptana.rdt";
+
+ // Preferences
+ public HashSet optionNames = new HashSet(20);
+ public Hashtable<String, String> optionsCache;
+
+ public final IEclipsePreferences[] preferencesLookup = new IEclipsePreferences[2];
+ static final int PREF_INSTANCE = 0;
+ static final int PREF_DEFAULT = 1;
/**
* Possible configurable option ID.
@@ -216,6 +233,7 @@
public void start(BundleContext context) throws Exception {
super.start(context);
context.registerService(IGemManager.class.getName(), GemManager.getInstance(), null);
+ initializePreferences();
boolean rubyDebugInstalled = GemManager.getInstance().gemInstalled("ruby-debug-ide");
// FIXME What if user has explicity disabled using ruby-debug?!
@@ -248,6 +266,40 @@
}
}
+ private void initializePreferences() {
+ // Create lookups
+ preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID);
+ preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID);
+
+ // Listen to instance preferences node removal from parent in order to refresh stored one
+ IEclipsePreferences.INodeChangeListener listener = new IEclipsePreferences.INodeChangeListener() {
+ public void added(IEclipsePreferences.NodeChangeEvent event) {
+ // do nothing
+ }
+ public void removed(IEclipsePreferences.NodeChangeEvent event) {
+ if (event.getChild() == preferencesLookup[PREF_INSTANCE]) {
+ preferencesLookup[PREF_INSTANCE] = new InstanceScope().getNode(PLUGIN_ID);
+ preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
+ }
+ }
+ };
+ ((IEclipsePreferences) preferencesLookup[PREF_INSTANCE].parent()).addNodeChangeListener(listener);
+ preferencesLookup[PREF_INSTANCE].addPreferenceChangeListener(new EclipsePreferencesListener());
+
+ // Listen to default preferences node removal from parent in order to refresh stored one
+ listener = new IEclipsePreferences.INodeChangeListener() {
+ public void added(IEclipsePreferences.NodeChangeEvent event) {
+ // do nothing
+ }
+ public void removed(IEclipsePreferences.NodeChangeEvent event) {
+ if (event.getChild() == preferencesLookup[PREF_DEFAULT]) {
+ preferencesLookup[PREF_DEFAULT] = new DefaultScope().getNode(PLUGIN_ID);
+ }
+ }
+ };
+ ((IEclipsePreferences) preferencesLookup[PREF_DEFAULT].parent()).addNodeChangeListener(listener);
+ }
+
protected void setRubyDebugAsDefault() {
LaunchingPlugin.getDefault().getPluginPreferences().setValue(org.rubypeople.rdt.internal.launching.PreferenceConstants.USE_RUBY_DEBUG, true);
}
@@ -308,4 +360,30 @@
public static String getPluginId() {
return PLUGIN_ID;
}
+
+ public Hashtable<String, String> getOptions() {
+
+ // return cached options if already computed
+// if (this.optionsCache != null) return new Hashtable<String, String>(this.optionsCache);
+
+ // init
+ Hashtable<String, String> options = new Hashtable<String, String>(10);
+ IPreferencesService service = Platform.getPreferencesService();
+
+ // set options using preferences service lookup
+ Iterator iterator = optionNames.iterator();
+ while (iterator.hasNext()) {
+ String propertyName = (String) iterator.next();
+ String propertyValue = service.get(propertyName, null, this.preferencesLookup);
+ if (propertyValue != null) {
+ options.put(propertyName, propertyValue);
+ }
+ }
+
+ // store built map in cache
+ this.optionsCache = new Hashtable<String, String>(options);
+
+ // return built map
+ return options;
+ }
}
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/RubyRedPreferenceInitializer.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/RubyRedPreferenceInitializer.java 2007-06-08 00:26:05 UTC (rev 2594)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/core/RubyRedPreferenceInitializer.java 2007-06-11 16:22:28 UTC (rev 2595)
@@ -1,5 +1,6 @@
package com.aptana.rdt.internal.core;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
@@ -13,6 +14,7 @@
public class RubyRedPreferenceInitializer extends AbstractPreferenceInitializer {
public void initializeDefaultPreferences() {
+ HashSet optionNames = AptanaRDTPlugin.getDefault().optionNames;
// Lint visitor settings
Map defaultOptionsMap = new LintOptions().getMap(); // compiler defaults
@@ -22,8 +24,9 @@
Map.Entry entry = (Map.Entry) iter.next();
String optionName = (String) entry.getKey();
defaultPreferences.put(optionName, (String) entry.getValue());
+ optionNames.add(optionName);
}
-
+ AptanaRDTPlugin.getDefault().optionsCache = null;
}
}
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java 2007-06-08 00:26:05 UTC (rev 2594)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/CodeComplexityVisitor.java 2007-06-11 16:22:28 UTC (rev 2595)
@@ -1,6 +1,8 @@
package com.aptana.rdt.internal.parser.warnings;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import org.jruby.ast.CaseNode;
import org.jruby.ast.DefnNode;
@@ -25,11 +27,11 @@
private int maxLocals;
private int returnCount;
private int branchCount;
- private int locals;
+ private Set locals;
private Map fOptions;
public CodeComplexityVisitor(String contents) {
- this(RubyModelManager.getRubyModelManager().getOptions(), contents);
+ this(AptanaRDTPlugin.getDefault().getOptions(), contents);
}
public CodeComplexityVisitor(Map options, String contents) {
@@ -61,7 +63,7 @@
public Instruction visitDefnNode(DefnNode iVisited) {
returnCount = 0;
branchCount = 0;
- locals = 0;
+ locals = new HashSet();
String[] args = ASTUtil.getArgs(iVisited.getArgsNode(), iVisited.getScope());
if (args != null && args.length > maxArgLength) {
@@ -70,7 +72,7 @@
ISourcePosition pos = iVisited.getPosition();
int lines = (pos.getEndLine() - pos.getStartLine()) - 1;
if (lines > maxLines) {
- createProblem(iVisited.getPosition(), "Too many lines in method: " + lines);
+ createProblem(iVisited.getNameNode().getPosition(), "Too many lines in method: " + lines);
}
return super.visitDefnNode(iVisited);
}
@@ -99,7 +101,7 @@
@Override
public Instruction visitLocalAsgnNode(LocalAsgnNode iVisited) {
- locals++;
+ locals.add(iVisited.getName());
return super.visitLocalAsgnNode(iVisited);
}
@@ -110,12 +112,12 @@
if (branchCount > maxBranches) {
createProblem(iVisited.getPosition(), "Too many branches: " + branchCount);
}
- if (locals > maxLocals) {
- createProblem(iVisited.getPosition(), "Too many local variables: " + locals);
+ if (locals.size() > maxLocals) {
+ createProblem(iVisited.getPosition(), "Too many local variables: " + locals.size());
}
returnCount = 0;
branchCount = 0;
- locals = 0;
+ locals.clear();
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-08 00:26:06
|
Revision: 2594
http://svn.sourceforge.net/rubyeclipse/?rev=2594&view=rev
Author: cawilliams
Date: 2007-06-07 17:26:05 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
run com.aptana.rdt from a JAR, specify newer version of JRuby plugin
Modified Paths:
--------------
trunk/org.rubypeople.rdt-feature/feature.xml
Modified: trunk/org.rubypeople.rdt-feature/feature.xml
===================================================================
--- trunk/org.rubypeople.rdt-feature/feature.xml 2007-06-08 00:10:51 UTC (rev 2593)
+++ trunk/org.rubypeople.rdt-feature/feature.xml 2007-06-08 00:26:05 UTC (rev 2594)
@@ -346,7 +346,7 @@
id="org.jruby"
download-size="0"
install-size="0"
- version="0.9.2.3129"
+ version="1.0.0.3788"
unpack="false"/>
<plugin
@@ -360,6 +360,7 @@
id="com.aptana.rdt"
download-size="0"
install-size="0"
- version="0.0.0"/>
+ version="0.0.0"
+ unpack="false"/>
</feature>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-08 00:10:52
|
Revision: 2593
http://svn.sourceforge.net/rubyeclipse/?rev=2593&view=rev
Author: cawilliams
Date: 2007-06-07 17:10:51 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
change version to match revision I updated to from JRuby SVN 10.0.0 RC2 rev 3788. (don't include RC2 in version or we might clash with the final 1.0.0)
Revision Links:
--------------
http://svn.sourceforge.net/rubyeclipse/?rev=3788&view=rev
Modified Paths:
--------------
trunk/org.jruby/META-INF/MANIFEST.MF
Modified: trunk/org.jruby/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.jruby/META-INF/MANIFEST.MF 2007-06-07 23:53:09 UTC (rev 2592)
+++ trunk/org.jruby/META-INF/MANIFEST.MF 2007-06-08 00:10:51 UTC (rev 2593)
@@ -2,7 +2,7 @@
Bundle-ManifestVersion: 2
Bundle-Name: JRuby Plug-in
Bundle-SymbolicName: org.jruby
-Bundle-Version: 0.9.2.3129
+Bundle-Version: 1.0.0.3788
Bundle-Localization: plugin
Require-Bundle: org.eclipse.core.runtime
Eclipse-LazyStart: false
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-07 23:53:10
|
Revision: 2592
http://svn.sourceforge.net/rubyeclipse/?rev=2592&view=rev
Author: cawilliams
Date: 2007-06-07 16:53:09 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
do a better job of listening for ruby-debug gem
Modified Paths:
--------------
trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java 2007-06-07 23:06:54 UTC (rev 2591)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/AptanaRDTPlugin.java 2007-06-07 23:53:09 UTC (rev 2592)
@@ -3,7 +3,6 @@
import java.io.File;
import java.io.IOException;
import java.net.URL;
-import java.util.Set;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IPath;
@@ -218,16 +217,18 @@
super.start(context);
context.registerService(IGemManager.class.getName(), GemManager.getInstance(), null);
- Set<Gem> gems = GemManager.getInstance().getGems(); // FIXME What if user has explicity disabled using ruby-debug?!
- if (gems.isEmpty()) {
+ boolean rubyDebugInstalled = GemManager.getInstance().gemInstalled("ruby-debug-ide");
+ // FIXME What if user has explicity disabled using ruby-debug?!
+ if (rubyDebugInstalled) {
+ setRubyDebugAsDefault();
+ } else {
GemManager.getInstance().addGemListener(new GemListener() {
public void gemsRefreshed() {
- boolean rubyDebugInstalled = GemManager.getInstance().gemInstalled("ruby-debug-ide");
- LaunchingPlugin.getDefault().getPluginPreferences().setValue(org.rubypeople.rdt.internal.launching.PreferenceConstants.USE_RUBY_DEBUG, rubyDebugInstalled);
- Job job = new RubyDebugGemListener(this);
- job.schedule();
- }
+ if (GemManager.getInstance().gemInstalled("ruby-debug-ide")) {
+ setRubyDebugUp();
+ }
+ }
public void gemRemoved(Gem gem) {
// ignore
@@ -235,14 +236,26 @@
public void gemAdded(Gem gem) {
// ignore
+ if(gem.getName().equals("ruby-debug-ide"))
+ setRubyDebugUp();
}
-
+
+ private void setRubyDebugUp() {
+ setRubyDebugAsDefault();
+ removeListener(this);
+ }
});
- } else {
- boolean rubyDebugInstalled = GemManager.getInstance().gemInstalled("ruby-debug-ide");
- LaunchingPlugin.getDefault().getPluginPreferences().setValue(org.rubypeople.rdt.internal.launching.PreferenceConstants.USE_RUBY_DEBUG, rubyDebugInstalled);
}
}
+
+ protected void setRubyDebugAsDefault() {
+ LaunchingPlugin.getDefault().getPluginPreferences().setValue(org.rubypeople.rdt.internal.launching.PreferenceConstants.USE_RUBY_DEBUG, true);
+ }
+
+ protected void removeListener(GemListener listener) {
+ Job job = new RubyDebugGemListener(listener);
+ job.schedule();
+ }
/*
* (non-Javadoc)
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-07 23:06:59
|
Revision: 2591
http://svn.sourceforge.net/rubyeclipse/?rev=2591&view=rev
Author: cawilliams
Date: 2007-06-07 16:06:54 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
update tracing flags to match what we check for in code
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/.options
Modified: trunk/org.rubypeople.rdt.core/.options
===================================================================
--- trunk/org.rubypeople.rdt.core/.options 2007-06-07 21:49:03 UTC (rev 2590)
+++ trunk/org.rubypeople.rdt.core/.options 2007-06-07 23:06:54 UTC (rev 2591)
@@ -3,7 +3,15 @@
# Turn on general debugging for org.eclipse.osgi
org.rubypeople.rdt.core/debug=false
org.rubypeople.rdt.core/codeformatter=false
+org.rubypeople.rdt.core/debug/buffermanager=false
+org.rubypeople.rdt.core/debug/rubymodel=false
+org.rubypeople.rdt.core/debug/rubydelta=false
+org.rubypeople.rdt.core/debug/rubydelta/verbose=false
+org.rubypeople.rdt.core/debug/postaction=false
+org.rubypeople.rdt.core/debug/builder=false
org.rubypeople.rdt.core/rubyparser=false
org.rubypeople.rdt.core/modelmanager=false
-org.rubypeople.rdt.core/symbolIndex=false
-org.rubypeople.rdt.core/rubyBuilder=false
\ No newline at end of file
+org.rubypeople.rdt.core/rubyBuilder=false
+org.rubypeople.rdt.core/formatter/enable_new=false
+org.rubypeople.rdt.core/perf/rubydeltalistener=false
+org.rubypeople.rdt.core/perf/reconcile=false
\ No newline at end of file
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-07 21:49:08
|
Revision: 2590
http://svn.sourceforge.net/rubyeclipse/?rev=2590&view=rev
Author: cawilliams
Date: 2007-06-07 14:49:03 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
move setting debug flags into RubyModelManager, implement a private function for tracing performance
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java 2007-06-07 21:15:54 UTC (rev 2589)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java 2007-06-07 21:49:03 UTC (rev 2590)
@@ -56,8 +56,6 @@
import org.rubypeople.rdt.internal.core.RubyModelManager;
import org.rubypeople.rdt.internal.core.RubyProject;
import org.rubypeople.rdt.internal.core.SetLoadpathOperation;
-import org.rubypeople.rdt.internal.core.builder.RubyBuilder;
-import org.rubypeople.rdt.internal.core.parser.RubyParser;
import org.rubypeople.rdt.internal.core.util.MementoTokenizer;
import org.rubypeople.rdt.internal.core.util.Util;
@@ -66,11 +64,6 @@
private static RubyCore RUBY_CORE_PLUGIN = null;
public final static String PLUGIN_ID = "org.rubypeople.rdt.core";//$NON-NLS-1$
-
- private static final String RUBY_PARSER_DEBUG_OPTION = RubyCore.PLUGIN_ID + "/rubyparser";//$NON-NLS-1$
- private static final String MODEL_MANAGER_VERBOSE_OPTION = RubyCore.PLUGIN_ID + "/modelmanager";//$NON-NLS-1$
- private static final String BUILDER_VERBOSE_OPTION = RubyCore.PLUGIN_ID + "/rubyBuilder";//$NON-NLS-1$
-
public final static String NATURE_ID = PLUGIN_ID + ".rubynature";//$NON-NLS-1$
/**
@@ -311,10 +304,6 @@
super.start(context);
RubyModelManager.getRubyModelManager().startup();
- RubyParser.setDebugging(isDebugOptionTrue(RUBY_PARSER_DEBUG_OPTION));
- RubyModelManager.setVerbose(isDebugOptionTrue(MODEL_MANAGER_VERBOSE_OPTION));
- RubyBuilder.setVerbose(isDebugOptionTrue(BUILDER_VERBOSE_OPTION));
-
ResourcesPlugin.getWorkspace().addResourceChangeListener(new RubyProjectListener(), IResourceChangeEvent.POST_CHANGE);
}
@@ -333,11 +322,6 @@
}
}
- private boolean isDebugOptionTrue(String option) {
- String optionText = Platform.getDebugOption(option);
- return optionText == null ? false : optionText.equalsIgnoreCase("true");
- }
-
public static boolean upgradeOldProjects() throws CoreException {
boolean projectUpgraded = false;
IProject[] projects = RubyCore.getRubyProjects();
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java 2007-06-07 21:15:54 UTC (rev 2589)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyModelManager.java 2007-06-07 21:49:03 UTC (rev 2590)
@@ -13,6 +13,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
@@ -90,6 +91,7 @@
import org.rubypeople.rdt.internal.core.buffer.BufferManager;
import org.rubypeople.rdt.internal.core.builder.RubyBuilder;
import org.rubypeople.rdt.internal.core.parser.MarkerUtility;
+import org.rubypeople.rdt.internal.core.parser.RubyParser;
import org.rubypeople.rdt.internal.core.search.RubyWorkspaceScope;
import org.rubypeople.rdt.internal.core.search.indexing.IndexManager;
import org.rubypeople.rdt.internal.core.util.Messages;
@@ -114,6 +116,9 @@
+ "/debug/rubydelta/verbose"; //$NON-NLS-1$
private static final String POST_ACTION_DEBUG = RubyCore.PLUGIN_ID + "/debug/postaction"; //$NON-NLS-1$
private static final String BUILDER_DEBUG = RubyCore.PLUGIN_ID + "/debug/builder"; //$NON-NLS-1$
+ private static final String RUBY_PARSER_DEBUG_OPTION = RubyCore.PLUGIN_ID + "/rubyparser";//$NON-NLS-1$
+ private static final String MODEL_MANAGER_VERBOSE_OPTION = RubyCore.PLUGIN_ID + "/modelmanager";//$NON-NLS-1$
+ private static final String BUILDER_VERBOSE_OPTION = RubyCore.PLUGIN_ID + "/rubyBuilder";//$NON-NLS-1$
private static final String ENABLE_NEW_FORMATTER = RubyCore.PLUGIN_ID + "/formatter/enable_new"; //$NON-NLS-1$
@@ -206,9 +211,9 @@
*/
protected Map<WorkingCopyOwner, Map> perWorkingCopyInfos = new HashMap<WorkingCopyOwner, Map>(5);
- private static boolean verbose = false;
public static boolean CP_RESOLVE_VERBOSE = false;
public static boolean ZIP_ACCESS_VERBOSE = false;
+ public static boolean VERBOSE = false;
// Preferences
HashSet optionNames = new HashSet(20);
@@ -219,8 +224,7 @@
static final int PREF_INSTANCE = 0;
static final int PREF_DEFAULT = 1;
- public static final IRubyScript[] NO_WORKING_COPY = new IRubyScript[0];
- public static final boolean VERBOSE = false;
+ public static final IRubyScript[] NO_WORKING_COPY = new IRubyScript[0];
public final static String CP_VARIABLE_PREFERENCES_PREFIX = RubyCore.PLUGIN_ID+".loadpathVariable."; //$NON-NLS-1$
public final static String CP_CONTAINER_PREFERENCES_PREFIX = RubyCore.PLUGIN_ID+".loadpathContainer."; //$NON-NLS-1$
@@ -868,14 +872,6 @@
}
}
- public static void setVerbose(boolean verbose) {
- RubyModelManager.verbose = verbose;
- }
-
- public static boolean isVerbose() {
- return verbose;
- }
-
public String getOption(String optionName) {
if (RubyCore.CORE_ENCODING.equals(optionName)) { return RubyCore.getEncoding(); }
String propertyName = optionName;
@@ -945,17 +941,17 @@
Platform.getContentTypeManager().addContentTypeChangeListener(this);
// retrieve variable values
-// long start = -1;
-// if (VERBOSE)
-// start = System.currentTimeMillis();
+ long start = -1;
+ if (VERBOSE)
+ start = System.currentTimeMillis();
loadVariablesAndContainers();
-// if (VERBOSE)
-// traceVariableAndContainers("Loaded", start); //$NON-NLS-1$
+ if (VERBOSE)
+ traceVariableAndContainers("Loaded", start); //$NON-NLS-1$
final IWorkspace workspace = ResourcesPlugin.getWorkspace();
workspace.addResourceChangeListener(
this.deltaState,
- /* update spec in JavaCore#addPreProcessingResourceChangedListener(...) if adding more event types */
+ /* update spec in RubyCore#addPreProcessingResourceChangedListener(...) if adding more event types */
IResourceChangeEvent.PRE_BUILD
| IResourceChangeEvent.POST_BUILD
| IResourceChangeEvent.POST_CHANGE
@@ -1458,12 +1454,24 @@
if (option != null) DeltaProcessor.VERBOSE = option.equalsIgnoreCase("true"); //$NON-NLS-1$
option = Platform.getDebugOption(RUBYMODEL_DEBUG);
- if (option != null) RubyModelManager.verbose = option.equalsIgnoreCase("true"); //$NON-NLS-1$
+ if (option != null) RubyModelManager.VERBOSE = option.equalsIgnoreCase("true"); //$NON-NLS-1$
option = Platform.getDebugOption(POST_ACTION_DEBUG);
if (option != null)
RubyModelOperation.POST_ACTION_VERBOSE = option.equalsIgnoreCase("true"); //$NON-NLS-1$
-
+
+ option = Platform.getDebugOption(RUBY_PARSER_DEBUG_OPTION);
+ if (option != null)
+ RubyParser.setDebugging(option.equalsIgnoreCase("true")); //$NON-NLS-1$
+
+ option = Platform.getDebugOption(MODEL_MANAGER_VERBOSE_OPTION);
+ if (option != null)
+ RubyModelManager.VERBOSE = option.equalsIgnoreCase("true"); //$NON-NLS-1$
+
+ option = Platform.getDebugOption(BUILDER_VERBOSE_OPTION);
+ if (option != null)
+ RubyBuilder.setVerbose(option.equalsIgnoreCase("true")); //$NON-NLS-1$
+
// configure performance options
if (PerformanceStats.ENABLED) {
DeltaProcessor.PERF = PerformanceStats.isEnabled(DELTA_LISTENER_PERF);
@@ -2925,5 +2933,19 @@
}
}
}
+
+ private void traceVariableAndContainers(String action, long start) {
+ Long delta = new Long(System.currentTimeMillis() - start);
+ Long length = new Long(getVariableAndContainersFile().length());
+ String pattern = "{0} {1} bytes in variablesAndContainers.dat in {2}ms"; //$NON-NLS-1$
+ String message = MessageFormat.format(pattern, new Object[]{action, length, delta});
+
+ System.out.println(message);
+ }
+
+ public static boolean isVerbose() {
+ return VERBOSE;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-07 21:15:56
|
Revision: 2589
http://svn.sourceforge.net/rubyeclipse/?rev=2589&view=rev
Author: cawilliams
Date: 2007-06-07 14:15:54 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
properly detect if we're referring to a variable 9so the read/write images are used when we do a search for occurrences in file of identifier)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java 2007-06-07 20:57:17 UTC (rev 2588)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java 2007-06-07 21:15:54 UTC (rev 2589)
@@ -10,14 +10,19 @@
import org.jruby.ast.AttrAssignNode;
import org.jruby.ast.ClassNode;
import org.jruby.ast.ClassVarAsgnNode;
+import org.jruby.ast.ClassVarDeclNode;
+import org.jruby.ast.ClassVarNode;
import org.jruby.ast.Colon2Node;
+import org.jruby.ast.ConstDeclNode;
import org.jruby.ast.ConstNode;
import org.jruby.ast.DStrNode;
import org.jruby.ast.FalseNode;
import org.jruby.ast.FixnumNode;
import org.jruby.ast.GlobalAsgnNode;
+import org.jruby.ast.GlobalVarNode;
import org.jruby.ast.HashNode;
import org.jruby.ast.InstAsgnNode;
+import org.jruby.ast.InstVarNode;
import org.jruby.ast.ListNode;
import org.jruby.ast.LocalAsgnNode;
import org.jruby.ast.ModuleNode;
@@ -193,4 +198,12 @@
return contents.substring(pos.getStartOffset(), pos.getEndOffset());
}
+ public static boolean isVariable(Node node) {
+ return (node instanceof GlobalAsgnNode) || (node instanceof GlobalVarNode)
+ || (node instanceof InstAsgnNode) || (node instanceof InstVarNode)
+ || (node instanceof ConstDeclNode) || (node instanceof ConstNode)
+ || (node instanceof ClassVarAsgnNode) || (node instanceof ClassVarDeclNode)
+ || (node instanceof ClassVarNode);
+ }
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java 2007-06-07 20:57:17 UTC (rev 2588)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java 2007-06-07 21:15:54 UTC (rev 2589)
@@ -96,7 +96,7 @@
if (groupKey == null) {
IRegion region= document.getLineInformation(line);
String lineContents= document.get(region.getOffset(), region.getLength()).trim();
- groupKey= new OccurrencesGroupKey(element, line, lineContents, isWriteAccess, isVariable(element));
+ groupKey= new OccurrencesGroupKey(element, line, lineContents, isWriteAccess, isVariable(fSelectedNode));
lineToGroup.put(lineInteger, groupKey);
} else if (isWriteAccess) {
// a line with read an write access is considered as write access:
@@ -110,8 +110,8 @@
}
}
- private boolean isVariable(IRubyElement element) {
- return element.isType(IRubyElement.INSTANCE_VAR) || element.isType(IRubyElement.GLOBAL) || element.isType(IRubyElement.CLASS_VAR) || element.isType(IRubyElement.LOCAL_VARIABLE) || element.isType(IRubyElement.DYNAMIC_VAR);
+ private boolean isVariable(Node node) {
+ return ASTUtil.isVariable(node);
}
public String initialize(Node root, int offset, int length) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-07 20:57:26
|
Revision: 2588
http://svn.sourceforge.net/rubyeclipse/?rev=2588&view=rev
Author: cawilliams
Date: 2007-06-07 13:57:17 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
add search for write references
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesInProjectAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesInWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/WriteReferencesSearchGroup.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java 2007-06-07 20:46:45 UTC (rev 2587)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java 2007-06-07 20:57:17 UTC (rev 2588)
@@ -132,6 +132,7 @@
public static String group_search;
public static String group_occurrences;
public static String group_declarations;
+ public static String group_writeReferences;
public static String RubyElementAction_operationUnavailable_title;
public static String RubyElementAction_operationUnavailable_generic;
@@ -183,6 +184,13 @@
public static String Search_FindDeclarationsInWorkingSetAction_label;
public static String Search_FindDeclarationsInWorkingSetAction_tooltip;
+ public static String Search_FindWriteReferencesAction_label;
+ public static String Search_FindWriteReferencesAction_tooltip;
+ public static String Search_FindWriteReferencesInWorkingSetAction_label;
+ public static String Search_FindWriteReferencesInWorkingSetAction_tooltip;
+ public static String Search_FindWriteReferencesInProjectAction_label;
+ public static String Search_FindWriteReferencesInProjectAction_tooltip;
+
static {
NLS.initializeMessages(BUNDLE_NAME, SearchMessages.class);
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties 2007-06-07 20:46:45 UTC (rev 2587)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties 2007-06-07 20:57:17 UTC (rev 2588)
@@ -82,6 +82,7 @@
group_declarations= Dec&larations
group_references= Re&ferences
group_readReferences= &Read Access
+group_writeReferences= &Write Access
group_occurrences= Occurre&nces in File
RubyElementAction_operationUnavailable_title= Operation Unavailable
@@ -117,7 +118,6 @@
Search_FindDeclarationsInWorkingSetAction_label= Working &Set...
Search_FindDeclarationsInWorkingSetAction_tooltip= Search for Declarations of the Selected Element in a Working Set
-
Search_FindReferencesAction_label= &Workspace
Search_FindReferencesAction_tooltip= Search for References to the Selected Element in the Workspace
@@ -136,6 +136,15 @@
Search_FindReadReferencesInWorkingSetAction_label= Working &Set...
Search_FindReadReferencesInWorkingSetAction_tooltip= Search for Read References to the Selected Element in a Working Set
+Search_FindWriteReferencesAction_label= &Workspace
+Search_FindWriteReferencesAction_tooltip= Search for Write References to the Selected Element in the Workspace
+
+Search_FindWriteReferencesInProjectAction_label= &Project
+Search_FindWriteReferencesInProjectAction_tooltip= Search for Write References to the Selected Element in Resources in the Enclosing Project of the Selected Element
+
+Search_FindWriteReferencesInWorkingSetAction_label= Working &Set...
+Search_FindWriteReferencesInWorkingSetAction_tooltip= Search for Write References to the Selected Element in a Working Set
+
Search_FindOccurrencesInFile_shortLabel= &Identifier
Search_FindOccurrencesInFile_label= I&dentifiers in File
Search_FindOccurrencesInFile_tooltip= Find Occurrences of the Selected Element in the Editor
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesAction.java 2007-06-07 20:57:17 UTC (rev 2588)
@@ -0,0 +1,71 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IField;
+import org.rubypeople.rdt.core.search.IRubySearchConstants;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+import org.rubypeople.rdt.internal.ui.search.SearchMessages;
+
+/**
+ * Finds field write accesses of the selected element in the workspace.
+ * The action is applicable to selections representing a Ruby element.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 2.0
+ */
+public class FindWriteReferencesAction extends FindReferencesAction {
+
+ /**
+ * Creates a new <code>FindWriteReferencesAction</code>. The action
+ * requires that the selection provided by the site's selection provider is of type
+ * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
+ *
+ * @param site the site providing context information for this action
+ */
+ public FindWriteReferencesAction(IWorkbenchSite site) {
+ super(site);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ */
+ public FindWriteReferencesAction(RubyEditor editor) {
+ super(editor);
+ }
+
+ Class[] getValidTypes() {
+ return new Class[] { IField.class };
+ }
+
+ void init() {
+ setText(SearchMessages.Search_FindWriteReferencesAction_label);
+ setToolTipText(SearchMessages.Search_FindWriteReferencesAction_tooltip);
+ setImageDescriptor(RubyPluginImages.DESC_OBJS_SEARCH_REF);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.FIND_WRITE_REFERENCES_IN_WORKSPACE_ACTION);
+ }
+
+ int getLimitTo() {
+ return IRubySearchConstants.WRITE_ACCESSES;
+ }
+
+ String getOperationUnavailableMessage() {
+ return SearchMessages.RubyElementAction_operationUnavailable_field;
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesInProjectAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesInProjectAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesInProjectAction.java 2007-06-07 20:57:17 UTC (rev 2588)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.core.search.IRubySearchScope;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+import org.rubypeople.rdt.internal.ui.search.RubySearchScopeFactory;
+import org.rubypeople.rdt.internal.ui.search.SearchMessages;
+import org.rubypeople.rdt.ui.search.ElementQuerySpecification;
+import org.rubypeople.rdt.ui.search.QuerySpecification;
+
+/**
+ * Finds field write accesses of the selected element in the enclosing project.
+ * The action is applicable to selections representing a Ruby field.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 3.0
+ */
+public class FindWriteReferencesInProjectAction extends FindWriteReferencesAction {
+
+ /**
+ * Creates a new <code>FindWriteReferencesInProjectAction</code>. The action
+ * requires that the selection provided by the site's selection provider is of type
+ * <code>IStructuredSelection</code>.
+ *
+ * @param site the site providing context information for this action
+ */
+ public FindWriteReferencesInProjectAction(IWorkbenchSite site) {
+ super(site);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ */
+ public FindWriteReferencesInProjectAction(RubyEditor editor) {
+ super(editor);
+ }
+
+ void init() {
+ setText(SearchMessages.Search_FindWriteReferencesInProjectAction_label);
+ setToolTipText(SearchMessages.Search_FindWriteReferencesInProjectAction_tooltip);
+ setImageDescriptor(RubyPluginImages.DESC_OBJS_SEARCH_REF);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.FIND_WRITE_REFERENCES_IN_PROJECT_ACTION);
+ }
+
+ QuerySpecification createQuery(IRubyElement element) throws RubyModelException {
+ RubySearchScopeFactory factory= RubySearchScopeFactory.getInstance();
+ RubyEditor editor= getEditor();
+
+ IRubySearchScope scope;
+ String description;
+ boolean isInsideJRE= factory.isInsideJRE(element);
+ if (editor != null) {
+ scope= factory.createRubyProjectSearchScope(editor.getEditorInput(), isInsideJRE);
+ description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
+ } else {
+ scope= factory.createRubyProjectSearchScope(element.getRubyProject(), isInsideJRE);
+ description= factory.getProjectScopeDescription(element.getRubyProject(), isInsideJRE);
+ }
+ return new ElementQuerySpecification(element, getLimitTo(), scope, description);
+ }
+
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesInWorkingSetAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesInWorkingSetAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindWriteReferencesInWorkingSetAction.java 2007-06-07 20:57:17 UTC (rev 2588)
@@ -0,0 +1,95 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IField;
+import org.rubypeople.rdt.core.search.IRubySearchConstants;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+import org.rubypeople.rdt.internal.ui.search.SearchMessages;
+
+/**
+ * Finds field write accesses of the selected element in working sets.
+ * The action is applicable to selections representing a Ruby field.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 2.0
+ */
+public class FindWriteReferencesInWorkingSetAction extends FindReferencesInWorkingSetAction {
+
+ /**
+ * Creates a new <code>FindWriteReferencesInWorkingSetAction</code>. The action
+ * requires that the selection provided by the site's selection provider is of type
+ * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be
+ * prompted to select the working sets.
+ *
+ * @param site the site providing context information for this action
+ */
+ public FindWriteReferencesInWorkingSetAction(IWorkbenchSite site) {
+ super(site);
+ }
+
+ /**
+ * Creates a new <code>FindWriteReferencesInWorkingSetAction</code>. The action
+ * requires that the selection provided by the site's selection provider is of type
+ * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
+ *
+ * @param site the site providing context information for this action
+ * @param workingSets the working sets to be used in the search
+ */
+ public FindWriteReferencesInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) {
+ super(site, workingSets);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ */
+ public FindWriteReferencesInWorkingSetAction(RubyEditor editor) {
+ super(editor);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ * @param workingSets the working sets to be used in the search
+ */
+ public FindWriteReferencesInWorkingSetAction(RubyEditor editor, IWorkingSet[] workingSets) {
+ super(editor, workingSets);
+ }
+
+ Class[] getValidTypes() {
+ return new Class[] { IField.class };
+ }
+
+ void init() {
+ setText(SearchMessages.Search_FindWriteReferencesInWorkingSetAction_label);
+ setToolTipText(SearchMessages.Search_FindWriteReferencesInWorkingSetAction_tooltip);
+ setImageDescriptor(RubyPluginImages.DESC_OBJS_SEARCH_REF);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.FIND_WRITE_REFERENCES_IN_WORKING_SET_ACTION);
+ }
+
+ int getLimitTo() {
+ return IRubySearchConstants.WRITE_ACCESSES;
+ }
+
+ String getOperationUnavailableMessage() {
+ return SearchMessages.RubyElementAction_operationUnavailable_field;
+ }
+}
+
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java 2007-06-07 20:46:45 UTC (rev 2587)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java 2007-06-07 20:57:17 UTC (rev 2588)
@@ -116,6 +116,24 @@
public static final String SEARCH_OCCURRENCES_IN_FILE= "org.rubypeople.rdt.ui.edit.text.ruby.search.occurrences.in.file"; //$NON-NLS-1$
/**
+ * Action definition ID of the search -> write access in workspace action
+ * (value <code>"org.rubypeople.rdt.ui.edit.text.ruby.search.write.access.in.workspace"</code>).
+ */
+ public static final String SEARCH_WRITE_ACCESS_IN_WORKSPACE= "org.rubypeople.rdt.ui.edit.text.ruby.search.write.access.in.workspace"; //$NON-NLS-1$
+
+ /**
+ * Action definition ID of the search -> write access in project action
+ * (value <code>"org.rubypeople.rdt.ui.edit.text.ruby.search.write.access.in.project"</code>).
+ */
+ public static final String SEARCH_WRITE_ACCESS_IN_PROJECT= "org.rubypeople.rdt.ui.edit.text.ruby.search.write.access.in.project"; //$NON-NLS-1$
+
+ /**
+ * Action definition ID of the search -> write access in working set action
+ * (value <code>"org.rubypeople.rdt.ui.edit.text.ruby.search.write.access.in.working.set"</code>).
+ */
+ public static final String SEARCH_WRITE_ACCESS_IN_WORKING_SET= "org.rubypeople.rdt.ui.edit.text.ruby.search.write.access.in.working.set"; //$NON-NLS-1$
+
+ /**
* Action definition ID of the search -> declarations in workspace action
* (value <code>"org.rubypeople.rdt.ui.edit.text.ruby.search.declarations.in.workspace"</code>).
*/
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-06-07 20:46:45 UTC (rev 2587)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-06-07 20:57:17 UTC (rev 2588)
@@ -60,7 +60,6 @@
*/
public static final String FIND_OCCURRENCES_IN_FILE= "org.rubypeople.rdt.ui.actions.OccurrencesInFile"; //$NON-NLS-1$
-
/**
* Search menu: name of standard Find Declarations in Workspace global action
* (value <code>"org.rubypeople.rdt.ui.actions.DeclarationsInWorkspace"</code>).
@@ -79,4 +78,23 @@
*/
public static final String FIND_DECLARATIONS_IN_WORKING_SET= "org.rubypeople.rdt.ui.actions.DeclarationsInWorkingSet"; //$NON-NLS-1$
+ /**
+ * Search menu: name of standard Find Write Access in Workspace global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.WriteAccessInWorkspace"</code>).
+ */
+ public static final String FIND_WRITE_ACCESS_IN_WORKSPACE= "org.rubypeople.rdt.ui.actions.WriteAccessInWorkspace"; //$NON-NLS-1$
+
+ /**
+ * Search menu: name of standard Find Write Access in Project global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.WriteAccessInProject"</code>).
+ */
+ public static final String FIND_WRITE_ACCESS_IN_PROJECT= "org.rubypeople.rdt.ui.actions.WriteAccessInProject"; //$NON-NLS-1$
+
+ /**
+ * Search menu: name of standard Find Read Access in Working Set global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.WriteAccessInWorkingSet"</code>).
+ */
+ public static final String FIND_WRITE_ACCESS_IN_WORKING_SET= "org.rubypeople.rdt.ui.actions.WriteAccessInWorkingSet"; //$NON-NLS-1$
+
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java 2007-06-07 20:46:45 UTC (rev 2587)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java 2007-06-07 20:57:17 UTC (rev 2588)
@@ -42,7 +42,7 @@
private ReferencesSearchGroup fReferencesGroup;
private ReadReferencesSearchGroup fReadAccessGroup;
-// private WriteReferencesSearchGroup fWriteAccessGroup;
+ private WriteReferencesSearchGroup fWriteAccessGroup;
private DeclarationsSearchGroup fDeclarationsGroup;
// private ImplementorsSearchGroup fImplementorsGroup;
private OccurrencesSearchGroup fOccurrencesGroup;
@@ -80,7 +80,7 @@
fReferencesGroup= new ReferencesSearchGroup(fEditor);
fReadAccessGroup= new ReadReferencesSearchGroup(fEditor);
-// fWriteAccessGroup= new WriteReferencesSearchGroup(fEditor);
+ fWriteAccessGroup= new WriteReferencesSearchGroup(fEditor);
fDeclarationsGroup= new DeclarationsSearchGroup(fEditor);
// fImplementorsGroup= new ImplementorsSearchGroup(fEditor);
fOccurrencesGroup= new OccurrencesSearchGroup(fEditor);
@@ -89,7 +89,7 @@
private RubySearchActionGroup(IWorkbenchSite site) {
fReferencesGroup= new ReferencesSearchGroup(site);
fReadAccessGroup= new ReadReferencesSearchGroup(site);
-// fWriteAccessGroup= new WriteReferencesSearchGroup(site);
+ fWriteAccessGroup= new WriteReferencesSearchGroup(site);
fDeclarationsGroup= new DeclarationsSearchGroup(site);
// fImplementorsGroup= new ImplementorsSearchGroup(site);
fOccurrencesGroup= new OccurrencesSearchGroup(site);
@@ -103,7 +103,7 @@
fDeclarationsGroup.setContext(context);
// fImplementorsGroup.setContext(context);
fReadAccessGroup.setContext(context);
-// fWriteAccessGroup.setContext(context);
+ fWriteAccessGroup.setContext(context);
fOccurrencesGroup.setContext(context);
}
@@ -116,7 +116,7 @@
fDeclarationsGroup.fillActionBars(actionBar);
// fImplementorsGroup.fillActionBars(actionBar);
fReadAccessGroup.fillActionBars(actionBar);
-// fWriteAccessGroup.fillActionBars(actionBar);
+ fWriteAccessGroup.fillActionBars(actionBar);
fOccurrencesGroup.fillActionBars(actionBar);
}
@@ -133,7 +133,7 @@
if (fEditor == null) {
// fImplementorsGroup.fillContextMenu(menu);
fReadAccessGroup.fillContextMenu(menu);
-// fWriteAccessGroup.fillContextMenu(menu);
+ fWriteAccessGroup.fillContextMenu(menu);
}
} else {
IMenuManager target= menu;
@@ -149,7 +149,7 @@
fDeclarationsGroup.fillContextMenu(target);
// fImplementorsGroup.fillContextMenu(target);
fReadAccessGroup.fillContextMenu(target);
-// fWriteAccessGroup.fillContextMenu(target);
+ fWriteAccessGroup.fillContextMenu(target);
if (searchSubMenu != null) {
fOccurrencesGroup.fillContextMenu(target);
@@ -171,7 +171,7 @@
fDeclarationsGroup.dispose();
// fImplementorsGroup.dispose();
fReadAccessGroup.dispose();
-// fWriteAccessGroup.dispose();
+ fWriteAccessGroup.dispose();
fOccurrencesGroup.dispose();
super.dispose();
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/WriteReferencesSearchGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/WriteReferencesSearchGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/WriteReferencesSearchGroup.java 2007-06-07 20:57:17 UTC (rev 2588)
@@ -0,0 +1,201 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import java.util.Iterator;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.search.ui.IContextMenuConstants;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+import org.rubypeople.rdt.internal.ui.search.SearchMessages;
+import org.rubypeople.rdt.internal.ui.search.SearchUtil;
+
+/**
+ * Action group that adds the search for write references actions to a
+ * context menu and the global menu bar.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 2.0
+ */
+public class WriteReferencesSearchGroup extends ActionGroup {
+
+ private static final String MENU_TEXT= SearchMessages.group_writeReferences;
+
+ private IWorkbenchSite fSite;
+ private RubyEditor fEditor;
+ private IActionBars fActionBars;
+
+ private String fGroupId;
+
+ private FindWriteReferencesAction fFindWriteReferencesAction;
+ private FindWriteReferencesInProjectAction fFindWriteReferencesInProjectAction;
+// private FindWriteReferencesInHierarchyAction fFindWriteReferencesInHierarchyAction;
+ private FindWriteReferencesInWorkingSetAction fFindWriteReferencesInWorkingSetAction;
+
+ /**
+ * Creates a new <code>WriteReferencesSearchGroup</code>. The action
+ * requires that the selection provided by the site's selection provider is of
+ * type <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
+ *
+ * @param site the view part that owns this action group
+ */
+ public WriteReferencesSearchGroup(IWorkbenchSite site) {
+ fSite= site;
+ fGroupId= IContextMenuConstants.GROUP_SEARCH;
+
+ fFindWriteReferencesAction= new FindWriteReferencesAction(site);
+ fFindWriteReferencesAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE);
+
+ fFindWriteReferencesInProjectAction= new FindWriteReferencesInProjectAction(site);
+ fFindWriteReferencesInProjectAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_PROJECT);
+
+// fFindWriteReferencesInHierarchyAction= new FindWriteReferencesInHierarchyAction(site);
+// fFindWriteReferencesInHierarchyAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY);
+
+ fFindWriteReferencesInWorkingSetAction= new FindWriteReferencesInWorkingSetAction(site);
+ fFindWriteReferencesInWorkingSetAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET);
+
+ // register the actions as selection listeners
+ ISelectionProvider provider= fSite.getSelectionProvider();
+ ISelection selection= provider.getSelection();
+ registerAction(fFindWriteReferencesAction, provider, selection);
+ registerAction(fFindWriteReferencesInProjectAction, provider, selection);
+// registerAction(fFindWriteReferencesInHierarchyAction, provider, selection);
+ registerAction(fFindWriteReferencesInWorkingSetAction, provider, selection);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ */
+ public WriteReferencesSearchGroup(RubyEditor editor) {
+ fEditor= editor;
+ fSite= fEditor.getSite();
+ fGroupId= ITextEditorActionConstants.GROUP_FIND;
+
+ fFindWriteReferencesAction= new FindWriteReferencesAction(fEditor);
+ fFindWriteReferencesAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKSPACE);
+ fEditor.setAction("SearchWriteAccessInWorkspace", fFindWriteReferencesAction); //$NON-NLS-1$
+
+ fFindWriteReferencesInProjectAction= new FindWriteReferencesInProjectAction(fEditor);
+ fFindWriteReferencesInProjectAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_PROJECT);
+ fEditor.setAction("SearchWriteAccessInProject", fFindWriteReferencesInProjectAction); //$NON-NLS-1$
+
+// fFindWriteReferencesInHierarchyAction= new FindWriteReferencesInHierarchyAction(fEditor);
+// fFindWriteReferencesInHierarchyAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_HIERARCHY);
+// fEditor.setAction("SearchWriteAccessInHierarchy", fFindWriteReferencesInHierarchyAction); //$NON-NLS-1$
+
+ fFindWriteReferencesInWorkingSetAction= new FindWriteReferencesInWorkingSetAction(fEditor);
+ fFindWriteReferencesInWorkingSetAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_WRITE_ACCESS_IN_WORKING_SET);
+ fEditor.setAction("SearchWriteAccessInWorkingSet", fFindWriteReferencesInWorkingSetAction); //$NON-NLS-1$
+ }
+
+ private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection) {
+ action.update(selection);
+ provider.addSelectionChangedListener(action);
+ }
+
+ private void addAction(IAction action, IMenuManager manager) {
+ if (action.isEnabled()) {
+ manager.add(action);
+ }
+ }
+
+ private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) {
+ FindAction action;
+ if (fEditor != null)
+ action= new WorkingSetFindAction(fEditor, new FindWriteReferencesInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets));
+ else
+ action= new WorkingSetFindAction(fSite, new FindWriteReferencesInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets));
+ action.update(getContext().getSelection());
+ addAction(action, manager);
+ }
+
+
+ /* (non-Rubydoc)
+ * Method declared on ActionGroup.
+ */
+ public void fillContextMenu(IMenuManager manager) {
+ MenuManager javaSearchMM= new MenuManager(MENU_TEXT, IContextMenuConstants.GROUP_SEARCH);
+ addAction(fFindWriteReferencesAction, javaSearchMM);
+ addAction(fFindWriteReferencesInProjectAction, javaSearchMM);
+// addAction(fFindWriteReferencesInHierarchyAction, javaSearchMM);
+
+ javaSearchMM.add(new Separator());
+
+ Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator();
+ while (iter.hasNext()) {
+ addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM);
+ }
+ addAction(fFindWriteReferencesInWorkingSetAction, javaSearchMM);
+
+ if (!javaSearchMM.isEmpty())
+ manager.appendToGroup(fGroupId, javaSearchMM);
+ }
+
+ /*
+ * Method declared on ActionGroup.
+ */
+ public void fillActionBars(IActionBars actionBars) {
+ Assert.isNotNull(actionBars);
+ super.fillActionBars(actionBars);
+ fActionBars= actionBars;
+ updateGlobalActionHandlers();
+ }
+
+ /*
+ * Method declared on ActionGroup.
+ */
+ public void dispose() {
+ ISelectionProvider provider= fSite.getSelectionProvider();
+ if (provider != null) {
+ disposeAction(fFindWriteReferencesAction, provider);
+ disposeAction(fFindWriteReferencesInProjectAction, provider);
+// disposeAction(fFindWriteReferencesInHierarchyAction, provider);
+ disposeAction(fFindWriteReferencesInWorkingSetAction, provider);
+ }
+ fFindWriteReferencesAction= null;
+ fFindWriteReferencesInProjectAction= null;
+// fFindWriteReferencesInHierarchyAction= null;
+ fFindWriteReferencesInWorkingSetAction= null;
+ updateGlobalActionHandlers();
+ super.dispose();
+ }
+
+ private void updateGlobalActionHandlers() {
+ if (fActionBars != null) {
+ fActionBars.setGlobalActionHandler(RdtActionConstants.FIND_WRITE_ACCESS_IN_WORKSPACE, fFindWriteReferencesAction);
+ fActionBars.setGlobalActionHandler(RdtActionConstants.FIND_WRITE_ACCESS_IN_PROJECT, fFindWriteReferencesInProjectAction);
+// fActionBars.setGlobalActionHandler(RdtActionConstants.FIND_WRITE_ACCESS_IN_HIERARCHY, fFindWriteReferencesInHierarchyAction);
+ fActionBars.setGlobalActionHandler(RdtActionConstants.FIND_WRITE_ACCESS_IN_WORKING_SET, fFindWriteReferencesInWorkingSetAction);
+ }
+ }
+
+ private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) {
+ if (action != null)
+ provider.removeSelectionChangedListener(action);
+ }
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-07 20:46:49
|
Revision: 2587
http://svn.sourceforge.net/rubyeclipse/?rev=2587&view=rev
Author: cawilliams
Date: 2007-06-07 13:46:45 -0700 (Thu, 07 Jun 2007)
Log Message:
-----------
add in searching for declarations
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/DeclarationsSearchGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsInProjectAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsInWorkingSetAction.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java 2007-06-06 16:44:06 UTC (rev 2586)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java 2007-06-07 20:46:45 UTC (rev 2587)
@@ -130,6 +130,8 @@
public static String group_references;
public static String group_readReferences;
public static String group_search;
+ public static String group_occurrences;
+ public static String group_declarations;
public static String RubyElementAction_operationUnavailable_title;
public static String RubyElementAction_operationUnavailable_generic;
@@ -171,11 +173,16 @@
public static String FindOccurrencesEngine_noSource_text;
public static String FindOccurrencesEngine_cannotParse_text;
+
+ public static String TextSearchLabelProvider_matchCountFormat;
- public static String group_occurrences;
+ public static String Search_FindDeclarationAction_label;
+ public static String Search_FindDeclarationAction_tooltip;
+ public static String Search_FindDeclarationsInProjectAction_label;
+ public static String Search_FindDeclarationsInProjectAction_tooltip;
+ public static String Search_FindDeclarationsInWorkingSetAction_label;
+ public static String Search_FindDeclarationsInWorkingSetAction_tooltip;
- public static String TextSearchLabelProvider_matchCountFormat;
-
static {
NLS.initializeMessages(BUNDLE_NAME, SearchMessages.class);
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties 2007-06-06 16:44:06 UTC (rev 2586)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties 2007-06-07 20:46:45 UTC (rev 2587)
@@ -79,6 +79,7 @@
RubySearchQuery_status_ok_message=Found {0} matches.
group_search=S&earch
+group_declarations= Dec&larations
group_references= Re&ferences
group_readReferences= &Read Access
group_occurrences= Occurre&nces in File
@@ -107,6 +108,16 @@
FindOccurrencesEngine_noSource_text= No source available. To perform this operation you need to attach source.
FindOccurrencesEngine_cannotParse_text= Cannot analyze the ruby script.
+Search_FindDeclarationAction_label= &Workspace
+Search_FindDeclarationAction_tooltip= Search for Declarations of the Selected Element in the Workspace
+
+Search_FindDeclarationsInProjectAction_label= &Project
+Search_FindDeclarationsInProjectAction_tooltip= Search for Declarations of the Selected Element in Resources in the Enclosing Project of the Selected Element
+
+Search_FindDeclarationsInWorkingSetAction_label= Working &Set...
+Search_FindDeclarationsInWorkingSetAction_tooltip= Search for Declarations of the Selected Element in a Working Set
+
+
Search_FindReferencesAction_label= &Workspace
Search_FindReferencesAction_tooltip= Search for References to the Selected Element in the Workspace
@@ -202,4 +213,4 @@
FiltersDialog_description_label=Filter Description:
FiltersDialog_limit_label=&Limit top level elements in Ruby search view to:
FiltersDialog_limit_error=Element limit must be a positive number
-FiltersDialogAction_label=&Filters...
\ No newline at end of file
+FiltersDialogAction_label=&Filters...
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/DeclarationsSearchGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/DeclarationsSearchGroup.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/DeclarationsSearchGroup.java 2007-06-07 20:46:45 UTC (rev 2587)
@@ -0,0 +1,203 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import java.util.Iterator;
+
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.search.ui.IContextMenuConstants;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.texteditor.ITextEditorActionConstants;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+import org.rubypeople.rdt.internal.ui.search.SearchMessages;
+import org.rubypeople.rdt.internal.ui.search.SearchUtil;
+
+/**
+ * Action group that adds the search for declarations actions to a
+ * context menu and the global menu bar.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 1.0
+ */
+public class DeclarationsSearchGroup extends ActionGroup {
+
+ private static final String MENU_TEXT= SearchMessages.group_declarations;
+
+ private IWorkbenchSite fSite;
+ private RubyEditor fEditor;
+ private IActionBars fActionBars;
+
+ private String fGroupId;
+
+ private FindDeclarationsAction fFindDeclarationsAction;
+ private FindDeclarationsInProjectAction fFindDeclarationsInProjectAction;
+ private FindDeclarationsInWorkingSetAction fFindDeclarationsInWorkingSetAction;
+// private FindDeclarationsInHierarchyAction fFindDeclarationsInHierarchyAction;
+
+ /**
+ * Creates a new <code>DeclarationsSearchGroup</code>. The group requires
+ * that the selection provided by the site's selection provider is of type <code>
+ * IStructuredSelection</code>.
+ *
+ * @param site the workbench site that owns this action group
+ */
+ public DeclarationsSearchGroup(IWorkbenchSite site) {
+ fSite= site;
+ fGroupId= IContextMenuConstants.GROUP_SEARCH;
+
+ fFindDeclarationsAction= new FindDeclarationsAction(site);
+ fFindDeclarationsAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKSPACE);
+
+ fFindDeclarationsInProjectAction= new FindDeclarationsInProjectAction(site);
+ fFindDeclarationsInProjectAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_PROJECTS);
+
+// fFindDeclarationsInHierarchyAction= new FindDeclarationsInHierarchyAction(site);
+// fFindDeclarationsInHierarchyAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_HIERARCHY);
+
+ fFindDeclarationsInWorkingSetAction= new FindDeclarationsInWorkingSetAction(site);
+ fFindDeclarationsInWorkingSetAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKING_SET);
+
+ // register the actions as selection listeners
+ ISelectionProvider provider= fSite.getSelectionProvider();
+ ISelection selection= provider.getSelection();
+ registerAction(fFindDeclarationsAction, provider, selection);
+ registerAction(fFindDeclarationsInProjectAction, provider, selection);
+// registerAction(fFindDeclarationsInHierarchyAction, provider, selection);
+ registerAction(fFindDeclarationsInWorkingSetAction, provider, selection);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ *
+ * @param editor the Ruby editor
+ */
+ public DeclarationsSearchGroup(RubyEditor editor) {
+ Assert.isNotNull(editor);
+ fEditor= editor;
+ fSite= fEditor.getSite();
+ fGroupId= ITextEditorActionConstants.GROUP_FIND;
+
+ fFindDeclarationsAction= new FindDeclarationsAction(fEditor);
+ fFindDeclarationsAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKSPACE);
+ fEditor.setAction("SearchDeclarationsInWorkspace", fFindDeclarationsAction); //$NON-NLS-1$
+
+ fFindDeclarationsInProjectAction= new FindDeclarationsInProjectAction(fEditor);
+ fFindDeclarationsInProjectAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_PROJECTS);
+ fEditor.setAction("SearchDeclarationsInProjects", fFindDeclarationsInProjectAction); //$NON-NLS-1$
+
+// fFindDeclarationsInHierarchyAction= new FindDeclarationsInHierarchyAction(fEditor);
+// fFindDeclarationsInHierarchyAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_HIERARCHY);
+// fEditor.setAction("SearchDeclarationsInHierarchy", fFindDeclarationsInHierarchyAction); //$NON-NLS-1$
+
+ fFindDeclarationsInWorkingSetAction= new FindDeclarationsInWorkingSetAction(fEditor);
+ fFindDeclarationsInWorkingSetAction.setActionDefinitionId(IRubyEditorActionDefinitionIds.SEARCH_DECLARATIONS_IN_WORKING_SET);
+ fEditor.setAction("SearchDeclarationsInWorkingSet", fFindDeclarationsInWorkingSetAction); //$NON-NLS-1$
+ }
+
+ private void registerAction(SelectionDispatchAction action, ISelectionProvider provider, ISelection selection) {
+ action.update(selection);
+ provider.addSelectionChangedListener(action);
+ }
+
+ /* (non-Rubydoc)
+ * Method declared on ActionGroup.
+ */
+ public void fillActionBars(IActionBars actionBars) {
+ Assert.isNotNull(actionBars);
+ super.fillActionBars(actionBars);
+ fActionBars= actionBars;
+ updateGlobalActionHandlers();
+ }
+
+ private void addAction(IAction action, IMenuManager manager) {
+ if (action.isEnabled()) {
+ manager.add(action);
+ }
+ }
+
+ private void addWorkingSetAction(IWorkingSet[] workingSets, IMenuManager manager) {
+ FindAction action;
+ if (fEditor != null)
+ action= new WorkingSetFindAction(fEditor, new FindDeclarationsInWorkingSetAction(fEditor, workingSets), SearchUtil.toString(workingSets));
+ else
+ action= new WorkingSetFindAction(fSite, new FindDeclarationsInWorkingSetAction(fSite, workingSets), SearchUtil.toString(workingSets));
+ action.update(getContext().getSelection());
+ addAction(action, manager);
+ }
+
+
+ /* (non-Rubydoc)
+ * Method declared on ActionGroup.
+ */
+ public void fillContextMenu(IMenuManager manager) {
+ IMenuManager javaSearchMM= new MenuManager(MENU_TEXT, IContextMenuConstants.GROUP_SEARCH);
+ addAction(fFindDeclarationsAction, javaSearchMM);
+ addAction(fFindDeclarationsInProjectAction, javaSearchMM);
+// addAction(fFindDeclarationsInHierarchyAction, javaSearchMM);
+
+ javaSearchMM.add(new Separator());
+
+ Iterator iter= SearchUtil.getLRUWorkingSets().sortedIterator();
+ while (iter.hasNext()) {
+ addWorkingSetAction((IWorkingSet[]) iter.next(), javaSearchMM);
+ }
+ addAction(fFindDeclarationsInWorkingSetAction, javaSearchMM);
+
+ if (!javaSearchMM.isEmpty())
+ manager.appendToGroup(fGroupId, javaSearchMM);
+ }
+
+ /*
+ * Method declared on ActionGroup.
+ */
+ public void dispose() {
+ ISelectionProvider provider= fSite.getSelectionProvider();
+ if (provider != null) {
+ disposeAction(fFindDeclarationsAction, provider);
+ disposeAction(fFindDeclarationsInProjectAction, provider);
+// disposeAction(fFindDeclarationsInHierarchyAction, provider);
+ disposeAction(fFindDeclarationsInWorkingSetAction, provider);
+ }
+ fFindDeclarationsAction= null;
+ fFindDeclarationsInProjectAction= null;
+// fFindDeclarationsInHierarchyAction= null;
+ fFindDeclarationsInWorkingSetAction= null;
+ updateGlobalActionHandlers();
+ super.dispose();
+ }
+
+ private void updateGlobalActionHandlers() {
+ if (fActionBars != null) {
+ fActionBars.setGlobalActionHandler(RdtActionConstants.FIND_DECLARATIONS_IN_WORKSPACE, fFindDeclarationsAction);
+ fActionBars.setGlobalActionHandler(RdtActionConstants.FIND_DECLARATIONS_IN_PROJECT, fFindDeclarationsInProjectAction);
+// fActionBars.setGlobalActionHandler(RdtActionConstants.FIND_DECLARATIONS_IN_HIERARCHY, fFindDeclarationsInHierarchyAction);
+ fActionBars.setGlobalActionHandler(RdtActionConstants.FIND_DECLARATIONS_IN_WORKING_SET, fFindDeclarationsInWorkingSetAction);
+ }
+ }
+
+ private void disposeAction(ISelectionChangedListener action, ISelectionProvider provider) {
+ if (action != null)
+ provider.removeSelectionChangedListener(action);
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsAction.java 2007-06-07 20:46:45 UTC (rev 2587)
@@ -0,0 +1,73 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IField;
+import org.rubypeople.rdt.core.IImportDeclaration;
+import org.rubypeople.rdt.core.IMethod;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceFolder;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.search.IRubySearchConstants;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+import org.rubypeople.rdt.internal.ui.search.SearchMessages;
+
+/**
+ * Finds declarations of the selected element in the workspace.
+ * The action is applicable to selections representing a Ruby element.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 1.0
+ */
+public class FindDeclarationsAction extends FindAction {
+
+ /**
+ * Creates a new <code>FindDeclarationsAction</code>. The action requires
+ * that the selection provided by the site's selection provider is of type <code>
+ * org.eclipse.jface.viewers.IStructuredSelection</code>.
+ *
+ * @param site the site providing context information for this action
+ */
+ public FindDeclarationsAction(IWorkbenchSite site) {
+ super(site);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ */
+ public FindDeclarationsAction(RubyEditor editor) {
+ super(editor);
+ }
+
+ void init() {
+ setText(SearchMessages.Search_FindDeclarationAction_label);
+ setToolTipText(SearchMessages.Search_FindDeclarationAction_tooltip);
+ setImageDescriptor(RubyPluginImages.DESC_OBJS_SEARCH_DECL);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.FIND_DECLARATIONS_IN_WORKSPACE_ACTION);
+ }
+
+ Class[] getValidTypes() {
+ return new Class[] { IField.class, IMethod.class, IType.class, IRubyScript.class, IImportDeclaration.class, ISourceFolder.class };
+ }
+
+ int getLimitTo() {
+ return IRubySearchConstants.DECLARATIONS | IRubySearchConstants.IGNORE_DECLARING_TYPE ;
+ }
+
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsInProjectAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsInProjectAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsInProjectAction.java 2007-06-07 20:46:45 UTC (rev 2587)
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.core.search.IRubySearchScope;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+import org.rubypeople.rdt.internal.ui.search.RubySearchScopeFactory;
+import org.rubypeople.rdt.internal.ui.search.SearchMessages;
+import org.rubypeople.rdt.ui.search.ElementQuerySpecification;
+import org.rubypeople.rdt.ui.search.QuerySpecification;
+
+/**
+ * Finds declarations of the selected element in the enclosing project
+ * of the selected element.
+ * The action is applicable to selections representing a Ruby element.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 1.0
+ */
+public class FindDeclarationsInProjectAction extends FindDeclarationsAction {
+
+ /**
+ * Creates a new <code>FindDeclarationsInProjectAction</code>. The action
+ * requires that the selection provided by the site's selection provider is of type
+ * <code>IStructuredSelection</code>.
+ *
+ * @param site the site providing context information for this action
+ */
+ public FindDeclarationsInProjectAction(IWorkbenchSite site) {
+ super(site);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ */
+ public FindDeclarationsInProjectAction(RubyEditor editor) {
+ super(editor);
+ }
+
+ void init() {
+ setText(SearchMessages.Search_FindDeclarationsInProjectAction_label);
+ setToolTipText(SearchMessages.Search_FindDeclarationsInProjectAction_tooltip);
+ setImageDescriptor(RubyPluginImages.DESC_OBJS_SEARCH_DECL);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.FIND_DECLARATIONS_IN_PROJECT_ACTION);
+ }
+
+ QuerySpecification createQuery(IRubyElement element) throws RubyModelException {
+ RubySearchScopeFactory factory= RubySearchScopeFactory.getInstance();
+ RubyEditor editor= getEditor();
+
+ IRubySearchScope scope;
+ String description;
+ boolean isInsideJRE= true;
+ if (editor != null) {
+ scope= factory.createRubyProjectSearchScope(editor.getEditorInput(), isInsideJRE);
+ description= factory.getProjectScopeDescription(editor.getEditorInput(), isInsideJRE);
+ } else {
+ scope= factory.createRubyProjectSearchScope(element.getRubyProject(), isInsideJRE);
+ description= factory.getProjectScopeDescription(element.getRubyProject(), isInsideJRE);
+ }
+ return new ElementQuerySpecification(element, getLimitTo(), scope, description);
+ }
+}
Added: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsInWorkingSetAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsInWorkingSetAction.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindDeclarationsInWorkingSetAction.java 2007-06-07 20:46:45 UTC (rev 2587)
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.ui.actions;
+
+import org.eclipse.ui.IWorkbenchSite;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.PlatformUI;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.core.search.IRubySearchScope;
+import org.rubypeople.rdt.internal.ui.IRubyHelpContextIds;
+import org.rubypeople.rdt.internal.ui.RubyPluginImages;
+import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
+import org.rubypeople.rdt.internal.ui.search.RubySearchScopeFactory;
+import org.rubypeople.rdt.internal.ui.search.SearchMessages;
+import org.rubypeople.rdt.internal.ui.search.SearchUtil;
+import org.rubypeople.rdt.ui.search.ElementQuerySpecification;
+import org.rubypeople.rdt.ui.search.QuerySpecification;
+
+/**
+ * Finds declarations of the selected element in working sets.
+ * The action is applicable to selections representing a Ruby element.
+ *
+ * <p>
+ * This class may be instantiated; it is not intended to be subclassed.
+ * </p>
+ *
+ * @since 2.0
+ */
+public class FindDeclarationsInWorkingSetAction extends FindDeclarationsAction {
+
+ private IWorkingSet[] fWorkingSet;
+
+ /**
+ * Creates a new <code>FindDeclarationsInWorkingSetAction</code>. The action
+ * requires that the selection provided by the site's selection provider is of type
+ * <code>org.eclipse.jface.viewers.IStructuredSelection</code>. The user will be
+ * prompted to select the working sets.
+ *
+ * @param site the site providing context information for this action
+ */
+ public FindDeclarationsInWorkingSetAction(IWorkbenchSite site) {
+ this(site, null);
+ }
+
+ /**
+ * Creates a new <code>FindDeclarationsInWorkingSetAction</code>. The action
+ * requires that the selection provided by the site's selection provider is of type
+ * <code>org.eclipse.jface.viewers.IStructuredSelection</code>.
+ *
+ * @param site the site providing context information for this action
+ * @param workingSets the working sets to be used in the search
+ */
+ public FindDeclarationsInWorkingSetAction(IWorkbenchSite site, IWorkingSet[] workingSets) {
+ super(site);
+ fWorkingSet= workingSets;
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ * @param editor the Ruby editor
+ */
+ public FindDeclarationsInWorkingSetAction(RubyEditor editor) {
+ this(editor, null);
+ }
+
+ /**
+ * Note: This constructor is for internal use only. Clients should not call this constructor.
+ *
+ * @param editor the Ruby editor
+ * @param workingSets the working sets to be used in the search
+ */
+ public FindDeclarationsInWorkingSetAction(RubyEditor editor, IWorkingSet[] workingSets) {
+ super(editor);
+ fWorkingSet= workingSets;
+ }
+
+ void init() {
+ setText(SearchMessages.Search_FindDeclarationsInWorkingSetAction_label);
+ setToolTipText(SearchMessages.Search_FindDeclarationsInWorkingSetAction_tooltip);
+ setImageDescriptor(RubyPluginImages.DESC_OBJS_SEARCH_DECL);
+ PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IRubyHelpContextIds.FIND_DECLARATIONS_IN_WORKING_SET_ACTION);
+ }
+
+ QuerySpecification createQuery(IRubyElement element) throws RubyModelException {
+ RubySearchScopeFactory factory= RubySearchScopeFactory.getInstance();
+
+ IWorkingSet[] workingSets= fWorkingSet;
+ if (fWorkingSet == null) {
+ workingSets= factory.queryWorkingSets();
+ if (workingSets == null)
+ return null;
+ }
+ SearchUtil.updateLRUWorkingSets(workingSets);
+ IRubySearchScope scope= factory.createRubySearchScope(workingSets, true);
+ String description= factory.getWorkingSetScopeDescription(workingSets, true);
+ return new ElementQuerySpecification(element, getLimitTo(), scope, description);
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java 2007-06-06 16:44:06 UTC (rev 2586)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java 2007-06-07 20:46:45 UTC (rev 2587)
@@ -114,6 +114,22 @@
* @since 1.0
*/
public static final String SEARCH_OCCURRENCES_IN_FILE= "org.rubypeople.rdt.ui.edit.text.ruby.search.occurrences.in.file"; //$NON-NLS-1$
+
+ /**
+ * Action definition ID of the search -> declarations in workspace action
+ * (value <code>"org.rubypeople.rdt.ui.edit.text.ruby.search.declarations.in.workspace"</code>).
+ */
+ public static final String SEARCH_DECLARATIONS_IN_WORKSPACE= "org.rubypeople.rdt.ui.edit.text.ruby.search.declarations.in.workspace"; //$NON-NLS-1$
+ /**
+ * Action definition ID of the search -> declarations in project action
+ * (value <code>"org.rubypeople.rdt.ui.edit.text.ruby.search.declarations.in.project"</code>).
+ */
+ public static final String SEARCH_DECLARATIONS_IN_PROJECTS= "org.rubypeople.rdt.ui.edit.text.ruby.search.declarations.in.project"; //$NON-NLS-1$
+ /**
+ * Action definition ID of the search -> declarations in working set action
+ * (value <code>"org.rubypeople.rdt.ui.edit.text.ruby.search.declarations.in.working.set"</code>).
+ */
+ public static final String SEARCH_DECLARATIONS_IN_WORKING_SET= "org.rubypeople.rdt.ui.edit.text.ruby.search.declarations.in.working.set"; //$NON-NLS-1$
+
-
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-06-06 16:44:06 UTC (rev 2586)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java 2007-06-07 20:46:45 UTC (rev 2587)
@@ -60,4 +60,23 @@
*/
public static final String FIND_OCCURRENCES_IN_FILE= "org.rubypeople.rdt.ui.actions.OccurrencesInFile"; //$NON-NLS-1$
+
+ /**
+ * Search menu: name of standard Find Declarations in Workspace global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.DeclarationsInWorkspace"</code>).
+ */
+ public static final String FIND_DECLARATIONS_IN_WORKSPACE= "org.rubypeople.rdt.ui.actions.DeclarationsInWorkspace"; //$NON-NLS-1$
+
+ /**
+ * Search menu: name of standard Find Declarations in Project global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.DeclarationsInProject"</code>).
+ */
+ public static final String FIND_DECLARATIONS_IN_PROJECT= "org.rubypeople.rdt.ui.actions.DeclarationsInProject"; //$NON-NLS-1$
+
+ /**
+ * Search menu: name of standard Find Declarations in Working Set global action
+ * (value <code>"org.rubypeople.rdt.ui.actions.DeclarationsInWorkingSet"</code>).
+ */
+ public static final String FIND_DECLARATIONS_IN_WORKING_SET= "org.rubypeople.rdt.ui.actions.DeclarationsInWorkingSet"; //$NON-NLS-1$
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java 2007-06-06 16:44:06 UTC (rev 2586)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java 2007-06-07 20:46:45 UTC (rev 2587)
@@ -43,7 +43,7 @@
private ReferencesSearchGroup fReferencesGroup;
private ReadReferencesSearchGroup fReadAccessGroup;
// private WriteReferencesSearchGroup fWriteAccessGroup;
-// private DeclarationsSearchGroup fDeclarationsGroup;
+ private DeclarationsSearchGroup fDeclarationsGroup;
// private ImplementorsSearchGroup fImplementorsGroup;
private OccurrencesSearchGroup fOccurrencesGroup;
@@ -81,7 +81,7 @@
fReferencesGroup= new ReferencesSearchGroup(fEditor);
fReadAccessGroup= new ReadReferencesSearchGroup(fEditor);
// fWriteAccessGroup= new WriteReferencesSearchGroup(fEditor);
-// fDeclarationsGroup= new DeclarationsSearchGroup(fEditor);
+ fDeclarationsGroup= new DeclarationsSearchGroup(fEditor);
// fImplementorsGroup= new ImplementorsSearchGroup(fEditor);
fOccurrencesGroup= new OccurrencesSearchGroup(fEditor);
}
@@ -90,7 +90,7 @@
fReferencesGroup= new ReferencesSearchGroup(site);
fReadAccessGroup= new ReadReferencesSearchGroup(site);
// fWriteAccessGroup= new WriteReferencesSearchGroup(site);
-// fDeclarationsGroup= new DeclarationsSearchGroup(site);
+ fDeclarationsGroup= new DeclarationsSearchGroup(site);
// fImplementorsGroup= new ImplementorsSearchGroup(site);
fOccurrencesGroup= new OccurrencesSearchGroup(site);
}
@@ -100,7 +100,7 @@
*/
public void setContext(ActionContext context) {
fReferencesGroup.setContext(context);
-// fDeclarationsGroup.setContext(context);
+ fDeclarationsGroup.setContext(context);
// fImplementorsGroup.setContext(context);
fReadAccessGroup.setContext(context);
// fWriteAccessGroup.setContext(context);
@@ -113,7 +113,7 @@
public void fillActionBars(IActionBars actionBar) {
super.fillActionBars(actionBar);
fReferencesGroup.fillActionBars(actionBar);
-// fDeclarationsGroup.fillActionBars(actionBar);
+ fDeclarationsGroup.fillActionBars(actionBar);
// fImplementorsGroup.fillActionBars(actionBar);
fReadAccessGroup.fillActionBars(actionBar);
// fWriteAccessGroup.fillActionBars(actionBar);
@@ -128,7 +128,7 @@
if(PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.SEARCH_USE_REDUCED_MENU)) {
fReferencesGroup.fillContextMenu(menu);
-// fDeclarationsGroup.fillContextMenu(menu);
+ fDeclarationsGroup.fillContextMenu(menu);
if (fEditor == null) {
// fImplementorsGroup.fillContextMenu(menu);
@@ -146,7 +146,7 @@
}
fReferencesGroup.fillContextMenu(target);
-// fDeclarationsGroup.fillContextMenu(target);
+ fDeclarationsGroup.fillContextMenu(target);
// fImplementorsGroup.fillContextMenu(target);
fReadAccessGroup.fillContextMenu(target);
// fWriteAccessGroup.fillContextMenu(target);
@@ -168,7 +168,7 @@
*/
public void dispose() {
fReferencesGroup.dispose();
-// fDeclarationsGroup.dispose();
+ fDeclarationsGroup.dispose();
// fImplementorsGroup.dispose();
fReadAccessGroup.dispose();
// fWriteAccessGroup.dispose();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-06 16:44:07
|
Revision: 2586
http://svn.sourceforge.net/rubyeclipse/?rev=2586&view=rev
Author: cawilliams
Date: 2007-06-06 09:44:06 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
handle remembering write usages as well as just normal occurrences
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java 2007-06-06 16:40:25 UTC (rev 2585)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java 2007-06-06 16:44:06 UTC (rev 2586)
@@ -21,6 +21,7 @@
import org.jruby.ast.ClassVarDeclNode;
import org.jruby.ast.ClassVarNode;
import org.jruby.ast.Colon2Node;
+import org.jruby.ast.ConstDeclNode;
import org.jruby.ast.ConstNode;
import org.jruby.ast.DAsgnNode;
import org.jruby.ast.DVarNode;
@@ -278,7 +279,7 @@
* @return
*/
private boolean isConstRef(Node node) {
- return (node instanceof ConstNode);
+ return (node instanceof ConstNode) || (node instanceof ConstDeclNode);
}
/**
@@ -339,6 +340,7 @@
// Scrape position from pertinent nodes
for (Node searchResult : searchResults) {
occurrences.add(searchResult);
+ if (searchResult instanceof LocalAsgnNode) fWriteUsages.add(searchResult);
}
}
@@ -381,6 +383,7 @@
// Scrape position from pertinent nodes
for (Node searchResult : searchResults) {
occurrences.add(searchResult);
+ if (searchResult instanceof DAsgnNode) fWriteUsages.add(searchResult);
}
}
@@ -395,7 +398,7 @@
Node searchSpace = determineSearchSpace(root, orig);
// Finalize searchSpace because Java's scoping rules are the awesome
- // todo: not needed?
+ // TODO: not needed?
// final Node finalSearchSpace = searchSpace;
// Get name of local variable reference
@@ -415,6 +418,7 @@
// Scrape position from pertinent nodes
for (Node searchResult : searchResults) {
occurrences.add(searchResult);
+ if (searchResult instanceof InstAsgnNode) fWriteUsages.add(searchResult);
}
}
@@ -483,6 +487,7 @@
// Scrape position from pertinent nodes
for (Node searchResult : searchResults) {
occurrences.add(searchResult);
+ if ((searchResult instanceof ClassVarAsgnNode) || (searchResult instanceof ClassVarDeclNode)) fWriteUsages.add(searchResult);
}
}
@@ -508,6 +513,7 @@
// Scrape position from pertinent nodes
for (Node searchResult : searchResults) {
occurrences.add(searchResult);
+ if (searchResult instanceof GlobalAsgnNode) fWriteUsages.add(searchResult);
}
}
@@ -577,6 +583,7 @@
for (Node searchResult : searchResults) {
occurrences.add(searchResult);
+ if (searchResult instanceof ConstDeclNode) fWriteUsages.add(searchResult);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-06 16:41:26
|
Revision: 2585
http://svn.sourceforge.net/rubyeclipse/?rev=2585&view=rev
Author: cawilliams
Date: 2007-06-06 09:40:25 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
when grabbing the RI or Rdoc paths, if we can't find the normal scripts, try appending the major version number to end for those weird OS installs like Debian (where they install ri1.8 and rdoc1.8 rather than ri and rdoc)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java 2007-06-06 14:37:04 UTC (rev 2584)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java 2007-06-06 16:40:25 UTC (rev 2585)
@@ -1674,6 +1674,20 @@
if (Platform.getOS().equals(Platform.OS_WIN32)) {
path += ".bat";
}
+ File file = new File(path);
+ if (file.exists()) return file;
+ // try adding major version number to end of command for OSes like Debian that do ri1.8
+ if (vm instanceof IVMInstall2) {
+ IVMInstall2 vm2 = (IVMInstall2) vm;
+ String version = vm2.getRubyVersion();
+ if (version == null || version.length() < 3) return file;
+ version = version.substring(0, 3);
+ path = installLocation.getAbsolutePath() + File.separator + "bin"
+ + File.separator + command + version;
+ if (Platform.getOS().equals(Platform.OS_WIN32)) {
+ path += ".bat";
+ }
+ }
return new File(path);
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-06 14:37:07
|
Revision: 2584
http://svn.sourceforge.net/rubyeclipse/?rev=2584&view=rev
Author: cawilliams
Date: 2007-06-06 07:37:04 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
rename DefaultOccurrencesFinder to OccurrencesFinder to match JDT more
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindOccurrencesInFileAction.java
trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2007-06-06 14:34:57 UTC (rev 2583)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2007-06-06 14:37:04 UTC (rev 2584)
@@ -82,7 +82,7 @@
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor.ITextConverter;
-import org.rubypeople.rdt.internal.ui.search.DefaultOccurrencesFinder;
+import org.rubypeople.rdt.internal.ui.search.OccurrencesFinder;
import org.rubypeople.rdt.internal.ui.search.IOccurrencesFinder;
import org.rubypeople.rdt.internal.ui.text.ContentAssistPreference;
import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
@@ -1422,7 +1422,7 @@
protected void installOccurrencesFinder(boolean forceUpdate) {
fMarkOccurrenceAnnotations= true;
- fOccurrencesFinder = new DefaultOccurrencesFinder();
+ fOccurrencesFinder = new OccurrencesFinder();
fPostSelectionListener = new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
Deleted: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java 2007-06-06 14:34:57 UTC (rev 2583)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java 2007-06-06 14:37:04 UTC (rev 2584)
@@ -1,729 +0,0 @@
-package org.rubypeople.rdt.internal.ui.search;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.LinkedList;
-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.Position;
-import org.eclipse.search.ui.text.Match;
-import org.jruby.ast.ArgumentNode;
-import org.jruby.ast.BlockArgNode;
-import org.jruby.ast.BlockNode;
-import org.jruby.ast.ClassNode;
-import org.jruby.ast.ClassVarAsgnNode;
-import org.jruby.ast.ClassVarDeclNode;
-import org.jruby.ast.ClassVarNode;
-import org.jruby.ast.Colon2Node;
-import org.jruby.ast.ConstNode;
-import org.jruby.ast.DAsgnNode;
-import org.jruby.ast.DVarNode;
-import org.jruby.ast.DefnNode;
-import org.jruby.ast.DefsNode;
-import org.jruby.ast.GlobalAsgnNode;
-import org.jruby.ast.GlobalVarNode;
-import org.jruby.ast.InstAsgnNode;
-import org.jruby.ast.InstVarNode;
-import org.jruby.ast.LocalAsgnNode;
-import org.jruby.ast.LocalVarNode;
-import org.jruby.ast.ModuleNode;
-import org.jruby.ast.Node;
-import org.jruby.ast.ReturnNode;
-import org.jruby.ast.SymbolNode;
-import org.jruby.lexer.yacc.ISourcePosition;
-import org.jruby.lexer.yacc.SourcePosition;
-import org.jruby.lexer.yacc.SyntaxException;
-import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.internal.core.parser.RubyParser;
-import org.rubypeople.rdt.internal.core.util.ASTUtil;
-import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator;
-import org.rubypeople.rdt.internal.ti.util.INodeAcceptor;
-import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator;
-import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator;
-
-/**
- * Implements "Mark Occurences" feature
- *
- * @author Jason Morrison
- *
- */
-public class DefaultOccurrencesFinder extends AbstractOccurencesFinder {
-
- // Root of the document to search
- private Node root;
-
- // Originating node; corresponds to cursor selection
- private Node fSelectedNode;
-
- private List<Node> fUsages= new ArrayList<Node>();
- private List<Node> fWriteUsages= new ArrayList<Node>();
-
- // Original source
- private String source;
-
- public String getJobLabel() {
- return SearchMessages.OccurrencesFinder_searchfor;
- }
-
- public String getUnformattedPluralLabel() {
- return SearchMessages.OccurrencesFinder_label_plural;
- }
-
- public String getUnformattedSingularLabel() {
- return SearchMessages.OccurrencesFinder_label_singular;
- }
-
- public void collectOccurrenceMatches(IRubyElement element, IDocument document, Collection resultingMatches) {
- HashMap lineToGroup= new HashMap();
-
- for (Iterator iter= fUsages.iterator(); iter.hasNext();) {
- Node node= (Node) iter.next();
- ISourcePosition position = getPositionOfName(node);
- int startPosition= position.getStartOffset();
- int length= position.getEndOffset() - position.getStartOffset();
- try {
- boolean isWriteAccess= fWriteUsages.contains(node);
- int line= document.getLineOfOffset(startPosition);
- Integer lineInteger= new Integer(line);
- OccurrencesGroupKey groupKey= (OccurrencesGroupKey) lineToGroup.get(lineInteger);
- if (groupKey == null) {
- IRegion region= document.getLineInformation(line);
- String lineContents= document.get(region.getOffset(), region.getLength()).trim();
- groupKey= new OccurrencesGroupKey(element, line, lineContents, isWriteAccess, isVariable(element));
- lineToGroup.put(lineInteger, groupKey);
- } else if (isWriteAccess) {
- // a line with read an write access is considered as write access:
- groupKey.setWriteAccess(true);
- }
- Match match= new Match(groupKey, startPosition, length);
- resultingMatches.add(match);
- } catch (BadLocationException e) {
- //nothing
- }
- }
- }
-
- private boolean isVariable(IRubyElement element) {
- return element.isType(IRubyElement.INSTANCE_VAR) || element.isType(IRubyElement.GLOBAL) || element.isType(IRubyElement.CLASS_VAR) || element.isType(IRubyElement.LOCAL_VARIABLE) || element.isType(IRubyElement.DYNAMIC_VAR);
- }
-
- public String initialize(Node root, int offset, int length) {
- if (root == null) {
- return null;
- }
- this.root = root;
- this.fSelectedNode = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset);
- if (fSelectedNode == null) {
- return SearchMessages.OccurrencesFinder_no_element;
- }
-// if (fSelectedNode.getPosition().getEndOffset() > offset + length) {
-// // Selection spans nodes; not handling that for now.
-// return "Selection spans nodes; can only search for a single node.";
-// }
- return null;
- }
-
- public String initialize(String source, int offset, int length) {
- if (source == null) {
- return null;
- } else {
- this.source = source;
- }
-
- Node root = null;
- try {
- RubyParser rubyParser = new RubyParser();
- root = rubyParser.parse(source);
- }
- // TODO: Is there anything else the parsing could choke on that should
- // be silently ignored with no markings?
- catch (SyntaxException se) {
- // ignore
- }
- return initialize(root, offset, length);
- }
-
- /**
- * Determines the kind of originating node, and collects occurrences
- * accordingly
- */
- public List<Position> perform() {
- // Mark no occurrences if root is null (AST couldn't be parsed
- // correctly.)
- if (root == null)
- return new LinkedList<Position>();
- if (fSelectedNode == null)
- return new LinkedList<Position>();
-
- if (fMarkLocalVariableOccurrences && isLocalVarRef(fSelectedNode)) {
- pushLocalVarRefs(root, fSelectedNode, fUsages);
- }
-
- if (fMarkLocalVariableOccurrences && isDVarRef(fSelectedNode)) {
- pushDVarRefs(root, fSelectedNode, fUsages);
- }
-
- if (fMarkLocalVariableOccurrences && isInstanceVarRef(fSelectedNode)) {
- pushInstVarRefs(root, fSelectedNode, fUsages);
- }
-
- if (fMarkLocalVariableOccurrences && isClassVarRef(fSelectedNode)) {
- pushClassVarRefs(root, fSelectedNode, fUsages);
- }
-
- if (fMarkLocalVariableOccurrences && isGlobalVarRef(fSelectedNode)) {
- pushGlobalVarRefs(root, fSelectedNode, fUsages);
- }
-
- if (fMarkConstantOccurrences && fSelectedNode instanceof SymbolNode) {
- pushSymbolRefs(root, fSelectedNode, fUsages);
- }
-
- // if ( isMethodRefNode(fSelectedNode)) {
- // pushMethodRefs( root, fSelectedNode, occurrences );
- // }
-
- if (fMarkConstantOccurrences && isConstRef(fSelectedNode)) {
- pushConstRefs(root, fSelectedNode, fUsages);
- }
-
- if (fMarkTypeOccurrences && isTypeRef(fSelectedNode)) {
- pushTypeRefs(root, fSelectedNode, fUsages);
- }
-
- if (fMarkMethodExitPoints) {
- pushReturns(root, fSelectedNode, fUsages);
- }
-
- // Convert ISourcePosition to IPosition
- List<Position> positions = new LinkedList<Position>();
- for (Node node : fUsages) {
- ISourcePosition occurrence = getPositionOfName(node);
- Position position = new Position(occurrence.getStartOffset(), occurrence.getEndOffset() - occurrence.getStartOffset());
- positions.add(position);
- }
-
- // Uniqueify positions
- positions = new LinkedList<Position>(new HashSet<Position>(positions));
-
- return positions;
- }
-
- // ****************************************************************************
- // *
- // * Reference kind definitions
- // *
- // ****************************************************************************
-
- /**
- * Determines whether a given node is a local variable reference
- *
- * @param node
- * @return
- */
- private boolean isLocalVarRef(Node node) {
- return ((node instanceof LocalAsgnNode) || (node instanceof ArgumentNode) || (node instanceof LocalVarNode));
- }
-
- /**
- * Determines whether a given node is a dynamic variable reference
- *
- * @param node
- * @return
- */
- private boolean isDVarRef(Node node) {
- return ((node instanceof DVarNode) || (node instanceof DAsgnNode));
- }
-
- /**
- * Determines whether a given node is an instance variable reference
- *
- * @param node
- * @return
- */
- private boolean isInstanceVarRef(Node node) {
- return ((node instanceof InstAsgnNode) || (node instanceof InstVarNode));
- }
-
- /**
- * Determines whether a given node is a class variable reference
- *
- * @param node
- * @return
- */
- private boolean isClassVarRef(Node node) {
- return ((node instanceof ClassVarNode) || (node instanceof ClassVarAsgnNode) || (node instanceof ClassVarDeclNode));
- }
-
- /**
- * Determines whether a given node is a global variable reference
- *
- * @param node
- * @return
- */
- private boolean isGlobalVarRef(Node node) {
- return ((node instanceof GlobalAsgnNode) || (node instanceof GlobalVarNode));
- }
-
- /**
- * Determines whether a given node is a constant reference (constant)
- *
- * @param node
- * @return
- */
- private boolean isConstRef(Node node) {
- return (node instanceof ConstNode);
- }
-
- /**
- * Determines whether a given node is a type reference (class, module)
- *
- * @param node
- * @return
- */
- private boolean isTypeRef(Node node) {
- // TODO: Classes can be referred to as a ConstNode; i.e. "class
- // Klass;end; k = Klass.new" the last reference is a ConstNode, not a
- // ClassNode. Special way to handle this?
- return ((node instanceof ClassNode) || (node instanceof ModuleNode) || (node instanceof ConstNode));
- }
-
- // ****************************************************************************
- // *
- // * Worker methods - handles delegation of occurrence searches
- // *
- // ****************************************************************************
-
- /**
- * Collects all corresponding local variable occurrences
- *
- * @param root
- * Root node to search
- * @param fSelectedNode
- * Originating node
- * @param occurrences
- */
- private void pushLocalVarRefs(Node root, Node orig, List<Node> occurrences) {
- // Find the search space
- Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
- }
- });
-
- // If no enclosing node found, search the entire space
- if (searchSpace == null) {
- searchSpace = root;
- }
-
- // Finalize searchSpace because Java's scoping rules are the awesome
- final Node finalSearchSpace = searchSpace;
-
- // Get name of local variable reference
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- String name = ASTUtil.getNameReflectively(node);
- return (name != null && name.equals(origName));
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
- }
-
- /**
- * Collects all corresponding dynamic variable occurrences
- *
- * @param root
- * Root node to search
- * @param fSelectedNode
- * Originating node
- * @param occurrences
- */
- private void pushDVarRefs(Node root, Node orig, List<Node> occurrences) {
- // Find the search space
- Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
- }
- });
-
- // If no enclosing node found, search the entire space
- if (searchSpace == null) {
- searchSpace = root;
- }
-
- // Get name of local variable reference
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isDVarRef(node)) {
- String name = ASTUtil.getNameReflectively(node);
- return (name != null && name.equals(origName));
- }
- return false;
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
- }
-
- /**
- * Collects all instance variable occurrences
- *
- * @param root
- * @param fSelectedNode
- * @param occurrences
- */
- private void pushInstVarRefs(Node root, Node orig, List<Node> occurrences) {
- Node searchSpace = determineSearchSpace(root, orig);
-
- // Finalize searchSpace because Java's scoping rules are the awesome
- // todo: not needed?
- // final Node finalSearchSpace = searchSpace;
-
- // Get name of local variable reference
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isInstanceVarRef(node)) {
- String name = ASTUtil.getNameReflectively(node);
- return (name != null && name.equals(origName));
- }
- return false;
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
-
- }
-
- private Node determineSearchSpace(Node root, Node orig) {
-
- // Find the name of the enclosing class
- ClassNode enclosingClass = (ClassNode) FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return (node instanceof ClassNode);
- }
- });
-
- // If no enclosing class is identified, search root.
- if (enclosingClass == null) {
- return root;
- }
- // Find the search space - all ClassNodes for that name within root
- // scope
- else {
- final String className = getClassNodeName(enclosingClass);
- List<Node> classNodes = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (node instanceof ClassNode) {
- return getClassNodeName((ClassNode) node).equals(className);
- }
- return false;
- }
- });
- BlockNode blockNode = new BlockNode(new SourcePosition());
- for (Node classNode : classNodes) {
- blockNode.add(classNode);
- }
- return blockNode;
- }
- }
-
- /**
- * Collects all class variable occurrences
- *
- * @param root
- * @param fSelectedNode
- * @param occurrences
- */
- private void pushClassVarRefs(Node root, Node orig, List<Node> occurrences) {
- Node searchSpace = determineSearchSpace(root, orig);
-
- // Finalize searchSpace because Java's scoping rules are the awesome
- // todo: not needed?
- // final Node finalSearchSpace = searchSpace;
-
- // Get name of local variable reference
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isClassVarRef(node)) {
- String name = ASTUtil.getNameReflectively(node);
- return (name != null && name.equals(origName));
- }
- return false;
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
-
- }
-
- /**
- * Collects all global variable occurrences
- *
- * @param root
- * @param fSelectedNode
- * @param occurrences
- */
- private void pushGlobalVarRefs(Node root, Node orig, List<Node> occurrences) {
- final Node searchSpace = root;
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return isGlobalVarRef(node) && ASTUtil.getNameReflectively(node).equals(origName);
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
- }
-
- /**
- * Collects all symbol occurrences
- *
- * @param root
- * @param fSelectedNode
- * @param occurrences
- */
- private void pushSymbolRefs(Node root, Node orig, List<Node> occurrences) {
- final Node searchSpace = root;
- final String origName = ((SymbolNode) orig).getName();
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return (node instanceof SymbolNode) && ((SymbolNode) node).getName().equals(origName);
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
- }
-
- // todo: complete
- // private void pushMethodRefs( Node root, Node fSelectedNode, List<ISourcePosition>
- // occurrences) {
- //
- // // DefnNode DefsNode CallNode VCallNode
- //
- // System.out.println("Finding occurrences for method reference node " +
- // fSelectedNode.toString() );
- //
- // final Node searchSpace = root;
- // String origName = getMethodRefName(fSelectedNode);
- //
- // // If fSelectedNode is a method definition, find all occurrences to that selector
- // for the fSelectedNode's enclosing type
- // if ( fSelectedNode instanceof DefnNode || fSelectedNode instanceof DefsNode )
- // {
- // ((DefnNode)fSelectedNode).g
- // }
- //
- // Node receiver = getMethodReceiver(fSelectedNode);
- // }
-
- /**
- * Collects all pertinent const occurrences
- */
- private void pushConstRefs(Node root, Node orig, List<Node> occurrences) {
- if (!isConstRef(orig)) {
- return;
- }
-
- final String matchName = ASTUtil.getNameReflectively(orig);
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isConstRef(node)) {
- return ASTUtil.getNameReflectively(node).equals(matchName);
- }
- return false;
- }
- });
-
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
- }
-
- /**
- * Collects all pertinent type ref occurrences
- */
- private void pushTypeRefs(Node root, Node orig, List<Node> occurrences) {
- if (!isTypeRef(orig)) {
- return;
- }
-
- final String matchName = ASTUtil.getNameReflectively(orig);
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isTypeRef(node)) {
- return getTypeRefName(node).equals(matchName);
- }
- return false;
- }
- });
-
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
- }
-
- private void pushReturns(Node root, Node orig, List<Node> occurrences) {
- // TODO Combine most of this stuff with the stuff in pushLocalVareRefs
- // Find the search space
- Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
- }
- });
-
- // If no enclosing node found, search the entire space
- if (searchSpace == null) {
- searchSpace = root;
- }
-// Find all return nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return (node instanceof ReturnNode);
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult);
- }
- }
-
- // ****************************************************************************
- // *
- // * Utility methods
- // *
- // ****************************************************************************
-
- /**
- * Gets the position of the name for the specified node.
- *
- * @param node
- * Node that responds to getName() or some variant
- * @return ISourcePosition that holds the name of the node
- */
- private ISourcePosition getPositionOfName(Node node) {
- ISourcePosition pos = node.getPosition();
-
- // TODO refactor the getting-of-name
- String name = null;
- if (node instanceof ReturnNode) {
- return node.getPosition();
- } else if (isLocalVarRef(node) || isDVarRef(node) || isInstanceVarRef(node) || isGlobalVarRef(node) || isClassVarRef(node) || isConstRef(node) || node instanceof BlockArgNode) {
- name = ASTUtil.getNameReflectively(node);
- } else if (node instanceof ClassNode) {
- name = getClassNodeName((ClassNode) node);
- String classDeclString = source.substring(pos.getStartOffset(), pos.getEndOffset());
- int begin = pos.getStartOffset() + classDeclString.indexOf(name);
- return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), begin, begin + name.length());
- } else if (node instanceof ModuleNode) {
- name = getModuleNodeName((ModuleNode) node);
- String moduleDeclString = source.substring(pos.getStartOffset(), pos.getEndOffset());
- int begin = moduleDeclString.indexOf(name);
- return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), begin, begin + name.length());
- } else if (node instanceof SymbolNode) {
- // XXX: This is a hack to get around improper offsets in my JRuby
- // copy; ":foo" returns offset for ":fo", so compensate by adding
- // one
- name = ((SymbolNode) node).getName();
- return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() + 1);
- }
-
- if (name == null) {
- throw new RuntimeException("Couldn't get the name for: " + node.toString());
- }
- return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length());
- }
-
- /**
- * Helper method to get the class name froma ClassNode
- *
- * @param classNode
- * @return
- */
- private String getClassNodeName(ClassNode classNode) {
- if (classNode.getCPath() instanceof Colon2Node) {
- Colon2Node c2node = (Colon2Node) classNode.getCPath();
- return c2node.getName();
- }
- throw new RuntimeException("ClassNode.getCPath() returned other than Colon2Node: " + classNode.toString());
- }
-
- /**
- * Helper method to get the class name from a ModuleNode
- *
- * @param classNode
- * @return
- */
- private String getModuleNodeName(ModuleNode moduleNode) {
- if (moduleNode.getCPath() instanceof Colon2Node) {
- Colon2Node c2node = (Colon2Node) moduleNode.getCPath();
- return c2node.getName();
- }
- throw new RuntimeException("ModuleNode.getCPath() returned other than Colon2Node: " + moduleNode.toString());
- }
-
- /**
- * Helper method to get the class name from a const ref node (Class/Module)
- *
- * @param node
- * @return
- */
- private String getTypeRefName(Node node) {
- if (node instanceof ClassNode) {
- return getClassNodeName((ClassNode) node);
- }
- if (node instanceof ModuleNode) {
- return getModuleNodeName((ModuleNode) node);
- }
- return ASTUtil.getNameReflectively(node);
- }
-
- public String getElementName() {
- if (fSelectedNode != null) {
- return ASTUtil.stringRepresentation(fSelectedNode);
- }
- return null;
- }
-
-}
Copied: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java (from rev 2583, trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java)
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesFinder.java 2007-06-06 14:37:04 UTC (rev 2584)
@@ -0,0 +1,729 @@
+package org.rubypeople.rdt.internal.ui.search;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+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.Position;
+import org.eclipse.search.ui.text.Match;
+import org.jruby.ast.ArgumentNode;
+import org.jruby.ast.BlockArgNode;
+import org.jruby.ast.BlockNode;
+import org.jruby.ast.ClassNode;
+import org.jruby.ast.ClassVarAsgnNode;
+import org.jruby.ast.ClassVarDeclNode;
+import org.jruby.ast.ClassVarNode;
+import org.jruby.ast.Colon2Node;
+import org.jruby.ast.ConstNode;
+import org.jruby.ast.DAsgnNode;
+import org.jruby.ast.DVarNode;
+import org.jruby.ast.DefnNode;
+import org.jruby.ast.DefsNode;
+import org.jruby.ast.GlobalAsgnNode;
+import org.jruby.ast.GlobalVarNode;
+import org.jruby.ast.InstAsgnNode;
+import org.jruby.ast.InstVarNode;
+import org.jruby.ast.LocalAsgnNode;
+import org.jruby.ast.LocalVarNode;
+import org.jruby.ast.ModuleNode;
+import org.jruby.ast.Node;
+import org.jruby.ast.ReturnNode;
+import org.jruby.ast.SymbolNode;
+import org.jruby.lexer.yacc.ISourcePosition;
+import org.jruby.lexer.yacc.SourcePosition;
+import org.jruby.lexer.yacc.SyntaxException;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.internal.core.parser.RubyParser;
+import org.rubypeople.rdt.internal.core.util.ASTUtil;
+import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator;
+import org.rubypeople.rdt.internal.ti.util.INodeAcceptor;
+import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator;
+import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator;
+
+/**
+ * Implements "Mark Occurences" feature
+ *
+ * @author Jason Morrison
+ *
+ */
+public class OccurrencesFinder extends AbstractOccurencesFinder {
+
+ // Root of the document to search
+ private Node root;
+
+ // Originating node; corresponds to cursor selection
+ private Node fSelectedNode;
+
+ private List<Node> fUsages= new ArrayList<Node>();
+ private List<Node> fWriteUsages= new ArrayList<Node>();
+
+ // Original source
+ private String source;
+
+ public String getJobLabel() {
+ return SearchMessages.OccurrencesFinder_searchfor;
+ }
+
+ public String getUnformattedPluralLabel() {
+ return SearchMessages.OccurrencesFinder_label_plural;
+ }
+
+ public String getUnformattedSingularLabel() {
+ return SearchMessages.OccurrencesFinder_label_singular;
+ }
+
+ public void collectOccurrenceMatches(IRubyElement element, IDocument document, Collection resultingMatches) {
+ HashMap lineToGroup= new HashMap();
+
+ for (Iterator iter= fUsages.iterator(); iter.hasNext();) {
+ Node node= (Node) iter.next();
+ ISourcePosition position = getPositionOfName(node);
+ int startPosition= position.getStartOffset();
+ int length= position.getEndOffset() - position.getStartOffset();
+ try {
+ boolean isWriteAccess= fWriteUsages.contains(node);
+ int line= document.getLineOfOffset(startPosition);
+ Integer lineInteger= new Integer(line);
+ OccurrencesGroupKey groupKey= (OccurrencesGroupKey) lineToGroup.get(lineInteger);
+ if (groupKey == null) {
+ IRegion region= document.getLineInformation(line);
+ String lineContents= document.get(region.getOffset(), region.getLength()).trim();
+ groupKey= new OccurrencesGroupKey(element, line, lineContents, isWriteAccess, isVariable(element));
+ lineToGroup.put(lineInteger, groupKey);
+ } else if (isWriteAccess) {
+ // a line with read an write access is considered as write access:
+ groupKey.setWriteAccess(true);
+ }
+ Match match= new Match(groupKey, startPosition, length);
+ resultingMatches.add(match);
+ } catch (BadLocationException e) {
+ //nothing
+ }
+ }
+ }
+
+ private boolean isVariable(IRubyElement element) {
+ return element.isType(IRubyElement.INSTANCE_VAR) || element.isType(IRubyElement.GLOBAL) || element.isType(IRubyElement.CLASS_VAR) || element.isType(IRubyElement.LOCAL_VARIABLE) || element.isType(IRubyElement.DYNAMIC_VAR);
+ }
+
+ public String initialize(Node root, int offset, int length) {
+ if (root == null) {
+ return null;
+ }
+ this.root = root;
+ this.fSelectedNode = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset);
+ if (fSelectedNode == null) {
+ return SearchMessages.OccurrencesFinder_no_element;
+ }
+// if (fSelectedNode.getPosition().getEndOffset() > offset + length) {
+// // Selection spans nodes; not handling that for now.
+// return "Selection spans nodes; can only search for a single node.";
+// }
+ return null;
+ }
+
+ public String initialize(String source, int offset, int length) {
+ if (source == null) {
+ return null;
+ } else {
+ this.source = source;
+ }
+
+ Node root = null;
+ try {
+ RubyParser rubyParser = new RubyParser();
+ root = rubyParser.parse(source);
+ }
+ // TODO: Is there anything else the parsing could choke on that should
+ // be silently ignored with no markings?
+ catch (SyntaxException se) {
+ // ignore
+ }
+ return initialize(root, offset, length);
+ }
+
+ /**
+ * Determines the kind of originating node, and collects occurrences
+ * accordingly
+ */
+ public List<Position> perform() {
+ // Mark no occurrences if root is null (AST couldn't be parsed
+ // correctly.)
+ if (root == null)
+ return new LinkedList<Position>();
+ if (fSelectedNode == null)
+ return new LinkedList<Position>();
+
+ if (fMarkLocalVariableOccurrences && isLocalVarRef(fSelectedNode)) {
+ pushLocalVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkLocalVariableOccurrences && isDVarRef(fSelectedNode)) {
+ pushDVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkLocalVariableOccurrences && isInstanceVarRef(fSelectedNode)) {
+ pushInstVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkLocalVariableOccurrences && isClassVarRef(fSelectedNode)) {
+ pushClassVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkLocalVariableOccurrences && isGlobalVarRef(fSelectedNode)) {
+ pushGlobalVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkConstantOccurrences && fSelectedNode instanceof SymbolNode) {
+ pushSymbolRefs(root, fSelectedNode, fUsages);
+ }
+
+ // if ( isMethodRefNode(fSelectedNode)) {
+ // pushMethodRefs( root, fSelectedNode, occurrences );
+ // }
+
+ if (fMarkConstantOccurrences && isConstRef(fSelectedNode)) {
+ pushConstRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkTypeOccurrences && isTypeRef(fSelectedNode)) {
+ pushTypeRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkMethodExitPoints) {
+ pushReturns(root, fSelectedNode, fUsages);
+ }
+
+ // Convert ISourcePosition to IPosition
+ List<Position> positions = new LinkedList<Position>();
+ for (Node node : fUsages) {
+ ISourcePosition occurrence = getPositionOfName(node);
+ Position position = new Position(occurrence.getStartOffset(), occurrence.getEndOffset() - occurrence.getStartOffset());
+ positions.add(position);
+ }
+
+ // Uniqueify positions
+ positions = new LinkedList<Position>(new HashSet<Position>(positions));
+
+ return positions;
+ }
+
+ // ****************************************************************************
+ // *
+ // * Reference kind definitions
+ // *
+ // ****************************************************************************
+
+ /**
+ * Determines whether a given node is a local variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isLocalVarRef(Node node) {
+ return ((node instanceof LocalAsgnNode) || (node instanceof ArgumentNode) || (node instanceof LocalVarNode));
+ }
+
+ /**
+ * Determines whether a given node is a dynamic variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isDVarRef(Node node) {
+ return ((node instanceof DVarNode) || (node instanceof DAsgnNode));
+ }
+
+ /**
+ * Determines whether a given node is an instance variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isInstanceVarRef(Node node) {
+ return ((node instanceof InstAsgnNode) || (node instanceof InstVarNode));
+ }
+
+ /**
+ * Determines whether a given node is a class variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isClassVarRef(Node node) {
+ return ((node instanceof ClassVarNode) || (node instanceof ClassVarAsgnNode) || (node instanceof ClassVarDeclNode));
+ }
+
+ /**
+ * Determines whether a given node is a global variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isGlobalVarRef(Node node) {
+ return ((node instanceof GlobalAsgnNode) || (node instanceof GlobalVarNode));
+ }
+
+ /**
+ * Determines whether a given node is a constant reference (constant)
+ *
+ * @param node
+ * @return
+ */
+ private boolean isConstRef(Node node) {
+ return (node instanceof ConstNode);
+ }
+
+ /**
+ * Determines whether a given node is a type reference (class, module)
+ *
+ * @param node
+ * @return
+ */
+ private boolean isTypeRef(Node node) {
+ // TODO: Classes can be referred to as a ConstNode; i.e. "class
+ // Klass;end; k = Klass.new" the last reference is a ConstNode, not a
+ // ClassNode. Special way to handle this?
+ return ((node instanceof ClassNode) || (node instanceof ModuleNode) || (node instanceof ConstNode));
+ }
+
+ // ****************************************************************************
+ // *
+ // * Worker methods - handles delegation of occurrence searches
+ // *
+ // ****************************************************************************
+
+ /**
+ * Collects all corresponding local variable occurrences
+ *
+ * @param root
+ * Root node to search
+ * @param fSelectedNode
+ * Originating node
+ * @param occurrences
+ */
+ private void pushLocalVarRefs(Node root, Node orig, List<Node> occurrences) {
+ // Find the search space
+ Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
+ }
+ });
+
+ // If no enclosing node found, search the entire space
+ if (searchSpace == null) {
+ searchSpace = root;
+ }
+
+ // Finalize searchSpace because Java's scoping rules are the awesome
+ final Node finalSearchSpace = searchSpace;
+
+ // Get name of local variable reference
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ String name = ASTUtil.getNameReflectively(node);
+ return (name != null && name.equals(origName));
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ /**
+ * Collects all corresponding dynamic variable occurrences
+ *
+ * @param root
+ * Root node to search
+ * @param fSelectedNode
+ * Originating node
+ * @param occurrences
+ */
+ private void pushDVarRefs(Node root, Node orig, List<Node> occurrences) {
+ // Find the search space
+ Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
+ }
+ });
+
+ // If no enclosing node found, search the entire space
+ if (searchSpace == null) {
+ searchSpace = root;
+ }
+
+ // Get name of local variable reference
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isDVarRef(node)) {
+ String name = ASTUtil.getNameReflectively(node);
+ return (name != null && name.equals(origName));
+ }
+ return false;
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ /**
+ * Collects all instance variable occurrences
+ *
+ * @param root
+ * @param fSelectedNode
+ * @param occurrences
+ */
+ private void pushInstVarRefs(Node root, Node orig, List<Node> occurrences) {
+ Node searchSpace = determineSearchSpace(root, orig);
+
+ // Finalize searchSpace because Java's scoping rules are the awesome
+ // todo: not needed?
+ // final Node finalSearchSpace = searchSpace;
+
+ // Get name of local variable reference
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isInstanceVarRef(node)) {
+ String name = ASTUtil.getNameReflectively(node);
+ return (name != null && name.equals(origName));
+ }
+ return false;
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+
+ }
+
+ private Node determineSearchSpace(Node root, Node orig) {
+
+ // Find the name of the enclosing class
+ ClassNode enclosingClass = (ClassNode) FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return (node instanceof ClassNode);
+ }
+ });
+
+ // If no enclosing class is identified, search root.
+ if (enclosingClass == null) {
+ return root;
+ }
+ // Find the search space - all ClassNodes for that name within root
+ // scope
+ else {
+ final String className = getClassNodeName(enclosingClass);
+ List<Node> classNodes = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (node instanceof ClassNode) {
+ return getClassNodeName((ClassNode) node).equals(className);
+ }
+ return false;
+ }
+ });
+ BlockNode blockNode = new BlockNode(new SourcePosition());
+ for (Node classNode : classNodes) {
+ blockNode.add(classNode);
+ }
+ return blockNode;
+ }
+ }
+
+ /**
+ * Collects all class variable occurrences
+ *
+ * @param root
+ * @param fSelectedNode
+ * @param occurrences
+ */
+ private void pushClassVarRefs(Node root, Node orig, List<Node> occurrences) {
+ Node searchSpace = determineSearchSpace(root, orig);
+
+ // Finalize searchSpace because Java's scoping rules are the awesome
+ // todo: not needed?
+ // final Node finalSearchSpace = searchSpace;
+
+ // Get name of local variable reference
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isClassVarRef(node)) {
+ String name = ASTUtil.getNameReflectively(node);
+ return (name != null && name.equals(origName));
+ }
+ return false;
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+
+ }
+
+ /**
+ * Collects all global variable occurrences
+ *
+ * @param root
+ * @param fSelectedNode
+ * @param occurrences
+ */
+ private void pushGlobalVarRefs(Node root, Node orig, List<Node> occurrences) {
+ final Node searchSpace = root;
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return isGlobalVarRef(node) && ASTUtil.getNameReflectively(node).equals(origName);
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ /**
+ * Collects all symbol occurrences
+ *
+ * @param root
+ * @param fSelectedNode
+ * @param occurrences
+ */
+ private void pushSymbolRefs(Node root, Node orig, List<Node> occurrences) {
+ final Node searchSpace = root;
+ final String origName = ((SymbolNode) orig).getName();
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return (node instanceof SymbolNode) && ((SymbolNode) node).getName().equals(origName);
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ // todo: complete
+ // private void pushMethodRefs( Node root, Node fSelectedNode, List<ISourcePosition>
+ // occurrences) {
+ //
+ // // DefnNode DefsNode CallNode VCallNode
+ //
+ // System.out.println("Finding occurrences for method reference node " +
+ // fSelectedNode.toString() );
+ //
+ // final Node searchSpace = root;
+ // String origName = getMethodRefName(fSelectedNode);
+ //
+ // // If fSelectedNode is a method definition, find all occurrences to that selector
+ // for the fSelectedNode's enclosing type
+ // if ( fSelectedNode instanceof DefnNode || fSelectedNode instanceof DefsNode )
+ // {
+ // ((DefnNode)fSelectedNode).g
+ // }
+ //
+ // Node receiver = getMethodReceiver(fSelectedNode);
+ // }
+
+ /**
+ * Collects all pertinent const occurrences
+ */
+ private void pushConstRefs(Node root, Node orig, List<Node> occurrences) {
+ if (!isConstRef(orig)) {
+ return;
+ }
+
+ final String matchName = ASTUtil.getNameReflectively(orig);
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isConstRef(node)) {
+ return ASTUtil.getNameReflectively(node).equals(matchName);
+ }
+ return false;
+ }
+ });
+
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ /**
+ * Collects all pertinent type ref occurrences
+ */
+ private void pushTypeRefs(Node root, Node orig, List<Node> occurrences) {
+ if (!isTypeRef(orig)) {
+ return;
+ }
+
+ final String matchName = ASTUtil.getNameReflectively(orig);
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isTypeRef(node)) {
+ return getTypeRefName(node).equals(matchName);
+ }
+ return false;
+ }
+ });
+
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ private void pushReturns(Node root, Node orig, List<Node> occurrences) {
+ // TODO Combine most of this stuff with the stuff in pushLocalVareRefs
+ // Find the search space
+ Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
+ }
+ });
+
+ // If no enclosing node found, search the entire space
+ if (searchSpace == null) {
+ searchSpace = root;
+ }
+// Find all return nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return (node instanceof ReturnNode);
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ // ****************************************************************************
+ // *
+ // * Utility methods
+ // *
+ // ****************************************************************************
+
+ /**
+ * Gets the position of the name for the specified node.
+ *
+ * @param node
+ * Node that responds to getName() or some variant
+ * @return ISourcePosition that holds the name of the node
+ */
+ private ISourcePosition getPositionOfName(Node node) {
+ ISourcePosition pos = node.getPosition();
+
+ // TODO refactor the getting-of-name
+ String name = null;
+ if (node instanceof ReturnNode) {
+ return node.getPosition();
+ } else if (isLocalVarRef(node) || isDVarRef(node) || isInstanceVarRef(node) || isGlobalVarRef(node) || isClassVarRef(node) || isConstRef(node) || node instanceof BlockArgNode) {
+ name = ASTUtil.getNameReflectively(node);
+ } else if (node instanceof ClassNode) {
+ name = getClassNodeName((ClassNode) node);
+ String classDeclString = source.substring(pos.getStartOffset(), pos.getEndOffset());
+ int begin = pos.getStartOffset() + classDeclString.indexOf(name);
+ return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), begin, begin + name.length());
+ } else if (node instanceof ModuleNode) {
+ name = getModuleNodeName((ModuleNode) node);
+ String moduleDeclString = source.substring(pos.getStartOffset(), pos.getEndOffset());
+ int begin = moduleDeclString.indexOf(name);
+ return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), begin, begin + name.length());
+ } else if (node instanceof SymbolNode) {
+ // XXX: This is a hack to get around improper offsets in my JRuby
+ // copy; ":foo" returns offset for ":fo", so compensate by adding
+ // one
+ name = ((SymbolNode) node).getName();
+ return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() + 1);
+ }
+
+ if (name == null) {
+ throw new RuntimeException("Couldn't get the name for: " + node.toString());
+ }
+ return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length());
+ }
+
+ /**
+ * Helper method to get the class name froma ClassNode
+ *
+ * @param classNode
+ * @return
+ */
+ private String getClassNodeName(ClassNode classNode) {
+ if (classNode.getCPath() instanceof Colon2Node) {
+ Colon2Node c2node = (Colon2Node) classNode.getCPath();
+ return c2node.getName();
+ }
+ throw new RuntimeException("ClassNode.getCPath() returned other than Colon2Node: " + classNode.toString());
+ }
+
+ /**
+ * Helper method to get the class name from a ModuleNode
+ *
+ * @param classNode
+ * @return
+ */
+ private String getModuleNodeName(ModuleNode moduleNode) {
+ if (moduleNode.getCPath() instanceof Colon2Node) {
+ Colon2Node c2node = (Colon2Node) moduleNode.getCPath();
+ return c2node.getName();
+ }
+ throw new RuntimeException("ModuleNode.getCPath() returned other than Colon2Node: " + moduleNode.toString());
+ }
+
+ /**
+ * Helper method to get the class name from a const ref node (Class/Module)
+ *
+ * @param node
+ * @return
+ */
+ private String getTypeRefName(Node node) {
+ if (node instanceof ClassNode) {
+ return getClassNodeName((ClassNode) node);
+ }
+ if (node instanceof ModuleNode) {
+ return getModuleNodeName((ModuleNode) node);
+ }
+ return ASTUtil.getNameReflectively(node);
+ }
+
+ public String getElementName() {
+ if (fSelectedNode != null) {
+ return ASTUtil.stringRepresentation(fSelectedNode);
+ }
+ return null;
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindOccurrencesInFileAction.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindOccurrencesInFileAction.java 2007-06-06 14:34:57 UTC (rev 2583)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindOccurrencesInFileAction.java 2007-06-06 14:37:04 UTC (rev 2584)
@@ -33,7 +33,7 @@
import org.rubypeople.rdt.internal.ui.actions.ActionUtil;
import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyScriptEditorInput;
import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
-import org.rubypeople.rdt.internal.ui.search.DefaultOccurrencesFinder;
+import org.rubypeople.rdt.internal.ui.search.OccurrencesFinder;
import org.rubypeople.rdt.internal.ui.search.FindOccurrencesEngine;
import org.rubypeople.rdt.internal.ui.search.SearchMessages;
@@ -143,7 +143,7 @@
IMember member= getMember(selection);
if (!ActionUtil.isProcessable(getShell(), member))
return;
- FindOccurrencesEngine engine= FindOccurrencesEngine.create(member, new DefaultOccurrencesFinder());
+ FindOccurrencesEngine engine= FindOccurrencesEngine.create(member, new OccurrencesFinder());
try {
ISourceRange range= member.getNameRange();
String result= engine.run(range.getOffset(), range.getLength());
@@ -178,7 +178,7 @@
IRubyElement input= getEditorInput(fEditor);
if (!ActionUtil.isProcessable(getShell(), input))
return;
- FindOccurrencesEngine engine= FindOccurrencesEngine.create(input, new DefaultOccurrencesFinder());
+ FindOccurrencesEngine engine= FindOccurrencesEngine.create(input, new OccurrencesFinder());
try {
String result= engine.run(ts.getOffset(), ts.getLength());
if (result != null)
Modified: trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java
===================================================================
--- trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java 2007-06-06 14:34:57 UTC (rev 2583)
+++ trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java 2007-06-06 14:37:04 UTC (rev 2584)
@@ -5,7 +5,7 @@
import junit.framework.TestCase;
import org.eclipse.jface.text.Position;
-import org.rubypeople.rdt.internal.ui.search.DefaultOccurrencesFinder;
+import org.rubypeople.rdt.internal.ui.search.OccurrencesFinder;
/**
* Tests related to matching occurrences.
@@ -17,7 +17,7 @@
private IOccurrencesFinder occurrencesFinder;
public void setUp() {
- occurrencesFinder = new DefaultOccurrencesFinder();
+ occurrencesFinder = new OccurrencesFinder();
occurrencesFinder.setFMarkConstantOccurrences(true);
occurrencesFinder.setFMarkFieldOccurrences(true);
occurrencesFinder.setFMarkLocalVariableOccurrences(true);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-06 14:34:59
|
Revision: 2583
http://svn.sourceforge.net/rubyeclipse/?rev=2583&view=rev
Author: cawilliams
Date: 2007-06-06 07:34:57 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
move all OccurrencesFinder stuff to UI
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/FindOccurrencesEngine.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesSearchQuery.java
trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/AbstractOccurencesFinder.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java
Deleted: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java 2007-06-06 14:33:07 UTC (rev 2582)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation 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
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.rubypeople.rdt.core.search;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-import org.jruby.ast.Node;
-import org.rubypeople.rdt.core.IRubyElement;
-
-public interface IOccurrencesFinder {
-
- /**
- *
- * @param source
- * Ruby source to search for occurrences
- * @param offset
- * position in source where selection is
- * @param length
- * length of the selection
- * @return
- */
- public String initialize(String source, int offset, int length);
-
- /**
- *
- * @param root
- * the root node
- * @param offset
- * position in source where selection is
- * @param length
- * length of the selection
- * @return
- */
- public String initialize(Node root, int offset, int length);
-
- /**
- * Returns a lit of AST Nodes back (which contain their associated
- * positions).
- *
- * @return List of AST Nodes
- */
- public List<Position> perform();
-
- public String getJobLabel();
-
- /**
- * Returns the plural label for this finder with 3 placeholders:
- * <ul>
- * <li>{0} for the {@link #getElementName() element name}</li>
- * <li>{1} for the number of results found</li>
- * <li>{2} for the scope (name of the compilation unit)</li>
- * </ul>
- *
- * @return the unformatted label
- */
- public String getUnformattedPluralLabel();
-
- /**
- * Returns the singular label for this finder with 2 placeholders:
- * <ul>
- * <li>{0} for the {@link #getElementName() element name}</li>
- * <li>{1} for the scope (name of the compilation unit)</li>
- * </ul>
- *
- * @return the unformatted label
- */
- public String getUnformattedSingularLabel();
-
- /**
- * Returns the name of the element to look for or <code>null</code> if the
- * finder hasn't been initialized yet.
- *
- * @return the name of the element
- */
- public String getElementName();
-
- public void collectOccurrenceMatches(IRubyElement element,
- IDocument document, Collection resultingMatches);
-
- /* Preferences */
- public void setFMarkConstantOccurrences(boolean markConstantOccurrences);
- public void setFMarkFieldOccurrences(boolean markFieldOccurrences);
- public void setFMarkLocalVariableOccurrences(boolean markLocalVariableOccurrences);
- public void setFMarkMethodExitPoints(boolean markMethodExitPoints);
- public void setFMarkMethodOccurrences(boolean markMethodOccurrences);
- public void setFMarkOccurrenceAnnotations(boolean markOccurrenceAnnotations);
- public void setFMarkTypeOccurrences(boolean markTypeOccurrences);
- public void setFStickyOccurrenceAnnotations(boolean stickyOccurrenceAnnotations);
-
-}
Deleted: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2007-06-06 14:33:07 UTC (rev 2582)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -1,48 +0,0 @@
-package org.rubypeople.rdt.internal.ti;
-
-import org.rubypeople.rdt.core.search.IOccurrencesFinder;
-
-public abstract class AbstractOccurencesFinder implements IOccurrencesFinder {
-
- protected boolean fMarkOccurrenceAnnotations;
- protected boolean fStickyOccurrenceAnnotations;
- protected boolean fMarkTypeOccurrences;
- protected boolean fMarkMethodOccurrences;
- protected boolean fMarkConstantOccurrences;
- protected boolean fMarkFieldOccurrences;
- protected boolean fMarkLocalVariableOccurrences;
- protected boolean fMarkMethodExitPoints;
-
- public void setFMarkConstantOccurrences(boolean markConstantOccurrences) {
- fMarkConstantOccurrences = markConstantOccurrences;
- }
-
- public void setFMarkFieldOccurrences(boolean markFieldOccurrences) {
- fMarkFieldOccurrences = markFieldOccurrences;
- }
-
- public void setFMarkLocalVariableOccurrences(boolean markLocalVariableOccurrences) {
- fMarkLocalVariableOccurrences = markLocalVariableOccurrences;
- }
-
- public void setFMarkMethodExitPoints(boolean markMethodExitPoints) {
- fMarkMethodExitPoints = markMethodExitPoints;
- }
-
- public void setFMarkMethodOccurrences(boolean markMethodOccurrences) {
- fMarkMethodOccurrences = markMethodOccurrences;
- }
-
- public void setFMarkOccurrenceAnnotations(boolean markOccurrenceAnnotations) {
- fMarkOccurrenceAnnotations = markOccurrenceAnnotations;
- }
-
- public void setFMarkTypeOccurrences(boolean markTypeOccurrences) {
- fMarkTypeOccurrences = markTypeOccurrences;
- }
-
- public void setFStickyOccurrenceAnnotations(boolean stickyOccurrenceAnnotations) {
- fStickyOccurrenceAnnotations = stickyOccurrenceAnnotations;
- }
-
-}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2007-06-06 14:33:07 UTC (rev 2582)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -80,10 +80,10 @@
import org.rubypeople.rdt.core.ISourceReference;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
-import org.rubypeople.rdt.core.search.IOccurrencesFinder;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor.ITextConverter;
import org.rubypeople.rdt.internal.ui.search.DefaultOccurrencesFinder;
+import org.rubypeople.rdt.internal.ui.search.IOccurrencesFinder;
import org.rubypeople.rdt.internal.ui.text.ContentAssistPreference;
import org.rubypeople.rdt.internal.ui.text.IRubyPartitions;
import org.rubypeople.rdt.internal.ui.text.PreferencesAdapter;
Copied: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/AbstractOccurencesFinder.java (from rev 2581, trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java)
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/AbstractOccurencesFinder.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/AbstractOccurencesFinder.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -0,0 +1,47 @@
+package org.rubypeople.rdt.internal.ui.search;
+
+
+public abstract class AbstractOccurencesFinder implements IOccurrencesFinder {
+
+ protected boolean fMarkOccurrenceAnnotations;
+ protected boolean fStickyOccurrenceAnnotations;
+ protected boolean fMarkTypeOccurrences;
+ protected boolean fMarkMethodOccurrences;
+ protected boolean fMarkConstantOccurrences;
+ protected boolean fMarkFieldOccurrences;
+ protected boolean fMarkLocalVariableOccurrences;
+ protected boolean fMarkMethodExitPoints;
+
+ public void setFMarkConstantOccurrences(boolean markConstantOccurrences) {
+ fMarkConstantOccurrences = markConstantOccurrences;
+ }
+
+ public void setFMarkFieldOccurrences(boolean markFieldOccurrences) {
+ fMarkFieldOccurrences = markFieldOccurrences;
+ }
+
+ public void setFMarkLocalVariableOccurrences(boolean markLocalVariableOccurrences) {
+ fMarkLocalVariableOccurrences = markLocalVariableOccurrences;
+ }
+
+ public void setFMarkMethodExitPoints(boolean markMethodExitPoints) {
+ fMarkMethodExitPoints = markMethodExitPoints;
+ }
+
+ public void setFMarkMethodOccurrences(boolean markMethodOccurrences) {
+ fMarkMethodOccurrences = markMethodOccurrences;
+ }
+
+ public void setFMarkOccurrenceAnnotations(boolean markOccurrenceAnnotations) {
+ fMarkOccurrenceAnnotations = markOccurrenceAnnotations;
+ }
+
+ public void setFMarkTypeOccurrences(boolean markTypeOccurrences) {
+ fMarkTypeOccurrences = markTypeOccurrences;
+ }
+
+ public void setFStickyOccurrenceAnnotations(boolean stickyOccurrenceAnnotations) {
+ fStickyOccurrenceAnnotations = stickyOccurrenceAnnotations;
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java 2007-06-06 14:33:07 UTC (rev 2582)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -42,7 +42,6 @@
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.internal.core.parser.RubyParser;
import org.rubypeople.rdt.internal.core.util.ASTUtil;
-import org.rubypeople.rdt.internal.ti.AbstractOccurencesFinder;
import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator;
import org.rubypeople.rdt.internal.ti.util.INodeAcceptor;
import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator;
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/FindOccurrencesEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/FindOccurrencesEngine.java 2007-06-06 14:33:07 UTC (rev 2582)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/FindOccurrencesEngine.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -18,7 +18,6 @@
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.ISourceReference;
import org.rubypeople.rdt.core.RubyModelException;
-import org.rubypeople.rdt.core.search.IOccurrencesFinder;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.internal.ui.rubyeditor.ASTProvider;
Copied: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java (from rev 2581, trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java)
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.ui.search;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.jruby.ast.Node;
+import org.rubypeople.rdt.core.IRubyElement;
+
+public interface IOccurrencesFinder {
+
+ /**
+ *
+ * @param source
+ * Ruby source to search for occurrences
+ * @param offset
+ * position in source where selection is
+ * @param length
+ * length of the selection
+ * @return
+ */
+ public String initialize(String source, int offset, int length);
+
+ /**
+ *
+ * @param root
+ * the root node
+ * @param offset
+ * position in source where selection is
+ * @param length
+ * length of the selection
+ * @return
+ */
+ public String initialize(Node root, int offset, int length);
+
+ /**
+ * Returns a lit of AST Nodes back (which contain their associated
+ * positions).
+ *
+ * @return List of AST Nodes
+ */
+ public List<Position> perform();
+
+ public String getJobLabel();
+
+ /**
+ * Returns the plural label for this finder with 3 placeholders:
+ * <ul>
+ * <li>{0} for the {@link #getElementName() element name}</li>
+ * <li>{1} for the number of results found</li>
+ * <li>{2} for the scope (name of the compilation unit)</li>
+ * </ul>
+ *
+ * @return the unformatted label
+ */
+ public String getUnformattedPluralLabel();
+
+ /**
+ * Returns the singular label for this finder with 2 placeholders:
+ * <ul>
+ * <li>{0} for the {@link #getElementName() element name}</li>
+ * <li>{1} for the scope (name of the compilation unit)</li>
+ * </ul>
+ *
+ * @return the unformatted label
+ */
+ public String getUnformattedSingularLabel();
+
+ /**
+ * Returns the name of the element to look for or <code>null</code> if the
+ * finder hasn't been initialized yet.
+ *
+ * @return the name of the element
+ */
+ public String getElementName();
+
+ public void collectOccurrenceMatches(IRubyElement element,
+ IDocument document, Collection resultingMatches);
+
+ /* Preferences */
+ public void setFMarkConstantOccurrences(boolean markConstantOccurrences);
+ public void setFMarkFieldOccurrences(boolean markFieldOccurrences);
+ public void setFMarkLocalVariableOccurrences(boolean markLocalVariableOccurrences);
+ public void setFMarkMethodExitPoints(boolean markMethodExitPoints);
+ public void setFMarkMethodOccurrences(boolean markMethodOccurrences);
+ public void setFMarkOccurrenceAnnotations(boolean markOccurrenceAnnotations);
+ public void setFMarkTypeOccurrences(boolean markTypeOccurrences);
+ public void setFStickyOccurrenceAnnotations(boolean stickyOccurrenceAnnotations);
+
+}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesSearchQuery.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesSearchQuery.java 2007-06-06 14:33:07 UTC (rev 2582)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesSearchQuery.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -21,7 +21,6 @@
import org.eclipse.search.ui.ISearchResult;
import org.eclipse.search.ui.text.Match;
import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.core.search.IOccurrencesFinder;
import org.rubypeople.rdt.internal.corext.util.Messages;
import org.rubypeople.rdt.internal.ui.dialogs.StatusInfo;
Modified: trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java
===================================================================
--- trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java 2007-06-06 14:33:07 UTC (rev 2582)
+++ trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java 2007-06-06 14:34:57 UTC (rev 2583)
@@ -5,7 +5,6 @@
import junit.framework.TestCase;
import org.eclipse.jface.text.Position;
-import org.rubypeople.rdt.core.search.IOccurrencesFinder;
import org.rubypeople.rdt.internal.ui.search.DefaultOccurrencesFinder;
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-06 14:33:10
|
Revision: 2582
http://svn.sourceforge.net/rubyeclipse/?rev=2582&view=rev
Author: cawilliams
Date: 2007-06-06 07:33:07 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
start adding search context menu and actions
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/plugin.xml
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPlugin.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/RubyPluginImages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyAbstractEditor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/RubyEditor.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/SearchMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/PreferenceConstants.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/RubyUI.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ActionMessages.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ActionMessages.properties
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/IRubyEditorActionDefinitionIds.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RdtActionConstants.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_match.gif
trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_read.gif
trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_write.gif
trunk/org.rubypeople.rdt.ui/icons/full/obj16/search_ref_obj.gif
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/ASTProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/FindOccurrencesEngine.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesGroupKey.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesSearchLabelProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesSearchQuery.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesSearchResult.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/OccurrencesSearchResultPage.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubyElementLine.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubyElementLineSorter.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/TextSearchLabelProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/TextSearchTableContentProvider.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindOccurrencesInFileAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindReadReferencesAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindReadReferencesInProjectAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindReadReferencesInWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindReferencesAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindReferencesInProjectAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/FindReferencesInWorkingSetAction.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/OccurrencesSearchGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ReadReferencesSearchGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/ReferencesSearchGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/RubySearchActionGroup.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/ui/actions/WorkingSetFindAction.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.ui/icons/full/obj16/search_ref_obj.gif
Added: trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_match.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_match.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_read.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_read.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_write.gif
===================================================================
(Binary files differ)
Property changes on: trunk/org.rubypeople.rdt.ui/icons/full/obj16/occ_write.gif
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: trunk/org.rubypeople.rdt.ui/icons/full/obj16/search_ref_obj.gif
===================================================================
(Binary files differ)
Added: trunk/org.rubypeople.rdt.ui/icons/full/obj16/search_ref_obj.gif
===================================================================
--- trunk/org.rubypeople.rdt.ui/icons/full/obj16/search_ref_obj.gif (rev 0)
+++ trunk/org.rubypeople.rdt.ui/icons/full/obj16/search_ref_obj.gif 2007-06-06 14:33:07 UTC (rev 2582)
@@ -0,0 +1,4 @@
+GIF89a |
|
From: <caw...@us...> - 2007-06-06 14:30:30
|
Revision: 2581
http://svn.sourceforge.net/rubyeclipse/?rev=2581&view=rev
Author: cawilliams
Date: 2007-06-06 07:30:28 -0700 (Wed, 06 Jun 2007)
Log Message:
-----------
move occurrences finder over to ui plugin
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/TS_TypeInference.java
trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/TS_InternalUiRubySearch.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java
trunk/org.rubypeople.rdt.ui.tests/src/org/rubypeople/rdt/internal/ui/search/MarkOccurrencesTest.java
Removed Paths:
-------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java
trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/IOccurrencesFinder.java
Copied: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java (from rev 2395, trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java)
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/search/IOccurrencesFinder.java 2007-06-06 14:30:28 UTC (rev 2581)
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.core.search;
+
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.Position;
+import org.jruby.ast.Node;
+import org.rubypeople.rdt.core.IRubyElement;
+
+public interface IOccurrencesFinder {
+
+ /**
+ *
+ * @param source
+ * Ruby source to search for occurrences
+ * @param offset
+ * position in source where selection is
+ * @param length
+ * length of the selection
+ * @return
+ */
+ public String initialize(String source, int offset, int length);
+
+ /**
+ *
+ * @param root
+ * the root node
+ * @param offset
+ * position in source where selection is
+ * @param length
+ * length of the selection
+ * @return
+ */
+ public String initialize(Node root, int offset, int length);
+
+ /**
+ * Returns a lit of AST Nodes back (which contain their associated
+ * positions).
+ *
+ * @return List of AST Nodes
+ */
+ public List<Position> perform();
+
+ public String getJobLabel();
+
+ /**
+ * Returns the plural label for this finder with 3 placeholders:
+ * <ul>
+ * <li>{0} for the {@link #getElementName() element name}</li>
+ * <li>{1} for the number of results found</li>
+ * <li>{2} for the scope (name of the compilation unit)</li>
+ * </ul>
+ *
+ * @return the unformatted label
+ */
+ public String getUnformattedPluralLabel();
+
+ /**
+ * Returns the singular label for this finder with 2 placeholders:
+ * <ul>
+ * <li>{0} for the {@link #getElementName() element name}</li>
+ * <li>{1} for the scope (name of the compilation unit)</li>
+ * </ul>
+ *
+ * @return the unformatted label
+ */
+ public String getUnformattedSingularLabel();
+
+ /**
+ * Returns the name of the element to look for or <code>null</code> if the
+ * finder hasn't been initialized yet.
+ *
+ * @return the name of the element
+ */
+ public String getElementName();
+
+ public void collectOccurrenceMatches(IRubyElement element,
+ IDocument document, Collection resultingMatches);
+
+ /* Preferences */
+ public void setFMarkConstantOccurrences(boolean markConstantOccurrences);
+ public void setFMarkFieldOccurrences(boolean markFieldOccurrences);
+ public void setFMarkLocalVariableOccurrences(boolean markLocalVariableOccurrences);
+ public void setFMarkMethodExitPoints(boolean markMethodExitPoints);
+ public void setFMarkMethodOccurrences(boolean markMethodOccurrences);
+ public void setFMarkOccurrenceAnnotations(boolean markOccurrenceAnnotations);
+ public void setFMarkTypeOccurrences(boolean markTypeOccurrences);
+ public void setFStickyOccurrenceAnnotations(boolean stickyOccurrenceAnnotations);
+
+}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2007-06-05 15:44:47 UTC (rev 2580)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/AbstractOccurencesFinder.java 2007-06-06 14:30:28 UTC (rev 2581)
@@ -1,12 +1,8 @@
package org.rubypeople.rdt.internal.ti;
-import java.util.Collection;
-import java.util.List;
+import org.rubypeople.rdt.core.search.IOccurrencesFinder;
-import org.eclipse.jface.text.IDocument;
-import org.rubypeople.rdt.core.IRubyElement;
-
-public class AbstractOccurencesFinder implements IOccurrencesFinder {
+public abstract class AbstractOccurencesFinder implements IOccurrencesFinder {
protected boolean fMarkOccurrenceAnnotations;
protected boolean fStickyOccurrenceAnnotations;
@@ -17,41 +13,6 @@
protected boolean fMarkLocalVariableOccurrences;
protected boolean fMarkMethodExitPoints;
- public void collectOccurrenceMatches(IRubyElement element,
- IDocument document, Collection resultingMatches) {
- // TODO Auto-generated method stub
- }
-
- public String getElementName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getJobLabel() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getUnformattedPluralLabel() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String getUnformattedSingularLabel() {
- // TODO Auto-generated method stub
- return null;
- }
-
- public String initialize(String source, int offset, int length) {
- // TODO Auto-generated method stub
- return null;
- }
-
- public List perform() {
- // TODO Auto-generated method stub
- return null;
- }
-
public void setFMarkConstantOccurrences(boolean markConstantOccurrences) {
fMarkConstantOccurrences = markConstantOccurrences;
}
Deleted: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2007-06-05 15:44:47 UTC (rev 2580)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java 2007-06-06 14:30:28 UTC (rev 2581)
@@ -1,665 +0,0 @@
-package org.rubypeople.rdt.internal.ti;
-
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.jface.text.Position;
-import org.jruby.ast.ArgumentNode;
-import org.jruby.ast.BlockArgNode;
-import org.jruby.ast.BlockNode;
-import org.jruby.ast.ClassNode;
-import org.jruby.ast.ClassVarAsgnNode;
-import org.jruby.ast.ClassVarDeclNode;
-import org.jruby.ast.ClassVarNode;
-import org.jruby.ast.Colon2Node;
-import org.jruby.ast.ConstNode;
-import org.jruby.ast.DAsgnNode;
-import org.jruby.ast.DVarNode;
-import org.jruby.ast.DefnNode;
-import org.jruby.ast.DefsNode;
-import org.jruby.ast.GlobalAsgnNode;
-import org.jruby.ast.GlobalVarNode;
-import org.jruby.ast.InstAsgnNode;
-import org.jruby.ast.InstVarNode;
-import org.jruby.ast.LocalAsgnNode;
-import org.jruby.ast.LocalVarNode;
-import org.jruby.ast.ModuleNode;
-import org.jruby.ast.Node;
-import org.jruby.ast.ReturnNode;
-import org.jruby.ast.SymbolNode;
-import org.jruby.lexer.yacc.ISourcePosition;
-import org.jruby.lexer.yacc.SourcePosition;
-import org.jruby.lexer.yacc.SyntaxException;
-import org.rubypeople.rdt.internal.core.parser.RubyParser;
-import org.rubypeople.rdt.internal.core.util.ASTUtil;
-import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator;
-import org.rubypeople.rdt.internal.ti.util.INodeAcceptor;
-import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator;
-import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator;
-
-/**
- * Implements "Mark Occurences" feature
- *
- * @author Jason Morrison
- *
- */
-public class DefaultOccurrencesFinder extends AbstractOccurencesFinder {
-
- // Root of the document to search
- private Node root;
-
- // Originating node; corresponds to cursor selection
- private Node orig;
-
- // Original source
- private String source;
-
- public String initialize(String source, int offset, int length) {
- if (source == null) {
- return null;
- }
-
- this.source = source;
- try {
- RubyParser rubyParser = new RubyParser();
- this.root = rubyParser.parse(source);
- if (this.root == null) {
- return null;
- }
- }
- // TODO: Is there anything else the parsing could choke on that should
- // be silently ignored with no markings?
- catch (SyntaxException se) {
- this.root = null;
- return null;
- }
- this.orig = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset);
- if (orig == null) {
- return null;
- }
- if (orig.getPosition().getEndOffset() > offset + length) {
- // Selection spans nodes; not handling that for now.
- return "Selection spans nodes; can only search for a single node.";
- }
-
- return null;
- }
-
- /**
- * Determines the kind of originating node, and collects occurrences
- * accordingly
- */
- public List<Position> perform() {
- // Mark no occurrences if root is null (AST couldn't be parsed
- // correctly.)
- if (root == null)
- return new LinkedList<Position>();
- if (orig == null)
- return new LinkedList<Position>();
-
- // occurrences to return
- List<ISourcePosition> occurrences = new LinkedList<ISourcePosition>();
-
- if (fMarkLocalVariableOccurrences && isLocalVarRef(orig)) {
- pushLocalVarRefs(root, orig, occurrences);
- }
-
- if (fMarkLocalVariableOccurrences && isDVarRef(orig)) {
- pushDVarRefs(root, orig, occurrences);
- }
-
- // XXX: Add pref for instvars
- if (fMarkLocalVariableOccurrences && isInstanceVarRef(orig)) {
- pushInstVarRefs(root, orig, occurrences);
- }
-
- // XXX: Add pref for classvars
- if (fMarkLocalVariableOccurrences && isClassVarRef(orig)) {
- pushClassVarRefs(root, orig, occurrences);
- }
-
- // XXX: Add pref for global vars
- if (fMarkLocalVariableOccurrences && isGlobalVarRef(orig)) {
- pushGlobalVarRefs(root, orig, occurrences);
- }
-
- // XXX: Add pref for symbols
- if (fMarkConstantOccurrences && orig instanceof SymbolNode) {
- pushSymbolRefs(root, orig, occurrences);
- }
-
- // if ( isMethodRefNode(orig)) {
- // pushMethodRefs( root, orig, occurrences );
- // }
-
- if (fMarkConstantOccurrences && isConstRef(orig)) {
- pushConstRefs(root, orig, occurrences);
- }
-
- if (fMarkTypeOccurrences && isTypeRef(orig)) {
- pushTypeRefs(root, orig, occurrences);
- }
-
- if (fMarkMethodExitPoints) {
- pushReturns(root, orig, occurrences);
- }
-
- // Convert ISourcePosition to IPosition
- List<Position> positions = new LinkedList<Position>();
- for (ISourcePosition occurrence : occurrences) {
- Position position = new Position(occurrence.getStartOffset(), occurrence.getEndOffset() - occurrence.getStartOffset());
- positions.add(position);
- }
-
- // Uniqueify positions
- positions = new LinkedList<Position>(new HashSet<Position>(positions));
-
- return positions;
- }
-
- // ****************************************************************************
- // *
- // * Reference kind definitions
- // *
- // ****************************************************************************
-
- /**
- * Determines whether a given node is a local variable reference
- *
- * @param node
- * @return
- */
- private boolean isLocalVarRef(Node node) {
- return ((node instanceof LocalAsgnNode) || (node instanceof ArgumentNode) || (node instanceof LocalVarNode));
- }
-
- /**
- * Determines whether a given node is a dynamic variable reference
- *
- * @param node
- * @return
- */
- private boolean isDVarRef(Node node) {
- return ((node instanceof DVarNode) || (node instanceof DAsgnNode));
- }
-
- /**
- * Determines whether a given node is an instance variable reference
- *
- * @param node
- * @return
- */
- private boolean isInstanceVarRef(Node node) {
- return ((node instanceof InstAsgnNode) || (node instanceof InstVarNode));
- }
-
- /**
- * Determines whether a given node is a class variable reference
- *
- * @param node
- * @return
- */
- private boolean isClassVarRef(Node node) {
- return ((node instanceof ClassVarNode) || (node instanceof ClassVarAsgnNode) || (node instanceof ClassVarDeclNode));
- }
-
- /**
- * Determines whether a given node is a global variable reference
- *
- * @param node
- * @return
- */
- private boolean isGlobalVarRef(Node node) {
- return ((node instanceof GlobalAsgnNode) || (node instanceof GlobalVarNode));
- }
-
- /**
- * Determines whether a given node is a constant reference (constant)
- *
- * @param node
- * @return
- */
- private boolean isConstRef(Node node) {
- return (node instanceof ConstNode);
- }
-
- /**
- * Determines whether a given node is a type reference (class, module)
- *
- * @param node
- * @return
- */
- private boolean isTypeRef(Node node) {
- // TODO: Classes can be referred to as a ConstNode; i.e. "class
- // Klass;end; k = Klass.new" the last reference is a ConstNode, not a
- // ClassNode. Special way to handle this?
- return ((node instanceof ClassNode) || (node instanceof ModuleNode) || (node instanceof ConstNode));
- }
-
- // ****************************************************************************
- // *
- // * Worker methods - handles delegation of occurrence searches
- // *
- // ****************************************************************************
-
- /**
- * Collects all corresponding local variable occurrences
- *
- * @param root
- * Root node to search
- * @param orig
- * Originating node
- * @param occurrences
- */
- private void pushLocalVarRefs(Node root, Node orig, List<ISourcePosition> occurrences) {
- // Find the search space
- Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
- }
- });
-
- // If no enclosing node found, search the entire space
- if (searchSpace == null) {
- searchSpace = root;
- }
-
- // Finalize searchSpace because Java's scoping rules are the awesome
- final Node finalSearchSpace = searchSpace;
-
- // Get name of local variable reference
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- String name = ASTUtil.getNameReflectively(node);
- return (name != null && name.equals(origName));
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(getPositionOfName(searchResult, searchSpace));
- }
- }
-
- /**
- * Collects all corresponding dynamic variable occurrences
- *
- * @param root
- * Root node to search
- * @param orig
- * Originating node
- * @param occurrences
- */
- private void pushDVarRefs(Node root, Node orig, List<ISourcePosition> occurrences) {
- // Find the search space
- Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
- }
- });
-
- // If no enclosing node found, search the entire space
- if (searchSpace == null) {
- searchSpace = root;
- }
-
- // Get name of local variable reference
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isDVarRef(node)) {
- String name = ASTUtil.getNameReflectively(node);
- return (name != null && name.equals(origName));
- }
- return false;
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(getPositionOfName(searchResult, searchSpace));
- }
- }
-
- /**
- * Collects all instance variable occurrences
- *
- * @param root
- * @param orig
- * @param occurrences
- */
- private void pushInstVarRefs(Node root, Node orig, List<ISourcePosition> occurrences) {
- Node searchSpace = determineSearchSpace(root, orig);
-
- // Finalize searchSpace because Java's scoping rules are the awesome
- // todo: not needed?
- // final Node finalSearchSpace = searchSpace;
-
- // Get name of local variable reference
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isInstanceVarRef(node)) {
- String name = ASTUtil.getNameReflectively(node);
- return (name != null && name.equals(origName));
- }
- return false;
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(getPositionOfName(searchResult, searchSpace));
- }
-
- }
-
- private Node determineSearchSpace(Node root, Node orig) {
-
- // Find the name of the enclosing class
- ClassNode enclosingClass = (ClassNode) FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return (node instanceof ClassNode);
- }
- });
-
- // If no enclosing class is identified, search root.
- if (enclosingClass == null) {
- return root;
- }
- // Find the search space - all ClassNodes for that name within root
- // scope
- else {
- final String className = getClassNodeName(enclosingClass);
- List<Node> classNodes = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (node instanceof ClassNode) {
- return getClassNodeName((ClassNode) node).equals(className);
- }
- return false;
- }
- });
- BlockNode blockNode = new BlockNode(new SourcePosition());
- for (Node classNode : classNodes) {
- blockNode.add(classNode);
- }
- return blockNode;
- }
- }
-
- /**
- * Collects all class variable occurrences
- *
- * @param root
- * @param orig
- * @param occurrences
- */
- private void pushClassVarRefs(Node root, Node orig, List<ISourcePosition> occurrences) {
- Node searchSpace = determineSearchSpace(root, orig);
-
- // Finalize searchSpace because Java's scoping rules are the awesome
- // todo: not needed?
- // final Node finalSearchSpace = searchSpace;
-
- // Get name of local variable reference
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isClassVarRef(node)) {
- String name = ASTUtil.getNameReflectively(node);
- return (name != null && name.equals(origName));
- }
- return false;
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(getPositionOfName(searchResult, searchSpace));
- }
-
- }
-
- /**
- * Collects all global variable occurrences
- *
- * @param root
- * @param orig
- * @param occurrences
- */
- private void pushGlobalVarRefs(Node root, Node orig, List<ISourcePosition> occurrences) {
- final Node searchSpace = root;
- final String origName = ASTUtil.getNameReflectively(orig);
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return isGlobalVarRef(node) && ASTUtil.getNameReflectively(node).equals(origName);
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(getPositionOfName(searchResult, searchSpace));
- }
- }
-
- /**
- * Collects all symbol occurrences
- *
- * @param root
- * @param orig
- * @param occurrences
- */
- private void pushSymbolRefs(Node root, Node orig, List<ISourcePosition> occurrences) {
- final Node searchSpace = root;
- final String origName = ((SymbolNode) orig).getName();
-
- // Find all pertinent nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return (node instanceof SymbolNode) && ((SymbolNode) node).getName().equals(origName);
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(getPositionOfName(searchResult, searchSpace));
- }
- }
-
- // todo: complete
- // private void pushMethodRefs( Node root, Node orig, List<ISourcePosition>
- // occurrences) {
- //
- // // DefnNode DefsNode CallNode VCallNode
- //
- // System.out.println("Finding occurrences for method reference node " +
- // orig.toString() );
- //
- // final Node searchSpace = root;
- // String origName = getMethodRefName(orig);
- //
- // // If orig is a method definition, find all occurrences to that selector
- // for the orig's enclosing type
- // if ( orig instanceof DefnNode || orig instanceof DefsNode )
- // {
- // ((DefnNode)orig).g
- // }
- //
- // Node receiver = getMethodReceiver(orig);
- // }
-
- /**
- * Collects all pertinent const occurrences
- */
- private void pushConstRefs(Node root, Node orig, List<ISourcePosition> occurrences) {
- if (!isConstRef(orig)) {
- return;
- }
-
- final String matchName = ASTUtil.getNameReflectively(orig);
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isConstRef(node)) {
- return ASTUtil.getNameReflectively(node).equals(matchName);
- }
- return false;
- }
- });
-
- for (Node searchResult : searchResults) {
- occurrences.add(getPositionOfName(searchResult, root));
- }
- }
-
- /**
- * Collects all pertinent type ref occurrences
- */
- private void pushTypeRefs(Node root, Node orig, List<ISourcePosition> occurrences) {
- if (!isTypeRef(orig)) {
- return;
- }
-
- final String matchName = ASTUtil.getNameReflectively(orig);
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- if (isTypeRef(node)) {
- return getTypeRefName(node).equals(matchName);
- }
- return false;
- }
- });
-
- for (Node searchResult : searchResults) {
- occurrences.add(getPositionOfName(searchResult, root));
- }
- }
-
- private void pushReturns(Node root, Node orig, List<ISourcePosition> occurrences) {
- // TODO Combine most of this stuff with the stuff in pushLocalVareRefs
- // Find the search space
- Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
- }
- });
-
- // If no enclosing node found, search the entire space
- if (searchSpace == null) {
- searchSpace = root;
- }
-// Find all return nodes
- List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
- public boolean doesAccept(Node node) {
- return (node instanceof ReturnNode);
- }
- });
-
- // Scrape position from pertinent nodes
- for (Node searchResult : searchResults) {
- occurrences.add(searchResult.getPosition());
- }
- }
-
- // ****************************************************************************
- // *
- // * Utility methods
- // *
- // ****************************************************************************
-
- /**
- * Gets the position of the name for the specified node.
- *
- * @param node
- * Node that responds to getName() or some variant
- * @param scope
- * Scope that holds the node (pertinent for locals and args)
- * @return ISourcePosition that holds the name of the node
- */
- private ISourcePosition getPositionOfName(Node node, Node scope) {
- ISourcePosition pos = node.getPosition();
-
- // TODO refactor the getting-of-name
- String name = null;
- if (isLocalVarRef(node) || isDVarRef(node) || isInstanceVarRef(node) || isGlobalVarRef(node) || isClassVarRef(node) || isConstRef(node) || node instanceof BlockArgNode) {
- name = ASTUtil.getNameReflectively(node);
- } else if (node instanceof ClassNode) {
- name = getClassNodeName((ClassNode) node);
- String classDeclString = source.substring(pos.getStartOffset(), pos.getEndOffset());
- int begin = pos.getStartOffset() + classDeclString.indexOf(name);
- return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), begin, begin + name.length());
- } else if (node instanceof ModuleNode) {
- name = getModuleNodeName((ModuleNode) node);
- String moduleDeclString = source.substring(pos.getStartOffset(), pos.getEndOffset());
- int begin = moduleDeclString.indexOf(name);
- return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), begin, begin + name.length());
- } else if (node instanceof SymbolNode) {
- // XXX: This is a hack to get around improper offsets in my JRuby
- // copy; ":foo" returns offset for ":fo", so compensate by adding
- // one
- name = ((SymbolNode) node).getName();
- return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length() + 1);
- }
-
- if (name == null) {
- throw new RuntimeException("Couldn't get the name for: " + node.toString() + " in " + scope.toString());
- }
- return new SourcePosition(pos.getFile(), pos.getStartLine(), pos.getEndLine(), pos.getStartOffset(), pos.getStartOffset() + name.length());
- }
-
- /**
- * Helper method to get the class name froma ClassNode
- *
- * @param classNode
- * @return
- */
- private String getClassNodeName(ClassNode classNode) {
- if (classNode.getCPath() instanceof Colon2Node) {
- Colon2Node c2node = (Colon2Node) classNode.getCPath();
- return c2node.getName();
- }
- throw new RuntimeException("ClassNode.getCPath() returned other than Colon2Node: " + classNode.toString());
- }
-
- /**
- * Helper method to get the class name from a ModuleNode
- *
- * @param classNode
- * @return
- */
- private String getModuleNodeName(ModuleNode moduleNode) {
- if (moduleNode.getCPath() instanceof Colon2Node) {
- Colon2Node c2node = (Colon2Node) moduleNode.getCPath();
- return c2node.getName();
- }
- throw new RuntimeException("ModuleNode.getCPath() returned other than Colon2Node: " + moduleNode.toString());
- }
-
- /**
- * Helper method to get the class name from a const ref node (Class/Module)
- *
- * @param node
- * @return
- */
- private String getTypeRefName(Node node) {
- if (node instanceof ClassNode) {
- return getClassNodeName((ClassNode) node);
- }
- if (node instanceof ModuleNode) {
- return getModuleNodeName((ModuleNode) node);
- }
- return ASTUtil.getNameReflectively(node);
- }
-
-}
Deleted: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java 2007-06-05 15:44:47 UTC (rev 2580)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/IOccurrencesFinder.java 2007-06-06 14:30:28 UTC (rev 2581)
@@ -1,88 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2006 IBM Corporation 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
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.rubypeople.rdt.internal.ti;
-
-import java.util.Collection;
-import java.util.List;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-import org.rubypeople.rdt.core.IRubyElement;
-
-public interface IOccurrencesFinder {
-
- /**
- *
- * @param source
- * Ruby source to search for occurrences
- * @param offset
- * position in source where selection is
- * @param length
- * length of the selection
- * @return
- */
- public String initialize(String source, int offset, int length);
-
- /**
- * Returns a lit of AST Nodes back (which contain their associated
- * positions).
- *
- * @return List of AST Nodes
- */
- public List<Position> perform();
-
- public String getJobLabel();
-
- /**
- * Returns the plural label for this finder with 3 placeholders:
- * <ul>
- * <li>{0} for the {@link #getElementName() element name}</li>
- * <li>{1} for the number of results found</li>
- * <li>{2} for the scope (name of the compilation unit)</li>
- * </ul>
- *
- * @return the unformatted label
- */
- public String getUnformattedPluralLabel();
-
- /**
- * Returns the singular label for this finder with 2 placeholders:
- * <ul>
- * <li>{0} for the {@link #getElementName() element name}</li>
- * <li>{1} for the scope (name of the compilation unit)</li>
- * </ul>
- *
- * @return the unformatted label
- */
- public String getUnformattedSingularLabel();
-
- /**
- * Returns the name of the lement to look for or <code>null</code> if the
- * finder hasn't been initialized yet.
- *
- * @return the name of the element
- */
- public String getElementName();
-
- public void collectOccurrenceMatches(IRubyElement element,
- IDocument document, Collection resultingMatches);
-
- /* Preferences */
- public void setFMarkConstantOccurrences(boolean markConstantOccurrences);
- public void setFMarkFieldOccurrences(boolean markFieldOccurrences);
- public void setFMarkLocalVariableOccurrences(boolean markLocalVariableOccurrences);
- public void setFMarkMethodExitPoints(boolean markMethodExitPoints);
- public void setFMarkMethodOccurrences(boolean markMethodOccurrences);
- public void setFMarkOccurrenceAnnotations(boolean markOccurrenceAnnotations);
- public void setFMarkTypeOccurrences(boolean markTypeOccurrences);
- public void setFStickyOccurrenceAnnotations(boolean stickyOccurrenceAnnotations);
-
-}
Deleted: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java 2007-06-05 15:44:47 UTC (rev 2580)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/MarkOccurrencesTest.java 2007-06-06 14:30:28 UTC (rev 2581)
@@ -1,215 +0,0 @@
-package org.rubypeople.rdt.internal.ti;
-
-import java.util.List;
-
-import junit.framework.TestCase;
-
-import org.eclipse.jface.text.Position;
-
-/**
- * Tests related to matching occurrences.
- *
- * @author Jason Morrison
- *`
- */
-public class MarkOccurrencesTest extends TestCase {
-
- private IOccurrencesFinder occurrencesFinder;
- public void setUp() {
- occurrencesFinder = new DefaultOccurrencesFinder();
- occurrencesFinder.setFMarkConstantOccurrences(true);
- occurrencesFinder.setFMarkFieldOccurrences(true);
- occurrencesFinder.setFMarkLocalVariableOccurrences(true);
- occurrencesFinder.setFMarkMethodExitPoints(true);
- occurrencesFinder.setFMarkMethodOccurrences(true);
- occurrencesFinder.setFMarkOccurrenceAnnotations(true);
- occurrencesFinder.setFMarkTypeOccurrences(true);
- occurrencesFinder.setFStickyOccurrenceAnnotations(true);
- }
-
- private void assertOccurrencesEqual(String source, int offset, String matchName, int[][] offsets )
- {
- occurrencesFinder.initialize(source, offset, 0);
- List<Position> occurrences = occurrencesFinder.perform();
- assertEquals( offsets.length, occurrences.size() );
-
- for ( int i = 0; i < offsets.length; i++ ) {
- int start = occurrences.get(i).getOffset();
- int length = occurrences.get(i).getLength();
- int end = occurrences.get(i).getOffset() + length;
-
- Position testPosition = new Position( start, length );
-
- assertTrue( occurrences.contains( testPosition ) );
-
-// assertEquals( offsets[i][0], start );
-// assertEquals( offsets[i][1], end );
- assertEquals( matchName, source.substring(start, end));
- }
- }
-
- /**
- * Match locals within ClassNode::DefnNode
- */
- public void testLocalVariableMatches() {
- String source = "class Klass;def foo(x);puts x*2;end;def bar;my_var = 5;my_var = 6;puts my_var;foo(my_var);end;end";
- int[][] offsets = {{44,50},{55,61},{71,77},{82,88}};
- assertOccurrencesEqual( source, 46, "my_var", offsets );
- }
-
- /**
- * Match args to locals
- */
- public void testArgMatches() {
- String source = "class Klass;def foo(my_arg);puts my_arg*2;end;end";
- int[][] offsets = {{20,26},{33,39}};
- assertOccurrencesEqual( source, 22, "my_arg", offsets );
- }
-
- /**
- * Match locals within Kernel::DefnNode
- */
- public void testLocalVariablesInKernelDefnScope() {
- String source = "def foo;my_var=5;puts my_var*2;end";
- int[][] offsets = {{8,14},{22,28}};
- assertOccurrencesEqual( source, 10, "my_var", offsets );
- }
-
- /**
- * Match locals in Kernel
- */
- public void testLocalVariablesInKernelScope() {
- String source = "my_var = 5;puts my_var*2;other_var = my_var * my_var";
- int[][] offsets = {{0,6},{16,22},{37,43},{46,52}};
- assertOccurrencesEqual( source, 1, "my_var", offsets );
- }
-
- /**
- * Match instance vars inside one ClassNode across DefnNode
- */
- public void testInstanceVariableMatches() {
- String source = "class Klass;def foo(param);@inst_var = param;puts @inst_var;end;def bar;y @inst_var;end;end";
- int[][] offsets = {{27,36},{50,59},{74,83}};
- assertOccurrencesEqual( source, 29, "@inst_var", offsets );
- }
-
- /**
- * Match instance vars inside two DefnNodes, each in a separate ClassNode (for the same class)
- */
- public void testInstanceVariableMatchInReopenedClass() {
- String source = "class Klass;def foo;@inst_var=5;end;end;class Klass;def bar;@inst_var=6;end;end";
- int[][] offsets = {{20,29},{60,69}};
- assertOccurrencesEqual( source, 23, "@inst_var", offsets );
- }
-
- /**
- * Test matching a local variable before, inside, and after a block.
- */
- public void testLocalVariableMatchesIntoBlockScope() {
- String source = "class Klass;def foo;my_var = 5;5.times { puts my_var };puts my_var;end;end";
- int[][] offsets = {{20,26},{46,52},{60,66}};
- assertOccurrencesEqual( source, 23, "my_var", offsets );
- }
-
- /**
- * Test referencing a global variable in various contexts.
- *
- */
- public void testGlobalVariableMatches() {
- String source = "$foo = 'bar';class Klass;def foo;$foo = 5;end;def bar;puts $foo;end;end;puts $foo";
- int[][] offsets = {{0,4},{33,37},{59,63},{77,81}};
- assertOccurrencesEqual(source, 0, "$foo", offsets);
- }
-
- /**
- * Test referencing a symbol in various contexts.
- *
- */
- public void testSymbolMatches() {
- String source = "a_var = :foo;class Klass;def foo;l = :foo;end;def bar;puts :foo;end;end;puts :foo.to_s";
-// String source = "$foo = 'bar';class Klass;def foo;$foo = 5;end;def bar;puts $foo;end;end;puts $foo";
- int[][] offsets = {{8,12},{37,41},{59,63},{77,81}};
- assertOccurrencesEqual(source, 9, ":foo", offsets);
- }
-
-//TODO: Method invocation tests need to know the type of their receiver.
-// Sub-goals are becoming necessary, i.e. for determining arg-type to match selectors by more
-// than name, and determining receiver-type to match selectors applied to other same-typed receivers.
-
-// public void testMethodInvocationMatchInsideMethod() {
-// String source = "class Klass;def foo;my_var = 5;y = my_var.to_s;puts y.to_s;end;end";
-// int[][] offsets = {{42,46},{54,58}};
-// assertOccurrencesEquals( source, 42, "to_s", offsets );
-// }
-//
-// public void testMethodInvocationMatchInKernelScope() {
-// String source = "my_var = 5;y = my_var.to_s;puts y.to_s";
-// int[][] offsets = {{22,26},{34,38}};
-// assertOccurrencesEquals(source, 22, "to_s", offsets);
-// }
-//
-// public void testStaticMethodInvocationMatchInKernelScope() {
-// String source = "puts 5;puts 6;puts 7;";
-// int[][] offsets = {{0,4},{7,11},{14,18}};
-// assertOccurrencesEquals( source, 0, "puts", offsets );
-// }
-//
-// public void testMethodInvocationMatchAgainstMultipleInstancesOfSameType() {
-// String source = "xvar = 5;yvar = 6;puts xvar.to_s;puts yvar.to_s";
-// int[][] offsets = {{28,32},{43,47}};
-// assertOccurrencesEquals(source, 28, "to_s", offsets);
-// }
-
- /**
- * Test matching against ConstNodes; specifically class occurrences
- */
- public void testTypeMatches() {
- String source = "f = String.new;class Klass;def foo;c = String;end;end;class MyString < String;end";
- int[][] offsets = {{4,10},{39,45},{71,77}};
- assertOccurrencesEqual( source, 4, "String", offsets );
- }
-
- public void testConstNodeToClassDeclNode() {
- String source = "class Klass;def foo;5;end;end;k = Klass.new";
- int[][] offsets = {{6,11},{34,39}};
- assertOccurrencesEqual( source, 34, "Klass", offsets );
- }
-
- public void testBlockArguments() {
- String source = "[1,2,3].each { |number| puts number }";
- int[][] offsets = {{16,22},{29,35}};
- assertOccurrencesEqual(source, 16, "number", offsets);
-// assertOccurrencesEqual(source, 29, "number", offsets);
- }
-
-
- /**
- * Match instance vars inside one ClassNode across DefnNode
- */
- public void testClassVariableMatches() {
- String source = "class Klass;def foo(param);@@cls_var = param;puts @@cls_var;end;def bar;y @@cls_var;end;end";
- int[][] offsets = {{27,36},{50,59},{74,83}};
- assertOccurrencesEqual( source, 29, "@@cls_var", offsets );
- }
-
- /**
- * Match instance vars inside two DefnNodes, each in a separate ClassNode (for the same class)
- */
- public void testClassVariableMatchInReopenedClass() {
- String source = "class Klass;def foo;@@cls_var=5;end;end;class Klass;def bar;@@cls_var=6;end;end";
- int[][] offsets = {{20,29},{60,69}};
- assertOccurrencesEqual( source, 23, "@@cls_var", offsets );
- }
-
-// Oddity with local/dvars:
-//
-// foo = Printer.new
-// [person, place, thing].each do |noun|
-// foo.print(noun)
-// end
-// noun = "hi"
-//
-// There are 3 refs to "noun". Clicking the first highlights 1&2, clicking 2 highlights 1&2
-// but clicking 3 highlights 2&3 - ????!
-
-}
Modified: trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/TS_TypeInference.java
===================================================================
--- trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/TS_TypeInference.java 2007-06-05 15:44:47 UTC (rev 2580)
+++ trunk/org.rubypeople.rdt.core.tests/src/org/rubypeople/rdt/internal/ti/TS_TypeInference.java 2007-06-06 14:30:28 UTC (rev 2581)
@@ -7,7 +7,6 @@
public static Test suite() {
TestSuite suite = new TestSuite("Type Inference");
suite.addTestSuite(DataFlowTypeInferrerTest.class);
- suite.addTestSuite(MarkOccurrencesTest.class);
suite.addTestSuite(ReferenceMatchTest.class);
suite.addTestSuite(TypeInferrerTest.class);
return suite;
Copied: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java (from rev 2574, trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java)
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java (rev 0)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/DefaultOccurrencesFinder.java 2007-06-06 14:30:28 UTC (rev 2581)
@@ -0,0 +1,730 @@
+package org.rubypeople.rdt.internal.ui.search;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedList;
+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.Position;
+import org.eclipse.search.ui.text.Match;
+import org.jruby.ast.ArgumentNode;
+import org.jruby.ast.BlockArgNode;
+import org.jruby.ast.BlockNode;
+import org.jruby.ast.ClassNode;
+import org.jruby.ast.ClassVarAsgnNode;
+import org.jruby.ast.ClassVarDeclNode;
+import org.jruby.ast.ClassVarNode;
+import org.jruby.ast.Colon2Node;
+import org.jruby.ast.ConstNode;
+import org.jruby.ast.DAsgnNode;
+import org.jruby.ast.DVarNode;
+import org.jruby.ast.DefnNode;
+import org.jruby.ast.DefsNode;
+import org.jruby.ast.GlobalAsgnNode;
+import org.jruby.ast.GlobalVarNode;
+import org.jruby.ast.InstAsgnNode;
+import org.jruby.ast.InstVarNode;
+import org.jruby.ast.LocalAsgnNode;
+import org.jruby.ast.LocalVarNode;
+import org.jruby.ast.ModuleNode;
+import org.jruby.ast.Node;
+import org.jruby.ast.ReturnNode;
+import org.jruby.ast.SymbolNode;
+import org.jruby.lexer.yacc.ISourcePosition;
+import org.jruby.lexer.yacc.SourcePosition;
+import org.jruby.lexer.yacc.SyntaxException;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.internal.core.parser.RubyParser;
+import org.rubypeople.rdt.internal.core.util.ASTUtil;
+import org.rubypeople.rdt.internal.ti.AbstractOccurencesFinder;
+import org.rubypeople.rdt.internal.ti.util.FirstPrecursorNodeLocator;
+import org.rubypeople.rdt.internal.ti.util.INodeAcceptor;
+import org.rubypeople.rdt.internal.ti.util.OffsetNodeLocator;
+import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator;
+
+/**
+ * Implements "Mark Occurences" feature
+ *
+ * @author Jason Morrison
+ *
+ */
+public class DefaultOccurrencesFinder extends AbstractOccurencesFinder {
+
+ // Root of the document to search
+ private Node root;
+
+ // Originating node; corresponds to cursor selection
+ private Node fSelectedNode;
+
+ private List<Node> fUsages= new ArrayList<Node>();
+ private List<Node> fWriteUsages= new ArrayList<Node>();
+
+ // Original source
+ private String source;
+
+ public String getJobLabel() {
+ return SearchMessages.OccurrencesFinder_searchfor;
+ }
+
+ public String getUnformattedPluralLabel() {
+ return SearchMessages.OccurrencesFinder_label_plural;
+ }
+
+ public String getUnformattedSingularLabel() {
+ return SearchMessages.OccurrencesFinder_label_singular;
+ }
+
+ public void collectOccurrenceMatches(IRubyElement element, IDocument document, Collection resultingMatches) {
+ HashMap lineToGroup= new HashMap();
+
+ for (Iterator iter= fUsages.iterator(); iter.hasNext();) {
+ Node node= (Node) iter.next();
+ ISourcePosition position = getPositionOfName(node);
+ int startPosition= position.getStartOffset();
+ int length= position.getEndOffset() - position.getStartOffset();
+ try {
+ boolean isWriteAccess= fWriteUsages.contains(node);
+ int line= document.getLineOfOffset(startPosition);
+ Integer lineInteger= new Integer(line);
+ OccurrencesGroupKey groupKey= (OccurrencesGroupKey) lineToGroup.get(lineInteger);
+ if (groupKey == null) {
+ IRegion region= document.getLineInformation(line);
+ String lineContents= document.get(region.getOffset(), region.getLength()).trim();
+ groupKey= new OccurrencesGroupKey(element, line, lineContents, isWriteAccess, isVariable(element));
+ lineToGroup.put(lineInteger, groupKey);
+ } else if (isWriteAccess) {
+ // a line with read an write access is considered as write access:
+ groupKey.setWriteAccess(true);
+ }
+ Match match= new Match(groupKey, startPosition, length);
+ resultingMatches.add(match);
+ } catch (BadLocationException e) {
+ //nothing
+ }
+ }
+ }
+
+ private boolean isVariable(IRubyElement element) {
+ return element.isType(IRubyElement.INSTANCE_VAR) || element.isType(IRubyElement.GLOBAL) || element.isType(IRubyElement.CLASS_VAR) || element.isType(IRubyElement.LOCAL_VARIABLE) || element.isType(IRubyElement.DYNAMIC_VAR);
+ }
+
+ public String initialize(Node root, int offset, int length) {
+ if (root == null) {
+ return null;
+ }
+ this.root = root;
+ this.fSelectedNode = OffsetNodeLocator.Instance().getNodeAtOffset(root, offset);
+ if (fSelectedNode == null) {
+ return SearchMessages.OccurrencesFinder_no_element;
+ }
+// if (fSelectedNode.getPosition().getEndOffset() > offset + length) {
+// // Selection spans nodes; not handling that for now.
+// return "Selection spans nodes; can only search for a single node.";
+// }
+ return null;
+ }
+
+ public String initialize(String source, int offset, int length) {
+ if (source == null) {
+ return null;
+ } else {
+ this.source = source;
+ }
+
+ Node root = null;
+ try {
+ RubyParser rubyParser = new RubyParser();
+ root = rubyParser.parse(source);
+ }
+ // TODO: Is there anything else the parsing could choke on that should
+ // be silently ignored with no markings?
+ catch (SyntaxException se) {
+ // ignore
+ }
+ return initialize(root, offset, length);
+ }
+
+ /**
+ * Determines the kind of originating node, and collects occurrences
+ * accordingly
+ */
+ public List<Position> perform() {
+ // Mark no occurrences if root is null (AST couldn't be parsed
+ // correctly.)
+ if (root == null)
+ return new LinkedList<Position>();
+ if (fSelectedNode == null)
+ return new LinkedList<Position>();
+
+ if (fMarkLocalVariableOccurrences && isLocalVarRef(fSelectedNode)) {
+ pushLocalVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkLocalVariableOccurrences && isDVarRef(fSelectedNode)) {
+ pushDVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkLocalVariableOccurrences && isInstanceVarRef(fSelectedNode)) {
+ pushInstVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkLocalVariableOccurrences && isClassVarRef(fSelectedNode)) {
+ pushClassVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkLocalVariableOccurrences && isGlobalVarRef(fSelectedNode)) {
+ pushGlobalVarRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkConstantOccurrences && fSelectedNode instanceof SymbolNode) {
+ pushSymbolRefs(root, fSelectedNode, fUsages);
+ }
+
+ // if ( isMethodRefNode(fSelectedNode)) {
+ // pushMethodRefs( root, fSelectedNode, occurrences );
+ // }
+
+ if (fMarkConstantOccurrences && isConstRef(fSelectedNode)) {
+ pushConstRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkTypeOccurrences && isTypeRef(fSelectedNode)) {
+ pushTypeRefs(root, fSelectedNode, fUsages);
+ }
+
+ if (fMarkMethodExitPoints) {
+ pushReturns(root, fSelectedNode, fUsages);
+ }
+
+ // Convert ISourcePosition to IPosition
+ List<Position> positions = new LinkedList<Position>();
+ for (Node node : fUsages) {
+ ISourcePosition occurrence = getPositionOfName(node);
+ Position position = new Position(occurrence.getStartOffset(), occurrence.getEndOffset() - occurrence.getStartOffset());
+ positions.add(position);
+ }
+
+ // Uniqueify positions
+ positions = new LinkedList<Position>(new HashSet<Position>(positions));
+
+ return positions;
+ }
+
+ // ****************************************************************************
+ // *
+ // * Reference kind definitions
+ // *
+ // ****************************************************************************
+
+ /**
+ * Determines whether a given node is a local variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isLocalVarRef(Node node) {
+ return ((node instanceof LocalAsgnNode) || (node instanceof ArgumentNode) || (node instanceof LocalVarNode));
+ }
+
+ /**
+ * Determines whether a given node is a dynamic variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isDVarRef(Node node) {
+ return ((node instanceof DVarNode) || (node instanceof DAsgnNode));
+ }
+
+ /**
+ * Determines whether a given node is an instance variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isInstanceVarRef(Node node) {
+ return ((node instanceof InstAsgnNode) || (node instanceof InstVarNode));
+ }
+
+ /**
+ * Determines whether a given node is a class variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isClassVarRef(Node node) {
+ return ((node instanceof ClassVarNode) || (node instanceof ClassVarAsgnNode) || (node instanceof ClassVarDeclNode));
+ }
+
+ /**
+ * Determines whether a given node is a global variable reference
+ *
+ * @param node
+ * @return
+ */
+ private boolean isGlobalVarRef(Node node) {
+ return ((node instanceof GlobalAsgnNode) || (node instanceof GlobalVarNode));
+ }
+
+ /**
+ * Determines whether a given node is a constant reference (constant)
+ *
+ * @param node
+ * @return
+ */
+ private boolean isConstRef(Node node) {
+ return (node instanceof ConstNode);
+ }
+
+ /**
+ * Determines whether a given node is a type reference (class, module)
+ *
+ * @param node
+ * @return
+ */
+ private boolean isTypeRef(Node node) {
+ // TODO: Classes can be referred to as a ConstNode; i.e. "class
+ // Klass;end; k = Klass.new" the last reference is a ConstNode, not a
+ // ClassNode. Special way to handle this?
+ return ((node instanceof ClassNode) || (node instanceof ModuleNode) || (node instanceof ConstNode));
+ }
+
+ // ****************************************************************************
+ // *
+ // * Worker methods - handles delegation of occurrence searches
+ // *
+ // ****************************************************************************
+
+ /**
+ * Collects all corresponding local variable occurrences
+ *
+ * @param root
+ * Root node to search
+ * @param fSelectedNode
+ * Originating node
+ * @param occurrences
+ */
+ private void pushLocalVarRefs(Node root, Node orig, List<Node> occurrences) {
+ // Find the search space
+ Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
+ }
+ });
+
+ // If no enclosing node found, search the entire space
+ if (searchSpace == null) {
+ searchSpace = root;
+ }
+
+ // Finalize searchSpace because Java's scoping rules are the awesome
+ final Node finalSearchSpace = searchSpace;
+
+ // Get name of local variable reference
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ String name = ASTUtil.getNameReflectively(node);
+ return (name != null && name.equals(origName));
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ /**
+ * Collects all corresponding dynamic variable occurrences
+ *
+ * @param root
+ * Root node to search
+ * @param fSelectedNode
+ * Originating node
+ * @param occurrences
+ */
+ private void pushDVarRefs(Node root, Node orig, List<Node> occurrences) {
+ // Find the search space
+ Node searchSpace = FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return ((node instanceof DefnNode) || (node instanceof DefsNode) ); // TODO: Block Body?
+ }
+ });
+
+ // If no enclosing node found, search the entire space
+ if (searchSpace == null) {
+ searchSpace = root;
+ }
+
+ // Get name of local variable reference
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isDVarRef(node)) {
+ String name = ASTUtil.getNameReflectively(node);
+ return (name != null && name.equals(origName));
+ }
+ return false;
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ /**
+ * Collects all instance variable occurrences
+ *
+ * @param root
+ * @param fSelectedNode
+ * @param occurrences
+ */
+ private void pushInstVarRefs(Node root, Node orig, List<Node> occurrences) {
+ Node searchSpace = determineSearchSpace(root, orig);
+
+ // Finalize searchSpace because Java's scoping rules are the awesome
+ // todo: not needed?
+ // final Node finalSearchSpace = searchSpace;
+
+ // Get name of local variable reference
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isInstanceVarRef(node)) {
+ String name = ASTUtil.getNameReflectively(node);
+ return (name != null && name.equals(origName));
+ }
+ return false;
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+
+ }
+
+ private Node determineSearchSpace(Node root, Node orig) {
+
+ // Find the name of the enclosing class
+ ClassNode enclosingClass = (ClassNode) FirstPrecursorNodeLocator.Instance().findFirstPrecursor(root, orig.getPosition().getStartOffset(), new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return (node instanceof ClassNode);
+ }
+ });
+
+ // If no enclosing class is identified, search root.
+ if (enclosingClass == null) {
+ return root;
+ }
+ // Find the search space - all ClassNodes for that name within root
+ // scope
+ else {
+ final String className = getClassNodeName(enclosingClass);
+ List<Node> classNodes = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (node instanceof ClassNode) {
+ return getClassNodeName((ClassNode) node).equals(className);
+ }
+ return false;
+ }
+ });
+ BlockNode blockNode = new BlockNode(new SourcePosition());
+ for (Node classNode : classNodes) {
+ blockNode.add(classNode);
+ }
+ return blockNode;
+ }
+ }
+
+ /**
+ * Collects all class variable occurrences
+ *
+ * @param root
+ * @param fSelectedNode
+ * @param occurrences
+ */
+ private void pushClassVarRefs(Node root, Node orig, List<Node> occurrences) {
+ Node searchSpace = determineSearchSpace(root, orig);
+
+ // Finalize searchSpace because Java's scoping rules are the awesome
+ // todo: not needed?
+ // final Node finalSearchSpace = searchSpace;
+
+ // Get name of local variable reference
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isClassVarRef(node)) {
+ String name = ASTUtil.getNameReflectively(node);
+ return (name != null && name.equals(origName));
+ }
+ return false;
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+
+ }
+
+ /**
+ * Collects all global variable occurrences
+ *
+ * @param root
+ * @param fSelectedNode
+ * @param occurrences
+ */
+ private void pushGlobalVarRefs(Node root, Node orig, List<Node> occurrences) {
+ final Node searchSpace = root;
+ final String origName = ASTUtil.getNameReflectively(orig);
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return isGlobalVarRef(node) && ASTUtil.getNameReflectively(node).equals(origName);
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ /**
+ * Collects all symbol occurrences
+ *
+ * @param root
+ * @param fSelectedNode
+ * @param occurrences
+ */
+ private void pushSymbolRefs(Node root, Node orig, List<Node> occurrences) {
+ final Node searchSpace = root;
+ final String origName = ((SymbolNode) orig).getName();
+
+ // Find all pertinent nodes
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(searchSpace, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ return (node instanceof SymbolNode) && ((SymbolNode) node).getName().equals(origName);
+ }
+ });
+
+ // Scrape position from pertinent nodes
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ // todo: complete
+ // private void pushMethodRefs( Node root, Node fSelectedNode, List<ISourcePosition>
+ // occurrences) {
+ //
+ // // DefnNode DefsNode CallNode VCallNode
+ //
+ // System.out.println("Finding occurrences for method reference node " +
+ // fSelectedNode.toString() );
+ //
+ // final Node searchSpace = root;
+ // String origName = getMethodRefName(fSelectedNode);
+ //
+ // // If fSelectedNode is a method definition, find all occurrences to that selector
+ // for the fSelectedNode's enclosing type
+ // if ( fSelectedNode instanceof DefnNode || fSelectedNode instanceof DefsNode )
+ // {
+ // ((DefnNode)fSelectedNode).g
+ // }
+ //
+ // Node receiver = getMethodReceiver(fSelectedNode);
+ // }
+
+ /**
+ * Collects all pertinent const occurrences
+ */
+ private void pushConstRefs(Node root, Node orig, List<Node> occurrences) {
+ if (!isConstRef(orig)) {
+ return;
+ }
+
+ final String matchName = ASTUtil.getNameReflectively(orig);
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isConstRef(node)) {
+ return ASTUtil.getNameReflectively(node).equals(matchName);
+ }
+ return false;
+ }
+ });
+
+ for (Node searchResult : searchResults) {
+ occurrences.add(searchResult);
+ }
+ }
+
+ /**
+ * Collects all pertinent type ref occurrences
+ */
+ private void pushTypeRefs(Node root, Node orig, List<Node> occurrences) {
+ if (!isTypeRef(orig)) {
+ return;
+ }
+
+ final String matchName = ASTUtil.getNameReflectively(orig);
+ List<Node> searchResults = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
+ public boolean doesAccept(Node node) {
+ if (isTypeRef(node...
[truncated message content] |
|
From: <caw...@us...> - 2007-06-05 15:44:55
|
Revision: 2580
http://svn.sourceforge.net/rubyeclipse/?rev=2580&view=rev
Author: cawilliams
Date: 2007-06-05 08:44:47 -0700 (Tue, 05 Jun 2007)
Log Message:
-----------
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.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/rubyeditor/EditorUtility.java
Modified: trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF 2007-06-05 14:54:47 UTC (rev 2579)
+++ trunk/org.rubypeople.rdt.ui/META-INF/MANIFEST.MF 2007-06-05 15:44:47 UTC (rev 2580)
@@ -52,6 +52,7 @@
org.rubypeople.rdt.core,
org.eclipse.ui.workbench,
org.eclipse.ui.forms,
+ org.eclipse.ui.navigator,
org.rubypeople.rdt.launching,
org.eclipse.search,
org.jruby,
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java 2007-06-05 14:54:47 UTC (rev 2579)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/corext/util/RubyModelUtil.java 2007-06-05 15:44:47 UTC (rev 2580)
@@ -3,6 +3,7 @@
*/
package org.rubypeople.rdt.internal.corext.util;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
@@ -139,4 +140,35 @@
public static String getTypeQualifiedName(IType type) {
return type.getTypeQualifiedName("::");
}
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=19253
+ *
+ * Reconciling happens in a separate thread. This can cause a situation where the
+ * Java element gets disposed after an exists test has been done. So we should not
+ * log not present exceptions when they happen in working copies.
+ */
+ public static boolean isExceptionToBeLogged(CoreException exception) {
+ if (!(exception instanceof RubyModelException))
+ return true;
+ RubyModelException je= (RubyModelException)exception;
+ if (!je.isDoesNotExist())
+ return true;
+ IRubyElement[] elements= je.getRubyModelStatus().getElements();
+ for (int i= 0; i < elements.length; i++) {
+ IRubyElement element= elements[i];
+ // if the element is already a compilation unit don't log
+ // does not exist exceptions. See bug
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=75894
+ // for more details
+ if (element.getElementType() == IRubyElement.SCRIPT)
+ continue;
+ IRubyScript unit= (IRubyScript)element.getAncestor(IRubyElement.SCRIPT);
+ if (unit == null)
+ return true;
+ if (!unit.isWorkingCopy())
+ return true;
+ }
+ return false;
+ }
}
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-06-05 14:54:47 UTC (rev 2579)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/actions/SelectionConverter.java 2007-06-05 15:44:47 UTC (rev 2580)
@@ -1,14 +1,20 @@
package org.rubypeople.rdt.internal.ui.actions;
+import java.lang.reflect.InvocationTargetException;
+
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.PlatformUI;
import org.rubypeople.rdt.core.ICodeAssist;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
+import org.rubypeople.rdt.internal.ui.rubyeditor.EditorUtility;
import org.rubypeople.rdt.internal.ui.rubyeditor.IRubyScriptEditorInput;
import org.rubypeople.rdt.internal.ui.rubyeditor.RubyEditor;
import org.rubypeople.rdt.ui.IWorkingCopyManager;
@@ -79,4 +85,41 @@
return EMPTY_RESULT;
}
+ /**
+ * Perform a code resolve in a separate thread.
+ * @param primaryOnly if <code>true</code> only primary working copies will be returned
+ * @throws InterruptedException
+ * @throws InvocationTargetException
+ * @since 1.0
+ */
+ public static IRubyElement[] codeResolveForked(RubyEditor editor, boolean primaryOnly) throws InvocationTargetException, InterruptedException {
+ return performForkedCodeResolve(getInput(editor, primaryOnly), (ITextSelection)editor.getSelectionProvider().getSelection());
+ }
+
+ /**
+ * @param primaryOnly if <code>true</code> only primary working copies will be returned
+ * @since 1.0
+ */
+ private static IRubyElement getInput(RubyEditor editor, boolean primaryOnly) {
+ if (editor == null)
+ return null;
+ return EditorUtility.getEditorInputRubyElement(editor, primaryOnly);
+ }
+
+ private static IRubyElement[] performForkedCodeResolve(final IRubyElement input, final ITextSelection selection) throws InvocationTargetException, InterruptedException {
+ final class CodeResolveRunnable implements IRunnableWithProgress {
+ IRubyElement[] result;
+ public void run(IProgressMonitor monitor) throws InvocationTargetException {
+ try {
+ result= codeResolve(input, selection);
+ } catch (RubyModelException e) {
+ throw new InvocationTargetException(e);
+ }
+ }
+ }
+ CodeResolveRunnable runnable= new CodeResolveRunnable();
+ PlatformUI.getWorkbench().getProgressService().busyCursorWhile(runnable);
+ return runnable.result;
+ }
+
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java 2007-06-05 14:54:47 UTC (rev 2579)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java 2007-06-05 15:44:47 UTC (rev 2580)
@@ -41,6 +41,7 @@
import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.ui.PreferenceConstants;
+import org.rubypeople.rdt.ui.RubyUI;
public class EditorUtility {
@@ -352,4 +353,25 @@
return Messages.format(RubyEditorMessages.EditorUtility_concatModifierStrings, new String[] {modifierString, newModifierString});
}
+ /**
+ * Returns the given editor's input as Ruby element.
+ *
+ * @param editor the editor
+ * @param primaryOnly if <code>true</code> only primary working copies will be returned
+ * @return the given editor's input as Ruby element or <code>null</code> if none
+ * @since 1.0
+ */
+ public static IRubyElement getEditorInputRubyElement(IEditorPart editor, boolean primaryOnly) {
+ Assert.isNotNull(editor);
+ IEditorInput editorInput= editor.getEditorInput();
+ if (editorInput == null)
+ return null;
+
+ IRubyElement je= RubyUI.getEditorInputRubyElement(editorInput);
+ if (je != null || primaryOnly)
+ return je;
+
+ return RubyPlugin.getDefault().getWorkingCopyManager().getWorkingCopy(editorInput, false);
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-05 14:54:48
|
Revision: 2579
http://svn.sourceforge.net/rubyeclipse/?rev=2579&view=rev
Author: cawilliams
Date: 2007-06-05 07:54:47 -0700 (Tue, 05 Jun 2007)
Log Message:
-----------
some fixes
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/IndexSelector.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/CharOperation.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java 2007-06-05 14:52:04 UTC (rev 2578)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java 2007-06-05 14:54:47 UTC (rev 2579)
@@ -180,7 +180,7 @@
public IResource getResource() {
SourceFolderRoot root = this.getSourceFolderRoot();
- if (root.isArchive()) {
+ if (root.isExternal()) {
return root.getResource();
}
int length = this.names.length;
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/IndexSelector.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/IndexSelector.java 2007-06-05 14:52:04 UTC (rev 2578)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/IndexSelector.java 2007-06-05 14:54:47 UTC (rev 2579)
@@ -19,6 +19,7 @@
import org.rubypeople.rdt.core.search.IRubySearchScope;
import org.rubypeople.rdt.core.search.SearchPattern;
import org.rubypeople.rdt.internal.compiler.util.SimpleSet;
+import org.rubypeople.rdt.internal.core.ExternalSourceFolderRoot;
import org.rubypeople.rdt.internal.core.RubyModelManager;
import org.rubypeople.rdt.internal.core.RubyProject;
import org.rubypeople.rdt.internal.core.search.indexing.IndexManager;
@@ -90,17 +91,17 @@
return true;
}
}
-// if (focus instanceof JarSourceFolderRoot) {
-// // focus is part of a jar
-// IPath focusPath = focus.getPath();
-// ILoadpathEntry[] entries = javaProject.getExpandedLoadpath();
-// for (int i = 0, length = entries.length; i < length; i++) {
-// ILoadpathEntry entry = entries[i];
-// if (entry.getEntryKind() == ILoadpathEntry.CPE_LIBRARY && entry.getPath().equals(focusPath))
-// return true;
-// }
-// return false;
-// }
+ if (focus instanceof ExternalSourceFolderRoot) {
+ // focus is part of a jar
+ IPath focusPath = focus.getPath();
+ ILoadpathEntry[] entries = javaProject.getExpandedLoadpath(true);
+ for (int i = 0, length = entries.length; i < length; i++) {
+ ILoadpathEntry entry = entries[i];
+ if (entry.getEntryKind() == ILoadpathEntry.CPE_LIBRARY && entry.getPath().equals(focusPath))
+ return true;
+ }
+ return false;
+ }
// look for dependent projects
IPath focusPath = ((RubyProject) focus).getProject().getFullPath();
ILoadpathEntry[] entries = javaProject.getExpandedLoadpath(true);
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/CharOperation.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/CharOperation.java 2007-06-05 14:52:04 UTC (rev 2578)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/CharOperation.java 2007-06-05 14:54:47 UTC (rev 2579)
@@ -1648,7 +1648,8 @@
}
public static char[] concatWith(char[][] enclosingTypeNames, String string) {
- StringBuffer buffer = new StringBuffer();
+ if (enclosingTypeNames == null) return NO_CHAR;
+ StringBuffer buffer = new StringBuffer();
for (int i = 0; i < enclosingTypeNames.length; i++) {
char[] name = enclosingTypeNames[i];
if (i > 0) buffer.append(string);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-05 14:52:07
|
Revision: 2578
http://svn.sourceforge.net/rubyeclipse/?rev=2578&view=rev
Author: cawilliams
Date: 2007-06-05 07:52:04 -0700 (Tue, 05 Jun 2007)
Log Message:
-----------
fix some issues with detecting file paths on console
Modified Paths:
--------------
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/console/RubyConsoleTracker.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/util/StackTraceLine.java
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/console/RubyConsoleTracker.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/console/RubyConsoleTracker.java 2007-06-01 18:56:59 UTC (rev 2577)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/console/RubyConsoleTracker.java 2007-06-05 14:52:04 UTC (rev 2578)
@@ -26,6 +26,7 @@
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.debug.ui.console.IConsole;
import org.eclipse.debug.ui.console.IConsoleLineTracker;
@@ -56,8 +57,16 @@
public boolean fileExists(String filename) {
File file = new File(filename);
if (file.exists()) return true;
- IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filename));
- if (iFile != null) return true;
+ IPath path = new Path(filename);
+ if (!path.isValidPath(filename)) {
+ return false;
+ }
+ try {
+ IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+ if (iFile != null) return iFile.exists();
+ } catch (IllegalArgumentException e) {
+ return false;
+ }
return false;
}
}
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/util/StackTraceLine.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/util/StackTraceLine.java 2007-06-01 18:56:59 UTC (rev 2577)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/util/StackTraceLine.java 2007-06-05 14:52:04 UTC (rev 2578)
@@ -86,7 +86,8 @@
private boolean isRelativePath() {
if (fFilename.startsWith("./")) return true;
- if (!fFilename.startsWith("/") && fFilename.charAt(fFilename.indexOf('/') - 1) != ':' ) return true;
+ int index = fFilename.indexOf('/');
+ if (index != -1 && !fFilename.startsWith("/") && fFilename.charAt(index - 1) != ':' ) return true;
return false;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-01 18:57:06
|
Revision: 2577
http://svn.sourceforge.net/rubyeclipse/?rev=2577&view=rev
Author: cawilliams
Date: 2007-06-01 11:56:59 -0700 (Fri, 01 Jun 2007)
Log Message:
-----------
gobble up null pointers
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java 2007-06-01 18:39:58 UTC (rev 2576)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyCompletionProcessor.java 2007-06-01 18:56:59 UTC (rev 2577)
@@ -122,6 +122,7 @@
private ICompletionProposal[] codeComplete(int offset) {
try {
IRubyScript script = fManager.getWorkingCopy(fEditor.getEditorInput());
+ if (script == null) return new ICompletionProposal[0];
RubyScriptCompletion requestor = new RubyScriptCompletion(script); // TODO Instantiate a real one
requestor.beginReporting();
script.codeComplete(offset - 1, requestor);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-01 18:40:00
|
Revision: 2576
http://svn.sourceforge.net/rubyeclipse/?rev=2576&view=rev
Author: cawilliams
Date: 2007-06-01 11:39:58 -0700 (Fri, 01 Jun 2007)
Log Message:
-----------
hmm, really shouldn't add dependencies on those plugins here....
Modified Paths:
--------------
trunk/org.jruby/META-INF/MANIFEST.MF
Modified: trunk/org.jruby/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.jruby/META-INF/MANIFEST.MF 2007-06-01 16:11:35 UTC (rev 2575)
+++ trunk/org.jruby/META-INF/MANIFEST.MF 2007-06-01 18:39:58 UTC (rev 2576)
@@ -4,9 +4,7 @@
Bundle-SymbolicName: org.jruby
Bundle-Version: 0.9.2.3129
Bundle-Localization: plugin
-Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.jface,
- org.eclipse.ui
+Require-Bundle: org.eclipse.core.runtime
Eclipse-LazyStart: false
Bundle-ClassPath: lib/asm-commons-2.2.3.jar,
lib/asm-2.2.3.jar,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-01 16:11:37
|
Revision: 2575
http://svn.sourceforge.net/rubyeclipse/?rev=2575&view=rev
Author: cawilliams
Date: 2007-06-01 09:11:35 -0700 (Fri, 01 Jun 2007)
Log Message:
-----------
latest jruby
Property Changed:
----------------
trunk/org.jruby/lib/jruby.jar
Property changes on: trunk/org.jruby/lib/jruby.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <caw...@us...> - 2007-06-01 16:11:18
|
Revision: 2574
http://svn.sourceforge.net/rubyeclipse/?rev=2574&view=rev
Author: cawilliams
Date: 2007-06-01 09:11:08 -0700 (Fri, 01 Jun 2007)
Log Message:
-----------
upgrdae to latest JRuby - include another JRuby lib that it needs.
Modified Paths:
--------------
trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/UnusedParameterVisitor.java
trunk/org.jruby/.classpath
trunk/org.jruby/META-INF/MANIFEST.MF
trunk/org.jruby/README
trunk/org.jruby/build.properties
trunk/org.jruby/src.zip
trunk/org.rubypeople.rdt.astviewer/src/org/rubypeople/rdt/astviewer/views/ViewContentProvider.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/RubyParser.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultOccurrencesFinder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultReferenceFinder.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeFactory.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/NodeProvider.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/formatsource/EditableFormatHelper.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/core/formatsource/PreviewGeneratorImpl.java
trunk/org.rubypeople.rdt.refactoring/src/org/rubypeople/rdt/refactoring/nodewrapper/ArgsNodeWrapper.java
trunk/org.rubypeople.rdt.refactoring.tests/src/org/rubypeople/rdt/refactoring/tests/core/nodewrapper/TC_MethodNodeWrapper.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/RubyPartitionScanner.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/text/ruby/RubyTokenScanner.java
Added Paths:
-----------
trunk/org.jruby/lib/backport-util-concurrent.jar
trunk/org.jruby/lib/jruby.jar
Removed Paths:
-------------
trunk/org.jruby/lib/jruby.jar
Modified: trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/UnusedParameterVisitor.java
===================================================================
--- trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/UnusedParameterVisitor.java 2007-05-31 16:27:21 UTC (rev 2573)
+++ trunk/com.aptana.rdt/src/com/aptana/rdt/internal/parser/warnings/UnusedParameterVisitor.java 2007-06-01 16:11:08 UTC (rev 2574)
@@ -56,7 +56,7 @@
ArgsNode args = (ArgsNode) argsNode;
ListNode argList = args.getArgs();
if (argList == null) return arguments;
- for (Iterator iter = argList.iterator(); iter.hasNext();) {
+ for (Iterator iter = argList.childNodes().iterator(); iter.hasNext();) {
Object node = iter.next();
if (node instanceof Node) {
arguments.add((Node)node);
Modified: trunk/org.jruby/.classpath
===================================================================
--- trunk/org.jruby/.classpath 2007-05-31 16:27:21 UTC (rev 2573)
+++ trunk/org.jruby/.classpath 2007-06-01 16:11:08 UTC (rev 2574)
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
+ <classpathentry exported="true" kind="lib" path="lib/backport-util-concurrent.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-2.2.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-commons-2.2.3.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jruby.jar" sourcepath="src.zip"/>
Modified: trunk/org.jruby/META-INF/MANIFEST.MF
===================================================================
--- trunk/org.jruby/META-INF/MANIFEST.MF 2007-05-31 16:27:21 UTC (rev 2573)
+++ trunk/org.jruby/META-INF/MANIFEST.MF 2007-06-01 16:11:08 UTC (rev 2574)
@@ -4,10 +4,13 @@
Bundle-SymbolicName: org.jruby
Bundle-Version: 0.9.2.3129
Bundle-Localization: plugin
-Require-Bundle: org.eclipse.core.runtime
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.jface,
+ org.eclipse.ui
Eclipse-LazyStart: false
Bundle-ClassPath: lib/asm-commons-2.2.3.jar,
lib/asm-2.2.3.jar,
+ lib/backport-util-concurrent.jar,
lib/jruby.jar
Export-Package: org.ablaf.ast,
org.ablaf.internal.ast,
@@ -33,7 +36,6 @@
org.jruby.parser,
org.jruby.runtime,
org.jruby.runtime.builtin,
- org.jruby.runtime.builtin.meta,
org.jruby.runtime.callback,
org.jruby.runtime.load,
org.jruby.runtime.marshal,
Modified: trunk/org.jruby/README
===================================================================
--- trunk/org.jruby/README 2007-05-31 16:27:21 UTC (rev 2573)
+++ trunk/org.jruby/README 2007-06-01 16:11:08 UTC (rev 2574)
@@ -1 +1,2 @@
-JRuby revision 3012
+JRuby revision 3788
+1.0.0RC2
\ No newline at end of file
Modified: trunk/org.jruby/build.properties
===================================================================
--- trunk/org.jruby/build.properties 2007-05-31 16:27:21 UTC (rev 2573)
+++ trunk/org.jruby/build.properties 2007-06-01 16:11:08 UTC (rev 2574)
@@ -2,4 +2,5 @@
bin.includes = META-INF/,\
lib/jruby.jar,\
lib/asm-commons-2.2.3.jar,\
- lib/asm-2.2.3.jar
+ lib/asm-2.2.3.jar,\
+ lib/backport-util-concurrent.jar
Added: trunk/org.jruby/lib/backport-util-concurrent.jar
===================================================================
(Binary files differ)
Property changes on: trunk/org.jruby/lib/backport-util-concurrent.jar
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Deleted: trunk/org.jruby/lib/jruby.jar
===================================================================
(Binary files differ)
Added: trunk/org.jruby/lib/jruby.jar
===================================================================
--- trunk/org.jruby/lib/jruby.jar (rev 0)
+++ trunk/org.jruby/lib/jruby.jar 2007-06-01 16:11:08 UTC (rev 2574)
@@ -0,0 +1,20421 @@
+PK
+ |
|
From: <caw...@us...> - 2007-05-31 16:27:27
|
Revision: 2573
http://svn.sourceforge.net/rubyeclipse/?rev=2573&view=rev
Author: cawilliams
Date: 2007-05-31 09:27:21 -0700 (Thu, 31 May 2007)
Log Message:
-----------
handle double-click opening of search results on elements in external files
Modified Paths:
--------------
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchEditorOpener.java
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchEditorOpener.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchEditorOpener.java 2007-05-31 16:19:03 UTC (rev 2572)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/search/RubySearchEditorOpener.java 2007-05-31 16:27:21 UTC (rev 2573)
@@ -111,7 +111,7 @@
String editorID= getEditorID(file);
return showInEditor(wbPage, new FileEditorInput(file), editorID);
}
- return null;
+ return showWithoutReuse(element, wbPage);
}
private IFile getFile(Object element) throws RubyModelException {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|