br.com.objectos.latest.Concrete Maven / Gradle / Ivy
Show all versions of objectos-latest Show documentation
/*
* Copyright (C) 2020-2022 Objectos Software LTDA.
*
* 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.
*/
package br.com.objectos.latest;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Indicates that the concrete implementation of the annotated type should be
* generated.
*
* Example
*
*
* The processing of the following class hierarchy:
*
*
* package com.example;
* @Concrete(modifiers = "public final", simpleName = "Example")
* abstract class ExampleJavaAny {
* public abstract void printSomething();
* }
*
* @Concrete.Bridge
* abstract class ExampleJava6 extends ExampleJavaAny {
* private final int value;
* @Constructor
* public ExampleJava6(int i) {
* this.value = i;
* }
*
* public final void printSomething() {
* System.out.println(value);
* }
* }
*
* @Concrete.Bridge
* abstract class ExampleJava11 extends ExampleJavaAny {
* private final String value;
* @Constructor
* public ExampleJava11(int i) {
* this.value = Integer.toString(i);
* }
*
* @Constructor
* public ExampleJava11(String s) {
* this.value = s;
* }
*
* public ExampleJava11(boolean ignoreMe) {}
*
* public final void printSomething() {
* System.out.println(value);
* }
* }
*
*
*
* Would generate the following class:
*
*
* package com.example;
* import br.com.objectos.latest.Generated;
* @Generated("br.com.objectos.latest.processor.ConcreteClassProcessor")
* public final class Example extends ExampleJava11 {
* public Example(int i) {
* super(i);
* }
*
* public Example(String s) {
* super(s);
* }
* }
*
*
*
* As the processor would choose, among the available bridges, the one that
* represents the latest version.
*
* @since 2
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface Concrete {
/**
* The modifiers for the generated concrete type as a single string.
*
* @return the modifiers
*/
String modifiers() default "";
/**
* The simple name of the generated concrete type.
*
* @return the simple name
*/
String simpleName();
/**
* Indicates that the annotated type should be considered as one of the
* possible bridges for the concrete implementation.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.TYPE)
public @interface Bridge {
/**
* Annotations to add to the generated type.
*
*
* The string values are written, as is, at the top of the generated type,
* one string per line. Therefore, the full declaration of the annotation
* invocation is expected.
*
*
* For example, a common use-case is to selective add the functional
* interface annotation to the generated type
*
*
* @Bridge(annotations = {
* "@java.lang.FunctionalInterface"
* })
* interface SomeInterfaceJava8 extends AbstractInterface {}
*
*
* while for Java 6 or Java 7 would be simply
*
*
* @Bridge
* interface SomeInterfaceJava6 extends AbstractInterface {}
*
* @return the lines to be added at the top of the type declaration as
* annotation values.
*/
String[] annotations() default {};
}
/**
* Indicates that a constructor with the same access level and the same
* signature as the annotated one should be generated for the concrete type.
* Should be used on the same type annotated with {@link Bridge}.
*/
@Documented
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.CONSTRUCTOR)
public @interface Constructor {}
}