Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type inferencing, syntax highlighting and code navigation for macro methods #1063

Open
eric-milles opened this issue Mar 19, 2020 · 1 comment

Comments

@eric-milles
Copy link
Member

eric-milles commented Mar 19, 2020

Consider the following (taken from https://docs.groovy-lang.org/latest/html/documentation/#_macro_methods):

src/main/macros/MacroMethod.groovy

package macros

import groovy.transform.*
import org.codehaus.groovy.ast.expr.*
import org.codehaus.groovy.macro.runtime.*

import static org.codehaus.groovy.ast.tools.GeneralUtils.*

@AutoFinal @CompileStatic
class MacroMethod {
  @Macro
  static Expression safe(MacroContext ctxt, MethodCallExpression call) {
    ternaryX(notNullX(call.objectExpression), call, nullX())
  }
}

META-INF/groovy/org.codehaus.groovy.runtime.ExtensionModule

moduleName=whatever
moduleVersion=1.0.0-SNAPSHOT
extensionClasses=macros.MacroMethod

script.groovy (in another project)

def objExp = null
def hashCode = safe(objExp.hashCode())
assert safe(hashCode.toString()) == null

Calls to macro method "safe" have default highlighting and make reference to MacroStub. It would be nice to have similar coloration to extension methods (DGMs) and have code navigation back to the actual macro method.

image

@eric-milles
Copy link
Member Author

Notes: no traces of the original method call expression is left in the AST after the macro method is processed. And groovy-macro cannot be patched since it is not shipped with the eclipse tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant