Groovy Pattern for matching a value in map

329 Views Asked by At

Hy guys, i'm working on a IDEA plugin and custom references. I have many references working, but i'm stuck with a difficult one.

I'd like to detect patterns in groovy such as this one :

result = run service: 'createAgreementItem', with: createAgreementItemInMap

In the above line, i'd like to get the createAgreementItem element to match.

run is defined in a groovy base script

package org.apache.ofbiz.service.engine
abstract class GroovyBaseScript extends Script {
    //...
    Map run(Map args) throws ExecutionServiceException {
        return runService((String)args.get('service'), (Map)args.get('with', new HashMap()))
    }
    //...

The problem is, what i'm trying to get isn't technically a parameter, it's a value from a map with the key equals to service. So this won't work :

GroovyPatterns.groovyLiteralExpression()
        .methodCallParameter(0,
                GroovyPatterns.psiMethod().withName("run")
                        .definedInClass("org.apache.ofbiz.service.engine.GroovyBaseScript"))

Do you have any ideas or any help ? Thanks in advance !

EDIT : Actually, i'm looking for a doc or an example for any use of the org.jetbrains.plugins.groovy.lang.psi.patterns.GroovyPatterns library. I don't get it, maybe i'm not familiar enough with groovy though i used it a bit. Any help welcome on this.

1

There are 1 best solutions below

3
Jeff Scott Brown On

The problem is, what i'm trying to get isn't technically a parameter, it's a value from a map with the key equals to "service"

If all you want to do is retrieve the service value from the Map then instead of args.get('with', new HashMap()) you could do args.with.service. If you wanted null safety, you could do args?.with?.service.