<commit_before>package com.poco.PoCoRuntime;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * Created by caoyan on 1/30/15.
 */
public class Promoter {
    /**
     *
     * @param pocoString
     *            the function want to be invoked
     * @throws Exception
     */
    public static void Reflect(String pocoString, Object[] objects) throws Exception {
        // className.funcName(#java.lang.Integer{42},#java.lang.String{402125})
        List<String> toExecute = Parse(pocoString);
        // class we are calling
        String className = toExecute.get(0)
                .substring(0, toExecute.get(0).length() - 1).trim();
        // the name of function the to be invoked
        String methodName = toExecute.get(1).trim();
        ArrayList<ReflectParameter> rps = null;
        // if params list is not empty
        if (toExecute.size() == 3) {
            String[] params = toExecute.get(2).split(","); // #java.lang.Integer{42}
            rps = ParseParameters(params);
        }
        ReflectExecute(className, methodName, rps, objects);
    }

    private static void ReflectExecute(String className, String methodName,
                                      ArrayList<ReflectParameter> params, Object[] objs) throws Exception {
        try {
        	boolean isfound = false;
        	
        	//get rid of the return type if the string contains it
        	if(className.trim().split(" ").length == 2)
        		className = className.trim().split(" ")[1];
            Class cls1 = Class.forName(className);
            Method[] methods = cls1.getMethods();
            Method theMethod = null;
            int paramCounts = params.size();

            for (Method method : methods) {
                // if find the method name
                if (method.getName().equals(methodName)) {
                    Type[] methodParams = method.getGenericParameterTypes();
                    if (methodParams.length == paramCounts) {
                        isfound = true;
                        int i = 0;
                        for (Iterator<ReflectParameter> it = params.iterator(); it
                                .hasNext();) {
                            String methodParam = GetTypeName(methodParams[i]
                                    .toString());
                            // if the type is not the primitive type
                            if (!methodParam.equals(it.next().GetParameterType())) {
                                isfound = false;
                                break;
                            }
                            i++;
                        }
                    }
                }
                if (isfound) {
                    theMethod = method;
                    break;
                }
            }
            // found the right method that is we wanted
            if (isfound) {
                if (paramCounts > 0) {
                    /*Object[] objs = new Object[paramCounts];
                    int i = 0;
                    for (Iterator<ReflectParameter> it = params.iterator(); it
                            .hasNext();) {
                        ReflectParameter rp = it.next();

                        if (!rp.GetParameterValue().equalsIgnoreCase("null"))
                            objs[i] = newInstance4Param(rp.GetParameterType(),
                                    rp.GetParameterValue());
                        i++;
                    }
                    */<commit_msg>handle null case<commit_after>package com.poco.PoCoRuntime;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


/**
 * Created by caoyan on 1/30/15.
 */
public class Promoter {
    /**
     *
     * @param pocoString
     *            the function want to be invoked
     * @throws Exception
     */
    public static void Reflect(String pocoString, Object[] objects) throws Exception {
        // className.funcName(#java.lang.Integer{42},#java.lang.String{402125})
        List<String> toExecute = Parse(pocoString);
        // class we are calling
        String className = toExecute.get(0).substring(0, toExecute.get(0).length() - 1).trim();
        // the name of function the to be invoked
        String methodName = toExecute.get(1).trim();
        ArrayList<ReflectParameter> rps = null;
        // if params list is not empty
        if (toExecute.size() == 3) {
            String[] params = toExecute.get(2).split(","); // #java.lang.Integer{42}
            rps = ParseParameters(params);
        }
        ReflectExecute(className, methodName, rps, objects);
    }

    private static void ReflectExecute(String className, String methodName,
                                      ArrayList<ReflectParameter> params, Object[] objs) throws Exception {
        try {
        	boolean isfound = false;
        	
        	//get rid of the return type if the string contains it
        	if(className.trim().split(" ").length == 2)
        		className = className.trim().split(" ")[1];
            Class cls1 = Class.forName(className);
            Method[] methods = cls1.getMethods();
            Method theMethod = null;
            int paramCounts = 0;
            if (params != null)
                paramCounts = params.size();

            for (Method method : methods) {
                // if find the method name
                if (method.getName().equals(methodName)) {
                    Type[] methodParams = method.getGenericParameterTypes();
                    if (methodParams.length == paramCounts) {
                        isfound = true;
                        int i = 0;
                        for (Iterator<ReflectParameter> it = params.iterator(); it
                                .hasNext();) {
                            String methodParam = GetTypeName(methodParams[i]
                                    .toString());
                            // if the type is not the primitive type
                            if (!methodParam.equals(it.next().GetParameterType())) {
                                isfound = false;
                                break;
                            }
                            i++;
                        }
                    }
                }
                if (isfound) {
                    theMethod = method;
                    break;
                }
            }
            // found the right method that is we wanted
            if (isfound) {
                if (paramCounts > 0) { 
{'fraction_non_alphanumeric': 0.10190256558085904, 'fraction_numerical': 0.008503891611415394, 'mean_word_length': 1.3828983516483517, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6531992', 'n_tokens_mistral': 1745, 'n_tokens_neox': 1661, 'n_words': 436}