¿Puedo usar anotaciones Java para definir comprobaciones de tiempo de compilación?

Por ejemplo, quería crear la anotación @Out para los parámetros de destino. Entonces, de alguna manera, usaría el compilador para verificar si el valor del parámetro se establece antes de que la función regrese. es posible?

También estaba pensando en una anotación @Immutable que no permitiría invocar ningún método no anotado con @Const o acceder a ningún campo público. (¿Tiempo de compilación y probablemente tiempo de ejecución?)

Hasta ahora tengo esto:

//I'm assuming Class retention is a subset of Runtime retention
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.PARAMETER)
public @interface Out
{
    //no idea what to go in here.
}

Esta es la otra anotación. de nuevo, no tengo una definición completa para ello:

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface Immutable
{

}

Creo que puedo comenzar a diseñar una estrategia para implementar eso en tiempo de ejecución usando la reflexión, pero quería instruir al compilador o al preprocesador para que compruebe esas cosas por mí, para que mis anotaciones tengan cero sobrecarga.

Esta es una de esas cosas que piensas "si esto se hubiera podido hacer, ya estaría allí, y si es así, ¿dónde puedo agarrarlo?".

Editar: Después de pensar más sobre@Const y@Immutable y después de recordar que Java pasa punteros a los objetos por valor, amplié la definición de@Const, se deshizo de@Immutabley modificó la definición de@Out, como sigue a continuación:

/**
* When Applied to a method, ensures the method doesn't change in any
* way the state of the object used to invoke it, i.e., all the fields
* of the object must remain the same, and no field may be returned,
* unless the field itself is marked as {@code @Const}. A method 
* annotated with {@code @Const} can only invoke other {@code @Const}
* methods of its class, can only use the class's fields to invoke
* {@code @Const} methods of the fields classes and can only pass fields
* as parameters to methods that annotate that formal parameter as
* {@code @Const}.
*
* When applied to a formal parameter, ensures the method will not
* modify the value referenced by the formal parameter. A formal   
* parameter annotated as {@code @Const} will not be aliased inside the
* body of the method. The method is not allowed to invoke another 
* method and pass the annotated parameter, save if the other method 
* also annotates the formal parameter as {@code @Const}. The method is 
* not allowed to use the parameter to invoke any of its type's methods,
* unless the method being invoked is also annotated as {@code @Const}
* 
* When applied to a field, ensures the field cannot be aliased and that
* no code can alter the state of that field, either from inside the   
* class that owns the field or from outside it. Any constructor in any
* derived class is allowed to set the value of the field and invoke any
* methods using it. As for methods, only those annotated as
* {@code @Const} may be invoked using the field. The field may only be
* passed as a parameter to a method if the method annotates the 
* corresponding formal parameter as {@code @Const}
* 
* When applied to a local variable, ensures neither the block where the
* variable is declared or any nested block will alter the value of that 
* local variable. The local variable may be defined only once, at any
* point where it is in scope. Only methods annotated as
* {@code @Const} may be invoked using this variable, and the variable 
* may only be passed as a parameter to another method if said method
* annotates its corresponding formal parameter as {@code @Const}
*
*/
@Retention(RetentionPolicy.SOURCE)
@Target({ElementType.METHOD, ElementType.PARAMETER, ElementType.FIELD,
ElementType.LOCAL_VARIABLE})
@Inherited
public @interface Const
{

}

Ahora el@Out:

/**
* The formal parameter annotated with {@code @Out} must be undefined in 
* the scope of the caller, and it's the responsibility of the method to
* define it. If allowNull is true, the parameter can be explicitly set
* to null in the body of the method.
*/
@Retention(RetentionPolicy.SOURCE)
@Target(ElementType.PARAMETER)
public @interface Out
{
    boolean allowNull() default false;
}

Editar: Estoy tratando de implementar esto como un complemento de eclipse, pero estoy completamente perdido leyendo el manual. Escribí un complemento con la lógica básica para acceder al AST y visitar métodos y campos. Luego hice un montón de anotaciones ficticias que mi complemento debería detectar, luego trato de imprimir los resultados, pero ni siquiera estoy seguro de qué esperar. Mi complemento es un complemento de "Incremental Build". Aquí está el código, si alguien pudiera echar un vistazo y explicarme algunas cosas. Estoy completamente perdido en esta API.

https://github.com/Starless2001/Plugin-for-Eclipse

Respuestas a la pregunta(1)

Su respuesta a la pregunta