if tag3 == "parameter_list":
                            parameter_list_node = node2

                    for node in block_cs_node:
                        cs_tree_str = ""
                        tag1 = node.tag.replace(STUPID_URL, "")
                        if tag1 == "name":
                            cs_function_name_origin = node.text
                            cs_function_name = node.text.lower()
                            processed_cs_code = ""

                            cs_function_block = find_biggest_block(
                                block_cs_node)
                            cs_decl_stmt_locals = list()
                            cs_decl_stmt_locals = iterate_to_get_node_with_type(
                                cs_function_block, "decl_stmt",
                                cs_decl_stmt_locals)
                            cs_local_vars_mapping = get_information_of_decl_stmts(
                                cs_decl_stmt_locals)

                            cs_decl_params = list()
                            cs_decl_params = iterate_to_get_node_with_type(
                                parameter_list_node, "decl", cs_decl_params)
                            cs_param_function_vars_mapping = get_information_of_decl(
                                cs_decl_params)
                            cs_local_vars_mapping = {
                                **cs_local_vars_mapping,
                                **cs_param_function_vars_mapping
                            }
                            cs_local_vars_mapping = {
                                **cs_local_vars_mapping,
							for node2 in block_cs_node:
								tag3 = node2.tag.replace(STUPID_URL,"")
								if tag3 == "parameter_list":
									parameter_list_node = node2

							for node in block_cs_node:
								cs_tree_str = ""
								tag1 = node.tag.replace(STUPID_URL,"")
								if tag1 == "name":
									cs_function_name_origin = node.text
									cs_function_name = node.text.lower()
									processed_cs_code = ""

									cs_function_block = find_biggest_block(block_cs_node)
									cs_decl_stmt_locals = list()
									cs_decl_stmt_locals = iterate_to_get_node_with_type(cs_function_block,"decl_stmt",cs_decl_stmt_locals)	
									cs_local_vars_mapping = get_information_of_decl_stmts(cs_decl_stmt_locals)

									cs_decl_params = list()
									cs_decl_params = iterate_to_get_node_with_type(parameter_list_node, "decl", cs_decl_params)
									cs_param_function_vars_mapping = get_information_of_decl(cs_decl_params)
									cs_local_vars_mapping = {**cs_local_vars_mapping,**cs_param_function_vars_mapping}
									cs_local_vars_mapping = {**cs_local_vars_mapping,**cs_global_vars_mapping}

									processed_cs_code = iterate_function_node_to_get_text("cs",block_cs_node,processed_cs_code,cs_parent_map,cs_local_vars_mapping,cs_global_vars_mapping,cs_object_method_mapping,cs_package_object_mapping,cs_third_party_object_method_mapping_list,cs_third_party_package_object_mapping_list,candidate_sdk_packages)
									processed_cs_code = processed_cs_code.replace("@","")
									processed_cs_code = remove_uncessary_tokens(processed_cs_code)
									processed_cs_code = remove_empty_intext(processed_cs_code)
									# processed_cs_code = keep_only_method_api(processed_cs_code)
									# processed_cs_code = keep_only_cs_sdk_method_api(processed_cs_code,cs_keywords)
示例#3
0
for r, ds, files in os.walk(
        os.path.join(CURRENT_DIR, "SRCML_DATA_2", lang, project)):
    for file in files:

        file_path = os.path.join(r, file)
        print "Parsing file : " + file_path + " --------------------------"

        try:
            tree = parse_tree(file_path)
            root = tree.getroot()
            parent_map = get_parent_map(tree)

            decorations = ["class", "interface"]
            for decoration in decorations:
                java_class_nodes = list()
                java_class_nodes = iterate_to_get_node_with_type(
                    root, decoration, java_class_nodes)

                biggest_block_java = None
                class_name = None
                if len(java_class_nodes) != 0:
                    # print java_class_nodes[0].text
                    for c in java_class_nodes[0].getchildren():
                        tag = c.tag.replace(STUPID_URL, "")
                        if tag == "block":
                            biggest_block_java = c
                        if tag == "name":
                            if c.text != None:
                                class_name = c.text
                            else:
                                for c2 in c.getchildren():
                                    tag2 = c2.tag.replace(STUPID_URL, "")
for r,ds,files in os.walk(os.path.join(CURRENT_DIR,"SRCML_DATA_2",lang,project)):
	for file in files:
	
		file_path = os.path.join(r, file)
		print "Parsing file : " + file_path + " --------------------------"
		
	
		try:
			tree = parse_tree(file_path)
			root  = tree.getroot()
			parent_map = get_parent_map(tree)
			
			decorations = ["class","interface","struct"]
			for decoration in decorations:
				cs_class_nodes = list()
				cs_class_nodes = iterate_to_get_node_with_type(root,decoration,cs_class_nodes)

				biggest_block_cs = None
				class_name = None
			
				if len(cs_class_nodes) != 0:
					for c in cs_class_nodes[0].getchildren():
						tag = c.tag.replace(STUPID_URL,"")
						if tag == "block":
							biggest_block_cs = c
						if tag == "name":
							if c.text != None:
								class_name = c.text
							else:
								for c2 in c.getchildren():
									tag2 = c2.tag.replace(STUPID_URL,"")
from xml_util import get_parameter_type_of_method

STUPID_URL = "{http://www.srcML.org/srcML/src}"
cs_signatures = list()
try:
    tree = parse_tree("Temp.xml")
    root = tree.getroot()
    parent_map = get_parent_map(tree)

except Exception as e:
    print("Error in this block : " + str(e))

decorations = ["class", "interface"]
for decoration in decorations:
    cs_class_nodes = list()
    cs_class_nodes = iterate_to_get_node_with_type(root, decoration,
                                                   cs_class_nodes)

    biggest_block_cs = None
    class_name = None

    if len(cs_class_nodes) != 0:
        for c in cs_class_nodes[0].getchildren():
            tag = c.tag.replace(STUPID_URL, "")
            if tag == "block":
                biggest_block_cs = c
            if tag == "name":
                if c.text != None:
                    class_name = c.text
                else:
                    for c2 in c.getchildren():
                        tag2 = c2.tag.replace(STUPID_URL, "")
                                                        java_function_name_origin = node2.text
                                                        java_function_name = node2.text.lower(
                                                        )

                                                        if cs_function_name == java_function_name:

                                                            processed_cs_code = ""
                                                            processed_java_code = ""

                                                            cs_function_block = find_biggest_block(
                                                                block_cs_node)
                                                            cs_decl_stmt_locals = list(
                                                            )
                                                            cs_decl_stmt_locals = iterate_to_get_node_with_type(
                                                                cs_function_block,
                                                                "decl_stmt",
                                                                cs_decl_stmt_locals
                                                            )
                                                            cs_local_vars_mapping = get_information_of_decl_stmts(
                                                                cs_decl_stmt_locals
                                                            )
                                                            processed_cs_code = iterate_function_node_to_get_text(
                                                                "cs",
                                                                block_cs_node,
                                                                processed_cs_code,
                                                                cs_parent_map,
                                                                cs_local_vars_mapping,
                                                                cs_global_vars_mapping,
                                                                cs_object_method_mapping,
                                                                cs_package_object_mapping,
                                                                cs_third_party_object_method_mapping_list,
					stmt_nodes_cs = iterate_to_get_node_with_types(biggest_block_cs,types_cs,stmt_temp_1)

					stmt_temp_2 = list()
					stmt_nodes_java = iterate_to_get_node_with_types(biggest_block_java,types_java,stmt_temp_2)


					print len(stmt_nodes_cs)
					print len(stmt_nodes_java)
					for cs_node in stmt_nodes_cs:
						processed_cs_code = iterate_recursive(cs_node,cs_tree_str,cs_parent_map)
						processed_cs_code = process_srcml_source_code(processed_cs_code)
						line_cs = project + "," + cs_file + "," + processed_cs_code
						with open("./evaluation_data/statements/statements_cs_" + project + "_1.csv","a") as out:
							out.write(line_cs + "\n")

					for java_node in stmt_nodes_java:
						processed_java_code = iterate_recursive(java_node,java_tree_str,java_parent_map)						
						processed_java_code = process_srcml_source_code(processed_java_code)	
						line_java = project + "," + java_file + "," + processed_java_code
						with open("./evaluation_data/statements/statements_java_" + project + "_1.csv","a") as out:
							out.write(line_java + "\n")
				except Exception as e:
					print e

nodes_origin = list()
cs_root  = cs_tree.getroot()

print cs_root
nodes_return = iterate_to_get_node_with_type(cs_root,"expr",nodes_origin)

												for node2 in block_java_node:
													java_tree_str = ""
													tag3 = node2.tag.replace(STUPID_URL,"")
													if tag3 == "name":
														java_function_name_origin = node2.text
														java_function_name = node2.text.lower()
														
														if cs_function_name == java_function_name:

															processed_cs_code = ""
															processed_java_code = ""


															cs_function_block = find_biggest_block(block_cs_node)
															cs_decl_stmt_locals = list()
															cs_decl_stmt_locals = iterate_to_get_node_with_type(cs_function_block,"decl_stmt",cs_decl_stmt_locals)	
															cs_local_vars_mapping = get_information_of_decl_stmts(cs_decl_stmt_locals)
															processed_cs_code = iterate_function_node_to_get_text("cs",block_cs_node,processed_cs_code,cs_parent_map,cs_local_vars_mapping,cs_global_vars_mapping,cs_object_method_mapping,cs_package_object_mapping,cs_third_party_object_method_mapping_list,cs_third_party_package_object_mapping_list)
															processed_cs_code = processed_cs_code.replace("@","")
															processed_cs_code = remove_empty_intext(processed_cs_code)
															
															java_function_block = find_biggest_block(block_java_node)
															java_decl_stmt_locals = list()
															java_decl_stmt_locals = iterate_to_get_node_with_type(java_function_block,"decl_stmt",java_decl_stmt_locals)					
															java_local_vars_mapping = get_information_of_decl_stmts(java_decl_stmt_locals)
															processed_java_code = iterate_function_node_to_get_text("java",block_java_node,processed_java_code,java_parent_map,java_local_vars_mapping,java_global_vars_mapping,java_object_method_mapping,java_package_object_mapping,java_third_party_object_method_mapping_list,java_third_party_package_object_mapping_list)
															processed_java_code = processed_java_code.replace("@","")
															processed_java_code = remove_empty_intext(processed_java_code)

															divide_1 = float(len(processed_cs_code))/float(len(processed_java_code))
															divide_2 = float(len(processed_java_code))/float(len(processed_cs_code))
                    print len(stmt_nodes_java)
                    for cs_node in stmt_nodes_cs:
                        processed_cs_code = iterate_recursive(
                            cs_node, cs_tree_str, cs_parent_map)
                        processed_cs_code = process_srcml_source_code(
                            processed_cs_code)
                        line_cs = project + "," + cs_file + "," + processed_cs_code
                        with open(
                                "./evaluation_data/statements/statements_cs_" +
                                project + "_1.csv", "a") as out:
                            out.write(line_cs + "\n")

                    for java_node in stmt_nodes_java:
                        processed_java_code = iterate_recursive(
                            java_node, java_tree_str, java_parent_map)
                        processed_java_code = process_srcml_source_code(
                            processed_java_code)
                        line_java = project + "," + java_file + "," + processed_java_code
                        with open(
                                "./evaluation_data/statements/statements_java_"
                                + project + "_1.csv", "a") as out:
                            out.write(line_java + "\n")
                except Exception as e:
                    print e

nodes_origin = list()
cs_root = cs_tree.getroot()

print cs_root
nodes_return = iterate_to_get_node_with_type(cs_root, "expr", nodes_origin)
					java_class_node = get_class_node_java(java_root)
					
					biggest_block_cs = None
					biggest_block_java = None

					for c in cs_class_node.getchildren():
						tag = c.tag.replace(STUPID_URL,"")
						if tag == "block":
							biggest_block_cs = c
					for j in java_class_node.getchildren():
						tag = j.tag.replace(STUPID_URL,"")
						if tag == "block":
							biggest_block_java = j

					expr_temp_1 = list()
					expr_nodes_cs = iterate_to_get_node_with_type(biggest_block_cs,"expr",expr_temp_1)

					expr_temp_2 = list()
					expr_nodes_java = iterate_to_get_node_with_type(biggest_block_java,"expr",expr_temp_2)


					print len(expr_nodes_cs)
					print len(expr_nodes_java)
					for cs_node in expr_nodes_cs:
						processed_cs_code = iterate_recursive(cs_node,cs_tree_str,cs_parent_map)
						processed_cs_code = process_srcml_source_code(processed_cs_code)
						line_cs = project + "," + cs_file + "," + processed_cs_code
						with open("./evaluation_data/expressions/expressions_cs_" + project + "_1.csv","a") as out:
							out.write(line_cs + "\n")

					for java_node in expr_nodes_java: