|
From: <caw...@us...> - 2007-01-29 16:02:26
|
Revision: 1894
http://svn.sourceforge.net/rubyeclipse/?rev=1894&view=rev
Author: cawilliams
Date: 2007-01-29 08:02:24 -0800 (Mon, 29 Jan 2007)
Log Message:
-----------
work out some of the kinks in hooking up the core library stubs...
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/RubyProject.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.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-01-29 14:55:03 UTC (rev 1893)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/CompletionEngine.java 2007-01-29 16:02:24 UTC (rev 1894)
@@ -90,15 +90,11 @@
if (this.prefix != null)
replaceStart -= this.prefix.length();
- // TODO Refactor out common code here...
- if (this.prefix != null && this.prefix.length() == 0) { // empty prefix
+ if (isConstant() || (emptyPrefix() && !isMethod)) { // type, constant, or empty prefix (with no preceding period)
suggestTypeNames(replaceStart);
suggestConstantNames(replaceStart);
- getDocumentsRubyElementsInScope(script, source.toString(), offset, replaceStart);
- } else if (isConstant()) { // type or constant
- suggestTypeNames(replaceStart);
- suggestConstantNames(replaceStart);
- } else { // method or variable
+ }
+ if (isMethod) { // method
ITypeInferrer inferrer = new DefaultTypeInferrer();
List<ITypeGuess> guesses = inferrer.infer(source.toString(), offset);
RubyElementRequestor requestor = new RubyElementRequestor(script);
@@ -109,13 +105,17 @@
suggestMethods(replaceStart, guess.getConfidence(), types[i]);
}
}
- // FIXME Traverse the IRubyElement model, not nodes (and don't reparse!)
- if (!isMethod)
- getDocumentsRubyElementsInScope(script, source.toString(), offset, replaceStart);
}
+ // FIXME Traverse the IRubyElement model, not nodes (and don't reparse!)
+ if (!isMethod)
+ getDocumentsRubyElementsInScope(script, source.toString(), offset, replaceStart);
this.requestor.endReporting();
}
+ private boolean emptyPrefix() {
+ return this.prefix != null && this.prefix.length() == 0;
+ }
+
private void suggestTypeNames(int replaceStart) {
List<String> types = ExperimentalIndex.getTypes();
// TODO Remove duplicates? Sort?
@@ -146,7 +146,7 @@
}
private boolean isConstant() {
- return this.prefix != null && this.prefix.length() > 0 && Character.isUpperCase(this.prefix.charAt(0));
+ return prefix != null && prefix.length() > 0 && Character.isUpperCase(prefix.charAt(0));
}
private void suggestMethods(int replaceStart, int confidence, IType type) throws RubyModelException {
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-01-29 14:55:03 UTC (rev 1893)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java 2007-01-29 16:02:24 UTC (rev 1894)
@@ -4,6 +4,7 @@
import java.util.List;
import java.util.StringTokenizer;
+import org.eclipse.core.runtime.IPath;
import org.rubypeople.rdt.core.IImportDeclaration;
import org.rubypeople.rdt.core.IParent;
import org.rubypeople.rdt.core.IRubyElement;
@@ -29,9 +30,10 @@
List<IType> types = new ArrayList<IType>();
IRubyProject rubyProject = script.getRubyProject();
try {
+ // 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]));
+ types.addAll(getTypeInSourceFolderRoot(roots[i], typeName));
}
} catch (RubyModelException e) {
RubyCore.log(e);
@@ -43,20 +45,34 @@
return (IType[]) types.toArray(new IType[matches.size()]);
}
- private List<IType> getTypeInSourceFolderRoot(ISourceFolderRoot root) {
+ private List<IType> getTypeInSourceFolderRoot(ISourceFolderRoot root, String typeName) {
List<IType> types = new ArrayList<IType>();
try {
- IImportDeclaration[] imports = script.getImports();
- for (int j = 0; j < imports.length; j++) {
- types.addAll(getTypeInImport(root, imports[j]));
+ 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()));
+ } else {
+ IImportDeclaration[] imports = script.getImports();
+ for (int j = 0; j < imports.length; j++) {
+ String path = imports[j].getElementName();
+ types.addAll(getTypeInImport(root, path));
+ }
}
} catch (RubyModelException e) {
RubyCore.log(e);
}
return types;
}
- private List<IType> getTypeInImport(ISourceFolderRoot root, IImportDeclaration importDecl) {
- String path = importDecl.getElementName();
+
+ /**
+ * Searches the root for the path given (and appends the typical ".rb" extension).
+ * If we find a match, grab the types inside the script.
+ * @param root The ISourceFolderRoot to search
+ * @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) {
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/RubyProject.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2007-01-29 14:55:03 UTC (rev 1893)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2007-01-29 16:02:24 UTC (rev 1894)
@@ -556,7 +556,7 @@
* boolean
* @param retrieveExportedRoots
* boolean
- * @throws JavaModelException
+ * @throws RubyModelException
*/
public void computeSourceFolderRoots(ILoadpathEntry resolvedEntry, ObjectVector accumulatedRoots, HashSet rootIDs, ILoadpathEntry referringEntry, boolean checkExistency, boolean retrieveExportedRoots, Map rootToResolvedEntries) throws RubyModelException {
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java 2007-01-29 14:55:03 UTC (rev 1893)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java 2007-01-29 16:02:24 UTC (rev 1894)
@@ -18,7 +18,10 @@
public class StandardVM extends AbstractVMInstall {
- private String fgSeparator;
+ /**
+ * Convenience handle to the system-specific file separator character
+ */
+ private static final char fgSeparator = File.separatorChar;
public StandardVM(IVMInstallType type, String id) {
super(type, id);
@@ -65,6 +68,13 @@
}
return null;
}
+
+ @Override
+ public IPath[] getLibraryLocations() {
+ IPath[] paths = super.getLibraryLocations();
+ if (paths != null) return paths;
+ return getDefaultLibraryLocations();
+ }
@Override
public void setLibraryLocations(IPath[] locations) {
@@ -102,13 +112,16 @@
private IPath[] getDefaultLibraryLocations() {
IPath[] dflts = getVMInstallType().getDefaultLibraryLocations(getInstallLocation());
+ IPath coreStubsPath = generateCoreStubs(StandardVMType.findRubyExecutable(getInstallLocation()));
+ if (coreStubsPath == null) {
+ return dflts;
+ }
IPath[] paths = new IPath[dflts.length + 1];
for (int i = 0; i < dflts.length; i++) {
paths[i] = dflts[i];
}
- // FIXME Handle possible null pointer being returned by findRubyExecutable
- paths[dflts.length] = generateCoreStubs(StandardVMType.findRubyExecutable(getInstallLocation()));
- return dflts;
+ paths[dflts.length] = coreStubsPath;
+ return paths;
}
/**
@@ -118,14 +131,15 @@
* @return an IPath pointing to the directory containing the core library stubs
*/
private IPath generateCoreStubs(File rubyExecutable) {
+ if (rubyExecutable == null) return null;
//locate the script to generate our core stubs
- File file = LaunchingPlugin.getFileInPlugin(new Path("ruby" + fgSeparator + "core_stubber.rb")); //$NON-NLS-1$
- IPath path = new Path(file.getParentFile().getAbsolutePath() + fgSeparator + getId() + fgSeparator + "lib"); //$NON-NLS-1$
- if (path.toFile().exists()) {
- return path; // we've already created the stubs for this VM
- }
- path.toFile().mkdirs(); // Make the directory structure to throw the files into
+ File file = LaunchingPlugin.getFileInPlugin(new Path("ruby/core_stubber.rb")); //$NON-NLS-1$
if (file.exists()) {
+ IPath path = new Path(file.getParentFile().getAbsolutePath() + fgSeparator + getId() + fgSeparator + "lib"); //$NON-NLS-1$
+ if (path.toFile().exists()) {
+ return path; // we've already created the stubs for this VM
+ }
+ path.toFile().mkdirs(); // Make the directory structure to throw the files into
String rubyExecutablePath = rubyExecutable.getAbsolutePath();
String[] cmdLine = new String[] {rubyExecutablePath, file.getAbsolutePath(), path.toOSString()};
Process p = null;
@@ -141,7 +155,8 @@
Thread.sleep(50);
} catch (InterruptedException e) {
}
- }
+ }
+ return path;
} catch (IOException ioe) {
LaunchingPlugin.log(ioe);
} finally {
@@ -150,6 +165,6 @@
}
}
}
- return path;
+ return null;
}
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java 2007-01-29 14:55:03 UTC (rev 1893)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java 2007-01-29 16:02:24 UTC (rev 1894)
@@ -138,7 +138,7 @@
private LibraryInfo generateLibraryInfo(File rubyHome, File rubyExecutable) {
LibraryInfo info = null;
//locate the script to grab us our loadpaths
- File file = LaunchingPlugin.getFileInPlugin(new Path("ruby" + fgSeparator + "loadpath.rb")); //$NON-NLS-1$
+ File file = LaunchingPlugin.getFileInPlugin(new Path("ruby/loadpath.rb")); //$NON-NLS-1$
if (file.exists()) {
String rubyExecutablePath = rubyExecutable.getAbsolutePath();
String[] cmdLine = new String[] {rubyExecutablePath, file.getAbsolutePath()}; //$NON-NLS-1$
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|