All Downloads are FREE. Search and download functionalities are using the official Maven repository.

gw.lang.function.gen_classes.gsp-text Maven / Gradle / Ivy

There is a newer version: 1.18.2
Show newest version
/*
 * Used to generate the block classes.  Should be run from this directory
 *
 *  Copyright 2014 Guidewire Software, Inc.
 */
uses java.lang.StringBuilder

for( arity in 0..16 ) {

  var clazz = new StringBuilder()
  var iface = new StringBuilder()

  // class per arity
  clazz.append( "package gw.lang.function;\n" )
       .append( "\n" )
       .append( "public abstract class Function${arity} extends AbstractBlock implements IFunction${arity} { \n" )
       .append( "\n" )
       .append( "  public Object invokeWithArgs(Object[] args) {\n" )
       .append( "    if(args.length != ${arity}) {\n" )
       .append( "      throw new IllegalArgumentException(\"You must pass ${arity} args to this block, but you passed\" + args.length);\n" )
       .append( "    } else { \n" )
       .append( "      return invoke(" )
       
  for( arg in 0..|arity index i ) {
    if( i != 0 ) {
      clazz.append( ", " )
    }
    clazz.append( "args[${arg}]" )
  }
  clazz.append( ");\n");

  clazz.append( "    }\n" )
       .append( "  }\n" )
       .append( "\n" )
       .append( "}\n" )

  // interface per arity
  iface.append( "package gw.lang.function;\n" )
       .append( "\n" )
       .append( "public interface IFunction${arity} extends IBlock { \n" )
       .append( "\n" )
       .append( "  public Object invoke(" )
  for( arg in 0..|arity index i ) {
    if( i != 0 ) {
      iface.append( ", " )
    }
    iface.append( "Object arg${arg}" )
  }
  iface.append( ");\n")
       .append( "\n" )
       .append( "}\n" )

  new java.io.File( "Function${arity}.java" ). write( clazz.toString() )
  new java.io.File( "IFunction${arity}.java" ). write( iface.toString() )
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy