|
From: <caw...@us...> - 2007-06-25 19:16:48
|
Revision: 2672
http://svn.sourceforge.net/rubyeclipse/?rev=2672&view=rev
Author: cawilliams
Date: 2007-06-25 12:16:42 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
fix some bugs and add more behavior to do completions for nested types, constants, class level methods on compeltiosn after '::'
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/codeassist/CompletionProposalComparator.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/TypeDeclarationLocator.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.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-06-25 17:59:10 UTC (rev 2671)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-06-25 19:16:42 UTC (rev 2672)
@@ -58,6 +58,7 @@
import org.rubypeople.rdt.internal.core.search.BasicSearchEngine;
import org.rubypeople.rdt.internal.core.search.CollectingSearchRequestor;
import org.rubypeople.rdt.internal.core.util.ASTUtil;
+import org.rubypeople.rdt.internal.core.util.Util;
import org.rubypeople.rdt.internal.ti.BasicTypeGuess;
import org.rubypeople.rdt.internal.ti.DefaultTypeInferrer;
import org.rubypeople.rdt.internal.ti.ITypeGuess;
@@ -67,6 +68,8 @@
import org.rubypeople.rdt.internal.ti.util.INodeAcceptor;
import org.rubypeople.rdt.internal.ti.util.ScopedNodeLocator;
+import sun.security.action.PutAllAction;
+
public class CompletionEngine {
private static final String OBJECT = "Object";
private static final String CONSTRUCTOR_INVOKE_NAME = "new";
@@ -91,18 +94,20 @@
prefix = prefix.substring(0, prefix.length() - 2);
RubyElementRequestor requestor = new RubyElementRequestor(script);
IType[] types = requestor.findType(prefix);
+ Map<String, CompletionProposal> proposals = new HashMap<String, CompletionProposal>();
for (int i = 0; i < types.length; i++) {
IType type = types[i];
- suggestTypesConstants(type);
+ proposals.putAll(suggestTypesConstants(type));
// Suggest nested types
- suggestNestedTypes(type);
+ proposals.putAll(suggestNestedTypes(type));
// Suggest class level methods
- Map<String, CompletionProposal> map = suggestMethods(100, type, false);
- for (CompletionProposal proposal : map.values()) {
- fRequestor.accept(proposal);
- }
+ proposals.putAll(suggestMethods(100, type, false));
}
-
+ List<CompletionProposal> list = new ArrayList<CompletionProposal>(proposals.values());
+ Collections.sort(list, new CompletionProposalComparator());
+ for (CompletionProposal proposal : list) {
+ fRequestor.accept(proposal);
+ }
this.fRequestor.endReporting();
fContext = null;
return;
@@ -176,7 +181,8 @@
fContext = null;
}
- private void suggestTypesConstants(IType type) throws RubyModelException {
+ private Map<String, CompletionProposal> suggestTypesConstants(IType type) throws RubyModelException {
+ Map<String, CompletionProposal> proposals = new HashMap<String, CompletionProposal>();
SearchPattern pattern = SearchPattern.createPattern(IRubyElement.CONSTANT, "*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
IRubySearchScope scope = BasicSearchEngine.createRubySearchScope(new IRubyElement[] {type});
List<SearchMatch> results = search(pattern, scope);
@@ -186,22 +192,32 @@
// Add proposal
CompletionProposal proposal = createProposal(fContext.getReplaceStart(), CompletionProposal.FIELD_REF, element.getElementName());
proposal.setType(type.getFullyQualifiedName());
- fRequestor.accept(proposal);
+ proposal.setName(element.getElementName());
+ proposals.put(element.getElementName(), proposal);
}
+ return proposals;
}
- private void suggestNestedTypes(IType type) throws RubyModelException {
+ private Map<String, CompletionProposal> suggestNestedTypes(IType type) throws RubyModelException {
+ Map<String, CompletionProposal> proposals = new HashMap<String, CompletionProposal>();
SearchPattern pattern = SearchPattern.createPattern(IRubyElement.TYPE, "*", IRubySearchConstants.DECLARATIONS, SearchPattern.R_PATTERN_MATCH);
IRubySearchScope scope = BasicSearchEngine.createRubySearchScope(new IRubyElement[] {type});
List<SearchMatch> results = search(pattern, scope);
for (SearchMatch match: results) {
IType aType = (IType) match.getElement();
- if (!aType.getFullyQualifiedName().startsWith(type.getFullyQualifiedName()) || aType.getFullyQualifiedName().equals(type.getFullyQualifiedName())) continue;
- // Add proposal
+ String fullname = aType.getFullyQualifiedName();
+ if (fullname.equals(type.getFullyQualifiedName())) continue; // don't return exact match to prefix
+ if (!fullname.startsWith(type.getFullyQualifiedName())) continue; // only return those nested underneath prefix
+ String[] parts = Util.getTypeNameParts(fullname);
+// Don't add if it's not the directly nested child (and is instead the grandchild)
+ if (parts.length != Util.getTypeNameParts(type.getFullyQualifiedName()).length + 1) continue;
+ // Add proposal
CompletionProposal proposal = createProposal(fContext.getReplaceStart(), CompletionProposal.TYPE_REF, aType.getElementName());
proposal.setType(aType.getFullyQualifiedName());
- fRequestor.accept(proposal);
+ proposal.setName(aType.getElementName());
+ proposals.put(aType.getElementName(), proposal);
}
+ return proposals;
}
private List<CompletionProposal> suggestAllMethodsMatchingPrefix(IRubyScript script) {
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionProposalComparator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionProposalComparator.java 2007-06-25 17:59:10 UTC (rev 2671)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionProposalComparator.java 2007-06-25 19:16:42 UTC (rev 2672)
@@ -6,6 +6,7 @@
public class CompletionProposalComparator implements Comparator<CompletionProposal> {
+ // FIXME Also take type of proposal into account! (type, constant, global, instance var, local, etc.)
public int compare(CompletionProposal o1, CompletionProposal o2) {
if (o1.getRelevance() == o2.getRelevance())
return o1.getName().compareTo(o2.getName());
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java 2007-06-25 17:59:10 UTC (rev 2671)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java 2007-06-25 19:16:42 UTC (rev 2672)
@@ -341,9 +341,6 @@
case IRubySearchConstants.CLASS :
typeSuffix = IIndexConstants.CLASS_SUFFIX;
break;
-// case IRubySearchConstants.CLASS_AND_MODULE :
-// typeSuffix = IIndexConstants.CLASS_AND_MODULE_SUFFIX; FIXME Converge the TYPE_SUFFIX and CLASS_AND_MODULE_SUFFIX
-// break;
case IRubySearchConstants.MODULE :
typeSuffix = IIndexConstants.MODULE_SUFFIX;
break;
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java 2007-06-25 17:59:10 UTC (rev 2671)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/RubySearchScope.java 2007-06-25 19:16:42 UTC (rev 2672)
@@ -385,8 +385,8 @@
root = (ISourceFolderRoot) element.getAncestor(IRubyElement.SOURCE_FOLDER_ROOT);
String relativePath;
- containerPath = root.getParent().getPath();
- relativePath = Util.relativePath(getPath(element, false/*full path*/), 1/*remove project segmet*/);
+ containerPath = root.getPath();
+ relativePath = Util.relativePath(getPath(element, true/*full path*/), 0/*remove project segment*/);
containerPathToString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString();
add(relativePath, containerPathToString, false/*not a package*/);
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java 2007-06-25 17:59:10 UTC (rev 2671)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/FieldLocator.java 2007-06-25 19:16:42 UTC (rev 2672)
@@ -34,7 +34,7 @@
@Override
public void reportMatches(final RubyScript script, final MatchLocator locator) {
if (!this.pattern.findReferences) { // just traverse our own model
- reportMatches((IParent) script, locator);
+ reportMatches((IParent) script, locator);
} else { // they want references too, so we need to traverse the AST
reportASTMatches(script, locator);
}
@@ -130,11 +130,11 @@
IRubyElement[] children = parent.getChildren();
for (int i = 0; i < children.length; i++) {
IRubyElement child = children[i];
- if (child.isType(IRubyElement.FIELD) ||
+ if ((child.isType(IRubyElement.FIELD) ||
child.isType(IRubyElement.GLOBAL) ||
child.isType(IRubyElement.CONSTANT) ||
child.isType(IRubyElement.CLASS_VAR) ||
- child.isType(IRubyElement.INSTANCE_VAR)) {
+ child.isType(IRubyElement.INSTANCE_VAR)) && (locator.encloses(child))) {
int accuracy = getAccuracy(child.getElementName());
if (accuracy != IMPOSSIBLE_MATCH) {
IMember member = (IMember) child;
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/TypeDeclarationLocator.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/TypeDeclarationLocator.java 2007-06-25 17:59:10 UTC (rev 2671)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/matching/TypeDeclarationLocator.java 2007-06-25 19:16:42 UTC (rev 2672)
@@ -28,7 +28,7 @@
IRubyElement[] children = parent.getChildren();
for (int i = 0; i < children.length; i++) {
IRubyElement child = children[i];
- if (child.isType(IRubyElement.TYPE)) {
+ if (child.isType(IRubyElement.TYPE) && locator.encloses(child)) {
int accuracy = getAccuracy((IType) child);
if (accuracy != IMPOSSIBLE_MATCH) {
IMember member = (IMember) child;
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-06-25 17:59:10 UTC (rev 2671)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/Util.java 2007-06-25 19:16:42 UTC (rev 2672)
@@ -794,7 +794,7 @@
return true;
}
- private static String[] getTypeNameParts(String fullyQualifiedName) {
+ public static String[] getTypeNameParts(String fullyQualifiedName) {
return fullyQualifiedName.split(NAMESPACE_DELIMETER);
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|