|
From: <caw...@us...> - 2006-08-31 01:10:39
|
Revision: 1598
http://svn.sourceforge.net/rubyeclipse/?rev=1598&view=rev
Author: cawilliams
Date: 2006-08-30 18:10:13 -0700 (Wed, 30 Aug 2006)
Log Message:
-----------
do a more thorough search up the hierarchy for methods to suggest
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java 2006-08-31 01:09:27 UTC (rev 1597)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java 2006-08-31 01:10:13 UTC (rev 1598)
@@ -666,6 +666,7 @@
if (offset < 0) offset = 0;
ITypeInferrer inferrer = new DefaultTypeInferrer();
+ // FIXME Ugly hacking here to handle where we have invalid syntax by invoking after a period
StringBuffer source = new StringBuffer(new String(getContents()));
int replaceStart = offset + 1;
char charAtOffset = (char) source.charAt(offset);
@@ -675,6 +676,7 @@
}
charAtOffset = (char) source.charAt(offset);
System.out.println(charAtOffset);
+
List<ITypeGuess> guesses = inferrer.infer(source.toString(), offset);
// TODO Grab the project and all referred projects!
IRubyProject[] projects = new IRubyProject[1];
@@ -685,18 +687,37 @@
System.out.println("Type Inferrer thinks this is a: "
+ guess.getType());
IType type = completer.findType(guess.getType());
- IMethod[] methods = type.getMethods();
- System.out.println("Got " + methods.length + " methods");
- for (int k = 0; k < methods.length; k++) {
- String name = methods[k].getElementName();
- System.out.println("Got method name: " + name);
- CompletionProposal proposal = new CompletionProposal(
- CompletionProposal.METHOD_REF, name, guess
- .getConfidence());
- // TODO Handle replacement start index correctly
- proposal.setReplaceRange(replaceStart, replaceStart + name.length());
- requestor.accept(proposal);
- }
+ suggestMethods(requestor, replaceStart, completer, guess, type);
}
}
+
+ private void suggestMethods(CompletionRequestor requestor, int replaceStart, RubyElementRequestor completer, ITypeGuess guess, IType type) throws RubyModelException {
+ if (type == null) return;
+
+ suggestMethods(requestor, replaceStart, guess.getConfidence(), type);
+ // Now grab methods from all the included modules
+ String[] modules = type.getIncludedModuleNames();
+ for (int x = 0; x < modules.length; x++) {
+ IType tmpType = completer.findType(modules[x]);
+ suggestMethods(requestor, replaceStart, guess.getConfidence(), tmpType);
+ }
+ String superClass = type.getSuperclassName();
+// FIXME This shouldn't happen! Object shouldn't be a parent of itself!
+ if (type.getElementName().equals("Object") && superClass.equals("Object")) return;
+ IType parentClass = completer.findType(superClass);
+ suggestMethods(requestor, replaceStart, completer, guess, parentClass);
+ }
+
+ private void suggestMethods(CompletionRequestor requestor, int replaceStart, int confidence, IType type) throws RubyModelException {
+ if (type == null) return;
+ IMethod[] methods = type.getMethods();
+ for (int k = 0; k < methods.length; k++) {
+ String name = methods[k].getElementName();
+ CompletionProposal proposal = new CompletionProposal(
+ CompletionProposal.METHOD_REF, name, confidence);
+ // TODO Handle replacement start index correctly
+ proposal.setReplaceRange(replaceStart, replaceStart + name.length());
+ requestor.accept(proposal);
+ }
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|