Java Code Examples for com.google.protobuf.Descriptors.FieldDescriptor#getDefaultValue()

The following examples show how to use com.google.protobuf.Descriptors.FieldDescriptor#getDefaultValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 2
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 3
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 4
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 5
Source File: GeneratedMessage.java    From 365browser with Apache License 2.0 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 6
Source File: GeneratedMessage.java    From travelguide with Apache License 2.0 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 7
Source File: GeneratedMessage.java    From travelguide with Apache License 2.0 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 8
Source File: GeneratedMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 9
Source File: GeneratedMessage.java    From play-store-api with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Object getField(final FieldDescriptor field) {
  if (field.isExtension()) {
    verifyContainingType(field);
    final Object value = extensions.getField(field);
    if (value == null) {
      if (field.isRepeated()) {
        return Collections.emptyList();
      } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
        // Lacking an ExtensionRegistry, we have no way to determine the
        // extension's real type, so we return a DynamicMessage.
        return DynamicMessage.getDefaultInstance(field.getMessageType());
      } else {
        return field.getDefaultValue();
      }
    } else {
      return value;
    }
  } else {
    return super.getField(field);
  }
}
 
Example 10
Source File: DynamicMessage.java    From travelguide with Apache License 2.0 5 votes vote down vote up
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 11
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.isRepeated()) {
      result = Collections.emptyList();
    } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 12
Source File: DynamicMessage.java    From 365browser with Apache License 2.0 5 votes vote down vote up
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.isRepeated()) {
      result = Collections.emptyList();
    } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 13
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.isRepeated()) {
      result = Collections.emptyList();
    } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 14
Source File: DynamicMessage.java    From travelguide with Apache License 2.0 5 votes vote down vote up
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.isRepeated()) {
      result = Collections.emptyList();
    } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 15
Source File: DynamicMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.isRepeated()) {
      result = Collections.emptyList();
    } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 16
Source File: DynamicMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 17
Source File: DynamicMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.isRepeated()) {
      result = Collections.emptyList();
    } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 18
Source File: DynamicMessage.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 19
Source File: DynamicMessage.java    From play-store-api with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getField(FieldDescriptor field) {
  verifyContainingType(field);
  Object result = fields.getField(field);
  if (result == null) {
    if (field.isRepeated()) {
      result = Collections.emptyList();
    } else if (field.getJavaType() == FieldDescriptor.JavaType.MESSAGE) {
      result = getDefaultInstance(field.getMessageType());
    } else {
      result = field.getDefaultValue();
    }
  }
  return result;
}
 
Example 20
Source File: ProtoGenerator.java    From fuchsia with Apache License 2.0 4 votes vote down vote up
private void generateProtoFromDescriptor(FieldDescriptor descriptor,
                                         Appendable out, String indent, Map<Descriptor, Boolean> descriptors)
        throws IOException {
    out.append(indent);
    if (descriptor.isRequired()) {
        out.append("required ");
    }

    if (descriptor.isOptional()) {
        out.append("optional ");
    }

    if (descriptor.isRepeated()) {
        out.append("repeated ");
    }

    if (descriptor.getType().equals(Type.MESSAGE)) {
        out.append(descriptor.getMessageType().getFullName() + " ");
        Descriptor messageType = descriptor.getMessageType();
        if (descriptors.get(messageType) == null) {
            descriptors.put(messageType, false);
        }
    } else if (descriptor.getType().equals(Type.ENUM)) {
        out.append(descriptor.getEnumType().getFullName() + " ");
    } else {
        out.append(descriptor.getType().toString().toLowerCase() + " ");
    }

    out.append(descriptor.getName() + " = " + descriptor.getNumber());

    if (descriptor.hasDefaultValue()) {
        out.append(" [default = ");
        Object defaultValue = descriptor.getDefaultValue();

        if (defaultValue instanceof EnumValueDescriptor) {
            out.append(((EnumValueDescriptor) defaultValue).getName());
        }

        out.append("]");
    }

    out.append(";\n");
}