package net.yslibrary.simplepreferences.processor;

import com.google.common.base.Strings;
import com.squareup.javapoet.TypeName;
import javax.lang.model.element.VariableElement;
import net.yslibrary.simplepreferences.annotation.Key;
import net.yslibrary.simplepreferences.processor.exception.ProcessingException;

/**
 * Created by yshrsmz on 2016/02/21.
 */
public class KeyAnnotatedField {

  public final VariableElement annotatedElement;
  public final TypeName type;
  public final String name;
  public final String preferenceKey;
  public final boolean omitGetterPrefix;

  public KeyAnnotatedField(VariableElement element) throws ProcessingException {
    annotatedElement = element;

    type = TypeName.get(element.asType());

    Key annotation = element.getAnnotation(Key.class);
    name = element.getSimpleName().toString();
    preferenceKey = Strings.isNullOrEmpty(annotation.name()) ? Utils.lowerCamelToLowerSnake(name)
        : annotation.name();
    omitGetterPrefix = annotation.omitGetterPrefix();
  }
}

@@ -123,16 +123,58 @@
 peName;%0A
+import javax.lang.model.element.Modifier;%0A
 import j
@@ -696,16 +696,228 @@
 ption %7B%0A
+    if (element.getModifiers().contains(Modifier.PRIVATE)) %7B%0A      throw new ProcessingException(element,%0A          %22Field %25s is private, must be accessible from inherited class%22, element.getSimpleName());%0A    %7D%0A
     anno

check if key annotated field is not private