<commit_before><?php

namespace PHPCR\Util\CND\Helper;

use PHPCR\Util\CND\Parser\SyntaxTreeNode,
    PHPCR\Util\CND\Parser\SyntaxTreeVisitorInterface,
    PHPCR\NamespaceRegistryInterface,
    PHPCR\NodeType\NodeTypeManagerInterface,
    PHPCR\NodeType\NodeTypeDefinitionInterface,
    PHPCR\PropertyType,
    PHPCR\Version\OnParentVersionAction;

/**
 * @author <NAME> <<EMAIL>>
 */
class CndSyntaxTreeNodeVisitor implements SyntaxTreeVisitorInterface
{
    /**
     * @var \PHPCR\NodeType\NodeTypeManagerInterface
     */
    protected $nodeTypeManager;

    /**
     * @var \PHPCR\NamespaceRegistryInterface
     */
    protected $namespaceRegistry;

    /**
     * @var array
     */
    protected $nodeTypeDefs = array();

    /**
     * @var array
     */
    protected $namespaces = array();

    /**
     * @var \PHPCR\NodeType\NodeTypeTemplateInterface
     */
    protected $curNodeTypeDef;

    /**
     * @var \PHPCR\NodeType\PropertyDefinitionTemplateInterface
     */
    protected $curPropTypeDef;

    public function __construct(NamespaceRegistryInterface $nsRegistry, NodeTypeManagerInterface $ntManager)
    {
        $this->namespaceRegistry = $nsRegistry;
        $this->nodeTypeManager = $ntManager;
    }

    public function getNodeTypeDefs()
    {
        return $this->nodeTypeDefs;
    }

    public function getNamespaces()
    {
        return $this->namespaces;
    }

    public function visit(SyntaxTreeNode $node)
    {
        switch ($node->getType()) {

            case 'nsMapping':
                $this->namespaces[$node->getProperty('prefix')] = $node->getProperty('uri');
                break;

            case 'nodeTypeDef':
                $this->curNodeTypeDef = $this->nodeTypeManager->createNodeTypeTemplate();
                $this->nodeTypeDefs[] = $this->curNodeTypeDef;
                break;

            case 'nodeTypeName':
                if ($node->hasProperty('value')) {
                    $this->curNodeTypeDef->setName($node->getProperty('value'));
                }
                break;

            case 'supertypes':
                if ($node->hasProperty('value')) {
                    $this->curNodeTypeDef->setDeclaredSuperTypeNames($node->getProperty('value'));
                }
                break;

            case 'nodeTypeAttributes':
                $this->setNodeTypeAttributes($node);
                // return false to indicate we don't want to visit the children
                return false;

            case 'propertyDef':
                $this->curPropTypeDef = $this->nodeTypeManager->createPropertyDefinitionTemplate();
                $this->curNodeTypeDef->getPropertyDefinitionTemplates()->append($this->curPropTypeDef);
                break;

            case 'propertyName':
                $this->curPropTypeDef->setName($node->getProperty('value'));
                break;

            case 'propertyType':
                $this->curPropTypeDef->setRequiredType(PropertyType::valueFromName($node->getProperty('value')));
                break;

            case 'defaultValues':
                $this->curPropTypeDef->setDefaultValues($node->getProperty('value'));
                break;

            case 'valueConstraints':
                $this->curPropTypeDef->setValueConstraints($node->getProperty('value'));
                break;

            case 'propertyTypeAttributes':
                $this->setPropertyTypeAttributes($node);
                // return false to indicate we don't want to visit the children
                return false;

            default:
                var_dump(sprintf('Unhandled node [%s]', $node->getType()));

        }
    }

    protected function setNodeTypeAttributes(SyntaxTreeNode $node)
    {
        if ($node->hasChild('orderable')) $this->curNodeTypeDef->setOrderableChildNodes(true);
        if ($node->hasChild('mixin')) $this->curNodeTypeDef->setMixin(true);
        if ($node->hasChild('abstract')) $this->curNodeTypeDef->setAbstract(true);
        if ($node->hasChild('query')) $this->curNodeTypeDef->setQueryable(true);
    }

    protected function setPropertyTypeAttributes(SyntaxTreeNode $node)
    {
        if ($node->hasChild('autocreated')) $this->curPropTypeDef->setAutoCreated(true);
        if ($node->hasChild('mandatory')) $this->curPropTypeDef->setMandatory(true);
        if ($node->hasChild('protected')) $this->curPropTypeDef->setProtected(true);
        if ($node->hasChild('multiple')) $this->curPropTypeDef->setMultiple(true);
        if ($node->hasChild('queryops')) $this->curPropTypeDef->setAvailableQueryOperators($node->getPRoperty('value'));

        if ($node->hasChild('nofulltext')) {
            $this->curPropTypeDef->setFullTextSearchable(false);<commit_msg>Deactivated debug code<commit_after><?php

namespace PHPCR\Util\CND\Helper;

use PHPCR\Util\CND\Parser\SyntaxTreeNode,
    PHPCR\Util\CND\Parser\SyntaxTreeVisitorInterface,
    PHPCR\NamespaceRegistryInterface,
    PHPCR\NodeType\NodeTypeManagerInterface,
    PHPCR\NodeType\NodeTypeDefinitionInterface,
    PHPCR\PropertyType,
    PHPCR\Version\OnParentVersionAction;

/**
 * @author <NAME> <<EMAIL>>
 */
class CndSyntaxTreeNodeVisitor implements SyntaxTreeVisitorInterface
{
    /**
     * @var \PHPCR\NodeType\NodeTypeManagerInterface
     */
    protected $nodeTypeManager;

    /**
     * @var \PHPCR\NamespaceRegistryInterface
     */
    protected $namespaceRegistry;

    /**
     * @var array
     */
    protected $nodeTypeDefs = array();

    /**
     * @var array
     */
    protected $namespaces = array();

    /**
     * @var \PHPCR\NodeType\NodeTypeTemplateInterface
     */
    protected $curNodeTypeDef;

    /**
     * @var \PHPCR\NodeType\PropertyDefinitionTemplateInterface
     */
    protected $curPropTypeDef;

    public function __construct(NamespaceRegistryInterface $nsRegistry, NodeTypeManagerInterface $ntManager)
    {
        $this->namespaceRegistry = $nsRegistry;
        $this->nodeTypeManager = $ntManager;
    }

    public function getNodeTypeDefs()
    {
        return $this->nodeTypeDefs;
    }

    public function getNamespaces()
    {
        return $this->namespaces;
    }

    public function visit(SyntaxTreeNode $node)
    {
        switch ($node->getType()) {

            case 'nsMapping':
                $this->namespaces[$node->getProperty('prefix')] = $node->getProperty('uri');
                break;

            case 'nodeTypeDef':
                $this->curNodeTypeDef = $this->nodeTypeManager->createNodeTypeTemplate();
                $this->nodeTypeDefs[] = $this->curNodeTypeDef;
                break;

            case 'nodeTypeName':
                if ($node->hasProperty('value')) {
                    $this->curNodeTypeDef->setName($node->getProperty('value'));
                }
                break;

            case 'supertypes':
                if ($node->hasProperty('value')) {
                    $this->curNodeTypeDef->setDeclaredSuperTypeNames($node->getProperty('value'));
                }
                break;

            case 'nodeTypeAttributes':
                $this->setNodeTypeAttributes($node);
                // return false to indicate we don't want to visit the children
                return false;

            case 'propertyDef':
                $this->curPropTypeDef = $this->nodeTypeManager->createPropertyDefinitionTemplate();
                $this->curNodeTypeDef->getPropertyDefinitionTemplates()->append($this->curPropTypeDef);
                break;

            case 'propertyName':
                $this->curPropTypeDef->setName($node->getProperty('value'));
                break;

            case 'propertyType':
                $this->curPropTypeDef->setRequiredType(PropertyType::valueFromName($node->getProperty('value')));
                break;

            case 'defaultValues':
                $this->curPropTypeDef->setDefaultValues($node->getProperty('value'));
                break;

            case 'valueConstraints':
                $this->curPropTypeDef->setValueConstraints($node->getProperty('value'));
                var_dump($this->curNodeTypeDef->getDeclaredChildNodeDefinitions());die;
                break;

            case 'propertyTypeAttributes':
                $this->setPropertyTypeAttributes($node);
                // return false to indicate we don't want to visit the children
                return false;

            default:
//                var_dump(sprintf('Unhandled node [%s]', $node->getType()));

        }
    }

    protected function setNodeTypeAttributes(SyntaxTreeNode $node)
    {
        if ($node->hasChild('orderable')) $this->curNodeTypeDef->setOrderableChildNodes(true);
        if ($node->hasChild('mixin')) $this->curNodeTypeDef->setMixin(true);
        if ($node->hasChild('abstract')) $this->curNodeTypeDef->setAbstract(true);
        if ($node->hasChild('query')) $this->curNodeTypeDef->setQueryable(true);
    }

    protected function setPropertyTypeAttributes(SyntaxTreeNode $node)
    {
        if ($node->hasChild('autocreated')) $this->curPropTypeDef->setAutoCreated(true);
        if ($node->hasChild('mandatory')) $this->curPropTypeDef->setMandatory(true);
        if ($node->hasChild('protected')) $this->curPropTypeDef->setProtected(true);
        if ($node->hasChild('multiple')) $this->curPropTypeDef->setMultiple(true);
        if ($node->hasChild('queryops')) $this->curPropTypeDef->setAvailableQueryOperators($node->getPRoperty('value'));

        if ($node->hasChild('nofulltext')) {
            $this->curPropTypeDef->setFullTextSearchable(false);
{'fraction_non_alphanumeric': 0.13072509128847157, 'fraction_numerical': 0.0, 'mean_word_length': 2.4432471264367814, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 159, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2976977', 'n_tokens_mistral': 2622, 'n_tokens_neox': 2449, 'n_words': 384}