For DSL purposes I want to detect methods defined like:
def "methodName"() {}
or
def "This is another method name"() {}
Is there any way to do that using reflection?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This information is not available at runtime. Even with an AST transformation, you would not be able to figure out that the method was defined using a string.
For this, you would have to write your own
AntlrParserPluginand use it using a customCompilerConfiguration. Then in methodDef fromAntlrParserPlugin, when the name of the method is parsed, you could check that the character before the name is a double quote. If a double quote is found, then add a custom annotation to the generatedMethodNode, so that the information is available at runtime…