Ejemplo n.º 1
0
 def get_list_of_classes_names(java_files):
     """
     It return a list of java classes names
     :param java_files: List of .java files
     :return: List of classes_names
     """
     classes = list()
     regex_handler = RegexHandler()
     for java_file in java_files:
         class_name = regex_handler.apply_class_name_from_path_regex(string=java_file)
         classes.append(class_name[0])
     return classes
Ejemplo n.º 2
0
 def __create_relation(java_file, data_type):
     """
     This private method prepare dictionary of classi and classj which have a relation
     :param java_file: class
     :param data_type: object data type or a return data type
     :return: dictionary
     """
     relation = dict()
     regex_handler = RegexHandler()
     class_name = regex_handler.apply_class_name_from_path_regex(string=java_file)[0]
     relation[data_type] = class_name
     return relation
Ejemplo n.º 3
0
 def get_list_of_classes_names_and_parents(java_files):
     """
     It return a dictionary of java classes names  and their parents in the given java files
     :param java_files: List of .java files
     :return: List of [{class_name: parent}, {...}, ...]
     """
     class_list = list()
     regex_handler = RegexHandler()
     for java_file in java_files:
         class_and_parent = regex_handler.apply_class_name_and_parent_regex(file_path=java_file)
         classes_dict = dict()
         for (class_name, class_parent)in class_and_parent:
             classes_dict[class_name] = class_parent
         class_list.append(classes_dict)
     return class_list
Ejemplo n.º 4
0
 def get_static_method_calls(java_file, classes=None):
     """
     Apply static method call pattern and return a list of all classes called a static method
     :param java_file: Java class
     :return: list of classes and object called a method
     """
     list_of_classes_or_objects = list()
     regex_handler = RegexHandler()
     objects_or_classes = regex_handler.apply_static_method_call_regex(file_path=java_file)
     if classes:
         for class_name in objects_or_classes:
             if class_name in classes:
                 list_of_classes_or_objects.append(class_name)
     else:
         list_of_classes_or_objects = objects_or_classes
     return list_of_classes_or_objects
Ejemplo n.º 5
0
 def get_attributes_types(java_file, only_final=False):
     """
     This method prepare a list of specific info from all attributes defined in the given class
     :param java_file: Class
     :param only_final: Include only final attributes
     :return: List
     """
     list_of_data_types = list()
     regex_handler = RegexHandler()
     attributes = regex_handler.apply_object_definition_regex(file_path=java_file)
     for (final_field, data_type, _) in attributes:
         if only_final and final_field == "final":
             list_of_data_types.append(data_type)
         elif not only_final and final_field != "final":
             list_of_data_types.append(data_type)
     return list_of_data_types
Ejemplo n.º 6
0
 def create_methods_dictionary(file_path):
     """
     This method takes a java file name and return a dicionary of the methods it contains
     :param file_path: Java File path
     :return: List of dictionaries of the file methods
     """
     methods_list = list()
     method_handler = RegexHandler()
     methods = method_handler.apply_methods_regex(file_path=file_path)
     for (access_modifier, return_type, name, arguments, body) in methods:
         method_dict = dict()
         method_dict["access_modifier"] = access_modifier
         method_dict["return_type"] = return_type
         method_dict["name"] = name
         method_dict["arguments"] = JavaFilesInfo.get_method_arguments(arguments)
         method_dict["body"] = body
         methods_list.append(method_dict)
     return methods_list
Ejemplo n.º 7
0
from regex_handler import RegexHandler
from nfa_to_nfd_converter import NFAToNFDConverter
from epsilon_nfa_to_nfa_converter import EpsilonNFAToNFAConverter
from substrings_accepted import SubstringsAccepted
from substrings_accepted import SubstringsAccepted
from state_reducer import StateReducer

if __name__ == "__main__":
    #expr = input("Digite a expressão regular aqui: ")
    expr = "a*b*c*"
    regex_handler = RegexHandler(expr)

    while regex_handler.check_running():
        regex_handler.check_union()
        regex_handler.check_concatenation()
        regex_handler.check_kleene()
        regex_handler.check_parentheses()

    # regex_handler.graph.create_output()

    epsilon_nfa_to_nfa_converter = EpsilonNFAToNFAConverter(
        regex_handler.graph)
    nfa_graph = epsilon_nfa_to_nfa_converter.epsilon_nfa_to_nfa()
    #nfa_graph.create_output()

    # SubstringsAccepted(nfa_graph)

    nfa_to_nfd_converter = NFAToNFDConverter(nfa_graph)
    nfd_graph = nfa_to_nfd_converter.nfa_to_nfd(id=0)
    #nfd_graph.create_output()
Ejemplo n.º 8
0
def create_automata_from_regex(min_state=False):
    expr = input("Digite a expressão regular aqui: ")
    regex_handler = RegexHandler(expr)

    while regex_handler.check_running():
        regex_handler.check_union()
        regex_handler.check_concatenation()
        regex_handler.check_kleene()
        regex_handler.check_parentheses()

    # regex_handler.graph.create_output()

    epsilon_nfa_to_nfa_converter = EpsilonNFAToNFAConverter(
        regex_handler.graph)
    nfa_graph = epsilon_nfa_to_nfa_converter.epsilon_nfa_to_nfa()
    # nfa_graph.create_output()

    if min_state is False:
        return nfa_graph

    nfa_to_nfd_converter = NFAToNFDConverter(nfa_graph)
    nfd_graph = nfa_to_nfd_converter.nfa_to_nfd(id=0)
    # nfd_graph.create_output()
    # return nfd_graph

    state_reducer = StateReducer(nfd_graph)
    reduced_graph = state_reducer.reduce_graph()

    return reduced_graph