All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jboss.cdi.tck.tests.extensions.alternative.metadata.MarketWrapper Maven / Gradle / Ivy

There is a newer version: 2.0.5.SP1
Show newest version
/*
 * JBoss, Home of Professional Open Source
 * Copyright 2014, Red Hat, Inc., and individual contributors
 * by the @authors tag. See the copyright.txt in the distribution for a
 * full listing of individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.jboss.cdi.tck.tests.extensions.alternative.metadata;

import org.jboss.cdi.tck.util.annotated.*;

import javax.enterprise.inject.Any;
import javax.enterprise.inject.spi.AnnotatedConstructor;
import javax.enterprise.inject.spi.AnnotatedField;
import javax.enterprise.inject.spi.AnnotatedMethod;
import javax.enterprise.inject.spi.AnnotatedType;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import java.util.HashSet;
import java.util.Set;

public class MarketWrapper extends AnnotatedTypeWrapper {

    private final Set typeClosure = new HashSet();
    private static boolean getBaseTypeOfMarketConstructorParameterUsed = false;
    private static boolean getBaseTypeOfBillProducerParameterUsed = false;
    private static boolean getTypeCLosureOfProducerFieldUsed = false;

    public MarketWrapper(AnnotatedType delegate) {
        super(delegate, true);
        typeClosure.add(Market.class);
        typeClosure.add(Object.class);

    }

    @Override
    public Set getTypeClosure() {
        return typeClosure;
    }

    @Override
    public Set> getConstructors() {
        Set> constructors = new HashSet>();
        for (AnnotatedConstructor constructor : super.getConstructors()) {
            if (constructor.getParameters().size() == 1) {
                constructors.add(wrapConstructor(constructor, true, Any.Literal.INSTANCE));
            } else {
                constructors.add(constructor);
            }
        }
        return constructors;
    }

    @Override
    public Set> getFields() {
        Set> fields = new HashSet>();
        for (AnnotatedField field : super.getFields()) {
            if (field.getJavaMember().getType().equals(Carrot.class)) {
                AnnotatedFieldWrapper fieldWrapper = new AnnotatedFieldWrapper(field, this, true) {
                    @Override
                    public Set getTypeClosure() {
                        Set types = new HashSet();
                        types.add(Carrot.class);
                        getTypeCLosureOfProducerFieldUsed = true;
                        return types;
                    }
                };
                fields.add(fieldWrapper);
            } else {
                fields.add(field);
            }
        }
        return fields;
    }

    @Override
    public Set> getMethods() {
        Set> methods = new HashSet>();
        for (AnnotatedMethod method : super.getMethods()) {
            if (method.getJavaMember().getName().equals("createBill")) {
                methods.add(wrapMethodParameter(method, true));
            } else {
                methods.add(method);
            }

        }
        return methods;
    }

    public AnnotatedMethodWrapper wrapMethodParameter(AnnotatedMethod delegate, boolean keepOriginalAnnotations) {

        AnnotatedMethodWrapper methodWrapper = new AnnotatedMethodWrapper(delegate, this, keepOriginalAnnotations);
        methodWrapper.replaceParameters(new AnnotatedParameterWrapper(methodWrapper.getParameter(0),methodWrapper, true) {
            @Override
            public Type getBaseType() {
                getBaseTypeOfBillProducerParameterUsed = true;
                return TropicalFruit.class;
            }
        });

        return methodWrapper;
    }

    private AnnotatedConstructor wrapConstructor
            (AnnotatedConstructor delegate, final boolean keepOriginalAnnotations, final Annotation... annotations) {
        AnnotatedConstructorWrapper constructor = new AnnotatedConstructorWrapper(delegate, this, keepOriginalAnnotations, annotations);
        constructor.replaceParameters(new AnnotatedParameterWrapper(constructor.getParameter(0),constructor,  keepOriginalAnnotations, annotations) {
            @Override
            public Type getBaseType() {
                getBaseTypeOfMarketConstructorParameterUsed = true;
                return TropicalFruit.class;
            }

        });
        return constructor;
    }

    public static boolean isGetBaseTypeOfMarketConstructorParameterUsed() {
        return getBaseTypeOfMarketConstructorParameterUsed;
    }

    public static boolean isGetBaseTypeOfBillProducerParameterUsed() {
        return getBaseTypeOfBillProducerParameterUsed;
    }

    public static boolean isGetTypeCLosureOfProducerFieldUsed() {
        return getTypeCLosureOfProducerFieldUsed;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy