<commit_before>/**
 * Copyright 2011-2015 <NAME>
 *
 * 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.androidtransfuse.adapter.element;

import org.androidtransfuse.adapter.ASTAnnotation;
import org.androidtransfuse.adapter.ASTFactory;
import org.androidtransfuse.adapter.ASTType;
import org.androidtransfuse.transaction.TransactionRuntimeException;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleAnnotationValueVisitor6;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * Visitor to convert between the given annotation field and the given class type T
 *
 * @param <T>
 * @author <NAME>
 */
public class AnnotationValueConverterVisitor<T> extends SimpleAnnotationValueVisitor6<T, Void> {

    private static final String ERROR_TYPE = "<error>";

    private final Class<T> type;
    private final ASTTypeBuilderVisitor astTypeBuilderVisitor;
    private final ElementConverterFactory astTypeElementConverterFactory;
    private final ASTFactory astFactory;

    public AnnotationValueConverterVisitor(Class<T> type,
                                           ASTTypeBuilderVisitor astTypeBuilderVisitor,
                                           ElementConverterFactory astTypeElementConverterFactory,
                                           ASTFactory astFactory) {
        this.type = type;
        this.astTypeBuilderVisitor = astTypeBuilderVisitor;
        this.astTypeElementConverterFactory = astTypeElementConverterFactory;
        this.astFactory = astFactory;
    }

    @Override
    public T visitBoolean(boolean b, Void aVoid) {
        return visitSimple(Boolean.class, b);
    }

    @Override
    public T visitByte(byte b, Void aVoid) {
        return visitSimple(Byte.class, b);
    }

    @Override
    public T visitChar(char c, Void aVoid) {
        return visitSimple(Character.class, c);
    }

    @Override
    public T visitDouble(double d, Void aVoid) {
        return visitSimple(Double.class, d);
    }

    @Override
    public T visitFloat(float f, Void aVoid) {
        return visitSimple(Float.class, f);
    }

    @Override
    public T visitInt(int i, Void aVoid) {
        return visitSimple(Integer.class, i);
    }

    @Override
    public T visitLong(long l, Void aVoid) {
        return visitSimple(Long.class, l);
    }

    @Override
    public T visitShort(short s, Void aVoid) {
        return visitSimple(Short.class, s);
    }

    @Override
    public T visitString(String s, Void aVoid) {
        return visitSimple(String.class, s);
    }

    @Override
    public T visitType(TypeMirror typeMirror, Void aVoid) {
        if (type.isAssignableFrom(ASTType.class)) {
            return (T) typeMirror.accept(astTypeBuilderVisitor, null);
        }
        return null;
    }<commit_msg>Fixed annotation value converter for primitive types<commit_after>/**
 * Copyright 2011-2015 <NAME>
 *
 * 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.androidtransfuse.adapter.element;

import org.androidtransfuse.adapter.ASTAnnotation;
import org.androidtransfuse.adapter.ASTFactory;
import org.androidtransfuse.adapter.ASTType;
import org.androidtransfuse.transaction.TransactionRuntimeException;

import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.ElementKind;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeMirror;
import javax.lang.model.util.SimpleAnnotationValueVisitor6;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;

/**
 * Visitor to convert between the given annotation field and the given class type T
 *
 * @param <T>
 * @author <NAME>
 */
public class AnnotationValueConverterVisitor<T> extends SimpleAnnotationValueVisitor6<T, Void> {

    private static final String ERROR_TYPE = "<error>";

    private final Class<T> type;
    private final ASTTypeBuilderVisitor astTypeBuilderVisitor;
    private final ElementConverterFactory astTypeElementConverterFactory;
    private final ASTFactory astFactory;

    public AnnotationValueConverterVisitor(Class<T> type,
                                           ASTTypeBuilderVisitor astTypeBuilderVisitor,
                                           ElementConverterFactory astTypeElementConverterFactory,
                                           ASTFactory astFactory) {
        this.type = type;
        this.astTypeBuilderVisitor = astTypeBuilderVisitor;
        this.astTypeElementConverterFactory = astTypeElementConverterFactory;
        this.astFactory = astFactory;
    }

    @Override
    public T visitBoolean(boolean b, Void aVoid) {
        return visitSimple(boolean.class, b);
    }

    @Override
    public T visitByte(byte b, Void aVoid) {
        return visitSimple(byte.class, b);
    }

    @Override
    public T visitChar(char c, Void aVoid) {
        return visitSimple(char.class, c);
    }

    @Override
    public T visitDouble(double d, Void aVoid) {
        return visitSimple(double.class, d);
    }

    @Override
    public T visitFloat(float f, Void aVoid) {
        return visitSimple(float.class, f);
    }

    @Override
    public T visitInt(int i, Void aVoid) {
        return visitSimple(int.class, i);
    }

    @Override
    public T visitLong(long l, Void aVoid) {
        return visitSimple(long.class, l);
    }

    @Override
    public T visitShort(short s, Void aVoid) {
        return visitSimple(short.class, s);
    }

    @Override
    public T visitString(String s, Void aVoid) {
        return visitSimple(String.class, s);
    }

    @Override
    public T visitType(TypeMirror typeMirror, Void aVoid) {
        if (type.isAssignableFrom(ASTType.class)) {
            return (T) typeMirror.accept(astTypeBuilderVisitor, null);
        }
        return null;
    }
{'fraction_non_alphanumeric': 0.07996609211641707, 'fraction_numerical': 0.003955919751342187, 'mean_word_length': 3.0942741469057258, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2684596', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1855, 'n_words': 562}