|
From: <caw...@us...> - 2007-04-06 15:31:17
|
Revision: 2293
http://svn.sourceforge.net/rubyeclipse/?rev=2293&view=rev
Author: cawilliams
Date: 2007-04-06 08:31:13 -0700 (Fri, 06 Apr 2007)
Log Message:
-----------
move searches into BasicSearchEngine - we're moving IndexManager to get more hollowed out and have it instead focus on just managing the storage/retrieval of Index objects and scheduling of Index related jobs
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/search/BasicSearchEngine.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.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-04-06 15:21:16 UTC (rev 2292)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-04-06 15:31:13 UTC (rev 2293)
@@ -45,6 +45,7 @@
import org.rubypeople.rdt.internal.core.RubyScript;
import org.rubypeople.rdt.internal.core.RubyType;
import org.rubypeople.rdt.internal.core.parser.RubyParser;
+import org.rubypeople.rdt.internal.core.search.BasicSearchEngine;
import org.rubypeople.rdt.internal.core.search.indexing.IndexManager;
import org.rubypeople.rdt.internal.core.util.ASTUtil;
import org.rubypeople.rdt.internal.ti.DefaultTypeInferrer;
@@ -135,7 +136,7 @@
}
private void suggestGlobals() {
- Set<String> globals = IndexManager.getGlobalNames(fContext.getScript());
+ Set<String> globals = BasicSearchEngine.getGlobalNames(fContext.getScript());
for (String name : globals) {
if (!fContext.prefixStartsWith(name))
continue;
@@ -145,7 +146,7 @@
}
private void suggestTypeNames() {
- Set<String> types = IndexManager.getTypeNames(fContext.getScript());
+ Set<String> types = BasicSearchEngine.getTypeNames(fContext.getScript());
for (String name : types) {
if (!fContext.prefixStartsWith(name))
continue;
@@ -162,7 +163,7 @@
}
private void suggestConstantNames() {
- Set<String> types = IndexManager.getConstantNames(fContext.getScript());
+ Set<String> types = BasicSearchEngine.getConstantNames(fContext.getScript());
for (String name : types) {
if (!fContext.prefixStartsWith(name))
continue;
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-04-06 15:21:16 UTC (rev 2292)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java 2007-04-06 15:31:13 UTC (rev 2293)
@@ -15,7 +15,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.indexing.IndexManager;
+import org.rubypeople.rdt.internal.core.search.BasicSearchEngine;
import org.rubypeople.rdt.internal.core.util.Util;
public class RubyElementRequestor {
@@ -48,7 +48,7 @@
}
if (types.size() == 0) { // Couldn't find any!
// Do a full search
- types.addAll(IndexManager.findType(typeName));
+ types.addAll(BasicSearchEngine.findType(typeName));
}
} catch (RubyModelException e) {
RubyCore.log(e);
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-04-06 15:21:16 UTC (rev 2292)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/BasicSearchEngine.java 2007-04-06 15:31:13 UTC (rev 2293)
@@ -1,5 +1,75 @@
package org.rubypeople.rdt.internal.core.search;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.eclipse.core.runtime.IPath;
+import org.rubypeople.rdt.core.IRubyElement;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IRubyScript;
+import org.rubypeople.rdt.core.ISourceFolderRoot;
+import org.rubypeople.rdt.core.IType;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.search.indexing.IndexManager;
+
public class BasicSearchEngine {
+
+ // FIXME We're doing poor man's scoping by passing in the script. We should actually create scope classes which could tell if a document fell in our out of it...
+ public static Set<String> getTypeNames(IRubyScript script) {
+ return getElementNames(IRubyElement.TYPE, script);
+ }
+ public static Set<String> getConstantNames(IRubyScript script) {
+ return getElementNames(IRubyElement.CONSTANT, script);
+ }
+
+ private static Set<String> getElementNames(int type, IRubyScript script) {
+ Set<String> names = new HashSet<String>();
+ Collection<SearchDocument> documents = getDocumentsInScope(script);
+ for (SearchDocument doc : documents) {
+ Set<String> elements = doc.getElementNamesOfType(type);
+ for (String element : elements) {
+ names.add(element);
+ }
+ }
+ return names;
+ }
+
+ private static Collection<SearchDocument> getDocumentsInScope(IRubyScript script) {
+ try {
+ Set<SearchDocument> matches = new HashSet<SearchDocument>();
+ IRubyProject project = script.getRubyProject();
+ ISourceFolderRoot[] roots = project.getSourceFolderRoots();
+ for (IPath path : documents().keySet()) {
+ // If path is in loadpath of script's project, add it
+ for (int i = 0; i < roots.length; i++) {
+ if (roots[i].getPath().isPrefixOf(path)) matches.add(documents().get(path));
+ }
+ }
+ return matches;
+ } catch (RubyModelException e) {
+ // ignore?
+ return documents().values();
+ }
+ }
+
+ public static Set<IType> findType(String name) {
+ Set<IType> types = new HashSet<IType>();
+ for (SearchDocument doc : documents().values()) {
+ IType type = doc.findType(name);
+ if (type != null)
+ types.add(type);
+ }
+ return types;
+ }
+
+ private static Map<IPath, SearchDocument> documents() {
+ return IndexManager.instance().documents;
+ }
+
+ public static Set<String> getGlobalNames(IRubyScript script) {
+ return getElementNames(IRubyElement.GLOBAL, script);
+ }
}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.java 2007-04-06 15:21:16 UTC (rev 2292)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/search/indexing/IndexManager.java 2007-04-06 15:31:13 UTC (rev 2293)
@@ -1,10 +1,7 @@
package org.rubypeople.rdt.internal.core.search.indexing;
-import java.util.Collection;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.jobs.Job;
@@ -12,17 +9,12 @@
import org.rubypeople.rdt.core.IElementChangedListener;
import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.IRubyElementDelta;
-import org.rubypeople.rdt.core.IRubyProject;
-import org.rubypeople.rdt.core.IRubyScript;
-import org.rubypeople.rdt.core.ISourceFolderRoot;
-import org.rubypeople.rdt.core.IType;
-import org.rubypeople.rdt.core.RubyModelException;
import org.rubypeople.rdt.internal.core.search.SearchDocument;
public class IndexManager implements IElementChangedListener {
private static IndexManager fgInstance;
- private static Map<IPath, SearchDocument> documents;
+ public static Map<IPath, SearchDocument> documents;
private IndexManager() {
documents = new HashMap<IPath, SearchDocument>();
@@ -31,60 +23,7 @@
public void elementChanged(ElementChangedEvent event) {
processDelta(event.getDelta());
}
-
- // FIXME We're doing poor man's scoping by passing in the script. We should actually create scope classes which could tell if a document fell in our out of it...
- public static Set<String> getTypeNames(IRubyScript script) {
- return getElementNames(IRubyElement.TYPE, script);
- }
- public static Set<String> getConstantNames(IRubyScript script) {
- return getElementNames(IRubyElement.CONSTANT, script);
- }
-
- private static Set<String> getElementNames(int type, IRubyScript script) {
- Set<String> names = new HashSet<String>();
- Collection<SearchDocument> documents = getDocumentsInScope(script);
- for (SearchDocument doc : documents) {
- Set<String> elements = doc.getElementNamesOfType(type);
- for (String element : elements) {
- names.add(element);
- }
- }
- return names;
- }
-
- private static Collection<SearchDocument> getDocumentsInScope(IRubyScript script) {
- try {
- Set<SearchDocument> matches = new HashSet<SearchDocument>();
- IRubyProject project = script.getRubyProject();
- ISourceFolderRoot[] roots = project.getSourceFolderRoots();
- for (IPath path : documents.keySet()) {
- // If path is in loadpath of script's project, add it
- for (int i = 0; i < roots.length; i++) {
- if (roots[i].getPath().isPrefixOf(path)) matches.add(documents.get(path));
- }
- }
- return matches;
- } catch (RubyModelException e) {
- // ignore?
- return documents.values();
- }
- }
-
- public static Set<IType> findType(String name) {
- Set<IType> types = new HashSet<IType>();
- for (SearchDocument doc : documents.values()) {
- IType type = doc.findType(name);
- if (type != null)
- types.add(type);
- }
- return types;
- }
-
- public static Set<String> getGlobalNames(IRubyScript script) {
- return getElementNames(IRubyElement.GLOBAL, script);
- }
-
private void processDelta(IRubyElementDelta delta) {
IRubyElement element = delta.getElement();
switch (delta.getKind()) {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|