|
From: <caw...@us...> - 2006-11-29 21:08:09
|
Revision: 1673
http://svn.sourceforge.net/rubyeclipse/?rev=1673&view=rev
Author: cawilliams
Date: 2006-11-29 13:08:08 -0800 (Wed, 29 Nov 2006)
Log Message:
-----------
tweak how we search for constants/types declaration a little (and add todo to fix way we search for local vars!)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java 2006-11-29 20:53:53 UTC (rev 1672)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java 2006-11-29 21:08:08 UTC (rev 1673)
@@ -41,8 +41,19 @@
if (selected instanceof ConstNode) {
ConstNode constNode = (ConstNode) selected;
String name = constNode.getName();
- // TODO Find constants too (not just types)
+ // Try to find a matching constant in this script
+ IRubyElement element = findChild(name, IRubyElement.CONSTANT, script);
+ if (element != null) {
+ return new IRubyElement[] { element };
+ }
+ // Now search for a type in this script
+ element = findChild(name, IRubyElement.TYPE, script);
+ if (element != null) {
+ return new IRubyElement[] { element };
+ }
+ // TODO Search the required/loaded files first!
// TODO Search scopes outward!
+ // Now search across project for type
IRubyProject[] projects = new IRubyProject[1];
projects[0] = script.getRubyProject();
RubyElementRequestor completer = new RubyElementRequestor(projects);
@@ -50,6 +61,7 @@
return new IRubyElement[] { type };
}
if (isLocalVarRef(selected)) {
+ // TODO Try the local namespace first!
List<IRubyElement> possible = getChildrenWithName(script
.getChildren(), IRubyElement.LOCAL_VARIABLE,
getName(selected));
@@ -74,6 +86,26 @@
return new IRubyElement[0];
}
+ private IRubyElement findChild(String name, int type,
+ IParent parent) {
+ try {
+ IRubyElement[] children = parent.getChildren();
+ for (int j = 0; j < children.length; j++) {
+ IRubyElement child = children[j];
+ if (child.getElementName().equals(name) && child.isType(type))
+ return child;
+ if (child instanceof IParent) {
+ IRubyElement found = findChild(name, type, (IParent) child);
+ if (found != null) return found;
+ }
+ }
+ } catch (RubyModelException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
+
private boolean isMethodCall(Node selected) {
return (selected instanceof VCallNode) || (selected instanceof FCallNode);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|