Unverified Commit 73e0d748 authored by ST-DDT's avatar ST-DDT

Switch to using enum based methods

parent 6ee16a9c
......@@ -185,42 +185,177 @@ void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field) {
printer->Print(" */\n");
}
void WriteFieldGetterDocComment(io::Printer* printer, const FieldDescriptor* field) {
void WriteFieldAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder) {
printer->Print("/**\n");
WriteDocCommentBody(printer, field);
printer->Print(" * <code>$def$</code>\n", "def",
EscapeJavadoc(FirstLineOf(field->DebugString())));
printer->Print(" * @return The $name$.\n", "name", field->camelcase_name());
switch (type) {
case HAZZER:
printer->Print(" * @return Whether the $name$ field is set.\n", "name",
field->camelcase_name());
break;
case GETTER:
printer->Print(" * @return The $name$.\n", "name",
field->camelcase_name());
break;
case SETTER:
printer->Print(" * @param value The $name$ to set.\n", "name",
field->camelcase_name());
break;
case CLEARER:
// Print nothing
break;
// Repeated
case LIST_COUNT:
printer->Print(" * @return The number of $name$(s).\n", "name",
field->camelcase_name());
break;
case LIST_GETTER:
printer->Print(" * @return A list containing the $name$(s).\n", "name",
field->camelcase_name());
break;
case LIST_INDEXED_GETTER:
printer->Print(" * @param index The index of the element to return.\n");
printer->Print(" * @return The $name$(s) at the given index.\n", "name",
field->camelcase_name());
break;
case LIST_INDEXED_SETTER:
printer->Print(" * @param index The index to set the value at.\n");
printer->Print(" * @param value The $name$ to set.\n", "name",
field->camelcase_name());
break;
case LIST_ADDER:
printer->Print(" * @param value The $name$ to add.\n", "name",
field->camelcase_name());
break;
case LIST_MULTI_ADDER:
printer->Print(" * @param values The $name$(s) to add.\n", "name",
field->camelcase_name());
break;
}
if (builder) {
printer->Print(" * @return This builder for chaining.\n");
}
printer->Print(" */\n");
}
void WriteFieldHaserDocComment(io::Printer* printer, const FieldDescriptor* field) {
void WriteFieldEnumValueAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder) {
printer->Print("/**\n");
WriteDocCommentBody(printer, field);
printer->Print(" * <code>$def$</code>\n", "def",
printer->Print(" * <code>$def$</code>\n", "def",
EscapeJavadoc(FirstLineOf(field->DebugString())));
printer->Print(" * @return Whether the $name$ field is set.\n", "name", field->camelcase_name());
switch (type) {
case HAZZER:
// Should never happen
break;
case GETTER:
printer->Print(" * @return The enum value for $name$.\n", "name",
field->camelcase_name());
break;
case SETTER:
printer->Print(" * @param value The enum value for $name$ to set.\n",
"name", field->camelcase_name());
break;
case CLEARER:
// Print nothing
break;
// Repeated
case LIST_COUNT:
// Should never happen
break;
case LIST_GETTER:
printer->Print(" * @return A list containing the enum values for $name$(s).\n",
"name", field->camelcase_name());
break;
case LIST_INDEXED_GETTER:
printer->Print(" * @param index The index of the value to return.\n");
printer->Print(" * @return The enum value of the $name$ at the given index.\n",
"name", field->camelcase_name());
break;
case LIST_INDEXED_SETTER:
printer->Print(" * @param index The index of the value to return.\n");
printer->Print(" * @param value The enum value of the $name$ to set.\n",
"name", field->camelcase_name());
break;
case LIST_ADDER:
printer->Print(" * @param value The enum value of the $name$ to add.\n",
"name", field->camelcase_name());
break;
case LIST_MULTI_ADDER:
printer->Print(" * @param values The enum values of the $name$(s) to add.\n",
"name", field->camelcase_name());
break;
}
if (builder) {
printer->Print(" * @return This builder for chaining.\n");
}
printer->Print(" */\n");
}
void WriteFieldSetterDocComment(io::Printer* printer, const FieldDescriptor* field) {
void WriteFieldStringBytesAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder) {
printer->Print("/**\n");
WriteDocCommentBody(printer, field);
printer->Print(" * <code>$def$</code>\n", "def",
printer->Print(" * <code>$def$</code>\n", "def",
EscapeJavadoc(FirstLineOf(field->DebugString())));
printer->Print(" * @param value The $name$ to set.\n", "name", field->camelcase_name());
printer->Print(" * @return This builder for chaining.\n");
switch (type) {
case HAZZER:
// Should never happen
break;
case GETTER:
printer->Print(" * @return The bytes for $name$.\n", "name",
field->camelcase_name());
break;
case SETTER:
printer->Print(" * @param value The bytes for $name$ to set.\n",
"name", field->camelcase_name());
break;
case CLEARER:
// Print nothing
break;
// Repeated
case LIST_COUNT:
// Should never happen
break;
case LIST_GETTER:
printer->Print(" * @return A list containing the bytes for $name$(s).\n",
"name", field->camelcase_name());
break;
case LIST_INDEXED_GETTER:
printer->Print(" * @param index The index of the value to return.\n");
printer->Print(" * @return The bytes of the $name$ at the given index.\n",
"name", field->camelcase_name());
break;
case LIST_INDEXED_SETTER:
printer->Print(" * @param index The index of the value to return.\n");
printer->Print(" * @param value The bytes of the $name$ to set.\n",
"name", field->camelcase_name());
break;
case LIST_ADDER:
printer->Print(" * @param value The bytes of the $name$ to add.\n",
"name", field->camelcase_name());
break;
case LIST_MULTI_ADDER:
printer->Print(" * @param values The bytes of the $name$(s) to add.\n",
"name", field->camelcase_name());
break;
}
if (builder) {
printer->Print(" * @return This builder for chaining.\n");
}
printer->Print(" */\n");
}
void WriteFieldClearerDocComment(io::Printer* printer, const FieldDescriptor* field) {
printer->Print("/**\n");
WriteDocCommentBody(printer, field);
printer->Print(" * <code>$def$</code>\n", "def",
EscapeJavadoc(FirstLineOf(field->DebugString())));
printer->Print(" * @return This builder for chaining.\n");
printer->Print(" */\n");
}
// Enum
void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_) {
printer->Print("/**\n");
......
......@@ -52,12 +52,36 @@ namespace protobuf {
namespace compiler {
namespace java {
enum FieldAccessorType {
HAZZER,
GETTER,
SETTER,
CLEARER,
// Repeated
LIST_COUNT,
LIST_GETTER,
LIST_INDEXED_GETTER,
LIST_INDEXED_SETTER,
LIST_ADDER,
LIST_MULTI_ADDER
};
void WriteMessageDocComment(io::Printer* printer, const Descriptor* message);
void WriteFieldDocComment(io::Printer* printer, const FieldDescriptor* field);
void WriteFieldGetterDocComment(io::Printer* printer, const FieldDescriptor* field);
void WriteFieldHaserDocComment(io::Printer* printer, const FieldDescriptor* field);
void WriteFieldSetterDocComment(io::Printer* printer, const FieldDescriptor* field);
void WriteFieldClearerDocComment(io::Printer* printer, const FieldDescriptor* field);
void WriteFieldAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder = false);
void WriteFieldEnumValueAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder = false);
void WriteFieldStringBytesAccessorDocComment(io::Printer* printer,
const FieldDescriptor* field,
const FieldAccessorType type,
const bool builder = false);
void WriteEnumDocComment(io::Printer* printer, const EnumDescriptor* enum_);
void WriteEnumValueDocComment(io::Printer* printer,
const EnumValueDescriptor* value);
......
......@@ -144,12 +144,12 @@ void ImmutableMessageFieldGenerator::GenerateInterfaceMembers(
// interface so that builders can choose dynamically to either return a
// message or a nested builder, so that asking for the interface doesn't
// cause a message to ever be built.
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n");
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n");
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldDocComment(printer, descriptor_);
printer->Print(
variables_,
"$deprecation$$type$OrBuilder get$capitalized_name$OrBuilder();\n");
......@@ -161,14 +161,14 @@ void ImmutableMessageFieldGenerator::GenerateMembers(
PrintExtraFieldInfo(variables_, printer);
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(
variables_,
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $get_has_field_bit_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(
variables_,
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
......@@ -185,14 +185,14 @@ void ImmutableMessageFieldGenerator::GenerateMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
} else {
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(
variables_,
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $name$_ != null;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(
variables_,
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
......@@ -261,7 +261,7 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
// field of type "Field" called "Field".
// boolean hasField()
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
if (support_field_presence) {
printer->Print(
variables_,
......@@ -279,14 +279,14 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
}
// Field getField()
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
PrintNestedBuilderFunction(
printer, "$deprecation$public $type$ ${$get$capitalized_name$$}$()",
"return $name$_ == null ? $type$.getDefaultInstance() : $name$_;\n",
"return $name$Builder_.getMessage();\n", NULL);
// Field.Builder setField(Field value)
WriteFieldSetterDocComment(printer, descriptor_);
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(
printer,
"$deprecation$public Builder ${$set$capitalized_name$$}$($type$ value)",
......@@ -303,7 +303,7 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
"return this;\n");
// Field.Builder setField(Field.Builder builderForValue)
WriteFieldSetterDocComment(printer, descriptor_);
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(
printer,
"$deprecation$public Builder ${$set$capitalized_name$$}$(\n"
......@@ -347,7 +347,7 @@ void ImmutableMessageFieldGenerator::GenerateBuilderMembers(
"return this;\n");
// Field.Builder clearField()
WriteFieldClearerDocComment(printer, descriptor_);
WriteFieldDocComment(printer, descriptor_);
PrintNestedBuilderFunction(
printer, "$deprecation$public Builder ${$clear$capitalized_name$$}$()",
......@@ -535,13 +535,13 @@ ImmutableMessageOneofFieldGenerator::~ImmutableMessageOneofFieldGenerator() {}
void ImmutableMessageOneofFieldGenerator::GenerateMembers(
io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
" if ($has_oneof_case_message$) {\n"
......@@ -579,7 +579,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
// field of type "Field" called "Field".
// boolean hasField()
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"$deprecation$public boolean ${$has$capitalized_name$$}$() {\n"
" return $has_oneof_case_message$;\n"
......@@ -587,7 +587,7 @@ void ImmutableMessageOneofFieldGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
// Field getField()
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
PrintNestedBuilderFunction(
printer, "$deprecation$public $type$ ${$get$capitalized_name$$}$()",
......
......@@ -121,9 +121,9 @@ int ImmutableMessageFieldLiteGenerator::GetNumBitsForMessage() const {
void ImmutableMessageFieldLiteGenerator::GenerateInterfaceMembers(
io::Printer* printer) const {
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_, "$deprecation$boolean has$capitalized_name$();\n");
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n");
}
......
......@@ -198,11 +198,11 @@ int ImmutablePrimitiveFieldLiteGenerator::GetNumBitsForMessage() const {
void ImmutablePrimitiveFieldLiteGenerator::GenerateInterfaceMembers(
io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(variables_,
"$deprecation$boolean has$capitalized_name$();\n");
}
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_, "$deprecation$$type$ get$capitalized_name$();\n");
}
......@@ -218,7 +218,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
printer->Print(variables_, "private $field_type$ $name$_;\n");
PrintExtraFieldInfo(variables_, printer);
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(
variables_,
"@java.lang.Override\n"
......@@ -228,7 +228,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
printer->Annotate("{", "}", descriptor_);
}
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
......@@ -236,7 +236,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
"}\n");
printer->Annotate("{", "}", descriptor_);
WriteFieldDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, SETTER);
printer->Print(variables_,
"private void set$capitalized_name$($type$ value) {\n"
"$null_check$"
......@@ -244,7 +244,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
" $name$_ = value;\n"
"}\n");
WriteFieldDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, CLEARER);
printer->Print(variables_,
"private void clear$capitalized_name$() {\n"
" $clear_has_field_bit_message$\n");
......@@ -264,7 +264,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateMembers(
void ImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(
variables_,
"@java.lang.Override\n"
......@@ -274,7 +274,7 @@ void ImmutablePrimitiveFieldLiteGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
......@@ -347,7 +347,7 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateMembers(
io::Printer* printer) const {
PrintExtraFieldInfo(variables_, printer);
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(
variables_,
"@java.lang.Override\n"
......@@ -357,7 +357,7 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateMembers(
printer->Annotate("{", "}", descriptor_);
}
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
......@@ -397,7 +397,7 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateFieldInfo(
void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateBuilderMembers(
io::Printer* printer) const {
if (SupportFieldPresence(descriptor_->file())) {
WriteFieldHaserDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, HAZZER);
printer->Print(
variables_,
"@java.lang.Override\n"
......@@ -407,7 +407,7 @@ void ImmutablePrimitiveOneofFieldLiteGenerator::GenerateBuilderMembers(
printer->Annotate("{", "}", descriptor_);
}
WriteFieldGetterDocComment(printer, descriptor_);
WriteFieldAccessorDocComment(printer, descriptor_, GETTER);
printer->Print(variables_,
"@java.lang.Override\n"
"$deprecation$public $type$ ${$get$capitalized_name$$}$() {\n"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment