|
From: <caw...@us...> - 2007-01-23 20:31:35
|
Revision: 1865
http://svn.sourceforge.net/rubyeclipse/?rev=1865&view=rev
Author: cawilliams
Date: 2007-01-23 12:31:32 -0800 (Tue, 23 Jan 2007)
Log Message:
-----------
mwa ha ha ha ha! I got it!
You can now do a go to declaration on a ruby project and have it open a standard library module/class in an editor!
(Granted you need to create the ruby project using our new wizard, and must swap your default interpreter to get the variable resolution set up - I've gotta fix that)
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.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/SourceFolder.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java
trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalRubyScript.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderInfo.java
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalRubyScript.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalRubyScript.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalRubyScript.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -0,0 +1,111 @@
+package org.rubypeople.rdt.internal.core;
+
+import java.io.CharArrayReader;
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.jruby.ast.Node;
+import org.jruby.lexer.yacc.SyntaxException;
+import org.rubypeople.rdt.core.IBuffer;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.core.WorkingCopyOwner;
+import org.rubypeople.rdt.internal.compiler.util.Util;
+import org.rubypeople.rdt.internal.core.buffer.BufferManager;
+import org.rubypeople.rdt.internal.core.parser.RubyParser;
+
+public class ExternalRubyScript extends RubyScript {
+
+ public ExternalRubyScript(ExternalSourceFolder parent, String name, WorkingCopyOwner owner) {
+ super(parent, name, owner);
+ }
+
+ @Override
+ protected boolean buildStructure(OpenableElementInfo info, IProgressMonitor pm, Map newElements, IResource underlyingResource) throws RubyModelException {
+ RubyScriptElementInfo unitInfo = (RubyScriptElementInfo) info;
+ // get buffer contents
+ IBuffer buffer = getBufferManager().getBuffer(this);
+ if (buffer == null) {
+ buffer = openBuffer(pm, unitInfo); // open buffer independently
+ // from the info, since we are
+ // building the info
+ }
+ final char[] contents = buffer == null ? null : buffer.getCharacters();
+ try {
+ RubyParser parser = new RubyParser();
+ Node node = parser.parse(null, new CharArrayReader(contents));
+ RubyScriptStructureBuilder visitor = new RubyScriptStructureBuilder(this, unitInfo, newElements);
+ if (node != null) node.accept(visitor);
+ unitInfo.setIsStructureKnown(true);
+ } catch (SyntaxException e) {
+ unitInfo.setIsStructureKnown(false);
+ unitInfo.setSyntaxException(e) ;
+ } catch (Exception e) {
+ RubyCore.log(e);
+ }
+ return unitInfo.isStructureKnown();
+ }
+
+ @Override
+ public boolean exists() {
+ return ((Openable)getOpenable()).exists();
+ }
+
+ /**
+ * Opens and returns buffer on the source code associated with this class file.
+ * Maps the source code to the children elements of this class file.
+ * If no source code is associated with this class file,
+ * <code>null</code> is returned.
+ *
+ * @see Openable
+ */
+ protected IBuffer openBuffer(IProgressMonitor pm, Object info) throws RubyModelException {
+ char[] contents = findSource();
+ if (contents != null) {
+ // create buffer
+ IBuffer buffer = getBufferManager().createBuffer(this);
+ if (buffer == null) return null;
+ BufferManager bufManager = getBufferManager();
+ bufManager.addBuffer(buffer);
+
+ // set the buffer source
+ if (buffer.getCharacters() == null){
+ buffer.setContents(contents);
+ }
+
+ // listen to buffer changes
+ buffer.addBufferChangedListener(this);
+
+ return buffer;
+ }
+ return null;
+ }
+
+ public File getFile() {
+ ExternalSourceFolder parent = (ExternalSourceFolder) getParent();
+ IPath parentPath = parent.getPath();
+ return parentPath.append(name).toFile();
+ }
+
+ private char[] findSource() {
+ File file = getFile();
+ byte[] bytes;
+ try {
+ bytes = Util.getFileByteContent(file);
+ } catch (IOException e) {
+ RubyCore.log(e);
+ return new char[0];
+ }
+ return new String(bytes).toCharArray();
+ }
+
+ @Override
+ public IResource getResource() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java 2007-01-23 18:31:25 UTC (rev 1864)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolder.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -1,9 +1,13 @@
package org.rubypeople.rdt.internal.core;
+import java.io.File;
+import java.util.ArrayList;
import java.util.HashMap;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.rubypeople.rdt.core.IRubyElement;
import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.util.Util;
public class ExternalSourceFolder extends SourceFolder {
@@ -20,10 +24,29 @@
if (!openableParent.isOpen()) {
openableParent.generateInfos(openableParent.createElementInfo(), newElements, pm);
}
- // XXX We need to modify ExtenralSourceFolerRoot's computeChildren method. None of the source folders' children are getting set!
}
public boolean isReadOnly() {
return true;
}
+
+ protected boolean computeChildren(OpenableElementInfo info) {
+ ArrayList<IRubyElement> vChildren = new ArrayList<IRubyElement>();
+ File file = getPath().toFile();
+ File[] members = file.listFiles();
+ for (int i = 0, max = members.length; i < max; i++) {
+ File child = members[i];
+ if (!child.isDirectory()) {
+ IRubyElement childElement;
+ if (Util.isValidRubyScriptName(child.getName())) {
+ childElement = new ExternalRubyScript(this, child.getName(), DefaultWorkingCopyOwner.PRIMARY);
+ vChildren.add(childElement);
+ }
+ }
+ }
+ IRubyElement[] children= new IRubyElement[vChildren.size()];
+ vChildren.toArray(children);
+ info.setChildren(children);
+ return true;
+ }
}
Added: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderInfo.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderInfo.java (rev 0)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderInfo.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -0,0 +1,5 @@
+package org.rubypeople.rdt.internal.core;
+
+public class ExternalSourceFolderInfo extends SourceFolderInfo {
+
+}
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java 2007-01-23 18:31:25 UTC (rev 1864)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/ExternalSourceFolderRoot.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -40,6 +40,15 @@
IRubyElement[] children = new IRubyElement[vChildren.size()];
vChildren.toArray(children);
info.setChildren(children);
+
+ // Now go through every SourceFolder and set it's children!
+ for (int i = 0; i < children.length; i++) {
+ ExternalSourceFolder packFrag = (ExternalSourceFolder) children[i];
+ ExternalSourceFolderInfo fragInfo = new ExternalSourceFolderInfo();
+ packFrag.computeChildren(fragInfo);
+ newElements.put(packFrag, fragInfo);
+ }
+
}
} catch (RubyModelException e) {
// problem resolving children; structure remains unknown
@@ -148,6 +157,7 @@
if (this.resource == null) {
this.resource = RubyModel.getTarget(ResourcesPlugin.getWorkspace().getRoot(), this.folderPath, false);
}
+ // FIXME We need to turn this File into an IResource somehow!
if (this.resource instanceof IResource) {
return super.getResource();
}
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-23 18:31:25 UTC (rev 1864)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyProject.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -51,6 +51,7 @@
import org.rubypeople.rdt.core.IRubyModelStatus;
import org.rubypeople.rdt.core.IRubyModelStatusConstants;
import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.ISourceFolder;
import org.rubypeople.rdt.core.ISourceFolderRoot;
import org.rubypeople.rdt.core.IType;
@@ -423,6 +424,10 @@
ISourceFolder folder = (ISourceFolder) child;
IType type = getType(folder, className);
if (type != null) return type;
+ } else if(child.isType(IRubyElement.SCRIPT)) {
+ IRubyScript script = (IRubyScript) child;
+ IType type = getType(script, className);
+ if (type != null) return type;
} else if(child.isType(IRubyElement.TYPE)) {
IType type = (IType) child;
if (type.getElementName().equals(className)) return type;
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-01-23 18:31:25 UTC (rev 1864)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScript.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -71,7 +71,7 @@
/**
* @param name
*/
- public RubyScript(RubyElement parent, String name, WorkingCopyOwner owner) {
+ public RubyScript(SourceFolder parent, String name, WorkingCopyOwner owner) {
super(parent);
this.name = name;
this.owner = owner;
@@ -235,7 +235,7 @@
*/
public IRubyElement getPrimaryElement(boolean checkOwner) {
if (checkOwner && isPrimary()) return this;
- return new RubyScript((RubyElement) getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
+ return new RubyScript((SourceFolder) getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
}
/*
@@ -323,7 +323,7 @@
if (buffer.getCharacters() == null) {
if (isWorkingCopy) {
IRubyScript original;
- if (!isPrimary() && (original = new RubyScript((RubyElement) getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY)).isOpen()) {
+ if (!isPrimary() && (original = new RubyScript((SourceFolder) getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY)).isOpen()) {
buffer.setContents(original.getSource());
} else {
IFile file = (IFile) getResource();
@@ -397,7 +397,7 @@
RubyModelManager manager = RubyModelManager.getRubyModelManager();
- RubyScript workingCopy = new RubyScript((RubyElement) getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
+ RubyScript workingCopy = new RubyScript((SourceFolder) getParent(), getElementName(), DefaultWorkingCopyOwner.PRIMARY);
RubyModelManager.PerWorkingCopyInfo perWorkingCopyInfo = manager.getPerWorkingCopyInfo(workingCopy, false/*
* don't
* create
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java 2007-01-23 18:31:25 UTC (rev 1864)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/SourceFolder.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -13,7 +13,6 @@
import org.eclipse.core.runtime.Path;
import org.rubypeople.rdt.core.IParent;
import org.rubypeople.rdt.core.IRubyElement;
-import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.IRubyScript;
import org.rubypeople.rdt.core.ISourceFolder;
import org.rubypeople.rdt.core.RubyModelException;
@@ -152,7 +151,8 @@
}
public IPath getPath() {
- IRubyProject root = this.getRubyProject();
+ SourceFolderRoot root = this.getSourceFolderRoot();
+
IPath path = root.getPath();
for (int i = 0, length = this.names.length; i < length; i++) {
String name = this.names[i];
@@ -180,17 +180,15 @@
SourceFolderRoot root = this.getSourceFolderRoot();
if (root.isArchive()) {
return root.getResource();
- } else {
- int length = this.names.length;
- if (length == 0) {
- return root.getResource();
- } else {
- IPath path = new Path(this.names[0]);
- for (int i = 1; i < length; i++)
- path = path.append(this.names[i]);
- return ((IContainer)root.getResource()).getFolder(path);
- }
}
+ int length = this.names.length;
+ if (length == 0) {
+ return root.getResource();
+ }
+ IPath path = new Path(this.names[0]);
+ for (int i = 1; i < length; i++)
+ path = path.append(this.names[i]);
+ return ((IContainer) root.getResource()).getFolder(path);
}
public IResource getUnderlyingResource() throws RubyModelException {
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java 2007-01-23 18:31:25 UTC (rev 1864)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -22,6 +22,8 @@
import org.jruby.parser.StaticScope;
public abstract class ASTUtil {
+ private static final boolean VERBOSE = false;
+
/**
* @param argsNode
* @param bodyNode
@@ -108,11 +110,15 @@
return stringRepresentation((DStrNode) node);
if (node instanceof StrNode)
return ((StrNode) node).getValue();
- System.err.println("Reached node type we don't know how to represent: "
+ log("Reached node type we don't know how to represent: "
+ node.getClass().getName());
return node.toString();
}
+ private static void log(String string) {
+ if (VERBOSE) System.out.println(string);
+ }
+
private static String stringRepresentation(DStrNode node) {
List children = node.childNodes();
StringBuffer buffer = new StringBuffer();
Modified: trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java
===================================================================
--- trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java 2007-01-23 18:31:25 UTC (rev 1864)
+++ trunk/org.rubypeople.rdt.ui/src/org/rubypeople/rdt/internal/ui/rubyeditor/EditorUtility.java 2007-01-23 20:31:32 UTC (rev 1865)
@@ -34,6 +34,7 @@
import org.rubypeople.rdt.core.ISourceReference;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.internal.core.ExternalRubyScript;
import org.rubypeople.rdt.internal.corext.util.RubyModelUtil;
import org.rubypeople.rdt.internal.ui.RubyPlugin;
import org.rubypeople.rdt.ui.PreferenceConstants;
@@ -141,7 +142,8 @@
if (resource instanceof IFile)
return new FileEditorInput((IFile) resource);
}
-
+ if (element instanceof ExternalRubyScript)
+ return new ExternalRubyFileEditorInput(((ExternalRubyScript) element).getFile());
element= element.getParent();
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|