|
From: <caw...@us...> - 2007-08-10 15:16:44
|
Revision: 2958
http://rubyeclipse.svn.sourceforge.net/rubyeclipse/?rev=2958&view=rev
Author: cawilliams
Date: 2007-08-10 08:16:40 -0700 (Fri, 10 Aug 2007)
Log Message:
-----------
Fix #5517 - Add warning check for local variable assignment that may intend to be attribute access
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java 2007-08-09 17:03:39 UTC (rev 2957)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/parser/InOrderVisitor.java 2007-08-10 15:16:40 UTC (rev 2958)
@@ -1197,53 +1197,7 @@
}
protected List<String> getArgumentsFromFunctionCall(IArgumentNode iVisited) {
- List<String> arguments = new ArrayList<String>();
- Node argsNode = iVisited.getArgsNode();
- Iterator iter = null;
- if (argsNode instanceof SplatNode) {
- SplatNode splat = (SplatNode) argsNode;
- iter = splat.childNodes().iterator();
- } else if (argsNode instanceof ArrayNode) {
- ArrayNode arrayNode = (ArrayNode) iVisited.getArgsNode();
- iter = arrayNode.childNodes().iterator();
- } else if (argsNode == null) {
- // Block?
- Node iterNode = null;
- if (iVisited instanceof FCallNode) {
- FCallNode fcall = (FCallNode) iVisited;
- iterNode = fcall.getIterNode();
- } else if (iVisited instanceof CallNode) {
- CallNode call = (CallNode) iVisited;
- iterNode = call.getIterNode();
- }
- if (iterNode == null) return arguments;
- if (iterNode instanceof IterNode) { // yup, it has a block
- IterNode yeah = (IterNode) iterNode;
- Node varNode = yeah.getVarNode();
- if (varNode instanceof DAsgnNode) { // single variable in block
- DAsgnNode dassgn = (DAsgnNode) varNode;
- arguments.add(dassgn.getName());
- } else if (varNode instanceof MultipleAsgnNode) { // multiple variables in block
- MultipleAsgnNode multi = (MultipleAsgnNode) varNode;
- ListNode list = multi.getHeadNode();
- if (list != null)
- iter = list.childNodes().iterator();
- else {
- Node multiArgsNode = multi.getArgsNode();
- if (multiArgsNode instanceof DAsgnNode) { // single variable in block
- DAsgnNode dassgn = (DAsgnNode) multiArgsNode;
- arguments.add(dassgn.getName());
- }
- }
- }
- }
- }
- if (iter == null) return arguments;
- for (; iter.hasNext();) {
- Node argument = (Node) iter.next();
- arguments.add(ASTUtil.getNameReflectively(argument));
- }
- return arguments;
+ return ASTUtil.getArgumentsFromFunctionCall(iVisited);
}
}
\ No newline at end of file
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-08-09 17:03:39 UTC (rev 2957)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/internal/core/util/ASTUtil.java 2007-08-10 15:16:40 UTC (rev 2958)
@@ -7,7 +7,9 @@
import org.jruby.ast.ArgsNode;
import org.jruby.ast.ArgumentNode;
+import org.jruby.ast.ArrayNode;
import org.jruby.ast.AttrAssignNode;
+import org.jruby.ast.CallNode;
import org.jruby.ast.ClassNode;
import org.jruby.ast.ClassVarAsgnNode;
import org.jruby.ast.ClassVarDeclNode;
@@ -15,20 +17,26 @@
import org.jruby.ast.Colon2Node;
import org.jruby.ast.ConstDeclNode;
import org.jruby.ast.ConstNode;
+import org.jruby.ast.DAsgnNode;
import org.jruby.ast.DStrNode;
+import org.jruby.ast.FCallNode;
import org.jruby.ast.FalseNode;
import org.jruby.ast.FixnumNode;
import org.jruby.ast.GlobalAsgnNode;
import org.jruby.ast.GlobalVarNode;
import org.jruby.ast.HashNode;
+import org.jruby.ast.IArgumentNode;
import org.jruby.ast.InstAsgnNode;
import org.jruby.ast.InstVarNode;
+import org.jruby.ast.IterNode;
import org.jruby.ast.ListNode;
import org.jruby.ast.LocalAsgnNode;
import org.jruby.ast.ModuleNode;
+import org.jruby.ast.MultipleAsgnNode;
import org.jruby.ast.NilNode;
import org.jruby.ast.Node;
import org.jruby.ast.SelfNode;
+import org.jruby.ast.SplatNode;
import org.jruby.ast.StrNode;
import org.jruby.ast.TrueNode;
import org.jruby.ast.ZArrayNode;
@@ -207,4 +215,54 @@
|| (node instanceof ClassVarNode);
}
+ public static List<String> getArgumentsFromFunctionCall(IArgumentNode iVisited) {
+ List<String> arguments = new ArrayList<String>();
+ Node argsNode = iVisited.getArgsNode();
+ Iterator iter = null;
+ if (argsNode instanceof SplatNode) {
+ SplatNode splat = (SplatNode) argsNode;
+ iter = splat.childNodes().iterator();
+ } else if (argsNode instanceof ArrayNode) {
+ ArrayNode arrayNode = (ArrayNode) iVisited.getArgsNode();
+ iter = arrayNode.childNodes().iterator();
+ } else if (argsNode == null) {
+ // Block?
+ Node iterNode = null;
+ if (iVisited instanceof FCallNode) {
+ FCallNode fcall = (FCallNode) iVisited;
+ iterNode = fcall.getIterNode();
+ } else if (iVisited instanceof CallNode) {
+ CallNode call = (CallNode) iVisited;
+ iterNode = call.getIterNode();
+ }
+ if (iterNode == null) return arguments;
+ if (iterNode instanceof IterNode) { // yup, it has a block
+ IterNode yeah = (IterNode) iterNode;
+ Node varNode = yeah.getVarNode();
+ if (varNode instanceof DAsgnNode) { // single variable in block
+ DAsgnNode dassgn = (DAsgnNode) varNode;
+ arguments.add(dassgn.getName());
+ } else if (varNode instanceof MultipleAsgnNode) { // multiple variables in block
+ MultipleAsgnNode multi = (MultipleAsgnNode) varNode;
+ ListNode list = multi.getHeadNode();
+ if (list != null)
+ iter = list.childNodes().iterator();
+ else {
+ Node multiArgsNode = multi.getArgsNode();
+ if (multiArgsNode instanceof DAsgnNode) { // single variable in block
+ DAsgnNode dassgn = (DAsgnNode) multiArgsNode;
+ arguments.add(dassgn.getName());
+ }
+ }
+ }
+ }
+ }
+ if (iter == null) return arguments;
+ for (; iter.hasNext();) {
+ Node argument = (Node) iter.next();
+ arguments.add(ASTUtil.getNameReflectively(argument));
+ }
+ return arguments;
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|