diff --git a/README.md b/README.md index fd3db5e7a0..96bf318da6 100644 --- a/README.md +++ b/README.md @@ -241,7 +241,7 @@ intention to use the vendored code as advertised by the `vendor` annotation. If no location is specified by the `vendor` annotation, the behavior is defined by the language generator. -The `vendor` annotation is currently only supported by Go and Dart. +The `vendor` annotation is currently only supported by Go, Dart and Java. The example below illustrates how this works. @@ -249,6 +249,7 @@ bar.frugal ("providing" IDL): ```thrift namespace go bar (vendor="github.com/Workiva/my-repo/gen-go/bar") namespace dart bar (vendor="my-repo/gen-go") +namespace java bar (vendor="com.workiva.bar.custom.pkg") struct Struct {} ``` diff --git a/compiler/compiler.go b/compiler/compiler.go index 5da56bb563..9bac00b602 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -127,7 +127,12 @@ func generateFrugalRec(f *parser.Frugal, g generator.ProgramGenerator, generate // Iterate through includes in order to ensure determinism in // generated code. - for _, inclFrugal := range f.OrderedIncludes() { + for _, include := range f.OrderedIncludes() { + // Skip recursive generation if include is marked vendor and use_vendor option is enabled + if _, vendored := include.Annotations.Vendor(); vendored && g.UseVendor() { + continue + } + inclFrugal := f.ParsedIncludes[include.Name] if err := generateFrugalRec(inclFrugal, g, globals.Recurse, lang); err != nil { return err } diff --git a/compiler/generator/dartlang/generator.go b/compiler/generator/dartlang/generator.go index 6d7b695ca7..13c6c9424b 100644 --- a/compiler/generator/dartlang/generator.go +++ b/compiler/generator/dartlang/generator.go @@ -239,7 +239,7 @@ func (g *Generator) addToPubspec(dir string) error { name = namespace.Value } - if g.useVendor() && includesSet[include] { + if g.UseVendor() && includesSet[include] { vendorPath, _ := namespace.Annotations.Vendor() deps[toLibraryName(vendorPath)] = dep{ Hosted: hostedDep{Name: toLibraryName(vendorPath), URL: "https://pub.workiva.org"}, @@ -1867,7 +1867,7 @@ func (g *Generator) generateIncludeImport(include *parser.Include) (string, erro name := include.Name _, vendored := include.Annotations.Vendor() - vendored = vendored && g.useVendor() + vendored = vendored && g.UseVendor() vendorPath := "" if namespace := g.Frugal.NamespaceForInclude(name, lang); namespace != nil { @@ -1911,7 +1911,7 @@ func (g *Generator) useEnums() bool { return useEnums } -func (g *Generator) useVendor() bool { +func (g *Generator) UseVendor() bool { _, ok := g.Options[useVendorOption] return ok } diff --git a/compiler/generator/generator.go b/compiler/generator/generator.go index a5306865f0..06599d434a 100644 --- a/compiler/generator/generator.go +++ b/compiler/generator/generator.go @@ -61,6 +61,7 @@ var Languages = LanguageOptions{ "suppress: suppress @Generated annotations entirely", "async": "Generate async client code using futures", "boxed_primitives": "Generate primitives as the boxed equivalents", + "use_vendor": "Use specified import references for vendored includes and do not generate code for them", }, "dart": Options{ "library_prefix": "Generate code that can be used within an existing library. " + @@ -100,6 +101,9 @@ type ProgramGenerator interface { // DefaultOutputDir returns the default directory for generated code. DefaultOutputDir() string + + // UseVendor returns whether this generator supports using vendored includes + UseVendor() bool } // LanguageGenerator generates source code as implemented for specific @@ -136,6 +140,9 @@ type LanguageGenerator interface { GenerateScopeImports(*os.File, *parser.Scope) error GeneratePublisher(*os.File, *parser.Scope) error GenerateSubscriber(*os.File, *parser.Scope) error + + // UseVendor returns whether this generator instance supports using vendored includes + UseVendor() bool } // GetPackageComponents returns the package string split on dots. @@ -337,3 +344,7 @@ func (o *programGenerator) GetOutputDir(dir string, f *parser.Frugal) string { func (o *programGenerator) DefaultOutputDir() string { return o.LanguageGenerator.DefaultOutputDir() } + +func (o *programGenerator) UseVendor() bool { + return o.LanguageGenerator.UseVendor() +} diff --git a/compiler/generator/golang/generator.go b/compiler/generator/golang/generator.go index 0c2bd98a24..08655234ad 100644 --- a/compiler/generator/golang/generator.go +++ b/compiler/generator/golang/generator.go @@ -1176,7 +1176,7 @@ func (g *Generator) generateIncludeImport(include *parser.Include, pkgPrefix str namespace := g.Frugal.NamespaceForInclude(includeName, lang) _, vendored := include.Annotations.Vendor() - vendored = vendored && g.useVendor() + vendored = vendored && g.UseVendor() vendorPath := "" if namespace != nil { @@ -2258,7 +2258,7 @@ func (g *Generator) generateAsync() bool { return ok } -func (g *Generator) useVendor() bool { +func (g *Generator) UseVendor() bool { _, ok := g.Options[useVendorOption] return ok } diff --git a/compiler/generator/html/generator.go b/compiler/generator/html/generator.go index 6e91a832c5..43e9bf5d90 100644 --- a/compiler/generator/html/generator.go +++ b/compiler/generator/html/generator.go @@ -78,6 +78,10 @@ func (g *Generator) DefaultOutputDir() string { return defaultOutputDir } +func (g *Generator) UseVendor() bool { + return false +} + func (g *Generator) generateStylesheet(file *os.File) error { _, err := file.WriteString(css) return err diff --git a/compiler/generator/java/generator.go b/compiler/generator/java/generator.go index 0791a6fd49..3b08d3ba3f 100644 --- a/compiler/generator/java/generator.go +++ b/compiler/generator/java/generator.go @@ -32,6 +32,7 @@ const ( defaultOutputDir = "gen-java" tab = "\t" generatedAnnotations = "generated_annotations" + useVendorOption = "use_vendor" tabtab = tab + tab tabtabtab = tab + tab + tab tabtabtabtab = tab + tab + tab + tab @@ -292,6 +293,23 @@ func (g *Generator) quote(s string) string { return strconv.Quote(s) } +func (g *Generator) namespaceForInclude(includeName string) string { + if includeName == "" { + return "" + } + + namespace := g.Frugal.NamespaceForInclude(includeName, lang) + if namespace == nil { + return "" + } + + if vendorPath, _ := namespace.Annotations.Vendor(); vendorPath != "" && g.UseVendor() && g.isVendoredInclude(includeName) { + return vendorPath + } + + return namespace.Value +} + func (g *Generator) generateConstantValueRec(t *parser.Type, value interface{}, indent string) (string, string) { underlyingType := g.Frugal.UnderlyingType(t) @@ -307,14 +325,14 @@ func (g *Generator) generateConstantValueRec(t *parser.Type, value interface{}, return "", fmt.Sprintf("%s.%s", idCtx.Enum.Name, idCtx.EnumValue.Name) case parser.IncludeConstant: include := idCtx.Include.Name - if namespace := g.Frugal.NamespaceForInclude(include, lang); namespace != nil { - include = namespace.Value + if namespace := g.namespaceForInclude(include); namespace != "" { + include = namespace } return "", fmt.Sprintf("%s.%sConstants.%s", include, idCtx.Include.Name, idCtx.Constant.Name) case parser.IncludeEnum: include := idCtx.Include.Name - if namespace := g.Frugal.NamespaceForInclude(include, lang); namespace != nil { - include = namespace.Value + if namespace := g.namespaceForInclude(include); namespace != "" { + include = namespace } return "", fmt.Sprintf("%s.%s.%s", include, idCtx.Enum.Name, idCtx.EnumValue.Name) default: @@ -2731,13 +2749,8 @@ func (g *Generator) generateServiceInterface(service *parser.Service, indent str func (g *Generator) getServiceExtendsName(service *parser.Service) string { serviceName := "F" + service.ExtendsService() include := service.ExtendsInclude() - if include != "" { - if namespace := g.Frugal.NamespaceForInclude(include, lang); namespace != nil { - include = namespace.Value - } else { - return serviceName - } - serviceName = include + "." + serviceName + if namespace := g.namespaceForInclude(include); namespace != "" { + serviceName = namespace + "." + serviceName } return serviceName } @@ -3272,13 +3285,20 @@ func containerType(typeName string) string { } } +func (g *Generator) isVendoredInclude(includeName string) bool { + include := g.Frugal.Include(includeName) + if include == nil { + return false + } + _, vendored := include.Annotations.Vendor() + return vendored +} + func (g *Generator) qualifiedTypeName(t *parser.Type) string { param := t.ParamName() include := t.IncludeName() - if include != "" { - if namespace := g.Frugal.NamespaceForInclude(include, lang); namespace != nil { - return fmt.Sprintf("%s.%s", namespace.Value, param) - } + if namespace := g.namespaceForInclude(include); namespace != "" { + return fmt.Sprintf("%s.%s", namespace, param) } return param } @@ -3328,3 +3348,8 @@ func (g *Generator) generateAsync() bool { _, ok := g.Options["async"] return ok } + +func (g *Generator) UseVendor() bool { + _, ok := g.Options[useVendorOption] + return ok +} diff --git a/compiler/generator/python/generator.go b/compiler/generator/python/generator.go index b1c3a1792c..2e65bc2d4d 100644 --- a/compiler/generator/python/generator.go +++ b/compiler/generator/python/generator.go @@ -1564,3 +1564,7 @@ func getAsyncOpt(options map[string]string) concurrencyModel { } return synchronous } + +func (g *Generator) UseVendor() bool { + return false +} diff --git a/compiler/parser/types.go b/compiler/parser/types.go index e7b1726315..fd0b4e6910 100644 --- a/compiler/parser/types.go +++ b/compiler/parser/types.go @@ -101,6 +101,20 @@ type Include struct { Annotations Annotations } +type byIncludeName []Include + +func (s byIncludeName) Len() int { + return len(s) +} + +func (s byIncludeName) Swap(i, j int) { + s[i], s[j] = s[j], s[i] +} + +func (s byIncludeName) Less(i, j int) bool { + return s[i].Name < s[j].Name +} + // Namespace represents an IDL namespace. type Namespace struct { Scope string @@ -689,19 +703,14 @@ func (f *Frugal) ContainsFrugalDefinitions() bool { return len(f.Scopes)+len(f.Services) > 0 } -// OrderedIncludes returns the ParsedIncludes in order, sorted by the include +// OrderedIncludes returns the Includes in order, sorted by the include // name. -func (f *Frugal) OrderedIncludes() []*Frugal { - keys := make([]string, 0, len(f.ParsedIncludes)) - for key := range f.ParsedIncludes { - keys = append(keys, key) - } - sort.Strings(keys) - - includes := make([]*Frugal, 0, len(f.ParsedIncludes)) - for _, key := range keys { - includes = append(includes, f.ParsedIncludes[key]) +func (f *Frugal) OrderedIncludes() []Include { + includes := make([]Include, 0, len(f.Includes)) + for _, include := range f.Includes { + includes = append(includes, *include) } + sort.Sort(byIncludeName(includes)) return includes } diff --git a/test/common_test.go b/test/common_test.go index 67ae32cc1d..c68af40227 100644 --- a/test/common_test.go +++ b/test/common_test.go @@ -121,3 +121,15 @@ func copyFilePair(pair FileComparisonPair) error { _, err = io.Copy(expectedFile, generatedFile) return err } + +func assertFilesNotExist(t *testing.T, filePaths []string) { + for _, fileThatShouldNotExist := range filePaths { + if _, err := os.Stat(fileThatShouldNotExist); !os.IsNotExist(err) { + if err != nil { + t.Errorf("Unexpected error checking for existence on %q: %s", fileThatShouldNotExist, err) + } else { + t.Errorf("Expected %q not to exist, but it did", fileThatShouldNotExist) + } + } + } +} diff --git a/test/dart_test.go b/test/dart_test.go index 9a9dc812f5..72c92f8af2 100644 --- a/test/dart_test.go +++ b/test/dart_test.go @@ -103,6 +103,10 @@ func TestValidDartVendor(t *testing.T) { "expected/dart/include_vendor/f_my_service_service.dart", filepath.Join(outputDir, "include_vendor", "lib", "src", "f_my_service_service.dart"), }, + { + "expected/dart/include_vendor/f_vendored_references.dart", + filepath.Join(outputDir, "include_vendor", "lib", "src", "f_vendored_references.dart"), + }, { "expected/dart/include_vendor/include_vendor.dart", filepath.Join(outputDir, "include_vendor", "lib", "include_vendor.dart"), @@ -147,6 +151,9 @@ func TestValidDartVendorNamespaceTargetGenerate(t *testing.T) { files := []FileComparisonPair{ {"expected/dart/vendor_namespace/vendor_namespace.dart", filepath.Join(outputDir, "vendor_namespace", "lib", "vendor_namespace.dart")}, {"expected/dart/vendor_namespace/f_item.dart", filepath.Join(outputDir, "vendor_namespace", "lib", "src", "f_item.dart")}, + {"expected/dart/vendor_namespace/f_vendored_base_service.dart", filepath.Join(outputDir, "vendor_namespace", "lib", "src", "f_vendored_base_service.dart")}, + {"expected/dart/vendor_namespace/f_vendor_namespace_constants.dart", filepath.Join(outputDir, "vendor_namespace", "lib", "src", "f_vendor_namespace_constants.dart")}, + {"expected/dart/vendor_namespace/f_my_enum.dart", filepath.Join(outputDir, "vendor_namespace", "lib", "src", "f_my_enum.dart")}, } copyAllFiles(t, files) compareAllFiles(t, files) diff --git a/test/expected/dart/include_vendor/f_my_service_service.dart b/test/expected/dart/include_vendor/f_my_service_service.dart index b856fd672d..2441ae17f9 100644 --- a/test/expected/dart/include_vendor/f_my_service_service.dart +++ b/test/expected/dart/include_vendor/f_my_service_service.dart @@ -15,16 +15,17 @@ import 'package:excepts/excepts.dart' as t_excepts; import 'package:include_vendor/include_vendor.dart' as t_include_vendor; -abstract class FMyService { +abstract class FMyService extends t_vendor_namespace.FVendoredBase { Future getItem(frugal.FContext ctx); } -class FMyServiceClient implements FMyService { +class FMyServiceClient extends t_vendor_namespace.FVendoredBaseClient implements FMyService { static final logging.Logger _frugalLog = new logging.Logger('MyService'); Map _methods; - FMyServiceClient(frugal.FServiceProvider provider, [List middleware]) { + FMyServiceClient(frugal.FServiceProvider provider, [List middleware]) + : super(provider, middleware) { _transport = provider.transport; _protocolFactory = provider.protocolFactory; var combined = middleware ?? []; diff --git a/test/expected/dart/include_vendor/f_vendored_references.dart b/test/expected/dart/include_vendor/f_vendored_references.dart new file mode 100644 index 0000000000..1fc3a2ad19 --- /dev/null +++ b/test/expected/dart/include_vendor/f_vendored_references.dart @@ -0,0 +1,207 @@ +// Autogenerated by Frugal Compiler (2.20.0) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +import 'dart:typed_data' show Uint8List; +import 'package:thrift/thrift.dart' as thrift; +import 'package:include_vendor/include_vendor.dart' as t_include_vendor; +import 'package:some_vendored_place/vendor_namespace.dart' as t_vendor_namespace; +import 'package:excepts/excepts.dart' as t_excepts; + +class VendoredReferences implements thrift.TBase { + static final thrift.TStruct _STRUCT_DESC = new thrift.TStruct("VendoredReferences"); + static final thrift.TField _REFERENCE_VENDORED_CONST_FIELD_DESC = new thrift.TField("reference_vendored_const", thrift.TType.I32, 1); + static final thrift.TField _REFERENCE_VENDORED_ENUM_FIELD_DESC = new thrift.TField("reference_vendored_enum", thrift.TType.I32, 2); + + int _reference_vendored_const; + static const int REFERENCE_VENDORED_CONST = 1; + int _reference_vendored_enum; + static const int REFERENCE_VENDORED_ENUM = 2; + + bool __isset_reference_vendored_const = false; + bool __isset_reference_vendored_enum = false; + + VendoredReferences() { + this.reference_vendored_const = t_vendor_namespace.VendorNamespaceConstants.a_const; + this.reference_vendored_enum = t_vendor_namespace.MyEnum.TWO; + } + + int get reference_vendored_const => this._reference_vendored_const; + + set reference_vendored_const(int reference_vendored_const) { + this._reference_vendored_const = reference_vendored_const; + this.__isset_reference_vendored_const = true; + } + + bool isSetReference_vendored_const() => this.__isset_reference_vendored_const; + + unsetReference_vendored_const() { + this.__isset_reference_vendored_const = false; + } + + int get reference_vendored_enum => this._reference_vendored_enum; + + set reference_vendored_enum(int reference_vendored_enum) { + this._reference_vendored_enum = reference_vendored_enum; + this.__isset_reference_vendored_enum = true; + } + + bool isSetReference_vendored_enum() => this.__isset_reference_vendored_enum; + + unsetReference_vendored_enum() { + this.__isset_reference_vendored_enum = false; + } + + getFieldValue(int fieldID) { + switch (fieldID) { + case REFERENCE_VENDORED_CONST: + return this.reference_vendored_const; + case REFERENCE_VENDORED_ENUM: + return this.reference_vendored_enum; + default: + throw new ArgumentError("Field $fieldID doesn't exist!"); + } + } + + setFieldValue(int fieldID, Object value) { + switch(fieldID) { + case REFERENCE_VENDORED_CONST: + if(value == null) { + unsetReference_vendored_const(); + } else { + this.reference_vendored_const = value as int; + } + break; + + case REFERENCE_VENDORED_ENUM: + if(value == null) { + unsetReference_vendored_enum(); + } else { + this.reference_vendored_enum = value as int; + } + break; + + default: + throw new ArgumentError("Field $fieldID doesn't exist!"); + } + } + + // Returns true if the field corresponding to fieldID is set (has been assigned a value) and false otherwise + bool isSet(int fieldID) { + switch(fieldID) { + case REFERENCE_VENDORED_CONST: + return isSetReference_vendored_const(); + case REFERENCE_VENDORED_ENUM: + return isSetReference_vendored_enum(); + default: + throw new ArgumentError("Field $fieldID doesn't exist!"); + } + } + + read(thrift.TProtocol iprot) { + thrift.TField field; + iprot.readStructBegin(); + while(true) { + field = iprot.readFieldBegin(); + if(field.type == thrift.TType.STOP) { + break; + } + switch(field.id) { + case REFERENCE_VENDORED_CONST: + if(field.type == thrift.TType.I32) { + reference_vendored_const = iprot.readI32(); + this.__isset_reference_vendored_const = true; + } else { + thrift.TProtocolUtil.skip(iprot, field.type); + } + break; + case REFERENCE_VENDORED_ENUM: + if(field.type == thrift.TType.I32) { + reference_vendored_enum = iprot.readI32(); + this.__isset_reference_vendored_enum = true; + } else { + thrift.TProtocolUtil.skip(iprot, field.type); + } + break; + default: + thrift.TProtocolUtil.skip(iprot, field.type); + break; + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + validate(); + } + + write(thrift.TProtocol oprot) { + validate(); + + oprot.writeStructBegin(_STRUCT_DESC); + if(isSetReference_vendored_const()) { + oprot.writeFieldBegin(_REFERENCE_VENDORED_CONST_FIELD_DESC); + oprot.writeI32(reference_vendored_const); + oprot.writeFieldEnd(); + } + if(isSetReference_vendored_enum()) { + oprot.writeFieldBegin(_REFERENCE_VENDORED_ENUM_FIELD_DESC); + oprot.writeI32(reference_vendored_enum); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + String toString() { + StringBuffer ret = new StringBuffer("VendoredReferences("); + + if(isSetReference_vendored_const()) { + ret.write("reference_vendored_const:"); + ret.write(this.reference_vendored_const); + } + + if(isSetReference_vendored_enum()) { + ret.write(", "); + ret.write("reference_vendored_enum:"); + String reference_vendored_enum_name = t_vendor_namespace.MyEnum.VALUES_TO_NAMES[this.reference_vendored_enum]; + if(reference_vendored_enum_name != null) { + ret.write(reference_vendored_enum_name); + ret.write(" ("); + } + ret.write(this.reference_vendored_enum); + if(reference_vendored_enum_name != null) { + ret.write(")"); + } + } + + ret.write(")"); + + return ret.toString(); + } + + bool operator ==(Object o) { + if(o == null || !(o is VendoredReferences)) { + return false; + } + VendoredReferences other = o as VendoredReferences; + return this.reference_vendored_const == other.reference_vendored_const + && this.reference_vendored_enum == other.reference_vendored_enum; + } + + VendoredReferences clone({ + int reference_vendored_const: null, + int reference_vendored_enum: null, + }) { + return new VendoredReferences() + ..reference_vendored_const = reference_vendored_const ?? this.reference_vendored_const + ..reference_vendored_enum = reference_vendored_enum ?? this.reference_vendored_enum; + } + + validate() { + // check for required fields + // check that fields of type enum have valid values + if(isSetReference_vendored_enum() && !t_vendor_namespace.MyEnum.VALID_VALUES.contains(reference_vendored_enum)) { + throw new thrift.TProtocolError(thrift.TProtocolErrorType.INVALID_DATA, "The field 'reference_vendored_enum' has been assigned the invalid value $reference_vendored_enum"); + } + } +} diff --git a/test/expected/dart/include_vendor/include_vendor.dart b/test/expected/dart/include_vendor/include_vendor.dart index 6270b00ccd..8f83d64702 100644 --- a/test/expected/dart/include_vendor/include_vendor.dart +++ b/test/expected/dart/include_vendor/include_vendor.dart @@ -3,6 +3,7 @@ library include_vendor; +export 'src/f_vendored_references.dart' show VendoredReferences; export 'src/f_my_service_service.dart' show FMyService; export 'src/f_my_service_service.dart' show FMyServiceClient; diff --git a/test/expected/dart/vendor_namespace/f_my_enum.dart b/test/expected/dart/vendor_namespace/f_my_enum.dart new file mode 100644 index 0000000000..1226634b7c --- /dev/null +++ b/test/expected/dart/vendor_namespace/f_my_enum.dart @@ -0,0 +1,17 @@ +// Autogenerated by Frugal Compiler (2.20.0) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +class MyEnum { + static const int ZERO = 0; + static const int TWO = 2; + + static final Set VALID_VALUES = new Set.from([ + ZERO, + TWO, + ]); + + static final Map VALUES_TO_NAMES = { + ZERO: 'ZERO', + TWO: 'TWO', + }; +} diff --git a/test/expected/dart/vendor_namespace/f_vendor_namespace_constants.dart b/test/expected/dart/vendor_namespace/f_vendor_namespace_constants.dart new file mode 100644 index 0000000000..3151526f8b --- /dev/null +++ b/test/expected/dart/vendor_namespace/f_vendor_namespace_constants.dart @@ -0,0 +1,12 @@ +// Autogenerated by Frugal Compiler (2.20.0) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +import 'dart:typed_data' show Uint8List; +import 'package:thrift/thrift.dart' as thrift; +import 'package:vendor_namespace/vendor_namespace.dart' as t_vendor_namespace; + +import 'dart:convert' show UTF8; + +class VendorNamespaceConstants { + static final int a_const = 1; +} diff --git a/test/expected/dart/vendor_namespace/f_vendored_base_service.dart b/test/expected/dart/vendor_namespace/f_vendored_base_service.dart new file mode 100644 index 0000000000..c7bd7ddfb8 --- /dev/null +++ b/test/expected/dart/vendor_namespace/f_vendored_base_service.dart @@ -0,0 +1,35 @@ +// Autogenerated by Frugal Compiler (2.20.0) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + + + +import 'dart:async'; + +import 'dart:typed_data' show Uint8List; +import 'package:logging/logging.dart' as logging; +import 'package:thrift/thrift.dart' as thrift; +import 'package:frugal/frugal.dart' as frugal; + +import 'package:vendor_namespace/vendor_namespace.dart' as t_vendor_namespace; + + +abstract class FVendoredBase { +} + +class FVendoredBaseClient implements FVendoredBase { + static final logging.Logger _frugalLog = new logging.Logger('VendoredBase'); + Map _methods; + + FVendoredBaseClient(frugal.FServiceProvider provider, [List middleware]) { + _transport = provider.transport; + _protocolFactory = provider.protocolFactory; + var combined = middleware ?? []; + combined.addAll(provider.middleware); + this._methods = {}; + } + + frugal.FTransport _transport; + frugal.FProtocolFactory _protocolFactory; + +} + diff --git a/test/expected/dart/vendor_namespace/vendor_namespace.dart b/test/expected/dart/vendor_namespace/vendor_namespace.dart index 11c479601c..9c54466f5c 100644 --- a/test/expected/dart/vendor_namespace/vendor_namespace.dart +++ b/test/expected/dart/vendor_namespace/vendor_namespace.dart @@ -3,5 +3,9 @@ library vendor_namespace; +export 'src/f_vendor_namespace_constants.dart' show VendorNamespaceConstants; export 'src/f_item.dart' show Item; +export 'src/f_my_enum.dart' show MyEnum; +export 'src/f_vendored_base_service.dart' show FVendoredBase; +export 'src/f_vendored_base_service.dart' show FVendoredBaseClient; diff --git a/test/expected/go/vendor/f_myservice_service.txt b/test/expected/go/vendor/f_myservice_service.txt index 2b2cf06277..0bd27f264c 100644 --- a/test/expected/go/vendor/f_myservice_service.txt +++ b/test/expected/go/vendor/f_myservice_service.txt @@ -21,10 +21,13 @@ var _ = bytes.Equal var _ = logrus.DebugLevel type FMyService interface { + vendor_namespace.FVendoredBase + GetItem(ctx frugal.FContext) (r *vendor_namespace.Item, err error) } type FMyServiceClient struct { + *vendor_namespace.FVendoredBaseClient transport frugal.FTransport protocolFactory *frugal.FProtocolFactory methods map[string]*frugal.Method @@ -33,9 +36,10 @@ type FMyServiceClient struct { func NewFMyServiceClient(provider *frugal.FServiceProvider, middleware ...frugal.ServiceMiddleware) *FMyServiceClient { methods := make(map[string]*frugal.Method) client := &FMyServiceClient{ - transport: provider.GetTransport(), - protocolFactory: provider.GetProtocolFactory(), - methods: methods, + FVendoredBaseClient: vendor_namespace.NewFVendoredBaseClient(provider, middleware...), + transport: provider.GetTransport(), + protocolFactory: provider.GetProtocolFactory(), + methods: methods, } middleware = append(middleware, provider.GetMiddleware()...) methods["getItem"] = frugal.NewMethod(client, client.getItem, "getItem", middleware) @@ -129,11 +133,11 @@ func (f *FMyServiceClient) getItem(ctx frugal.FContext) (r *vendor_namespace.Ite } type FMyServiceProcessor struct { - *frugal.FBaseProcessor + *vendor_namespace.FVendoredBaseProcessor } func NewFMyServiceProcessor(handler FMyService, middleware ...frugal.ServiceMiddleware) *FMyServiceProcessor { - p := &FMyServiceProcessor{frugal.NewFBaseProcessor()} + p := &FMyServiceProcessor{vendor_namespace.NewFVendoredBaseProcessor(handler, middleware...)} p.AddToProcessorMap("getItem", &myserviceFGetItem{frugal.NewFBaseProcessorFunction(p.GetWriteMutex(), frugal.NewMethod(handler, handler.GetItem, "GetItem", middleware))}) return p } diff --git a/test/expected/go/vendor/f_types.txt b/test/expected/go/vendor/f_types.txt index 1f939e7b5e..932aabdad2 100644 --- a/test/expected/go/vendor/f_types.txt +++ b/test/expected/go/vendor/f_types.txt @@ -23,3 +23,147 @@ var GoUnusedProtection__ int func init() { } + +type VendoredReferences struct { + ReferenceVendoredConst int32 `thrift:"reference_vendored_const,1" db:"reference_vendored_const" json:"reference_vendored_const,omitempty"` + ReferenceVendoredEnum vendor_namespace.MyEnum `thrift:"reference_vendored_enum,2" db:"reference_vendored_enum" json:"reference_vendored_enum,omitempty"` +} + +func NewVendoredReferences() *VendoredReferences { + return &VendoredReferences{ + ReferenceVendoredConst: vendor_namespace.AConst, + ReferenceVendoredEnum: vendor_namespace.MyEnum_TWO, + } +} + +var VendoredReferences_ReferenceVendoredConst_DEFAULT int32 = vendor_namespace.AConst + +func (p *VendoredReferences) IsSetReferenceVendoredConst() bool { + return p.ReferenceVendoredConst != VendoredReferences_ReferenceVendoredConst_DEFAULT +} + +func (p *VendoredReferences) GetReferenceVendoredConst() int32 { + return p.ReferenceVendoredConst +} + +var VendoredReferences_ReferenceVendoredEnum_DEFAULT vendor_namespace.MyEnum = vendor_namespace.MyEnum_TWO + +func (p *VendoredReferences) IsSetReferenceVendoredEnum() bool { + return p.ReferenceVendoredEnum != VendoredReferences_ReferenceVendoredEnum_DEFAULT +} + +func (p *VendoredReferences) GetReferenceVendoredEnum() vendor_namespace.MyEnum { + return p.ReferenceVendoredEnum +} + +func (p *VendoredReferences) Read(iprot thrift.TProtocol) error { + if _, err := iprot.ReadStructBegin(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) + } + + for { + _, fieldTypeId, fieldId, err := iprot.ReadFieldBegin() + if err != nil { + return thrift.PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err) + } + if fieldTypeId == thrift.STOP { + break + } + switch fieldId { + case 1: + if err := p.ReadField1(iprot); err != nil { + return err + } + case 2: + if err := p.ReadField2(iprot); err != nil { + return err + } + default: + if err := iprot.Skip(fieldTypeId); err != nil { + return err + } + } + if err := iprot.ReadFieldEnd(); err != nil { + return err + } + } + if err := iprot.ReadStructEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T read struct end error: ", p), err) + } + return nil +} + +func (p *VendoredReferences) ReadField1(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 1: ", err) + } else { + p.ReferenceVendoredConst = v + } + return nil +} + +func (p *VendoredReferences) ReadField2(iprot thrift.TProtocol) error { + if v, err := iprot.ReadI32(); err != nil { + return thrift.PrependError("error reading field 2: ", err) + } else { + temp := vendor_namespace.MyEnum(v) + p.ReferenceVendoredEnum = temp + } + return nil +} + +func (p *VendoredReferences) Write(oprot thrift.TProtocol) error { + if err := oprot.WriteStructBegin("VendoredReferences"); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) + } + if err := p.writeField1(oprot); err != nil { + return err + } + if err := p.writeField2(oprot); err != nil { + return err + } + if err := oprot.WriteFieldStop(); err != nil { + return thrift.PrependError("write field stop error: ", err) + } + if err := oprot.WriteStructEnd(); err != nil { + return thrift.PrependError("write struct stop error: ", err) + } + return nil +} + +func (p *VendoredReferences) writeField1(oprot thrift.TProtocol) error { + if p.IsSetReferenceVendoredConst() { + if err := oprot.WriteFieldBegin("reference_vendored_const", thrift.I32, 1); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 1:reference_vendored_const: ", p), err) + } + if err := oprot.WriteI32(int32(p.ReferenceVendoredConst)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.reference_vendored_const (1) field write error: ", p), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 1:reference_vendored_const: ", p), err) + } + } + return nil +} + +func (p *VendoredReferences) writeField2(oprot thrift.TProtocol) error { + if p.IsSetReferenceVendoredEnum() { + if err := oprot.WriteFieldBegin("reference_vendored_enum", thrift.I32, 2); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 2:reference_vendored_enum: ", p), err) + } + if err := oprot.WriteI32(int32(p.ReferenceVendoredEnum)); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.reference_vendored_enum (2) field write error: ", p), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 2:reference_vendored_enum: ", p), err) + } + } + return nil +} + +func (p *VendoredReferences) String() string { + if p == nil { + return "" + } + return fmt.Sprintf("VendoredReferences(%+v)", *p) +} diff --git a/test/expected/go/vendor_namespace/f_types.txt b/test/expected/go/vendor_namespace/f_types.txt index 86ffe506f9..db44770a02 100644 --- a/test/expected/go/vendor_namespace/f_types.txt +++ b/test/expected/go/vendor_namespace/f_types.txt @@ -5,6 +5,8 @@ package vendor_namespace import ( "bytes" + "database/sql/driver" + "errors" "fmt" "git.apache.org/thrift.git/lib/go/thrift" @@ -17,9 +19,67 @@ var _ = bytes.Equal var GoUnusedProtection__ int +const AConst = 1 + func init() { } +type MyEnum int64 + +const ( + MyEnum_ZERO MyEnum = 0 + MyEnum_TWO MyEnum = 2 +) + +func (p MyEnum) String() string { + switch p { + case MyEnum_ZERO: + return "ZERO" + case MyEnum_TWO: + return "TWO" + } + return "" +} + +func MyEnumFromString(s string) (MyEnum, error) { + switch s { + case "ZERO": + return MyEnum_ZERO, nil + case "TWO": + return MyEnum_TWO, nil + } + return MyEnum(0), fmt.Errorf("not a valid MyEnum string") +} + +func (p MyEnum) MarshalText() ([]byte, error) { + return []byte(p.String()), nil +} + +func (p *MyEnum) UnmarshalText(text []byte) error { + q, err := MyEnumFromString(string(text)) + if err != nil { + return err + } + *p = q + return nil +} + +func (p *MyEnum) Scan(value interface{}) error { + v, ok := value.(int64) + if !ok { + return errors.New("Scan value is not int64") + } + *p = MyEnum(v) + return nil +} + +func (p *MyEnum) Value() (driver.Value, error) { + if p == nil { + return nil, nil + } + return int64(*p), nil +} + type Item struct { } diff --git a/test/expected/go/vendor_namespace/f_vendoredbase_service.txt b/test/expected/go/vendor_namespace/f_vendoredbase_service.txt new file mode 100644 index 0000000000..04377dada4 --- /dev/null +++ b/test/expected/go/vendor_namespace/f_vendoredbase_service.txt @@ -0,0 +1,58 @@ +// Autogenerated by Frugal Compiler (2.20.0) +// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + +package vendor_namespace + +import ( + "bytes" + "fmt" + + "git.apache.org/thrift.git/lib/go/thrift" + "github.com/Sirupsen/logrus" + "github.com/Workiva/frugal/lib/go" +) + +// (needed to ensure safety because of naive import list construction.) +var _ = thrift.ZERO +var _ = fmt.Printf +var _ = bytes.Equal +var _ = logrus.DebugLevel + +type FVendoredBase interface { +} + +type FVendoredBaseClient struct { + transport frugal.FTransport + protocolFactory *frugal.FProtocolFactory + methods map[string]*frugal.Method +} + +func NewFVendoredBaseClient(provider *frugal.FServiceProvider, middleware ...frugal.ServiceMiddleware) *FVendoredBaseClient { + methods := make(map[string]*frugal.Method) + client := &FVendoredBaseClient{ + transport: provider.GetTransport(), + protocolFactory: provider.GetProtocolFactory(), + methods: methods, + } + middleware = append(middleware, provider.GetMiddleware()...) + return client +} + +type FVendoredBaseProcessor struct { + *frugal.FBaseProcessor +} + +func NewFVendoredBaseProcessor(handler FVendoredBase, middleware ...frugal.ServiceMiddleware) *FVendoredBaseProcessor { + p := &FVendoredBaseProcessor{frugal.NewFBaseProcessor()} + return p +} + +func vendoredbaseWriteApplicationError(ctx frugal.FContext, oprot *frugal.FProtocol, type_ int32, method, message string) error { + x := thrift.NewTApplicationException(type_, message) + oprot.WriteResponseHeader(ctx) + oprot.WriteMessageBegin(method, thrift.EXCEPTION, 0) + x.Write(oprot) + oprot.WriteMessageEnd() + oprot.Flush() + return x +} diff --git a/test/expected/java/valid_vendor/FMyService.java b/test/expected/java/valid_vendor/FMyService.java new file mode 100644 index 0000000000..3cd798a7c7 --- /dev/null +++ b/test/expected/java/valid_vendor/FMyService.java @@ -0,0 +1,931 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.exception.TTransportExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.processor.FBaseProcessor; +import com.workiva.frugal.processor.FProcessor; +import com.workiva.frugal.processor.FProcessorFunction; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FServiceProvider; +import com.workiva.frugal.transport.FTransport; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TMessage; +import org.apache.thrift.protocol.TMessageType; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import javax.annotation.Generated; +import java.util.Arrays; +import java.util.concurrent.*; + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class FMyService { + + private static final Logger logger = LoggerFactory.getLogger(FMyService.class); + + public interface Iface extends some.vendored.pkg.FVendoredBase.Iface { + + public some.vendored.pkg.Item getItem(FContext ctx) throws TException, InvalidData; + + } + + public static class Client extends some.vendored.pkg.FVendoredBase.Client implements Iface { + + private Iface proxy; + + public Client(FServiceProvider provider, ServiceMiddleware... middleware) { + super(provider, middleware); + Iface client = new InternalClient(provider); + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + middleware = combined.toArray(new ServiceMiddleware[0]); + proxy = InvocationHandler.composeMiddleware(client, Iface.class, middleware); + } + + public some.vendored.pkg.Item getItem(FContext ctx) throws TException, InvalidData { + return proxy.getItem(ctx); + } + + } + + private static class InternalClient extends some.vendored.pkg.FVendoredBase.Client implements Iface { + + private FTransport transport; + private FProtocolFactory protocolFactory; + public InternalClient(FServiceProvider provider) { + super(provider); + this.transport = provider.getTransport(); + this.protocolFactory = provider.getProtocolFactory(); + } + + public some.vendored.pkg.Item getItem(FContext ctx) throws TException, InvalidData { + TMemoryOutputBuffer memoryBuffer = new TMemoryOutputBuffer(this.transport.getRequestSizeLimit()); + FProtocol oprot = this.protocolFactory.getProtocol(memoryBuffer); + oprot.writeRequestHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.CALL, 0)); + getItem_args args = new getItem_args(); + args.write(oprot); + oprot.writeMessageEnd(); + TTransport response = this.transport.request(ctx, memoryBuffer.getWriteBytes()); + + FProtocol iprot = this.protocolFactory.getProtocol(response); + iprot.readResponseHeader(ctx); + TMessage message = iprot.readMessageBegin(); + if (!message.name.equals("getItem")) { + throw new TApplicationException(TApplicationExceptionType.WRONG_METHOD_NAME, "getItem failed: wrong method name"); + } + if (message.type == TMessageType.EXCEPTION) { + TApplicationException e = TApplicationException.read(iprot); + iprot.readMessageEnd(); + TException returnedException = e; + if (e.getType() == TApplicationExceptionType.RESPONSE_TOO_LARGE) { + returnedException = new TTransportException(TTransportExceptionType.RESPONSE_TOO_LARGE, e.getMessage()); + } + throw returnedException; + } + if (message.type != TMessageType.REPLY) { + throw new TApplicationException(TApplicationExceptionType.INVALID_MESSAGE_TYPE, "getItem failed: invalid message type"); + } + getItem_result res = new getItem_result(); + res.read(iprot); + iprot.readMessageEnd(); + if (res.isSetSuccess()) { + return res.success; + } + if (res.d != null) { + throw res.d; + } + throw new TApplicationException(TApplicationExceptionType.MISSING_RESULT, "getItem failed: unknown result"); + } + } + + public static class Processor extends some.vendored.pkg.FVendoredBase.Processor implements FProcessor { + + private Iface handler; + + public Processor(Iface iface, ServiceMiddleware... middleware) { + super(iface, middleware); + handler = InvocationHandler.composeMiddleware(iface, Iface.class, middleware); + } + + protected java.util.Map getProcessMap() { + java.util.Map processMap = super.getProcessMap(); + processMap.put("getItem", new GetItem()); + return processMap; + } + + protected java.util.Map> getAnnotationsMap() { + java.util.Map> annotationsMap = super.getAnnotationsMap(); + return annotationsMap; + } + + @Override + public void addMiddleware(ServiceMiddleware middleware) { + super.addMiddleware(middleware); + handler = InvocationHandler.composeMiddleware(handler, Iface.class, new ServiceMiddleware[]{middleware}); + } + + private class GetItem implements FProcessorFunction { + + public void process(FContext ctx, FProtocol iprot, FProtocol oprot) throws TException { + getItem_args args = new getItem_args(); + try { + args.read(iprot); + } catch (TException e) { + iprot.readMessageEnd(); + synchronized (WRITE_LOCK) { + e = writeApplicationException(ctx, oprot, TApplicationExceptionType.PROTOCOL_ERROR, "getItem", e.getMessage()); + } + throw e; + } + + iprot.readMessageEnd(); + getItem_result result = new getItem_result(); + try { + result.success = handler.getItem(ctx); + result.setSuccessIsSet(true); + } catch (InvalidData d) { + result.d = d; + } catch (TApplicationException e) { + oprot.writeResponseHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.EXCEPTION, 0)); + e.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + return; + } catch (TException e) { + synchronized (WRITE_LOCK) { + e = (TApplicationException) writeApplicationException(ctx, oprot, TApplicationExceptionType.INTERNAL_ERROR, "getItem", "Internal error processing getItem: " + e.getMessage()).initCause(e); + } + throw e; + } + synchronized (WRITE_LOCK) { + try { + oprot.writeResponseHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.REPLY, 0)); + result.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + } catch (TTransportException e) { + if (e.getType() == TTransportExceptionType.REQUEST_TOO_LARGE) { + writeApplicationException(ctx, oprot, TApplicationExceptionType.RESPONSE_TOO_LARGE, "getItem", "response too large: " + e.getMessage()); + } else { + throw e; + } + } + } + } + } + + } + + public static class getItem_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getItem_args"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new getItem_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new getItem_argsTupleSchemeFactory()); + } + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public getItem_args() { + } + + /** + * Performs a deep copy on other. + */ + public getItem_args(getItem_args other) { + } + + public getItem_args deepCopy() { + return new getItem_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof getItem_args) + return this.equals((getItem_args)that); + return false; + } + + public boolean equals(getItem_args that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + return list.hashCode(); + } + + @Override + public int compareTo(getItem_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("getItem_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getItem_argsStandardSchemeFactory implements SchemeFactory { + public getItem_argsStandardScheme getScheme() { + return new getItem_argsStandardScheme(); + } + } + + private static class getItem_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getItem_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getItem_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getItem_argsTupleSchemeFactory implements SchemeFactory { + public getItem_argsTupleScheme getScheme() { + return new getItem_argsTupleScheme(); + } + } + + private static class getItem_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getItem_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getItem_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + + } + + } + + public static class getItem_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getItem_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0); + private static final org.apache.thrift.protocol.TField D_FIELD_DESC = new org.apache.thrift.protocol.TField("d", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new getItem_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new getItem_resultTupleSchemeFactory()); + } + + public some.vendored.pkg.Item success; + public InvalidData d; + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + D((short)1, "d") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // D + return D; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public getItem_result() { + } + + public getItem_result( + some.vendored.pkg.Item success, + InvalidData d) { + this(); + this.success = success; + this.d = d; + } + + /** + * Performs a deep copy on other. + */ + public getItem_result(getItem_result other) { + if (other.isSetSuccess()) { + this.success = new some.vendored.pkg.Item(other.success); + } + if (other.isSetD()) { + this.d = new InvalidData(other.d); + } + } + + public getItem_result deepCopy() { + return new getItem_result(this); + } + + @Override + public void clear() { + this.success = null; + + this.d = null; + + } + + public some.vendored.pkg.Item getSuccess() { + return this.success; + } + + public getItem_result setSuccess(some.vendored.pkg.Item success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public InvalidData getD() { + return this.d; + } + + public getItem_result setD(InvalidData d) { + this.d = d; + return this; + } + + public void unsetD() { + this.d = null; + } + + /** Returns true if field d is set (has been assigned a value) and false otherwise */ + public boolean isSetD() { + return this.d != null; + } + + public void setDIsSet(boolean value) { + if (!value) { + this.d = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((some.vendored.pkg.Item)value); + } + break; + + case D: + if (value == null) { + unsetD(); + } else { + setD((InvalidData)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case D: + return getD(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case D: + return isSetD(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof getItem_result) + return this.equals((getItem_result)that); + return false; + } + + public boolean equals(getItem_result that) { + if (that == null) + return false; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + boolean this_present_d = true && this.isSetD(); + boolean that_present_d = true && that.isSetD(); + if (this_present_d || that_present_d) { + if (!(this_present_d && that_present_d)) + return false; + if (!this.d.equals(that.d)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_success = true && (isSetSuccess()); + list.add(present_success); + if (present_success) + list.add(success); + + boolean present_d = true && (isSetD()); + list.add(present_d); + if (present_d) + list.add(d); + + return list.hashCode(); + } + + @Override + public int compareTo(getItem_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetD()).compareTo(other.isSetD()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetD()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.d, other.d); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("getItem_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("d:"); + if (this.d == null) { + sb.append("null"); + } else { + sb.append(this.d); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (success != null) { + success.validate(); + } + if (d != null) { + d.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getItem_resultStandardSchemeFactory implements SchemeFactory { + public getItem_resultStandardScheme getScheme() { + return new getItem_resultStandardScheme(); + } + } + + private static class getItem_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getItem_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.success = new some.vendored.pkg.Item(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // D + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.d = new InvalidData(); + struct.d.read(iprot); + struct.setDIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getItem_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + struct.success.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.d != null) { + oprot.writeFieldBegin(D_FIELD_DESC); + struct.d.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getItem_resultTupleSchemeFactory implements SchemeFactory { + public getItem_resultTupleScheme getScheme() { + return new getItem_resultTupleScheme(); + } + } + + private static class getItem_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getItem_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetD()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + struct.success.write(oprot); + } + if (struct.isSetD()) { + struct.d.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getItem_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.success = new some.vendored.pkg.Item(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.d = new InvalidData(); + struct.d.read(iprot); + struct.setDIsSet(true); + } + } + + } + + } + +} \ No newline at end of file diff --git a/test/expected/java/valid_vendor/InvalidData.java b/test/expected/java/valid_vendor/InvalidData.java new file mode 100644 index 0000000000..409f1193b4 --- /dev/null +++ b/test/expected/java/valid_vendor/InvalidData.java @@ -0,0 +1,493 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class InvalidData extends TException implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("InvalidData"); + + private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC = new org.apache.thrift.protocol.TField("code", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField WHY_FIELD_DESC = new org.apache.thrift.protocol.TField("why", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new InvalidDataStandardSchemeFactory()); + schemes.put(TupleScheme.class, new InvalidDataTupleSchemeFactory()); + } + + public int code; + public String why; + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + CODE((short)1, "code"), + WHY((short)2, "why") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CODE + return CODE; + case 2: // WHY + return WHY; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __CODE_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public InvalidData() { + } + + public InvalidData( + int code, + String why) { + this(); + this.code = code; + setCodeIsSet(true); + this.why = why; + } + + /** + * Performs a deep copy on other. + */ + public InvalidData(InvalidData other) { + __isset_bitfield = other.__isset_bitfield; + this.code = other.code; + if (other.isSetWhy()) { + this.why = other.why; + } + } + + public InvalidData deepCopy() { + return new InvalidData(this); + } + + @Override + public void clear() { + setCodeIsSet(false); + this.code = 0; + + this.why = null; + + } + + public int getCode() { + return this.code; + } + + public InvalidData setCode(int code) { + this.code = code; + setCodeIsSet(true); + return this; + } + + public void unsetCode() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __CODE_ISSET_ID); + } + + /** Returns true if field code is set (has been assigned a value) and false otherwise */ + public boolean isSetCode() { + return EncodingUtils.testBit(__isset_bitfield, __CODE_ISSET_ID); + } + + public void setCodeIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __CODE_ISSET_ID, value); + } + + public String getWhy() { + return this.why; + } + + public InvalidData setWhy(String why) { + this.why = why; + return this; + } + + public void unsetWhy() { + this.why = null; + } + + /** Returns true if field why is set (has been assigned a value) and false otherwise */ + public boolean isSetWhy() { + return this.why != null; + } + + public void setWhyIsSet(boolean value) { + if (!value) { + this.why = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case CODE: + if (value == null) { + unsetCode(); + } else { + setCode((Integer)value); + } + break; + + case WHY: + if (value == null) { + unsetWhy(); + } else { + setWhy((String)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case CODE: + return getCode(); + + case WHY: + return getWhy(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case CODE: + return isSetCode(); + case WHY: + return isSetWhy(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof InvalidData) + return this.equals((InvalidData)that); + return false; + } + + public boolean equals(InvalidData that) { + if (that == null) + return false; + + boolean this_present_code = true; + boolean that_present_code = true; + if (this_present_code || that_present_code) { + if (!(this_present_code && that_present_code)) + return false; + if (this.code != that.code) + return false; + } + + boolean this_present_why = true && this.isSetWhy(); + boolean that_present_why = true && that.isSetWhy(); + if (this_present_why || that_present_why) { + if (!(this_present_why && that_present_why)) + return false; + if (!this.why.equals(that.why)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_code = true; + list.add(present_code); + if (present_code) + list.add(code); + + boolean present_why = true && (isSetWhy()); + list.add(present_why); + if (present_why) + list.add(why); + + return list.hashCode(); + } + + @Override + public int compareTo(InvalidData other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetCode()).compareTo(other.isSetCode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetWhy()).compareTo(other.isSetWhy()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetWhy()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.why, other.why); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("InvalidData("); + boolean first = true; + + sb.append("code:"); + sb.append(this.code); + first = false; + if (!first) sb.append(", "); + sb.append("why:"); + if (this.why == null) { + sb.append("null"); + } else { + sb.append(this.why); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class InvalidDataStandardSchemeFactory implements SchemeFactory { + public InvalidDataStandardScheme getScheme() { + return new InvalidDataStandardScheme(); + } + } + + private static class InvalidDataStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, InvalidData struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // CODE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // WHY + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.why = iprot.readString(); + struct.setWhyIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, InvalidData struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(CODE_FIELD_DESC); + int elem4 = struct.code; + oprot.writeI32(elem4); + oprot.writeFieldEnd(); + if (struct.why != null) { + oprot.writeFieldBegin(WHY_FIELD_DESC); + String elem5 = struct.why; + oprot.writeString(elem5); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class InvalidDataTupleSchemeFactory implements SchemeFactory { + public InvalidDataTupleScheme getScheme() { + return new InvalidDataTupleScheme(); + } + } + + private static class InvalidDataTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, InvalidData struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetCode()) { + optionals.set(0); + } + if (struct.isSetWhy()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetCode()) { + int elem6 = struct.code; + oprot.writeI32(elem6); + } + if (struct.isSetWhy()) { + String elem7 = struct.why; + oprot.writeString(elem7); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, InvalidData struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } + if (incoming.get(1)) { + struct.why = iprot.readString(); + struct.setWhyIsSet(true); + } + } + + } + +} diff --git a/test/expected/java/valid_vendor/MyScopePublisher.java b/test/expected/java/valid_vendor/MyScopePublisher.java new file mode 100644 index 0000000000..d442d0ebab --- /dev/null +++ b/test/expected/java/valid_vendor/MyScopePublisher.java @@ -0,0 +1,121 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor.java; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FScopeProvider; +import com.workiva.frugal.transport.FPublisherTransport; +import com.workiva.frugal.transport.FSubscriberTransport; +import com.workiva.frugal.transport.FSubscription; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TException; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import org.apache.thrift.protocol.*; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Generated; + + + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class MyScopePublisher { + + public interface Iface { + public void open() throws TException; + + public void close() throws TException; + + public void publishnewItem(FContext ctx, some.vendored.pkg.Item req) throws TException; + + } + + public static class Client implements Iface { + private static final String DELIMITER = "."; + + private final Iface target; + private final Iface proxy; + + public Client(FScopeProvider provider, ServiceMiddleware... middleware) { + target = new InternalMyScopePublisher(provider); + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + middleware = combined.toArray(new ServiceMiddleware[0]); + proxy = InvocationHandler.composeMiddleware(target, Iface.class, middleware); + } + + public void open() throws TException { + target.open(); + } + + public void close() throws TException { + target.close(); + } + + public void publishnewItem(FContext ctx, some.vendored.pkg.Item req) throws TException { + proxy.publishnewItem(ctx, req); + } + + protected static class InternalMyScopePublisher implements Iface { + + private FScopeProvider provider; + private FPublisherTransport transport; + private FProtocolFactory protocolFactory; + + protected InternalMyScopePublisher() { + } + + public InternalMyScopePublisher(FScopeProvider provider) { + this.provider = provider; + } + + public void open() throws TException { + FScopeProvider.Publisher publisher = provider.buildPublisher(); + transport = publisher.getTransport(); + protocolFactory = publisher.getProtocolFactory(); + transport.open(); + } + + public void close() throws TException { + transport.close(); + } + + public void publishnewItem(FContext ctx, some.vendored.pkg.Item req) throws TException { + String op = "newItem"; + String prefix = ""; + String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + TMemoryOutputBuffer memoryBuffer = new TMemoryOutputBuffer(transport.getPublishSizeLimit()); + FProtocol oprot = protocolFactory.getProtocol(memoryBuffer); + oprot.writeRequestHeader(ctx); + oprot.writeMessageBegin(new TMessage(op, TMessageType.CALL, 0)); + req.write(oprot); + oprot.writeMessageEnd(); + transport.publish(topic, memoryBuffer.getWriteBytes()); + } + } + } +} diff --git a/test/expected/java/valid_vendor/MyScopeSubscriber.java b/test/expected/java/valid_vendor/MyScopeSubscriber.java new file mode 100644 index 0000000000..bb9c72c37b --- /dev/null +++ b/test/expected/java/valid_vendor/MyScopeSubscriber.java @@ -0,0 +1,141 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor.java; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FScopeProvider; +import com.workiva.frugal.transport.FPublisherTransport; +import com.workiva.frugal.transport.FSubscriberTransport; +import com.workiva.frugal.transport.FSubscription; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TException; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import org.apache.thrift.protocol.*; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Generated; + + + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class MyScopeSubscriber { + + public interface Iface { + public FSubscription subscribenewItem(final newItemHandler handler) throws TException; + + } + + public interface IfaceThrowable { + public FSubscription subscribenewItemThrowable(final newItemThrowableHandler handler) throws TException; + + } + + public interface newItemHandler { + void onnewItem(FContext ctx, some.vendored.pkg.Item req) throws TException; + } + + public interface newItemThrowableHandler { + void onnewItem(FContext ctx, some.vendored.pkg.Item req) throws TException; + } + + public static class Client implements Iface, IfaceThrowable { + private static final String DELIMITER = "."; + private static final Logger LOGGER = LoggerFactory.getLogger(Client.class); + + private final FScopeProvider provider; + private final ServiceMiddleware[] middleware; + + public Client(FScopeProvider provider, ServiceMiddleware... middleware) { + this.provider = provider; + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + this.middleware = combined.toArray(new ServiceMiddleware[0]); + } + + public FSubscription subscribenewItem(final newItemHandler handler) throws TException { + final String op = "newItem"; + String prefix = ""; + final String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + final FScopeProvider.Subscriber subscriber = provider.buildSubscriber(); + final FSubscriberTransport transport = subscriber.getTransport(); + final newItemHandler proxiedHandler = InvocationHandler.composeMiddleware(handler, newItemHandler.class, middleware); + transport.subscribe(topic, recvnewItem(op, subscriber.getProtocolFactory(), proxiedHandler)); + return FSubscription.of(topic, transport); + } + + private FAsyncCallback recvnewItem(String op, FProtocolFactory pf, newItemHandler handler) { + return new FAsyncCallback() { + public void onMessage(TTransport tr) throws TException { + FProtocol iprot = pf.getProtocol(tr); + FContext ctx = iprot.readRequestHeader(); + TMessage msg = iprot.readMessageBegin(); + if (!msg.name.equals(op)) { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + throw new TApplicationException(TApplicationExceptionType.UNKNOWN_METHOD); + } + some.vendored.pkg.Item received = new some.vendored.pkg.Item(); + received.read(iprot); + iprot.readMessageEnd(); + handler.onnewItem(ctx, received); + } + }; + } + + public FSubscription subscribenewItemThrowable(final newItemThrowableHandler handler) throws TException { + final String op = "newItem"; + String prefix = ""; + final String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + final FScopeProvider.Subscriber subscriber = provider.buildSubscriber(); + final FSubscriberTransport transport = subscriber.getTransport(); + final newItemThrowableHandler proxiedHandler = InvocationHandler.composeMiddleware(handler, newItemThrowableHandler.class, middleware); + transport.subscribe(topic, recvnewItem(op, subscriber.getProtocolFactory(), proxiedHandler)); + return FSubscription.of(topic, transport); + } + + private FAsyncCallback recvnewItem(String op, FProtocolFactory pf, newItemThrowableHandler handler) { + return new FAsyncCallback() { + public void onMessage(TTransport tr) throws TException { + FProtocol iprot = pf.getProtocol(tr); + FContext ctx = iprot.readRequestHeader(); + TMessage msg = iprot.readMessageBegin(); + if (!msg.name.equals(op)) { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + throw new TApplicationException(TApplicationExceptionType.UNKNOWN_METHOD); + } + some.vendored.pkg.Item received = new some.vendored.pkg.Item(); + received.read(iprot); + iprot.readMessageEnd(); + handler.onnewItem(ctx, received); + } + }; + } + } + +} diff --git a/test/expected/java/valid_vendor/VendoredReferences.java b/test/expected/java/valid_vendor/VendoredReferences.java new file mode 100644 index 0000000000..f4e2474515 --- /dev/null +++ b/test/expected/java/valid_vendor/VendoredReferences.java @@ -0,0 +1,495 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ +package include_vendor.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class VendoredReferences implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("VendoredReferences"); + + private static final org.apache.thrift.protocol.TField REFERENCE_VENDORED_CONST_FIELD_DESC = new org.apache.thrift.protocol.TField("reference_vendored_const", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField REFERENCE_VENDORED_ENUM_FIELD_DESC = new org.apache.thrift.protocol.TField("reference_vendored_enum", org.apache.thrift.protocol.TType.I32, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new VendoredReferencesStandardSchemeFactory()); + schemes.put(TupleScheme.class, new VendoredReferencesTupleSchemeFactory()); + } + + public int reference_vendored_const; // optional + public some.vendored.pkg.MyEnum reference_vendored_enum; // optional + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + REFERENCE_VENDORED_CONST((short)1, "reference_vendored_const"), + REFERENCE_VENDORED_ENUM((short)2, "reference_vendored_enum") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // REFERENCE_VENDORED_CONST + return REFERENCE_VENDORED_CONST; + case 2: // REFERENCE_VENDORED_ENUM + return REFERENCE_VENDORED_ENUM; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __REFERENCE_VENDORED_CONST_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public VendoredReferences() { + this.reference_vendored_const = some.vendored.pkg.vendor_namespaceConstants.a_const; + + this.reference_vendored_enum = some.vendored.pkg.MyEnum.TWO; + + } + + /** + * Performs a deep copy on other. + */ + public VendoredReferences(VendoredReferences other) { + __isset_bitfield = other.__isset_bitfield; + this.reference_vendored_const = other.reference_vendored_const; + if (other.isSetReference_vendored_enum()) { + this.reference_vendored_enum = other.reference_vendored_enum; + } + } + + public VendoredReferences deepCopy() { + return new VendoredReferences(this); + } + + @Override + public void clear() { + this.reference_vendored_const = some.vendored.pkg.vendor_namespaceConstants.a_const; + + this.reference_vendored_enum = some.vendored.pkg.MyEnum.TWO; + + } + + public int getReference_vendored_const() { + return this.reference_vendored_const; + } + + public VendoredReferences setReference_vendored_const(int reference_vendored_const) { + this.reference_vendored_const = reference_vendored_const; + setReference_vendored_constIsSet(true); + return this; + } + + public void unsetReference_vendored_const() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID); + } + + /** Returns true if field reference_vendored_const is set (has been assigned a value) and false otherwise */ + public boolean isSetReference_vendored_const() { + return EncodingUtils.testBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID); + } + + public void setReference_vendored_constIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID, value); + } + + public some.vendored.pkg.MyEnum getReference_vendored_enum() { + return this.reference_vendored_enum; + } + + public VendoredReferences setReference_vendored_enum(some.vendored.pkg.MyEnum reference_vendored_enum) { + this.reference_vendored_enum = reference_vendored_enum; + return this; + } + + public void unsetReference_vendored_enum() { + this.reference_vendored_enum = null; + } + + /** Returns true if field reference_vendored_enum is set (has been assigned a value) and false otherwise */ + public boolean isSetReference_vendored_enum() { + return this.reference_vendored_enum != null; + } + + public void setReference_vendored_enumIsSet(boolean value) { + if (!value) { + this.reference_vendored_enum = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case REFERENCE_VENDORED_CONST: + if (value == null) { + unsetReference_vendored_const(); + } else { + setReference_vendored_const((Integer)value); + } + break; + + case REFERENCE_VENDORED_ENUM: + if (value == null) { + unsetReference_vendored_enum(); + } else { + setReference_vendored_enum((some.vendored.pkg.MyEnum)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case REFERENCE_VENDORED_CONST: + return getReference_vendored_const(); + + case REFERENCE_VENDORED_ENUM: + return getReference_vendored_enum(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case REFERENCE_VENDORED_CONST: + return isSetReference_vendored_const(); + case REFERENCE_VENDORED_ENUM: + return isSetReference_vendored_enum(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof VendoredReferences) + return this.equals((VendoredReferences)that); + return false; + } + + public boolean equals(VendoredReferences that) { + if (that == null) + return false; + + boolean this_present_reference_vendored_const = true && this.isSetReference_vendored_const(); + boolean that_present_reference_vendored_const = true && that.isSetReference_vendored_const(); + if (this_present_reference_vendored_const || that_present_reference_vendored_const) { + if (!(this_present_reference_vendored_const && that_present_reference_vendored_const)) + return false; + if (this.reference_vendored_const != that.reference_vendored_const) + return false; + } + + boolean this_present_reference_vendored_enum = true && this.isSetReference_vendored_enum(); + boolean that_present_reference_vendored_enum = true && that.isSetReference_vendored_enum(); + if (this_present_reference_vendored_enum || that_present_reference_vendored_enum) { + if (!(this_present_reference_vendored_enum && that_present_reference_vendored_enum)) + return false; + if (!this.reference_vendored_enum.equals(that.reference_vendored_enum)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_reference_vendored_const = true && (isSetReference_vendored_const()); + list.add(present_reference_vendored_const); + if (present_reference_vendored_const) + list.add(reference_vendored_const); + + boolean present_reference_vendored_enum = true && (isSetReference_vendored_enum()); + list.add(present_reference_vendored_enum); + if (present_reference_vendored_enum) + list.add(reference_vendored_enum.getValue()); + + return list.hashCode(); + } + + @Override + public int compareTo(VendoredReferences other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetReference_vendored_const()).compareTo(other.isSetReference_vendored_const()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetReference_vendored_const()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.reference_vendored_const, other.reference_vendored_const); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetReference_vendored_enum()).compareTo(other.isSetReference_vendored_enum()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetReference_vendored_enum()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.reference_vendored_enum, other.reference_vendored_enum); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("VendoredReferences("); + boolean first = true; + + if (isSetReference_vendored_const()) { + sb.append("reference_vendored_const:"); + sb.append(this.reference_vendored_const); + first = false; + } + if (isSetReference_vendored_enum()) { + if (!first) sb.append(", "); + sb.append("reference_vendored_enum:"); + if (this.reference_vendored_enum == null) { + sb.append("null"); + } else { + sb.append(this.reference_vendored_enum); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class VendoredReferencesStandardSchemeFactory implements SchemeFactory { + public VendoredReferencesStandardScheme getScheme() { + return new VendoredReferencesStandardScheme(); + } + } + + private static class VendoredReferencesStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, VendoredReferences struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // REFERENCE_VENDORED_CONST + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.reference_vendored_const = iprot.readI32(); + struct.setReference_vendored_constIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // REFERENCE_VENDORED_ENUM + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.reference_vendored_enum = some.vendored.pkg.MyEnum.findByValue(iprot.readI32()); + struct.setReference_vendored_enumIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, VendoredReferences struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetReference_vendored_const()) { + oprot.writeFieldBegin(REFERENCE_VENDORED_CONST_FIELD_DESC); + int elem0 = struct.reference_vendored_const; + oprot.writeI32(elem0); + oprot.writeFieldEnd(); + } + if (struct.reference_vendored_enum != null) { + if (struct.isSetReference_vendored_enum()) { + oprot.writeFieldBegin(REFERENCE_VENDORED_ENUM_FIELD_DESC); + some.vendored.pkg.MyEnum elem1 = struct.reference_vendored_enum; + oprot.writeI32(elem1.getValue()); + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class VendoredReferencesTupleSchemeFactory implements SchemeFactory { + public VendoredReferencesTupleScheme getScheme() { + return new VendoredReferencesTupleScheme(); + } + } + + private static class VendoredReferencesTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, VendoredReferences struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetReference_vendored_const()) { + optionals.set(0); + } + if (struct.isSetReference_vendored_enum()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetReference_vendored_const()) { + int elem2 = struct.reference_vendored_const; + oprot.writeI32(elem2); + } + if (struct.isSetReference_vendored_enum()) { + some.vendored.pkg.MyEnum elem3 = struct.reference_vendored_enum; + oprot.writeI32(elem3.getValue()); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, VendoredReferences struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.reference_vendored_const = iprot.readI32(); + struct.setReference_vendored_constIsSet(true); + } + if (incoming.get(1)) { + struct.reference_vendored_enum = some.vendored.pkg.MyEnum.findByValue(iprot.readI32()); + struct.setReference_vendored_enumIsSet(true); + } + } + + } + +} diff --git a/test/expected/java/valid_vendor/include_vendorConstants.java b/test/expected/java/valid_vendor/include_vendorConstants.java new file mode 100644 index 0000000000..00ca376ae1 --- /dev/null +++ b/test/expected/java/valid_vendor/include_vendorConstants.java @@ -0,0 +1,40 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ +package include_vendor.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class include_vendorConstants { + public static final int reference_vendored_const = some.vendored.pkg.vendor_namespaceConstants.a_const; + +} diff --git a/test/expected/java/valid_vendor_no_path/FMyService.java b/test/expected/java/valid_vendor_no_path/FMyService.java new file mode 100644 index 0000000000..ffd330b1ec --- /dev/null +++ b/test/expected/java/valid_vendor_no_path/FMyService.java @@ -0,0 +1,931 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor_no_path.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.exception.TTransportExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.processor.FBaseProcessor; +import com.workiva.frugal.processor.FProcessor; +import com.workiva.frugal.processor.FProcessorFunction; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FServiceProvider; +import com.workiva.frugal.transport.FTransport; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TMessage; +import org.apache.thrift.protocol.TMessageType; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import javax.annotation.Generated; +import java.util.Arrays; +import java.util.concurrent.*; + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class FMyService { + + private static final Logger logger = LoggerFactory.getLogger(FMyService.class); + + public interface Iface extends vendor_namespace.java.FVendoredBase.Iface { + + public vendor_namespace.java.Item getItem(FContext ctx) throws TException, InvalidData; + + } + + public static class Client extends vendor_namespace.java.FVendoredBase.Client implements Iface { + + private Iface proxy; + + public Client(FServiceProvider provider, ServiceMiddleware... middleware) { + super(provider, middleware); + Iface client = new InternalClient(provider); + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + middleware = combined.toArray(new ServiceMiddleware[0]); + proxy = InvocationHandler.composeMiddleware(client, Iface.class, middleware); + } + + public vendor_namespace.java.Item getItem(FContext ctx) throws TException, InvalidData { + return proxy.getItem(ctx); + } + + } + + private static class InternalClient extends vendor_namespace.java.FVendoredBase.Client implements Iface { + + private FTransport transport; + private FProtocolFactory protocolFactory; + public InternalClient(FServiceProvider provider) { + super(provider); + this.transport = provider.getTransport(); + this.protocolFactory = provider.getProtocolFactory(); + } + + public vendor_namespace.java.Item getItem(FContext ctx) throws TException, InvalidData { + TMemoryOutputBuffer memoryBuffer = new TMemoryOutputBuffer(this.transport.getRequestSizeLimit()); + FProtocol oprot = this.protocolFactory.getProtocol(memoryBuffer); + oprot.writeRequestHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.CALL, 0)); + getItem_args args = new getItem_args(); + args.write(oprot); + oprot.writeMessageEnd(); + TTransport response = this.transport.request(ctx, memoryBuffer.getWriteBytes()); + + FProtocol iprot = this.protocolFactory.getProtocol(response); + iprot.readResponseHeader(ctx); + TMessage message = iprot.readMessageBegin(); + if (!message.name.equals("getItem")) { + throw new TApplicationException(TApplicationExceptionType.WRONG_METHOD_NAME, "getItem failed: wrong method name"); + } + if (message.type == TMessageType.EXCEPTION) { + TApplicationException e = TApplicationException.read(iprot); + iprot.readMessageEnd(); + TException returnedException = e; + if (e.getType() == TApplicationExceptionType.RESPONSE_TOO_LARGE) { + returnedException = new TTransportException(TTransportExceptionType.RESPONSE_TOO_LARGE, e.getMessage()); + } + throw returnedException; + } + if (message.type != TMessageType.REPLY) { + throw new TApplicationException(TApplicationExceptionType.INVALID_MESSAGE_TYPE, "getItem failed: invalid message type"); + } + getItem_result res = new getItem_result(); + res.read(iprot); + iprot.readMessageEnd(); + if (res.isSetSuccess()) { + return res.success; + } + if (res.d != null) { + throw res.d; + } + throw new TApplicationException(TApplicationExceptionType.MISSING_RESULT, "getItem failed: unknown result"); + } + } + + public static class Processor extends vendor_namespace.java.FVendoredBase.Processor implements FProcessor { + + private Iface handler; + + public Processor(Iface iface, ServiceMiddleware... middleware) { + super(iface, middleware); + handler = InvocationHandler.composeMiddleware(iface, Iface.class, middleware); + } + + protected java.util.Map getProcessMap() { + java.util.Map processMap = super.getProcessMap(); + processMap.put("getItem", new GetItem()); + return processMap; + } + + protected java.util.Map> getAnnotationsMap() { + java.util.Map> annotationsMap = super.getAnnotationsMap(); + return annotationsMap; + } + + @Override + public void addMiddleware(ServiceMiddleware middleware) { + super.addMiddleware(middleware); + handler = InvocationHandler.composeMiddleware(handler, Iface.class, new ServiceMiddleware[]{middleware}); + } + + private class GetItem implements FProcessorFunction { + + public void process(FContext ctx, FProtocol iprot, FProtocol oprot) throws TException { + getItem_args args = new getItem_args(); + try { + args.read(iprot); + } catch (TException e) { + iprot.readMessageEnd(); + synchronized (WRITE_LOCK) { + e = writeApplicationException(ctx, oprot, TApplicationExceptionType.PROTOCOL_ERROR, "getItem", e.getMessage()); + } + throw e; + } + + iprot.readMessageEnd(); + getItem_result result = new getItem_result(); + try { + result.success = handler.getItem(ctx); + result.setSuccessIsSet(true); + } catch (InvalidData d) { + result.d = d; + } catch (TApplicationException e) { + oprot.writeResponseHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.EXCEPTION, 0)); + e.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + return; + } catch (TException e) { + synchronized (WRITE_LOCK) { + e = (TApplicationException) writeApplicationException(ctx, oprot, TApplicationExceptionType.INTERNAL_ERROR, "getItem", "Internal error processing getItem: " + e.getMessage()).initCause(e); + } + throw e; + } + synchronized (WRITE_LOCK) { + try { + oprot.writeResponseHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.REPLY, 0)); + result.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + } catch (TTransportException e) { + if (e.getType() == TTransportExceptionType.REQUEST_TOO_LARGE) { + writeApplicationException(ctx, oprot, TApplicationExceptionType.RESPONSE_TOO_LARGE, "getItem", "response too large: " + e.getMessage()); + } else { + throw e; + } + } + } + } + } + + } + + public static class getItem_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getItem_args"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new getItem_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new getItem_argsTupleSchemeFactory()); + } + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public getItem_args() { + } + + /** + * Performs a deep copy on other. + */ + public getItem_args(getItem_args other) { + } + + public getItem_args deepCopy() { + return new getItem_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof getItem_args) + return this.equals((getItem_args)that); + return false; + } + + public boolean equals(getItem_args that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + return list.hashCode(); + } + + @Override + public int compareTo(getItem_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("getItem_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getItem_argsStandardSchemeFactory implements SchemeFactory { + public getItem_argsStandardScheme getScheme() { + return new getItem_argsStandardScheme(); + } + } + + private static class getItem_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getItem_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getItem_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getItem_argsTupleSchemeFactory implements SchemeFactory { + public getItem_argsTupleScheme getScheme() { + return new getItem_argsTupleScheme(); + } + } + + private static class getItem_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getItem_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getItem_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + + } + + } + + public static class getItem_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getItem_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0); + private static final org.apache.thrift.protocol.TField D_FIELD_DESC = new org.apache.thrift.protocol.TField("d", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new getItem_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new getItem_resultTupleSchemeFactory()); + } + + public vendor_namespace.java.Item success; + public InvalidData d; + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + D((short)1, "d") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // D + return D; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public getItem_result() { + } + + public getItem_result( + vendor_namespace.java.Item success, + InvalidData d) { + this(); + this.success = success; + this.d = d; + } + + /** + * Performs a deep copy on other. + */ + public getItem_result(getItem_result other) { + if (other.isSetSuccess()) { + this.success = new vendor_namespace.java.Item(other.success); + } + if (other.isSetD()) { + this.d = new InvalidData(other.d); + } + } + + public getItem_result deepCopy() { + return new getItem_result(this); + } + + @Override + public void clear() { + this.success = null; + + this.d = null; + + } + + public vendor_namespace.java.Item getSuccess() { + return this.success; + } + + public getItem_result setSuccess(vendor_namespace.java.Item success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public InvalidData getD() { + return this.d; + } + + public getItem_result setD(InvalidData d) { + this.d = d; + return this; + } + + public void unsetD() { + this.d = null; + } + + /** Returns true if field d is set (has been assigned a value) and false otherwise */ + public boolean isSetD() { + return this.d != null; + } + + public void setDIsSet(boolean value) { + if (!value) { + this.d = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((vendor_namespace.java.Item)value); + } + break; + + case D: + if (value == null) { + unsetD(); + } else { + setD((InvalidData)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case D: + return getD(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case D: + return isSetD(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof getItem_result) + return this.equals((getItem_result)that); + return false; + } + + public boolean equals(getItem_result that) { + if (that == null) + return false; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + boolean this_present_d = true && this.isSetD(); + boolean that_present_d = true && that.isSetD(); + if (this_present_d || that_present_d) { + if (!(this_present_d && that_present_d)) + return false; + if (!this.d.equals(that.d)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_success = true && (isSetSuccess()); + list.add(present_success); + if (present_success) + list.add(success); + + boolean present_d = true && (isSetD()); + list.add(present_d); + if (present_d) + list.add(d); + + return list.hashCode(); + } + + @Override + public int compareTo(getItem_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetD()).compareTo(other.isSetD()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetD()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.d, other.d); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("getItem_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("d:"); + if (this.d == null) { + sb.append("null"); + } else { + sb.append(this.d); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (success != null) { + success.validate(); + } + if (d != null) { + d.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getItem_resultStandardSchemeFactory implements SchemeFactory { + public getItem_resultStandardScheme getScheme() { + return new getItem_resultStandardScheme(); + } + } + + private static class getItem_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getItem_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.success = new vendor_namespace.java.Item(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // D + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.d = new InvalidData(); + struct.d.read(iprot); + struct.setDIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getItem_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + struct.success.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.d != null) { + oprot.writeFieldBegin(D_FIELD_DESC); + struct.d.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getItem_resultTupleSchemeFactory implements SchemeFactory { + public getItem_resultTupleScheme getScheme() { + return new getItem_resultTupleScheme(); + } + } + + private static class getItem_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getItem_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetD()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + struct.success.write(oprot); + } + if (struct.isSetD()) { + struct.d.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getItem_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.success = new vendor_namespace.java.Item(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.d = new InvalidData(); + struct.d.read(iprot); + struct.setDIsSet(true); + } + } + + } + + } + +} \ No newline at end of file diff --git a/test/expected/java/valid_vendor_no_path/InvalidData.java b/test/expected/java/valid_vendor_no_path/InvalidData.java new file mode 100644 index 0000000000..409f1193b4 --- /dev/null +++ b/test/expected/java/valid_vendor_no_path/InvalidData.java @@ -0,0 +1,493 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class InvalidData extends TException implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("InvalidData"); + + private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC = new org.apache.thrift.protocol.TField("code", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField WHY_FIELD_DESC = new org.apache.thrift.protocol.TField("why", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new InvalidDataStandardSchemeFactory()); + schemes.put(TupleScheme.class, new InvalidDataTupleSchemeFactory()); + } + + public int code; + public String why; + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + CODE((short)1, "code"), + WHY((short)2, "why") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CODE + return CODE; + case 2: // WHY + return WHY; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __CODE_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public InvalidData() { + } + + public InvalidData( + int code, + String why) { + this(); + this.code = code; + setCodeIsSet(true); + this.why = why; + } + + /** + * Performs a deep copy on other. + */ + public InvalidData(InvalidData other) { + __isset_bitfield = other.__isset_bitfield; + this.code = other.code; + if (other.isSetWhy()) { + this.why = other.why; + } + } + + public InvalidData deepCopy() { + return new InvalidData(this); + } + + @Override + public void clear() { + setCodeIsSet(false); + this.code = 0; + + this.why = null; + + } + + public int getCode() { + return this.code; + } + + public InvalidData setCode(int code) { + this.code = code; + setCodeIsSet(true); + return this; + } + + public void unsetCode() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __CODE_ISSET_ID); + } + + /** Returns true if field code is set (has been assigned a value) and false otherwise */ + public boolean isSetCode() { + return EncodingUtils.testBit(__isset_bitfield, __CODE_ISSET_ID); + } + + public void setCodeIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __CODE_ISSET_ID, value); + } + + public String getWhy() { + return this.why; + } + + public InvalidData setWhy(String why) { + this.why = why; + return this; + } + + public void unsetWhy() { + this.why = null; + } + + /** Returns true if field why is set (has been assigned a value) and false otherwise */ + public boolean isSetWhy() { + return this.why != null; + } + + public void setWhyIsSet(boolean value) { + if (!value) { + this.why = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case CODE: + if (value == null) { + unsetCode(); + } else { + setCode((Integer)value); + } + break; + + case WHY: + if (value == null) { + unsetWhy(); + } else { + setWhy((String)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case CODE: + return getCode(); + + case WHY: + return getWhy(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case CODE: + return isSetCode(); + case WHY: + return isSetWhy(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof InvalidData) + return this.equals((InvalidData)that); + return false; + } + + public boolean equals(InvalidData that) { + if (that == null) + return false; + + boolean this_present_code = true; + boolean that_present_code = true; + if (this_present_code || that_present_code) { + if (!(this_present_code && that_present_code)) + return false; + if (this.code != that.code) + return false; + } + + boolean this_present_why = true && this.isSetWhy(); + boolean that_present_why = true && that.isSetWhy(); + if (this_present_why || that_present_why) { + if (!(this_present_why && that_present_why)) + return false; + if (!this.why.equals(that.why)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_code = true; + list.add(present_code); + if (present_code) + list.add(code); + + boolean present_why = true && (isSetWhy()); + list.add(present_why); + if (present_why) + list.add(why); + + return list.hashCode(); + } + + @Override + public int compareTo(InvalidData other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetCode()).compareTo(other.isSetCode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetWhy()).compareTo(other.isSetWhy()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetWhy()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.why, other.why); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("InvalidData("); + boolean first = true; + + sb.append("code:"); + sb.append(this.code); + first = false; + if (!first) sb.append(", "); + sb.append("why:"); + if (this.why == null) { + sb.append("null"); + } else { + sb.append(this.why); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class InvalidDataStandardSchemeFactory implements SchemeFactory { + public InvalidDataStandardScheme getScheme() { + return new InvalidDataStandardScheme(); + } + } + + private static class InvalidDataStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, InvalidData struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // CODE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // WHY + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.why = iprot.readString(); + struct.setWhyIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, InvalidData struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(CODE_FIELD_DESC); + int elem4 = struct.code; + oprot.writeI32(elem4); + oprot.writeFieldEnd(); + if (struct.why != null) { + oprot.writeFieldBegin(WHY_FIELD_DESC); + String elem5 = struct.why; + oprot.writeString(elem5); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class InvalidDataTupleSchemeFactory implements SchemeFactory { + public InvalidDataTupleScheme getScheme() { + return new InvalidDataTupleScheme(); + } + } + + private static class InvalidDataTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, InvalidData struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetCode()) { + optionals.set(0); + } + if (struct.isSetWhy()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetCode()) { + int elem6 = struct.code; + oprot.writeI32(elem6); + } + if (struct.isSetWhy()) { + String elem7 = struct.why; + oprot.writeString(elem7); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, InvalidData struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } + if (incoming.get(1)) { + struct.why = iprot.readString(); + struct.setWhyIsSet(true); + } + } + + } + +} diff --git a/test/expected/java/valid_vendor_no_path/MyScopePublisher.java b/test/expected/java/valid_vendor_no_path/MyScopePublisher.java new file mode 100644 index 0000000000..3e7fba0699 --- /dev/null +++ b/test/expected/java/valid_vendor_no_path/MyScopePublisher.java @@ -0,0 +1,121 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor_no_path.java; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FScopeProvider; +import com.workiva.frugal.transport.FPublisherTransport; +import com.workiva.frugal.transport.FSubscriberTransport; +import com.workiva.frugal.transport.FSubscription; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TException; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import org.apache.thrift.protocol.*; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Generated; + + + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class MyScopePublisher { + + public interface Iface { + public void open() throws TException; + + public void close() throws TException; + + public void publishnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException; + + } + + public static class Client implements Iface { + private static final String DELIMITER = "."; + + private final Iface target; + private final Iface proxy; + + public Client(FScopeProvider provider, ServiceMiddleware... middleware) { + target = new InternalMyScopePublisher(provider); + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + middleware = combined.toArray(new ServiceMiddleware[0]); + proxy = InvocationHandler.composeMiddleware(target, Iface.class, middleware); + } + + public void open() throws TException { + target.open(); + } + + public void close() throws TException { + target.close(); + } + + public void publishnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException { + proxy.publishnewItem(ctx, req); + } + + protected static class InternalMyScopePublisher implements Iface { + + private FScopeProvider provider; + private FPublisherTransport transport; + private FProtocolFactory protocolFactory; + + protected InternalMyScopePublisher() { + } + + public InternalMyScopePublisher(FScopeProvider provider) { + this.provider = provider; + } + + public void open() throws TException { + FScopeProvider.Publisher publisher = provider.buildPublisher(); + transport = publisher.getTransport(); + protocolFactory = publisher.getProtocolFactory(); + transport.open(); + } + + public void close() throws TException { + transport.close(); + } + + public void publishnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException { + String op = "newItem"; + String prefix = ""; + String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + TMemoryOutputBuffer memoryBuffer = new TMemoryOutputBuffer(transport.getPublishSizeLimit()); + FProtocol oprot = protocolFactory.getProtocol(memoryBuffer); + oprot.writeRequestHeader(ctx); + oprot.writeMessageBegin(new TMessage(op, TMessageType.CALL, 0)); + req.write(oprot); + oprot.writeMessageEnd(); + transport.publish(topic, memoryBuffer.getWriteBytes()); + } + } + } +} diff --git a/test/expected/java/valid_vendor_no_path/MyScopeSubscriber.java b/test/expected/java/valid_vendor_no_path/MyScopeSubscriber.java new file mode 100644 index 0000000000..65783198c2 --- /dev/null +++ b/test/expected/java/valid_vendor_no_path/MyScopeSubscriber.java @@ -0,0 +1,141 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor_no_path.java; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FScopeProvider; +import com.workiva.frugal.transport.FPublisherTransport; +import com.workiva.frugal.transport.FSubscriberTransport; +import com.workiva.frugal.transport.FSubscription; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TException; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import org.apache.thrift.protocol.*; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Generated; + + + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class MyScopeSubscriber { + + public interface Iface { + public FSubscription subscribenewItem(final newItemHandler handler) throws TException; + + } + + public interface IfaceThrowable { + public FSubscription subscribenewItemThrowable(final newItemThrowableHandler handler) throws TException; + + } + + public interface newItemHandler { + void onnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException; + } + + public interface newItemThrowableHandler { + void onnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException; + } + + public static class Client implements Iface, IfaceThrowable { + private static final String DELIMITER = "."; + private static final Logger LOGGER = LoggerFactory.getLogger(Client.class); + + private final FScopeProvider provider; + private final ServiceMiddleware[] middleware; + + public Client(FScopeProvider provider, ServiceMiddleware... middleware) { + this.provider = provider; + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + this.middleware = combined.toArray(new ServiceMiddleware[0]); + } + + public FSubscription subscribenewItem(final newItemHandler handler) throws TException { + final String op = "newItem"; + String prefix = ""; + final String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + final FScopeProvider.Subscriber subscriber = provider.buildSubscriber(); + final FSubscriberTransport transport = subscriber.getTransport(); + final newItemHandler proxiedHandler = InvocationHandler.composeMiddleware(handler, newItemHandler.class, middleware); + transport.subscribe(topic, recvnewItem(op, subscriber.getProtocolFactory(), proxiedHandler)); + return FSubscription.of(topic, transport); + } + + private FAsyncCallback recvnewItem(String op, FProtocolFactory pf, newItemHandler handler) { + return new FAsyncCallback() { + public void onMessage(TTransport tr) throws TException { + FProtocol iprot = pf.getProtocol(tr); + FContext ctx = iprot.readRequestHeader(); + TMessage msg = iprot.readMessageBegin(); + if (!msg.name.equals(op)) { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + throw new TApplicationException(TApplicationExceptionType.UNKNOWN_METHOD); + } + vendor_namespace.java.Item received = new vendor_namespace.java.Item(); + received.read(iprot); + iprot.readMessageEnd(); + handler.onnewItem(ctx, received); + } + }; + } + + public FSubscription subscribenewItemThrowable(final newItemThrowableHandler handler) throws TException { + final String op = "newItem"; + String prefix = ""; + final String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + final FScopeProvider.Subscriber subscriber = provider.buildSubscriber(); + final FSubscriberTransport transport = subscriber.getTransport(); + final newItemThrowableHandler proxiedHandler = InvocationHandler.composeMiddleware(handler, newItemThrowableHandler.class, middleware); + transport.subscribe(topic, recvnewItem(op, subscriber.getProtocolFactory(), proxiedHandler)); + return FSubscription.of(topic, transport); + } + + private FAsyncCallback recvnewItem(String op, FProtocolFactory pf, newItemThrowableHandler handler) { + return new FAsyncCallback() { + public void onMessage(TTransport tr) throws TException { + FProtocol iprot = pf.getProtocol(tr); + FContext ctx = iprot.readRequestHeader(); + TMessage msg = iprot.readMessageBegin(); + if (!msg.name.equals(op)) { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + throw new TApplicationException(TApplicationExceptionType.UNKNOWN_METHOD); + } + vendor_namespace.java.Item received = new vendor_namespace.java.Item(); + received.read(iprot); + iprot.readMessageEnd(); + handler.onnewItem(ctx, received); + } + }; + } + } + +} diff --git a/test/expected/java/valid_vendor_no_path/VendoredReferences.java b/test/expected/java/valid_vendor_no_path/VendoredReferences.java new file mode 100644 index 0000000000..6e4305a3ff --- /dev/null +++ b/test/expected/java/valid_vendor_no_path/VendoredReferences.java @@ -0,0 +1,495 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ +package include_vendor_no_path.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class VendoredReferences implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("VendoredReferences"); + + private static final org.apache.thrift.protocol.TField REFERENCE_VENDORED_CONST_FIELD_DESC = new org.apache.thrift.protocol.TField("reference_vendored_const", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField REFERENCE_VENDORED_ENUM_FIELD_DESC = new org.apache.thrift.protocol.TField("reference_vendored_enum", org.apache.thrift.protocol.TType.I32, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new VendoredReferencesStandardSchemeFactory()); + schemes.put(TupleScheme.class, new VendoredReferencesTupleSchemeFactory()); + } + + public int reference_vendored_const; // optional + public vendor_namespace.java.MyEnum reference_vendored_enum; // optional + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + REFERENCE_VENDORED_CONST((short)1, "reference_vendored_const"), + REFERENCE_VENDORED_ENUM((short)2, "reference_vendored_enum") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // REFERENCE_VENDORED_CONST + return REFERENCE_VENDORED_CONST; + case 2: // REFERENCE_VENDORED_ENUM + return REFERENCE_VENDORED_ENUM; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __REFERENCE_VENDORED_CONST_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public VendoredReferences() { + this.reference_vendored_const = vendor_namespace.java.vendor_namespace_no_pathConstants.a_const; + + this.reference_vendored_enum = vendor_namespace.java.MyEnum.TWO; + + } + + /** + * Performs a deep copy on other. + */ + public VendoredReferences(VendoredReferences other) { + __isset_bitfield = other.__isset_bitfield; + this.reference_vendored_const = other.reference_vendored_const; + if (other.isSetReference_vendored_enum()) { + this.reference_vendored_enum = other.reference_vendored_enum; + } + } + + public VendoredReferences deepCopy() { + return new VendoredReferences(this); + } + + @Override + public void clear() { + this.reference_vendored_const = vendor_namespace.java.vendor_namespace_no_pathConstants.a_const; + + this.reference_vendored_enum = vendor_namespace.java.MyEnum.TWO; + + } + + public int getReference_vendored_const() { + return this.reference_vendored_const; + } + + public VendoredReferences setReference_vendored_const(int reference_vendored_const) { + this.reference_vendored_const = reference_vendored_const; + setReference_vendored_constIsSet(true); + return this; + } + + public void unsetReference_vendored_const() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID); + } + + /** Returns true if field reference_vendored_const is set (has been assigned a value) and false otherwise */ + public boolean isSetReference_vendored_const() { + return EncodingUtils.testBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID); + } + + public void setReference_vendored_constIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID, value); + } + + public vendor_namespace.java.MyEnum getReference_vendored_enum() { + return this.reference_vendored_enum; + } + + public VendoredReferences setReference_vendored_enum(vendor_namespace.java.MyEnum reference_vendored_enum) { + this.reference_vendored_enum = reference_vendored_enum; + return this; + } + + public void unsetReference_vendored_enum() { + this.reference_vendored_enum = null; + } + + /** Returns true if field reference_vendored_enum is set (has been assigned a value) and false otherwise */ + public boolean isSetReference_vendored_enum() { + return this.reference_vendored_enum != null; + } + + public void setReference_vendored_enumIsSet(boolean value) { + if (!value) { + this.reference_vendored_enum = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case REFERENCE_VENDORED_CONST: + if (value == null) { + unsetReference_vendored_const(); + } else { + setReference_vendored_const((Integer)value); + } + break; + + case REFERENCE_VENDORED_ENUM: + if (value == null) { + unsetReference_vendored_enum(); + } else { + setReference_vendored_enum((vendor_namespace.java.MyEnum)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case REFERENCE_VENDORED_CONST: + return getReference_vendored_const(); + + case REFERENCE_VENDORED_ENUM: + return getReference_vendored_enum(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case REFERENCE_VENDORED_CONST: + return isSetReference_vendored_const(); + case REFERENCE_VENDORED_ENUM: + return isSetReference_vendored_enum(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof VendoredReferences) + return this.equals((VendoredReferences)that); + return false; + } + + public boolean equals(VendoredReferences that) { + if (that == null) + return false; + + boolean this_present_reference_vendored_const = true && this.isSetReference_vendored_const(); + boolean that_present_reference_vendored_const = true && that.isSetReference_vendored_const(); + if (this_present_reference_vendored_const || that_present_reference_vendored_const) { + if (!(this_present_reference_vendored_const && that_present_reference_vendored_const)) + return false; + if (this.reference_vendored_const != that.reference_vendored_const) + return false; + } + + boolean this_present_reference_vendored_enum = true && this.isSetReference_vendored_enum(); + boolean that_present_reference_vendored_enum = true && that.isSetReference_vendored_enum(); + if (this_present_reference_vendored_enum || that_present_reference_vendored_enum) { + if (!(this_present_reference_vendored_enum && that_present_reference_vendored_enum)) + return false; + if (!this.reference_vendored_enum.equals(that.reference_vendored_enum)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_reference_vendored_const = true && (isSetReference_vendored_const()); + list.add(present_reference_vendored_const); + if (present_reference_vendored_const) + list.add(reference_vendored_const); + + boolean present_reference_vendored_enum = true && (isSetReference_vendored_enum()); + list.add(present_reference_vendored_enum); + if (present_reference_vendored_enum) + list.add(reference_vendored_enum.getValue()); + + return list.hashCode(); + } + + @Override + public int compareTo(VendoredReferences other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetReference_vendored_const()).compareTo(other.isSetReference_vendored_const()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetReference_vendored_const()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.reference_vendored_const, other.reference_vendored_const); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetReference_vendored_enum()).compareTo(other.isSetReference_vendored_enum()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetReference_vendored_enum()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.reference_vendored_enum, other.reference_vendored_enum); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("VendoredReferences("); + boolean first = true; + + if (isSetReference_vendored_const()) { + sb.append("reference_vendored_const:"); + sb.append(this.reference_vendored_const); + first = false; + } + if (isSetReference_vendored_enum()) { + if (!first) sb.append(", "); + sb.append("reference_vendored_enum:"); + if (this.reference_vendored_enum == null) { + sb.append("null"); + } else { + sb.append(this.reference_vendored_enum); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class VendoredReferencesStandardSchemeFactory implements SchemeFactory { + public VendoredReferencesStandardScheme getScheme() { + return new VendoredReferencesStandardScheme(); + } + } + + private static class VendoredReferencesStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, VendoredReferences struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // REFERENCE_VENDORED_CONST + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.reference_vendored_const = iprot.readI32(); + struct.setReference_vendored_constIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // REFERENCE_VENDORED_ENUM + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.reference_vendored_enum = vendor_namespace.java.MyEnum.findByValue(iprot.readI32()); + struct.setReference_vendored_enumIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, VendoredReferences struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetReference_vendored_const()) { + oprot.writeFieldBegin(REFERENCE_VENDORED_CONST_FIELD_DESC); + int elem0 = struct.reference_vendored_const; + oprot.writeI32(elem0); + oprot.writeFieldEnd(); + } + if (struct.reference_vendored_enum != null) { + if (struct.isSetReference_vendored_enum()) { + oprot.writeFieldBegin(REFERENCE_VENDORED_ENUM_FIELD_DESC); + vendor_namespace.java.MyEnum elem1 = struct.reference_vendored_enum; + oprot.writeI32(elem1.getValue()); + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class VendoredReferencesTupleSchemeFactory implements SchemeFactory { + public VendoredReferencesTupleScheme getScheme() { + return new VendoredReferencesTupleScheme(); + } + } + + private static class VendoredReferencesTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, VendoredReferences struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetReference_vendored_const()) { + optionals.set(0); + } + if (struct.isSetReference_vendored_enum()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetReference_vendored_const()) { + int elem2 = struct.reference_vendored_const; + oprot.writeI32(elem2); + } + if (struct.isSetReference_vendored_enum()) { + vendor_namespace.java.MyEnum elem3 = struct.reference_vendored_enum; + oprot.writeI32(elem3.getValue()); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, VendoredReferences struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.reference_vendored_const = iprot.readI32(); + struct.setReference_vendored_constIsSet(true); + } + if (incoming.get(1)) { + struct.reference_vendored_enum = vendor_namespace.java.MyEnum.findByValue(iprot.readI32()); + struct.setReference_vendored_enumIsSet(true); + } + } + + } + +} diff --git a/test/expected/java/vendored_but_no_use_vendor/FMyService.java b/test/expected/java/vendored_but_no_use_vendor/FMyService.java new file mode 100644 index 0000000000..ffd1498d8d --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/FMyService.java @@ -0,0 +1,931 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.exception.TTransportExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.processor.FBaseProcessor; +import com.workiva.frugal.processor.FProcessor; +import com.workiva.frugal.processor.FProcessorFunction; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FServiceProvider; +import com.workiva.frugal.transport.FTransport; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TMessage; +import org.apache.thrift.protocol.TMessageType; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import javax.annotation.Generated; +import java.util.Arrays; +import java.util.concurrent.*; + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class FMyService { + + private static final Logger logger = LoggerFactory.getLogger(FMyService.class); + + public interface Iface extends vendor_namespace.java.FVendoredBase.Iface { + + public vendor_namespace.java.Item getItem(FContext ctx) throws TException, InvalidData; + + } + + public static class Client extends vendor_namespace.java.FVendoredBase.Client implements Iface { + + private Iface proxy; + + public Client(FServiceProvider provider, ServiceMiddleware... middleware) { + super(provider, middleware); + Iface client = new InternalClient(provider); + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + middleware = combined.toArray(new ServiceMiddleware[0]); + proxy = InvocationHandler.composeMiddleware(client, Iface.class, middleware); + } + + public vendor_namespace.java.Item getItem(FContext ctx) throws TException, InvalidData { + return proxy.getItem(ctx); + } + + } + + private static class InternalClient extends vendor_namespace.java.FVendoredBase.Client implements Iface { + + private FTransport transport; + private FProtocolFactory protocolFactory; + public InternalClient(FServiceProvider provider) { + super(provider); + this.transport = provider.getTransport(); + this.protocolFactory = provider.getProtocolFactory(); + } + + public vendor_namespace.java.Item getItem(FContext ctx) throws TException, InvalidData { + TMemoryOutputBuffer memoryBuffer = new TMemoryOutputBuffer(this.transport.getRequestSizeLimit()); + FProtocol oprot = this.protocolFactory.getProtocol(memoryBuffer); + oprot.writeRequestHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.CALL, 0)); + getItem_args args = new getItem_args(); + args.write(oprot); + oprot.writeMessageEnd(); + TTransport response = this.transport.request(ctx, memoryBuffer.getWriteBytes()); + + FProtocol iprot = this.protocolFactory.getProtocol(response); + iprot.readResponseHeader(ctx); + TMessage message = iprot.readMessageBegin(); + if (!message.name.equals("getItem")) { + throw new TApplicationException(TApplicationExceptionType.WRONG_METHOD_NAME, "getItem failed: wrong method name"); + } + if (message.type == TMessageType.EXCEPTION) { + TApplicationException e = TApplicationException.read(iprot); + iprot.readMessageEnd(); + TException returnedException = e; + if (e.getType() == TApplicationExceptionType.RESPONSE_TOO_LARGE) { + returnedException = new TTransportException(TTransportExceptionType.RESPONSE_TOO_LARGE, e.getMessage()); + } + throw returnedException; + } + if (message.type != TMessageType.REPLY) { + throw new TApplicationException(TApplicationExceptionType.INVALID_MESSAGE_TYPE, "getItem failed: invalid message type"); + } + getItem_result res = new getItem_result(); + res.read(iprot); + iprot.readMessageEnd(); + if (res.isSetSuccess()) { + return res.success; + } + if (res.d != null) { + throw res.d; + } + throw new TApplicationException(TApplicationExceptionType.MISSING_RESULT, "getItem failed: unknown result"); + } + } + + public static class Processor extends vendor_namespace.java.FVendoredBase.Processor implements FProcessor { + + private Iface handler; + + public Processor(Iface iface, ServiceMiddleware... middleware) { + super(iface, middleware); + handler = InvocationHandler.composeMiddleware(iface, Iface.class, middleware); + } + + protected java.util.Map getProcessMap() { + java.util.Map processMap = super.getProcessMap(); + processMap.put("getItem", new GetItem()); + return processMap; + } + + protected java.util.Map> getAnnotationsMap() { + java.util.Map> annotationsMap = super.getAnnotationsMap(); + return annotationsMap; + } + + @Override + public void addMiddleware(ServiceMiddleware middleware) { + super.addMiddleware(middleware); + handler = InvocationHandler.composeMiddleware(handler, Iface.class, new ServiceMiddleware[]{middleware}); + } + + private class GetItem implements FProcessorFunction { + + public void process(FContext ctx, FProtocol iprot, FProtocol oprot) throws TException { + getItem_args args = new getItem_args(); + try { + args.read(iprot); + } catch (TException e) { + iprot.readMessageEnd(); + synchronized (WRITE_LOCK) { + e = writeApplicationException(ctx, oprot, TApplicationExceptionType.PROTOCOL_ERROR, "getItem", e.getMessage()); + } + throw e; + } + + iprot.readMessageEnd(); + getItem_result result = new getItem_result(); + try { + result.success = handler.getItem(ctx); + result.setSuccessIsSet(true); + } catch (InvalidData d) { + result.d = d; + } catch (TApplicationException e) { + oprot.writeResponseHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.EXCEPTION, 0)); + e.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + return; + } catch (TException e) { + synchronized (WRITE_LOCK) { + e = (TApplicationException) writeApplicationException(ctx, oprot, TApplicationExceptionType.INTERNAL_ERROR, "getItem", "Internal error processing getItem: " + e.getMessage()).initCause(e); + } + throw e; + } + synchronized (WRITE_LOCK) { + try { + oprot.writeResponseHeader(ctx); + oprot.writeMessageBegin(new TMessage("getItem", TMessageType.REPLY, 0)); + result.write(oprot); + oprot.writeMessageEnd(); + oprot.getTransport().flush(); + } catch (TTransportException e) { + if (e.getType() == TTransportExceptionType.REQUEST_TOO_LARGE) { + writeApplicationException(ctx, oprot, TApplicationExceptionType.RESPONSE_TOO_LARGE, "getItem", "response too large: " + e.getMessage()); + } else { + throw e; + } + } + } + } + } + + } + + public static class getItem_args implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getItem_args"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new getItem_argsStandardSchemeFactory()); + schemes.put(TupleScheme.class, new getItem_argsTupleSchemeFactory()); + } + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public getItem_args() { + } + + /** + * Performs a deep copy on other. + */ + public getItem_args(getItem_args other) { + } + + public getItem_args deepCopy() { + return new getItem_args(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof getItem_args) + return this.equals((getItem_args)that); + return false; + } + + public boolean equals(getItem_args that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + return list.hashCode(); + } + + @Override + public int compareTo(getItem_args other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("getItem_args("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getItem_argsStandardSchemeFactory implements SchemeFactory { + public getItem_argsStandardScheme getScheme() { + return new getItem_argsStandardScheme(); + } + } + + private static class getItem_argsStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getItem_args struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getItem_args struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getItem_argsTupleSchemeFactory implements SchemeFactory { + public getItem_argsTupleScheme getScheme() { + return new getItem_argsTupleScheme(); + } + } + + private static class getItem_argsTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getItem_args struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getItem_args struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + + } + + } + + public static class getItem_result implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("getItem_result"); + + private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.STRUCT, (short)0); + private static final org.apache.thrift.protocol.TField D_FIELD_DESC = new org.apache.thrift.protocol.TField("d", org.apache.thrift.protocol.TType.STRUCT, (short)1); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new getItem_resultStandardSchemeFactory()); + schemes.put(TupleScheme.class, new getItem_resultTupleSchemeFactory()); + } + + public vendor_namespace.java.Item success; + public InvalidData d; + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + SUCCESS((short)0, "success"), + D((short)1, "d") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 0: // SUCCESS + return SUCCESS; + case 1: // D + return D; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public getItem_result() { + } + + public getItem_result( + vendor_namespace.java.Item success, + InvalidData d) { + this(); + this.success = success; + this.d = d; + } + + /** + * Performs a deep copy on other. + */ + public getItem_result(getItem_result other) { + if (other.isSetSuccess()) { + this.success = new vendor_namespace.java.Item(other.success); + } + if (other.isSetD()) { + this.d = new InvalidData(other.d); + } + } + + public getItem_result deepCopy() { + return new getItem_result(this); + } + + @Override + public void clear() { + this.success = null; + + this.d = null; + + } + + public vendor_namespace.java.Item getSuccess() { + return this.success; + } + + public getItem_result setSuccess(vendor_namespace.java.Item success) { + this.success = success; + return this; + } + + public void unsetSuccess() { + this.success = null; + } + + /** Returns true if field success is set (has been assigned a value) and false otherwise */ + public boolean isSetSuccess() { + return this.success != null; + } + + public void setSuccessIsSet(boolean value) { + if (!value) { + this.success = null; + } + } + + public InvalidData getD() { + return this.d; + } + + public getItem_result setD(InvalidData d) { + this.d = d; + return this; + } + + public void unsetD() { + this.d = null; + } + + /** Returns true if field d is set (has been assigned a value) and false otherwise */ + public boolean isSetD() { + return this.d != null; + } + + public void setDIsSet(boolean value) { + if (!value) { + this.d = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case SUCCESS: + if (value == null) { + unsetSuccess(); + } else { + setSuccess((vendor_namespace.java.Item)value); + } + break; + + case D: + if (value == null) { + unsetD(); + } else { + setD((InvalidData)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case SUCCESS: + return getSuccess(); + + case D: + return getD(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case SUCCESS: + return isSetSuccess(); + case D: + return isSetD(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof getItem_result) + return this.equals((getItem_result)that); + return false; + } + + public boolean equals(getItem_result that) { + if (that == null) + return false; + + boolean this_present_success = true && this.isSetSuccess(); + boolean that_present_success = true && that.isSetSuccess(); + if (this_present_success || that_present_success) { + if (!(this_present_success && that_present_success)) + return false; + if (!this.success.equals(that.success)) + return false; + } + + boolean this_present_d = true && this.isSetD(); + boolean that_present_d = true && that.isSetD(); + if (this_present_d || that_present_d) { + if (!(this_present_d && that_present_d)) + return false; + if (!this.d.equals(that.d)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_success = true && (isSetSuccess()); + list.add(present_success); + if (present_success) + list.add(success); + + boolean present_d = true && (isSetD()); + list.add(present_d); + if (present_d) + list.add(d); + + return list.hashCode(); + } + + @Override + public int compareTo(getItem_result other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetSuccess()).compareTo(other.isSetSuccess()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetSuccess()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.success, other.success); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetD()).compareTo(other.isSetD()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetD()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.d, other.d); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("getItem_result("); + boolean first = true; + + sb.append("success:"); + if (this.success == null) { + sb.append("null"); + } else { + sb.append(this.success); + } + first = false; + if (!first) sb.append(", "); + sb.append("d:"); + if (this.d == null) { + sb.append("null"); + } else { + sb.append(this.d); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + if (success != null) { + success.validate(); + } + if (d != null) { + d.validate(); + } + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class getItem_resultStandardSchemeFactory implements SchemeFactory { + public getItem_resultStandardScheme getScheme() { + return new getItem_resultStandardScheme(); + } + } + + private static class getItem_resultStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, getItem_result struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 0: // SUCCESS + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.success = new vendor_namespace.java.Item(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 1: // D + if (schemeField.type == org.apache.thrift.protocol.TType.STRUCT) { + struct.d = new InvalidData(); + struct.d.read(iprot); + struct.setDIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, getItem_result struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.success != null) { + oprot.writeFieldBegin(SUCCESS_FIELD_DESC); + struct.success.write(oprot); + oprot.writeFieldEnd(); + } + if (struct.d != null) { + oprot.writeFieldBegin(D_FIELD_DESC); + struct.d.write(oprot); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class getItem_resultTupleSchemeFactory implements SchemeFactory { + public getItem_resultTupleScheme getScheme() { + return new getItem_resultTupleScheme(); + } + } + + private static class getItem_resultTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, getItem_result struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetSuccess()) { + optionals.set(0); + } + if (struct.isSetD()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetSuccess()) { + struct.success.write(oprot); + } + if (struct.isSetD()) { + struct.d.write(oprot); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, getItem_result struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.success = new vendor_namespace.java.Item(); + struct.success.read(iprot); + struct.setSuccessIsSet(true); + } + if (incoming.get(1)) { + struct.d = new InvalidData(); + struct.d.read(iprot); + struct.setDIsSet(true); + } + } + + } + + } + +} \ No newline at end of file diff --git a/test/expected/java/vendored_but_no_use_vendor/FVendoredBase.java b/test/expected/java/vendored_but_no_use_vendor/FVendoredBase.java new file mode 100644 index 0000000000..4e8ffe62a7 --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/FVendoredBase.java @@ -0,0 +1,119 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package vendor_namespace.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.exception.TTransportExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.processor.FBaseProcessor; +import com.workiva.frugal.processor.FProcessor; +import com.workiva.frugal.processor.FProcessorFunction; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FServiceProvider; +import com.workiva.frugal.transport.FTransport; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.TException; +import org.apache.thrift.protocol.TMessage; +import org.apache.thrift.protocol.TMessageType; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import javax.annotation.Generated; +import java.util.Arrays; +import java.util.concurrent.*; + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class FVendoredBase { + + private static final Logger logger = LoggerFactory.getLogger(FVendoredBase.class); + + public interface Iface { + + } + + public static class Client implements Iface { + + private Iface proxy; + + public Client(FServiceProvider provider, ServiceMiddleware... middleware) { + Iface client = new InternalClient(provider); + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + middleware = combined.toArray(new ServiceMiddleware[0]); + proxy = InvocationHandler.composeMiddleware(client, Iface.class, middleware); + } + + } + + private static class InternalClient implements Iface { + + private FTransport transport; + private FProtocolFactory protocolFactory; + public InternalClient(FServiceProvider provider) { + this.transport = provider.getTransport(); + this.protocolFactory = provider.getProtocolFactory(); + } + + } + + public static class Processor extends FBaseProcessor implements FProcessor { + + private Iface handler; + + public Processor(Iface iface, ServiceMiddleware... middleware) { + handler = InvocationHandler.composeMiddleware(iface, Iface.class, middleware); + } + + protected java.util.Map getProcessMap() { + java.util.Map processMap = new java.util.HashMap<>(); + return processMap; + } + + protected java.util.Map> getAnnotationsMap() { + java.util.Map> annotationsMap = new java.util.HashMap<>(); + return annotationsMap; + } + + @Override + public void addMiddleware(ServiceMiddleware middleware) { + handler = InvocationHandler.composeMiddleware(handler, Iface.class, new ServiceMiddleware[]{middleware}); + } + + } + +} \ No newline at end of file diff --git a/test/expected/java/vendored_but_no_use_vendor/InvalidData.java b/test/expected/java/vendored_but_no_use_vendor/InvalidData.java new file mode 100644 index 0000000000..409f1193b4 --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/InvalidData.java @@ -0,0 +1,493 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class InvalidData extends TException implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("InvalidData"); + + private static final org.apache.thrift.protocol.TField CODE_FIELD_DESC = new org.apache.thrift.protocol.TField("code", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField WHY_FIELD_DESC = new org.apache.thrift.protocol.TField("why", org.apache.thrift.protocol.TType.STRING, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new InvalidDataStandardSchemeFactory()); + schemes.put(TupleScheme.class, new InvalidDataTupleSchemeFactory()); + } + + public int code; + public String why; + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + CODE((short)1, "code"), + WHY((short)2, "why") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // CODE + return CODE; + case 2: // WHY + return WHY; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __CODE_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public InvalidData() { + } + + public InvalidData( + int code, + String why) { + this(); + this.code = code; + setCodeIsSet(true); + this.why = why; + } + + /** + * Performs a deep copy on other. + */ + public InvalidData(InvalidData other) { + __isset_bitfield = other.__isset_bitfield; + this.code = other.code; + if (other.isSetWhy()) { + this.why = other.why; + } + } + + public InvalidData deepCopy() { + return new InvalidData(this); + } + + @Override + public void clear() { + setCodeIsSet(false); + this.code = 0; + + this.why = null; + + } + + public int getCode() { + return this.code; + } + + public InvalidData setCode(int code) { + this.code = code; + setCodeIsSet(true); + return this; + } + + public void unsetCode() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __CODE_ISSET_ID); + } + + /** Returns true if field code is set (has been assigned a value) and false otherwise */ + public boolean isSetCode() { + return EncodingUtils.testBit(__isset_bitfield, __CODE_ISSET_ID); + } + + public void setCodeIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __CODE_ISSET_ID, value); + } + + public String getWhy() { + return this.why; + } + + public InvalidData setWhy(String why) { + this.why = why; + return this; + } + + public void unsetWhy() { + this.why = null; + } + + /** Returns true if field why is set (has been assigned a value) and false otherwise */ + public boolean isSetWhy() { + return this.why != null; + } + + public void setWhyIsSet(boolean value) { + if (!value) { + this.why = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case CODE: + if (value == null) { + unsetCode(); + } else { + setCode((Integer)value); + } + break; + + case WHY: + if (value == null) { + unsetWhy(); + } else { + setWhy((String)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case CODE: + return getCode(); + + case WHY: + return getWhy(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case CODE: + return isSetCode(); + case WHY: + return isSetWhy(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof InvalidData) + return this.equals((InvalidData)that); + return false; + } + + public boolean equals(InvalidData that) { + if (that == null) + return false; + + boolean this_present_code = true; + boolean that_present_code = true; + if (this_present_code || that_present_code) { + if (!(this_present_code && that_present_code)) + return false; + if (this.code != that.code) + return false; + } + + boolean this_present_why = true && this.isSetWhy(); + boolean that_present_why = true && that.isSetWhy(); + if (this_present_why || that_present_why) { + if (!(this_present_why && that_present_why)) + return false; + if (!this.why.equals(that.why)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_code = true; + list.add(present_code); + if (present_code) + list.add(code); + + boolean present_why = true && (isSetWhy()); + list.add(present_why); + if (present_why) + list.add(why); + + return list.hashCode(); + } + + @Override + public int compareTo(InvalidData other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetCode()).compareTo(other.isSetCode()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetCode()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.code, other.code); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetWhy()).compareTo(other.isSetWhy()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetWhy()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.why, other.why); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("InvalidData("); + boolean first = true; + + sb.append("code:"); + sb.append(this.code); + first = false; + if (!first) sb.append(", "); + sb.append("why:"); + if (this.why == null) { + sb.append("null"); + } else { + sb.append(this.why); + } + first = false; + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class InvalidDataStandardSchemeFactory implements SchemeFactory { + public InvalidDataStandardScheme getScheme() { + return new InvalidDataStandardScheme(); + } + } + + private static class InvalidDataStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, InvalidData struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // CODE + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // WHY + if (schemeField.type == org.apache.thrift.protocol.TType.STRING) { + struct.why = iprot.readString(); + struct.setWhyIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, InvalidData struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldBegin(CODE_FIELD_DESC); + int elem4 = struct.code; + oprot.writeI32(elem4); + oprot.writeFieldEnd(); + if (struct.why != null) { + oprot.writeFieldBegin(WHY_FIELD_DESC); + String elem5 = struct.why; + oprot.writeString(elem5); + oprot.writeFieldEnd(); + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class InvalidDataTupleSchemeFactory implements SchemeFactory { + public InvalidDataTupleScheme getScheme() { + return new InvalidDataTupleScheme(); + } + } + + private static class InvalidDataTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, InvalidData struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetCode()) { + optionals.set(0); + } + if (struct.isSetWhy()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetCode()) { + int elem6 = struct.code; + oprot.writeI32(elem6); + } + if (struct.isSetWhy()) { + String elem7 = struct.why; + oprot.writeString(elem7); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, InvalidData struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.code = iprot.readI32(); + struct.setCodeIsSet(true); + } + if (incoming.get(1)) { + struct.why = iprot.readString(); + struct.setWhyIsSet(true); + } + } + + } + +} diff --git a/test/expected/java/vendored_but_no_use_vendor/Item.java b/test/expected/java/vendored_but_no_use_vendor/Item.java new file mode 100644 index 0000000000..bdf4bb942a --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/Item.java @@ -0,0 +1,278 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ +package vendor_namespace.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class Item implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("Item"); + + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new ItemStandardSchemeFactory()); + schemes.put(TupleScheme.class, new ItemTupleSchemeFactory()); + } + + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + public Item() { + } + + /** + * Performs a deep copy on other. + */ + public Item(Item other) { + } + + public Item deepCopy() { + return new Item(this); + } + + @Override + public void clear() { + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof Item) + return this.equals((Item)that); + return false; + } + + public boolean equals(Item that) { + if (that == null) + return false; + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + return list.hashCode(); + } + + @Override + public int compareTo(Item other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("Item("); + boolean first = true; + + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class ItemStandardSchemeFactory implements SchemeFactory { + public ItemStandardScheme getScheme() { + return new ItemStandardScheme(); + } + } + + private static class ItemStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, Item struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, Item struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class ItemTupleSchemeFactory implements SchemeFactory { + public ItemTupleScheme getScheme() { + return new ItemTupleScheme(); + } + } + + private static class ItemTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, Item struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, Item struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + } + + } + +} diff --git a/test/expected/java/vendored_but_no_use_vendor/MyEnum.java b/test/expected/java/vendored_but_no_use_vendor/MyEnum.java new file mode 100644 index 0000000000..24992ccca7 --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/MyEnum.java @@ -0,0 +1,37 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ +package vendor_namespace.java; + +import java.util.Map; +import java.util.HashMap; +import org.apache.thrift.TEnum; + +public enum MyEnum implements org.apache.thrift.TEnum { + ZERO(0), + TWO(2); + + private final int value; + + private MyEnum(int value) { + this.value = value; + } + + public int getValue() { + return value; + } + + public static MyEnum findByValue(int value) { + switch (value) { + case 0: + return ZERO; + case 2: + return TWO; + default: + return null; + } + } +} diff --git a/test/expected/java/vendored_but_no_use_vendor/MyScopePublisher.java b/test/expected/java/vendored_but_no_use_vendor/MyScopePublisher.java new file mode 100644 index 0000000000..8f8126611c --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/MyScopePublisher.java @@ -0,0 +1,121 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor.java; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FScopeProvider; +import com.workiva.frugal.transport.FPublisherTransport; +import com.workiva.frugal.transport.FSubscriberTransport; +import com.workiva.frugal.transport.FSubscription; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TException; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import org.apache.thrift.protocol.*; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Generated; + + + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class MyScopePublisher { + + public interface Iface { + public void open() throws TException; + + public void close() throws TException; + + public void publishnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException; + + } + + public static class Client implements Iface { + private static final String DELIMITER = "."; + + private final Iface target; + private final Iface proxy; + + public Client(FScopeProvider provider, ServiceMiddleware... middleware) { + target = new InternalMyScopePublisher(provider); + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + middleware = combined.toArray(new ServiceMiddleware[0]); + proxy = InvocationHandler.composeMiddleware(target, Iface.class, middleware); + } + + public void open() throws TException { + target.open(); + } + + public void close() throws TException { + target.close(); + } + + public void publishnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException { + proxy.publishnewItem(ctx, req); + } + + protected static class InternalMyScopePublisher implements Iface { + + private FScopeProvider provider; + private FPublisherTransport transport; + private FProtocolFactory protocolFactory; + + protected InternalMyScopePublisher() { + } + + public InternalMyScopePublisher(FScopeProvider provider) { + this.provider = provider; + } + + public void open() throws TException { + FScopeProvider.Publisher publisher = provider.buildPublisher(); + transport = publisher.getTransport(); + protocolFactory = publisher.getProtocolFactory(); + transport.open(); + } + + public void close() throws TException { + transport.close(); + } + + public void publishnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException { + String op = "newItem"; + String prefix = ""; + String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + TMemoryOutputBuffer memoryBuffer = new TMemoryOutputBuffer(transport.getPublishSizeLimit()); + FProtocol oprot = protocolFactory.getProtocol(memoryBuffer); + oprot.writeRequestHeader(ctx); + oprot.writeMessageBegin(new TMessage(op, TMessageType.CALL, 0)); + req.write(oprot); + oprot.writeMessageEnd(); + transport.publish(topic, memoryBuffer.getWriteBytes()); + } + } + } +} diff --git a/test/expected/java/vendored_but_no_use_vendor/MyScopeSubscriber.java b/test/expected/java/vendored_but_no_use_vendor/MyScopeSubscriber.java new file mode 100644 index 0000000000..5d41a4a9da --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/MyScopeSubscriber.java @@ -0,0 +1,141 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ + +package include_vendor.java; + +import com.workiva.frugal.FContext; +import com.workiva.frugal.exception.TApplicationExceptionType; +import com.workiva.frugal.middleware.InvocationHandler; +import com.workiva.frugal.middleware.ServiceMiddleware; +import com.workiva.frugal.protocol.*; +import com.workiva.frugal.provider.FScopeProvider; +import com.workiva.frugal.transport.FPublisherTransport; +import com.workiva.frugal.transport.FSubscriberTransport; +import com.workiva.frugal.transport.FSubscription; +import com.workiva.frugal.transport.TMemoryOutputBuffer; +import org.apache.thrift.TException; +import org.apache.thrift.TApplicationException; +import org.apache.thrift.transport.TTransport; +import org.apache.thrift.transport.TTransportException; +import org.apache.thrift.protocol.*; + +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import javax.annotation.Generated; + + + + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class MyScopeSubscriber { + + public interface Iface { + public FSubscription subscribenewItem(final newItemHandler handler) throws TException; + + } + + public interface IfaceThrowable { + public FSubscription subscribenewItemThrowable(final newItemThrowableHandler handler) throws TException; + + } + + public interface newItemHandler { + void onnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException; + } + + public interface newItemThrowableHandler { + void onnewItem(FContext ctx, vendor_namespace.java.Item req) throws TException; + } + + public static class Client implements Iface, IfaceThrowable { + private static final String DELIMITER = "."; + private static final Logger LOGGER = LoggerFactory.getLogger(Client.class); + + private final FScopeProvider provider; + private final ServiceMiddleware[] middleware; + + public Client(FScopeProvider provider, ServiceMiddleware... middleware) { + this.provider = provider; + List combined = Arrays.asList(middleware); + combined.addAll(provider.getMiddleware()); + this.middleware = combined.toArray(new ServiceMiddleware[0]); + } + + public FSubscription subscribenewItem(final newItemHandler handler) throws TException { + final String op = "newItem"; + String prefix = ""; + final String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + final FScopeProvider.Subscriber subscriber = provider.buildSubscriber(); + final FSubscriberTransport transport = subscriber.getTransport(); + final newItemHandler proxiedHandler = InvocationHandler.composeMiddleware(handler, newItemHandler.class, middleware); + transport.subscribe(topic, recvnewItem(op, subscriber.getProtocolFactory(), proxiedHandler)); + return FSubscription.of(topic, transport); + } + + private FAsyncCallback recvnewItem(String op, FProtocolFactory pf, newItemHandler handler) { + return new FAsyncCallback() { + public void onMessage(TTransport tr) throws TException { + FProtocol iprot = pf.getProtocol(tr); + FContext ctx = iprot.readRequestHeader(); + TMessage msg = iprot.readMessageBegin(); + if (!msg.name.equals(op)) { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + throw new TApplicationException(TApplicationExceptionType.UNKNOWN_METHOD); + } + vendor_namespace.java.Item received = new vendor_namespace.java.Item(); + received.read(iprot); + iprot.readMessageEnd(); + handler.onnewItem(ctx, received); + } + }; + } + + public FSubscription subscribenewItemThrowable(final newItemThrowableHandler handler) throws TException { + final String op = "newItem"; + String prefix = ""; + final String topic = String.format("%sMyScope%s%s", prefix, DELIMITER, op); + final FScopeProvider.Subscriber subscriber = provider.buildSubscriber(); + final FSubscriberTransport transport = subscriber.getTransport(); + final newItemThrowableHandler proxiedHandler = InvocationHandler.composeMiddleware(handler, newItemThrowableHandler.class, middleware); + transport.subscribe(topic, recvnewItem(op, subscriber.getProtocolFactory(), proxiedHandler)); + return FSubscription.of(topic, transport); + } + + private FAsyncCallback recvnewItem(String op, FProtocolFactory pf, newItemThrowableHandler handler) { + return new FAsyncCallback() { + public void onMessage(TTransport tr) throws TException { + FProtocol iprot = pf.getProtocol(tr); + FContext ctx = iprot.readRequestHeader(); + TMessage msg = iprot.readMessageBegin(); + if (!msg.name.equals(op)) { + TProtocolUtil.skip(iprot, TType.STRUCT); + iprot.readMessageEnd(); + throw new TApplicationException(TApplicationExceptionType.UNKNOWN_METHOD); + } + vendor_namespace.java.Item received = new vendor_namespace.java.Item(); + received.read(iprot); + iprot.readMessageEnd(); + handler.onnewItem(ctx, received); + } + }; + } + } + +} diff --git a/test/expected/java/vendored_but_no_use_vendor/VendoredReferences.java b/test/expected/java/vendored_but_no_use_vendor/VendoredReferences.java new file mode 100644 index 0000000000..c733d28abb --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/VendoredReferences.java @@ -0,0 +1,495 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ +package include_vendor.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class VendoredReferences implements org.apache.thrift.TBase, java.io.Serializable, Cloneable, Comparable { + private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("VendoredReferences"); + + private static final org.apache.thrift.protocol.TField REFERENCE_VENDORED_CONST_FIELD_DESC = new org.apache.thrift.protocol.TField("reference_vendored_const", org.apache.thrift.protocol.TType.I32, (short)1); + private static final org.apache.thrift.protocol.TField REFERENCE_VENDORED_ENUM_FIELD_DESC = new org.apache.thrift.protocol.TField("reference_vendored_enum", org.apache.thrift.protocol.TType.I32, (short)2); + + private static final Map, SchemeFactory> schemes = new HashMap, SchemeFactory>(); + static { + schemes.put(StandardScheme.class, new VendoredReferencesStandardSchemeFactory()); + schemes.put(TupleScheme.class, new VendoredReferencesTupleSchemeFactory()); + } + + public int reference_vendored_const; // optional + public vendor_namespace.java.MyEnum reference_vendored_enum; // optional + /** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */ + public enum _Fields implements org.apache.thrift.TFieldIdEnum { + REFERENCE_VENDORED_CONST((short)1, "reference_vendored_const"), + REFERENCE_VENDORED_ENUM((short)2, "reference_vendored_enum") + ; + + private static final Map byName = new HashMap(); + + static { + for (_Fields field : EnumSet.allOf(_Fields.class)) { + byName.put(field.getFieldName(), field); + } + } + + /** + * Find the _Fields constant that matches fieldId, or null if its not found. + */ + public static _Fields findByThriftId(int fieldId) { + switch(fieldId) { + case 1: // REFERENCE_VENDORED_CONST + return REFERENCE_VENDORED_CONST; + case 2: // REFERENCE_VENDORED_ENUM + return REFERENCE_VENDORED_ENUM; + default: + return null; + } + } + + /** + * Find the _Fields constant that matches fieldId, throwing an exception + * if it is not found. + */ + public static _Fields findByThriftIdOrThrow(int fieldId) { + _Fields fields = findByThriftId(fieldId); + if (fields == null) throw new IllegalArgumentException("Field " + fieldId + " doesn't exist!"); + return fields; + } + + /** + * Find the _Fields constant that matches name, or null if its not found. + */ + public static _Fields findByName(String name) { + return byName.get(name); + } + + private final short _thriftId; + private final String _fieldName; + + _Fields(short thriftId, String fieldName) { + _thriftId = thriftId; + _fieldName = fieldName; + } + + public short getThriftFieldId() { + return _thriftId; + } + + public String getFieldName() { + return _fieldName; + } + } + + // isset id assignments + private static final int __REFERENCE_VENDORED_CONST_ISSET_ID = 0; + private byte __isset_bitfield = 0; + public VendoredReferences() { + this.reference_vendored_const = vendor_namespace.java.vendor_namespaceConstants.a_const; + + this.reference_vendored_enum = vendor_namespace.java.MyEnum.TWO; + + } + + /** + * Performs a deep copy on other. + */ + public VendoredReferences(VendoredReferences other) { + __isset_bitfield = other.__isset_bitfield; + this.reference_vendored_const = other.reference_vendored_const; + if (other.isSetReference_vendored_enum()) { + this.reference_vendored_enum = other.reference_vendored_enum; + } + } + + public VendoredReferences deepCopy() { + return new VendoredReferences(this); + } + + @Override + public void clear() { + this.reference_vendored_const = vendor_namespace.java.vendor_namespaceConstants.a_const; + + this.reference_vendored_enum = vendor_namespace.java.MyEnum.TWO; + + } + + public int getReference_vendored_const() { + return this.reference_vendored_const; + } + + public VendoredReferences setReference_vendored_const(int reference_vendored_const) { + this.reference_vendored_const = reference_vendored_const; + setReference_vendored_constIsSet(true); + return this; + } + + public void unsetReference_vendored_const() { + __isset_bitfield = EncodingUtils.clearBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID); + } + + /** Returns true if field reference_vendored_const is set (has been assigned a value) and false otherwise */ + public boolean isSetReference_vendored_const() { + return EncodingUtils.testBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID); + } + + public void setReference_vendored_constIsSet(boolean value) { + __isset_bitfield = EncodingUtils.setBit(__isset_bitfield, __REFERENCE_VENDORED_CONST_ISSET_ID, value); + } + + public vendor_namespace.java.MyEnum getReference_vendored_enum() { + return this.reference_vendored_enum; + } + + public VendoredReferences setReference_vendored_enum(vendor_namespace.java.MyEnum reference_vendored_enum) { + this.reference_vendored_enum = reference_vendored_enum; + return this; + } + + public void unsetReference_vendored_enum() { + this.reference_vendored_enum = null; + } + + /** Returns true if field reference_vendored_enum is set (has been assigned a value) and false otherwise */ + public boolean isSetReference_vendored_enum() { + return this.reference_vendored_enum != null; + } + + public void setReference_vendored_enumIsSet(boolean value) { + if (!value) { + this.reference_vendored_enum = null; + } + } + + public void setFieldValue(_Fields field, Object value) { + switch (field) { + case REFERENCE_VENDORED_CONST: + if (value == null) { + unsetReference_vendored_const(); + } else { + setReference_vendored_const((Integer)value); + } + break; + + case REFERENCE_VENDORED_ENUM: + if (value == null) { + unsetReference_vendored_enum(); + } else { + setReference_vendored_enum((vendor_namespace.java.MyEnum)value); + } + break; + + } + } + + public Object getFieldValue(_Fields field) { + switch (field) { + case REFERENCE_VENDORED_CONST: + return getReference_vendored_const(); + + case REFERENCE_VENDORED_ENUM: + return getReference_vendored_enum(); + + } + throw new IllegalStateException(); + } + + /** Returns true if field corresponding to fieldID is set (has been assigned a value) and false otherwise */ + public boolean isSet(_Fields field) { + if (field == null) { + throw new IllegalArgumentException(); + } + + switch (field) { + case REFERENCE_VENDORED_CONST: + return isSetReference_vendored_const(); + case REFERENCE_VENDORED_ENUM: + return isSetReference_vendored_enum(); + } + throw new IllegalStateException(); + } + + @Override + public boolean equals(Object that) { + if (that == null) + return false; + if (that instanceof VendoredReferences) + return this.equals((VendoredReferences)that); + return false; + } + + public boolean equals(VendoredReferences that) { + if (that == null) + return false; + + boolean this_present_reference_vendored_const = true && this.isSetReference_vendored_const(); + boolean that_present_reference_vendored_const = true && that.isSetReference_vendored_const(); + if (this_present_reference_vendored_const || that_present_reference_vendored_const) { + if (!(this_present_reference_vendored_const && that_present_reference_vendored_const)) + return false; + if (this.reference_vendored_const != that.reference_vendored_const) + return false; + } + + boolean this_present_reference_vendored_enum = true && this.isSetReference_vendored_enum(); + boolean that_present_reference_vendored_enum = true && that.isSetReference_vendored_enum(); + if (this_present_reference_vendored_enum || that_present_reference_vendored_enum) { + if (!(this_present_reference_vendored_enum && that_present_reference_vendored_enum)) + return false; + if (!this.reference_vendored_enum.equals(that.reference_vendored_enum)) + return false; + } + + return true; + } + + @Override + public int hashCode() { + List list = new ArrayList(); + + boolean present_reference_vendored_const = true && (isSetReference_vendored_const()); + list.add(present_reference_vendored_const); + if (present_reference_vendored_const) + list.add(reference_vendored_const); + + boolean present_reference_vendored_enum = true && (isSetReference_vendored_enum()); + list.add(present_reference_vendored_enum); + if (present_reference_vendored_enum) + list.add(reference_vendored_enum.getValue()); + + return list.hashCode(); + } + + @Override + public int compareTo(VendoredReferences other) { + if (!getClass().equals(other.getClass())) { + return getClass().getName().compareTo(other.getClass().getName()); + } + + int lastComparison = 0; + + lastComparison = Boolean.valueOf(isSetReference_vendored_const()).compareTo(other.isSetReference_vendored_const()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetReference_vendored_const()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.reference_vendored_const, other.reference_vendored_const); + if (lastComparison != 0) { + return lastComparison; + } + } + lastComparison = Boolean.valueOf(isSetReference_vendored_enum()).compareTo(other.isSetReference_vendored_enum()); + if (lastComparison != 0) { + return lastComparison; + } + if (isSetReference_vendored_enum()) { + lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.reference_vendored_enum, other.reference_vendored_enum); + if (lastComparison != 0) { + return lastComparison; + } + } + return 0; + } + + public _Fields fieldForId(int fieldId) { + return _Fields.findByThriftId(fieldId); + } + + public void read(org.apache.thrift.protocol.TProtocol iprot) throws org.apache.thrift.TException { + schemes.get(iprot.getScheme()).getScheme().read(iprot, this); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot) throws org.apache.thrift.TException { + schemes.get(oprot.getScheme()).getScheme().write(oprot, this); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("VendoredReferences("); + boolean first = true; + + if (isSetReference_vendored_const()) { + sb.append("reference_vendored_const:"); + sb.append(this.reference_vendored_const); + first = false; + } + if (isSetReference_vendored_enum()) { + if (!first) sb.append(", "); + sb.append("reference_vendored_enum:"); + if (this.reference_vendored_enum == null) { + sb.append("null"); + } else { + sb.append(this.reference_vendored_enum); + } + first = false; + } + sb.append(")"); + return sb.toString(); + } + + public void validate() throws org.apache.thrift.TException { + // check for required fields + // check for sub-struct validity + } + + private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException { + try { + write(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(out))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { + try { + // it doesn't seem like you should have to do this, but java serialization is wacky, and doesn't call the default constructor. + __isset_bitfield = 0; + read(new org.apache.thrift.protocol.TCompactProtocol(new org.apache.thrift.transport.TIOStreamTransport(in))); + } catch (org.apache.thrift.TException te) { + throw new java.io.IOException(te); + } + } + + private static class VendoredReferencesStandardSchemeFactory implements SchemeFactory { + public VendoredReferencesStandardScheme getScheme() { + return new VendoredReferencesStandardScheme(); + } + } + + private static class VendoredReferencesStandardScheme extends StandardScheme { + + public void read(org.apache.thrift.protocol.TProtocol iprot, VendoredReferences struct) throws org.apache.thrift.TException { + org.apache.thrift.protocol.TField schemeField; + iprot.readStructBegin(); + while (true) { + schemeField = iprot.readFieldBegin(); + if (schemeField.type == org.apache.thrift.protocol.TType.STOP) { + break; + } + switch (schemeField.id) { + case 1: // REFERENCE_VENDORED_CONST + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.reference_vendored_const = iprot.readI32(); + struct.setReference_vendored_constIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + case 2: // REFERENCE_VENDORED_ENUM + if (schemeField.type == org.apache.thrift.protocol.TType.I32) { + struct.reference_vendored_enum = vendor_namespace.java.MyEnum.findByValue(iprot.readI32()); + struct.setReference_vendored_enumIsSet(true); + } else { + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + break; + default: + org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type); + } + iprot.readFieldEnd(); + } + iprot.readStructEnd(); + + // check for required fields of primitive type, which can't be checked in the validate method + struct.validate(); + } + + public void write(org.apache.thrift.protocol.TProtocol oprot, VendoredReferences struct) throws org.apache.thrift.TException { + struct.validate(); + + oprot.writeStructBegin(STRUCT_DESC); + if (struct.isSetReference_vendored_const()) { + oprot.writeFieldBegin(REFERENCE_VENDORED_CONST_FIELD_DESC); + int elem0 = struct.reference_vendored_const; + oprot.writeI32(elem0); + oprot.writeFieldEnd(); + } + if (struct.reference_vendored_enum != null) { + if (struct.isSetReference_vendored_enum()) { + oprot.writeFieldBegin(REFERENCE_VENDORED_ENUM_FIELD_DESC); + vendor_namespace.java.MyEnum elem1 = struct.reference_vendored_enum; + oprot.writeI32(elem1.getValue()); + oprot.writeFieldEnd(); + } + } + oprot.writeFieldStop(); + oprot.writeStructEnd(); + } + + } + + private static class VendoredReferencesTupleSchemeFactory implements SchemeFactory { + public VendoredReferencesTupleScheme getScheme() { + return new VendoredReferencesTupleScheme(); + } + } + + private static class VendoredReferencesTupleScheme extends TupleScheme { + + @Override + public void write(org.apache.thrift.protocol.TProtocol prot, VendoredReferences struct) throws org.apache.thrift.TException { + TTupleProtocol oprot = (TTupleProtocol) prot; + BitSet optionals = new BitSet(); + if (struct.isSetReference_vendored_const()) { + optionals.set(0); + } + if (struct.isSetReference_vendored_enum()) { + optionals.set(1); + } + oprot.writeBitSet(optionals, 2); + if (struct.isSetReference_vendored_const()) { + int elem2 = struct.reference_vendored_const; + oprot.writeI32(elem2); + } + if (struct.isSetReference_vendored_enum()) { + vendor_namespace.java.MyEnum elem3 = struct.reference_vendored_enum; + oprot.writeI32(elem3.getValue()); + } + } + + @Override + public void read(org.apache.thrift.protocol.TProtocol prot, VendoredReferences struct) throws org.apache.thrift.TException { + TTupleProtocol iprot = (TTupleProtocol) prot; + BitSet incoming = iprot.readBitSet(2); + if (incoming.get(0)) { + struct.reference_vendored_const = iprot.readI32(); + struct.setReference_vendored_constIsSet(true); + } + if (incoming.get(1)) { + struct.reference_vendored_enum = vendor_namespace.java.MyEnum.findByValue(iprot.readI32()); + struct.setReference_vendored_enumIsSet(true); + } + } + + } + +} diff --git a/test/expected/java/vendored_but_no_use_vendor/include_vendorConstants.java b/test/expected/java/vendored_but_no_use_vendor/include_vendorConstants.java new file mode 100644 index 0000000000..601267a495 --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/include_vendorConstants.java @@ -0,0 +1,40 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ +package include_vendor.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class include_vendorConstants { + public static final int reference_vendored_const = vendor_namespace.java.vendor_namespaceConstants.a_const; + +} diff --git a/test/expected/java/vendored_but_no_use_vendor/vendor_namespaceConstants.java b/test/expected/java/vendored_but_no_use_vendor/vendor_namespaceConstants.java new file mode 100644 index 0000000000..8c251e4115 --- /dev/null +++ b/test/expected/java/vendored_but_no_use_vendor/vendor_namespaceConstants.java @@ -0,0 +1,40 @@ +/** + * Autogenerated by Frugal Compiler (2.20.0) + * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING + * + * @generated + */ +package vendor_namespace.java; + +import org.apache.thrift.scheme.IScheme; +import org.apache.thrift.scheme.SchemeFactory; +import org.apache.thrift.scheme.StandardScheme; + +import org.apache.thrift.scheme.TupleScheme; +import org.apache.thrift.protocol.TTupleProtocol; +import org.apache.thrift.protocol.TProtocolException; +import org.apache.thrift.EncodingUtils; +import org.apache.thrift.TException; +import org.apache.thrift.async.AsyncMethodCallback; +import org.apache.thrift.server.AbstractNonblockingServer.*; +import java.util.List; +import java.util.ArrayList; +import java.util.Map; +import java.util.HashMap; +import java.util.EnumMap; +import java.util.Set; +import java.util.HashSet; +import java.util.EnumSet; +import java.util.Collections; +import java.util.BitSet; +import java.nio.ByteBuffer; +import java.util.Arrays; +import javax.annotation.Generated; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +@Generated(value = "Autogenerated by Frugal Compiler (2.20.0)", date = "2015-11-24") +public class vendor_namespaceConstants { + public static final int a_const = 1; + +} diff --git a/test/go_test.go b/test/go_test.go index a91d35f03c..e0250c1289 100644 --- a/test/go_test.go +++ b/test/go_test.go @@ -113,6 +113,7 @@ func TestValidGoVendorNamespaceTargetGenerate(t *testing.T) { files := []FileComparisonPair{ {"expected/go/vendor_namespace/f_types.txt", filepath.Join(outputDir, "vendor_namespace", "f_types.go")}, + {"expected/go/vendor_namespace/f_vendoredbase_service.txt", filepath.Join(outputDir, "vendor_namespace", "f_vendoredbase_service.go")}, } copyAllFiles(t, files) compareAllFiles(t, files) diff --git a/test/idl/include_vendor.frugal b/test/idl/include_vendor.frugal index b14c600092..6d89290dc5 100644 --- a/test/idl/include_vendor.frugal +++ b/test/idl/include_vendor.frugal @@ -1,8 +1,14 @@ +namespace java include_vendor.java + include "vendor_namespace.frugal" (vendor) include "excepts.frugal" +struct VendoredReferences { + 1: optional i32 reference_vendored_const = vendor_namespace.a_const + 2: optional vendor_namespace.MyEnum reference_vendored_enum = vendor_namespace.MyEnum.TWO +} -service MyService { +service MyService extends vendor_namespace.VendoredBase { vendor_namespace.Item getItem() throws (1:excepts.InvalidData d) } diff --git a/test/idl/include_vendor_no_path.frugal b/test/idl/include_vendor_no_path.frugal index 617fcf05f2..fd3f73fbdd 100644 --- a/test/idl/include_vendor_no_path.frugal +++ b/test/idl/include_vendor_no_path.frugal @@ -1,8 +1,14 @@ +namespace java include_vendor_no_path.java + include "vendor_namespace_no_path.frugal" (vendor) include "excepts.frugal" +struct VendoredReferences { + 1: optional i32 reference_vendored_const = vendor_namespace_no_path.a_const + 2: optional vendor_namespace_no_path.MyEnum reference_vendored_enum = vendor_namespace_no_path.MyEnum.TWO +} -service MyService { +service MyService extends vendor_namespace_no_path.VendoredBase { vendor_namespace_no_path.Item getItem() throws (1:excepts.InvalidData d) } diff --git a/test/idl/vendor_namespace.frugal b/test/idl/vendor_namespace.frugal index f472a746a8..2a741c0bce 100644 --- a/test/idl/vendor_namespace.frugal +++ b/test/idl/vendor_namespace.frugal @@ -1,4 +1,14 @@ namespace go vendor_namespace (vendor="github.com/Workiva/some/vendored/place/vendor_namespace") namespace dart vendor_namespace (vendor="some_vendored_place") +namespace java vendor_namespace.java (vendor="some.vendored.pkg") + +const i32 a_const = 1 struct Item {} + +enum MyEnum { + ZERO, + TWO = 2 +} + +service VendoredBase {} diff --git a/test/idl/vendor_namespace_no_path.frugal b/test/idl/vendor_namespace_no_path.frugal index 3e0a5885c1..e24cca2f7d 100644 --- a/test/idl/vendor_namespace_no_path.frugal +++ b/test/idl/vendor_namespace_no_path.frugal @@ -1,4 +1,14 @@ namespace go vendor_namespace namespace dart vendor_namespace +namespace java vendor_namespace.java + +const i32 a_const = 1 struct Item {} + +enum MyEnum { + ZERO, + TWO = 2 +} + +service VendoredBase {} diff --git a/test/java_test.go b/test/java_test.go index 57f3d42d7f..38b011f491 100644 --- a/test/java_test.go +++ b/test/java_test.go @@ -121,3 +121,115 @@ func TestValidJavaBoxedPrimitives(t *testing.T) { copyAllFiles(t, files) compareAllFiles(t, files) } + +// Ensures correct import references are used when -use-vendor is set and the +// IDL has a vendored include. +func TestValidJavaVendor(t *testing.T) { + nowBefore := globals.Now + defer func() { + globals.Now = nowBefore + }() + globals.Now = time.Date(2015, 11, 24, 0, 0, 0, 0, time.UTC) + + options := compiler.Options{ + File: includeVendor, + Gen: "java:use_vendor", + Out: outputDir + "/valid_vendor", + Delim: delim, + Recurse: true, + } + if err := compiler.Compile(options); err != nil { + t.Fatal("Unexpected error", err) + } + + files := []FileComparisonPair{ + {"expected/java/valid_vendor/FMyService.java", filepath.Join(outputDir, "valid_vendor", "include_vendor", "java", "FMyService.java")}, + {"expected/java/valid_vendor/MyScopePublisher.java", filepath.Join(outputDir, "valid_vendor", "include_vendor", "java", "MyScopePublisher.java")}, + {"expected/java/valid_vendor/MyScopeSubscriber.java", filepath.Join(outputDir, "valid_vendor", "include_vendor", "java", "MyScopeSubscriber.java")}, + {"expected/java/valid_vendor/VendoredReferences.java", filepath.Join(outputDir, "valid_vendor", "include_vendor", "java", "VendoredReferences.java")}, + {"expected/java/valid_vendor/InvalidData.java", filepath.Join(outputDir, "valid_vendor", "InvalidData.java")}, + } + copyAllFiles(t, files) + compareAllFiles(t, files) + + filesNotToGenerate := []string{ + filepath.Join(filepath.Join(outputDir, "valid_vendor", "vendor_namespace", "java", "Item.java")), + filepath.Join(filepath.Join(outputDir, "valid_vendor", "vendor_namespace", "java", "vendor_namespaceConstants.java")), + filepath.Join(filepath.Join(outputDir, "valid_vendor", "vendor_namespace", "java", "MyEnum.java")), + filepath.Join(filepath.Join(outputDir, "valid_vendor", "vendor_namespace", "java", "FVendoredBase.java")), + } + + assertFilesNotExist(t, filesNotToGenerate) + +} + +func TestValidJavaVendorButNotUseVendor(t *testing.T) { + nowBefore := globals.Now + defer func() { + globals.Now = nowBefore + }() + globals.Now = time.Date(2015, 11, 24, 0, 0, 0, 0, time.UTC) + + options := compiler.Options{ + File: includeVendor, + Gen: "java", + Out: outputDir + "/vendored_but_no_use_vendor", + Delim: delim, + Recurse: true, + } + if err := compiler.Compile(options); err != nil { + t.Fatal("Unexpected error", err) + } + + files := []FileComparisonPair{ + {"expected/java/vendored_but_no_use_vendor/FMyService.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "include_vendor", "java", "FMyService.java")}, + {"expected/java/vendored_but_no_use_vendor/MyScopePublisher.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "include_vendor", "java", "MyScopePublisher.java")}, + {"expected/java/vendored_but_no_use_vendor/MyScopeSubscriber.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "include_vendor", "java", "MyScopeSubscriber.java")}, + {"expected/java/vendored_but_no_use_vendor/VendoredReferences.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "include_vendor", "java", "VendoredReferences.java")}, + {"expected/java/vendored_but_no_use_vendor/InvalidData.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "InvalidData.java")}, + {"expected/java/vendored_but_no_use_vendor/Item.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "vendor_namespace", "java", "Item.java")}, + {"expected/java/vendored_but_no_use_vendor/vendor_namespaceConstants.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "vendor_namespace", "java", "vendor_namespaceConstants.java")}, + {"expected/java/vendored_but_no_use_vendor/MyEnum.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "vendor_namespace", "java", "MyEnum.java")}, + {"expected/java/vendored_but_no_use_vendor/FVendoredBase.java", filepath.Join(outputDir, "vendored_but_no_use_vendor", "vendor_namespace", "java", "FVendoredBase.java")}, + } + copyAllFiles(t, files) + compareAllFiles(t, files) +} + +func TestValidJavaVendorNoPathUsesDefinedNamespace(t *testing.T) { + nowBefore := globals.Now + defer func() { + globals.Now = nowBefore + }() + globals.Now = time.Date(2015, 11, 24, 0, 0, 0, 0, time.UTC) + + options := compiler.Options{ + File: includeVendorNoPath, + Gen: "java:use_vendor", + Out: outputDir + "/valid_vendor_no_path", + Delim: delim, + Recurse: true, + } + if err := compiler.Compile(options); err != nil { + t.Fatal("Unexpected error", err) + } + + files := []FileComparisonPair{ + {"expected/java/valid_vendor_no_path/FMyService.java", filepath.Join(outputDir, "valid_vendor_no_path", "include_vendor_no_path", "java", "FMyService.java")}, + {"expected/java/valid_vendor_no_path/MyScopePublisher.java", filepath.Join(outputDir, "valid_vendor_no_path", "include_vendor_no_path", "java", "MyScopePublisher.java")}, + {"expected/java/valid_vendor_no_path/MyScopeSubscriber.java", filepath.Join(outputDir, "valid_vendor_no_path", "include_vendor_no_path", "java", "MyScopeSubscriber.java")}, + {"expected/java/valid_vendor_no_path/VendoredReferences.java", filepath.Join(outputDir, "valid_vendor_no_path", "include_vendor_no_path", "java", "VendoredReferences.java")}, + {"expected/java/valid_vendor_no_path/InvalidData.java", filepath.Join(outputDir, "valid_vendor_no_path", "InvalidData.java")}, + } + copyAllFiles(t, files) + compareAllFiles(t, files) + + filesNotToGenerate := []string{ + filepath.Join(outputDir, "valid_vendor_no_path", "vendor_namespace", "java", "Item.java"), + filepath.Join(outputDir, "valid_vendor_no_path", "vendor_namespace", "java", "vendor_namespaceConstants.java"), + filepath.Join(outputDir, "valid_vendor_no_path", "vendor_namespace", "java", "MyEnum.java"), + filepath.Join(outputDir, "valid_vendor_no_path", "vendor_namespace", "java", "FVendoredBase.java"), + } + + assertFilesNotExist(t, filesNotToGenerate) +}