Coverage Report

##### Coverage Report - org.webmacro.engine.MacroDefinition

Classes in this File | Line Coverage | Branch Coverage | Complexity
MacroDefinition |
0% | 0/16
0% | 0/6
| 2.0;2

1 |  |
     /*
2 |  |
      * Copyright (C) 1998-2001 Semiotek Inc.  All Rights Reserved.
3 |  |
      *
4 |  |
      * Redistribution and use in source and binary forms, with or without
5 |  |
      * modification, are permitted under the terms of either of the following
6 |  |
      * Open Source licenses:
7 |  |
      *
8 |  |
      * The GNU General Public License, version 2, or any later version, as
9 |  |
      * published by the Free Software Foundation
10 |  |
      * (http://www.fsf.org/copyleft/gpl.html);
11 |  |
      *
12 |  |
      *  or
13 |  |
      *
14 |  |
      * The Semiotek Public License (http://webmacro.org/LICENSE.)
15 |  |
      *
16 |  |
      * This software is provided "as is", with NO WARRANTY, not even the
17 |  |
      * implied warranties of fitness to purpose, or merchantability. You
18 |  |
      * assume all risks and liabilities associated with its use.
19 |  |
      *
20 |  |
      * See www.webmacro.org for more information on the WebMacro project.
21 |  |
      */
22 |  |
23 |  |
24 |  |
     package org.webmacro.engine;
25 |  |
26 |  |
27 |  |
     /**
28 |  |
      * MacroDefinition.java
29 |  |
      *
30 |  |
      * Represents a (C-style) macro, which gets expanded during the
31 |  |
      * building of a template.  Not to be confused with Macro as used
32 |  |
      * by WebMacro, which is something else.
33 |  |
      * @author Brian Goetz
34 |  |
      */
35 |  |
36 |  |
     public class MacroDefinition
37 |  |
     {
38 |  |
39 |  |
         private String name;
40 |  |
         private String[] argNames;
41 |  |
         Object macroBody;
42 |  |
43 |  |
         public MacroDefinition (String name,
44 |  |
                                 String[] argNames,
45 |  |
                                 Object macroBody)
46 | 0 |
         {
47 | 0 |
             this.name = name;
48 | 0 |
             this.argNames = argNames;
49 | 0 |
             this.macroBody = macroBody;
50 | 0 |
         }
51 |  |
52 |  |
         public String[] getArgNames ()
53 |  |
         {
54 | 0 |
             return argNames;
55 |  |
         }
56 |  |
57 |  |
         public String getName ()
58 |  |
         {
59 | 0 |
             return name;
60 |  |
         }
61 |  |
62 |  |
         public Object getMacroBody ()
63 |  |
         {
64 | 0 |
             return macroBody;
65 |  |
         }
66 |  |
67 |  |
         public Object expand (Object[] args, BuildContext bc)
68 |  |
                 throws BuildException
69 |  |
         {
70 | 0 |
             if (args.length != argNames.length)
71 | 0 |
                 throw new BuildException("#" + name + ": invoked with "
72 |  |
                         + args.length + " arguments, expecting "
73 |  |
                         + argNames.length + " arguments");
74 | 0 |
             if (macroBody instanceof Builder)
75 |  |
             {
76 | 0 |
                 if (bc instanceof MacroBuildContext)
77 | 0 |
                     bc = ((MacroBuildContext) bc).getRootContext();
78 | 0 |
                 MacroBuildContext mbc = new MacroBuildContext(this, args, bc);
79 | 0 |
                 return ((Builder) macroBody).build(mbc);
80 |  |
             }
81 |  |
             else
82 | 0 |
                 return macroBody;
83 |  |
         }
84 |  |
     }
85 |  |