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

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

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

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.gitee.l0km/common-thrifty

  data.put(field.getName(), value);
} catch (Exception e) {
  Throwables.throwIfUnchecked(e);
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.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-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-thrift

public 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.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

@Test
public void testMatchByJavaNameWithThriftNameOverride()
    throws Exception
{
  ThriftCatalog catalog = readCodecManager.getCatalog();
  ThriftType thriftType = catalog.getThriftType(BonkConstructorNameOverride.class);
  ThriftStructMetadata structMetadata = thriftType.getStructMetadata();
  assertEquals(structMetadata.getField(1).getName(), "myMessage");
  assertEquals(structMetadata.getField(2).getName(), "myType");
  BonkConstructorNameOverride bonk = new BonkConstructorNameOverride("message", 42);
  testRoundTripSerialize(bonk, new TCompactProtocol.Factory());
}
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());
      }
    }
  }
}
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

cases.add(caseStatement(field.getId(), field.getName() + "-inject-field"));
read.visitLabel(field.getName() + "-inject-field");
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

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

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

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

write.loadConstant(field.getName());
  write.ifNullGoto("field_is_null_" + field.getName());
    write.ifNullGoto("field_is_null_" + field.getName());
  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);
  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.facebook.swift/swift-codec

for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
  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)
origin: com.facebook.swift/swift-codec

  LocalVariableDefinition variable = read.addInitializedLocalVariable(
      toParameterizedType(field.getThriftType()),
      "f_" + field.getName()
  );
  structData.put(field.getId(), variable);
List<CaseStatement> cases = new ArrayList<>();
for (ThriftFieldMetadata field : metadata.getFields(THRIFT_FIELD)) {
  cases.add(caseStatement(field.getId(), field.getName() + "-field"));
  read.visitLabel(field.getName() + "-field");
origin: com.facebook.swift/swift-codec

LocalVariableDefinition variable = read.addInitializedLocalVariable(
    toParameterizedType(field.getThriftType()),
    "f_" + field.getName()
);
unionData.put(field.getId(), variable);
cases.add(caseStatement(field.getId(), field.getName() + "-field"));
read.visitLabel(field.getName() + "-field");
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");
com.facebook.swift.codec.metadataThriftFieldMetadatagetName

Popular methods of ThriftFieldMetadata

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

Popular in Java

  • Making http requests using okhttp
  • orElseThrow (Optional)
    Return the contained value, if present, otherwise throw an exception to be created by the provided s
  • scheduleAtFixedRate (ScheduledExecutorService)
  • runOnUiThread (Activity)
  • Font (java.awt)
    The Font class represents fonts, which are used to render text in a visible way. A font provides the
  • Rectangle (java.awt)
    A Rectangle specifies an area in a coordinate space that is enclosed by the Rectangle object's top-
  • IOException (java.io)
    Signals a general, I/O-related error. Error details may be specified when calling the constructor, a
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • NumberFormat (java.text)
    The abstract base class for all number formats. This class provides the interface for formatting and
  • Collection (java.util)
    Collection is the root of the collection hierarchy. It defines operations on data collections and t
  • 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