Giter Club home page Giter Club logo

metagen's Introduction

MetaGen is an annotation processor that generates metadata about classes.

Features

Currently it only generates property meta information that can be used to construct refactor safe property expressions.

For example, using metagen-wicket module the following code that depends on strings:

IModel<Person> person=getPersonModel();
IModel<String> street=new PropertyModel<Street>(person, "address.street");

can be replaced with the following:

IModel<Person> person=getPersonModel();
IModel<String> street=MetaModel.of(person).get(PersonMeta.address).get(AddressMeta.street);

although the code is a more verbose then its string alternative it will generate a compile time error should any properties change instead of failing at runtime like its more concise string alternative.

Triggers

The processor supports the following triggers that will generate meta classes:

  • A class is annotated with a JPA annotaiton, eg @Entity or @MappedSuperClass
  • A class is annotated with @Bean annotation
  • A field or getter is annotated with @Property annotation

The annotation processor is still in early stages of development

Installation

Add the following dependencies into your pom.xml

<dependency>
	<groupId>net.ftlines.metagen</groupId>
	<artifactId>metagen-core</artifactId>
	<version>${metagen.version}</version>
</dependency>
<dependency>
	<groupId>net.ftlines.metagen</groupId>
	<artifactId>metagen-processor</artifactId>
	<version>${metagen.version}</version>
</dependency>
<dependency>
	<groupId>net.ftlines.metagen</groupId>
	<artifactId>metagen-wicket</artifactId>
	<version>${metagen.version}</version>
</dependency>

See here for available versions: http://search.maven.org/#search%7Cga%7C1%7Cnet.ftlines.metagen

Add the following to your build plugins in your pom.xml

<!-- disable default annotation processing by javac -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <compilerArgument>-proc:none</compilerArgument>
   </configuration>
</plugin>
<!-- use maven-processor to run apt processors -->
<plugin>
    <groupId>org.bsc.maven</groupId>
    <artifactId>maven-processor-plugin</artifactId>
    <version>2.0.5</version>
    <executions>
        <execution>
            <id>process</id>
            <goals>
                <goal>process</goal>
            </goals>
            <phase>generate-sources</phase>
            <configuration>
                <outputDirectory>target/metamodel</outputDirectory>
            </configuration>
        </execution>
    </executions>
</plugin>
<!-- make sure target/metamodel is on the source path -->
<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
        <execution>
            <id>add-source</id>
            <phase>generate-sources</phase>
            <goals>
                <goal>add-source</goal>
            </goals>
            <configuration>
                <sources>
                    <source>target/metamodel</source>
                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>

You may also need to add a plugin repository to get the 2.0.5 version of the maven processor:

<pluginRepository>
    <id>sonatype-repo</id>
    <url>https://oss.sonatype.org/content/repositories/releases</url>
</pluginRepository>

Building MetaGen from source

Because this is an annotation processor there are some hoops to jump through compared to other projects. Namely, the project has to be installed like this: mvn install -Dmaven.test.skip=true After the above command has been executed normal commands can be used, such as mvn eclipse:eclipse

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.