From commits-return-5801-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Fri Mar 9 01:06:14 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id A48CB18064C for ; Fri, 9 Mar 2018 01:06:13 +0100 (CET) Received: (qmail 86087 invoked by uid 500); 9 Mar 2018 00:06:12 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 86078 invoked by uid 99); 9 Mar 2018 00:06:12 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Mar 2018 00:06:12 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 01DB9F650E; Fri, 9 Mar 2018 00:06:11 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sunlan@apache.org To: commits@groovy.apache.org Message-Id: <9d994c14072f4e2e823d002c9fd60d39@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: groovy git commit: Minor refactoring: Extract common method for `ClassNode` Date: Fri, 9 Mar 2018 00:06:11 +0000 (UTC) Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X f9c2ffa65 -> f5f421b71 Minor refactoring: Extract common method for `ClassNode` (cherry picked from commit 3bbd5a7) Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/f5f421b7 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/f5f421b7 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/f5f421b7 Branch: refs/heads/GROOVY_2_6_X Commit: f5f421b715439b04d9353e2420d57fcc200b82c6 Parents: f9c2ffa Author: sunlan Authored: Fri Mar 9 08:04:00 2018 +0800 Committer: sunlan Committed: Fri Mar 9 08:06:01 2018 +0800 ---------------------------------------------------------------------- .../java/org/codehaus/groovy/ast/ClassNode.java | 31 ++++++++ .../codehaus/groovy/classgen/asm/MopWriter.java | 2 +- .../asm/sc/StaticTypesWriterController.java | 9 ++- src/test/groovy/transform/stc/LambdaTest.groovy | 83 ++++++++++++-------- 4 files changed, 88 insertions(+), 37 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/f5f421b7/src/main/java/org/codehaus/groovy/ast/ClassNode.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/groovy/ast/ClassNode.java b/src/main/java/org/codehaus/groovy/ast/ClassNode.java index 083d5b4..d6ddb83 100644 --- a/src/main/java/org/codehaus/groovy/ast/ClassNode.java +++ b/src/main/java/org/codehaus/groovy/ast/ClassNode.java @@ -964,6 +964,21 @@ public class ClassNode extends AnnotatedNode implements Opcodes, GroovydocHolder } /** + * + * @param classNodes the class nodes for the interfaces + * @return true if this class or any base class implements any of the given interfaces + */ + public boolean implementsAnyInterfaces(ClassNode... classNodes) { + for (ClassNode classNode : classNodes) { + if (implementsInterface(classNode)) { + return true; + } + } + + return false; + } + + /** * @param classNode the class node for the interface * @return true if this class or any base class implements the given interface */ @@ -980,6 +995,22 @@ public class ClassNode extends AnnotatedNode implements Opcodes, GroovydocHolder } /** + * + * @param classNodes the class nodes for the interfaces + * @return true if this class declares that it implements any of the given interfaces + * or if one of its interfaces extends directly or indirectly any of the given interfaces + */ + public boolean declaresAnyInterfaces(ClassNode... classNodes) { + for (ClassNode classNode : classNodes) { + if (declaresInterface(classNode)) { + return true; + } + } + + return false; + } + + /** * @param classNode the class node for the interface * @return true if this class declares that it implements the given interface * or if one of its interfaces extends directly or indirectly the interface http://git-wip-us.apache.org/repos/asf/groovy/blob/f5f421b7/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java b/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java index fff65d1..6d06742 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/MopWriter.java @@ -86,7 +86,7 @@ public class MopWriter { public void createMopMethods() { ClassNode classNode = controller.getClassNode(); - if (classNode.declaresInterface(ClassHelper.GENERATED_CLOSURE_Type) || classNode.declaresInterface(ClassHelper.GENERATED_LAMBDA_TYPE)) { + if (classNode.declaresAnyInterfaces(ClassHelper.GENERATED_CLOSURE_Type, ClassHelper.GENERATED_LAMBDA_TYPE)) { return; } Set currentClassSignatures = buildCurrentClassSignatureSet(classNode.getMethods()); http://git-wip-us.apache.org/repos/asf/groovy/blob/f5f421b7/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java index 5ce784a..7891d03 100644 --- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java +++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesWriterController.java @@ -94,14 +94,15 @@ public class StaticTypesWriterController extends DelegatingController { private void updateStaticCompileFlag(final MethodNode mn) { ClassNode classNode = getClassNode(); AnnotatedNode node = mn; - boolean implementsGeneratedClosureOrGeneratedLambdaInterface = classNode.implementsInterface(ClassHelper.GENERATED_CLOSURE_Type) || classNode.implementsInterface(ClassHelper.GENERATED_LAMBDA_TYPE); + boolean implementsGeneratedClosureOrGeneratedLambdaInterface = classNode.implementsAnyInterfaces(ClassHelper.GENERATED_CLOSURE_Type, ClassHelper.GENERATED_LAMBDA_TYPE); if (implementsGeneratedClosureOrGeneratedLambdaInterface) { node = classNode.getOuterClass(); } - isInStaticallyCheckedMethod = mn != null && ( - StaticCompilationVisitor.isStaticallyCompiled(node) - || implementsGeneratedClosureOrGeneratedLambdaInterface && classNode.getNodeMetaData(StaticCompilationMetadataKeys.STATIC_COMPILE_NODE) != null); + boolean isStaticCompileNode = classNode.getNodeMetaData(StaticCompilationMetadataKeys.STATIC_COMPILE_NODE) != null; + isInStaticallyCheckedMethod = + mn != null && (StaticCompilationVisitor.isStaticallyCompiled(node) + || implementsGeneratedClosureOrGeneratedLambdaInterface && isStaticCompileNode); } @Override http://git-wip-us.apache.org/repos/asf/groovy/blob/f5f421b7/src/test/groovy/transform/stc/LambdaTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy index 4d8003c..8303f91 100644 --- a/src/test/groovy/transform/stc/LambdaTest.groovy +++ b/src/test/groovy/transform/stc/LambdaTest.groovy @@ -27,9 +27,10 @@ class LambdaTest extends GroovyTestCase { private static final boolean SKIP_ERRORS = true; private static final boolean PRE_JAVA8 = VMPluginFactory.getPlugin().getVersion() < 8; private static final boolean USE_PARROT = ParserVersion.V_2 != CompilerConfiguration.DEFAULT.parserVersion + public static final boolean SKIP_TEST = PRE_JAVA8 || !USE_PARROT void testFunction() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -50,7 +51,7 @@ class LambdaTest extends GroovyTestCase { } void testFunction2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -70,8 +71,9 @@ class LambdaTest extends GroovyTestCase { ''' } + void testFunctionScript() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -87,8 +89,25 @@ class LambdaTest extends GroovyTestCase { ''' } + void testFunctionScript2() { + if (SKIP_TEST) return; + + assertScript ''' + import groovy.transform.CompileStatic + import java.util.stream.Collectors + import java.util.stream.Stream + + @CompileStatic + void p() { + assert [2, 3, 4] == [1, 2, 3].stream().map(e -> e.plus 1).collect(Collectors.toList()); + } + + p() + ''' + } + void testBinaryOperator() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -109,7 +128,7 @@ class LambdaTest extends GroovyTestCase { } void testConsumer() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -131,7 +150,7 @@ class LambdaTest extends GroovyTestCase { } void testPredicate() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -154,7 +173,7 @@ class LambdaTest extends GroovyTestCase { } void testUnaryOperator() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -177,7 +196,7 @@ class LambdaTest extends GroovyTestCase { } void testBiConsumer() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -199,7 +218,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithLocalVariables() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -222,7 +241,7 @@ class LambdaTest extends GroovyTestCase { void testFunctionWithLocalVariables2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -245,7 +264,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithLocalVariables4() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -268,7 +287,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithStaticMethodCall() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -295,7 +314,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithStaticMethodCall2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -322,7 +341,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithInstanceMethodCall() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -347,7 +366,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionInConstructor() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -372,7 +391,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithInstanceMethodCall2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -397,7 +416,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithInstanceMethodCall3() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -422,7 +441,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionCall() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -445,7 +464,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionCall2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -468,7 +487,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionCall3() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -491,7 +510,7 @@ class LambdaTest extends GroovyTestCase { } void testConsumerCall() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -516,7 +535,7 @@ class LambdaTest extends GroovyTestCase { } void testConsumerCall2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -541,7 +560,7 @@ class LambdaTest extends GroovyTestCase { } void testConsumerCall3() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -566,7 +585,7 @@ class LambdaTest extends GroovyTestCase { } void testSamCall() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -593,7 +612,7 @@ class LambdaTest extends GroovyTestCase { } void testSamCall2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -620,7 +639,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithUpdatingLocalVariable() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -643,7 +662,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithUpdatingLocalVariable2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -666,7 +685,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithVariableDeclaration() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -690,7 +709,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithMixingVariableDeclarationAndMethodInvocation() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -720,7 +739,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithNestedLambda() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -749,7 +768,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithNestedLambda2() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic @@ -776,7 +795,7 @@ class LambdaTest extends GroovyTestCase { } void testFunctionWithNestedLambda3() { - if (PRE_JAVA8 || !USE_PARROT) return; + if (SKIP_TEST) return; assertScript ''' import groovy.transform.CompileStatic