1 // Protocol Buffers - Google's data interchange format 2 // Copyright 2008 Google Inc. All rights reserved. 3 // 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file or at 6 // https://developers.google.com/open-source/licenses/bsd 7 8 package com.google.protobuf; 9 10 // TODO: Change ContainingType to extend Message 11 /** 12 * Interface that generated extensions implement. 13 * 14 * @author liujisi@google.com (Jisi Liu) 15 */ 16 public abstract class Extension<ContainingType extends MessageLite, Type> 17 extends ExtensionLite<ContainingType, Type> { 18 // TODO: Add package-private constructor. 19 20 /** {@inheritDoc} Overridden to return {@link Message} instead of {@link MessageLite}. */ 21 @Override getMessageDefaultInstance()22 public abstract Message getMessageDefaultInstance(); 23 24 /** Returns the descriptor of the extension. */ getDescriptor()25 public abstract Descriptors.FieldDescriptor getDescriptor(); 26 27 /** Returns whether or not this extension is a Lite Extension. */ 28 @Override isLite()29 final boolean isLite() { 30 return false; 31 } 32 33 // All the methods below are extension implementation details. 34 35 /** The API type that the extension is used for. */ 36 protected enum ExtensionType { 37 IMMUTABLE, 38 MUTABLE, 39 PROTO1, 40 } 41 getExtensionType()42 protected abstract ExtensionType getExtensionType(); 43 44 /** Type of a message extension. */ 45 public enum MessageType { 46 PROTO1, 47 PROTO2, 48 } 49 50 /** 51 * If the extension is a message extension (i.e., getLiteType() == MESSAGE), returns the type of 52 * the message, otherwise undefined. 53 */ getMessageType()54 public MessageType getMessageType() { 55 return MessageType.PROTO2; 56 } 57 fromReflectionType(Object value)58 protected abstract Object fromReflectionType(Object value); 59 singularFromReflectionType(Object value)60 protected abstract Object singularFromReflectionType(Object value); 61 toReflectionType(Object value)62 protected abstract Object toReflectionType(Object value); 63 singularToReflectionType(Object value)64 protected abstract Object singularToReflectionType(Object value); 65 } 66