<commit_before>/*
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.sal.binding.generator.impl

import javassist.ClassPool
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
import org.opendaylight.yangtools.yang.model.api.SchemaNode
import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils
import javassist.CtClass
import java.util.Map
import org.opendaylight.yangtools.yang.common.QName
import javassist.CtField
import static javassist.Modifier.*
import static org.opendaylight.yangtools.sal.binding.generator.impl.CodecMapping.*
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer
import org.opendaylight.yangtools.sal.binding.model.api.Type
import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder
import org.opendaylight.yangtools.binding.generator.util.Types
import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType
import java.util.HashMap
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode
import java.util.List
import java.util.TreeSet
import com.google.common.base.Joiner
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode
import static org.opendaylight.yangtools.sal.binding.generator.util.ClassLoaderUtils.*;
import org.opendaylight.yangtools.yang.binding.BindingDeserializer
import org.opendaylight.yangtools.yang.binding.BindingCodec
import org.slf4j.LoggerFactory
import org.opendaylight.yangtools.sal.binding.generator.util.CodeGenerationException
import org.opendaylight.yangtools.yang.model.api.ChoiceNode
import java.security.ProtectionDomain
import java.io.File
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty
import java.util.Map.Entry
import java.util.AbstractMap.SimpleEntry
import org.opendaylight.yangtools.yang.binding.DataObject
import org.opendaylight.yangtools.yang.binding.Augmentation
import java.util.Iterator
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema
import java.util.concurrent.ConcurrentHashMap
import static extension org.opendaylight.yangtools.sal.binding.generator.util.YangSchemaUtils.*;
import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl
import org.opendaylight.yangtools.yang.model.util.ExtendedType
import org.opendaylight.yangtools.yang.model.util.EnumerationType
import static com.google.common.base.Preconditions.*
import org.opendaylight.yangtools.yang.model.api.SchemaPath
import javassist.CtMethod
import javassist.CannotCompileException
import java.util.concurrent.locks.Lock
import java.util.concurrent.Callable
import org.opendaylight.yangtools.sal.binding.generator.util.ClassLoaderUtils
import org.opendaylight.yangtools.yang.model.api.TypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
import java.util.HashSet
import java.util.Collections
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit
import java.util.Set
import org.opendaylight.yangtools.sal.binding.generator.util.XtendHelper
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
import org.opendaylight.yangtools.yang.binding.BindingMapping
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition
import java.util.Collection

class TransformerGenerator {

    private static val log = LoggerFactory.getLogger(TransformerGenerator)

    public static val STRING = Types.typeForClass(String);
    public static val BOOLEAN = Types.typeForClass(Boolean);
    public static val INTEGER = Types.typeForClass(Integer);
    public static val INSTANCE_IDENTIFIER = Types.typeForClass(InstanceIdentifier)

    //public static val DECIMAL = Types.typeForClass(Decimal);
    public static val LONG = Types.typeForClass(Long);

    val ClassPool classPool
    val extension JavassistUtils utils;

    CtClass BINDING_CODEC

    CtClass ctQName

    @Property
    var File classFileCapturePath;

    @Property
    var Map<Type, Type> typeDefinitions = new ConcurrentHashMap();

    @Property
    var Map<Type, GeneratedTypeBuilder> typeToDefinition = new ConcurrentHashMap();

    @Property
    var Map<SchemaPath, GeneratedTypeBuilder> pathToType = new ConcurrentHashMap();

    @Property
    var Map<Type, SchemaNode> typeToSchemaNode = new ConcurrentHashMap();

    @Property
    var Map<Type, AugmentationSchema> typeToAugmentation = new ConcurrentHashMap();

    @Property
    var LazyGeneratedCodecRegistry listener;

    @Property
    var extension GeneratedClassLoadingStrategy classLoadingStrategy

    public static val CLASS_TYPE = Types.typeForClass(Class);

    public new(ClassPool pool) {
        classPool = pool;
        utils = new JavassistUtils(pool)

        BINDING_CODEC = BindingCodec.asCtClass;
        ctQName = QName.asCtClass

        this.classLoadingStrategy = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy();
    }

    def Class<? extends BindingCodec<Map<QName, Object>, Object>> transformerFor(Class<?> inputType) {
        return withClassLoaderAndLock(inputType.classLoader, lock) [ |
            val ret = getGeneratedClass(inputType)
            if (ret !== null) {
                listener.onClassProcessed(inputType);
                return ret as Class<? extends BindingCodec<Map<QName,Object>, Object>>;
            }
            val ref = Types.typeForClass(inputType)
            val node = typeToSchemaNode.get(ref)
            createMapping(inputType, node, null)
            val typeSpecBuilder = typeToDefinition.get(ref)
            checkState(typeSpecBuilder !== null, "Could not find typedefinition for %s", inputType.name);
            val typeSpec = typeSpecBuilder.toInstance();
            val newret = generateTransformerFor(inputType, typeSpec, node);
            listener.onClassProcessed(inputType);
            return newret as Class<? extends BindingCodec<Map<QName,Object>, Object>>;<commit_msg>BUG-893: do not use deprecated contructor<commit_after>/*
 * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
 *
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 * and is available at http://www.eclipse.org/legal/epl-v10.html
 */
package org.opendaylight.yangtools.sal.binding.generator.impl

import javassist.ClassPool
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType
import org.opendaylight.yangtools.yang.model.api.SchemaNode
import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils
import javassist.CtClass
import java.util.Map
import org.opendaylight.yangtools.yang.common.QName
import javassist.CtField
import static javassist.Modifier.*
import static org.opendaylight.yangtools.sal.binding.generator.impl.CodecMapping.*
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer
import org.opendaylight.yangtools.sal.binding.model.api.Type
import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder
import org.opendaylight.yangtools.binding.generator.util.Types
import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType
import java.util.HashMap
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode
import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode
import java.util.List
import java.util.TreeSet
import com.google.common.base.Joiner
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject
import org.opendaylight.yangtools.sal.binding.model.api.Enumeration
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode
import static org.opendaylight.yangtools.sal.binding.generator.util.ClassLoaderUtils.*;
import org.opendaylight.yangtools.yang.binding.BindingDeserializer
import org.opendaylight.yangtools.yang.binding.BindingCodec
import org.slf4j.LoggerFactory
import org.opendaylight.yangtools.sal.binding.generator.util.CodeGenerationException
import org.opendaylight.yangtools.yang.model.api.ChoiceNode
import java.security.ProtectionDomain
import java.io.File
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty
import java.util.Map.Entry
import java.util.AbstractMap.SimpleEntry
import org.opendaylight.yangtools.yang.binding.DataObject
import org.opendaylight.yangtools.yang.binding.Augmentation
import java.util.Iterator
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema
import java.util.concurrent.ConcurrentHashMap
import static extension org.opendaylight.yangtools.sal.binding.generator.util.YangSchemaUtils.*;
import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl
import org.opendaylight.yangtools.yang.model.util.ExtendedType
import org.opendaylight.yangtools.yang.model.util.EnumerationType
import static com.google.common.base.Preconditions.*
import org.opendaylight.yangtools.yang.model.api.SchemaPath
import javassist.CtMethod
import javassist.CannotCompileException
import java.util.concurrent.locks.Lock
import java.util.concurrent.Callable
import org.opendaylight.yangtools.sal.binding.generator.util.ClassLoaderUtils
import org.opendaylight.yangtools.yang.model.api.TypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
import java.util.HashSet
import java.util.Collections
import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit
import java.util.Set
import org.opendaylight.yangtools.sal.binding.generator.util.XtendHelper
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition
import org.opendaylight.yangtools.yang.binding.BindingMapping
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition
import java.util.Collection

class TransformerGenerator {

    private static val log = LoggerFactory.getLogger(TransformerGenerator)

    public static val STRING = Types.typeForClass(String);
    public static val BOOLEAN = Types.typeForClass(Boolean);
    public static val INTEGER = Types.typeForClass(Integer);
    public static val INSTANCE_IDENTIFIER = Types.typeForClass(InstanceIdentifier)

    //public static val DECIMAL = Types.typeForClass(Decimal);
    public static val LONG = Types.typeForClass(Long);

    val extension JavassistUtils utils;

    CtClass BINDING_CODEC

    CtClass ctQName

    @Property
    var File classFileCapturePath;

    @Property
    var Map<Type, Type> typeDefinitions = new ConcurrentHashMap();

    @Property
    var Map<Type, GeneratedTypeBuilder> typeToDefinition = new ConcurrentHashMap();

    @Property
    var Map<SchemaPath, GeneratedTypeBuilder> pathToType = new ConcurrentHashMap();

    @Property
    var Map<Type, SchemaNode> typeToSchemaNode = new ConcurrentHashMap();

    @Property
    var Map<Type, AugmentationSchema> typeToAugmentation = new ConcurrentHashMap();

    @Property
    var LazyGeneratedCodecRegistry listener;

    @Property
    var extension GeneratedClassLoadingStrategy classLoadingStrategy

    public static val CLASS_TYPE = Types.typeForClass(Class);

    public new(ClassPool pool) {
        utils = JavassistUtils.forClassPool(pool)

        BINDING_CODEC = BindingCodec.asCtClass;
        ctQName = QName.asCtClass

        this.classLoadingStrategy = GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy();
    }

    def Class<? extends BindingCodec<Map<QName, Object>, Object>> transformerFor(Class<?> inputType) {
        return withClassLoaderAndLock(inputType.classLoader, lock) [ |
            val ret = getGeneratedClass(inputType)
            if (ret !== null) {
                listener.onClassProcessed(inputType);
                return ret as Class<? extends BindingCodec<Map<QName,Object>, Object>>;
            }
            val ref = Types.typeForClass(inputType)
            val node = typeToSchemaNode.get(ref)
            createMapping(inputType, node, null)
            val typeSpecBuilder = typeToDefinition.get(ref)
            checkState(typeSpecBuilder !== null, "Could not find typedefinition for %s", inputType.name);
            val typeSpec = typeSpecBuilder.toInstance();
            val newret = generateTransformerFor(inputType, typeSpec, node);
            listener.onClassProcessed(inputType);
            return newret as Class<? extends BindingCodec<Map<QName,Object>, Object>>;
{'fraction_non_alphanumeric': 0.08523020257826888, 'fraction_numerical': 0.0015469613259668509, 'mean_word_length': 4.9413566739606125, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '4561710', 'n_tokens_mistral': 4125, 'n_tokens_neox': 3882, 'n_words': 718}