40 lines
1.2 KiB
Java
40 lines
1.2 KiB
Java
package io.gitlab.jfronny.gson.compile.processor.adapter;
|
|
|
|
import com.squareup.javapoet.*;
|
|
import io.gitlab.jfronny.gson.compile.processor.SerializableClass;
|
|
import io.gitlab.jfronny.gson.compile.processor.util.valueprocessor.Property;
|
|
|
|
import java.util.List;
|
|
import java.util.Set;
|
|
|
|
public class OtherSerializableAdapter extends AdapterAdapter {
|
|
private String adapter;
|
|
|
|
@Override
|
|
public boolean applies() {
|
|
return adapter != null;
|
|
}
|
|
|
|
@Override
|
|
protected String createAdapter(String name) {
|
|
return adapter;
|
|
}
|
|
|
|
@Override
|
|
public void hydrate(Property<?> property, TypeSpec.Builder klazz, CodeBlock.Builder code, List<TypeVariableName> typeVariables, Set<SerializableClass> other) {
|
|
super.hydrate(property, klazz, code, typeVariables, other);
|
|
for (SerializableClass adapter : other) {
|
|
if (TypeName.get(adapter.classElement().asType()).equals(typeName)) {
|
|
// Use self-made adapter
|
|
this.adapter = adapter.generatedClassName().toString();
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void dehydrate() {
|
|
super.dehydrate();
|
|
this.adapter = null;
|
|
}
|
|
}
|