From 27167b58fa5f327fb704bbc923625be38f38fe4e Mon Sep 17 00:00:00 2001 From: Sander Hautvast Date: Mon, 16 Nov 2020 18:00:43 +0100 Subject: [PATCH] code example in README.md --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 260fc36..c2db9be 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,26 @@ compiles java 'opcode' to bytecode. project status: early stage * At this moment a complete compile cycle is guaranteed (unittested) for a really simple class. + +``` +BeeSource createEmptyClass() throws ClassNotFoundException { + return BeeSource.builder() + .withClassFileVersion(Version.V14) + .withPackage("nl.sander.beejava.test") + .withAccessFlags(PUBLIC, SUPER) + .withSimpleName("EmptyBean") + .withSuperClass(Object.class) // Not mandatory, like in java sourcecode + .withConstructors(createDefaultConstructor()) // There's no default constructor in beejava. The user must always add them + .build(); + } + +BeeConstructor createDefaultConstructor() throws ClassNotFoundException { + return BeeConstructor.builder() + .withAccessFlags(MethodAccessFlags.PUBLIC) + .withCode( + line(0, LD_VAR, Ref.THIS), + line(1, INVOKE, Ref.SUPER, "", "()"), + line(5, RETURN)) + .build(); + } +``` \ No newline at end of file