java_extension_lite.cc
Go to the documentation of this file.
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
7 // met:
8 //
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
14 // distribution.
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 
32 
39 
40 namespace google {
41 namespace protobuf {
42 namespace compiler {
43 namespace java {
44 
46  const FieldDescriptor* descriptor, Context* context)
47  : descriptor_(descriptor), name_resolver_(context->GetNameResolver()) {
48  if (descriptor_->extension_scope() != NULL) {
49  scope_ =
51  } else {
53  }
54 }
55 
57 
59  std::map<std::string, std::string> vars;
60  const bool kUseImmutableNames = true;
61  InitTemplateVars(descriptor_, scope_, kUseImmutableNames, name_resolver_,
62  &vars);
63  printer->Print(vars, "public static final int $constant_name$ = $number$;\n");
64 
66  if (descriptor_->is_repeated()) {
67  printer->Print(
68  vars,
69  "public static final\n"
70  " com.google.protobuf.GeneratedMessageLite.GeneratedExtension<\n"
71  " $containing_type$,\n"
72  " $type$> $name$ = com.google.protobuf.GeneratedMessageLite\n"
73  " .newRepeatedGeneratedExtension(\n"
74  " $containing_type$.getDefaultInstance(),\n"
75  " $prototype$,\n"
76  " $enum_map$,\n"
77  " $number$,\n"
78  " com.google.protobuf.WireFormat.FieldType.$type_constant$,\n"
79  " $packed$,\n"
80  " $singular_type$.class);\n");
81  } else {
82  printer->Print(
83  vars,
84  "public static final\n"
85  " com.google.protobuf.GeneratedMessageLite.GeneratedExtension<\n"
86  " $containing_type$,\n"
87  " $type$> $name$ = com.google.protobuf.GeneratedMessageLite\n"
88  " .newSingularGeneratedExtension(\n"
89  " $containing_type$.getDefaultInstance(),\n"
90  " $default$,\n"
91  " $prototype$,\n"
92  " $enum_map$,\n"
93  " $number$,\n"
94  " com.google.protobuf.WireFormat.FieldType.$type_constant$,\n"
95  " $singular_type$.class);\n");
96  }
97  printer->Annotate("name", descriptor_);
98 }
99 
101  io::Printer* printer) {
102  return 0;
103 }
104 
106  io::Printer* printer) {
107  printer->Print("registry.add($scope$.$name$);\n", "scope", scope_, "name",
109  return 7;
110 }
111 
112 } // namespace java
113 } // namespace compiler
114 } // namespace protobuf
115 } // namespace google
google::protobuf::io::Printer::Print
void Print(const std::map< std::string, std::string > &variables, const char *text)
Definition: printer.cc:112
google::protobuf::compiler::java::UnderscoresToCamelCaseCheckReserved
std::string UnderscoresToCamelCaseCheckReserved(const FieldDescriptor *field)
Definition: java_helpers.cc:212
java_name_resolver.h
google::protobuf::FieldDescriptor
Definition: src/google/protobuf/descriptor.h:515
java_doc_comment.h
java_helpers.h
NULL
NULL
Definition: test_security_zap.cpp:405
google::protobuf::compiler::java::ImmutableExtensionLiteGenerator::~ImmutableExtensionLiteGenerator
virtual ~ImmutableExtensionLiteGenerator()
Definition: java_extension_lite.cc:56
google::protobuf::compiler::java::Context
Definition: java_context.h:65
google::protobuf::compiler::java::ImmutableExtensionLiteGenerator::name_resolver_
ClassNameResolver * name_resolver_
Definition: java_extension_lite.h:64
google::protobuf::compiler::java::ImmutableExtensionLiteGenerator::descriptor_
const FieldDescriptor * descriptor_
Definition: java_extension_lite.h:63
google::protobuf::compiler::java::WriteFieldDocComment
void WriteFieldDocComment(io::Printer *printer, const FieldDescriptor *field)
Definition: java_doc_comment.cc:175
google::protobuf::compiler::java::ClassNameResolver::GetImmutableClassName
std::string GetImmutableClassName(const DescriptorType *descriptor)
Definition: java_name_resolver.h:88
descriptor
Descriptor * descriptor
Definition: php/ext/google/protobuf/protobuf.h:936
google::protobuf::compiler::java::ImmutableExtensionLiteGenerator::ImmutableExtensionLiteGenerator
ImmutableExtensionLiteGenerator(const FieldDescriptor *descriptor, Context *context)
Definition: java_extension_lite.cc:45
java_extension_lite.h
strutil.h
google::protobuf::FieldDescriptor::file
const FileDescriptor * file() const
google::protobuf::FieldDescriptor::extension_scope
const Descriptor * extension_scope() const
google::protobuf::compiler::java::ImmutableExtensionLiteGenerator::GenerateRegistrationCode
virtual int GenerateRegistrationCode(io::Printer *printer)
Definition: java_extension_lite.cc:105
printer.h
google::protobuf::compiler::java::ExtensionGenerator::InitTemplateVars
static void InitTemplateVars(const FieldDescriptor *descriptor, const std::string &scope, bool immutable, ClassNameResolver *name_resolver, std::map< std::string, std::string > *vars_pointer)
Definition: java_extension.cc:64
google::protobuf::io::Printer::Annotate
void Annotate(const char *varname, const SomeDescriptor *descriptor)
Definition: printer.h:199
google::protobuf::io::Printer
Definition: printer.h:181
java
google::protobuf::compiler::java::ImmutableExtensionLiteGenerator::Generate
virtual void Generate(io::Printer *printer)
Definition: java_extension_lite.cc:58
google::protobuf::compiler::java::ImmutableExtensionLiteGenerator::scope_
std::string scope_
Definition: java_extension_lite.h:65
java_context.h
descriptor_
const Descriptor * descriptor_
Definition: field_comparator_test.cc:56
google::protobuf::compiler::java::ImmutableExtensionLiteGenerator::GenerateNonNestedInitializationCode
virtual int GenerateNonNestedInitializationCode(io::Printer *printer)
Definition: java_extension_lite.cc:100
google::protobuf::FieldDescriptor::is_repeated
bool is_repeated() const
Definition: src/google/protobuf/descriptor.h:2067
compiler
Definition: plugin.pb.cc:22
google
Definition: data_proto2_to_proto3_util.h:11


libaditof
Author(s):
autogenerated on Wed May 21 2025 02:06:54