diff options
author | Mark Spruiell <mes@zeroc.com> | 2016-08-23 17:28:35 -0700 |
---|---|---|
committer | Mark Spruiell <mes@zeroc.com> | 2016-08-23 17:28:35 -0700 |
commit | e6cbf802f2977d06854a65036a860740e24d3151 (patch) | |
tree | 7e1a19dff8bb864a86da6699d0360c3d703e71c5 /cpp/src/Slice/JavaUtil.h | |
parent | Small .gitignore cleanup (diff) | |
download | ice-e6cbf802f2977d06854a65036a860740e24d3151.tar.bz2 ice-e6cbf802f2977d06854a65036a860740e24d3151.tar.xz ice-e6cbf802f2977d06854a65036a860740e24d3151.zip |
Major changes in Java:
- Moved existing Java mapping sources to java-compat subdirectory
- Added new "Java 8" mapping in java subdirectory
- Significant features of Java 8 mapping:
- All classes in com.zeroc package (e.g., com.zeroc.Ice.Communicator)
- New AMI mapping that uses java.util.concurrent.CompletableFuture
- New AMD mapping that uses java.util.concurrent.CompletionStage
- New mapping for out parameters - "holder" types have been eliminated
- New mapping for optional types that uses JDK classes from java.util
(e.g., java.util.Optional)
- "TIE" classes are no longer supported or necessary; servant classes
now only need to implement a generated interface
- Moved IceGrid GUI to new mapping
- The "Java Compat" mapping is provided only for backward compatibility
to ease migration to Ice 3.7. The Slice compiler supports a new --compat
option to generate code for this mapping. However, users are encouraged
to migrate to the new mapping as soon as possible.
Diffstat (limited to 'cpp/src/Slice/JavaUtil.h')
-rw-r--r-- | cpp/src/Slice/JavaUtil.h | 191 |
1 files changed, 164 insertions, 27 deletions
diff --git a/cpp/src/Slice/JavaUtil.h b/cpp/src/Slice/JavaUtil.h index 6473f406e0e..d9375be077e 100644 --- a/cpp/src/Slice/JavaUtil.h +++ b/cpp/src/Slice/JavaUtil.h @@ -59,11 +59,11 @@ public: virtual void printHeader(); }; -class JavaGenerator : private ::IceUtil::noncopyable +class JavaCompatGenerator : private ::IceUtil::noncopyable { public: - virtual ~JavaGenerator(); + virtual ~JavaCompatGenerator(); // // Validate all metadata in the unit with a "java:" prefix. @@ -74,7 +74,7 @@ public: protected: - JavaGenerator(const std::string&); + JavaCompatGenerator(const std::string&); // // Given the fully-scoped Java class name, create any intermediate @@ -220,33 +220,170 @@ protected: private: - class MetaDataVisitor : public ParserVisitor + std::string _dir; + ::IceUtilInternal::Output* _out; + mutable std::map<std::string, std::string> _filePackagePrefix; +}; + +class JavaGenerator : private ::IceUtil::noncopyable +{ +public: + + virtual ~JavaGenerator(); + + // + // Validate all metadata in the unit with a "java:" prefix. + // + static void validateMetaData(const UnitPtr&); + + void close(); + +protected: + + JavaGenerator(const std::string&); + + // + // Given the fully-scoped Java class name, create any intermediate + // package directories and open the class file, + // + void open(const std::string&, const std::string&); + + ::IceUtilInternal::Output& output() const; + + // + // Check a symbol against any of the Java keywords. If a + // match is found, return the symbol with a leading underscore. + // + std::string fixKwd(const std::string&) const; + + // + // Convert a Slice scoped name into a Java name. + // + std::string convertScopedName(const std::string&, + const std::string& = std::string(), + const std::string& = std::string()) const; + + + // + // Returns the package prefix for a give Slice file. + // + std::string getPackagePrefix(const ContainedPtr&) const; + + // + // Returns the Java package of a Contained entity. + // + std::string getPackage(const ContainedPtr&) const; + + // + // Returns the Java name for a Contained entity. If the optional + // package argument matches the entity's package name, then the + // package is removed from the result. + // + std::string getAbsolute(const ContainedPtr&, + const std::string& = std::string(), + const std::string& = std::string(), + const std::string& = std::string()) const; + + // + // Return the method call necessary to obtain the static type ID for an object type. + // + std::string getStaticId(const TypePtr&, const std::string&) const; + + // + // Determines whether an operation should use the optional mapping. + // + bool useOptionalMapping(const OperationPtr&); + + // + // Returns the optional type corresponding to the given Slice type. + // + std::string getOptionalFormat(const TypePtr&); + + // + // Get the Java name for a type. If an optional scope is provided, + // the scope will be removed from the result if possible. + // + enum TypeMode { - public: - - virtual bool visitUnitStart(const UnitPtr&); - virtual bool visitModuleStart(const ModulePtr&); - virtual void visitClassDecl(const ClassDeclPtr&); - virtual bool visitClassDefStart(const ClassDefPtr&); - virtual bool visitExceptionStart(const ExceptionPtr&); - virtual bool visitStructStart(const StructPtr&); - virtual void visitOperation(const OperationPtr&); - virtual void visitDataMember(const DataMemberPtr&); - virtual void visitSequence(const SequencePtr&); - virtual void visitDictionary(const DictionaryPtr&); - virtual void visitEnum(const EnumPtr&); - virtual void visitConst(const ConstPtr&); - - private: - - StringList getMetaData(const ContainedPtr&); - void validateType(const SyntaxTreeBasePtr&, const StringList&, const std::string&, const std::string&); - void validateGetSet(const SyntaxTreeBasePtr&, const StringList&, const std::string&, const std::string&); - - StringSet _history; + TypeModeIn, + TypeModeOut, + TypeModeMember, + TypeModeReturn }; + std::string typeToString(const TypePtr&, TypeMode, const std::string& = std::string(), + const StringList& = StringList(), bool = true, bool = false, bool = false) const; - friend class JavaGenerator::MetaDataVisitor; + // + // Get the Java object name for a type. For primitive types, this returns the + // Java class type (e.g., Integer). For all other types, this function delegates + // to typeToString. + // + std::string typeToObjectString(const TypePtr&, TypeMode, const std::string& = std::string(), + const StringList& = StringList(), bool = true, bool = false) const; + + // + // Generate code to marshal or unmarshal a type. + // + enum OptionalMode + { + OptionalNone, + OptionalInParam, + OptionalOutParam, + OptionalReturnParam, + OptionalMember + }; + + void writeMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const TypePtr&, OptionalMode, + bool, int, const std::string&, bool, int&, const StringList& = StringList(), + const std::string& patchParams = ""); + + // + // Generate code to marshal or unmarshal a dictionary type. + // + void writeDictionaryMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const DictionaryPtr&, + const std::string&, bool, int&, bool, + const StringList& = StringList()); + + // + // Generate code to marshal or unmarshal a sequence type. + // + void writeSequenceMarshalUnmarshalCode(::IceUtilInternal::Output&, const std::string&, const SequencePtr&, + const std::string&, bool, int&, bool, const StringList& = StringList()); + + // + // Search metadata for an entry with the given prefix and return the entire string. + // + static bool findMetaData(const std::string&, const StringList&, std::string&); + + // + // Get custom type metadata. If metadata is found, the abstract and + // concrete types are extracted and the function returns true. If an + // abstract type is not specified, it is set to an empty string. + // + static bool getTypeMetaData(const StringList&, std::string&, std::string&); + + // + // Determine whether a custom type is defined. The function checks the + // metadata of the type's original definition, as well as any optional + // metadata that typically represents a data member or parameter. + // + static bool hasTypeMetaData(const TypePtr&, const StringList& = StringList()); + + // + // Obtain the concrete and abstract types for a dictionary or sequence type. + // The functions return true if a custom type was defined and false to indicate + // the default mapping was used. + // + bool getDictionaryTypes(const DictionaryPtr&, const std::string&, const StringList&, + std::string&, std::string&, bool) const; + bool getSequenceTypes(const SequencePtr&, const std::string&, const StringList&, std::string&, std::string&, + bool) const; + + virtual JavaOutput* createOutput(); + + static const std::string _getSetMetaData; + +private: std::string _dir; ::IceUtilInternal::Output* _out; |