|
From: <caw...@us...> - 2007-03-08 20:43:07
|
Revision: 2109
http://svn.sourceforge.net/rubyeclipse/?rev=2109&view=rev
Author: cawilliams
Date: 2007-03-08 12:43:03 -0800 (Thu, 08 Mar 2007)
Log Message:
-----------
begin handling "class << self" idiom for defining class level/singleton methods
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java 2007-03-08 20:23:13 UTC (rev 2108)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/RubyScriptStructureBuilder.java 2007-03-08 20:43:03 UTC (rev 2109)
@@ -159,6 +159,7 @@
private Map newElements;
private RubyElementInfo importContainerInfo;
private boolean DEBUG = false;
+ private boolean inSingletonClass;
/**
*
@@ -750,7 +751,7 @@
RubyElement type = getCurrentType();
String[] parameterNames = ASTUtil.getArgs(iVisited.getArgsNode(), iVisited.getScope());
- RubyMethod method = new RubyMethod(type, name, parameterNames);
+ RubyMethod method = createMethod(name, type, parameterNames);
modelStack.push(method);
RubyElementInfo parentInfo = infoStack.peek();
@@ -774,6 +775,12 @@
return null;
}
+ private RubyMethod createMethod(String name, RubyElement type, String[] parameterNames) {
+ if (inSingletonClass)
+ return new RubySingletonMethod(type, name, parameterNames);
+ return new RubyMethod(type, name, parameterNames);
+ }
+
/**
* @param visibility
* @return
@@ -1558,9 +1565,15 @@
* @see org.jruby.ast.visitor.NodeVisitor#visitSClassNode(org.jruby.ast.SClassNode)
*/
public Instruction visitSClassNode(SClassNode iVisited) {
- handleNode(iVisited);
- visitNode(iVisited.getReceiverNode());
- visitNode(iVisited.getBodyNode());
+ handleNode(iVisited);
+
+ Node receiver = iVisited.getReceiverNode();
+ if (receiver instanceof SelfNode) {
+// TODO We need to mark that we're in the singlteon class - this means all instance methods are actually singleton methods on the class we're in...
+ inSingletonClass = true;
+ visitNode(iVisited.getBodyNode());
+ inSingletonClass = false;
+ }
return null;
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|