View Javadoc
1   package net.sourceforge.pmd.lang.vm.directive;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  /**
23   * This class acts as a proxy for potential macros.  When the AST is built
24   * this class is inserted as a placeholder for the macro (whether or not
25   * the macro is actually defined).  At render time we check whether there is
26   * a implementation for the macro call. If an implementation cannot be
27   * found the literal text is rendered.
28   * @since 1.6
29   */
30  public class RuntimeMacro extends Directive
31  {
32      /**
33       * Name of the macro
34       */
35      private String macroName;    
36     
37      /**
38       * Create a RuntimeMacro instance. Macro name and source
39       * template stored for later use.
40       *
41       * @param macroName name of the macro
42       */
43      public RuntimeMacro(String macroName)
44      {
45          if (macroName == null)
46          {
47              throw new IllegalArgumentException("Null arguments");
48          }
49          
50          this.macroName = macroName.intern();
51      }
52  
53      /**
54       * Return name of this Velocimacro.
55       *
56       * @return The name of this Velocimacro.
57       */
58      public String getName()
59      {
60          return macroName;
61      }
62  
63      /**
64       * Override to always return "macro".  We don't want to use
65       * the macro name here, since when writing VTL that uses the
66       * scope, we are within a #macro call.  The macro name will instead
67       * be used as the scope name when defining the body of a BlockMacro.
68       */
69      public String getScopeName()
70      {
71          return "macro";
72      }
73  
74      /**
75       * Velocimacros are always LINE
76       * type directives.
77       *
78       * @return The type of this directive.
79       */
80      public int getType()
81      {
82          return LINE;
83      }
84      
85  }