001package net.gdface.codegen.thrift.metadata;
002
003import com.facebook.swift.codec.ThriftField.Requiredness;
004import com.facebook.swift.codec.metadata.DecoratorThriftFieldMetadata;
005import com.facebook.swift.codec.metadata.ThriftFieldMetadataUtil;
006import com.google.common.base.Predicate;
007
008import net.gdface.annotation.CodegenRequired;
009
010import static net.gdface.codegen.thrift.metadata.CodegenPreAllocFilter.PREALLOC_FILTER;
011public class CodegenErpcPointerFilter implements Predicate<DecoratorThriftFieldMetadata> {
012        public static final CodegenErpcPointerFilter POINTER_FILTER = new CodegenErpcPointerFilter();
013        public CodegenErpcPointerFilter() {
014        }
015
016        @Override
017        public boolean apply(DecoratorThriftFieldMetadata input) {              
018                if(!PREALLOC_FILTER.apply(input)){
019                        if(!Requiredness.REQUIRED.equals(input.getRequiredness())){
020                                CodegenRequired ann = ThriftFieldMetadataUtil.extractFieldAnnotation(input,CodegenRequired.class);                              
021                                if(ann == null || !ann.value()){
022                                        switch (input.getErpcType().getProtocolType()) {
023                                        case STRING:
024                                                return true;
025                                        case LIST:
026                                        case BINARY:
027                                                return false;
028                                        default:
029                                                return true;
030                                        }
031                                }       
032                        }                       
033                }
034                return false;
035        }
036
037}