|
From: <caw...@us...> - 2007-09-05 20:58:06
|
Revision: 3090
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=3090&view=rev
Author: cawilliams
Date: 2007-09-05 13:58:05 -0700 (Wed, 05 Sep 2007)
Log Message:
-----------
improve resolution of Constants/Type names (grab the namespace and try the fully qualified name if can't find after everything else)
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 2007-09-05 20:37:48 UTC (rev 3089)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java 2007-09-05 20:58:05 UTC (rev 3090)
@@ -58,6 +58,7 @@
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;
public class SelectionEngine {
@@ -104,17 +105,37 @@
String name = constNode.getName();
// Try to find a matching constant in this script
// TODO Use convention of all caps versus camelcase to decided which to search for first?
- IRubyElement element = findChild(name, IRubyElement.CONSTANT, script);
- if (element != null) {
- return new IRubyElement[] { element };
+ try {
+ IRubySearchScope scope = SearchEngine.createRubySearchScope(new IRubyElement[] {script});
+ List<SearchMatch> matches = search(scope, IRubyElement.CONSTANT, name, IRubySearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
+ for (SearchMatch match : matches) {
+ IRubyElement element = (IRubyElement) match.getElement();
+ if (element != null) {
+ return new IRubyElement[] { element };
+ }
+ }
+ } catch (CoreException e) {
+ RubyCore.log(e);
}
// Now search for a type in this script
- element = findChild(name, IRubyElement.TYPE, script);
- if (element != null) {
- return new IRubyElement[] { element };
+ try {
+ IRubySearchScope scope = SearchEngine.createRubySearchScope(new IRubyElement[] {script});
+ List<SearchMatch> matches = search(scope, IRubyElement.TYPE, name, IRubySearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH);
+ for (SearchMatch match : matches) {
+ IRubyElement element = (IRubyElement) match.getElement();
+ if (element != null) {
+ return new IRubyElement[] { element };
+ }
+ }
+ } catch (CoreException e) {
+ RubyCore.log(e);
}
RubyElementRequestor completer = new RubyElementRequestor(script);
- return completer.findType(name);
+ IType[] types = completer.findType(name);
+ if (types != null && types.length > 0) return types;
+ String fullyQualifiedName = getFullyQualifiedName(root, name);
+ if (fullyQualifiedName == null) return new IRubyElement[0];
+ return completer.findType(fullyQualifiedName); // get fully qualified name of surrounding type!
}
if (isLocalVarRef(selected)) {
// TODO Try the local namespace first!
@@ -171,17 +192,48 @@
}
return new IRubyElement[0];
}
+
+ private String getFullyQualifiedName(Node root, String name) {
+ List<Node> surrounding = ScopedNodeLocator.Instance().findNodesInScope(root, new INodeAcceptor() {
+
+ public boolean doesAccept(Node node) {
+ return node instanceof ModuleNode || node instanceof ClassNode;
+ }
+
+ });
+ // drop last class/module
+ if (surrounding.size() < 2) return null;
+ surrounding.remove(surrounding.size() - 1);
+ StringBuffer buffer = new StringBuffer();
+ boolean first = true;
+ for (Node node : surrounding) {
+ if (!first) {
+ buffer.append("::");
+ }
+ buffer.append(ASTUtil.getNameReflectively(node));
+ if (first) {
+ first = false;
+ }
+ }
+ buffer.append("::");
+ buffer.append(name);
+ return buffer.toString();
+ }
private List<SearchMatch> search(int type, String patternString, int limitTo, int matchRule) throws CoreException {
+ return search(SearchEngine.createWorkspaceScope(), type, patternString, limitTo, matchRule);
+ }
+
+ private List<SearchMatch> search(IRubySearchScope scope, int type, String patternString, int limitTo, int matchRule) throws CoreException {
SearchEngine engine = new SearchEngine();
SearchPattern pattern = SearchPattern.createPattern(type, patternString, limitTo, matchRule);
SearchParticipant[] participants = new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()};
CollectingSearchRequestor requestor = new CollectingSearchRequestor();
- IRubySearchScope scope = SearchEngine.createWorkspaceScope();
engine.search(pattern, participants, scope, requestor, null);
return requestor.getResults();
}
+
private IType[] getReceiver(IRubyScript script, String source, Node selected, Node root, int start) {
List<IType> types = new ArrayList<IType>();
if ((selected instanceof FCallNode) || (selected instanceof VCallNode)) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|