GithubHelp home page GithubHelp logo

revisitorannotationsprocessor's Introduction

revisitor-annotations-processor

This is an attempt to port the revisitor implementation pattern (cf https://hal.inria.fr/hal-01568169) as a vanilla Java library.

Maven

So far the only version available is the bleeding edge HEAD of the main branch of this repository.

<repositories>
  <repository>
      <id>jitpack.io</id>
      <url>https://jitpack.io</url>
  </repository>
</repositories>
<dependency>
    <groupId>com.github.manuelleduc</groupId>
    <artifactId>revisitorannotationsprocessor</artifactId>
    <version>-SNAPSHOT</version>
</dependency>

Usage

Adding the @Revisitor annotation on a Java object will allow the generation of a Revisitor interface following the class hierarchy.

The @Revisitor annotation is active and is triggered during code generation, before the compilation phase.

Example

For instance the following java definition.

package demo;

@Revisitor
class A {}
class B extends A {}
class C extends A {}
class D extends C {}

Lead to the generation of the following interface:

package demo.revisitor;


interface ARevisitor<AT, BT extends AT, CT extends AT, DT extends CT> {
  AT a(A it);
  BT b(B it);
  CT c(C it);
  DT d(D it);

  default AT $(A it) {
    if(Objects.equals(it.getClass(), A.class)) return a(it);
    if(Objects.equals(it.getClass(), B.class)) return b((B)it);
    if(Objects.equals(it.getClass(), C.class)) return c((C)it);
    if(Objects.equals(it.getClass(), D.class)) return d((D)it);
    return null;
  }

  default BT $(B it) {
    if(Objects.equals(it.getClass(), B.class)) return b(it);
    return null;
  }

  default CT $(C it) {
    if(Objects.equals(it.getClass(), C.class)) return c(it);
    if(Objects.equals(it.getClass(), D.class)) return d((D)it);
    return null;
  }

  default DT $(D it) {
    if(Objects.equals(it.getClass(), D.class)) return d(it);
    return null;
  }

}

Notes

So far the generation is only working by inheritance. A comprehensive implementation should also support classes references.

TODO

Group classes by their Revisitor Metadata

revisitorannotationsprocessor's People

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.