package io.gitlab.jfronny.gson.compile.processor.adapter; import com.squareup.javapoet.*; import io.gitlab.jfronny.gson.compile.processor.Const; import io.gitlab.jfronny.gson.compile.processor.SerializableClass; import io.gitlab.jfronny.gson.compile.processor.util.valueprocessor.Property; import javax.annotation.processing.Messager; import javax.annotation.processing.ProcessingEnvironment; import javax.lang.model.type.TypeMirror; import javax.lang.model.util.Types; import java.util.*; public abstract class Adapter { protected Property property; protected TypeSpec.Builder klazz; protected List typeVariables; protected Set other; protected TypeMirror type; protected TypeMirror unboxedType; protected CodeBlock.Builder code; protected String argName; protected Messager message; protected Types typeUtils; protected Map options; protected TypeName typeName; public abstract boolean applies(); public abstract void generateWrite(Runnable writeGet); public abstract void generateRead(); public void init(ProcessingEnvironment env) { this.message = env.getMessager(); this.typeUtils = env.getTypeUtils(); this.options = env.getOptions(); } public void hydrate(Property property, TypeSpec.Builder klazz, CodeBlock.Builder code, List typeVariables, Set other) { this.property = property; this.klazz = klazz; this.typeVariables = typeVariables; this.other = other; this.type = property.getType(); this.code = code; try { this.unboxedType = typeUtils.unboxedType(type); } catch (IllegalArgumentException e) { this.unboxedType = type; } this.argName = Const.ARG_PREFIX + this.property.getName(); this.typeName = TypeName.get(type).box(); } public void dehydrate() { this.property = null; this.klazz = null; this.typeVariables = null; this.other = null; this.type = null; this.code = null; this.unboxedType = null; this.argName = null; this.typeName = null; } }