title: Setting property value with custom runtime annotation
body: <p>I am trying to come up with a custom annotation, wanted to see if my use-case fit a allowed way of using custom annotation.</p>
  
  <p>I want to replicate what Spring @Value does, but instead of reading a property off of a property, i want to my custom thing. </p>
  
  <pre><code>@Documented
  @Target(ElementType.FIELD)
  @Retention(RetentionPolicy.RUNTIME)
  @SupportedSourceVersion(SourceVersion.RELEASE_8)
  public @interface EncryptedValue {
     String value();
  }
  
  public Class TestEncrypted {
  
    @EncryptedValue("dGVzdCBzdHJpbmc=");
    public String someEncryptedValue;
  }
  </code></pre>
  
  <p>I am hoping in annotation processor, i decrypt value and set to the field someEncryptedValue. </p>
  
  <pre><code>/**
   *
   */
  @SupportedAnnotationTypes("annotation.EncryptedValue")
  @SupportedSourceVersion(SourceVersion.RELEASE_8)
  public class CustomProcessor extends AbstractProcessor{
  
      private Types typeUtils;
      private Elements elementUtils;
      private Filer filer;
      private Messager messager;
  
      @Override
      public synchronized void init(ProcessingEnvironment processingEnv) {
          super.init(processingEnv);
          typeUtils = processingEnv.getTypeUtils();
          elementUtils = processingEnv.getElementUtils();
          filer = processingEnv.getFiler();
          messager = processingEnv.getMessager();
      }
  
      @Override
      public boolean process(Set&lt;? extends TypeElement&gt; annotations, RoundEnvironment roundEnv) {
          for (TypeElement annotation : annotations) {
              Set&lt;? extends Element&gt; annotatedElements = roundEnv.getElementsAnnotatedWith(annotation);
              for(Element ele : annotatedElements) {
                  EncryptedValue encryptedValue = ele.getAnnotation(EncryptedValue.class);
                  if(!ele.getKind().isField()){
                      messager.printMessage(Diagnostic.Kind.ERROR,"EncryptedValue is supported for field");
                      return false;
                  }
                  String annotationValue = encryptedValue.value();
                  // now get the enclosing type
                  Set&lt;Modifier&gt; modifiers = ele.getModifiers();
                  String nameOfVariable = ele.getSimpleName().toString();
                  // check to see what fields we can modify (i think we can't modify static).
                  messager.printMessage(Diagnostic.Kind.NOTE,"ClassType: "+ele.getSimpleName().toString()+", nameOf="+annotationValue);
  
                  String simpleName = ele.getEnclosingElement().getSimpleName().toString();
                  for (Element elem  : roundEnv.getRootElements()) {
                      messager.printMessage(Diagnostic.Kind.NOTE, "Enclosing ClassName: "+elem.getSimpleName().toString());
                      if (elem.getSimpleName().toString().equals(simpleName)) {
                          for (Element variableDeclaration : elem.getEnclosedElements()) {
                              if (variableDeclaration instanceof VariableElement) {
                                  messager.printMessage(Diagnostic.Kind.NOTE, "variable: "+((VariableElement) variableDeclaration).getSimpleName().toString());
  
                              }
                          }
                      }
                  }
  
              }
          }
          return true;
      }
  }
  </code></pre>
  
  <p>I get the variable, its return types and everything, but not sure how to set value of the variable from this annotation, even if i figure it out, is it good way of using custom annotations.</p>
  
  <p>*Note: This might be sample, what I am planning to do is much more complicated than above sample.</p>