gson-compile/gson-compile-processor/src/main/java/io/gitlab/jfronny/gson/compile/processor/adapter/Adapter.java

66 lines
2.2 KiB
Java
Raw Normal View History

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<TypeVariableName> typeVariables;
protected Set<SerializableClass> other;
protected TypeMirror type;
protected TypeMirror unboxedType;
protected CodeBlock.Builder code;
protected String argName;
protected Messager message;
protected Types typeUtils;
protected Map<String, String> options;
2022-11-01 11:38:37 +01:00
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<TypeVariableName> typeVariables, Set<SerializableClass> 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();
2022-11-01 11:38:37 +01:00
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;
2022-11-01 11:38:37 +01:00
this.typeName = null;
}
}