[ 
https://issues.apache.org/jira/browse/GROOVY-10771?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17610241#comment-17610241
 ] 

Eric Milles edited comment on GROOVY-10771 at 9/27/22 9:01 PM:
---------------------------------------------------------------

Your type checking script extends from 
{{org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport$TypeCheckingDSL}}.
  This type makes a few things available to you via {{getProperty(String)}}, 
{{setProperty(String,Object)}} and {{invokeMethod(String,Object)}}.  
{{isBinaryExpression}} comes from here:
{code:java}
        public Object invokeMethod(final String name, final Object args) {
            if (name.startsWith("is") && name.endsWith("Expression") && args 
instanceof Object[] && ((Object[]) args).length == 1) {
                String type = name.substring(2);
                Object target = ((Object[]) args)[0];
                if (target==null) return false;
                try {
                    Class typeClass = 
Class.forName("org.codehaus.groovy.ast.expr."+type);
                    return typeClass.isAssignableFrom(target.getClass());
                } catch (ClassNotFoundException e) {
                    return false;
                }
            }
{code}

Mostly, it delegates to 
{{org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport}} which 
is where {{setup}}, {{finish}} and so on come from.


was (Author: emilles):
Your type checking script extends from 
{{org.codehaus.groovy.transform.stc.GroovyTypeCheckingExtensionSupport$TypeCheckingDSL}}.
  This type makes a few things available to you via {{getProperty(String)}}, 
{{setProperty(String,Object)}} and {{invokeMethod(String,Object)}}.  
{{isBinaryExpression}} comes from here:
{code:java}
        public Object invokeMethod(final String name, final Object args) {
            if (name.startsWith("is") && name.endsWith("Expression") && args 
instanceof Object[] && ((Object[]) args).length == 1) {
                String type = name.substring(2);
                Object target = ((Object[]) args)[0];
                if (target==null) return false;
                try {
                    Class typeClass = 
Class.forName("org.codehaus.groovy.ast.expr."+type);
                    return typeClass.isAssignableFrom(target.getClass());
                } catch (ClassNotFoundException e) {
                    return false;
                }
            }
{code}

> Type-checking extension scripts should import AST classes
> ---------------------------------------------------------
>
>                 Key: GROOVY-10771
>                 URL: https://issues.apache.org/jira/browse/GROOVY-10771
>             Project: Groovy
>          Issue Type: Improvement
>          Components: Static Type Checker
>    Affects Versions: 4.0.5
>            Reporter: Christopher Smith
>            Priority: Minor
>
> Scripts used as type-checking extensions have some imports applied 
> automatically, but these imports do not include, for example, {{ClassNode}}, 
> which is the type of some of the callback signatures to be implemented. It 
> seems to me that the automatic imports should include
> {code}
> org.codehaus.groovy.ast.*
> org.codehaus.groovy.ast.expr.*
> {code}



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to