Coverage Report - org.webmacro.directive.MacroDirective
 
Classes in this File Line Coverage Branch Coverage Complexity
MacroDirective
18%
3/16
0%
0/2
1.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  
 package org.webmacro.directive;
 24  
 
 25  
 import org.webmacro.Context;
 26  
 import org.webmacro.FastWriter;
 27  
 import org.webmacro.PropertyException;
 28  
 import org.webmacro.TemplateVisitor;
 29  
 import org.webmacro.engine.BuildContext;
 30  
 import org.webmacro.engine.BuildException;
 31  
 import org.webmacro.engine.MacroDefinition;
 32  
 
 33  
 import java.io.IOException;
 34  
 
 35  
 /**
 36  
  * MacroDirective
 37  
  *
 38  
  * @author Brian Goetz
 39  
  */
 40  
 
 41  
 public class MacroDirective extends Directive
 42  
 {
 43  
 
 44  
     private static final int MACRO_NAME = 1;
 45  
     private static final int MACRO_ARGS = 2;
 46  
     private static final int MACRO_BODY = 3;
 47  
 
 48  
     private static final ArgDescriptor[]
 49  2
             myArgs = new ArgDescriptor[]{
 50  
                 new NameArg(MACRO_NAME),
 51  
                 new FormalArgListArg(MACRO_ARGS),
 52  
                 new BlockArg(MACRO_BODY)
 53  
             };
 54  
 
 55  
     private static final DirectiveDescriptor
 56  2
             myDescr = new DirectiveDescriptor(null, null, myArgs, null);
 57  
 
 58  
     public static DirectiveDescriptor getDescriptor ()
 59  
     {
 60  6
         return myDescr;
 61  
     }
 62  
 
 63  
     public MacroDirective ()
 64  0
     {
 65  0
     }
 66  
 
 67  
     public Object build (DirectiveBuilder builder,
 68  
                          BuildContext bc)
 69  
             throws BuildException
 70  
     {
 71  0
         String name = (String) builder.getArg(MACRO_NAME, bc);
 72  0
         Object[] args = (Object[]) builder.getArg(MACRO_ARGS, bc);
 73  0
         String[] argNames = new String[args.length];
 74  0
         for (int i = 0; i < args.length; i++)
 75  0
             argNames[i] = (String) args[i];
 76  0
         Object body = builder.getArg(MACRO_BODY);
 77  0
         MacroDefinition macro = new MacroDefinition(name, argNames, body);
 78  0
         bc.putMacro(name, macro);
 79  0
         return null;
 80  
     }
 81  
 
 82  
     public void write (FastWriter out, Context context)
 83  
             throws PropertyException, IOException
 84  
     {
 85  0
     }
 86  
 
 87  
     public void accept (TemplateVisitor v)
 88  
     {
 89  0
     }
 90  
 
 91  
 }