|
From: <caw...@us...> - 2007-02-23 19:57:58
|
Revision: 2022
http://svn.sourceforge.net/rubyeclipse/?rev=2022&view=rev
Author: cawilliams
Date: 2007-02-23 11:57:57 -0800 (Fri, 23 Feb 2007)
Log Message:
-----------
refactor out some common code (to Util which may not be the best place for it) so we can handle code completion for variables whose declared type is a fully qualified/complex/namespaced name).
an example is invoking method completion on a avriable whose type is "TMail::Mail"
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultTypeInferrer.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java 2007-02-23 19:38:55 UTC (rev 2021)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java 2007-02-23 19:57:57 UTC (rev 2022)
@@ -16,6 +16,7 @@
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.search.ExperimentalIndex;
+import org.rubypeople.rdt.internal.core.util.Util;
public class RubyElementRequestor {
@@ -27,7 +28,16 @@
this.script = script;
}
- public IType[] findType(String typeName) {
+ public IType[] findType(String fullyQualifiedName) {
+ IType[] types = findTypeWithSimpleName(Util.getSimpleName(fullyQualifiedName));
+ List<IType> matches = new ArrayList<IType>();
+ for (int i = 0; i < types.length; i++) {
+ if (Util.parentsMatch(types[i], fullyQualifiedName)) matches.add(types[i]);
+ }
+ return matches.toArray(new IType[matches.size()]);
+ }
+
+ private IType[] findTypeWithSimpleName(String typeName) {
List<IType> types = new ArrayList<IType>();
IRubyProject rubyProject = script.getRubyProject();
try {
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-02-23 19:38:55 UTC (rev 2021)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/SelectionEngine.java 2007-02-23 19:57:57 UTC (rev 2022)
@@ -25,6 +25,7 @@
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.parser.RubyParser;
import org.rubypeople.rdt.internal.core.util.ASTUtil;
@@ -49,16 +50,11 @@
String simpleName = ((Colon2Node)selected).getName();
String fullyQualifiedName = ASTUtil.getFullyQualifiedName((Colon2Node) selected);
IRubyElement element = findChild(simpleName, IRubyElement.TYPE, script);
- if (element != null && parentsMatch((IType)element, fullyQualifiedName)) {
+ if (element != null && Util.parentsMatch((IType)element, fullyQualifiedName)) {
return new IRubyElement[] { element };
}
RubyElementRequestor completer = new RubyElementRequestor(script);
- IType[] types = completer.findType(simpleName);
- List<IType> matches = new ArrayList<IType>();
- for (int i = 0; i < types.length; i++) {
- if (parentsMatch(types[i], fullyQualifiedName)) matches.add(types[i]);
- }
- return matches.toArray(new IType[matches.size()]);
+ return completer.findType(fullyQualifiedName);
}
if (selected instanceof ConstNode) {
ConstNode constNode = (ConstNode) selected;
@@ -120,22 +116,6 @@
return new IRubyElement[0];
}
- private boolean parentsMatch(IType type, String fullyQualifiedName) {
- String[] names = getTrimmedSimpleNames(fullyQualifiedName);
- for (int i = names.length - 2; i >= 0; i--) { // Start at second last name piece, go all the way to first
- IType parent = type.getDeclaringType();
- if (parent == null || !names[i].equals(parent.getElementName())) {
- return false;
- }
- type = parent;
- }
- return true;
- }
-
- private String[] getTrimmedSimpleNames(String fullyQualifiedName) {
- return fullyQualifiedName.split("::");
- }
-
private IRubyElement findChild(String name, int type,
IParent parent) {
try {
@@ -150,8 +130,7 @@
}
}
} catch (RubyModelException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ RubyCore.log(e);
}
return null;
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java 2007-02-23 19:38:55 UTC (rev 2021)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java 2007-02-23 19:57:57 UTC (rev 2022)
@@ -29,6 +29,7 @@
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyModelStatusConstants;
import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IType;
import org.rubypeople.rdt.core.RubyConventions;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
@@ -42,6 +43,7 @@
private static boolean ENABLE_RUBY_LIKE_EXTENSIONS = true;
private static char[][] RUBY_LIKE_EXTENSIONS;
private static char[][] RUBY_LIKE_FILENAMES;
+ private static final String NAMESPACE_DELIMETER = "::";
private Util() {
// cannot be instantiated
@@ -769,4 +771,25 @@
return true;
}
+ public static String getSimpleName(String fullyQualifiedName) {
+ String[] names = getTypeNameParts(fullyQualifiedName);
+ return names[names.length - 1];
+ }
+
+ public static boolean parentsMatch(IType type, String fullyQualifiedName) {
+ String[] names = getTypeNameParts(fullyQualifiedName);
+ for (int i = names.length - 2; i >= 0; i--) { // Start at second last name piece, go all the way to first
+ IType parent = type.getDeclaringType();
+ if (parent == null || !names[i].equals(parent.getElementName())) {
+ return false;
+ }
+ type = parent;
+ }
+ return true;
+ }
+
+ private static String[] getTypeNameParts(String fullyQualifiedName) {
+ return fullyQualifiedName.split(NAMESPACE_DELIMETER);
+ }
+
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultTypeInferrer.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultTypeInferrer.java 2007-02-23 19:38:55 UTC (rev 2021)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/ti/DefaultTypeInferrer.java 2007-02-23 19:57:57 UTC (rev 2022)
@@ -20,6 +20,7 @@
import org.jruby.ast.LocalVarNode;
import org.jruby.ast.Node;
import org.jruby.ast.RootNode;
+import org.jruby.ast.VCallNode;
import org.rubypeople.rdt.internal.core.parser.RubyParser;
import org.rubypeople.rdt.internal.core.util.ASTUtil;
import org.rubypeople.rdt.internal.ti.data.LiteralNodeTypeNames;
@@ -201,14 +202,18 @@
}
private void tryLocalVarNode(Node node, List<ITypeGuess> guesses) {
+ if (node instanceof VCallNode) {
+ // FIXME How do we handle local variables who show up as VCallNodes?
+ return;
+ }
+
if (!(node instanceof LocalVarNode))
return;
LocalVarNode localVarNode = (LocalVarNode) node;
int nodeStart = node.getPosition().getStartOffset();
final String localVarName = TypeInferenceHelper.Instance().getVarName(localVarNode);
- // See if it has been assigned to, earlier [todo: in this local
- // scope].
+ // See if it has been assigned to, earlier [TODO: in this local scope].
// Find first assignment to this var name that occurs before the
// reference
// TODO: This will find assignments in other local scopes that
@@ -281,7 +286,7 @@
if (callNode.getReceiverNode() instanceof ConstNode) {
name = ((ConstNode) callNode.getReceiverNode()).getName();
} else if (callNode.getReceiverNode() instanceof Colon2Node) {
- ASTUtil.getFullyQualifiedName((Colon2Node) node);
+ name = ASTUtil.getFullyQualifiedName((Colon2Node) callNode.getReceiverNode());
}
if (name != null)
guesses.add(new BasicTypeGuess(name, 100));
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|