From dev-return-4907-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Sat May 26 00:00:45 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 8F0CA180627 for ; Sat, 26 May 2018 00:00:44 +0200 (CEST) Received: (qmail 87560 invoked by uid 500); 25 May 2018 22:00:43 -0000 Mailing-List: contact dev-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 dev@groovy.apache.org Received: (qmail 87539 invoked by uid 99); 25 May 2018 22:00:42 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 25 May 2018 22:00:42 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id 9BFF0CC78B for ; Fri, 25 May 2018 22:00:42 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.299 X-Spam-Level: * X-Spam-Status: No, score=1.299 tagged_above=-999 required=6.31 tests=[HTML_MESSAGE=2, RCVD_IN_DNSWL_LOW=-0.7, SPF_PASS=-0.001] autolearn=disabled Received: from mx1-lw-us.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id 53g6PXw6DAlb for ; Fri, 25 May 2018 22:00:40 +0000 (UTC) Received: from mx25lb.world4you.com (mx25lb.world4you.com [81.19.149.135]) by mx1-lw-us.apache.org (ASF Mail Server at mx1-lw-us.apache.org) with ESMTPS id 7E6DC5F35B for ; Fri, 25 May 2018 22:00:40 +0000 (UTC) Received: from [84.112.214.51] (helo=[192.168.0.26]) by mx25lb.world4you.com with esmtpsa (TLSv1.2:DHE-RSA-AES256-SHA:256) (Exim 4.84_2) (envelope-from ) id 1fMKlF-0007lg-0f; Sat, 26 May 2018 00:00:33 +0200 To: dev@groovy.apache.org From: MG Subject: Groovy 2.5 @Macro ? Message-ID: <6343a2ff-ab74-d666-baeb-8b85e4b65e84@arscreat.com> Date: Sat, 26 May 2018 00:00:32 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="------------1120523CC54591578674C98D" Content-Language: en-US X-SA-Do-Not-Run: Yes X-AV-Do-Run: Yes X-SA-Exim-Connect-IP: 84.112.214.51 X-SA-Exim-Mail-From: mgbiz@arscreat.com X-SA-Exim-Scanned: No (on mx25lb.world4you.com); SAEximRunCond expanded to false This is a multi-part message in MIME format. --------------1120523CC54591578674C98D Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Hi guys, giving the new Groovy 2.5 macro functionality a spin, and would have expected the code below to replace the "call" to nv(x) with the AST expression created in the method, i.e. returning the name of the "passed" variable. Instead no macro magic happens, and the compilation accordingly fails with "groovy.lang.MissingMethodException: No signature of method: groovy.GroovyMacroSpike.nv() is applicable for argument types: (Integer) values: [123]": import org.codehaus.groovy.ast.expr.Expression import org.codehaus.groovy.ast.expr.VariableExpression import org.codehaus.groovy.macro.runtime.Macro import org.codehaus.groovy.macro.runtime.MacroContext import org.junit.Ignore import org.junit.Test import static org.codehaus.groovy.ast.tools.GeneralUtils.constX class GroovyMacroSpike { @Test @Ignore void nvTest() { final x =123 assert x ==123 assert nv(x) =="x" } @Macro Expression nv(MacroContext ctx, VariableExpression variable) { return constX(variable.getName()); } } What is missing to make this work ? mg --------------1120523CC54591578674C98D Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 7bit Hi guys,

giving the new Groovy 2.5 macro functionality a spin, and would have expected the code below to replace the "call" to nv(x) with the AST expression created in the method, i.e. returning the name of the "passed" variable. Instead no macro magic happens, and the compilation accordingly fails with "groovy.lang.MissingMethodException: No signature of method: groovy.GroovyMacroSpike.nv() is applicable for argument types: (Integer) values: [123]":
import org.codehaus.groovy.ast.expr.Expression
import org.codehaus.groovy.ast.expr.VariableExpression
import org.codehaus.groovy.macro.runtime.Macro
import org.codehaus.groovy.macro.runtime.MacroContext
import org.junit.Ignore
import org.junit.Test

import static org.codehaus.groovy.ast.tools.GeneralUtils.constX

class GroovyMacroSpike {
  @Test
  @Ignore
  void nvTest() {
    final x = 123
    assert x == 123
    assert nv(x) == "x"
  }

  @Macro
  Expression nv(MacroContext ctx, VariableExpression variable) {
    return constX(variable.getName());
  }
}
What is missing to make this work ?
mg


--------------1120523CC54591578674C98D--