Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
package com.publicobject.quine;
import com.squareup.javapoet.FieldSpec;
import com.squareup.javapoet.JavaFile;
import com.squareup.javapoet.MethodSpec;
import com.squareup.javapoet.TypeSpec;
import javax.lang.model.element.Modifier;
class Quine {
static String PACKAGE = "com.publicobject.quine";
public static void main(String[] args) {
String string = "$S";
String body = "String string = $S;\n"
+ "String body = $S;\n"
+ "System.out.println($T.builder(PACKAGE, $T.classBuilder(\"Quine\")\n"
+ " .addField($T.builder(String.class, \"PACKAGE\", Modifier.STATIC)\n"
+ " .initializer($S, PACKAGE)\n"
+ " .build())\n"
+ " .addMethod($T.methodBuilder(\"main\")\n"
+ " .addModifiers($T.PUBLIC, $T.STATIC)\n"
+ " .addParameter(String[].class, \"args\")\n"
+ " .addCode(body, string, body, JavaFile.class, TypeSpec.class, FieldSpec.class, string, MethodSpec.class, Modifier.class, Modifier.class)\n"
+ " .build())\n"
+ " .build())\n"
+ " .skipJavaLangImports(true)\n"
+ " .build());\n";
System.out.println(JavaFile.builder(PACKAGE, TypeSpec.classBuilder("Quine")
.addField(FieldSpec.builder(String.class, "PACKAGE", Modifier.STATIC)
.initializer("$S", PACKAGE)
.build())
.addMethod(MethodSpec.methodBuilder("main")
.addModifiers(Modifier.PUBLIC, Modifier.STATIC)
.addParameter(String[].class, "args")
.addCode(body, string, body, JavaFile.class, TypeSpec.class, FieldSpec.class, string, MethodSpec.class, Modifier.class, Modifier.class)
.build())
.build())
.skipJavaLangImports(true)
.build());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.