|
From: <caw...@us...> - 2007-02-23 19:15:28
|
Revision: 2018
http://svn.sourceforge.net/rubyeclipse/?rev=2018&view=rev
Author: cawilliams
Date: 2007-02-23 11:15:24 -0800 (Fri, 23 Feb 2007)
Log Message:
-----------
set super class name properly. Extract constants. Traverse up inheritance hierarchy for suggesting method completions.
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-02-23 18:53:28 UTC (rev 2017)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-02-23 19:15:24 UTC (rev 2018)
@@ -52,6 +52,7 @@
import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator;
public class CompletionEngine {
+ private static final String CONSTRUCTOR_INVOKE_NAME = "new";
private CompletionRequestor requestor;
private CompletionContext context;
@@ -142,6 +143,15 @@
for (int k = 0; k < methods.length; k++) {
suggestMethod(methods[k], type.getElementName(), confidence);
}
+ // FIXME If a method name matches an existing suggestion (i.e. its overriden in the subclass), don't suggest it again!
+ String superClass = type.getSuperclassName();
+ if (superClass == null) return;
+ RubyElementRequestor requestor = new RubyElementRequestor(type.getRubyScript());
+ IType[] supers = requestor.findType(superClass);
+ for (int i = 0; i < supers.length; i++) {
+ IType superType = supers[i];
+ suggestMethods(confidence, superType);
+ }
}
private void suggestMethod(IMethod method, String typeName, int confidence) {
@@ -151,7 +161,7 @@
if (method.isSingleton()) {
flags |= Flags.AccStatic;
if (method.isConstructor())
- name = "new";
+ name = CONSTRUCTOR_INVOKE_NAME;
else
name = name.substring(typeName.length() + 1);
} else {
@@ -184,7 +194,11 @@
proposal.setReplaceRange(start, start + name.length());
proposal.setFlags(flags);
proposal.setName(name);
- proposal.setDeclaringType(typeName);
+ IType declaringType = method.getDeclaringType();
+ String declaringName = typeName;
+ if (declaringType != null)
+ declaringName = declaringType.getElementName();
+ proposal.setDeclaringType(declaringName);
requestor.accept(proposal);
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java 2007-02-23 18:53:28 UTC (rev 2017)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java 2007-02-23 19:15:24 UTC (rev 2018)
@@ -144,6 +144,13 @@
*/
public class RubyScriptStructureBuilder implements NodeVisitor {
+ private static final String MODULE = "Module";
+ private static final String MODULE_KEYWORD = "module";
+ private static final String METHOD_KEYWORD = "def";
+ private static final String CONSTRUCTOR_NAME = "initialize";
+ private static final String NAMESPACE_DELIMETER = "::";
+ private static final String CLASS_KEYWORD = "class";
+ private static final String OBJECT = "Object";
private InfoStack infoStack = new InfoStack();
private HandleStack modelStack = new HandleStack();
private RubyScriptElementInfo scriptInfo;
@@ -186,7 +193,7 @@
// TODO Use the visibility for the original method that this is aliasing
Visibility visibility = currentVisibility;
- if (name.equals("initialize"))
+ if (name.equals(CONSTRUCTOR_NAME))
visibility = Visibility.PROTECTED;
// TODO Find the existing method and steal it's parameter names
@@ -511,11 +518,13 @@
RubyTypeElementInfo info = new RubyTypeElementInfo();
info.setHandle(handle);
ISourcePosition pos = iVisited.getPosition();
- setKeywordRange("class", pos, info, name);
+ setKeywordRange(CLASS_KEYWORD, pos, info, name);
- String superClass = getSuperClassName(iVisited.getSuperNode());
- info.setSuperclassName(superClass);
-
+ if (!name.equals(OBJECT)) {
+ String superClass = getSuperClassName(iVisited.getSuperNode());
+ info.setSuperclassName(superClass);
+ }
+// TODO Collect the included modules and set them here!
info.setIncludedModuleNames(new String[] {});
infoStack.push(info);
@@ -524,7 +533,7 @@
visitNode(iVisited.getSuperNode());
visitNode(iVisited.getBodyNode());
- // TODO Collect the included modules and set them here!
+
modelStack.pop();
infoStack.pop();
return null;
@@ -553,7 +562,7 @@
*/
private String getSuperClassName(Node superNode) {
if (superNode == null)
- return "Object";
+ return OBJECT;
return getFullyQualifiedName(superNode);
}
@@ -568,7 +577,7 @@
Colon2Node colonNode = (Colon2Node) node;
String prefix = getFullyQualifiedName(colonNode.getLeftNode());
if (prefix.length() > 0)
- prefix = prefix + "::";
+ prefix = prefix + NAMESPACE_DELIMETER;
return prefix + colonNode.getName();
}
return "";
@@ -736,7 +745,7 @@
String name = iVisited.getName();
Visibility visibility = currentVisibility;
- if (name.equals("initialize"))
+ if (name.equals(CONSTRUCTOR_NAME))
visibility = Visibility.PROTECTED;
RubyElement type = getCurrentType();
@@ -752,7 +761,7 @@
// TODO Set more information
info.setVisibility(convertVisibility(visibility));
ISourcePosition pos = iVisited.getPosition();
- setKeywordRange("def", pos, info, name);
+ setKeywordRange(METHOD_KEYWORD, pos, info, name);
infoStack.push(info);
newElements.put(method, info);
@@ -841,7 +850,7 @@
// TODO Set more info!
infoStack.push(info);
ISourcePosition pos = iVisited.getPosition();
- setKeywordRange("def", pos, info, fullName);
+ setKeywordRange(METHOD_KEYWORD, pos, info, fullName);
info.setArgumentNames(parameterNames);
info.setVisibility(convertVisibility(visibility));
@@ -1166,7 +1175,7 @@
} else if (value instanceof BignumNode) {
return "Bignum";
}
- return "Object";
+ return OBJECT;
}
/*
@@ -1327,9 +1336,9 @@
RubyTypeElementInfo info = new RubyTypeElementInfo();
info.setHandle(module);
ISourcePosition pos = iVisited.getPosition();
- setKeywordRange("module", pos, info, name);
- info.setSuperclassName("Module");
- // TODO Set more info!
+ setKeywordRange(MODULE_KEYWORD, pos, info, name);
+ // TODO Set super module better! set Module if null, set nothing if name is Module.
+ info.setSuperclassName(MODULE);
infoStack.push(info);
newElements.put(module, info);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|