├── swift-generator └── src │ ├── test │ └── resources │ │ ├── include_path_1 │ │ └── from_include_path_1.inc │ │ ├── include_path_2 │ │ └── from_include_path_2.inc │ │ ├── include_path_tests │ │ ├── from_same_path.inc │ │ └── test_basic.thrift │ │ └── basic │ │ └── UnionTest.thrift │ └── main │ ├── resources │ └── templates │ │ └── java │ │ ├── regular.st │ │ └── ctor.st │ └── java │ └── com │ └── facebook │ └── swift │ └── generator │ ├── template │ ├── JavaContext.java │ └── BaseJavaContext.java │ ├── util │ └── SwiftInternalStringUtils.java │ ├── SwiftGeneratorTweak.java │ └── swift2thrift │ └── template │ ├── ThriftServiceMetadataRenderer.java │ └── FieldRequirednessRenderer.java ├── .arcconfig ├── notice.md ├── swift-javadoc └── src │ └── main │ └── resources │ └── META-INF │ └── services │ └── javax.annotation.processing.Processor ├── swift-idl-parser ├── src │ ├── test │ │ └── resources │ │ │ ├── const.thrift │ │ │ ├── typedef.thrift │ │ │ └── thrift │ │ │ ├── test │ │ │ ├── ExceptionTest.thrift │ │ │ ├── PythonReservedKeywords.thrift │ │ │ ├── JavaBeansTest.thrift │ │ │ └── StressTest.thrift │ │ │ └── tutorial │ │ │ └── shared.thrift │ └── main │ │ └── java │ │ └── com │ │ └── facebook │ │ └── swift │ │ └── parser │ │ ├── visitor │ │ ├── Nameable.java │ │ ├── DocumentVisitor.java │ │ └── Visitable.java │ │ ├── model │ │ ├── ThriftType.java │ │ ├── ConstValue.java │ │ ├── VoidType.java │ │ ├── Struct.java │ │ ├── Union.java │ │ ├── ThriftException.java │ │ ├── ConstInteger.java │ │ ├── ConstDouble.java │ │ ├── Definition.java │ │ ├── IdentifierType.java │ │ ├── ConstString.java │ │ ├── ConstIdentifier.java │ │ ├── ConstList.java │ │ ├── ConstMap.java │ │ ├── ContainerType.java │ │ ├── ListType.java │ │ ├── SetType.java │ │ ├── Typedef.java │ │ └── StringEnum.java │ │ └── util │ │ └── IntegerEnumFieldList.java └── README.md ├── .gitignore ├── src └── license │ └── LICENSE-HEADER.txt ├── NEWS.md ├── swift-codec └── src │ ├── test │ └── java │ │ └── com │ │ └── facebook │ │ └── swift │ │ └── codec │ │ ├── Fruit.java │ │ ├── generics │ │ ├── GenericThriftStructBean.java │ │ ├── GenericThriftStructField.java │ │ ├── GenericThriftStruct.java │ │ ├── GenericThriftStructFieldBase.java │ │ ├── ConcreteThriftStructDerivedFromGenericField.java │ │ ├── GenericThriftStructBase.java │ │ └── GenericThriftStructBeanBase.java │ │ ├── Letter.java │ │ ├── idlannotations │ │ ├── StructWithIdlAnnotations.java │ │ ├── BeanWithOneIdlAnnotationMapForField.java │ │ ├── ExceptionWithIdlAnnotations.java │ │ └── BeanWithMatchingIdlAnnotationsMapsForField.java │ │ ├── internal │ │ ├── compiler │ │ │ ├── TestCompilerThriftCodecFactory.java │ │ │ └── TestCompilerToReflectionThriftCodecFactory.java │ │ └── reflection │ │ │ ├── TestReflectionThriftCodecFactory.java │ │ │ └── TestReflectionToCompilerThriftCodecFactory.java │ │ └── recursion │ │ ├── CoRecursive.java │ │ ├── WithoutRecursiveAnnotation.java │ │ ├── ViaListElementType.java │ │ ├── ViaNestedListElementType.java │ │ ├── ViaMapKeyAndValueTypes.java │ │ ├── CoRecursiveTreeHelper.java │ │ ├── CoRecursiveHelper.java │ │ ├── CoRecursiveTree.java │ │ └── WithSwiftRecursiveAnnotation.java │ └── main │ └── java │ └── com │ └── facebook │ └── swift │ └── codec │ ├── metadata │ ├── FieldKind.java │ ├── Extractor.java │ ├── Injection.java │ ├── ThriftInjection.java │ ├── ThriftExtraction.java │ ├── MetadataErrorException.java │ ├── MetadataWarningException.java │ ├── ThriftTypeReference.java │ └── MethodInjection.java │ ├── internal │ ├── UnknownEnumValueException.java │ ├── ThriftCodecFactory.java │ ├── compiler │ │ ├── DynamicClassLoader.java │ │ ├── SwiftBytecodeHelper.java │ │ └── byteCode │ │ │ └── CaseStatement.java │ ├── ForCompiler.java │ ├── coercion │ │ ├── ToThrift.java │ │ └── FromThrift.java │ └── builtin │ │ ├── ByteThriftCodec.java │ │ ├── LongThriftCodec.java │ │ ├── ShortThriftCodec.java │ │ ├── BooleanThriftCodec.java │ │ ├── DoubleThriftCodec.java │ │ ├── IntegerThriftCodec.java │ │ └── StringThriftCodec.java │ ├── ThriftOrder.java │ ├── ThriftDocumentation.java │ ├── InternalThriftCodec.java │ └── ThriftProtocolType.java ├── swift-service └── src │ ├── test │ ├── java │ │ └── com │ │ │ └── facebook │ │ │ └── swift │ │ │ ├── service │ │ │ ├── ResultCode.java │ │ │ ├── exceptions │ │ │ │ ├── NonThriftCheckedException.java │ │ │ │ ├── NonThriftUncheckedException.java │ │ │ │ ├── ThriftCheckedException.java │ │ │ │ ├── ThriftUncheckedException.java │ │ │ │ ├── ExceptionServiceClient.java │ │ │ │ └── ThriftCheckedSubclassableException.java │ │ │ ├── oneway │ │ │ │ ├── OneWayServiceClient.java │ │ │ │ ├── OneWayException.java │ │ │ │ ├── OneWayService.java │ │ │ │ ├── OneWayServiceHandler.java │ │ │ │ └── OnewayTest.java │ │ │ ├── annotations │ │ │ │ ├── BaseServiceImplementation.java │ │ │ │ ├── BaseService.java │ │ │ │ ├── DerivedServiceOne.java │ │ │ │ ├── DerivedServiceTwo.java │ │ │ │ ├── CombinedService.java │ │ │ │ ├── SingleDerivedServiceImplementation.java │ │ │ │ ├── MultipleDerivedServiceImplementation.java │ │ │ │ ├── CombinedServiceImplementation.java │ │ │ │ └── MultipleDerivedServiceImplementationWithExplicitAnnotation.java │ │ │ ├── Scribe.java │ │ │ ├── async │ │ │ │ ├── MalformedService.java │ │ │ │ └── AsyncScribe.java │ │ │ ├── SwiftScribe.java │ │ │ ├── ThriftScribeService.java │ │ │ ├── explicitidentifiers │ │ │ │ └── CustomArgument.java │ │ │ └── scribe │ │ │ │ └── ResultCode.java │ │ │ └── generics │ │ │ ├── GenericService.java │ │ │ ├── GenericInterface.java │ │ │ └── GenericStruct.java │ └── resources │ │ ├── scribe.thrift │ │ ├── rsa.crt │ │ └── rsa.key │ └── main │ └── java │ └── com │ └── facebook │ └── swift │ └── service │ ├── RuntimeTException.java │ ├── ThriftServerWorkerExecutor.java │ ├── RuntimeTProtocolException.java │ ├── RuntimeTTransportException.java │ ├── ThriftServerTimer.java │ ├── RuntimeTApplicationException.java │ └── ThriftClientEventHandler.java ├── swift-load-generator └── src │ └── main │ └── java │ └── com │ └── facebook │ └── swift │ └── perf │ └── loadgenerator │ ├── TransportType.java │ ├── Operation.java │ └── LoadError.java ├── swift-annotations ├── src │ └── main │ │ └── java │ │ └── com │ │ └── facebook │ │ └── swift │ │ ├── codec │ │ ├── ThriftIdlAnnotation.java │ │ ├── ThriftEnum.java │ │ ├── ThriftStruct.java │ │ ├── ThriftUnion.java │ │ ├── ThriftUnionId.java │ │ ├── ThriftConstructor.java │ │ └── ThriftEnumValue.java │ │ └── service │ │ ├── ThriftException.java │ │ ├── ThriftService.java │ │ └── ThriftMethod.java └── pom.xml ├── swift-generator-cli └── src │ └── main │ ├── java │ └── com │ │ └── facebook │ │ └── swift │ │ └── generator │ │ └── util │ │ └── ColonParameterSplitter.java │ └── resources │ └── logback.xml ├── CHANGES.md └── swift-maven-plugin └── src └── test └── projects ├── basic ├── idl │ └── scribe.thrift └── pom.xml ├── shortcircuit ├── idl │ └── scribe.thrift └── pom.xml └── namespace_fallback ├── idl └── scribe.thrift └── pom.xml /swift-generator/src/test/resources/include_path_1/from_include_path_1.inc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /swift-generator/src/test/resources/include_path_2/from_include_path_2.inc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /swift-generator/src/test/resources/include_path_tests/from_same_path.inc: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.arcconfig: -------------------------------------------------------------------------------- 1 | { 2 | "project_id" : "swift", 3 | "conduit_uri" : "https://phabricator.fb.com/api/" 4 | } 5 | -------------------------------------------------------------------------------- /notice.md: -------------------------------------------------------------------------------- 1 | Swift Copyright Notices 2 | ======================= 3 | 4 | * Copyright 2012 Facebook, Inc. http://facebook.com 5 | -------------------------------------------------------------------------------- /swift-javadoc/src/main/resources/META-INF/services/javax.annotation.processing.Processor: -------------------------------------------------------------------------------- 1 | com.facebook.swift.javadoc.JavaDocProcessor 2 | -------------------------------------------------------------------------------- /swift-idl-parser/src/test/resources/const.thrift: -------------------------------------------------------------------------------- 1 | namespace java.swift com.facebook.const_test 2 | 3 | const map ABC = { 4 | "B": 1, 5 | "C": 0, 6 | "D": 1, 7 | } 8 | 9 | const list DEF = [ 10 | "D", 11 | "E", 12 | "F", 13 | ] 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.versionsBackup 3 | dependency-reduced-pom.xml 4 | test-output/ 5 | /atlassian-ide-plugin.x 6 | .idea/ 7 | .*.swo 8 | *~ 9 | *.swp 10 | *.iml 11 | *.ipr 12 | *.iws 13 | .DS_Store 14 | .project 15 | .classpath 16 | .settings 17 | eclipse-classes 18 | .arc 19 | .pmd 20 | .pmdruleset 21 | -------------------------------------------------------------------------------- /swift-idl-parser/README.md: -------------------------------------------------------------------------------- 1 | # Project Status: 🚨 Unmaintained 🚨 2 | 3 | This project is archived and no longer maintained. At the time of archiving, 4 | open issues and pull requests were closed and tagged with `2018-05-archive`. 5 | For pre-existing users who need an open source alternative, we recommend taking 6 | a look at [airlift/drift](https://github.com/airlift/drift). 7 | 8 | # Parser for Thrift IDL 9 | -------------------------------------------------------------------------------- /swift-generator/src/test/resources/include_path_tests/test_basic.thrift: -------------------------------------------------------------------------------- 1 | // This test file (in conjuction with config in SwiftGeneratorTest) attempts to finds one include 2 | // from a relative include path, one from an absolute include path, as well as on from the same 3 | // root as the file itself. 4 | 5 | include "from_include_path_1.inc" 6 | include "from_include_path_2.inc" 7 | include "from_same_path.inc" 8 | 9 | // The test code checks that something got generated, so use a dummy struct for at least one 10 | // file to show up 11 | struct Dummy { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /src/license/LICENSE-HEADER.txt: -------------------------------------------------------------------------------- 1 | COPYRIGHT_SECTION 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); you may 4 | not use this file except in compliance with the License. You may obtain 5 | a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 | License for the specific language governing permissions and limitations 13 | under the License. 14 | -------------------------------------------------------------------------------- /swift-idl-parser/src/test/resources/typedef.thrift: -------------------------------------------------------------------------------- 1 | namespace java com.facebook.test 2 | 3 | typedef i32 SomeTypeDef 4 | typedef SomeTypeDef SomeOtherTypeDef 5 | 6 | typedef SomeStruct SomeStructTypeDef 7 | 8 | struct SomeStruct { 9 | 1: i32 intField, 10 | 3: SomeTypeDef tdField, 11 | 4: bool boolField, 12 | 5: SomeStructTypeDef structField, 13 | } 14 | 15 | 16 | exception StrangeException { 17 | 1: string message; 18 | } 19 | 20 | service TestService 21 | { 22 | SomeStruct getStruct( 23 | 1: list listStrings, 24 | 2: i64 i64Value, 25 | 3: SomeTypeDef type, 26 | 4: i32 i32Value) 27 | throws (1:StrangeException se); 28 | } 29 | -------------------------------------------------------------------------------- /NEWS.md: -------------------------------------------------------------------------------- 1 | News 2 | ==== 3 | 4 | * 0.11.0 5 | 6 | Add support for Nifty 0.11.0 receiveTimeout. 7 | 8 | The nifty code now supports two timeouts: 9 | 10 | - receiveTimeout now reflects the amount of time that a client is 11 | willing to wait for the server complete a response. 12 | 13 | - readTimeout is the amount of a time that can pass without the server 14 | sending any data. 15 | 16 | Before 0.11.0, readTimeout had the semantics of receiveTimeout. 17 | 18 | The default value for readTimeout changed from 1 minute to 10 seconds. 19 | 20 | If a client configuration sets thrift.client.read-timeout, this setting 21 | must be changed to be thrift.client.receive-timeout. 22 | 23 | See the Nifty CHANGES.md file for more details. 24 | 25 | -------------------------------------------------------------------------------- /swift-generator/src/main/resources/templates/java/regular.st: -------------------------------------------------------------------------------- 1 | _structbody(context) ::= << 2 | <_constructor(context)> 3 | 4 | }; separator="\n\n"> 5 | >> 6 | 7 | _field(field) ::= << 8 | private ; 9 | 10 | <_fieldAnnotation(field)> 11 | public () { return ; } 12 | 13 | @ThriftField 14 | public void (final ) { this. = ; } 15 | >> 16 | 17 | _constructor(element) ::= << 18 | public () { 19 | } 20 | >> 21 | 22 | _union_body(context) ::= << 23 | <_union_constructor(context)> 24 | 25 | }; separator="\n\n"> 26 | >> 27 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/Fruit.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | public enum Fruit 19 | { 20 | APPLE, BANANA, CHERRY 21 | } 22 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/ResultCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | public enum ResultCode 19 | { 20 | OK, TRY_LATER 21 | } 22 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/visitor/Nameable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.visitor; 17 | 18 | public interface Nameable 19 | { 20 | String getName(); 21 | } 22 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/FieldKind.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | public enum FieldKind 19 | { 20 | THRIFT_FIELD, 21 | THRIFT_UNION_ID; 22 | } 23 | -------------------------------------------------------------------------------- /swift-load-generator/src/main/java/com/facebook/swift/perf/loadgenerator/TransportType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.perf.loadgenerator; 17 | 18 | public enum TransportType 19 | { 20 | FRAMED, 21 | UNFRAMED, 22 | } 23 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ThriftType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | public abstract class ThriftType 19 | { 20 | @Override 21 | public abstract String toString(); 22 | } 23 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/codec/ThriftIdlAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | public @interface ThriftIdlAnnotation 19 | { 20 | String key() default ""; 21 | String value() default ""; 22 | } 23 | -------------------------------------------------------------------------------- /swift-generator/src/main/java/com/facebook/swift/generator/template/JavaContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generator.template; 17 | 18 | public interface JavaContext 19 | { 20 | String getJavaPackage(); 21 | 22 | String getJavaName(); 23 | } 24 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/exceptions/NonThriftCheckedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.exceptions; 17 | 18 | class NonThriftCheckedException extends Exception { 19 | private static final long serialVersionUID = 1L; 20 | } 21 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/oneway/OneWayServiceClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.oneway; 17 | 18 | public interface OneWayServiceClient extends OneWayService, AutoCloseable { 19 | @Override 20 | public void close(); 21 | } 22 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/exceptions/NonThriftUncheckedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.exceptions; 17 | 18 | class NonThriftUncheckedException extends RuntimeException { 19 | private static final long serialVersionUID = 1L; 20 | } 21 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ConstValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | public abstract class ConstValue 19 | { 20 | public abstract Object value(); 21 | 22 | @Override 23 | public abstract String toString(); 24 | } 25 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/UnknownEnumValueException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal; 17 | 18 | public class UnknownEnumValueException extends Exception { 19 | public UnknownEnumValueException(String message) { 20 | super(message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/generics/GenericThriftStructBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.generics; 17 | 18 | import com.facebook.swift.codec.ThriftStruct; 19 | 20 | @ThriftStruct 21 | public final class GenericThriftStructBean extends GenericThriftStructBeanBase 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/generics/GenericThriftStructField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.generics; 17 | 18 | import com.facebook.swift.codec.ThriftStruct; 19 | 20 | @ThriftStruct 21 | public final class GenericThriftStructField extends GenericThriftStructFieldBase 22 | { 23 | } 24 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/oneway/OneWayException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.oneway; 17 | 18 | import com.facebook.swift.codec.ThriftStruct; 19 | 20 | @ThriftStruct 21 | public final class OneWayException extends Exception { 22 | private static final long serialVersionUID = 1L; 23 | } 24 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/exceptions/ThriftCheckedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.exceptions; 17 | 18 | import com.facebook.swift.codec.ThriftStruct; 19 | 20 | @ThriftStruct 21 | public final class ThriftCheckedException extends Exception { 22 | private static final long serialVersionUID = 1L; 23 | } 24 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/BaseServiceImplementation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | public class BaseServiceImplementation implements BaseService 19 | { 20 | @Override 21 | public void fooBase() 22 | { 23 | throw new IllegalStateException("NYI"); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /swift-idl-parser/src/test/resources/thrift/test/ExceptionTest.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | exception MyException { 21 | 1: string msg, 22 | } (message = 'msg') 23 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/exceptions/ThriftUncheckedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.exceptions; 17 | 18 | import com.facebook.swift.codec.ThriftStruct; 19 | 20 | @ThriftStruct 21 | public final class ThriftUncheckedException extends RuntimeException { 22 | private static final long serialVersionUID = 1L; 23 | } 24 | -------------------------------------------------------------------------------- /swift-generator/src/main/resources/templates/java/ctor.st: -------------------------------------------------------------------------------- 1 | _structbody(context) ::= << 2 | <_constructor(context)> 3 | 4 | }; separator="\n\n"> 5 | >> 6 | 7 | _field(field) ::= << 8 | private ; 9 | 10 | <_fieldAnnotation(field)> 11 | public () { return ; } 12 | 13 | public void (final ) { this. = ; } 14 | >> 15 | 16 | _constructor(element) ::= << 17 | @ThriftConstructor 18 | public <_params(element.fields)> { 19 | }; separator="\n"> 20 | } 21 | 22 | public () { 23 | } 24 | >> 25 | 26 | _ctorAssignment(field) ::= << 27 | this. = ; 28 | >> 29 | 30 | _union_body(context) ::= << 31 | <_union_constructor(context)> 32 | 33 | }; separator="\n\n"> 34 | >> 35 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/Extractor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | 20 | abstract class Extractor extends FieldMetadata 21 | { 22 | protected Extractor(ThriftField annotation, FieldKind fieldKind) 23 | { 24 | super(annotation, fieldKind); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/Injection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | 20 | abstract class Injection extends FieldMetadata 21 | { 22 | protected Injection(ThriftField annotation, FieldKind fieldKind) 23 | { 24 | super(annotation, fieldKind); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/VoidType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | 20 | public class VoidType 21 | extends ThriftType 22 | { 23 | @Override 24 | public String toString() 25 | { 26 | return MoreObjects.toStringHelper(this).toString(); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/BaseService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | import com.facebook.swift.service.ThriftService; 20 | 21 | @ThriftService("BaseService") 22 | public interface BaseService 23 | { 24 | @ThriftMethod 25 | public void fooBase(); 26 | } 27 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/Struct.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import java.util.List; 19 | 20 | public class Struct 21 | extends AbstractStruct 22 | { 23 | public Struct(String name, List fields, List annotations) 24 | { 25 | super(name, fields, annotations); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/Union.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import java.util.List; 19 | 20 | public class Union 21 | extends AbstractStruct 22 | { 23 | public Union(String name, List fields, List annotations) 24 | { 25 | super(name, fields, annotations); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/DerivedServiceOne.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | import com.facebook.swift.service.ThriftService; 20 | 21 | @ThriftService("DerivedServiceOne") 22 | public interface DerivedServiceOne extends BaseService 23 | { 24 | @ThriftMethod 25 | public void fooOne(); 26 | } 27 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/DerivedServiceTwo.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | import com.facebook.swift.service.ThriftService; 20 | 21 | @ThriftService("DerivedServiceTwo") 22 | public interface DerivedServiceTwo extends BaseService 23 | { 24 | @ThriftMethod 25 | public void fooTwo(); 26 | } 27 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/generics/GenericService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generics; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | 20 | public class GenericService implements GenericInterface 21 | { 22 | @Override 23 | @ThriftMethod 24 | public GenericStruct echo(GenericStruct genericObject) 25 | { 26 | return genericObject; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/CombinedService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | import com.facebook.swift.service.ThriftService; 20 | 21 | @ThriftService("CombinedService") 22 | public interface CombinedService extends DerivedServiceOne, DerivedServiceTwo 23 | { 24 | @ThriftMethod 25 | public void fooCombined(); 26 | } 27 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/Letter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | public enum Letter 19 | { 20 | A(65), B(66), C(67), D(68); 21 | 22 | private final int asciiValue; 23 | 24 | Letter(int asciiValue) 25 | { 26 | 27 | this.asciiValue = asciiValue; 28 | } 29 | 30 | @ThriftEnumValue 31 | public int getAsciiValue() 32 | { 33 | return asciiValue; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/Scribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import org.apache.thrift.TException; 19 | 20 | import java.io.Closeable; 21 | import java.util.List; 22 | 23 | @ThriftService("scribe") 24 | public interface Scribe extends Closeable 25 | { 26 | @ThriftMethod("Log") 27 | ResultCode log(List messages) throws TException; 28 | 29 | @Override 30 | void close(); 31 | } 32 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/visitor/DocumentVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.visitor; 17 | 18 | import java.io.IOException; 19 | 20 | 21 | /** 22 | * Document visitor to collect information from the Document tree. 23 | */ 24 | public interface DocumentVisitor 25 | { 26 | boolean accept(Visitable visitable); 27 | 28 | void visit(Visitable visitable) throws IOException; 29 | 30 | void finish() throws IOException; 31 | } 32 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/ThriftInjection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | 19 | /** 20 | *

ThriftInjection contains information an injection point for a single thrift field.

21 | * 22 | *

Implementation of this interface are expected to be thread safe.

23 | */ 24 | public interface ThriftInjection 25 | { 26 | short getId(); 27 | 28 | String getName(); 29 | 30 | FieldKind getFieldKind(); 31 | } 32 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/ThriftExtraction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | 19 | /** 20 | *

ThriftExtraction contains information an extraction point for a single thrift field.

21 | * 22 | *

Implementations of this interface are expected to be thread safe.

23 | */ 24 | public interface ThriftExtraction 25 | { 26 | short getId(); 27 | 28 | String getName(); 29 | 30 | FieldKind getFieldKind(); 31 | } 32 | -------------------------------------------------------------------------------- /swift-generator-cli/src/main/java/com/facebook/swift/generator/util/ColonParameterSplitter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generator.util; 17 | 18 | import com.beust.jcommander.converters.IParameterSplitter; 19 | 20 | import java.util.Arrays; 21 | import java.util.List; 22 | 23 | public class ColonParameterSplitter implements IParameterSplitter 24 | { 25 | @Override 26 | public List split(String value) { 27 | return Arrays.asList(value.split(":")); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /swift-generator-cli/src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 22 | 23 | 24 | %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/SingleDerivedServiceImplementation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | public class SingleDerivedServiceImplementation implements DerivedServiceOne 19 | { 20 | @Override 21 | public void fooOne() 22 | { 23 | throw new IllegalStateException("NYI"); 24 | } 25 | 26 | @Override 27 | public void fooBase() 28 | { 29 | throw new IllegalStateException("NYI"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/codec/ThriftEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | @Documented 26 | @Retention(RUNTIME) 27 | @Target({TYPE}) 28 | public @interface ThriftEnum 29 | { 30 | String value() default ""; 31 | } 32 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | Changes 2 | ======= 3 | 4 | * 0.13.0 5 | 6 | - Server overload behavior: you can set the maximum number of queued requests, and server will throw a TApplicationException if the queue length would be exceeded 7 | - swift-generator support for optional fields: optional fields that would otherwise generate into primitive types will used boxed types instead 8 | - swift2thrift-generator support for optional fields: fields annotation as requiredness=OPTIONAL will generate into optional fields in thrift IDL 9 | - BREAKING CHANGE: @ThriftStruct and @ThriftUnion classes used with this release (and all future releases) must all be declared 'final' 10 | - BREAKING CHANGE: The @ThriftField annotation field 'required' (a boolean) was changed to 'requiredness' (an enum covering optional) 11 | - Many bug fixes compared to 0.12.0 12 | 13 | * 0.11.0 14 | 15 | - Add a config option (thrift.client.receive-timeout) to ThriftClientConfig 16 | - Change default value for thrift.client.read-timeout from 1 minute to 10 seconds 17 | - Set default value for thrift.client.receive-timeout to 1 minute 18 | - Add constructors to ThriftClientManager that also take a receiveTimeout. 19 | 20 | 21 | -------------------------------------------------------------------------------- /swift-load-generator/src/main/java/com/facebook/swift/perf/loadgenerator/Operation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.perf.loadgenerator; 17 | 18 | public enum Operation 19 | { 20 | NOOP, 21 | ONEWAY_NOOP, 22 | ASYNC_NOOP, 23 | ADD, 24 | ECHO, 25 | SEND, 26 | RECV, 27 | SEND_RECV, 28 | ONEWAY_SEND, 29 | ONEWAY_THROW, 30 | THROW_UNEXPECTED, 31 | THROW_ERROR, 32 | SLEEP, 33 | ONEWAY_SLEEP, 34 | BAD_BURN, 35 | BAD_SLEEP, 36 | ONEWAY_BURN, 37 | BURN, 38 | } 39 | -------------------------------------------------------------------------------- /swift-service/src/test/resources/scribe.thrift: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/thrift --gen cpp:pure_enums --gen php 2 | 3 | ## Copyright (c) 2007-2008 Facebook 4 | ## 5 | ## Licensed under the Apache License, Version 2.0 (the "License"); 6 | ## you may not use this file except in compliance with the License. 7 | ## You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, software 12 | ## distributed under the License is distributed on an "AS IS" BASIS, 13 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ## See the License for the specific language governing permissions and 15 | ## limitations under the License. 16 | ## 17 | ## See accompanying file LICENSE or visit the Scribe site at: 18 | ## http://developers.facebook.com/scribe/ 19 | 20 | namespace java com.facebook.swift.service.scribe 21 | 22 | enum ResultCode 23 | { 24 | OK, 25 | TRY_LATER 26 | } 27 | 28 | struct LogEntry 29 | { 30 | 1: string category, 31 | 2: string message 32 | } 33 | 34 | service scribe 35 | { 36 | ResultCode Log(1: list messages); 37 | } 38 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ThriftException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; 19 | 20 | import java.util.List; 21 | 22 | @SuppressFBWarnings("NM_CLASS_NOT_EXCEPTION") 23 | public class ThriftException 24 | extends AbstractStruct 25 | { 26 | public ThriftException(String name, List fields, List annotations) 27 | { 28 | super(name, fields, annotations); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /swift-maven-plugin/src/test/projects/basic/idl/scribe.thrift: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/thrift --gen cpp:pure_enums --gen php 2 | 3 | ## Copyright (c) 2007-2008 Facebook 4 | ## 5 | ## Licensed under the Apache License, Version 2.0 (the "License"); 6 | ## you may not use this file except in compliance with the License. 7 | ## You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, software 12 | ## distributed under the License is distributed on an "AS IS" BASIS, 13 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ## See the License for the specific language governing permissions and 15 | ## limitations under the License. 16 | ## 17 | ## See accompanying file LICENSE or visit the Scribe site at: 18 | ## http://developers.facebook.com/scribe/ 19 | 20 | namespace java com.facebook.swift.service.scribe 21 | 22 | enum ResultCode 23 | { 24 | OK, 25 | TRY_LATER 26 | } 27 | 28 | struct LogEntry 29 | { 30 | 1: string category, 31 | 2: string message 32 | } 33 | 34 | service scribe 35 | { 36 | ResultCode Log(1: list messages); 37 | } 38 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/async/MalformedService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.async; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | import com.facebook.swift.service.ThriftService; 20 | 21 | /** 22 | * A broken thrift service interface class, where one of the thrift methods has a parameter of a 23 | * type that is not valid to pass via thrift 24 | */ 25 | @ThriftService 26 | public interface MalformedService 27 | { 28 | @ThriftMethod 29 | void foo(MalformedService bar); 30 | } 31 | -------------------------------------------------------------------------------- /swift-maven-plugin/src/test/projects/shortcircuit/idl/scribe.thrift: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/thrift --gen cpp:pure_enums --gen php 2 | 3 | ## Copyright (c) 2007-2008 Facebook 4 | ## 5 | ## Licensed under the Apache License, Version 2.0 (the "License"); 6 | ## you may not use this file except in compliance with the License. 7 | ## You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, software 12 | ## distributed under the License is distributed on an "AS IS" BASIS, 13 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ## See the License for the specific language governing permissions and 15 | ## limitations under the License. 16 | ## 17 | ## See accompanying file LICENSE or visit the Scribe site at: 18 | ## http://developers.facebook.com/scribe/ 19 | 20 | namespace java com.facebook.swift.service.scribe 21 | 22 | enum ResultCode 23 | { 24 | OK, 25 | TRY_LATER 26 | } 27 | 28 | struct LogEntry 29 | { 30 | 1: string category, 31 | 2: string message 32 | } 33 | 34 | service scribe 35 | { 36 | ResultCode Log(1: list messages); 37 | } 38 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/generics/GenericInterface.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generics; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | import com.facebook.swift.service.ThriftService; 20 | 21 | @ThriftService 22 | public interface GenericInterface 23 | { 24 | @ThriftMethod 25 | GenericStruct echo(GenericStruct gen); 26 | 27 | public static interface Client extends GenericInterface, AutoCloseable 28 | { 29 | @Override 30 | public void close(); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /swift-maven-plugin/src/test/projects/namespace_fallback/idl/scribe.thrift: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/thrift --gen cpp:pure_enums --gen php 2 | 3 | ## Copyright (c) 2007-2008 Facebook 4 | ## 5 | ## Licensed under the Apache License, Version 2.0 (the "License"); 6 | ## you may not use this file except in compliance with the License. 7 | ## You may obtain a copy of the License at 8 | ## 9 | ## http://www.apache.org/licenses/LICENSE-2.0 10 | ## 11 | ## Unless required by applicable law or agreed to in writing, software 12 | ## distributed under the License is distributed on an "AS IS" BASIS, 13 | ## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | ## See the License for the specific language governing permissions and 15 | ## limitations under the License. 16 | ## 17 | ## See accompanying file LICENSE or visit the Scribe site at: 18 | ## http://developers.facebook.com/scribe/ 19 | 20 | namespace java com.facebook.swift.service.scribe 21 | 22 | enum ResultCode 23 | { 24 | OK, 25 | TRY_LATER 26 | } 27 | 28 | struct LogEntry 29 | { 30 | 1: string category, 31 | 2: string message 32 | } 33 | 34 | service scribe 35 | { 36 | ResultCode Log(1: list messages); 37 | } 38 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/service/ThriftException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | 21 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 22 | 23 | /** 24 | * Provides mapping for Thrift method exceptions 25 | */ 26 | @Documented 27 | @Retention(RUNTIME) 28 | public @interface ThriftException 29 | { 30 | Class type(); 31 | 32 | short id(); 33 | 34 | String name() default ""; 35 | } 36 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/generics/GenericThriftStruct.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.generics; 17 | 18 | import com.facebook.swift.codec.ThriftConstructor; 19 | import com.facebook.swift.codec.ThriftField; 20 | import com.facebook.swift.codec.ThriftStruct; 21 | 22 | @ThriftStruct 23 | public final class GenericThriftStruct extends GenericThriftStructBase 24 | { 25 | @ThriftConstructor 26 | public GenericThriftStruct(@ThriftField(1) T genericProperty) 27 | { 28 | super(genericProperty); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/exceptions/ExceptionServiceClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.exceptions; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | import org.apache.thrift.TApplicationException; 20 | 21 | public interface ExceptionServiceClient extends ExceptionService, AutoCloseable { 22 | // Extra method that doesn't exist in the service interface 23 | @ThriftMethod 24 | public void missingMethod() throws TApplicationException; 25 | 26 | @Override 27 | public void close(); 28 | } 29 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/ThriftCodecFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal; 17 | 18 | import com.facebook.swift.codec.ThriftCodec; 19 | import com.facebook.swift.codec.ThriftCodecManager; 20 | import com.facebook.swift.codec.metadata.ThriftStructMetadata; 21 | 22 | /** 23 | * Implementations of this interface are expected to be thread safe. 24 | */ 25 | public interface ThriftCodecFactory 26 | { 27 | ThriftCodec generateThriftTypeCodec(ThriftCodecManager codecManager, ThriftStructMetadata metadata); 28 | } 29 | -------------------------------------------------------------------------------- /swift-generator/src/main/java/com/facebook/swift/generator/util/SwiftInternalStringUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generator.util; 17 | 18 | import com.google.common.base.CharMatcher; 19 | import com.google.common.base.Strings; 20 | 21 | /** 22 | * Dain's fault. 23 | */ 24 | public final class SwiftInternalStringUtils 25 | { 26 | private SwiftInternalStringUtils() 27 | { 28 | } 29 | 30 | public static boolean isBlank(final String str) 31 | { 32 | return CharMatcher.WHITESPACE.removeFrom(Strings.nullToEmpty(str)).length() == 0; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /swift-service/src/test/resources/rsa.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIDGDCCAgACCQDzFwebgl2PsDANBgkqhkiG9w0BAQUFADBOMQswCQYDVQQGEwJY 3 | WDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MQwwCgYDVQQKDANSU0ExDDAKBgNVBAsM 4 | A1JTQTEMMAoGA1UEAwwDUlNBMB4XDTE2MDExNDE5NDYzM1oXDTE3MDExMzE5NDYz 5 | M1owTjELMAkGA1UEBhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEMMAoGA1UE 6 | CgwDUlNBMQwwCgYDVQQLDANSU0ExDDAKBgNVBAMMA1JTQTCCASIwDQYJKoZIhvcN 7 | AQEBBQADggEPADCCAQoCggEBANyeX1NYeawwW5p0LSxURYHanQcEt8JyQW491wZ/ 8 | NnZf8VAIWTELhE+pAz8gQeQRSIAV8h74PsKJDiLtLDXeUev/yhalD3bG0jS2zez4 9 | 1XAM9p37vumOpvAKZz1F1iO180/lndnS6rIaSiJC6G8km16bVQCGJE7PYmkghQmK 10 | SrGsZg6zJck5HLoUCEQkVjZPzATurZUMQ/dCQhrwr+lSh46iIJmVsLBKnPPG9U7I 11 | wonyRHEiu0y4O8F2OB+sZCQ4RVe8OamwJNYlwN8T+guqlhzrwBbudE1TiSct8Pgd 12 | sGtv+/Uea7b9lYV7tNkKir3aD3Og95LY+gHWalO+Uu4IznECAwEAATANBgkqhkiG 13 | 9w0BAQUFAAOCAQEAHkGyaB9q9bZ3Jy8ypXdGzgoDCzmnCXbpFApuLiBOUN9hAyXC 14 | 49jsC9Y2jrZ73WMeUlf9WgFuJ0qMu8lb0kH9rDtfWiyRr0UfatU8WgOKMWOTbzSV 15 | lpkGVFz1wcZos35hRT3j2tuFm4DvfS6n8El6OIhHLN/0RVoexN5JRBVU9R2ngONy 16 | 7uIyxC6ONkm1WTLARZhGH9SOphq0FKZb8k8l9lqhfDNuccbWsZDyrg6yqX/z7jas 17 | VyvOM8bonJ0OXZfOqhM+tchll3HPiSSSVJFva/Bw6Yt7/Zt9Taz3CL3Sc+y9e8tG 18 | 3dObYsJfNJzBSk7Zkeagu4axpbcpz557bINbYQ== 19 | -----END CERTIFICATE----- 20 | -------------------------------------------------------------------------------- /swift-load-generator/src/main/java/com/facebook/swift/perf/loadgenerator/LoadError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.perf.loadgenerator; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | @ThriftStruct(value = "LoadError") 22 | public class LoadError extends Exception 23 | { 24 | private int code; 25 | 26 | @ThriftField(value = 1) 27 | public int getCode() { 28 | return code; 29 | } 30 | 31 | @ThriftField(value = 1) 32 | public void setCode(int code) 33 | { 34 | this.code = code; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/service/ThriftService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | /** 26 | * Marks a class as a service that can be exported with Thrift. 27 | */ 28 | @Documented 29 | @Retention(RUNTIME) 30 | @Target(TYPE) 31 | public @interface ThriftService 32 | { 33 | String value() default ""; 34 | } 35 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/compiler/DynamicClassLoader.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.compiler; 17 | 18 | /** 19 | * A ClassLoader that allows for loading of classes from an array of bytes. 20 | */ 21 | public class DynamicClassLoader extends ClassLoader 22 | { 23 | public DynamicClassLoader(ClassLoader parent) 24 | { 25 | super(parent); 26 | } 27 | 28 | public Class defineClass(String name, byte[] byteCode) 29 | throws ClassFormatError 30 | { 31 | return defineClass(name, byteCode, 0, byteCode.length); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/ThriftOrder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.FIELD; 23 | import static java.lang.annotation.ElementType.METHOD; 24 | import static java.lang.annotation.ElementType.TYPE; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | @Documented 28 | @Retention(RUNTIME) 29 | @Target({TYPE, METHOD, FIELD}) 30 | public @interface ThriftOrder 31 | { 32 | int value(); 33 | } 34 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/MetadataErrorException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | public class MetadataErrorException extends RuntimeException 19 | { 20 | private static final long serialVersionUID = 1L; 21 | 22 | public MetadataErrorException(String formatString, Object... args) 23 | { 24 | super("Error: " + String.format(formatString, args)); 25 | } 26 | 27 | public MetadataErrorException(Throwable cause, String formatString, Object... args) 28 | { 29 | super("Error: " + String.format(formatString, args), cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /swift-idl-parser/src/test/resources/thrift/test/PythonReservedKeywords.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | namespace py thrift.test.PythonReservedKeywords 21 | 22 | enum from 23 | { 24 | from = 1 25 | } 26 | 27 | typedef i64 from 28 | 29 | struct from 30 | { 31 | 1: string from 32 | } 33 | 34 | exception from { 35 | 1: string from 36 | } 37 | 38 | service from 39 | { 40 | list from(1: list thing, 2:from from) 41 | } 42 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/codec/ThriftStruct.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | @Documented 26 | @Retention(RUNTIME) 27 | @Target({TYPE}) 28 | public @interface ThriftStruct 29 | { 30 | String value() default ""; 31 | 32 | Class builder() default void.class; 33 | 34 | ThriftIdlAnnotation[] idlAnnotations() default {}; 35 | } 36 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/codec/ThriftUnion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.TYPE; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | @Documented 26 | @Retention(RUNTIME) 27 | @Target({TYPE}) 28 | public @interface ThriftUnion 29 | { 30 | String value() default ""; 31 | 32 | Class builder() default void.class; 33 | 34 | ThriftIdlAnnotation[] idlAnnotations() default {}; 35 | } 36 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/MetadataWarningException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | public class MetadataWarningException extends RuntimeException 19 | { 20 | private static final long serialVersionUID = 1L; 21 | 22 | public MetadataWarningException(String formatString, Object... args) 23 | { 24 | super("Warning: " + String.format(formatString, args)); 25 | } 26 | 27 | public MetadataWarningException(Throwable cause, String formatString, Object... args) 28 | { 29 | super("Warning: " + String.format(formatString, args), cause); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/oneway/OneWayService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.oneway; 17 | 18 | import com.facebook.swift.service.ThriftMethod; 19 | import com.facebook.swift.service.ThriftService; 20 | import org.apache.thrift.TException; 21 | 22 | @ThriftService 23 | public interface OneWayService 24 | { 25 | @ThriftMethod 26 | public void verifyConnectionState() throws TException; 27 | 28 | @ThriftMethod(oneway = true) 29 | public void onewayMethod() throws TException; 30 | 31 | @ThriftMethod(oneway = true) 32 | public void onewayThrow() throws TException, OneWayException; 33 | } 34 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/codec/ThriftUnionId.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.FIELD; 23 | import static java.lang.annotation.ElementType.METHOD; 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 25 | 26 | /** 27 | * Marks a field or method as the field containing the state of an union. 28 | */ 29 | @Documented 30 | @Retention(RUNTIME) 31 | @Target({METHOD, FIELD}) 32 | public @interface ThriftUnionId 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/MultipleDerivedServiceImplementation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | public class MultipleDerivedServiceImplementation implements DerivedServiceOne, DerivedServiceTwo 19 | { 20 | @Override 21 | public void fooOne() 22 | { 23 | throw new IllegalStateException("NYI"); 24 | } 25 | 26 | @Override 27 | public void fooTwo() 28 | { 29 | throw new IllegalStateException("NYI"); 30 | } 31 | 32 | @Override 33 | public void fooBase() 34 | { 35 | throw new IllegalStateException("NYI"); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/ThriftDocumentation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.FIELD; 23 | import static java.lang.annotation.ElementType.METHOD; 24 | import static java.lang.annotation.ElementType.TYPE; 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 26 | 27 | @Documented 28 | @Retention(RUNTIME) 29 | @Target({TYPE, METHOD, FIELD}) 30 | public @interface ThriftDocumentation 31 | { 32 | String[] value() default {}; 33 | } 34 | -------------------------------------------------------------------------------- /swift-idl-parser/src/test/resources/thrift/test/JavaBeansTest.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | namespace java thrift.test 21 | 22 | struct OneOfEachBeans { 23 | 1: bool boolean_field, 24 | 2: byte a_bite, 25 | 3: i16 integer16, 26 | 4: i32 integer32, 27 | 5: i64 integer64, 28 | 6: double double_precision, 29 | 7: string some_characters, 30 | 8: binary base64, 31 | 9: list byte_list, 32 | 10: list i16_list, 33 | 11: list i64_list 34 | } 35 | -------------------------------------------------------------------------------- /swift-service/src/main/java/com/facebook/swift/service/RuntimeTException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import org.apache.thrift.TException; 19 | 20 | /** 21 | * Runtime equivalent of TException. If a swift client receives a TException 22 | * for a method that doesn't declare TException to be thrown, the underlying 23 | * exception is wrapped in this class and rethrown. 24 | */ 25 | public class RuntimeTException extends RuntimeException 26 | { 27 | private static final long serialVersionUID = 1L; 28 | 29 | public RuntimeTException(String message, TException cause) 30 | { 31 | super(message, cause); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/SwiftScribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import java.util.ArrayList; 19 | import java.util.List; 20 | 21 | public class SwiftScribe implements Scribe 22 | { 23 | private final List messages = new ArrayList<>(); 24 | 25 | public List getMessages() 26 | { 27 | return messages; 28 | } 29 | 30 | @Override 31 | public ResultCode log(List messages) 32 | { 33 | this.messages.addAll(messages); 34 | return ResultCode.OK; 35 | } 36 | 37 | @Override 38 | public void close() 39 | { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /swift-idl-parser/src/test/resources/thrift/test/StressTest.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | namespace cpp test.stress 21 | 22 | service Service { 23 | 24 | void echoVoid(), 25 | byte echoByte(1: byte arg), 26 | i32 echoI32(1: i32 arg), 27 | i64 echoI64(1: i64 arg), 28 | string echoString(1: string arg), 29 | list echoList(1: list arg), 30 | set echoSet(1: set arg), 31 | map echoMap(1: map arg), 32 | } 33 | 34 | -------------------------------------------------------------------------------- /swift-service/src/main/java/com/facebook/swift/service/ThriftServerWorkerExecutor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.FIELD; 24 | import static java.lang.annotation.ElementType.METHOD; 25 | import static java.lang.annotation.ElementType.PARAMETER; 26 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 27 | 28 | @BindingAnnotation 29 | @Retention(RUNTIME) 30 | @Target({METHOD, FIELD, PARAMETER}) 31 | public @interface ThriftServerWorkerExecutor 32 | { 33 | } 34 | -------------------------------------------------------------------------------- /swift-generator/src/test/resources/basic/UnionTest.thrift: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/thrift -java 2 | 3 | /** 4 | * Licensed to the Apache Software Foundation (ASF) under one 5 | * or more contributor license agreements. See the NOTICE file 6 | * distributed with this work for additional information 7 | * regarding copyright ownership. The ASF licenses this file 8 | * to you under the Apache License, Version 2.0 (the 9 | * "License"); you may not use this file except in compliance 10 | * with the License. You may obtain a copy of the License at 11 | * 12 | * http://www.apache.org/licenses/LICENSE-2.0 13 | * 14 | * Unless required by applicable law or agreed to in writing, software 15 | * distributed under the License is distributed on an "AS IS" BASIS, 16 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 | * See the License for the specific language governing permissions and 18 | * limitations under the License. 19 | */ 20 | 21 | union foo_unique_types { 22 | 1: string bar; 23 | 2: i32 baz; 24 | } 25 | 26 | union foo_duplicate_types { 27 | 1: i32 bar; 28 | 2: i32 baz; 29 | } 30 | 31 | union foo_same_erasure { 32 | 1: list bar; 33 | 2: list baz; 34 | } 35 | 36 | union foo_complicated_container { 37 | 1: list> bar; 38 | 2: list> baz; 39 | } 40 | -------------------------------------------------------------------------------- /swift-idl-parser/src/test/resources/thrift/tutorial/shared.thrift: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one 3 | * or more contributor license agreements. See the NOTICE file 4 | * distributed with this work for additional information 5 | * regarding copyright ownership. The ASF licenses this file 6 | * to you under the Apache License, Version 2.0 (the 7 | * "License"); you may not use this file except in compliance 8 | * with the License. You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, 13 | * software distributed under the License is distributed on an 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | * KIND, either express or implied. See the License for the 16 | * specific language governing permissions and limitations 17 | * under the License. 18 | */ 19 | 20 | /** 21 | * This Thrift file can be included by other Thrift files that want to share 22 | * these definitions. 23 | */ 24 | 25 | namespace cpp shared 26 | namespace java shared 27 | namespace perl shared 28 | namespace lua shared 29 | 30 | struct SharedStruct { 31 | 1: i32 key 32 | 2: string value 33 | } 34 | 35 | service SharedService { 36 | SharedStruct getStruct(1: i32 key) 37 | } 38 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/oneway/OneWayServiceHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.oneway; 17 | 18 | import org.apache.thrift.TException; 19 | 20 | public class OneWayServiceHandler implements OneWayService 21 | { 22 | @Override 23 | public void verifyConnectionState() throws TException { 24 | // do nothing, used only to verify two-way communication still works 25 | } 26 | 27 | @Override 28 | public void onewayMethod() throws TException { 29 | return; 30 | } 31 | 32 | @Override 33 | public void onewayThrow() throws TException, OneWayException { 34 | throw new OneWayException(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/service/ThriftMethod.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.METHOD; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | /** 26 | * Marks a method to be exported in a Thrift service. 27 | */ 28 | @Documented 29 | @Retention(RUNTIME) 30 | @Target(METHOD) 31 | public @interface ThriftMethod 32 | { 33 | String value() default ""; 34 | 35 | boolean oneway() default false; 36 | 37 | ThriftException[] exception() default {}; 38 | } 39 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/async/AsyncScribe.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.async; 17 | 18 | import com.facebook.swift.service.LogEntry; 19 | import com.facebook.swift.service.ResultCode; 20 | import com.facebook.swift.service.ThriftMethod; 21 | import com.facebook.swift.service.ThriftService; 22 | import com.google.common.util.concurrent.ListenableFuture; 23 | import org.apache.thrift.TException; 24 | 25 | import java.util.List; 26 | 27 | @ThriftService 28 | public interface AsyncScribe extends AutoCloseable 29 | { 30 | @ThriftMethod(value = "Log") 31 | public ListenableFuture log(List logEntries) 32 | throws TException; 33 | } 34 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/idlannotations/StructWithIdlAnnotations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.idlannotations; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftIdlAnnotation; 20 | import com.facebook.swift.codec.ThriftStruct; 21 | 22 | @ThriftStruct( 23 | idlAnnotations = { 24 | @ThriftIdlAnnotation(key = "testkey1", value = "testvalue1"), 25 | @ThriftIdlAnnotation(key = "testkey2", value = "testvalue2"), 26 | } 27 | ) 28 | public class StructWithIdlAnnotations 29 | { 30 | @ThriftField(1) 31 | public String message; 32 | 33 | @ThriftField(2) 34 | public int type; 35 | } 36 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ConstInteger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | 20 | public class ConstInteger 21 | extends ConstValue 22 | { 23 | private final long value; 24 | 25 | public ConstInteger(long value) 26 | { 27 | this.value = value; 28 | } 29 | 30 | @Override 31 | public Long value() 32 | { 33 | return value; 34 | } 35 | 36 | @Override 37 | public String toString() 38 | { 39 | return MoreObjects.toStringHelper(this) 40 | .add("value", value) 41 | .toString(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/ThriftTypeReference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | import com.facebook.swift.codec.ThriftProtocolType; 19 | 20 | import java.lang.reflect.Type; 21 | 22 | /** 23 | * An interface to either a resolved {@link ThriftType} or the information to compute one. 24 | * 25 | * Used when computing struct/union metadata, as a placeholder for field types that might 26 | * not be directly resolvable yet (in cases of recursive types). 27 | */ 28 | public interface ThriftTypeReference 29 | { 30 | Type getJavaType(); 31 | 32 | ThriftProtocolType getProtocolType(); 33 | 34 | boolean isRecursive(); 35 | 36 | ThriftType get(); 37 | } 38 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ConstDouble.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | 20 | public class ConstDouble 21 | extends ConstValue 22 | { 23 | private final double value; 24 | 25 | public ConstDouble(double value) 26 | { 27 | this.value = value; 28 | } 29 | 30 | @Override 31 | public Double value() 32 | { 33 | return value; 34 | } 35 | 36 | @Override 37 | public String toString() 38 | { 39 | return MoreObjects.toStringHelper(this) 40 | .add("value", value) 41 | .toString(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/Definition.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.facebook.swift.parser.visitor.DocumentVisitor; 19 | import com.facebook.swift.parser.visitor.Nameable; 20 | import com.facebook.swift.parser.visitor.Visitable; 21 | 22 | import java.io.IOException; 23 | 24 | public abstract class Definition implements Visitable, Nameable 25 | { 26 | @Override 27 | public void visit(final DocumentVisitor visitor) throws IOException 28 | { 29 | Visitable.Utils.visit(visitor, this); 30 | } 31 | 32 | @Override 33 | public abstract String getName(); 34 | 35 | @Override 36 | public abstract String toString(); 37 | } 38 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/InternalThriftCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 24 | import static java.lang.annotation.ElementType.FIELD; 25 | import static java.lang.annotation.ElementType.METHOD; 26 | import static java.lang.annotation.ElementType.PARAMETER; 27 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 28 | 29 | @Target({ METHOD, CONSTRUCTOR, FIELD, PARAMETER }) 30 | @Retention(RUNTIME) 31 | @BindingAnnotation 32 | public @interface InternalThriftCodec { 33 | } 34 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/ForCompiler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 24 | import static java.lang.annotation.ElementType.FIELD; 25 | import static java.lang.annotation.ElementType.METHOD; 26 | import static java.lang.annotation.ElementType.PARAMETER; 27 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 28 | 29 | @Target({ METHOD, CONSTRUCTOR, FIELD, PARAMETER }) 30 | @Retention(RUNTIME) 31 | @BindingAnnotation 32 | public @interface ForCompiler 33 | { 34 | } 35 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/util/IntegerEnumFieldList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.util; 17 | 18 | import com.facebook.swift.parser.model.IntegerEnumField; 19 | 20 | import java.util.ArrayList; 21 | 22 | public class IntegerEnumFieldList extends ArrayList 23 | { 24 | public long getNextImplicitEnumerationValue() 25 | { 26 | int lastFieldIndex = size() - 1; 27 | if (lastFieldIndex < 0) { 28 | // No previous values to derive from, and thrift enumerations start at zero by default 29 | return 0; 30 | } 31 | IntegerEnumField lastField = get(lastFieldIndex); 32 | return lastField.getValue() + 1; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/codec/ThriftConstructor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.CONSTRUCTOR; 23 | import static java.lang.annotation.ElementType.METHOD; 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 25 | 26 | /** 27 | * The constructor Thrift should use when creating the class. This annotation is also applied to 28 | * the factory method of a builder class. 29 | */ 30 | @Documented 31 | @Retention(RUNTIME) 32 | @Target({METHOD, CONSTRUCTOR}) 33 | public @interface ThriftConstructor 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /swift-service/src/main/java/com/facebook/swift/service/RuntimeTProtocolException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import org.apache.thrift.protocol.TProtocolException; 19 | 20 | /** 21 | * Runtime equivalent of TProtocolException. If a swift client receives a 22 | * TProtocolException for a method that doesn't declare TProtocolException 23 | * to be thrown, the underlying exception is wrapped in this class and 24 | * rethrown. 25 | */ 26 | public class RuntimeTProtocolException extends RuntimeTException 27 | { 28 | private static final long serialVersionUID = 1L; 29 | 30 | public RuntimeTProtocolException(String message, TProtocolException cause) 31 | { 32 | super(message, cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /swift-annotations/src/main/java/com/facebook/swift/codec/ThriftEnumValue.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.METHOD; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | /** 26 | * Marks the method of a Thrift enum that will return the value of the enum constant in Thrift. 27 | * This must be a public, non-static, no-arg method that returns an int or Integer. This method 28 | * must return a constant value. 29 | */ 30 | @Documented 31 | @Retention(RUNTIME) 32 | @Target(METHOD) 33 | public @interface ThriftEnumValue 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /swift-service/src/main/java/com/facebook/swift/service/RuntimeTTransportException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import org.apache.thrift.transport.TTransportException; 19 | 20 | /** 21 | * Runtime equivalent of TTransportException. If a swift client receives a 22 | * TTransportException for a method that doesn't declare TTransportException 23 | * to be thrown, the underlying exception is wrapped in this class and 24 | * rethrown. 25 | */ 26 | public class RuntimeTTransportException extends RuntimeTException 27 | { 28 | private static final long serialVersionUID = 1L; 29 | 30 | public RuntimeTTransportException(String message, TTransportException cause) 31 | { 32 | super(message, cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /swift-service/src/main/java/com/facebook/swift/service/ThriftServerTimer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import com.google.inject.BindingAnnotation; 19 | 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.FIELD; 24 | import static java.lang.annotation.ElementType.METHOD; 25 | import static java.lang.annotation.ElementType.PARAMETER; 26 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 27 | 28 | /*** 29 | * Annotation for the netty Timer to be shared by all guice-injected ThriftServers 30 | */ 31 | @BindingAnnotation 32 | @Retention(RUNTIME) 33 | @Target({FIELD, PARAMETER, METHOD}) 34 | public @interface ThriftServerTimer { 35 | } 36 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/CombinedServiceImplementation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | public class CombinedServiceImplementation implements CombinedService 19 | { 20 | @Override 21 | public void fooCombined() 22 | { 23 | throw new IllegalStateException("NYI"); 24 | } 25 | 26 | @Override 27 | public void fooOne() 28 | { 29 | throw new IllegalStateException("NYI"); 30 | } 31 | 32 | @Override 33 | public void fooTwo() 34 | { 35 | throw new IllegalStateException("NYI"); 36 | } 37 | 38 | @Override 39 | public void fooBase() 40 | { 41 | throw new IllegalStateException("NYI"); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /swift-service/src/main/java/com/facebook/swift/service/RuntimeTApplicationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import org.apache.thrift.TApplicationException; 19 | 20 | /** 21 | * Runtime equivalent of TApplicationException. If a swift client receives a 22 | * TApplicationException for a method that doesn't declare 23 | * TApplicationException to be thrown, the underlying exception is wrapped in 24 | * this class and rethrown. 25 | */ 26 | public class RuntimeTApplicationException extends RuntimeTException 27 | { 28 | private static final long serialVersionUID = 1L; 29 | 30 | public RuntimeTApplicationException(String message, TApplicationException cause) 31 | { 32 | super(message, cause); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/coercion/ToThrift.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.coercion; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.METHOD; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | /** 26 | * Marks a method as being a conversion to a native Thrift type from a Java Type. A method with 27 | * this annotation must be public, static, with a single parameter of any Java type, and must return 28 | * a native Thrift type. 29 | */ 30 | @Documented 31 | @Retention(RUNTIME) 32 | @Target({METHOD}) 33 | public @interface ToThrift 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/coercion/FromThrift.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.coercion; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.Retention; 20 | import java.lang.annotation.Target; 21 | 22 | import static java.lang.annotation.ElementType.METHOD; 23 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 24 | 25 | /** 26 | * Marks a method as being a conversion from a native Thrift type to a Java Type. A method with 27 | * this annotation must be public, static, with a single parameter of a native Thrift type, and can 28 | * return any Java type other than void. 29 | */ 30 | @Documented 31 | @Retention(RUNTIME) 32 | @Target({METHOD}) 33 | public @interface FromThrift 34 | { 35 | } 36 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/generics/GenericThriftStructFieldBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.generics; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | 20 | import java.util.Objects; 21 | 22 | public class GenericThriftStructFieldBase 23 | { 24 | @ThriftField(1) 25 | public T genericField; 26 | 27 | @Override 28 | public boolean equals(Object obj) 29 | { 30 | if (obj == this) { 31 | return true; 32 | } 33 | if (obj == null || getClass() != obj.getClass()) { 34 | return false; 35 | } 36 | GenericThriftStructFieldBase other = (GenericThriftStructFieldBase) obj; 37 | return Objects.equals(genericField, other.genericField); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/ThriftScribeService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import com.facebook.swift.service.scribe.LogEntry; 19 | import com.facebook.swift.service.scribe.ResultCode; 20 | import com.facebook.swift.service.scribe.scribe; 21 | 22 | import java.util.ArrayList; 23 | import java.util.List; 24 | 25 | public class ThriftScribeService implements scribe.Iface 26 | { 27 | private final List messages = new ArrayList<>(); 28 | 29 | public List getMessages() 30 | { 31 | return messages; 32 | } 33 | 34 | @Override 35 | public ResultCode Log(List messages) 36 | { 37 | this.messages.addAll(messages); 38 | return ResultCode.OK; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/ThriftProtocolType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec; 17 | 18 | public enum ThriftProtocolType 19 | { 20 | UNKNOWN((byte) 0), 21 | BOOL((byte) 2), 22 | BYTE((byte) 3), 23 | DOUBLE((byte) 4), 24 | I16((byte) 6), 25 | I32((byte) 8), 26 | I64((byte) 10), 27 | STRING((byte) 11), 28 | STRUCT((byte) 12), 29 | MAP((byte) 13), 30 | SET((byte) 14), 31 | LIST((byte) 15), 32 | ENUM((byte) 8), // same as I32 type 33 | BINARY((byte) 11); // same as STRING type 34 | 35 | private final byte type; 36 | 37 | private ThriftProtocolType(byte type) 38 | { 39 | this.type = type; 40 | } 41 | 42 | public byte getType() 43 | { 44 | return type; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/generics/GenericStruct.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generics; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.Objects; 22 | 23 | @ThriftStruct 24 | public final class GenericStruct 25 | { 26 | @ThriftField(1) 27 | public T genericField; 28 | 29 | @Override 30 | public boolean equals(Object obj) 31 | { 32 | if (obj == null) { 33 | return false; 34 | } 35 | if (obj == this || getClass() != obj.getClass()) { 36 | return true; 37 | } 38 | GenericStruct other = (GenericStruct) obj; 39 | return Objects.equals(genericField, other.genericField); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/explicitidentifiers/CustomArgument.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.explicitidentifiers; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | @ThriftStruct 22 | public final class CustomArgument 23 | { 24 | public CustomArgument() 25 | { 26 | this.integerField = 0; 27 | this.stringField = null; 28 | } 29 | 30 | public CustomArgument(int integerField, String stringField) 31 | { 32 | this.integerField = integerField; 33 | this.stringField = stringField; 34 | } 35 | 36 | @ThriftField(value = 1) 37 | public int integerField; 38 | 39 | @ThriftField(value = 2) 40 | public String stringField; 41 | } 42 | -------------------------------------------------------------------------------- /swift-generator/src/main/java/com/facebook/swift/generator/SwiftGeneratorTweak.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generator; 17 | 18 | /** 19 | * Code generation tweaks. 20 | */ 21 | public enum SwiftGeneratorTweak 22 | { 23 | ADD_THRIFT_EXCEPTION, // Add TException to generated method signatures 24 | EXTEND_RUNTIME_EXCEPTION, // Make generated exceptions extend RuntimeException instead of Exception 25 | ADD_CLOSEABLE_INTERFACE, // Make generated Services extend Closeable and add a close() method 26 | USE_PLAIN_JAVA_NAMESPACE, // Use the java namespace, not the java.swift namespace 27 | FALLBACK_TO_PLAIN_JAVA_NAMESPACE // First try to use java.swift namespace if it is present in IDL, 28 | // otherwise use the java namespace 29 | } 30 | 31 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/IdentifierType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | 20 | import static com.google.common.base.Preconditions.checkNotNull; 21 | 22 | public class IdentifierType 23 | extends ThriftType 24 | { 25 | private final String name; 26 | 27 | public IdentifierType(String name) 28 | { 29 | this.name = checkNotNull(name, "name"); 30 | } 31 | 32 | public String getName() 33 | { 34 | return name; 35 | } 36 | 37 | @Override 38 | public String toString() 39 | { 40 | return MoreObjects.toStringHelper(this) 41 | .add("name", name) 42 | .toString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /swift-generator/src/main/java/com/facebook/swift/generator/template/BaseJavaContext.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generator.template; 17 | 18 | import com.facebook.swift.generator.SwiftDocumentContext; 19 | 20 | import java.net.URI; 21 | 22 | public abstract class BaseJavaContext implements JavaContext { 23 | 24 | protected final SwiftDocumentContext swiftDocumentContext; 25 | 26 | public BaseJavaContext(SwiftDocumentContext swiftDocumentContext) { 27 | this.swiftDocumentContext = swiftDocumentContext; 28 | } 29 | 30 | public String getSourceIDLPath() throws Exception { 31 | URI inputBase = swiftDocumentContext.getSwiftGeneratorConfig().getInputBase(); 32 | URI idlUri = swiftDocumentContext.getThriftIdlUri(); 33 | return inputBase.relativize(idlUri).getPath(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ConstString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | 20 | import static com.google.common.base.Preconditions.checkNotNull; 21 | 22 | public class ConstString 23 | extends ConstValue 24 | { 25 | private final String value; 26 | 27 | public ConstString(String value) 28 | { 29 | this.value = checkNotNull(value, "value"); 30 | } 31 | 32 | @Override 33 | public String value() 34 | { 35 | return value; 36 | } 37 | 38 | @Override 39 | public String toString() 40 | { 41 | return MoreObjects.toStringHelper(this) 42 | .add("value", value) 43 | .toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/annotations/MultipleDerivedServiceImplementationWithExplicitAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.annotations; 17 | 18 | import com.facebook.swift.service.ThriftService; 19 | 20 | @ThriftService("MultipleDerivedServiceImplementation") 21 | public class MultipleDerivedServiceImplementationWithExplicitAnnotation implements DerivedServiceOne, DerivedServiceTwo 22 | { 23 | @Override 24 | public void fooOne() 25 | { 26 | throw new IllegalStateException("NYI"); 27 | } 28 | 29 | @Override 30 | public void fooTwo() 31 | { 32 | throw new IllegalStateException("NYI"); 33 | } 34 | 35 | @Override 36 | public void fooBase() 37 | { 38 | throw new IllegalStateException("NYI"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/internal/compiler/TestCompilerThriftCodecFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.compiler; 17 | 18 | import com.facebook.swift.codec.AbstractThriftCodecManagerTest; 19 | import com.facebook.swift.codec.ThriftCodecManager; 20 | import org.testng.annotations.Test; 21 | 22 | @Test 23 | public class TestCompilerThriftCodecFactory extends AbstractThriftCodecManagerTest 24 | { 25 | private final ThriftCodecManager manager = new ThriftCodecManager(new CompilerThriftCodecFactory(true)); 26 | 27 | @Override 28 | public ThriftCodecManager createReadCodecManager() 29 | { 30 | return manager; 31 | } 32 | 33 | @Override 34 | public ThriftCodecManager createWriteCodecManager() 35 | { 36 | return manager; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ConstIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | 20 | import static com.google.common.base.Preconditions.checkNotNull; 21 | 22 | public class ConstIdentifier 23 | extends ConstValue 24 | { 25 | private final String value; 26 | 27 | public ConstIdentifier(String value) 28 | { 29 | this.value = checkNotNull(value, "value"); 30 | } 31 | 32 | @Override 33 | public String value() 34 | { 35 | return value; 36 | } 37 | 38 | @Override 39 | public String toString() 40 | { 41 | return MoreObjects.toStringHelper(this) 42 | .add("value", value) 43 | .toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/internal/reflection/TestReflectionThriftCodecFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.reflection; 17 | 18 | import com.facebook.swift.codec.AbstractThriftCodecManagerTest; 19 | import com.facebook.swift.codec.ThriftCodecManager; 20 | 21 | import org.testng.annotations.Test; 22 | 23 | @Test 24 | public class TestReflectionThriftCodecFactory extends AbstractThriftCodecManagerTest 25 | { 26 | private final ThriftCodecManager manager = new ThriftCodecManager(new ReflectionThriftCodecFactory()); 27 | 28 | @Override 29 | public ThriftCodecManager createReadCodecManager() 30 | { 31 | return manager; 32 | } 33 | 34 | @Override 35 | public ThriftCodecManager createWriteCodecManager() 36 | { 37 | return manager; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /swift-maven-plugin/src/test/projects/basic/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.facebook.swift.its 6 | basic 7 | 1.0 8 | 9 | 10 | 11 | 12 | com.facebook.mojo 13 | swift-maven-plugin 14 | ${it-plugin.version} 15 | 16 | 17 | 18 | generate 19 | 20 | 21 | 22 | 23 | 24 | ${project.basedir}/idl 25 | 26 | *.thrift 27 | 28 | 29 | ${project.groupId}.test 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /swift-maven-plugin/src/test/projects/shortcircuit/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.facebook.swift.its 6 | basic 7 | 1.0 8 | 9 | 10 | 11 | 12 | com.facebook.mojo 13 | swift-maven-plugin 14 | ${it-plugin.version} 15 | 16 | 17 | 18 | generate 19 | 20 | 21 | 22 | 23 | 24 | ${project.basedir}/idl 25 | 26 | scribe.thrift 27 | 28 | 29 | ${project.groupId}.test 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /swift-maven-plugin/src/test/projects/namespace_fallback/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | com.facebook.swift.its 6 | basic 7 | 1.0 8 | 9 | 10 | 11 | 12 | com.facebook.mojo 13 | swift-maven-plugin 14 | ${it-plugin.version} 15 | 16 | 17 | 18 | generate 19 | 20 | 21 | 22 | 23 | 24 | ${project.basedir}/idl 25 | 26 | *.thrift 27 | 28 | 29 | true 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/CoRecursive.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.Objects; 22 | 23 | @ThriftStruct 24 | public class CoRecursive 25 | { 26 | @ThriftField(1) 27 | public CoRecursiveHelper child; 28 | 29 | @ThriftField(2) 30 | public String data; 31 | 32 | @Override 33 | public boolean equals(Object obj) 34 | { 35 | if (this == obj) { 36 | return true; 37 | } 38 | if (obj == null || getClass() != obj.getClass()) { 39 | return false; 40 | } 41 | 42 | final CoRecursive that = (CoRecursive) obj; 43 | 44 | return Objects.equals(data, that.data) && 45 | Objects.equals(child, that.child); 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/idlannotations/BeanWithOneIdlAnnotationMapForField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.idlannotations; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftIdlAnnotation; 20 | import com.facebook.swift.codec.ThriftStruct; 21 | 22 | @ThriftStruct 23 | public class BeanWithOneIdlAnnotationMapForField 24 | { 25 | private int type; 26 | 27 | @ThriftField(1) 28 | public String message; 29 | 30 | @ThriftField(value = 2, idlAnnotations = { 31 | @ThriftIdlAnnotation(key = "testkey1", value = "testvalue1"), 32 | @ThriftIdlAnnotation(key = "testkey2", value = "testvalue2") 33 | }) 34 | public int getType() 35 | { 36 | return type; 37 | } 38 | 39 | @ThriftField 40 | public void setType(int type) 41 | { 42 | this.type = type; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/internal/compiler/TestCompilerToReflectionThriftCodecFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.compiler; 17 | 18 | import com.facebook.swift.codec.AbstractThriftCodecManagerTest; 19 | import com.facebook.swift.codec.ThriftCodecManager; 20 | import com.facebook.swift.codec.internal.reflection.ReflectionThriftCodecFactory; 21 | 22 | import org.testng.annotations.Test; 23 | 24 | @Test 25 | public class TestCompilerToReflectionThriftCodecFactory extends AbstractThriftCodecManagerTest 26 | { 27 | @Override 28 | public ThriftCodecManager createReadCodecManager() 29 | { 30 | return new ThriftCodecManager(new ReflectionThriftCodecFactory()); 31 | } 32 | 33 | @Override 34 | public ThriftCodecManager createWriteCodecManager() 35 | { 36 | return new ThriftCodecManager(new CompilerThriftCodecFactory(true)); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/internal/reflection/TestReflectionToCompilerThriftCodecFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.reflection; 17 | 18 | import com.facebook.swift.codec.AbstractThriftCodecManagerTest; 19 | import com.facebook.swift.codec.ThriftCodecManager; 20 | import com.facebook.swift.codec.internal.compiler.CompilerThriftCodecFactory; 21 | 22 | import org.testng.annotations.Test; 23 | 24 | @Test 25 | public class TestReflectionToCompilerThriftCodecFactory extends AbstractThriftCodecManagerTest 26 | { 27 | @Override 28 | public ThriftCodecManager createReadCodecManager() 29 | { 30 | return new ThriftCodecManager(new CompilerThriftCodecFactory(true)); 31 | } 32 | 33 | @Override 34 | public ThriftCodecManager createWriteCodecManager() 35 | { 36 | return new ThriftCodecManager(new ReflectionThriftCodecFactory()); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/oneway/OnewayTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.oneway; 17 | 18 | import com.facebook.swift.service.base.SuiteBase; 19 | import org.apache.thrift.TException; 20 | import org.testng.annotations.Test; 21 | 22 | @Test 23 | public class OnewayTest extends SuiteBase 24 | { 25 | 26 | public OnewayTest() 27 | { 28 | super(OneWayServiceHandler.class, OneWayServiceClient.class); 29 | } 30 | 31 | @Test 32 | public void testOnewayCall() 33 | throws TException 34 | { 35 | getClient().onewayMethod(); 36 | getClient().verifyConnectionState(); 37 | } 38 | 39 | @Test 40 | public void testOneWayThrow() 41 | throws TException, OneWayException 42 | { 43 | getClient().onewayThrow(); 44 | getClient().verifyConnectionState(); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/compiler/SwiftBytecodeHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.compiler; 17 | 18 | import java.lang.reflect.Method; 19 | 20 | public final class SwiftBytecodeHelper 21 | { 22 | public static final Method NO_CONSTRUCTOR_FOUND; 23 | 24 | static { 25 | try { 26 | NO_CONSTRUCTOR_FOUND = SwiftBytecodeHelper.class.getMethod("noConstructorFound", new Class[] {Class.class, short.class}); 27 | } 28 | catch (Throwable t) { 29 | throw new ExceptionInInitializerError(t); 30 | } 31 | } 32 | 33 | 34 | private SwiftBytecodeHelper() 35 | { 36 | } 37 | 38 | public static Throwable noConstructorFound(Class clazz, short fieldId) 39 | { 40 | return new IllegalStateException(String.format("No constructor for Union %s with field id %s found", clazz.getSimpleName(), fieldId)); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /swift-service/src/main/java/com/facebook/swift/service/ThriftClientEventHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service; 17 | 18 | import com.facebook.nifty.client.ClientRequestContext; 19 | 20 | public abstract class ThriftClientEventHandler 21 | { 22 | public Object getContext(String methodName, ClientRequestContext requestContext) 23 | { 24 | return null; 25 | } 26 | 27 | public void preWrite(Object context, String methodName, Object[] args) {} 28 | public void postWrite(Object context, String methodName, Object[] args) {} 29 | public void preRead(Object context, String methodName) {} 30 | public void preReadException(Object context, String methodName, Throwable t) {} 31 | public void postRead(Object context, String methodName, Object result) {} 32 | public void postReadException(Object context, String methodName, Throwable t) {} 33 | public void done(Object context, String methodName) {} 34 | } 35 | -------------------------------------------------------------------------------- /swift-annotations/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 21 | 4.0.0 22 | 23 | 24 | com.facebook.swift 25 | swift-root 26 | 0.23.2-SNAPSHOT 27 | ../pom.xml 28 | 29 | 30 | swift-annotations 31 | jar 32 | ${project.artifactId} 33 | Annotations for use in Swift interfaces and types 34 | 35 | 36 | ${project.parent.basedir} 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ConstList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | import com.google.common.collect.ImmutableList; 20 | 21 | import java.util.List; 22 | 23 | import static com.google.common.base.Preconditions.checkNotNull; 24 | 25 | public class ConstList 26 | extends ConstValue 27 | { 28 | private final List values; 29 | 30 | public ConstList(List values) 31 | { 32 | this.values = ImmutableList.copyOf(checkNotNull(values, "values")); 33 | } 34 | 35 | @Override 36 | public List value() 37 | { 38 | return values; 39 | } 40 | 41 | @Override 42 | public String toString() 43 | { 44 | return MoreObjects.toStringHelper(this) 45 | .add("values", values) 46 | .toString(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/WithoutRecursiveAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.Objects; 22 | 23 | @ThriftStruct 24 | public class WithoutRecursiveAnnotation 25 | { 26 | @ThriftField(1) 27 | public WithoutRecursiveAnnotation child; 28 | 29 | @ThriftField(2) 30 | public String data; 31 | 32 | @Override 33 | public boolean equals(Object obj) 34 | { 35 | if (this == obj) { 36 | return true; 37 | } 38 | if (obj == null || getClass() != obj.getClass()) { 39 | return false; 40 | } 41 | 42 | final WithoutRecursiveAnnotation that = (WithoutRecursiveAnnotation) obj; 43 | 44 | return Objects.equals(data, that.data) && 45 | Objects.equals(child, that.child); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/generics/ConcreteThriftStructDerivedFromGenericField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.generics; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.Objects; 22 | 23 | @ThriftStruct 24 | public final class ConcreteThriftStructDerivedFromGenericField extends GenericThriftStructFieldBase 25 | { 26 | @ThriftField(2) 27 | public String concreteField; 28 | 29 | @Override 30 | public boolean equals(Object obj) 31 | { 32 | if (obj == this) { 33 | return true; 34 | } 35 | if (obj == null || getClass() != obj.getClass()) { 36 | return false; 37 | } 38 | ConcreteThriftStructDerivedFromGenericField other = (ConcreteThriftStructDerivedFromGenericField) obj; 39 | return Objects.equals(concreteField, other.concreteField) && super.equals(obj); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/ViaListElementType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | @ThriftStruct 25 | public class ViaListElementType 26 | { 27 | @ThriftField(value = 1) 28 | public List children; 29 | 30 | @ThriftField(2) 31 | public String data; 32 | 33 | @Override 34 | public boolean equals(Object obj) 35 | { 36 | if (this == obj) { 37 | return true; 38 | } 39 | if (obj == null || getClass() != obj.getClass()) { 40 | return false; 41 | } 42 | 43 | final ViaListElementType that = (ViaListElementType) obj; 44 | 45 | return Objects.equals(data, that.data) && 46 | Objects.equals(children, that.children); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ConstMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | import com.google.common.collect.ImmutableMap; 20 | 21 | import java.util.Map; 22 | 23 | import static com.google.common.base.Preconditions.checkNotNull; 24 | 25 | public class ConstMap 26 | extends ConstValue 27 | { 28 | private final Map values; 29 | 30 | public ConstMap(Map values) 31 | { 32 | this.values = ImmutableMap.copyOf(checkNotNull(values, "value")); 33 | } 34 | 35 | @Override 36 | public Map value() 37 | { 38 | return values; 39 | } 40 | 41 | @Override 42 | public String toString() 43 | { 44 | return MoreObjects.toStringHelper(this) 45 | .add("values", values) 46 | .toString(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/exceptions/ThriftCheckedSubclassableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.service.exceptions; 17 | 18 | import com.facebook.swift.codec.ThriftConstructor; 19 | import com.facebook.swift.codec.ThriftField; 20 | import com.facebook.swift.codec.ThriftStruct; 21 | 22 | @ThriftStruct 23 | public class ThriftCheckedSubclassableException extends Exception { 24 | private static final long serialVersionUID = 1L; 25 | 26 | @ThriftConstructor 27 | public ThriftCheckedSubclassableException(@ThriftField String message) { 28 | super(message); 29 | } 30 | 31 | @ThriftField(1) 32 | public String getMessage() { 33 | return super.getMessage(); 34 | } 35 | 36 | public static class Subclass extends ThriftCheckedSubclassableException { 37 | private static final long serialVersionUID = 1L; 38 | 39 | public Subclass(String message) { 40 | super(message); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ContainerType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.Optional; 19 | import com.google.common.collect.ImmutableList; 20 | 21 | import java.util.List; 22 | 23 | import static com.google.common.base.Preconditions.checkNotNull; 24 | 25 | public abstract class ContainerType 26 | extends ThriftType 27 | { 28 | protected final Optional cppType; 29 | protected final List annotations; 30 | 31 | public ContainerType(String cppType, List annotations) 32 | { 33 | this.cppType = Optional.fromNullable(cppType); 34 | this.annotations = ImmutableList.copyOf(checkNotNull(annotations, "annotations")); 35 | } 36 | 37 | public Optional getCppType() 38 | { 39 | return cppType; 40 | } 41 | 42 | public List getAnnotations() 43 | { 44 | return annotations; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/ViaNestedListElementType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.List; 22 | import java.util.Objects; 23 | 24 | @ThriftStruct 25 | public class ViaNestedListElementType 26 | { 27 | @ThriftField(value = 1) 28 | public List> children; 29 | 30 | @ThriftField(2) 31 | public String data; 32 | 33 | @Override 34 | public boolean equals(Object obj) 35 | { 36 | if (this == obj) { 37 | return true; 38 | } 39 | if (obj == null || getClass() != obj.getClass()) { 40 | return false; 41 | } 42 | 43 | final ViaNestedListElementType that = (ViaNestedListElementType) obj; 44 | 45 | return Objects.equals(data, that.data) && 46 | Objects.equals(children, that.children); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/ViaMapKeyAndValueTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.Map; 22 | import java.util.Objects; 23 | 24 | @ThriftStruct 25 | public class ViaMapKeyAndValueTypes 26 | { 27 | @ThriftField(value = 1) 28 | public Map children; 29 | 30 | @ThriftField(2) 31 | public String data; 32 | 33 | @Override 34 | public boolean equals(Object obj) 35 | { 36 | if (this == obj) { 37 | return true; 38 | } 39 | if (obj == null || getClass() != obj.getClass()) { 40 | return false; 41 | } 42 | 43 | final ViaMapKeyAndValueTypes that = (ViaMapKeyAndValueTypes) obj; 44 | 45 | return Objects.equals(data, that.data) && 46 | Objects.equals(children, that.children); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/generics/GenericThriftStructBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.generics; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | 20 | import java.util.Objects; 21 | 22 | public class GenericThriftStructBase 23 | { 24 | private T genericProperty; 25 | 26 | public GenericThriftStructBase(@ThriftField(1) T genericProperty) 27 | { 28 | this.genericProperty = genericProperty; 29 | } 30 | 31 | @ThriftField(1) 32 | public T getGenericProperty() 33 | { 34 | return genericProperty; 35 | } 36 | 37 | @Override 38 | public boolean equals(Object obj) 39 | { 40 | if (obj == this) { 41 | return true; 42 | } 43 | if (obj == null || getClass() != obj.getClass()) { 44 | return false; 45 | } 46 | GenericThriftStructBase other = (GenericThriftStructBase) obj; 47 | return Objects.equals(this.genericProperty, other.genericProperty); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/generics/GenericThriftStructBeanBase.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.generics; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | 20 | import java.util.Objects; 21 | 22 | public class GenericThriftStructBeanBase 23 | { 24 | private T genericProperty; 25 | 26 | @ThriftField(1) 27 | public T getGenericProperty() 28 | { 29 | return genericProperty; 30 | } 31 | 32 | @ThriftField(1) 33 | public void setGenericProperty(T value) 34 | { 35 | this.genericProperty = value; 36 | } 37 | 38 | @Override 39 | public boolean equals(Object obj) 40 | { 41 | if (obj == this) { 42 | return true; 43 | } 44 | if (obj == null || getClass() != obj.getClass()) { 45 | return false; 46 | } 47 | GenericThriftStructBeanBase other = (GenericThriftStructBeanBase) obj; 48 | return Objects.equals(this.genericProperty, other.genericProperty); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/CoRecursiveTreeHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | import com.google.common.base.Objects; 21 | 22 | @ThriftStruct 23 | public class CoRecursiveTreeHelper 24 | { 25 | @ThriftField(1) 26 | public CoRecursiveTree child; 27 | 28 | @ThriftField(2) 29 | public String data; 30 | 31 | @Override 32 | public boolean equals(Object o) 33 | { 34 | if (this == o) { 35 | return true; 36 | } 37 | if (o == null || getClass() != o.getClass()) { 38 | return false; 39 | } 40 | CoRecursiveTreeHelper that = (CoRecursiveTreeHelper) o; 41 | return Objects.equal(child, that.child) && 42 | Objects.equal(data, that.data); 43 | } 44 | 45 | @Override 46 | public int hashCode() 47 | { 48 | return Objects.hashCode(child, data); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/ListType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | 20 | import java.util.List; 21 | 22 | import static com.google.common.base.Preconditions.checkNotNull; 23 | 24 | public class ListType 25 | extends ContainerType 26 | { 27 | private final ThriftType type; 28 | 29 | public ListType(ThriftType type, String cppType, List annotations) 30 | { 31 | super(cppType, annotations); 32 | this.type = checkNotNull(type, "type"); 33 | } 34 | 35 | public ThriftType getElementType() 36 | { 37 | return type; 38 | } 39 | 40 | @Override 41 | public String toString() 42 | { 43 | return MoreObjects.toStringHelper(this) 44 | .add("type", type) 45 | .add("cppType", cppType) 46 | .add("annotations", annotations) 47 | .toString(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/SetType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | 20 | import java.util.List; 21 | 22 | import static com.google.common.base.Preconditions.checkNotNull; 23 | 24 | public class SetType 25 | extends ContainerType 26 | { 27 | private final ThriftType type; 28 | 29 | public SetType(ThriftType type, String cppType, List annotations) 30 | { 31 | super(cppType, annotations); 32 | this.type = checkNotNull(type, "type"); 33 | } 34 | 35 | public ThriftType getElementType() 36 | { 37 | return type; 38 | } 39 | 40 | @Override 41 | public String toString() 42 | { 43 | return MoreObjects.toStringHelper(this) 44 | .add("type", type) 45 | .add("cppType", cppType) 46 | .add("annotations", annotations) 47 | .toString(); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/CoRecursiveHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.Objects; 22 | 23 | import static com.facebook.swift.codec.ThriftField.*; 24 | 25 | @ThriftStruct 26 | public class CoRecursiveHelper 27 | { 28 | @ThriftField(value = 1, requiredness = Requiredness.OPTIONAL, isRecursive = Recursiveness.TRUE) 29 | public CoRecursive child; 30 | 31 | @ThriftField(2) 32 | public String data; 33 | 34 | @Override 35 | public boolean equals(Object obj) 36 | { 37 | if (this == obj) { 38 | return true; 39 | } 40 | if (obj == null || getClass() != obj.getClass()) { 41 | return false; 42 | } 43 | 44 | final CoRecursiveHelper that = (CoRecursiveHelper) obj; 45 | 46 | return Objects.equals(data, that.data) && 47 | Objects.equals(child, that.child); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /swift-generator/src/main/java/com/facebook/swift/generator/swift2thrift/template/ThriftServiceMetadataRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2013 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generator.swift2thrift.template; 17 | 18 | import com.facebook.swift.service.metadata.ThriftServiceMetadata; 19 | import org.stringtemplate.v4.AttributeRenderer; 20 | 21 | import java.util.Locale; 22 | import java.util.Map; 23 | 24 | public class ThriftServiceMetadataRenderer implements AttributeRenderer 25 | { 26 | private final Map serviceMap; 27 | 28 | public ThriftServiceMetadataRenderer(Map serviceMap) 29 | { 30 | this.serviceMap = serviceMap; 31 | } 32 | 33 | @Override 34 | public String toString(Object o, String formatString, Locale locale) 35 | { 36 | return toString((ThriftServiceMetadata)o); 37 | } 38 | 39 | public String toString(ThriftServiceMetadata s) { 40 | String result = serviceMap.get(s); 41 | return result == null ? s.getName() : result + "." + s.getName(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/CoRecursiveTree.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | import com.google.common.base.Objects; 21 | 22 | import java.util.List; 23 | 24 | @ThriftStruct 25 | public class CoRecursiveTree 26 | { 27 | @ThriftField(1) 28 | public List children; 29 | 30 | @ThriftField(2) 31 | public String data; 32 | 33 | @Override 34 | public boolean equals(Object o) 35 | { 36 | if (this == o) { 37 | return true; 38 | } 39 | if (o == null || getClass() != o.getClass()) { 40 | return false; 41 | } 42 | CoRecursiveTree that = (CoRecursiveTree) o; 43 | return Objects.equal(children, that.children) && 44 | Objects.equal(data, that.data); 45 | } 46 | 47 | @Override 48 | public int hashCode() 49 | { 50 | return Objects.hashCode(children, data); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/visitor/Visitable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.visitor; 17 | 18 | import java.io.IOException; 19 | import java.util.Collection; 20 | 21 | public interface Visitable 22 | { 23 | void visit(DocumentVisitor visitor) throws IOException; 24 | 25 | public static final class Utils 26 | { 27 | private Utils() 28 | { 29 | } 30 | 31 | public static void visitAll(final DocumentVisitor visitor, final Collection visitables) throws IOException 32 | { 33 | if (visitables != null && !visitables.isEmpty()) { 34 | for (Visitable visitable : visitables) { 35 | if (visitor.accept(visitable)) { 36 | visitable.visit(visitor); 37 | } 38 | } 39 | } 40 | } 41 | 42 | public static void visit(final DocumentVisitor visitor, final Visitable visitable) throws IOException 43 | { 44 | visitor.visit(visitable); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/Typedef.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | import com.google.common.base.Preconditions; 20 | 21 | import static com.google.common.base.Preconditions.checkNotNull; 22 | 23 | public class Typedef 24 | extends Definition 25 | { 26 | private final String name; 27 | private final ThriftType type; 28 | 29 | public Typedef(String name, ThriftType type) 30 | { 31 | this.name = checkNotNull(name, "name"); 32 | this.type = Preconditions.checkNotNull(type, "type"); 33 | } 34 | 35 | @Override 36 | public String getName() 37 | { 38 | return name; 39 | } 40 | 41 | public ThriftType getType() 42 | { 43 | return type; 44 | } 45 | 46 | @Override 47 | public String toString() 48 | { 49 | return MoreObjects.toStringHelper(this) 50 | .add("name", name) 51 | .add("type", type) 52 | .toString(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/idlannotations/ExceptionWithIdlAnnotations.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.idlannotations; 17 | 18 | import com.facebook.swift.codec.ThriftConstructor; 19 | import com.facebook.swift.codec.ThriftField; 20 | import com.facebook.swift.codec.ThriftIdlAnnotation; 21 | import com.facebook.swift.codec.ThriftStruct; 22 | 23 | @ThriftStruct( 24 | idlAnnotations = { 25 | @ThriftIdlAnnotation(key = "message", value = "message") 26 | } 27 | ) 28 | public class ExceptionWithIdlAnnotations extends Exception 29 | { 30 | private int type; 31 | 32 | @ThriftConstructor 33 | public ExceptionWithIdlAnnotations(@ThriftField(1) String message, 34 | @ThriftField(2) int type) 35 | { 36 | super(message); 37 | this.type = type; 38 | } 39 | 40 | @ThriftField(1) 41 | public String getMessage() 42 | { 43 | return super.getMessage(); 44 | } 45 | 46 | @ThriftField(2) 47 | public int getType() 48 | { 49 | return type; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/idlannotations/BeanWithMatchingIdlAnnotationsMapsForField.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.idlannotations; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftIdlAnnotation; 20 | import com.facebook.swift.codec.ThriftStruct; 21 | 22 | @ThriftStruct 23 | public class BeanWithMatchingIdlAnnotationsMapsForField 24 | { 25 | private int type; 26 | 27 | @ThriftField(1) 28 | public String message; 29 | 30 | @ThriftField(value = 2, idlAnnotations = { 31 | @ThriftIdlAnnotation(key = "testkey1", value = "testvalue1"), 32 | @ThriftIdlAnnotation(key = "testkey2", value = "testvalue2") 33 | }) 34 | public int getType() 35 | { 36 | return type; 37 | } 38 | 39 | @ThriftField(value = 2, idlAnnotations = { 40 | @ThriftIdlAnnotation(key = "testkey1", value = "testvalue1"), 41 | @ThriftIdlAnnotation(key = "testkey2", value = "testvalue2") 42 | }) 43 | public void setType(int type) 44 | { 45 | this.type = type; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /swift-codec/src/test/java/com/facebook/swift/codec/recursion/WithSwiftRecursiveAnnotation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.recursion; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import com.facebook.swift.codec.ThriftStruct; 20 | 21 | import java.util.Objects; 22 | 23 | import static com.facebook.swift.codec.ThriftField.*; 24 | 25 | 26 | @ThriftStruct 27 | public class WithSwiftRecursiveAnnotation 28 | { 29 | @ThriftField(value = 1, requiredness = Requiredness.OPTIONAL, isRecursive = Recursiveness.TRUE) 30 | public WithSwiftRecursiveAnnotation child; 31 | 32 | @ThriftField(2) 33 | public String data; 34 | 35 | @Override 36 | public boolean equals(Object obj) 37 | { 38 | if (this == obj) { 39 | return true; 40 | } 41 | if (obj == null || getClass() != obj.getClass()) { 42 | return false; 43 | } 44 | 45 | final WithSwiftRecursiveAnnotation that = (WithSwiftRecursiveAnnotation) obj; 46 | 47 | return Objects.equals(data, that.data) && 48 | Objects.equals(child, that.child); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-generator/src/main/java/com/facebook/swift/generator/swift2thrift/template/FieldRequirednessRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.generator.swift2thrift.template; 17 | 18 | import com.facebook.swift.codec.ThriftField; 19 | import org.stringtemplate.v4.AttributeRenderer; 20 | 21 | import java.util.Locale; 22 | 23 | import static com.google.common.base.Preconditions.checkArgument; 24 | 25 | public class FieldRequirednessRenderer implements AttributeRenderer 26 | { 27 | @Override 28 | public String toString(Object o, String formatString, Locale locale) 29 | { 30 | checkArgument(o instanceof ThriftField.Requiredness); 31 | 32 | ThriftField.Requiredness requiredness = (ThriftField.Requiredness)o; 33 | 34 | switch (requiredness) { 35 | case NONE: 36 | return ""; 37 | 38 | case REQUIRED: 39 | return "required"; 40 | 41 | case OPTIONAL: 42 | return "optional"; 43 | 44 | default: 45 | throw new IllegalArgumentException("Invalid value for field requiredness"); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/compiler/byteCode/CaseStatement.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.compiler.byteCode; 17 | 18 | import javax.annotation.concurrent.Immutable; 19 | 20 | @Immutable 21 | public class CaseStatement 22 | { 23 | public static CaseStatement caseStatement(int key, String label) 24 | { 25 | return new CaseStatement(label, key); 26 | } 27 | 28 | private final int key; 29 | private final String label; 30 | 31 | CaseStatement(String label, int key) 32 | { 33 | this.label = label; 34 | this.key = key; 35 | } 36 | 37 | public String getLabel() 38 | { 39 | return label; 40 | } 41 | 42 | public int getKey() 43 | { 44 | return key; 45 | } 46 | 47 | @Override 48 | public String toString() 49 | { 50 | final StringBuilder sb = new StringBuilder(); 51 | sb.append("CaseStatement"); 52 | sb.append("{label='").append(label).append('\''); 53 | sb.append(", value=").append(key); 54 | sb.append('}'); 55 | return sb.toString(); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/builtin/ByteThriftCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.builtin; 17 | 18 | import com.facebook.swift.codec.ThriftCodec; 19 | import com.facebook.swift.codec.metadata.ThriftType; 20 | import com.google.common.base.Preconditions; 21 | import org.apache.thrift.protocol.TProtocol; 22 | 23 | import javax.annotation.concurrent.Immutable; 24 | 25 | @Immutable 26 | public class ByteThriftCodec implements ThriftCodec 27 | { 28 | @Override 29 | public ThriftType getType() 30 | { 31 | return ThriftType.BYTE; 32 | } 33 | 34 | @Override 35 | public Byte read(TProtocol protocol) 36 | throws Exception 37 | { 38 | Preconditions.checkNotNull(protocol, "protocol is null"); 39 | return protocol.readByte(); 40 | } 41 | 42 | @Override 43 | public void write(Byte value, TProtocol protocol) 44 | throws Exception 45 | { 46 | Preconditions.checkNotNull(value, "value is null"); 47 | Preconditions.checkNotNull(protocol, "protocol is null"); 48 | protocol.writeByte(value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/builtin/LongThriftCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.builtin; 17 | 18 | import com.facebook.swift.codec.ThriftCodec; 19 | import com.facebook.swift.codec.metadata.ThriftType; 20 | import com.google.common.base.Preconditions; 21 | import org.apache.thrift.protocol.TProtocol; 22 | 23 | import javax.annotation.concurrent.Immutable; 24 | 25 | @Immutable 26 | public class LongThriftCodec implements ThriftCodec 27 | { 28 | @Override 29 | public ThriftType getType() 30 | { 31 | return ThriftType.I64; 32 | } 33 | 34 | @Override 35 | public Long read(TProtocol protocol) 36 | throws Exception 37 | { 38 | Preconditions.checkNotNull(protocol, "protocol is null"); 39 | return protocol.readI64(); 40 | } 41 | 42 | @Override 43 | public void write(Long value, TProtocol protocol) 44 | throws Exception 45 | { 46 | Preconditions.checkNotNull(value, "value is null"); 47 | Preconditions.checkNotNull(protocol, "protocol is null"); 48 | protocol.writeI64(value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/metadata/MethodInjection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.metadata; 17 | 18 | import com.google.common.collect.ImmutableList; 19 | 20 | import java.lang.reflect.Method; 21 | import java.util.List; 22 | 23 | class MethodInjection 24 | { 25 | private final Method method; 26 | private final List parameters; 27 | 28 | public MethodInjection(Method method, List parameters) 29 | { 30 | this.method = method; 31 | this.parameters = ImmutableList.copyOf(parameters); 32 | } 33 | 34 | public Method getMethod() 35 | { 36 | return method; 37 | } 38 | 39 | public List getParameters() 40 | { 41 | return parameters; 42 | } 43 | 44 | @Override 45 | public String toString() 46 | { 47 | final StringBuilder sb = new StringBuilder(); 48 | sb.append("MethodInjection"); 49 | sb.append("{method=").append(method); 50 | sb.append(", parameters=").append(parameters); 51 | sb.append('}'); 52 | return sb.toString(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/builtin/ShortThriftCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.builtin; 17 | 18 | import com.facebook.swift.codec.ThriftCodec; 19 | import com.facebook.swift.codec.metadata.ThriftType; 20 | import com.google.common.base.Preconditions; 21 | import org.apache.thrift.protocol.TProtocol; 22 | 23 | import javax.annotation.concurrent.Immutable; 24 | 25 | @Immutable 26 | public class ShortThriftCodec implements ThriftCodec 27 | { 28 | @Override 29 | public ThriftType getType() 30 | { 31 | return ThriftType.I16; 32 | } 33 | 34 | @Override 35 | public Short read(TProtocol protocol) 36 | throws Exception 37 | { 38 | Preconditions.checkNotNull(protocol, "protocol is null"); 39 | return protocol.readI16(); 40 | } 41 | 42 | @Override 43 | public void write(Short value, TProtocol protocol) 44 | throws Exception 45 | { 46 | Preconditions.checkNotNull(value, "value is null"); 47 | Preconditions.checkNotNull(protocol, "protocol is null"); 48 | protocol.writeI16(value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/builtin/BooleanThriftCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.builtin; 17 | 18 | import com.facebook.swift.codec.ThriftCodec; 19 | import com.facebook.swift.codec.metadata.ThriftType; 20 | import com.google.common.base.Preconditions; 21 | import org.apache.thrift.protocol.TProtocol; 22 | 23 | import javax.annotation.concurrent.Immutable; 24 | 25 | @Immutable 26 | public class BooleanThriftCodec implements ThriftCodec 27 | { 28 | @Override 29 | public ThriftType getType() 30 | { 31 | return ThriftType.BOOL; 32 | } 33 | 34 | @Override 35 | public Boolean read(TProtocol protocol) 36 | throws Exception 37 | { 38 | Preconditions.checkNotNull(protocol, "protocol is null"); 39 | return protocol.readBool(); 40 | } 41 | 42 | @Override 43 | public void write(Boolean value, TProtocol protocol) 44 | throws Exception 45 | { 46 | Preconditions.checkNotNull(value, "value is null"); 47 | Preconditions.checkNotNull(protocol, "protocol is null"); 48 | protocol.writeBool(value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/builtin/DoubleThriftCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.builtin; 17 | 18 | import com.facebook.swift.codec.ThriftCodec; 19 | import com.facebook.swift.codec.metadata.ThriftType; 20 | import com.google.common.base.Preconditions; 21 | import org.apache.thrift.protocol.TProtocol; 22 | 23 | import javax.annotation.concurrent.Immutable; 24 | 25 | @Immutable 26 | public class DoubleThriftCodec implements ThriftCodec 27 | { 28 | @Override 29 | public ThriftType getType() 30 | { 31 | return ThriftType.DOUBLE; 32 | } 33 | 34 | @Override 35 | public Double read(TProtocol protocol) 36 | throws Exception 37 | { 38 | Preconditions.checkNotNull(protocol, "protocol is null"); 39 | return protocol.readDouble(); 40 | } 41 | 42 | @Override 43 | public void write(Double value, TProtocol protocol) 44 | throws Exception 45 | { 46 | Preconditions.checkNotNull(value, "value is null"); 47 | Preconditions.checkNotNull(protocol, "protocol is null"); 48 | protocol.writeDouble(value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/builtin/IntegerThriftCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.builtin; 17 | 18 | import com.facebook.swift.codec.ThriftCodec; 19 | import com.facebook.swift.codec.metadata.ThriftType; 20 | import com.google.common.base.Preconditions; 21 | import org.apache.thrift.protocol.TProtocol; 22 | 23 | import javax.annotation.concurrent.Immutable; 24 | 25 | @Immutable 26 | public class IntegerThriftCodec implements ThriftCodec 27 | { 28 | @Override 29 | public ThriftType getType() 30 | { 31 | return ThriftType.I32; 32 | } 33 | 34 | @Override 35 | public Integer read(TProtocol protocol) 36 | throws Exception 37 | { 38 | Preconditions.checkNotNull(protocol, "protocol is null"); 39 | return protocol.readI32(); 40 | } 41 | 42 | @Override 43 | public void write(Integer value, TProtocol protocol) 44 | throws Exception 45 | { 46 | Preconditions.checkNotNull(value, "value is null"); 47 | Preconditions.checkNotNull(protocol, "protocol is null"); 48 | protocol.writeI32(value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-codec/src/main/java/com/facebook/swift/codec/internal/builtin/StringThriftCodec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.codec.internal.builtin; 17 | 18 | import com.facebook.swift.codec.ThriftCodec; 19 | import com.facebook.swift.codec.metadata.ThriftType; 20 | import com.google.common.base.Preconditions; 21 | import org.apache.thrift.protocol.TProtocol; 22 | 23 | import javax.annotation.concurrent.Immutable; 24 | 25 | @Immutable 26 | public class StringThriftCodec implements ThriftCodec 27 | { 28 | @Override 29 | public ThriftType getType() 30 | { 31 | return ThriftType.STRING; 32 | } 33 | 34 | @Override 35 | public String read(TProtocol protocol) 36 | throws Exception 37 | { 38 | Preconditions.checkNotNull(protocol, "protocol is null"); 39 | return protocol.readString(); 40 | } 41 | 42 | @Override 43 | public void write(String value, TProtocol protocol) 44 | throws Exception 45 | { 46 | Preconditions.checkNotNull(value, "value is null"); 47 | Preconditions.checkNotNull(protocol, "protocol is null"); 48 | protocol.writeString(value); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /swift-idl-parser/src/main/java/com/facebook/swift/parser/model/StringEnum.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | package com.facebook.swift.parser.model; 17 | 18 | import com.google.common.base.MoreObjects; 19 | import com.google.common.collect.ImmutableList; 20 | 21 | import java.util.List; 22 | 23 | import static com.google.common.base.Preconditions.checkNotNull; 24 | 25 | public class StringEnum 26 | extends Definition 27 | { 28 | private final String name; 29 | private final List values; 30 | 31 | public StringEnum(String name, List values) 32 | { 33 | this.name = checkNotNull(name, "name"); 34 | this.values = ImmutableList.copyOf(checkNotNull(values, "values")); 35 | } 36 | 37 | @Override 38 | public String getName() 39 | { 40 | return name; 41 | } 42 | 43 | public List getValues() 44 | { 45 | return values; 46 | } 47 | 48 | @Override 49 | public String toString() 50 | { 51 | return MoreObjects.toStringHelper(this) 52 | .add("name", name) 53 | .add("values", values) 54 | .toString(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /swift-service/src/test/java/com/facebook/swift/service/scribe/ResultCode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Facebook, Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 5 | * not use this file except in compliance with the License. You may obtain 6 | * a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | * License for the specific language governing permissions and limitations 14 | * under the License. 15 | */ 16 | /** 17 | * Autogenerated by Thrift Compiler (0.9.0) 18 | * 19 | * DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 20 | * @generated 21 | */ 22 | package com.facebook.swift.service.scribe; 23 | 24 | 25 | import java.util.Map; 26 | import java.util.HashMap; 27 | import org.apache.thrift.TEnum; 28 | 29 | public enum ResultCode implements org.apache.thrift.TEnum { 30 | OK(0), 31 | TRY_LATER(1); 32 | 33 | private final int value; 34 | 35 | private ResultCode(int value) { 36 | this.value = value; 37 | } 38 | 39 | /** 40 | * Get the integer value of this enum value, as defined in the Thrift IDL. 41 | */ 42 | public int getValue() { 43 | return value; 44 | } 45 | 46 | /** 47 | * Find a the enum type by its integer value, as defined in the Thrift IDL. 48 | * @return null if the value is not found. 49 | */ 50 | public static ResultCode findByValue(int value) { 51 | switch (value) { 52 | case 0: 53 | return OK; 54 | case 1: 55 | return TRY_LATER; 56 | default: 57 | return null; 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /swift-service/src/test/resources/rsa.key: -------------------------------------------------------------------------------- 1 | -----BEGIN PRIVATE KEY----- 2 | MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDcnl9TWHmsMFua 3 | dC0sVEWB2p0HBLfCckFuPdcGfzZ2X/FQCFkxC4RPqQM/IEHkEUiAFfIe+D7CiQ4i 4 | 7Sw13lHr/8oWpQ92xtI0ts3s+NVwDPad+77pjqbwCmc9RdYjtfNP5Z3Z0uqyGkoi 5 | QuhvJJtem1UAhiROz2JpIIUJikqxrGYOsyXJORy6FAhEJFY2T8wE7q2VDEP3QkIa 6 | 8K/pUoeOoiCZlbCwSpzzxvVOyMKJ8kRxIrtMuDvBdjgfrGQkOEVXvDmpsCTWJcDf 7 | E/oLqpYc68AW7nRNU4knLfD4HbBrb/v1Hmu2/ZWFe7TZCoq92g9zoPeS2PoB1mpT 8 | vlLuCM5xAgMBAAECggEAZt8WNgfYXFkELcYkVjpJWt50QBSMFwgtyFjfjfD9lT7x 9 | h88Mv9jN7lMx51qEPvNsKgWRq603noBH7jNHXSr4aiIQunRm/IyC8f+Xj/sLkz8I 10 | M+xyPfe9kcpYD3MkAezSspuv+iTmOPwXO1iVh1W7eObXQPJLtc/v5HM8dZFdePC7 11 | ztwZ6M6TxxBcGRp7Q79CVwGBQg/IRPe5btUKBEPm/p/T1IlUMxu4XhCaRraVY1J5 12 | F+Y1C16f3KlcpShT/7P8ETMh74CYSN1gpijzizsp+TSKkJBbRHNB6191Jtefb5NY 13 | YIN4pIjAVKBpVeU09eZU8MR37nCZVUFBit9x3YjpjQKBgQDyEKhXlt8OJsbHJNb1 14 | L8vIO7ULmyPbjjond5zSTMFFQZ++XGY2YETy9P9BwWnwFU9gkVNIk2d/Zw3nRm3t 15 | 6hr/8Y1M5sSKHAfp6E3tLoyAA8j375OaDjqwb9/+vYXoMK6KgmSNLoEYkyKuFZi8 16 | FNcujHAbVcoM5Z+3qgunBXu54wKBgQDpUaf7Kp2SlBrWvGEFQmACOcQoEN6YZ9NM 17 | iVqteTML4LwpdH2bKhla3ZtB3LIVJchTFDdAPwb45J8ka3Xkh6Mu41If91UPEPU0 18 | rxnxQDbdTkj+CyqItmJv/srr/D413Fq4zFr6nzoogmNdP1sqMGKMRFvr/Q1ArskG 19 | WbQsWS9WmwKBgQCUounbrsaUd/cC/XoI4Cpvb0pCMCcagADxjx76eysKDbu7Nh2F 20 | MiPkU9ARXmRgiZVOJK5RGEIrFuqQosyJlICzvG0ZVXJFo+SwGncPNtALI0faBoBJ 21 | zob3JBsU3udEpe/nGR4JGw8mOeLHpnc8tkdTS+TixBDnTnB+ZKn3CwToJQKBgQCG 22 | 7odUNRANrgNbfnQpg3pcryWm+iKRRzImyCSdwELqMpz+6HSfoJgrOY/JZiXDHyec 23 | DEvrpseUdzsl59O1R0/zFNnwzKvvW6JDRqSdJcLU96o06SY/DCMfm92k3iroITiC 24 | OQTAfgc3WDi4u6QwYO0NK5dxgdYBO1PcjVIqd6Vt0wKBgQDPg9LjSwU91UrhxoYt 25 | OgFaxOT0tzhKU/LiB7yf0zZoOlwkOVBqmEfcJMaUb9WvyQqFAB/1UuHbKQrhPhl7 26 | 1x1X05DOOJ2L3CF/ePxirPAghDU0ShkoE/TjlDRrApMrun42zp9dNcAcCbLPShMQ 27 | 8LihO1Ig1Eg/W+LL0DDvPO2WPQ== 28 | -----END PRIVATE KEY----- 29 | --------------------------------------------------------------------------------