SQL-like DSL for finding classes and methods





5
Date Submitted Tue. Oct. 17th, 2006 3:00 PM
Revision 1 of 1
Helper glaforge
Tags dsl | groovy
Comments 0 comments
SQL-like DSL for finding classes and methods

// Java 5, with Iterable interface for the foreach loop
explorer.find(new ClassFinder() {
    public boolean classMatches(QueryClass aClass) {
        for (QueryMethod aMethod: aClass.getMethods()) {
            if (aMethod.isLike("join") && aMethod.isReturning("net.jxta.credential.Credential"))
                return true;
        }
        return false;
    }
});
 

def explorer = new Explorer() // pass it some jar file paths

explorer.query(
    select: classes,
     where: extend("net.jxta.service.Service"),
       and: hasMethod(
             like: "join",
        returning: "net.jxta.credential.Credential"
       )
}

explorer.findAllClasses { aClass ->
    aClass.isExtending("net.jxta.service.Service") &&
    aClass.hasMethod { aMethod ->
        aMethod.like("join") &&
        aMethod.returning("net.jxta.credential.Credential")
    }
}

explorer.findAllClasses {
    it.isExtending("net.jxta.service.Service") &&
    it.hasAMethod {
        it.isLike("join") &&
        it.isReturning("net.jxta.credential.Credential")
    }
}

it.hasAMethod.like("join").returning("net.jxta.credential.Credential")
 

Guillaume Laforge

glaforge.free.fr/blog/groovy

Comments

There are currently no comments for this snippet.

Voting