Source File

class energyplus_refactor_helper.source_file.SourceFile(path: Path, function_calls: list[str])

This class represents a single source code file, processing it to find all matching function calls, and providing functionality to refactor them into a new form automatically.

Parameters:
  • path – The Path instance pointing to this source file

  • function_calls – The list of function calls currently being searched

static find_function_in_raw_line(functions: list[str], full_raw_line: str) tuple[int | None, int]

A simple worker function that searches a source line looking for one of the function call strings, and if found, returns both the found value along with the index in the line where it was found.

Parameters:
  • functions – A list of function calls as defined in one of the config classes

  • full_raw_line – A full line from the rwa source code, to be searched.

Returns:

A tuple, where the first item is an optional found error call type int, and the second is the index.

find_functions_in_original_text() list[FunctionCall]

Processes the original source code for this file, identifying all function calls. This function returns an array of FunctionCall objects for each function call processed.

Returns:

A list of FunctionCall instances, one for each function call processed.

get_advanced_function_distribution() list[int]

Returns a distribution of function calls for the given file. This returns an integer for the function call type from the specific function call search config list, from 1 to N, where N is the number of function calls being searched.

Returns:

An array of integers, one per line of original source code, indicating function call for that line.

get_binary_function_distribution() list[int]

Returns a distribution of function calls for the given file. This simply returns a 0 or 1, where 1 indicates the line is part of a function call, and 0 means it is not.

Returns:

An array of integers, one per line of original source code, indicating function call for that line.

get_function_call_groups() list[FunctionCallGroup]

This function loops over all found function calls in this file, groups them together into FunctionCallChunk instances.

Returns:

A list of FunctionCallChunk instances containing full function call info for this file.

get_new_file_text_function_based(func_visitor) str

Modifies the original file text, replacing every function call with the modified version.

Returns:

Returns the modified source code as a Python string.

get_new_file_text_group_based(group_visitor) str

Modifies the original file text, replacing every function call group with the modified version.

Returns:

Returns the modified source code as a Python string.

write_new_text_to_file(visitor, operate_on_group: bool) None

Overwrites existing file contents with the modified version, replacing each function call with the new version as defined by the action instance itself.

Parameters:
  • visitor – A callable function that takes either a FunctionCall or a FunctionCallInstance and returns a string. The type should depend on the group_flag argument.

  • operate_on_group – A flag indicating whether the action will operate on groups of function calls (if True) or individual function calls (if False)

Returns:

None