Skip to content

gitter-badger/JavaPoetic

 
 

Repository files navigation

JavaPoetic

Download JitPack Build Status Join the chat at https://gitter.im/yongjhih/JavaPoetic

art/java-poetic.png

JavaPoet Simple Builder.

Square JavaPoet: https://github.com/square/javapoet

For JavaPoet example:

package com.example.helloworld;

public final class HelloWorld {
  public static void main(String[] args) {
    System.out.println("Hello, JavaPoet!");
  }
}

Before:

MethodSpec main = MethodSpec.methodBuilder("main")
    .addModifiers(Modifier.PUBLIC, Modifier.STATIC)
    .returns(void.class)
    .addParameter(String[].class, "args")
    .addStatement("$T.out.println($S)", System.class, "Hello, JavaPoet!")
    .build();

TypeSpec helloWorld = TypeSpec.classBuilder("HelloWorld")
    .addModifiers(Modifier.PUBLIC, Modifier.FINAL)
    .addMethod(main)
    .build();

JavaFile javaFile = JavaFile.builder("com.example.helloworld", helloWorld)
    .build();

javaFile.emit(System.out);

After:

JavaFile javaFile = PoeticFile.Of.packages("com.example.helloworld").of(
            PoeticClass.Of.publics().classes("HelloWorld").method(
                PoeticMethod.Of.publics().statics().voids().name("main").parameter(String.class, "args").statement(
                    PoeticStatement.of("$T.out.println($S)", System.class, "Hello, JavaPoet!")
                )
            )
        );

javaFile.emit(System.out);

Installation

repositories {
    maven { url "https://jitpack.io" }
}

dependencies {
    compile 'com.github.yongjhih:javapoetic:-SNAPSHOT'
}

via jcenter(in progress):

repositories {
    jcenter()
}

dependencies {
    compile 'com.infstory:javapoetic:1.0.0'
}

Test

./gradlew test

License

Copyright 2015 8tory, Inc.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

JavaPoet Simple Builder

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%