/* * [Generate.java] * * Summary: Generate Java code to test generated code. * * Copyright: (c) 1997-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 5.7 2008-04-02 add build number to title * 5.8 2009-12-21 use keyword final as much as possible in generated code. * 5.9 2010-02-21 use of FastCat instead of StringBuilder. Generate code to use Aux buffering for Readers and Writers. * 6.0 2010-12-06 support getResourceAsStream, FileReader, FileWriter. */ package com.mindprod.fileio; import com.mindprod.fastcat.FastCat; import java.io.FileWriter; import java.io.IOException; import static java.lang.System.*; /** * Generate Java code to test generated code. *

* We don't generate the expansions as HTML the way we do with the Converter. They are only available as the Applet. * * @author Roedy Green, Canadian Mind Products * @version 6.0 2010-12-06 support getResourceAsStream, FileReader, FileWriter * @since 1997 */ public class Generate { /** * Generate all possible combinations. They will be tested separately to see if they can be compiled. Only used * during debugging. Puts results in C:\temp\TestClass.java where it can be test compiled. */ private static void generateAllCombinationsForCompileTest() { if ( FileIO.DEBUGGING ) { out.println( "Generating TestClass.java of all combinations of file i/o" ); try { FileWriter p = new FileWriter( "C:/temp/TestClass.java" ); FastCat dummyHead = new FastCat( 13 ); dummyHead.append( "// Test file to ensure all code FileIO can generate will at least compile." ); dummyHead.append( "\npackage com.mindprod.fileio;import static java.lang.System.out;import static java.lang.System.err;" ); dummyHead.append( "\nimport java.io.*;" ); dummyHead.append( "\nimport java.net.*;" ); dummyHead.append( "\nimport java.util.zip.*;" ); dummyHead.append( "\nimport static java.lang.System.err;" ); dummyHead.append( "\nimport static java.lang.System.*;" ); dummyHead.append( "\nimport com.mindprod.ledatastream.*;" ); dummyHead.append( "\nfinal class TestClass {" ); dummyHead.append( "\nprivate static int readBytesBlocking ( InputStream in, byte b[], int off, " + "int len ) throws IOException{" ); dummyHead.append( "\nreturn 0; }" ); dummyHead.append( "\nvoid dummy () {" ); dummyHead.append( "\ntry {\n" ); p.write( dummyHead.toString() ); for ( FileType f : FileType.values() ) { for ( DataType d : DataType.values() ) { for ( int inputting = 0; inputting < 2; inputting++ ) { for ( int buffered = 0; buffered < 2; buffered++ ) { for ( int compressed = 0; compressed < 2; compressed++ ) { // nesting to create new // local variable environment // and to visually break p.write( "// " + f.toString() + " " + d.toString() + " " + ( ( inputting == 0 ) ? "read" : "write" ) + " " + ( ( buffered == 0 ) ? "unbuffered" : "buffered" ) + " " + ( ( compressed == 0 ) ? "uncompressed" : "compressed" ) + "\n" ); p.write( "{\n" + How.how( f, d, inputting != 0, buffered != 0, compressed != 0 ) + "}\n\n" ); } } } } } p.write( "} catch ( Exception e ) {}}}\n" ); p.close(); } catch ( IOException e ) { err.println(); e.printStackTrace( err ); err.println(); } } } public static void main( String[] args ) { if ( FileIO.DEBUGGING ) { // generate Java source code all combinations to test compile generateAllCombinationsForCompileTest(); } else { err.println( "Nothing generated unless FileIO.DEBUGGING=true." ); } } }