You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Jamie Echlin <ja...@gmail.com> on 2015/09/02 09:24:24 UTC

replace a property in a static type checking script

Struggling a bit here with my STC script.

The binding variables has a Map<String, Object>

But, based on the key, the STC script can provide a more specific type. So
the input script might be something like:

map["duck"].quack()

This is failing at the moment because Object has no quack() method.

In the unresolvedProperty closure I am trying to replace map["duck"] with
an expression with a Duck return type:

def bexp = new BinaryExpression(objectExpression.leftExpression,
objectExpression.operation, objectExpression.rightExpression)
bexp.setType(ClassHelper.make(Duck))
def replacementPexp = new PropertyExpression(bexp, pexp.property)
makeDynamic(replacementPexp, ClassHelper.VOID_TYPE)
setHandled(false);

I don't want to set this as handled, because I want quack() to be checked.

Is there a way to tell the STC script to "reparse" this expression as I am
trying to do, or do I need another AST transform in an earlier compile
phase?

Any help appreciated, please LMK if not clear.

cheers, jamie