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   *  VelocimacroProxy.java
24   *
25   *   a proxy Directive-derived object to fit with the current directive system
26   *
27   * @author <a href="mailto:geirm@optonline.net">Geir Magnusson Jr.</a>
28   * @version $Id: VelocimacroProxy.java 898032 2010-01-11 19:51:03Z nbubna $
29   */
30  public class VelocimacroProxy extends Directive
31  {
32      private String macroName;
33      private String[] argArray = null;
34      private String[] literalArgArray = null;
35      private int numMacroArgs = 0;
36  
37      /**
38       * Return name of this Velocimacro.
39       * @return The name of this Velocimacro.
40       */
41      public String getName()
42      {
43          return  macroName;
44      }
45  
46      /**
47       * Velocimacros are always LINE type directives.
48       * @return The type of this directive.
49       */
50      public int getType()
51      {
52          return LINE;
53      }
54  
55      /**
56       * sets the directive name of this VM
57       * 
58       * @param name
59       */
60      public void setName(String name)
61      {
62          macroName = name;
63      }
64  
65      /**
66       * sets the array of arguments specified in the macro definition
67       * 
68       * @param arr
69       */
70      public void setArgArray(String[] arr)
71      {
72          argArray = arr;
73          
74          // for performance reasons we precache these strings - they are needed in
75          // "render literal if null" functionality
76          literalArgArray = new String[arr.length];
77          for(int i = 0; i < arr.length; i++)
78          {
79              literalArgArray[i] = ".literal.$" + argArray[i];
80          }
81  
82          /*
83           * get the arg count from the arg array. remember that the arg array has the macro name as
84           * it's 0th element
85           */
86  
87          numMacroArgs = argArray.length - 1;
88      }
89  
90     /**
91       * returns the number of ars needed for this VM
92       * 
93       * @return The number of ars needed for this VM
94       */
95      public int getNumArgs()
96      {
97          return numMacroArgs;
98      }
99  
100 }
101