package com.tinkerpop.frames.annotations;

import com.tinkerpop.blueprints.Direction;
import com.tinkerpop.blueprints.Edge;
import com.tinkerpop.blueprints.Element;
import com.tinkerpop.blueprints.Vertex;
import com.tinkerpop.frames.ClassUtilities;
import com.tinkerpop.frames.FramedGraph;
import com.tinkerpop.frames.Property;

import java.lang.reflect.Method;

public class PropertyAnnotationHandler implements AnnotationHandler<Property> {

    @Override
    public Class<Property> getAnnotationType() {
        return Property.class;
    }

    @Override
    public Object processElement(final Property annotation, final Method method, final Object[] arguments, final FramedGraph framedGraph, final Element element, final Direction direction) {
        if (ClassUtilities.isGetMethod(method)) {
            return element.getProperty(annotation.value());
        } else if (ClassUtilities.isSetMethod(method)) {
            Object value = arguments[0];
            if (null == value) {
                element.removeProperty(annotation.value());
            } else {
                element.setProperty(annotation.value(), value);
            }
            return null;
        } else if (ClassUtilities.isRemoveMethod(method)) {
            element.removeProperty(annotation.value());
            return null;
        }

        return null;
    }

}

@@ -36,16 +36,50 @@
 tions;%0A%0A
+import java.lang.reflect.Method;%0A%0A
 import c
@@ -117,46 +117,8 @@
 on;%0A
-import com.tinkerpop.blueprints.Edge;%0A
 impo
@@ -158,48 +158,8 @@
 nt;%0A
-import com.tinkerpop.blueprints.Vertex;%0A
 impo
@@ -282,42 +282,8 @@
 y;%0A%0A
-import java.lang.reflect.Method;%0A%0A
 publ
@@ -714,34 +714,33 @@
 hod)) %7B%0A
-            return
+%09%09%09Object value =
  element
@@ -765,32 +765,140 @@
 ation.value());%0A
+%09%09%09if (method.getReturnType().isEnum())%0A%09%09%09%09return getValueAsEnum(method, value);%0A%09%09%09else%0A%09%09%09%09return value;%0A
         %7D else i
@@ -1093,32 +1093,143 @@
  else %7B%0A
-                
+%09%09%09%09if (value.getClass().isEnum()) %7B%0A%09%09%09%09%09element.setProperty(annotation.value(), ((Enum%3C?%3E) value).name());%0A%09%09%09%09%7D else %7B%0A%09%09%09%09%09
 element.
@@ -1268,28 +1268,25 @@
 value);%0A
-            
+%09%09%09%09%7D%0A%09%09%09
 %7D%0A      
@@ -1484,10 +1484,187 @@
 %0A    %7D%0A%0A
+%09private Enum getValueAsEnum(final Method method, final Object value) %7B%0A%09%09Class%3CEnum%3E en = (Class%3CEnum%3E) method.getReturnType();%0A%09%09return Enum.valueOf(en, value.toString());%0A%09%7D%0A
 %7D%0A

Support enum based properties type.