/** Get the value of an extension. */
//@Override (Java 1.6 override semantics, but we must support 1.5)
public final <Type> Type getExtension(
final GeneratedExtension<MessageType, Type> extension) {
verifyExtensionContainingType(extension);
FieldDescriptor descriptor = extension.getDescriptor();
final Object value = extensions.getField(descriptor);
if (value == null) {
if (descriptor.isRepeated()) {
return (Type) Collections.emptyList();
} else if (descriptor.getJavaType() ==
FieldDescriptor.JavaType.MESSAGE) {
return (Type) extension.getMessageDefaultInstance();
} else {
return (Type) extension.fromReflectionType(
descriptor.getDefaultValue());
}
} else {
return (Type) extension.fromReflectionType(value);
}
}