diff options
Diffstat (limited to 'src/google/protobuf/compiler/java/java_field.h')
-rw-r--r-- | src/google/protobuf/compiler/java/java_field.h | 90 |
1 files changed, 77 insertions, 13 deletions
diff --git a/src/google/protobuf/compiler/java/java_field.h b/src/google/protobuf/compiler/java/java_field.h index f5bef7a..db339d5 100644 --- a/src/google/protobuf/compiler/java/java_field.h +++ b/src/google/protobuf/compiler/java/java_field.h @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -35,14 +35,23 @@ #ifndef GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ #define GOOGLE_PROTOBUF_COMPILER_JAVA_FIELD_H__ +#include <map> +#include <memory> #include <string> + #include <google/protobuf/stubs/common.h> #include <google/protobuf/descriptor.h> namespace google { namespace protobuf { + namespace compiler { + namespace java { + class Context; // context.h + class ClassNameResolver; // name_resolver.h + } + } namespace io { - class Printer; // printer.h + class Printer; // printer.h } } @@ -50,46 +59,101 @@ namespace protobuf { namespace compiler { namespace java { -class FieldGenerator { +class ImmutableFieldGenerator { public: - FieldGenerator() {} - virtual ~FieldGenerator(); + ImmutableFieldGenerator() {} + virtual ~ImmutableFieldGenerator(); + virtual int GetNumBitsForMessage() const = 0; + virtual int GetNumBitsForBuilder() const = 0; + virtual void GenerateInterfaceMembers(io::Printer* printer) const = 0; virtual void GenerateMembers(io::Printer* printer) const = 0; virtual void GenerateBuilderMembers(io::Printer* printer) const = 0; virtual void GenerateInitializationCode(io::Printer* printer) const = 0; + virtual void GenerateBuilderClearCode(io::Printer* printer) const = 0; virtual void GenerateMergingCode(io::Printer* printer) const = 0; virtual void GenerateBuildingCode(io::Printer* printer) const = 0; virtual void GenerateParsingCode(io::Printer* printer) const = 0; virtual void GenerateParsingCodeFromPacked(io::Printer* printer) const; + virtual void GenerateParsingDoneCode(io::Printer* printer) const = 0; virtual void GenerateSerializationCode(io::Printer* printer) const = 0; virtual void GenerateSerializedSizeCode(io::Printer* printer) const = 0; + virtual void GenerateFieldBuilderInitializationCode(io::Printer* printer) + const = 0; + + virtual void GenerateEqualsCode(io::Printer* printer) const = 0; + virtual void GenerateHashCode(io::Printer* printer) const = 0; virtual string GetBoxedType() const = 0; private: - GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGenerator); + GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(ImmutableFieldGenerator); }; + // Convenience class which constructs FieldGenerators for a Descriptor. +template<typename FieldGeneratorType> class FieldGeneratorMap { public: - explicit FieldGeneratorMap(const Descriptor* descriptor); + explicit FieldGeneratorMap(const Descriptor* descriptor, + Context* context); ~FieldGeneratorMap(); - const FieldGenerator& get(const FieldDescriptor* field) const; - const FieldGenerator& get_extension(int index) const; + const FieldGeneratorType& get(const FieldDescriptor* field) const; private: const Descriptor* descriptor_; - scoped_array<scoped_ptr<FieldGenerator> > field_generators_; - scoped_array<scoped_ptr<FieldGenerator> > extension_generators_; - - static FieldGenerator* MakeGenerator(const FieldDescriptor* field); + Context* context_; + ClassNameResolver* name_resolver_; + scoped_array<scoped_ptr<FieldGeneratorType> > field_generators_; GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(FieldGeneratorMap); }; +template<typename FieldGeneratorType> +inline const FieldGeneratorType& +FieldGeneratorMap<FieldGeneratorType>::get(const FieldDescriptor* field) const { + GOOGLE_CHECK_EQ(field->containing_type(), descriptor_); + return *field_generators_[field->index()]; +} + +// Instantiate template for mutable and immutable maps. +template<> +FieldGeneratorMap<ImmutableFieldGenerator>:: +FieldGeneratorMap(const Descriptor* descriptor, + Context* context); + +template<> +FieldGeneratorMap<ImmutableFieldGenerator>::~FieldGeneratorMap(); + + +// Field information used in FieldGeneartors. +struct FieldGeneratorInfo { + string name; + string capitalized_name; + string disambiguated_reason; +}; + +// Oneof information used in OneofFieldGeneartors. +struct OneofGeneratorInfo { + string name; + string capitalized_name; +}; + +// Set some common variables used in variable FieldGenerators. +void SetCommonFieldVariables(const FieldDescriptor* descriptor, + const FieldGeneratorInfo* info, + map<string, string>* variables); + +// Set some common oneof variables used in OneofFieldGenerators. +void SetCommonOneofVariables(const FieldDescriptor* descriptor, + const OneofGeneratorInfo* info, + map<string, string>* variables); + +// Print useful comments before a field's accessors. +void PrintExtraFieldInfo(const map<string, string>& variables, + io::Printer* printer); + } // namespace java } // namespace compiler } // namespace protobuf |