Package com.facebook.swift.codec.metadata

Examples of com.facebook.swift.codec.metadata.ThriftConstructorInjection


            throws Exception
    {
        // construct instance
        Object instance;
        {
            ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
            Object[] parametersValues = new Object[constructor.getParameters().size()];
            for (ThriftParameterInjection parameter : constructor.getParameters()) {
                Object value = data.get(parameter.getId());
                parametersValues[parameter.getParameterIndex()] = value;
            }

            try {
                instance = constructor.getConstructor().newInstance(parametersValues);
            }
            catch (InvocationTargetException e) {
                if (e.getTargetException() != null) {
                    Throwables.propagateIfInstanceOf(e.getTargetException(), Exception.class);
                }
View Full Code Here


        else {
            read.newObject(metadata.getBuilderClass()).dup();
        }

        // invoke constructor
        ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
        // push parameters on stack
        for (ThriftParameterInjection parameter : constructor.getParameters()) {
            read.loadVariable(structData.get(parameter.getId()));
        }
        // invoke constructor
        read.invokeConstructor(constructor.getConstructor())
                .storeVariable(instance);
        return instance;
    }
View Full Code Here

        read.visitLabel("no-field-ctor");

        // No args c'tor present.
        if (metadata.getConstructorInjection().isPresent()) {
            ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
            // invoke constructor
            read.invokeConstructor(constructor.getConstructor())
                    .storeVariable(instance);
        }
        else {
            read.pop() // get rid of the half-constructed element
                    .loadConstant(metadata.getStructClass())
View Full Code Here

            throws Exception
    {
        // construct instance
        Object instance;
        {
            ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
            Object[] parametersValues = new Object[constructor.getParameters().size()];
            for (ThriftParameterInjection parameter : constructor.getParameters()) {
                Object value = data.get(parameter.getId());
                parametersValues[parameter.getParameterIndex()] = value;
            }

            try {
                instance = constructor.getConstructor().newInstance(parametersValues);
            }
            catch (InvocationTargetException e) {
                if (e.getTargetException() != null) {
                    Throwables.propagateIfInstanceOf(e.getTargetException(), Exception.class);
                }
View Full Code Here

        if (data != null) {
            fieldMetadata = metadataMap.get(data.getKey());

            if (fieldMetadata != null && fieldMetadata.getConstructorInjection().isPresent()) {
                    ThriftConstructorInjection constructor = fieldMetadata.getConstructorInjection().get();

                    Object[] parametersValues = new Object[] { data.getValue() };

                    try {
                        instance = constructor.getConstructor().newInstance(parametersValues);
                    }
                    catch (InvocationTargetException e) {
                        if (e.getTargetException() != null) {
                            Throwables.propagateIfInstanceOf(e.getTargetException(), Exception.class);
                        }
                        throw e;
                    }
            }
        }

        if (instance == null && metadata.getConstructorInjection().isPresent()) {
            ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
            // must be no-args
            Object[] parametersValues = new Object[0];

            try {
                instance = constructor.getConstructor().newInstance(parametersValues);
            }
            catch (InvocationTargetException e) {
                if (e.getTargetException() != null) {
                    Throwables.propagateIfInstanceOf(e.getTargetException(), Exception.class);
                }
View Full Code Here

        else {
            read.newObject(metadata.getBuilderClass()).dup();
        }

        // invoke constructor
        ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
        // push parameters on stack
        for (ThriftParameterInjection parameter : constructor.getParameters()) {
            read.loadVariable(structData.get(parameter.getId()));
        }
        // invoke constructor
        read.invokeConstructor(constructor.getConstructor())
                .storeVariable(instance);
        return instance;
    }
View Full Code Here

        read.visitLabel("no-field-ctor");

        // No args c'tor present.
        if (metadata.getConstructorInjection().isPresent()) {
            ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
            // invoke constructor
            read.invokeConstructor(constructor.getConstructor())
                    .storeVariable(instance);
        }
        else {
            read.pop() // get rid of the half-constructed element
                    .loadConstant(metadata.getStructClass())
View Full Code Here

        else {
            read.newObject(metadata.getBuilderClass()).dup();
        }

        // invoke constructor
        ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
        // push parameters on stack
        for (ThriftParameterInjection parameter : constructor.getParameters()) {
            read.loadVariable(structData.get(parameter.getId()));
        }
        // invoke constructor
        read.invokeConstructor(constructor.getConstructor())
                .storeVariable(instance);
        return instance;
    }
View Full Code Here

        read.visitLabel("no-field-ctor");

        // No args c'tor present.
        if (metadata.getConstructorInjection().isPresent()) {
            ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
            // invoke constructor
            read.invokeConstructor(constructor.getConstructor())
                    .storeVariable(instance);
        }
        else {
            read.pop() // get rid of the half-constructed element
                    .loadConstant(metadata.getStructClass())
View Full Code Here

            throws Exception
    {
        // construct instance
        Object instance;
        {
            ThriftConstructorInjection constructor = metadata.getConstructorInjection().get();
            Object[] parametersValues = new Object[constructor.getParameters().size()];
            for (ThriftParameterInjection parameter : constructor.getParameters()) {
                Object value = data.get(parameter.getId());
                parametersValues[parameter.getParameterIndex()] = value;
            }

            try {
                instance = constructor.getConstructor().newInstance(parametersValues);
            }
            catch (InvocationTargetException e) {
                if (e.getTargetException() != null) {
                    Throwables.propagateIfInstanceOf(e.getTargetException(), Exception.class);
                }
View Full Code Here

TOP

Related Classes of com.facebook.swift.codec.metadata.ThriftConstructorInjection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.