Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions docs/Design/SoftArchitecture/MG.tex
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ \section{Module Hierarchy} \label{SecMH}
\item [\refstepcounter{mnum} \mthemnum \label{mUGENR}:] UseAGeneratorRefactorer Module
\item [\refstepcounter{mnum} \mthemnum \label{mCRC}:] CacheRepeatedCallsRefactorer Module
\item [\refstepcounter{mnum} \mthemnum \label{mLEC}:] LongElementChainRefactorer Module
\item [\refstepcounter{mnum} \mthemnum \label{mLPL}:] LongParameterListRefactorer Module
\item [\refstepcounter{mnum} \mthemnum \label{mPyA}:] Pylint Analyzer Module
\item [\refstepcounter{mnum} \mthemnum \label{mTest}:] Testing Functionality Module
\end{description}
Expand All @@ -268,7 +269,7 @@ \section{Module Hierarchy} \label{SecMH}
& UseAGeneratorRefactorer Module\\
& ?\\
& LongElementChainRefactorer Module\\
& ?\\
& LongParameterListRefactorer Module\\
& ?\\
& ?\\
& ?\\
Expand Down Expand Up @@ -389,6 +390,17 @@ \subsubsection{Long Element Chain Module (\mref{mLEC})}
\item[Implemented By:] EcoOptimizer
\end{description}

\subsubsection{Long Parameter List Module (\mref{mLPL})}

% [Record, Library, Abstract Object, or Abstract Data Type]

\begin{description}
\item[Secrets:] How to parse a given code file to its AST representation, traverse the AST tree to identify functions or methods with long parameter lists, and encapsulate related parameters into objects or structures. Additionally, it identifies all function or method calls associated with these functions and updates their arguments to align with the refactored signature.
\item[Services:] Detects long parameter lists in functions or methods using AST parsing, simplifies their structure by grouping related parameters into objects or structures, and updates all associated function or method calls throughout the file. This improves code readability, reduces complexity, and ensures correctness while maintaining the program’s intended behavior.
\item[Implemented By:] EcoOptimizer
\end{description}


\subsection{Software Decision Module}

\begin{description}
Expand Down Expand Up @@ -548,7 +560,7 @@ \section{Timeline}
Long Message Chain & Mya Hussain & Jan 6, 2025 \\ \hline
Member Ignoring Method & Sevhena Walker & Jan 6, 2025 \\ \hline
Repeated Calls & Nivetha Kuruparan & Jan 6, 2025 \\ \hline
String Concatenation in Loop & Team Member 8 & Jan 6, 2025 \\ \hline
String Concatenation in Loop & Sevhena Walker & Jan 6, 2025 \\ \hline
Long Parameter List & Tanveer Brar & Jan 6, 2025 \\ \hline
Smell & All & Jan 31, 2025 \\ \hline
Analyzers & All & Jan 31, 2025 \\ \hline
Expand Down
94 changes: 94 additions & 0 deletions docs/Design/SoftDetailedDes/MIS.tex
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,100 @@ \section{Module Decomposition}
\newpage
~\newpage

\section{MIS of LongParameterListRefactorer} \label{Module} \wss{Use labels for
cross-referencing}

\wss{You can reference SRS labels, such as R\ref{R_Inputs}.}

\wss{It is also possible to use \LaTeX for hypperlinks to external documents.}

\subsection{Module}

LongParameterListRefactorer is a module that identifies and refactors functions or methods with long parameter lists(detected beyond configured threshold) in Python code. The refactoring aims to improve code readability, maintainability, and energy efficiency by encapsulating related parameters into objects and removing unused ones.

\subsection{Uses}

\begin{itemize}
\item Uses \texttt{Smell} interface for data access
\item Inherits from \texttt{BaseRefactorer}
\item Inherits from Python's \texttt{ast} module's \texttt{NodeTransformer}
\end{itemize}

\subsection{Syntax}

\subsubsection{Exported Constants}

None

\subsubsection{Exported Access Programs}

\begin{center}
\begin{tabular}{|p{3cm}|p{5cm}|p{2cm}|p{3cm}|}
\hline
\textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\
\hline
\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\
\hline
\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: float} & None & Logging exceptions \\
\hline
\end{tabular}
\end{center}

\subsection{Semantics}

\subsubsection{State Variables}

None

\subsubsection{Environment Variables}

\begin{itemize}
\item \textbf{File system}: Used for reading, writing, and storing temporary and refactored files.
\item \textbf{Logger}: Logs details of the refactoring process.
\end{itemize}

\subsubsection{Assumptions}

\begin{itemize}
\item Input files are valid Python scripts.
\item Smells identified by \texttt{pylint\_smell} include valid line numbers.
\item Refactored code must pass the provided test suite.
\end{itemize}

\subsubsection{Access Routine Semantics}

\paragraph{\texttt{init(output\_dir: Path)}}
\begin{itemize}
\item \textbf{Transition}: Initializes the refactorer with the specified output directory.
\item \textbf{Output}: None.
\item \textbf{Exception}: None.
\end{itemize}

\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}}
\begin{itemize}
\item \textbf{Transition}:
\begin{enumerate}
\item Reads the file at \texttt{file\_path} and locates the target function using \texttt{pylint\_smell}.
\item Analyzes function body to remove unused parameters. Updates the function signature and references in the code accordingly.
\item If number of used parameters also exceeds the maximum configured limit, encapsulates related parameters into classes. Updates the function signature and references in the code accordingly.
\item Writes the refactored code to a temporary file.
\end{enumerate}
\item \textbf{Output}: None.Refactored file is saved if improvements are validated.
\item \textbf{Exception}: Logs exceptions during file operations or the refactoring process.
\end{itemize}

\subsubsection{Local Functions}

\begin{enumerate}
\item \texttt{get\_used\_parameters(function\_node: ast.FunctionDef, params: list[str]) -> set[str]}: Identifies parameters used within the function body.
\item \texttt{get\_parameters\_with\_default\_value(default\_values: list[ast.Constant], params: list[str]) -> dict}: Maps parameter names to their default values.
\item \texttt{classify\_parameters(params: list[str]) -> dict}: Classifies parameters into \texttt{data} and \texttt{config} groups based on naming conventions.
\item \texttt{create\_parameter\_object\_class(param\_names: list[str], default\_value\_params: dict, class\_name: str) -> str}: Generates class definitions for encapsulating parameters.
\item \texttt{update\_function\_signature(function\_node: ast.FunctionDef, params: dict) -> ast.FunctionDef}: Updates function signatures to use encapsulated parameter objects.
\item \texttt{update\_parameter\_usages(function\_node: ast.FunctionDef, params: dict) -> ast.FunctionDef}: Replaces parameter usages within the function body with attributes of encapsulated objects.
\item \texttt{update\_function\_calls(tree: ast.Module, function\_node: ast.FunctionDef, params: dict) -> ast.Module}: Updates all calls to the refactored function.
\end{enumerate}

\section{MIS of \wss{Module Name}} \label{Module} \wss{Use labels for
cross-referencing}

Expand Down