use of org.codehaus.groovy.macro.runtime.Macro in project groovy by apache.
the class MacroGroovyMethods method macro.
@Macro
public static Expression macro(MacroContext macroContext, PropertyExpression phaseExpression, ConstantExpression asIsConstantExpression, ClosureExpression closureExpression) {
if (closureExpression.getParameters() != null && closureExpression.getParameters().length > 0) {
macroContext.getSourceUnit().addError(new SyntaxException("Macro closure arguments are not allowed" + '\n', closureExpression));
return macroContext.getCall();
}
final String source;
try {
source = ClosureUtils.convertClosureToSource(macroContext.getSourceUnit().getSource(), closureExpression);
} catch (Exception e) {
throw new RuntimeException(e);
}
BlockStatement closureBlock = (BlockStatement) closureExpression.getCode();
Boolean asIs = (Boolean) asIsConstantExpression.getValue();
return callX(propX(classX(ClassHelper.makeWithoutCaching(MacroBuilder.class, false)), "INSTANCE"), "macro", args(phaseExpression != null ? phaseExpression : constX(null), asIsConstantExpression, constX(source), buildSubstitutions(macroContext.getSourceUnit(), closureExpression), classX(ClassHelper.makeWithoutCaching(MacroBuilder.getMacroValue(closureBlock, asIs).getClass(), false))));
}
Aggregations