You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2020/10/09 11:41:12 UTC
[groovy] branch GROOVY-8258 updated: GROOVY-8258: minor refactor
and add a test case to fix
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch GROOVY-8258
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY-8258 by this push:
new 5939499 GROOVY-8258: minor refactor and add a test case to fix
5939499 is described below
commit 59394990606d2adfde38c49dbbfb36965f06d0bc
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Oct 9 19:40:57 2020 +0800
GROOVY-8258: minor refactor and add a test case to fix
---
.../org/apache/groovy/linq/dsl/GinqAstBuilder.java | 36 ++++++++++++++--------
.../groovy/org/apache/groovy/linq/GinqTest.groovy | 16 ++++++++++
2 files changed, 40 insertions(+), 12 deletions(-)
diff --git a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/dsl/GinqAstBuilder.java b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/dsl/GinqAstBuilder.java
index ce3874c..bc49477 100644
--- a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/dsl/GinqAstBuilder.java
+++ b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/dsl/GinqAstBuilder.java
@@ -49,7 +49,6 @@ import java.util.Deque;
public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorReportable {
private Deque<GinqExpression> ginqExpressionStack = new ArrayDeque<>();
private GinqExpression latestGinqExpression;
- private AbstractGinqExpression ginqExpression; // store the return value
private final SourceUnit sourceUnit;
public GinqAstBuilder(SourceUnit sourceUnit) {
@@ -60,6 +59,16 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
return latestGinqExpression;
}
+ private void setLatestGinqExpressionClause(AbstractGinqExpression ginqExpressionClause) {
+ GinqExpression ginqExpression = ginqExpressionStack.peek();
+ ginqExpression.putNodeMetaData(__LATEST_GINQ_EXPRESSION_CLAUSE, ginqExpressionClause);
+ }
+
+ private AbstractGinqExpression getLatestGinqExpressionClause() {
+ GinqExpression ginqExpression = ginqExpressionStack.peek();
+ return ginqExpression.getNodeMetaData(__LATEST_GINQ_EXPRESSION_CLAUSE);
+ }
+
@Override
public void visitMethodCallExpression(MethodCallExpression call) {
super.visitMethodCallExpression(call);
@@ -70,6 +79,7 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
}
GinqExpression currentGinqExpression = ginqExpressionStack.peek();
+ AbstractGinqExpression latestGinqExpressionClause = getLatestGinqExpressionClause();
if ("from".equals(methodName) || JoinExpression.isJoinExpression(methodName)) {
ArgumentListExpression arguments = (ArgumentListExpression) call.getArguments();
@@ -111,7 +121,7 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
currentGinqExpression.addJoinExpression((JoinExpression) dataSourceExpression);
}
dataSourceExpression.setSourcePosition(call);
- ginqExpression = dataSourceExpression;
+ setLatestGinqExpressionClause(dataSourceExpression);
return;
}
@@ -132,10 +142,10 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
filterExpression.setSourcePosition(call);
- if (ginqExpression instanceof DataSourceExpression) {
- ((DataSourceExpression) ginqExpression).addFilterExpression(filterExpression);
+ if (latestGinqExpressionClause instanceof DataSourceExpression) {
+ ((DataSourceExpression) latestGinqExpressionClause).addFilterExpression(filterExpression);
} else {
- throw new GroovyBugError("The preceding expression is not a DataSourceExpression: " + ginqExpression);
+ throw new GroovyBugError("The preceding expression is not a DataSourceExpression: " + latestGinqExpressionClause);
}
return;
@@ -145,10 +155,10 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
GroupExpression groupExpression = new GroupExpression(call.getArguments());
groupExpression.setSourcePosition(call);
- if (ginqExpression instanceof DataSourceExpression) {
- ((DataSourceExpression) ginqExpression).setGroupExpression(groupExpression);
+ if (latestGinqExpressionClause instanceof DataSourceExpression) {
+ ((DataSourceExpression) latestGinqExpressionClause).setGroupExpression(groupExpression);
} else {
- throw new GroovyBugError("The preceding expression is not a DataSourceExpression: " + ginqExpression);
+ throw new GroovyBugError("The preceding expression is not a DataSourceExpression: " + latestGinqExpressionClause);
}
return;
@@ -158,10 +168,10 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
OrderExpression orderExpression = new OrderExpression(call.getArguments());
orderExpression.setSourcePosition(call);
- if (ginqExpression instanceof DataSourceExpression) {
- ((DataSourceExpression) ginqExpression).setOrderExpression(orderExpression);
+ if (latestGinqExpressionClause instanceof DataSourceExpression) {
+ ((DataSourceExpression) latestGinqExpressionClause).setOrderExpression(orderExpression);
} else {
- throw new GroovyBugError("The preceding expression is not a DataSourceExpression: " + ginqExpression);
+ throw new GroovyBugError("The preceding expression is not a DataSourceExpression: " + latestGinqExpressionClause);
}
return;
@@ -172,7 +182,7 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
selectExpression.setSourcePosition(call);
currentGinqExpression.setSelectExpression(selectExpression);
- ginqExpression = selectExpression;
+ setLatestGinqExpressionClause(selectExpression);
latestGinqExpression = ginqExpressionStack.pop();
@@ -184,4 +194,6 @@ public class GinqAstBuilder extends CodeVisitorSupport implements SyntaxErrorRep
public SourceUnit getSourceUnit() {
return sourceUnit;
}
+
+ private static final String __LATEST_GINQ_EXPRESSION_CLAUSE = "__latestGinqExpressionClause";
}
diff --git a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
index f6da498..44fef6c 100644
--- a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
+++ b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
@@ -19,6 +19,7 @@
package org.apache.groovy.linq
import groovy.json.JsonSlurper
+import groovy.test.NotYetImplemented
import groovy.transform.CompileDynamic
import groovy.transform.CompileStatic
import org.junit.Test
@@ -695,6 +696,21 @@ class GinqTest {
'''
}
+ @NotYetImplemented
+ @Test
+ void "testGinq - nested from - 15"() {
+ assertScript '''
+ assert [1, 2] == GINQ {
+ from n in [0, 1, 2]
+ where n in (
+ from m in [1, 2]
+ select m
+ )
+ select n
+ }.toList()
+ '''
+ }
+
@Test
void "testGinq - from leftjoin select - 1"() {
assertScript '''