Skip to content

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

Open
@eric-milles

Description

@eric-milles

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions