You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2017/11/13 02:44:36 UTC
[1/5] groovy git commit: GROOVY-7315: CompileStatic/TypeChecked
cannot create non-static nested inner class using named-arg short-hand syntax
(closes #634)
Repository: groovy
Updated Branches:
refs/heads/GROOVY_2_6_X ff4eb69dd -> 412c6441c
GROOVY-7315: CompileStatic/TypeChecked cannot create non-static nested inner class using named-arg short-hand syntax (closes #634)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/45aa4b31
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/45aa4b31
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/45aa4b31
Branch: refs/heads/GROOVY_2_6_X
Commit: 45aa4b31bcd3b09ad700b122a57b33040cb15d06
Parents: ff4eb69
Author: paulk <pa...@asert.com.au>
Authored: Sun Nov 12 23:07:27 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Nov 13 12:44:06 2017 +1000
----------------------------------------------------------------------
.../ConstructorCallTransformer.java | 40 ++++++++++++++------
.../stc/StaticTypeCheckingVisitor.java | 27 +++++++++----
.../groovy/transform/stc/BugsSTCTest.groovy | 31 ++++++++++++++-
3 files changed, 77 insertions(+), 21 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/45aa4b31/src/main/org/codehaus/groovy/transform/sc/transformers/ConstructorCallTransformer.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/sc/transformers/ConstructorCallTransformer.java b/src/main/org/codehaus/groovy/transform/sc/transformers/ConstructorCallTransformer.java
index 854959b..6c42e78 100644
--- a/src/main/org/codehaus/groovy/transform/sc/transformers/ConstructorCallTransformer.java
+++ b/src/main/org/codehaus/groovy/transform/sc/transformers/ConstructorCallTransformer.java
@@ -22,6 +22,8 @@ import org.codehaus.groovy.ast.ClassHelper;
import org.codehaus.groovy.ast.ClassNode;
import org.codehaus.groovy.ast.ConstructorNode;
import org.codehaus.groovy.ast.GroovyCodeVisitor;
+import org.codehaus.groovy.ast.InnerClassNode;
+import org.codehaus.groovy.ast.Parameter;
import org.codehaus.groovy.ast.expr.BinaryExpression;
import org.codehaus.groovy.ast.expr.ConstructorCallExpression;
import org.codehaus.groovy.ast.expr.Expression;
@@ -55,15 +57,16 @@ public class ConstructorCallTransformer {
Expression transformConstructorCall(final ConstructorCallExpression expr) {
ConstructorNode node = (ConstructorNode) expr.getNodeMetaData(DIRECT_METHOD_CALL_TARGET);
if (node == null) return expr;
- if (node.getParameters().length == 1
- && StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(node.getParameters()[0].getType(), ClassHelper.MAP_TYPE)
+ Parameter[] params = node.getParameters();
+ if ((params.length == 1 || params.length == 2) // 2 is for inner class case
+ && StaticTypeCheckingSupport.implementsInterfaceOrIsSubclassOf(params[params.length - 1].getType(), ClassHelper.MAP_TYPE)
&& node.getCode() == StaticTypeCheckingVisitor.GENERATED_EMPTY_STATEMENT) {
Expression arguments = expr.getArguments();
if (arguments instanceof TupleExpression) {
TupleExpression tupleExpression = (TupleExpression) arguments;
List<Expression> expressions = tupleExpression.getExpressions();
- if (expressions.size() == 1) {
- Expression expression = expressions.get(0);
+ if (expressions.size() == 1 || expressions.size() == 2) { // 2 = inner class case
+ Expression expression = expressions.get(expressions.size() - 1);
if (expression instanceof MapExpression) {
MapExpression map = (MapExpression) expression;
// check that the node doesn't belong to the list of declared constructors
@@ -73,7 +76,8 @@ public class ConstructorCallTransformer {
return staticCompilationTransformer.superTransform(expr);
}
}
- // replace this call with a call to <init>() + appropriate setters
+ // replace call to <init>(Map) or <init>(this, Map)
+ // with a call to <init>() or <init>(this) + appropriate setters
// for example, foo(x:1, y:2) is replaced with:
// { def tmp = new Foo(); tmp.x = 1; tmp.y = 2; return tmp }()
MapStyleConstructorCall result = new MapStyleConstructorCall(
@@ -97,19 +101,23 @@ public class ConstructorCallTransformer {
private AsmClassGenerator acg;
private final ClassNode declaringClass;
private final MapExpression map;
- private final ConstructorCallExpression orginalCall;
+ private final ConstructorCallExpression originalCall;
+ private final boolean innerClassCall;
public MapStyleConstructorCall(
final StaticCompilationTransformer transformer,
final ClassNode declaringClass,
final MapExpression map,
- ConstructorCallExpression orginalCall) {
+ final ConstructorCallExpression originalCall) {
this.staticCompilationTransformer = transformer;
this.declaringClass = declaringClass;
this.map = map;
- this.orginalCall = orginalCall;
- this.setSourcePosition(orginalCall);
- this.copyNodeMetaData(orginalCall);
+ this.originalCall = originalCall;
+ this.setSourcePosition(originalCall);
+ this.copyNodeMetaData(originalCall);
+ List<Expression> originalExpressions = originalCall.getArguments() instanceof TupleExpression ?
+ ((TupleExpression)originalCall.getArguments()).getExpressions() : null;
+ this.innerClassCall = originalExpressions != null && originalExpressions.size() == 2;
}
@Override
@@ -117,7 +125,7 @@ public class ConstructorCallTransformer {
if (visitor instanceof AsmClassGenerator) {
acg = (AsmClassGenerator) visitor;
} else {
- orginalCall.visit(visitor);
+ originalCall.visit(visitor);
}
super.visit(visitor);
}
@@ -137,7 +145,15 @@ public class ConstructorCallTransformer {
String classInternalName = BytecodeHelper.getClassInternalName(declaringClass);
mv.visitTypeInsn(NEW, classInternalName);
mv.visitInsn(DUP);
- mv.visitMethodInsn(INVOKESPECIAL, classInternalName, "<init>", "()V", false);
+ String desc = "()V";
+ if (innerClassCall && declaringClass.isRedirectNode() && declaringClass.redirect() instanceof InnerClassNode) {
+ // load "this"
+ mv.visitVarInsn(ALOAD, 0);
+ InnerClassNode icn = (InnerClassNode) declaringClass.redirect();
+ Parameter[] params = { new Parameter(icn.getOuterClass(), "$p$") };
+ desc = BytecodeHelper.getMethodDescriptor(ClassHelper.VOID_TYPE, params);
+ }
+ mv.visitMethodInsn(INVOKESPECIAL, classInternalName, "<init>", desc, false);
mv.visitVarInsn(ASTORE, tmpObj); // store it into tmp variable
// load every field
http://git-wip-us.apache.org/repos/asf/groovy/blob/45aa4b31/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index e650473..bd2a44f 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -1927,9 +1927,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
MethodNode node;
- if (args.length == 1
- && implementsInterfaceOrIsSubclassOf(args[0], MAP_TYPE)
- && findMethod(receiver, "<init>", ClassNode.EMPTY_ARRAY).size() == 1
+ if (looksLikeNamedArgConstructor(receiver, args)
+ && findMethod(receiver, "<init>", DefaultGroovyMethods.init(args)).size() == 1
&& findMethod(receiver, "<init>", args).isEmpty()) {
// bean-style constructor
node = typeCheckMapConstructor(call, receiver, arguments);
@@ -1941,7 +1940,7 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
node = findMethodOrFail(call, receiver, "<init>", args);
if (node != null) {
- if (node.getParameters().length == 0 && args.length == 1 && implementsInterfaceOrIsSubclassOf(args[0], MAP_TYPE)) {
+ if (looksLikeNamedArgConstructor(receiver, args) && node.getParameters().length + 1 == args.length) {
node = typeCheckMapConstructor(call, receiver, arguments);
} else {
typeCheckMethodsWithGenericsOrFail(receiver, args, node, call);
@@ -1951,17 +1950,31 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
extension.afterMethodCall(call);
}
+ private boolean looksLikeNamedArgConstructor(ClassNode receiver, ClassNode[] args) {
+ return (args.length == 1 || args.length == 2 && isInnerConstructor(receiver, args[0]))
+ && implementsInterfaceOrIsSubclassOf(args[args.length - 1], MAP_TYPE);
+ }
+
+ private boolean isInnerConstructor(ClassNode receiver, ClassNode parent) {
+ return receiver.isRedirectNode() && receiver.redirect() instanceof InnerClassNode &&
+ receiver.redirect().getOuterClass().equals(parent);
+ }
+
protected MethodNode typeCheckMapConstructor(final ConstructorCallExpression call, final ClassNode receiver, final Expression arguments) {
MethodNode node = null;
if (arguments instanceof TupleExpression) {
TupleExpression texp = (TupleExpression) arguments;
List<Expression> expressions = texp.getExpressions();
- if (expressions.size() == 1) {
- Expression expression = expressions.get(0);
+ // should only get here with size = 2 when inner class constructor
+ if (expressions.size() == 1 || expressions.size() == 2) {
+ Expression expression = expressions.get(expressions.size() - 1);
if (expression instanceof MapExpression) {
MapExpression argList = (MapExpression) expression;
checkGroovyConstructorMap(call, receiver, argList);
- node = new ConstructorNode(Opcodes.ACC_PUBLIC, new Parameter[]{new Parameter(MAP_TYPE, "map")}, ClassNode.EMPTY_ARRAY, GENERATED_EMPTY_STATEMENT);
+ Parameter[] params = expressions.size() == 1
+ ? new Parameter[]{new Parameter(MAP_TYPE, "map")}
+ : new Parameter[]{new Parameter(receiver.redirect().getOuterClass(), "$p$"), new Parameter(MAP_TYPE, "map")};
+ node = new ConstructorNode(Opcodes.ACC_PUBLIC, params, ClassNode.EMPTY_ARRAY, GENERATED_EMPTY_STATEMENT);
node.setDeclaringClass(receiver);
}
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/45aa4b31/src/test/groovy/transform/stc/BugsSTCTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/BugsSTCTest.groovy b/src/test/groovy/transform/stc/BugsSTCTest.groovy
index 7f09833..07b3ba4 100644
--- a/src/test/groovy/transform/stc/BugsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/BugsSTCTest.groovy
@@ -20,8 +20,6 @@ package groovy.transform.stc
/**
* Unit tests for static type checking : bug fixes.
- *
- * @author Cedric Champeau
*/
class BugsSTCTest extends StaticTypeCheckingTestCase {
// GROOVY-5456
@@ -717,4 +715,33 @@ Printer
assert Child.name == 'Child'
'''
}
+
+ // GROOVY-7315
+ void testNamedArgConstructorSupportWithInnerClassesAndCS() {
+ assertScript '''
+ import groovy.transform.*
+ @ToString
+ class X {
+ int a
+ static X makeX() { new X(a:1) }
+ Y makeY() {
+ new Y(b:2)
+ }
+ @ToString
+ private class Y {
+ int b
+ @ToString
+ private class Z {
+ int c
+ }
+ Z makeZ() {
+ new Z(c:3)
+ }
+ }
+ }
+ assert X.makeX().toString() == 'X(1)'
+ assert X.makeX().makeY().toString() == 'X$Y(2)'
+ assert X.makeX().makeY().makeZ().toString() == 'X$Y$Z(3)'
+ '''
+ }
}
[2/5] groovy git commit: GROOVY-8295: Groovyc ant task can overflow
Windows command line if classpath is large (closes #629)
Posted by pa...@apache.org.
GROOVY-8295: Groovyc ant task can overflow Windows command line if classpath is large (closes #629)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/c6b48269
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/c6b48269
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/c6b48269
Branch: refs/heads/GROOVY_2_6_X
Commit: c6b4826935d39d31919d739b182cc8c19a8a0e19
Parents: 8aac16a
Author: paulk <pa...@asert.com.au>
Authored: Tue Nov 7 12:30:10 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Nov 13 12:44:07 2017 +1000
----------------------------------------------------------------------
.../java/org/codehaus/groovy/ant/Groovyc.java | 58 ++++++++++----------
1 file changed, 30 insertions(+), 28 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/c6b48269/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
----------------------------------------------------------------------
diff --git a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
index d69dcb4..cf6408c 100644
--- a/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
+++ b/subprojects/groovy-ant/src/main/java/org/codehaus/groovy/ant/Groovyc.java
@@ -20,23 +20,6 @@ package org.codehaus.groovy.ant;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyResourceLoader;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.nio.charset.Charset;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.StringTokenizer;
-
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.DefaultParser;
@@ -62,6 +45,22 @@ import org.codehaus.groovy.tools.FileSystemCompiler;
import org.codehaus.groovy.tools.RootLoader;
import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.StringTokenizer;
+
/**
* Compiles Groovy source files using Ant.
* <p>
@@ -1029,7 +1028,7 @@ public class Groovyc extends MatchingTask {
commandLineList.add(javaHome + separator + "bin" + separator + "java");
}
commandLineList.add("-classpath");
- commandLineList.add(classpath.toString());
+ commandLineList.add(getClasspathRelative(classpath));
final String fileEncodingProp = System.getProperty("file.encoding");
if ((fileEncodingProp != null) && !fileEncodingProp.equals("")) {
@@ -1057,6 +1056,15 @@ public class Groovyc extends MatchingTask {
}
}
+ private String getClasspathRelative(Path classpath) {
+ String raw = classpath.toString();
+ String baseDir = getProject().getBaseDir().getAbsolutePath();
+ if (!raw.startsWith(baseDir)) {
+ return raw;
+ }
+ return "." + raw.substring(baseDir.length());
+ }
+
/**
* Add "groovyc" parameters to the commandLineList, based on the ant configuration.
*
@@ -1066,7 +1074,7 @@ public class Groovyc extends MatchingTask {
*/
private void doNormalCommandLineList(List<String> commandLineList, List<String> jointOptions, Path classpath) {
commandLineList.add("--classpath");
- commandLineList.add(classpath.toString());
+ commandLineList.add(getClasspathRelative(classpath));
if (jointCompilation) {
commandLineList.add("-j");
commandLineList.addAll(jointOptions);
@@ -1133,18 +1141,12 @@ public class Groovyc extends MatchingTask {
}
private String[] makeCommandLine(List<String> commandLineList) {
- final String[] commandLine = new String[commandLineList.size()];
- for (int i = 0; i < commandLine.length; ++i) {
- commandLine[i] = commandLineList.get(i);
- }
- log.verbose("Compilation arguments:");
- log.verbose(DefaultGroovyMethods.join(commandLine, "\n"));
- return commandLine;
+ log.verbose("Compilation arguments:\n" + DefaultGroovyMethods.join(commandLineList, "\n"));
+ return commandLineList.toArray(new String[commandLineList.size()]);
}
private void runForked(String[] commandLine) {
- // use the main method in FileSystemCompiler
- final Execute executor = new Execute(); // new LogStreamHandler ( attributes , Project.MSG_INFO , Project.MSG_WARN ) ) ;
+ final Execute executor = new Execute();
executor.setAntRun(getProject());
executor.setWorkingDirectory(getProject().getBaseDir());
executor.setCommandline(commandLine);
[5/5] groovy git commit: GROOVY-8376: Add @DelegatesTo/@ClosureParams
for DGM#identity (closes #632)
Posted by pa...@apache.org.
GROOVY-8376: Add @DelegatesTo/@ClosureParams for DGM#identity (closes #632)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/412c6441
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/412c6441
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/412c6441
Branch: refs/heads/GROOVY_2_6_X
Commit: 412c6441cdfadb39847e36cbb369d900f950a9dd
Parents: 699d75c
Author: paulk <pa...@asert.com.au>
Authored: Mon Nov 13 10:57:11 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Nov 13 12:44:08 2017 +1000
----------------------------------------------------------------------
.../codehaus/groovy/runtime/DefaultGroovyMethods.java | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/412c6441/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
index 1df7be1..eec02af 100644
--- a/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java
@@ -256,9 +256,16 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* @param self the object to have a closure act upon
* @param closure the closure to call on the object
* @return result of calling the closure
+ * @see #with(Object, Closure)
* @since 1.0
*/
- public static <T> T identity(Object self, Closure<T> closure) {
+ public static <T,U> T identity(
+ @DelegatesTo.Target("self") U self,
+ @DelegatesTo(value=DelegatesTo.Target.class,
+ target="self",
+ strategy=Closure.DELEGATE_FIRST)
+ @ClosureParams(FirstParam.class)
+ Closure<T> closure) {
return DefaultGroovyMethods.with(self, closure);
}
@@ -311,7 +318,7 @@ public class DefaultGroovyMethods extends DefaultGroovyMethodsSupport {
* Allows the closure to be called for the object reference self.
* <p/>
* Any method invoked inside the closure will first be invoked on the
- * self reference. For exampe, the following method calls to the append()
+ * self reference. For example, the following method calls to the append()
* method are invoked on the StringBuilder instance and then, because
* 'returning' is true, the self instance is returned:
* <pre class="groovyTestCase">
[3/5] groovy git commit: GROOVY-8289: STC and default value in ctor
is causing debugging error (closes #630)
Posted by pa...@apache.org.
GROOVY-8289: STC and default value in ctor is causing debugging error (closes #630)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/8aac16a0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/8aac16a0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/8aac16a0
Branch: refs/heads/GROOVY_2_6_X
Commit: 8aac16a053bd3b5c8a6ac4be2a236feb4e113cfb
Parents: 45aa4b3
Author: paulk <pa...@asert.com.au>
Authored: Tue Nov 7 17:37:16 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Nov 13 12:44:07 2017 +1000
----------------------------------------------------------------------
.../groovy/classgen/AsmClassGenerator.java | 6 +--
src/test/groovy/bugs/Groovy8289Bug.groovy | 43 ++++++++++++++++++++
2 files changed, 46 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/8aac16a0/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
index 0e18e08..d3f0939 100644
--- a/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
+++ b/src/main/org/codehaus/groovy/classgen/AsmClassGenerator.java
@@ -434,6 +434,9 @@ public class AsmClassGenerator extends ClassGenerator {
}
private void visitStdMethod(MethodNode node, boolean isConstructor, Parameter[] parameters, Statement code) {
+ controller.getCompileStack().init(node.getVariableScope(), parameters);
+ controller.getCallSiteWriter().makeSiteEntry();
+
MethodVisitor mv = controller.getMethodVisitor();
final ClassNode superClass = controller.getClassNode().getSuperClass();
if (isConstructor && (code == null || !((ConstructorNode) node).firstStatementIsSpecialConstructorCall())) {
@@ -463,9 +466,6 @@ public class AsmClassGenerator extends ClassGenerator {
}
}
- controller.getCompileStack().init(node.getVariableScope(), parameters);
- controller.getCallSiteWriter().makeSiteEntry();
-
// handle body
super.visitConstructorOrMethod(node, isConstructor);
http://git-wip-us.apache.org/repos/asf/groovy/blob/8aac16a0/src/test/groovy/bugs/Groovy8289Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8289Bug.groovy b/src/test/groovy/bugs/Groovy8289Bug.groovy
new file mode 100644
index 0000000..2091f66
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8289Bug.groovy
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs
+
+import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase
+
+class Groovy8289Bug extends AbstractBytecodeTestCase {
+ void testConstructorLineIndex() {
+ def bytecode= compile(method:'<init>', '''
+ @groovy.transform.CompileStatic
+ class C {
+ String string
+ C(String s = null) { string = s }
+ static void main(args) {
+ def c = new C('') // put breakpoint on this line, run as Java app, and step
+ println c
+ }
+ }
+ ''')
+
+ assert bytecode.hasStrictSequence([
+ 'L0',
+ 'ALOAD 0',
+ 'INVOKESPECIAL java/lang/Object.<init> ()V'
+ ])
+ }
+}
[4/5] groovy git commit: GROOVY-8376: Add @DelegatesTo to
SwingBuilder methods that call setDelegate
Posted by pa...@apache.org.
GROOVY-8376: Add @DelegatesTo to SwingBuilder methods that call setDelegate
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/699d75cb
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/699d75cb
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/699d75cb
Branch: refs/heads/GROOVY_2_6_X
Commit: 699d75cba0dd2373a98bf46612beef6b4b8e1865
Parents: c6b4826
Author: paulk <pa...@asert.com.au>
Authored: Sat Nov 11 22:49:59 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Nov 13 12:44:08 2017 +1000
----------------------------------------------------------------------
.../groovy/groovy/swing/SwingBuilder.groovy | 48 ++++++++++----------
1 file changed, 23 insertions(+), 25 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/699d75cb/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
----------------------------------------------------------------------
diff --git a/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy b/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
index 8d5571e..1089a54 100644
--- a/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
+++ b/subprojects/groovy-swing/src/main/groovy/groovy/swing/SwingBuilder.groovy
@@ -87,20 +87,18 @@ import groovy.swing.factory.CollectionFactory
/**
* A helper class for creating Swing widgets using GroovyMarkup
- *
- * @author <a href="mailto:james@coredevelopers.net">James Strachan</a>
*/
-public class SwingBuilder extends FactoryBuilderSupport {
+class SwingBuilder extends FactoryBuilderSupport {
private static final Logger LOG = Logger.getLogger(SwingBuilder.name)
private static boolean headless = false
- public static final String DELEGATE_PROPERTY_OBJECT_ID = "_delegateProperty:id";
- public static final String DEFAULT_DELEGATE_PROPERTY_OBJECT_ID = "id";
+ static final String DELEGATE_PROPERTY_OBJECT_ID = "_delegateProperty:id"
+ static final String DEFAULT_DELEGATE_PROPERTY_OBJECT_ID = "id"
private static final Random random = new Random()
- public SwingBuilder(boolean init = true) {
+ SwingBuilder(boolean init = true) {
super(init)
headless = GraphicsEnvironment.isHeadless()
containingWindows = new LinkedList()
@@ -129,7 +127,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
registerFactory("bind", bindFactory)
addAttributeDelegate(bindFactory.&bindingAttributeDelegate)
registerFactory("bindProxy", new BindProxyFactory())
- registerFactory ("bindGroup", new BindGroupFactory());
+ registerFactory ("bindGroup", new BindGroupFactory())
}
def registerPassThruNodes() {
@@ -294,7 +292,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
/**
* Do some overrides for standard component handlers, else use super
*/
- public void registerBeanFactory(String nodeName, String groupName, Class klass) {
+ void registerBeanFactory(String nodeName, String groupName, Class klass) {
// poke at the type to see if we need special handling
if (LayoutManager.isAssignableFrom(klass)) {
registerFactory(nodeName, groupName, new LayoutFactory(klass))
@@ -321,12 +319,12 @@ public class SwingBuilder extends FactoryBuilderSupport {
*
* @param c this closure is run in the EDT
*/
- public SwingBuilder edt(Closure c) {
+ SwingBuilder edt(@DelegatesTo(SwingBuilder) Closure c) {
c.setDelegate(this)
if (headless || SwingUtilities.isEventDispatchThread()) {
c.call(this)
} else {
- Map<String, Object> continuationData = getContinuationData();
+ Map<String, Object> continuationData = getContinuationData()
try {
if (!(c instanceof MethodClosure)) {
c = c.curry([this])
@@ -341,7 +339,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
} catch (InvocationTargetException e) {
throw new GroovyRuntimeException("exception in event dispatch thread", e.getTargetException())
} finally {
- restoreFromContinuationData(continuationData);
+ restoreFromContinuationData(continuationData)
}
}
return this
@@ -353,7 +351,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
*
* @param c this closure is run in the EDT
*/
- public SwingBuilder doLater(Closure c) {
+ SwingBuilder doLater(@DelegatesTo(SwingBuilder) Closure c) {
c.setDelegate(this)
if (headless) {
c.call()
@@ -375,7 +373,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
*
* @param c this closure is started outside of the EDT
*/
- public SwingBuilder doOutside(Closure c) {
+ SwingBuilder doOutside(@DelegatesTo(SwingBuilder) Closure c) {
c.setDelegate(this)
if (!(c instanceof MethodClosure)) {
c = c.curry([this])
@@ -393,7 +391,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
*
* @param c run this closure in the new builder using the edt method
*/
- public static SwingBuilder edtBuilder(Closure c) {
+ static SwingBuilder edtBuilder(@DelegatesTo(SwingBuilder) Closure c) {
SwingBuilder builder = new SwingBuilder()
return builder.edt(c)
}
@@ -403,7 +401,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
* @param c run this closure in the builder using the edt method
*/
@Deprecated
- public static SwingBuilder '$static_methodMissing'(String method, Object args) {
+ static SwingBuilder '$static_methodMissing'(String method, Object args) {
if (method == 'build' && args.length == 1 && args[0] instanceof Closure) {
return edtBuilder(args[0])
} else {
@@ -416,16 +414,16 @@ public class SwingBuilder extends FactoryBuilderSupport {
*
* @param c run this closure in the builder
*/
- public Object build(Closure c) {
+ Object build(@DelegatesTo(SwingBuilder) Closure c) {
c.setDelegate(this)
return c.call()
}
- public KeyStroke shortcut(key, modifier = 0) {
+ KeyStroke shortcut(key, modifier = 0) {
return KeyStroke.getKeyStroke(key, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | modifier)
}
- public KeyStroke shortcut(String key, modifier = 0) {
+ KeyStroke shortcut(String key, modifier = 0) {
KeyStroke ks = KeyStroke.getKeyStroke(key)
if (ks == null) {
return null
@@ -433,11 +431,11 @@ public class SwingBuilder extends FactoryBuilderSupport {
return KeyStroke.getKeyStroke(ks.getKeyCode(), ks.getModifiers() | modifier | Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) }
}
- public static LookAndFeel lookAndFeel(Object laf, Closure initCode) {
+ static LookAndFeel lookAndFeel(Object laf, Closure initCode) {
lookAndFeel([:], laf, initCode)
}
- public static LookAndFeel lookAndFeel(Map attributes = [:], Object laf = null, Closure initCode = null) {
+ static LookAndFeel lookAndFeel(Map attributes = [:], Object laf = null, Closure initCode = null) {
// if we get rid of this warning, we can make it static.
//if (context) {
// LOG.warning "For best result do not call lookAndFeel when it is a child of a SwingBuilder node, initialization of the Look and Feel may be inconsistent."
@@ -445,9 +443,9 @@ public class SwingBuilder extends FactoryBuilderSupport {
groovy.swing.LookAndFeelHelper.instance.lookAndFeel(laf, attributes, initCode)
}
- public static LookAndFeel lookAndFeel(Object... lafs) {
+ static LookAndFeel lookAndFeel(Object... lafs) {
if (lafs.length == 1) {
- lookAndFeel([:], lafs[0], null as Closure);
+ lookAndFeel([:], lafs[0], null as Closure)
}
for (Object laf in lafs) {
try {
@@ -486,7 +484,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
lookAndFeel([:], laf, null as Closure)
}
- public static objectIDAttributeDelegate(def builder, def node, def attributes) {
+ static objectIDAttributeDelegate(def builder, def node, def attributes) {
def idAttr = builder.getAt(DELEGATE_PROPERTY_OBJECT_ID) ?: DEFAULT_DELEGATE_PROPERTY_OBJECT_ID
def theID = attributes.remove(idAttr)
if (theID) {
@@ -501,7 +499,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
}
}
- public static clientPropertyAttributeDelegate(def builder, def node, def attributes) {
+ static clientPropertyAttributeDelegate(def builder, def node, def attributes) {
def clientPropertyMap = attributes.remove("clientProperties")
clientPropertyMap.each { key, value ->
node.putClientProperty key, value
@@ -512,7 +510,7 @@ public class SwingBuilder extends FactoryBuilderSupport {
}
}
- public void createKeyStrokeAction( Map attributes, JComponent component = null ) {
+ void createKeyStrokeAction( Map attributes, JComponent component = null ) {
component = findTargetComponent(attributes, component)
if( !attributes.containsKey("keyStroke") ) {
throw new RuntimeException("You must define a value for keyStroke:")