Tabnine Logo
ThriftFieldMetadata
Code IndexAdd Tabnine to your IDE (free)

How to use
ThriftFieldMetadata
in
com.facebook.swift.codec.metadata

Best Java code snippets using com.facebook.swift.codec.metadata.ThriftFieldMetadata (Showing top 20 results out of 315)

origin: com.gitee.l0km/common-thrifty

DecoratorThriftFieldMetadata(ThriftFieldMetadata input){
  super(
      input.getId(),
      input.getRequiredness(),
      input.getThriftType(),
      input.getName(),
      input.getType(),
      input.getInjections(),
      input.getConstructorInjection(),
      input.getMethodInjection(),
      input.getExtraction(),
      input.getCoercion());
  // 获取field的类型
  List<ThriftInjection> injections = getInjections();
  checkState(injections.size()>0,"invalid size of injections");
  ThriftInjection injection = injections.get(0);		
  if(injection instanceof ThriftParameterInjection){
    javaType = ((ThriftParameterInjection)injection).getJavaType();
  }else if(injection instanceof ThriftFieldInjection){
    javaType = ((ThriftFieldInjection)injection).getField().getType();
  }else{
    javaType = null;
    // 对于不支持的数据类型无法获取field类型,输出警告
    logger.warning(
        String.format("UNSUPPORED TYPE %s,can't get Java Type. "
            + "(不识别的ThriftInjection实例类型,无法实现requiredness转义)",
        null == injection? null : injection.getClass().getName()));
  }
}
/** 重载方法,实现 requiredness 转义 */
origin: com.gitee.l0km/common-thrifty

try {
  if (field.isWriteOnly()) {
    continue;
    if (field.getRequiredness() == Requiredness.REQUIRED) {
      throw new RuntimeException("required field was not set");
    } else {
  data.put(field.getName(), value);
} catch (Exception e) {
  Throwables.throwIfUnchecked(e);
origin: com.facebook.swift/swift-codec

private static boolean needsCastAfterRead(ThriftFieldMetadata field, Method readMethod)
{
  Class<?> methodReturn = readMethod.getReturnType();
  Class<?> fieldType;
  if (field.getCoercion().isPresent()) {
    fieldType = field.getCoercion().get().getFromThrift().getParameterTypes()[0];
  }
  else {
    fieldType = TypeToken.of(field.getThriftType().getJavaType()).getRawType();
  }
  boolean needsCast = !fieldType.isAssignableFrom(methodReturn);
  return needsCast;
}
origin: com.gitee.l0km/swift-service-parser

/**
 *  {@code Map<String, Type>}形式返回指定方法的参数名列表
 * @param method
 * @return
 */
public static final LinkedHashMap<String, Type> signtureOfMethod(ThriftMethodMetadata method){
  checkNotNull(method,"method is null");
  LinkedHashMap<String, Type> map = Maps.<String,Type>newLinkedHashMap();
  for(ThriftFieldMetadata param:method.getParameters()){
    map.put(param.getName(), param.getThriftType().getJavaType());
  }        
  return map;
}
/**
origin: com.facebook.swift/swift-codec

  private <T> void verifyField(ThriftStructMetadata metadata, int id, String name)
  {
    ThriftFieldMetadata messageField = metadata.getField(id);
    assertNotNull(messageField, "field '" + name + "' is null");
    assertEquals(messageField.getId(), id);
    assertEquals(messageField.getName(), name);
    assertFalse(messageField.isReadOnly());
    assertFalse(messageField.isWriteOnly());

    assertTrue(messageField.getExtraction().isPresent());
    ThriftExtraction extraction = messageField.getExtraction().get();
    assertEquals(extraction.getId(), id);
    assertEquals(extraction.getName(), name);

    assertNotNull(messageField.getInjections());
    assertEquals(messageField.getInjections().size(), 1);
    ThriftInjection injection = messageField.getInjections().get(0);
    assertEquals(injection.getId(), id);
    assertEquals(injection.getName(), name);
  }
}
origin: com.facebook.swift/swift-codec

write.loadConstant(field.getName());
write.loadConstant(field.getId());
FieldDefinition codecField = codecFields.get(field.getId());
if (codecField != null) {
  write.loadThis().getField(codecType, codecField);
  write.ifNullGoto("field_is_null_" + field.getName());
if (field.getCoercion().isPresent()) {
  write.invokeStatic(field.getCoercion().get().getToThrift());
    write.ifNullGoto("field_is_null_" + field.getName());
Method writeMethod = getWriteMethod(field.getThriftType());
if (writeMethod == null) {
  throw new IllegalArgumentException("Unsupported field type " + field.getThriftType().getProtocolType());
  write.gotoLabel("field_end_" + field.getName());
  write.visitLabel("field_is_null_" + field.getName());
  write.visitLabel("field_end_" + field.getName());
origin: com.facebook.swift/swift-codec

@Override
public void write(T instance, TProtocol protocol)
    throws Exception
{
  TProtocolWriter writer = new TProtocolWriter(protocol);
  Short idValue = (Short) getFieldValue(instance, idField.getKey());
  writer.writeStructBegin(metadata.getStructName());
  if (metadataMap.containsKey(idValue)) {
    ThriftFieldMetadata fieldMetadata = metadataMap.get(idValue);
    if (fieldMetadata.isReadOnly() || fieldMetadata.getType() != THRIFT_FIELD) {
      throw new IllegalStateException(format("Field %s is not readable", fieldMetadata.getName()));
    }
    Object fieldValue = getFieldValue(instance, fieldMetadata);
    // write the field
    if (fieldValue != null) {
      @SuppressWarnings("unchecked")
      ThriftCodec<Object> codec = (ThriftCodec<Object>) fields.get(fieldMetadata.getId());
      writer.writeField(fieldMetadata.getName(), fieldMetadata.getId(), codec, fieldValue);
    }
  }
  writer.writeStructEnd();
}
origin: com.facebook.swift/swift-codec

/**
 * Declares a field for each delegate codec
 *
 * @return a map from field id to the codec for the field
 */
private Map<Short, FieldDefinition> declareCodecFields()
{
  Map<Short, FieldDefinition> codecFields = new TreeMap<>();
  for (ThriftFieldMetadata fieldMetadata : metadata.getFields()) {
    if (needsCodec(fieldMetadata)) {
      ThriftCodec<?> codec = codecManager.getCodec(fieldMetadata.getThriftType());
      String fieldName = fieldMetadata.getName() + "Codec";
      FieldDefinition codecField = new FieldDefinition(a(PRIVATE, FINAL), fieldName, type(codec.getClass()));
      classDefinition.addField(codecField);
      codecFields.put(fieldMetadata.getId(), codecField);
      parameters.add(codecField, codec);
    }
  }
  return codecFields;
}
origin: com.facebook.swift/swift-codec

@Override
public void write(T instance, TProtocol protocol)
    throws Exception
{
  TProtocolWriter writer = new TProtocolWriter(protocol);
  writer.writeStructBegin(metadata.getStructName());
  for (ThriftFieldMetadata fieldMetadata : metadata.getFields(THRIFT_FIELD)) {
    // is the field readable?
    if (fieldMetadata.isWriteOnly()) {
      continue;
    }
    // get the field value
    Object fieldValue = getFieldValue(instance, fieldMetadata);
    // write the field
    if (fieldValue != null) {
      @SuppressWarnings("unchecked")
      ThriftCodec<Object> codec = (ThriftCodec<Object>) fields.get(fieldMetadata.getId());
      writer.writeField(fieldMetadata.getName(), fieldMetadata.getId(), codec, fieldValue);
    }
  }
  writer.writeStructEnd();
}
origin: com.gitee.l0km/swift-service-parser

int pcount = 0;
for (ThriftFieldMetadata parameter : method.getParameters()) {
  stream.printf("\tparam %d: %s %s %s\n", pcount++, parameter.getRequiredness(),parameter.getName(),
      parameter.getThriftType().getJavaType());
origin: com.gitee.l0km/common-thrift

try {
  if (field.isWriteOnly()) {
    continue;
    if (field.getRequiredness() == Requiredness.REQUIRED) {
      throw new TProtocolException("required field was not set");
    } else {
  data.put(field.getId(), value);
} catch (Exception e) {
  Throwables.throwIfUnchecked(e);
origin: com.facebook.swift/swift-codec

cases.add(caseStatement(field.getId(), field.getName() + "-inject-field"));
read.visitLabel(field.getName() + "-inject-field");
injectField(read, field, instance, unionData.get(field.getId()));
if (field.getMethodInjection().isPresent()) {
  injectMethod(read, field.getMethodInjection().get(), instance, unionData);
origin: com.facebook.swift/swift-codec

if (field.getConstructorInjection().isPresent()) {
  cases.add(caseStatement(field.getId(), field.getName() + "-id-field"));
if (field.getConstructorInjection().isPresent()) {
  read.visitLabel(field.getName() + "-id-field");
  read.loadVariable("f_" + field.getName());
  read.invokeConstructor(field.getConstructorInjection().get().getConstructor())
      .storeVariable(instance)
      .gotoLabel("instance-ok");
origin: com.gitee.l0km/common-swift-metadata

  @Override
  public Short apply(ThriftFieldMetadata input)
  {
    return input.getId();
  }
}));
origin: com.facebook.swift/swift-codec

protected AbstractReflectionThriftCodec(ThriftCodecManager manager, ThriftStructMetadata metadata)
{
  this.metadata = metadata;
  ImmutableSortedMap.Builder<Short, ThriftCodec<?>> fields = ImmutableSortedMap.naturalOrder();
  for (ThriftFieldMetadata fieldMetadata : metadata.getFields(THRIFT_FIELD)) {
    fields.put(fieldMetadata.getId(), manager.getCodec(fieldMetadata.getThriftType()));
  }
  this.fields = fields.build();
}
origin: com.facebook.swift/swift-generator

private boolean verifyStruct(ThriftType t, boolean quiet)
{
  if (t.getProtocolType() == ThriftProtocolType.ENUM) {
    knownTypes.add(t);
    return true;
  }
  ThriftStructMetadata metadata = t.getStructMetadata();
  boolean ok = true;
  knownTypes.add(t);
  for (ThriftFieldMetadata fieldMetadata: metadata.getFields(FieldKind.THRIFT_FIELD)) {
    if (!recursive && fieldMetadata.isTypeReferenceRecursive()) {
      continue;
    }
    boolean fieldOk = verifyField(fieldMetadata.getThriftType());
    if (!fieldOk) {
      ok = false;
      if (!quiet) {
        LOG.error("Unknown type %s in %s.%s",
             thriftTypeRenderer.toString(fieldMetadata.getThriftType()),
             metadata.getStructName(),
             fieldMetadata.getName());
      }
    }
  }
  if (!ok) {
    knownTypes.remove(t);
  }
  return ok;
}
origin: com.facebook.swift/swift-codec

fieldMetadata = metadataMap.get(data.getKey());
if (fieldMetadata != null && fieldMetadata.getConstructorInjection().isPresent()) {
    ThriftConstructorInjection constructor = fieldMetadata.getConstructorInjection().get();
for (ThriftInjection injection : fieldMetadata.getInjections()) {
  if (injection instanceof ThriftFieldInjection) {
    ThriftFieldInjection fieldInjection = (ThriftFieldInjection) injection;
if (fieldMetadata.getMethodInjection().isPresent()) {
  Object[] parametersValues = new Object[] { data.getValue() };
      fieldMetadata.getMethodInjection().get().getMethod().invoke(instance, parametersValues);
for (ThriftInjection injection : idField.getKey().getInjections()) {
  if (injection instanceof ThriftFieldInjection) {
    ThriftFieldInjection fieldInjection = (ThriftFieldInjection) injection;
origin: com.facebook.swift/swift-codec

cases.add(caseStatement(field.getId(), field.getName() + "-write-field"));
write.visitLabel(field.getName() + "-write-field");
writeField(write, protocol, field);
write.gotoLabel("default-write");
origin: com.facebook.swift/swift-codec

if (field.isReadOnly() || field.getType() != THRIFT_FIELD) {
  reader.skipFieldData();
  continue;
 if (field.getRequiredness() == ThriftField.Requiredness.REQUIRED) {
  throw new TProtocolException("required field was not set");
 } else {
origin: com.facebook.swift/swift-codec

private void injectField(MethodDefinition read, ThriftFieldMetadata field, LocalVariableDefinition instance, LocalVariableDefinition sourceVariable)
{
  for (ThriftInjection injection : field.getInjections()) {
    if (injection instanceof ThriftFieldInjection) {
      ThriftFieldInjection fieldInjection = (ThriftFieldInjection) injection;
      // if field is an Object && field != null
      if (!isProtocolTypeJavaPrimitive(field)) {
        read.loadVariable(sourceVariable)
            .ifNullGoto("field_is_null_" + field.getName());
      }
      // write value
      read.loadVariable(instance)
          .loadVariable(sourceVariable)
          .putField(fieldInjection.getField());
      // else do nothing
      if (!isProtocolTypeJavaPrimitive(field)) {
        read.visitLabel("field_is_null_" + field.getName());
      }
    }
  }
}
com.facebook.swift.codec.metadataThriftFieldMetadata

Javadoc

ThriftFieldMetadata defines a single thrift field including the value extraction and injection points.

Most used methods

  • getId
  • getName
  • getRequiredness
  • getThriftType
  • getConstructorInjection
  • getExtraction
  • getInjections
  • getType
  • isWriteOnly
  • getCoercion
  • getMethodInjection
  • <init>
  • getMethodInjection,
  • <init>,
  • isReadOnly,
  • isTypePredicate,
  • getIdGetter,
  • getIdlAnnotations,
  • isRecursiveReference,
  • isTypeReferenceRecursive

Popular in Java

  • Creating JSON documents from java classes using gson
  • putExtra (Intent)
  • compareTo (BigDecimal)
  • notifyDataSetChanged (ArrayAdapter)
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • Socket (java.net)
    Provides a client-side TCP socket.
  • Format (java.text)
    The base class for all formats. This is an abstract base class which specifies the protocol for clas
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • Handler (java.util.logging)
    A Handler object accepts a logging request and exports the desired messages to a target, for example
  • Loader (org.hibernate.loader)
    Abstract superclass of object loading (and querying) strategies. This class implements useful common
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now