01 /*
02 * SPDX-License-Identifier: Apache-2.0
03 *
04 * Copyright 2008-2021 the original author or authors.
05 *
06 * Licensed under the Apache License, Version 2.0 (the "License");
07 * you may not use this file except in compliance with the License.
08 * You may obtain a copy of the License at
09 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18 package org.codehaus.griffon.compile.core.ast.transform;
19
20 import org.codehaus.groovy.ast.ClassNode;
21 import org.codehaus.groovy.ast.MethodNode;
22
23 import javax.annotation.Nonnull;
24 import java.lang.reflect.Modifier;
25
26 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.NO_EXCEPTIONS;
27 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.THIS;
28 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.args;
29 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.call;
30 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.injectMethod;
31 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.param;
32 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.params;
33 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.stmnt;
34 import static org.codehaus.griffon.compile.core.ast.GriffonASTUtils.var;
35 import static org.codehaus.groovy.ast.ClassHelper.STRING_TYPE;
36 import static org.codehaus.groovy.ast.ClassHelper.VOID_TYPE;
37
38 /**
39 * @author Andres Almiray
40 * @since 2.0.0
41 */
42 public class GriffonControllerASTInjector extends GriffonMvcArtifactASTInjector {
43 private static final ClassNode OBJECT_ARRAY_TYPE = makeClassSafe(Object[].class);
44 private static final String INVOKE_ACTION = "invokeAction";
45 private static final String ACTION_NAME = "actionName";
46 private static final String ARGS = "args";
47
48 @Override
49 public void inject(@Nonnull ClassNode classNode, @Nonnull String artifactType) {
50 super.inject(classNode, artifactType);
51
52 // void invokeAction(String actionName, Object... args)
53 injectMethod(classNode, new MethodNode(
54 INVOKE_ACTION,
55 Modifier.PUBLIC,
56 VOID_TYPE,
57 params(
58 param(STRING_TYPE, ACTION_NAME),
59 param(OBJECT_ARRAY_TYPE, ARGS)),
60 NO_EXCEPTIONS,
61 stmnt(call(
62 applicationProperty(classNode, "actionManager"),
63 INVOKE_ACTION,
64 args(THIS, var(ACTION_NAME), var(ARGS))))
65 ));
66 }
67 }
|