Revision: 1544 Author: cawilliams Date: 2006-07-22 21:58:15 -0700 (Sat, 22 Jul 2006) ViewCVS: http://svn.sourceforge.net/rubyeclipse/?rev=1544&view=rev Log Message: ----------- make the solution slightly less hacky. Now we create a link to the ruby core stubs inside the project that's doing the code completion. We need to move this link creation into project creation/interpreter choosing. We also need to see if we can enforce that the ruby stubs are read-only. Eventually we need to solidify this link creation to be able to do the same for other external libraries and gems. (and create nice project proprty pages to edit this stuff, and nice little icons like the JDT books and jars) Modified Paths: -------------- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java Modified: branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java =================================================================== --- branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java 2006-07-22 19:20:42 UTC (rev 1543) +++ branches/type_inferrence/trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/codeassist/RubyElementRequestor.java 2006-07-23 04:58:15 UTC (rev 1544) @@ -1,17 +1,9 @@ package org.rubypeople.rdt.internal.codeassist; import java.io.File; -import java.io.FilenameFilter; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import org.eclipse.core.internal.resources.ProjectDescription; -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IProjectDescription; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; @@ -25,77 +17,40 @@ private IRubyProject[] projects; - private IRubyProject fDummyProject; - private List fScripts; - public RubyElementRequestor(IRubyProject[] projects) { -// Get path of folder containing ruby stubs + this.projects = projects; + // Get path of folder containing ruby core stubs String dirName = RubyCore.getOSDirectory(RubyCore.getPlugin()) + "ruby/lib"; - // Iterate through the stubs, and create a RubyScript for each one File rubyfolder = new File(dirName); IPath projectPath = new Path(rubyfolder.getAbsolutePath()); - fDummyProject = createRubyCoreProject(projectPath); - fScripts = new ArrayList(); - - File[] scripts = rubyfolder.listFiles(new FilenameFilter() { - - public boolean accept(File dir, String name) { - return name.endsWith(".rb"); + // XXX This is still a big hack. We're adding the ruby core library on demand. We need to add it when the project is created (and/ore interpreter is installed) + IFolder folder = projects[0].getProject().getFolder("ruby_core"); + if (!folder.exists()) { + try { + folder.createLink(projectPath, IResource.ALLOW_MISSING_LOCAL, null); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); } - - }); - for (int i = 0; i < scripts.length; i++) { - IPath path = new Path(scripts[i].getAbsolutePath()); - path = path.removeFirstSegments(projectPath.segmentCount()); - IFile file = fDummyProject.getProject().getFile(path); - IRubyScript script = fDummyProject.getRubyScript(file); - fScripts.add(script); } - this.projects = new IRubyProject[projects.length + 1]; - this.projects[0] = fDummyProject; - for (int x = 0; x < projects.length; x++) { - this.projects[x+1] = projects[x]; - } - } - private IRubyProject createRubyCoreProject(IPath location) { - String name = "####internal"; //$NON-NLS-1$ - IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); -// while (true) { - IProject project = root.getProject(name); - if (!project.exists()) { - try { - IProjectDescription desc = ResourcesPlugin.getWorkspace().newProjectDescription(name); - desc.setLocation(location); - project.create(desc, null); - project.open(null); - } catch (CoreException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - return RubyCore.create(project); -// } } public IType findType(String typeName) { try { - for (Iterator iter = fScripts.iterator(); iter.hasNext();) { - IRubyScript script = (IRubyScript) iter.next(); - IType type = findTypeInScript(typeName, script); - if (type != null) return type; - } for (int x = 0; x < projects.length; x++) { IRubyProject project = projects[x]; - System.out.println("Checking project: " + project.getElementName()); + System.out.println("Checking project: " + + project.getElementName()); IRubyScript[] scripts = project.getRubyScripts(); System.out.println("Got " + scripts.length + " scripts"); for (int i = 0; i < scripts.length; i++) { IRubyScript script = scripts[i]; IType type = findTypeInScript(typeName, script); - if (type != null) return type; + if (type != null) + return type; } } } catch (RubyModelException e) { @@ -105,7 +60,8 @@ return null; } - private IType findTypeInScript(String typeName, IRubyScript script) throws RubyModelException { + private IType findTypeInScript(String typeName, IRubyScript script) + throws RubyModelException { System.out.println("Checking for that type inside script: " + script.getElementName()); IType[] types = script.getTypes(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |