The Wayback Machine - https://web.archive.org/web/20200906202500/https://github.com/objectos/code
Skip to content
master
Go to file
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

ObjectosCode

Java source code generation and annotation processing library.

Build Status Maven Central GitHub license

Example

The following code:

PackageName examplesPackage = PackageName.named("br.com.objectos.code.examples");
ClassName helloWorld = examplesPackage.nestedClass("HelloWorld");
Identifier obj = id("obj");

MethodCode mainMethod = method(
    _public(), _static(), _void(), id("main"),
    param(a(cn(String.class)), id("args")),

    _var(helloWorld, obj, _new(helloWorld)),
    invoke(obj, "sayHello")
);

MethodCode sayHelloMethod = method(
    _public(), _final(), _void(), id("sayHello"),
    cn(System.class).id("out").invoke("println", invoke("helloMessage"))
);

MethodCode helloMessageMethod = method(
    _private(), cn(String.class), id("helloMessage"),
    _return(l("Hello world!"))
);

ClassCode helloWorldClass = _class(
    _public(), _final(), id("HelloWorld"),
    mainMethod,
    sayHelloMethod,
    helloMessageMethod
);

JavaFile helloWorldFile = javaFile(
    examplesPackage,
    helloWorldClass
);

System.out.println(helloWorldFile.toString());

produces the following output:

package br.com.objectos.code.examples;

public final class HelloWorld {
  
  public static void main(String[] args) {
    HelloWorld obj = new HelloWorld();
    obj.sayHello();
  }
  
  public final void sayHello() {
    System.out.println(helloMessage());
  }

  private String helloMessage() {
    return "Hello world!";
  }

}

Documentation

A proper documentation is on the way.

In the meantime you can browse some examples here.

Maven

objectos::code is at Maven Central.

<dependency>
	<groupId>br.com.objectos.code</groupId>
	<artifactId>code</artifactId>
	<version>0.29.1</version>
</dependency>

License

Copyright (C) 2014-2020 Objectos Software LTDA

Licensed under the GNU Affero General Public License v3.

Notice

This library includes code from other open-source projects. See attached NOTICE.txt.

About

Java source code generation and annotation processing library.

Topics

Resources

License

Packages

No packages published
You can’t perform that action at this time.