|
From: <caw...@us...> - 2007-02-06 18:24:05
|
Revision: 1916
http://svn.sourceforge.net/rubyeclipse/?rev=1916&view=rev
Author: cawilliams
Date: 2007-02-06 10:23:50 -0800 (Tue, 06 Feb 2007)
Log Message:
-----------
fnd types outside of imports quicker by leveraging our "experimental indexer"; for completion proposals on class level methods, replace correct portion
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/RubyElementRequestor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/ExperimentalIndex.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-06 13:10:52 UTC (rev 1915)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-02-06 18:23:50 UTC (rev 1916)
@@ -5,6 +5,7 @@
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.jruby.ast.ClassNode;
import org.jruby.ast.ClassVarAsgnNode;
@@ -117,7 +118,7 @@
}
private void suggestTypeNames(int replaceStart) {
- List<String> types = ExperimentalIndex.getTypes();
+ Set<String> types = ExperimentalIndex.getTypeNames();
// TODO Remove duplicates? Sort?
for (String name : types) {
if (this.prefix != null && !name.startsWith(this.prefix))
@@ -134,7 +135,7 @@
}
private void suggestConstantNames(int replaceStart) {
- List<String> types = ExperimentalIndex.getConstants();
+ Set<String> types = ExperimentalIndex.getConstantNames();
// TODO Remove duplicates? Sort?
for (String name : types) {
if (this.prefix != null && !name.startsWith(this.prefix))
@@ -155,14 +156,14 @@
IMethod[] methods = type.getMethods();
for (int k = 0; k < methods.length; k++) {
IMethod method = methods[k];
+ int start = replaceStart;
String name = method.getElementName();
if (prefix != null && !name.startsWith(prefix))
continue;
- CompletionProposal proposal = new CompletionProposal(CompletionProposal.METHOD_REF, name, confidence);
- proposal.setReplaceRange(replaceStart, replaceStart + name.length());
int flags = Flags.AccDefault;
if (method.isSingleton()) {
flags |= Flags.AccStatic;
+ start -= type.getElementName().length() + 1;
}
switch (method.getVisibility()) {
case IMethod.PRIVATE:
@@ -177,6 +178,8 @@
default:
break;
}
+ CompletionProposal proposal = new CompletionProposal(CompletionProposal.METHOD_REF, name, confidence);
+ proposal.setReplaceRange(start, start + name.length());
proposal.setFlags(flags);
requestor.accept(proposal);
}
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-06 13:10:52 UTC (rev 1915)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java 2007-02-06 18:23:50 UTC (rev 1916)
@@ -1,6 +1,7 @@
package org.rubypeople.rdt.internal.codeassist;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.List;
import java.util.StringTokenizer;
@@ -15,6 +16,7 @@
import org.rubypeople.rdt.core.IType;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.search.ExperimentalIndex;
public class RubyElementRequestor {
@@ -33,35 +35,49 @@
// FIXME Search the roots in a particular order? Return first match?
ISourceFolderRoot[] roots = rubyProject.getSourceFolderRoots();
for (int i = 0; i < roots.length; i++) {
- types.addAll(getTypeInSourceFolderRoot(roots[i], typeName));
+ types.addAll(getImportedTypesInSourceFolderRoot(roots[i], typeName));
}
+ if (types.size() == 0) { // Couldn't find any!
+ // Do a full search
+ types.addAll(ExperimentalIndex.findType(typeName));
+ }
} catch (RubyModelException e) {
RubyCore.log(e);
}
+ return (IType[]) types.toArray(new IType[types.size()]);
+ }
+
+ private List<IType> filterToMatches(String typeName, List<IType> types) {
List<IType> matches = new ArrayList<IType>();
for (IType type : types) {
if (type.getElementName().equals(typeName)) matches.add(type);
}
- return (IType[]) types.toArray(new IType[matches.size()]);
+ return matches;
}
- private List<IType> getTypeInSourceFolderRoot(ISourceFolderRoot root, String typeName) {
+ private List<IType> getTypesInSourceFolderRoot(ISourceFolderRoot root, String typeName) {
+ List<IType> types = getTypes(root);
+ return filterToMatches(typeName, types);
+ }
+
+ private List<IType> getImportedTypesInSourceFolderRoot(ISourceFolderRoot root, String typeName) {
List<IType> types = new ArrayList<IType>();
try {
IPath rootPath = root.getPath();
// FIXME this is an ugly hack to search the core library in a special way (no need to look at imports)
if (rootPath.toString().contains("org.rubypeople.rdt.launching")) {
- types.addAll(getTypeInImport(root, typeName.toLowerCase()));
+ types.addAll(getTypesInImport(root, typeName.toLowerCase()));
} else {
IImportDeclaration[] imports = script.getImports();
for (int j = 0; j < imports.length; j++) {
String path = imports[j].getElementName();
- types.addAll(getTypeInImport(root, path));
+ types.addAll(getTypesInImport(root, path));
}
}
} catch (RubyModelException e) {
RubyCore.log(e);
}
+
return types;
}
@@ -72,7 +88,7 @@
* @param path The internal path to search.
* @return a List of ITypes which seem to be a match
*/
- private List<IType> getTypeInImport(ISourceFolderRoot root, String path) {
+ private List<IType> getTypesInImport(ISourceFolderRoot root, String path) {
StringTokenizer tokenizer = new StringTokenizer(path, SEPARATOR_CHARS);
List<String> tokens = new ArrayList<String>();
while(tokenizer.hasMoreTokens()) {
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 2007-02-06 13:10:52 UTC (rev 1915)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java 2007-02-06 18:23:50 UTC (rev 1916)
@@ -606,7 +606,7 @@
}
/**
- * @see ICompilationUnit#getTypes()
+ * @see ICompilationUnit#getTypeNames()
*/
public IType[] getTypes() throws RubyModelException {
ArrayList list = getChildrenOfType(TYPE);
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/ExperimentalIndex.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/ExperimentalIndex.java 2007-02-06 13:10:52 UTC (rev 1915)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/ExperimentalIndex.java 2007-02-06 18:23:50 UTC (rev 1916)
@@ -1,8 +1,9 @@
package org.rubypeople.rdt.internal.core.search;
-import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
@@ -10,35 +11,57 @@
import org.eclipse.core.runtime.jobs.Job;
import org.rubypeople.rdt.core.ElementChangedEvent;
import org.rubypeople.rdt.core.IElementChangedListener;
+import org.rubypeople.rdt.core.IField;
import org.rubypeople.rdt.core.IParent;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyElementDelta;
import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.IType;
import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.RubyModelManager;
public class ExperimentalIndex implements IElementChangedListener {
private static ExperimentalIndex fgInstance;
- private static ArrayList<String> fgConstants;
- private static ArrayList<String> fgTypes;
+ private static HashSet<IField> fgConstants;
+ private static HashSet<IType> fgTypes;
private ExperimentalIndex() {
- fgTypes = new ArrayList<String>();
- fgConstants = new ArrayList<String>();
+ fgTypes = new HashSet<IType>();
+ fgConstants = new HashSet<IField>();
}
public void elementChanged(ElementChangedEvent event) {
processDelta(event.getDelta());
}
- public static List<String> getTypes() {
- return Collections.unmodifiableList((ArrayList<String>)fgTypes.clone()); // clone to avoid concurrent modification when iterating
+ public static Set<String> getTypeNames() {
+ Set<IType> types = Collections.unmodifiableSet((HashSet<IType>)fgTypes.clone()); // clone to avoid concurrent modification when iterating
+ Set<String> names = new HashSet<String>();
+ for (IType type : types) {
+ names.add(type.getElementName());
+ }
+ return names;
}
- public static List<String> getConstants() {
- return Collections.unmodifiableList((ArrayList<String>)fgConstants.clone()); // clone to avoid concurrent modification when iterating
+ public static Set<String> getConstantNames() {
+ Set<IField> types = Collections.unmodifiableSet((HashSet<IField>)fgConstants.clone()); // clone to avoid concurrent modification when iterating
+ Set<String> names = new HashSet<String>();
+ for (IField type : types) {
+ names.add(type.getElementName());
+ }
+ return names;
}
+
+ public static Set<IType> findType(String name) {
+ Set<IType> types = Collections.unmodifiableSet((HashSet<IType>)fgTypes.clone()); // clone to avoid concurrent modification when iterating
+ Set<IType> matches = new HashSet<IType>();
+ for (IType type : types) {
+ if (type.getElementName().equals(name))
+ matches.add(type);
+ }
+ return matches;
+ }
private void processDelta(IRubyElementDelta delta) {
IRubyElement element = delta.getElement();
@@ -62,10 +85,10 @@
void removeElement(IRubyElement element) {
switch (element.getElementType()) {
case IRubyElement.TYPE:
- fgTypes.remove(element.getElementName());
+ fgTypes.remove(element);
break;
case IRubyElement.CONSTANT:
- fgConstants.remove(element.getElementName());
+ fgConstants.remove(element);
break;
}
}
@@ -73,10 +96,10 @@
void addElement(IRubyElement element) {
switch (element.getElementType()) {
case IRubyElement.TYPE:
- fgTypes.add(element.getElementName());
+ fgTypes.add((IType)element);
break;
case IRubyElement.CONSTANT:
- fgConstants.add(element.getElementName());
+ fgConstants.add((IField)element);
break;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|