Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public ThriftEnumMetadata(

Method enumValueMethod = null;
for (Method method : enumClass.getMethods()) {
if (method.isSynthetic()) {
continue;
}
if (method.isAnnotationPresent(ThriftEnumValue.class)) {
checkArgument(
Modifier.isPublic(method.getModifiers()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (C) 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.airlift.drift.codec;

public interface GenericReturnValue<T>
{
@SuppressWarnings("unused") // used to test bridge method
T getEnumValue();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.airlift.drift.codec;

import io.airlift.drift.annotations.ThriftEnum;
import io.airlift.drift.annotations.ThriftEnumValue;

@ThriftEnum
public enum GenericReturnValueEnum implements GenericReturnValue<Integer> {
GENERIC_RETURN_VALUE_ENUMValueEnum(1);

private final Integer enumValue;

GenericReturnValueEnum(Integer enumValue)
{
this.enumValue = enumValue;
}

@ThriftEnumValue
@Override
public Integer getEnumValue()
{
return enumValue;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,14 @@ public void testAddUnionCodec()
testRoundTripSerialize(union);
}

@Test
private void testGenericReturnValueEnum() throws Exception
{
ThriftEnumMetadata<GenericReturnValueEnum> enumMetadata = thriftEnumMetadata(GenericReturnValueEnum.class);
testRoundTripSerialize(enumType(enumMetadata), GenericReturnValueEnum.GENERIC_RETURN_VALUE_ENUMValueEnum);
testRoundTripSerialize(list(enumType(enumMetadata)), ImmutableList.copyOf(GenericReturnValueEnum.values()));
}

private <T> void testRoundTripSerialize(T value)
throws Exception
{
Expand Down