@param \Protobuf\Compiler\Entity             $entity
@param \google\protobuf\FieldDescriptorProto $field

@return string
498162
protected function generateExtensionField(Entity $entity, FieldDescriptorProto $field)
    {
        $name     = $field->getName();
        $number   = $field->getNumber();
        $docBlock = $this->getDocBlockType($field);
        $type     = $this->getFieldTypeName($field);
        $label    = $this->getFieldLabelName($field);
        $property = PropertyGenerator::fromArray([
            'static'       => true,
            'name'         => $name,
            'visibility'   => PropertyGenerator::VISIBILITY_PROTECTED,
            'docblock'     => [
                'shortDescription' => "Extension field : $name $label $type = $number",
                'tags'             => [
                    [
                        'name'        => 'var',
                        'description' => '\Protobuf\Extension',
                    ]
                ]
            ]
        ]);

        $property->getDocblock()->setWordWrap(false);

        return $property;
    }
499841
protected function getEntityAttributeValue($entity, $field)
    {
        $functionName = 'get'.ucfirst($field);

        $fieldValue = call_user_func([$entity, $functionName]);

        return $fieldValue;
    }
942668
protected function generateAddMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $fieldName  = $field->getName();
        $fieldType  = $field->getType();
        $collClass  = $this->getCollectionClassName($field);
        $methodName = 'add' . $this->getClassifiedName($field);
        $typeHint   = ($fieldType !== Type::TYPE_BYTES())
            ? $this->getDoctype($field)
            : null;

        $lines[] = 'if ($this->' . $fieldName . ' === null) {';
        $lines[] = '    $this->' . $fieldName . ' = new ' . $collClass . '();';
        $lines[] = '}';
        $lines[] = null;
        $lines[] = ($fieldType !== Type::TYPE_BYTES())
            ? '$this->' . $fieldName . '->add($value);'
            : '$this->' . $fieldName . '->add(\Protobuf\Stream::wrap($value));';

        return MethodGenerator::fromArray([
            'name'       => $methodName,
            'body'       => implode(PHP_EOL, $lines),
            'parameters' => [
                [
                    'name'   => 'value',
                    'type'   => $typeHint
                ]
            ],
            'docblock'   => [
                'shortDescription' => "Add a new element to '$fieldName'",
                'tags'             => [
                    [
                        'name'        => 'param',
                        'description' => $this->getDoctype($field) . ' $value'
                    ]
                ]
            ]
        ]);
    }
1061254
protected function generateExtensionMethod(Entity $entity, FieldDescriptorProto $field)
    {
        $fieldName  = $field->getName();
        $methodName = $this->getCamelizedName($field);
        $lines      = $this->generateBody($entity, $field);
        $body       = implode(PHP_EOL, $lines);
        $method     = MethodGenerator::fromArray([
            'static'     => true,
            'body'       => $body,
            'name'       => $methodName,
            'docblock'   => [
                'shortDescription' => "Extension field : $fieldName",
                'tags'             => [
                    [
                        'name'        => 'return',
                        'description' => '\Protobuf\Extension\ExtensionField',
                    ]
                ]
            ]
        ]);

        $method->getDocblock()->setWordWrap(false);

        return $method;
    }
576400
protected function parseProperty(string $entity, $entityName, array $fields, Schema $schema, $instance)
    {
        $this->entity     = $entity;
        $this->entityName = $entityName;
        $this->entityDate = date('Y年m月d日');
        $this->fields     = $fields;
        $removeTablePrefix = $this->removeTablePrefix;

        $entityClass = $this->entity;
        if (!empty($removeTablePrefix)) {
            $entityClass = StringHelper::replaceFirst($removeTablePrefix, '', $this->entity);
        }
        $this->entityClass = StringHelper::camel($entityClass);
        $this->entityClass = ucfirst($this->entityClass);

        $param = [
            $schema,
            $this->uses,
            $this->extends,
            $this->entity,
            $this->entityName,
            $this->entityClass,
            $this->entityDate,
            $this->fields,
            $instance,
        ];

        $sgGenerator = new SetGetGenerator();
        $sgGenerator(...$param);
    }
478646
private Object getEntityFieldValue(EntityMetadata entityMetadata, Object entity, String field)
    {
        Class clazz = entityMetadata.getEntityClazz();
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                entityMetadata.getPersistenceUnit());
        EntityType entityType = metaModel.entity(clazz);

        if (field.indexOf(".") > 0 && entityMetadata.getEntityClazz().equals(entity.getClass()))
        {
            String fieldName = field.substring(field.indexOf(".") + 1, field.length());
            Attribute attribute = entityType.getAttribute(fieldName);
            return PropertyAccessorHelper.getObject(entity, (Field) attribute.getJavaMember());
        }
        else
        {
            // for hbase v2 client (sends arraylist for specific fields)
            if (entity instanceof ArrayList)
            {
                Object element = ((ArrayList) entity).get(0);
                ((ArrayList) entity).remove(0);
                return element;
            }
            else
            {
                return entity;
            }
        }
    }
616880
protected function getMethodOutputTypeHint(MethodDescriptorProto $method)
    {
        $refType   = $method->getOutputType();
        $refEntity = $this->getEntity($refType);

        if ($method->getServerStreaming()) {
            return '\Iterator';
        }

        return $refEntity->getNamespacedName();
    }
568125
protected function getCamelizedName(FieldDescriptorProto $field)
    {
        $name  = $field->getName();
        $value = $this->getCamelizedValue($name);

        return $value;
    }
440742
public function generateFieldSizeStatement(Entity $entity, FieldDescriptorProto $field)
    {
        $body     = [];
        $name     = $field->getName();
        $type     = $field->getType();
        $rule     = $field->getLabel();
        $tag      = $field->getNumber();
        $options  = $field->getOptions();
        $variable = $this->targetVar ?: '$this->' . $name;
        $isPack   = $options ? $options->getPacked() : false;

        $wire    = $isPack ? WireFormat::WIRE_LENGTH : WireFormat::getWireType($type->value(), null);
        $key     = WireFormat::getFieldKey($tag, $wire);
        $keySize = $this->getSizeCalculator()->computeVarintSize($key);

        if ($rule === Label::LABEL_REPEATED() && $isPack) {
            $itemValSttm = ($type === Type::TYPE_ENUM())
                ? '$val->value()'
                : '$val';

            $body[] = '$innerSize = 0;';
            $body[] = null;
            $body[] = 'foreach (' . $variable . ' as $val) {';
            $body[] = '    $innerSize += ' . $this->generateValueSizeStatement($type->value(), $itemValSttm) . ';';
            $body[] = '}';
            $body[] = null;
            $body[] = '$size += ' . $keySize . ';';
            $body[] = '$size += $innerSize;';
            $body[] = '$size += $calculator->computeVarintSize($innerSize);';

            return $body;
        }

        if ($type === Type::TYPE_MESSAGE() && $rule === Label::LABEL_REPEATED()) {
            $body[] = 'foreach (' . $variable . ' as $val) {';
            $body[] = '    $innerSize = $val->serializedSize($context);';
            $body[] = null;
            $body[] = '    $size += ' . $keySize . ';';
            $body[] = '    $size += $innerSize;';
            $body[] = '    $size += $calculator->computeVarintSize($innerSize);';
            $body[] = '}';

            return $body;
        }

        if ($type === Type::TYPE_ENUM() && $rule === Label::LABEL_REPEATED()) {
            $body[] = 'foreach (' . $variable . ' as $val) {';
            $body[] = '    $size += ' . $keySize . ';';
            $body[] = '    $size += ' . $this->generateValueSizeStatement($type->value(), '$val->value()') . ';';
            $body[] = '}';

            return $body;
        }

        if ($rule === Label::LABEL_REPEATED()) {
            $body[] = 'foreach (' . $variable . ' as $val) {';
            $body[] = '    $size += ' . $keySize . ';';
            $body[] = '    $size += ' . $this->generateValueSizeStatement($type->value(), '$val') . ';';
            $body[] = '}';

            return $body;
        }

        if ($type === Type::TYPE_ENUM()) {
            $body[] = '$size += ' . $keySize . ';';
            $body[] = '$size += ' . $this->generateValueSizeStatement($type->value(), $variable . '->value()') . ';';

            return $body;
        }

        if ($type !== Type::TYPE_MESSAGE()) {
            $body[] = '$size += ' . $keySize . ';';
            $body[] = '$size += ' . $this->generateValueSizeStatement($type->value(), $variable) . ';';

            return $body;
        }

        $body[] = '$innerSize = ' . $variable . '->serializedSize($context);';
        $body[] = null;
        $body[] = '$size += ' . $keySize . ';';
        $body[] = '$size += $innerSize;';
        $body[] = '$size += $calculator->computeVarintSize($innerSize);';

        return $body;
    }
482274
protected function _updateField($entity, $field, $refreshTimestamp)
    {
        if ($entity->isDirty($field)) {
            return;
        }

        $ts = $this->timestamp(null, $refreshTimestamp);

        $columnType = $this->getTable()->getSchema()->getColumnType($field);
        if (!$columnType) {
            return;
        }

        /** @var \Cake\Database\Type\DateTimeType $type */
        $type = Type::build($columnType);

        if (!$type instanceof Type\DateTimeType) {
            deprecationWarning('TimestampBehavior support for column types other than DateTimeType will be removed in 4.0.');
            $entity->set($field, (string)$ts);

            return;
        }

        $class = $type->getDateTimeClassName();

        $entity->set($field, new $class($ts));
    }
756677
protected function generateWriteCallback(Entity $entity, FieldDescriptorProto $field)
    {
        $body  = [];
        $sttm  = $this->generateFieldWriteStatement($entity, $field);
        $lines = $this->addIndentation($sttm, 1);

        $body[] = '$writeCallback = function (\Protobuf\WriteContext $context, $value) {';
        $body[] = '    $stream      = $context->getStream();';
        $body[] = '    $writer      = $context->getWriter();';
        $body[] = '    $sizeContext = $context->getComputeSizeContext();';
        $body[] = null;
        $body   = array_merge($body, $lines);
        $body[] = '};';

        return $body;
    }
505758
protected function getCollectionClassName(FieldDescriptorProto $field)
    {
        $type = $field->getType();

        if ($type === Type::TYPE_MESSAGE()) {
            return '\Protobuf\MessageCollection';
        }

        if ($type === Type::TYPE_BYTES()) {
            return '\Protobuf\StreamCollection';
        }

        if ($type === Type::TYPE_ENUM()) {
            return '\Protobuf\EnumCollection';
        }

        return '\Protobuf\ScalarCollection';
    }
407846
private function retrieveFilterFieldDescription(
        AdminInterface $admin,
        string $field
    ): FieldDescriptionInterface {
        $admin->getFilterFieldDescriptions();

        $fieldDescription = $admin->getFilterFieldDescription($field);

        if (!$fieldDescription) {
            throw new \RuntimeException(sprintf('The field "%s" does not exist.', $field));
        }

        if (null === $fieldDescription->getTargetEntity()) {
            throw new \RuntimeException(sprintf('No associated entity with field "%s".', $field));
        }

        return $fieldDescription;
    }
205836
protected function _getFileName($entity, $field, $options = [])
    {
        $_options = [
        ];

        $options = Hash::merge($_options, $options);

        $config = $this->config($field);

        $_upload = $this->_uploads[$field];

        $fileInfo = explode('.', $_upload['name']);
        $extension = end($fileInfo);

        $fileName = $config['fileName'];

        $replacements = [
            '{ORIGINAL}' => $_upload['name'],
            '{field}' => $entity->get($config['field']),
            '{extension}' => $extension,
            '{DS}' => DIRECTORY_SEPARATOR,
            '//' => DIRECTORY_SEPARATOR,
            '/' => DIRECTORY_SEPARATOR,
            '\\' => DIRECTORY_SEPARATOR,
        ];

        $builtFileName = str_replace(array_keys($replacements), array_values($replacements), $fileName);

        return $builtFileName;
    }
947322
public function getFileUrl($entity, $field, $fileName = null)
    {
        if (func_num_args() < 3) {
            if ($entity) {
                $fileName = PropertyHelper::getValue($entity, $field);
            }
        }

        if ($fileName instanceof File) {
            $fileName = $fileName->getBasename();
        }

        if ($fileName) {
            return ltrim($this->httpRoot . '/' . $this->getRelativePath($entity, $field) . '/' . $fileName, '/');
        }

        return null;
    }
996590
private function getFieldDescriptors($entityName, $id)
    {
        if (null === $this->fieldDescriptors) {
            $this->initFieldDescriptors($entityName, $id);
        }

        return $this->fieldDescriptors;
    }
775294
protected function getDocBlockType(FieldDescriptorProto $field)
    {
        $type     = $this->getDoctype($field);
        $typeName = $field->getTypeName();
        $label    = $field->getLabel();

        if ($label === Label::LABEL_REPEATED()) {
            $type = '\Protobuf\Collection';
        }

        if ($label === Label::LABEL_REPEATED() && $typeName !== null) {
            $typeName  = $field->getTypeName();
            $refEntity = $this->getEntity($typeName);
            $reference = $refEntity->getNamespacedName();
            $type      = $type . sprintf('<%s>', $reference);
        }

        return $type;
    }