1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.webmacro.engine;
25
26
27 /***
28 * MacroBuilder.java
29 *
30 * Represents the invocation of a (C-style) macro, which gets expanded
31 * during the building of a template. Not to be confused with Macro
32 * as used by WebMacro, which is something else.
33 * @author Brian Goetz
34 */
35
36 public class MacroBuilder implements Builder
37 {
38
39 private String name;
40 private ListBuilder argsBuilder;
41 private int lineNo, colNo;
42 private String[] nullArgs = new String[0];
43
44 public MacroBuilder (String name,
45 ListBuilder argsBuilder,
46 int lineNo, int colNo)
47 {
48 this.name = name;
49 this.argsBuilder = argsBuilder;
50 this.lineNo = lineNo;
51 this.colNo = colNo;
52 }
53
54 /***
55 * Expand the macro. Gets the macro definition from the build context.
56 */
57 public Object build (BuildContext bc) throws BuildException
58 {
59 MacroDefinition md = bc.getMacro(name);
60 if (md == null)
61 {
62 boolean relax = bc.getBroker().getBooleanSetting("RelaxedDirectiveBuilding");
63 if (relax)
64 return "#" + name + " ";
65 else
66 throw new BuildException("#" + name + ": no such Macro or Directive");
67 }
68 Object[] args = argsBuilder.buildAsArray(bc);
69 return md.expand(args, bc);
70 }
71 }
72