com.appsingularity.postman.compiler.writers.fields.BasicMapFieldWriter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of postman-compiler Show documentation
Show all versions of postman-compiler Show documentation
Easy parceling for Android.
package com.appsingularity.postman.compiler.writers.fields;
import android.support.annotation.NonNull;
import com.appsingularity.postman.compiler.writers.AbsCollectedFieldWriter;
import com.squareup.javapoet.MethodSpec;
import java.util.HashMap;
import javax.lang.model.element.Element;
public class BasicMapFieldWriter extends AbsCollectedFieldWriter {
public BasicMapFieldWriter(@NonNull Element element) {
super(element);
}
@Override
public void writeShipMethod(@NonNull MethodSpec.Builder shipMethod) {
String attr = mElement.getSimpleName().toString();
shipMethod.addStatement("dest.writeMap(source.$L)", attr);
}
@Override
public void writeReceiveMethod(@NonNull MethodSpec.Builder receiveMethod) {
String attr = mElement.getSimpleName().toString();
receiveMethod.addStatement("// Reading target.$L", attr);
receiveMethod.addStatement("target.$L = new $T<>()", attr, HashMap.class);
receiveMethod.addStatement("in.readMap(target.$L, getClass().getClassLoader())", attr);
}
}