Last active
January 22, 2017 00:45
-
-
Save edefazio/b491989cd6ef72ad7ea2bc0005895c81 to your computer and use it in GitHub Desktop.
example varcode building a class model
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package usecase.model; | |
import java.io.Serializable; | |
import varcode.java.Java; | |
import varcode.java.adhoc.Export; | |
import varcode.java.model._class; | |
public class ModelClass | |
{ | |
static _class _ModelOfClass = _class.of( | |
"package usecase.model;", | |
"import java.util.UUID;", | |
"import java.io.Serializable", | |
"/** Class Javadoc comment */", | |
"@Deprecated", | |
"public class ModelOfClass<K,V> implements Serializable" ) | |
.staticBlock( "System.out.println( \"In Static Block\" );" ) | |
.field( "private static final long serialVersionUID = 42L;" ) | |
.property( | |
"/** Field JavaDoc */", | |
"@Deprecated", | |
"public final int memberField;" ) | |
.method( | |
"/** Method Javadoc*/", | |
"@Deprecated", | |
"public String getId( String prefix )", | |
"return prefix + UUID.randomUUID().toString();" ) | |
.mainMethod( "System.out.println( \"Hello World\");" ) | |
.constructor( | |
"/** constructor Javadoc */", | |
"@Deprecated", | |
"public ModelOfClass( int fieldValue )", | |
"this.memberField = fieldValue;" ); | |
public static void main( String[] args ) | |
{ | |
Export.dir("C:\\MyApp\\src\\main\\java\\").toFile(_ModelOfClass ); | |
//create an instance, pass 100 in as argument | |
Object instance = _ModelOfClass.instance( 100 ); | |
Java.callMain( instance ); //prints "Hello World" | |
Java.call( instance, "getId", "somePrefix" ); | |
//export the compiled "usecase.model.ModelOfClass.class" file | |
Export.dir( "C:\\MyApp\\target\\classes\\" ).toFile( instance.getClass() ); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
contents of the exported file : "C:/MyApp/src/main/java/usecase/ModelOfClass.java"