Skip to content
/ todo Public

An exercise to implement Rust's std::todo macro features in Java via static factory methods and AspectJ's aspect-oriented programming. Primarily includes a development aid static factory method for marking unimplemented code parts while providing an annotation-driven approach similar to Rust's std::todo macro.

License

Notifications You must be signed in to change notification settings

maikbasel/todo

Repository files navigation

TODO

Table of Contents

About the Project

This project is an exercise in bringing functionality from Rust's std::todo macro into the Java ecosystem. Inspired by Rust's straightforward and efficient approach, this project implements a similar behavior in Java making use of static factory methods and aspect-oriented programming. The central feature of the project consists of a static factory method that aids in the development process by signaling parts of the code that are yet to be implemented. Simultaneously, this project taps into the power of AspectJ to leverage aspect-oriented programming to also provide an annotation-driven approach to implementing something similar to Rust's std::todo macro.

Features

  • TODO annotation.
  • TODO helper method.

Prerequisites

  • Install Java 17 on your computer here.

Installation

TODO provides two ways of marking code as yet to be implemented, either by using a factory method or by annotation. If you don't care about the annotation add a dependency on TODO using Maven:

<dependency>
    <groupId>io.github.maikbasel</groupId>
    <artifactId>todo</artifactId>
    <version>0.1.0</version>
</dependency>

To add a dependency using Gradle:

dependencies {
  // Pick one:

  // 1. Use TODO in your implementation only:
  implementation("io.github.maikbasel:todo:0.1.0")

  // 2. Use TODO types in your public API:
  api("io.github.maikbasel:todo:0.1.0")
}

If you also want to leverage the @Todo annotation you also need to set up AspectJ in your project. To use TODO with you can, for example, use the io.freefair.aspectj.post-compile-weaving gradle plugin by adding the following dependencies to your build.gradle.kts:

plugins {
    id("java")
    id("io.freefair.aspectj.post-compile-weaving") version ("6.3.0")
}

dependencies {
    aspect("io.github.maikbasel:todo:0.1.0")
    implementation("org.aspectj:aspectjrt:1.9.21")
}

For more information on when to use api and when to use implementation, consult the Gradle documentation on API and implementation separation.

Usage

Either use the todo() factory method:

package io.github.maikbasel.todo.example;

import io.github.maikbasel.todo.Dev;

public class Service {

    public void process() {
        Dev.todo();
    }
}

or if you configured AspectJ you can use the @Todo annotation:

package io.github.maikbasel.todo.example;

import io.github.maikbasel.todo.Todo;

public class Service {

    @Todo
    public void process() {
    }
}

Both will result in a NotImplementedException to be thrown when the method you marked as TODO is called.

Development

Build the project locally using gradle

./gradlew build

About

An exercise to implement Rust's std::todo macro features in Java via static factory methods and AspectJ's aspect-oriented programming. Primarily includes a development aid static factory method for marking unimplemented code parts while providing an annotation-driven approach similar to Rust's std::todo macro.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages