From ecccfbbb090e184b343dbbe5d1bc822b06bc5463 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 17 Jan 2025 14:41:53 -0500 Subject: [PATCH 1/5] Formatting and detail fixes --- docs/Design/SoftArchitecture/MG.tex | 73 ++- docs/Design/SoftDetailedDes/MIS.tex | 671 ++++++++++++---------------- 2 files changed, 309 insertions(+), 435 deletions(-) diff --git a/docs/Design/SoftArchitecture/MG.tex b/docs/Design/SoftArchitecture/MG.tex index f8a01734..f7655198 100644 --- a/docs/Design/SoftArchitecture/MG.tex +++ b/docs/Design/SoftArchitecture/MG.tex @@ -46,8 +46,7 @@ \section{Revision History} \begin{tabularx}{\textwidth}{p{3cm}p{2cm}X} \toprule {\bf Date} & {\bf Version} & {\bf Notes}\\ \midrule -Date 1 & 1.0 & Notes\\ -Date 2 & 1.1 & Notes\\ +January 17th, 2025 & 0.1 & Initial draft\\ \bottomrule \end{tabularx} @@ -74,7 +73,11 @@ \subsection{Abbreviations and Acronyms} SRS & Software Requirements Specification\\ \progname & Explanation of program name\\ UC & Unlikely Change \\ - \wss{etc.} & \wss{...}\\ + VS & Visual Studio\\ + API & Application Programing Interface\\ + IDE & Integrated Development Environment\\ + AST & Abstract Syntax Tree\\ + CSV & Comma-Separated Values\\ \bottomrule \end{tabular}\\ @@ -235,20 +238,19 @@ \section{Module Hierarchy} \label{SecMH} actually be implemented. \begin{description} -\item [\refstepcounter{mnum} \mthemnum \label{mHH}:] Hardware-Hiding Module -\item [\refstepcounter{mnum} \mthemnum \label{mLMC}:] LongMessageChainRefactorer Module -\item [\refstepcounter{mnum} \mthemnum \label{mLLF}:] LongLambdaFunctionRefactorer Module -\item [\refstepcounter{mnum} \mthemnum \label{mM}:] Measurements Module -\item [\refstepcounter{mnum} \mthemnum \label{mSmell}:] Smell Module -\item [\refstepcounter{mnum} \mthemnum \label{mBR}:] BaseRefactorer Module -\item [\refstepcounter{mnum} \mthemnum \label{mMIMR}:] MakeStaticRefactorer Module -\item [\refstepcounter{mnum} \mthemnum \label{mSCLR}:] UseListAccumulationRefactorer Module -\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 + \item [\refstepcounter{mnum} \mthemnum \label{mSmell}:] Smell Module + \item [\refstepcounter{mnum} \mthemnum \label{mBR}:] BaseRefactorer Module + \item [\refstepcounter{mnum} \mthemnum \label{mMIMR}:] MakeStaticRefactorer Module + \item [\refstepcounter{mnum} \mthemnum \label{mSCLR}:] UseListAccumulationRefactorer Module + \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{mLMC}:] LongMessageChainRefactorer Module + \item [\refstepcounter{mnum} \mthemnum \label{mLLF}:] LongLambdaFunctionRefactorer Module + \item [\refstepcounter{mnum} \mthemnum \label{mMeasure}:] Measurements Module + \item [\refstepcounter{mnum} \mthemnum \label{mPyA}:] Pylint Analyzer Module + \item [\refstepcounter{mnum} \mthemnum \label{mTest}:] Testing Functionality Module \end{description} @@ -264,25 +266,20 @@ \section{Module Hierarchy} \label{SecMH} \multirow{7}{0.3\textwidth}{Behaviour-Hiding Module} & Smell Module\\ & BaseRefactorer Module\\ -& CacheRepeatedCallsRefactorer Module\\ & MakeStaticRefactorer Module\\ & UseListAccumulationRefactorer Module\\ -& ?\\ & UseAGeneratorRefactorer Module\\ -& ?\\ +& CacheRepeatedCallsRefactorer Module\\ & LongElementChainRefactorer Module\\ & LongParameterListRefactorer Module\\ -& ?\\ -& ?\\ -& ?\\ +& LongMessageChainRefactorer Module\\ +& LongLambdaFunctionRefactorer Module\\ \midrule -\multirow{3}{0.3\textwidth}{Software Decision Module} & {?}\\ -& Measurements Module\\ -& ?\\ -\multirow{3}{0.3\textwidth}{Software Decision Module} & Pylint Analyzer Module\\ + +\multirow{3}{0.3\textwidth}{Software Decision Module} & Measurements Module\\ +& PylintAnalyzer Module\\ & Testing Functionality Module\\ -& Measurements Module\\ \bottomrule \end{tabular} @@ -402,9 +399,6 @@ \subsubsection{Long Parameter List Module (\mref{mLPL})} \item[Implemented By:] EcoOptimizer \end{description} - -\subsection{Software Decision Module} - \subsubsection{Long Message Chain Refactorer (\mref{mLMC})} @@ -431,19 +425,9 @@ \subsubsection{Long Lambda Function Refactorer (\mref{mLLF})} \item[Type of Module:] Library: a reusable component that provides functionality for refactoring long lambda functions in Python code. \end{description} +\subsection{Software Decision Module} -\begin{description} -\item[Secrets:] The design decision based on mathematical theorems, physical - facts, or programming considerations. The secrets of this module are - \emph{not} described in the SRS. -\item[Services:] Includes data structure and algorithms used in the system that - do not provide direct interaction with the user. - % Changes in these modules are more likely to be motivated by a desire to - % improve performance than by externally imposed changes. -\item[Implemented By:] -- -\end{description} - -\subsection{Measurements Module} +\subsubsection{Measurements Module (\mref{mMeasure})} \begin{description} \item[Secrets:] How to measure energy consumption and carbon emissions of a given Python program using the CodeCarbon library, including managing temporary directories for storing output, executing the program, and processing the emissions data from a CSV file. @@ -451,9 +435,6 @@ \subsection{Measurements Module} \item[Implemented By:] CodeCarbonEnergyMeter \end{description} -\subsubsection{Etc.} -\subsubsection{Pylint Analyzer Module} - \subsubsection{Pylint Analyzer Module (\mref{mPyA})} \begin{description} diff --git a/docs/Design/SoftDetailedDes/MIS.tex b/docs/Design/SoftDetailedDes/MIS.tex index bd5752b1..3ae2ae82 100644 --- a/docs/Design/SoftDetailedDes/MIS.tex +++ b/docs/Design/SoftDetailedDes/MIS.tex @@ -62,7 +62,7 @@ \section{Revision History} \section{Symbols, Abbreviations and Acronyms} -See SRS Documentation at \wss{give url} +See \href{https://github.com/ssm-lab/capstone--source-code-optimizer/blob/main/docs/SRS/SRS.pdf}{SRS} Documentation. \wss{Also add any additional symbols, abbreviations or acronyms} @@ -84,32 +84,43 @@ \section{Introduction} \section{Notation} -\wss{You should describe your notation. You can use what is below as - a starting point.} - -The structure of the MIS for modules comes from \citet{HoffmanAndStrooper1995}, -with the addition that template modules have been adapted from -\cite{GhezziEtAl2003}. The mathematical notation comes from Chapter 3 of -\citet{HoffmanAndStrooper1995}. For instance, the symbol := is used for a -multiple assignment statement and conditional rules follow the form $(c_1 -\Rightarrow r_1 | c_2 \Rightarrow r_2 | ... | c_n \Rightarrow r_n )$. - The following table summarizes the primitive data types used by \progname. -\begin{center} -\renewcommand{\arraystretch}{1.2} -\noindent -\begin{tabular}{l l p{7.5cm}} -\toprule -\textbf{Data Type} & \textbf{Notation} & \textbf{Description}\\ -\midrule -character & char & a single symbol or digit\\ -integer & $\mathbb{Z}$ & a number without a fractional component in (-$\infty$, $\infty$) \\ -natural number & $\mathbb{N}$ & a number without a fractional component in [1, $\infty$) \\ -real & $\mathbb{R}$ & any number in (-$\infty$, $\infty$)\\ -\bottomrule -\end{tabular} -\end{center} +\begin{table} + \centering + \renewcommand{\arraystretch}{1.2} + \noindent + \begin{tabular}{l l p{7.5cm}} + \toprule + \textbf{Data Type} & \textbf{Notation} & \textbf{Description}\\ + \midrule + optional & ? & denotes a variable as optional\\ + character & char & a single symbol or digit\\ + String & str & a sequence of characters\\ + integer & $\mathbb{Z}$ & a number without a fractional component in (-$\infty$, $\infty$) \\ + natural number & $\mathbb{N}$ & a number without a fractional component in [1, $\infty$) \\ + real & $\mathbb{R}$ & any number in (-$\infty$, $\infty$)\\ + boolean & $\mathbb{B}$ & True or False\\ + code smell & Smell & a collection of data representing a code smell\\ + path & Path & Data object representing a path in a filesystem\\ + list & list[T] & a collection of objects of type T\\ + set & set[T] & a collection of \textit{unique} objects of type T\\ + dictionary & dict & data structure containing multiple key-value pairs\\ + AST Node & AST & AST node representing any AST node\\ + AST Constant & Constant & AST node representing a constant\\ + AST Function Definition & FuncDef & AST node representing a function definition\\ + AST Module & Module & AST node representing a Module\\ + AST Class Definition & ClassDef & ast node representing a class definition\\ + AST Call & Call & ast node representing a function call\\ + AST Lambda & Lambda & ast node representing a lambda function\\ + AST List Comprehension & ListComp & ast node representing a list comprehension\\ + AST Generator Expression & GenExp & ast node representing a generator expression\\ + current instance & self & a reference to the current instance of a module\\ + \bottomrule + \end{tabular} + \label{tab:mis-notation} + \caption{MIS Notation} +\end{table} \noindent The specification of \progname \ uses some derived data types: sequences, strings, and @@ -156,15 +167,134 @@ \section{Module Decomposition} ~\newpage -\section{MIS of LongMessageChainRefactorer} +\section{MIS of Smell Data Type} \label{mis:smell} +\texttt{Smell} \subsection{Module} +Contains data related to a code smell. + +\subsection{Uses} +None + +\subsection{Syntax} +\noindent +\textbf{Exported Constants}: None + +\noindent +\textbf{Exported Access Programs}: None -LongMessageChainRefactorer is a module that identifies and refactors -long message chains in Python code to improve readability, maintainability, -and performance. It specifically handles long chains by breaking them into -separate statements, ensuring proper refactoring while maintaining the -original functionality. +\subsection{Semantics} + +\subsubsection{State Variables} +\begin{itemize} + \item \texttt{absolutePath: str}: Absolute path to the source file containing the smell. + \item \texttt{column: int}: Starting column in the source file where the smell is detected. + \item \texttt{confidence: str}: Confidence level for the smell detection. + \item \texttt{endColumn?: int}: Ending column for the smell location, if applicable. + \item \texttt{endLine?: int}: Ending line number for the smell location, if applicable. + \item \texttt{occurences: dict}: Contains positional data related to where the smell is located in a code file. + \item \texttt{message: str}: Descriptive message explaining the smell. + \item \texttt{messageId: str}: Unique identifier for the specific message or warning. + \item \texttt{module: str}: Module or component name containing the smell. + \item \texttt{obj: str}: Specific object associated with the smell. + \item \texttt{path: str}: Relative path to the source file from the project root. + \item \texttt{symbol: str}: Symbol or code construct involved in the smell. + \item \texttt{type: str}: Type or category of the smell. +\end{itemize} + +\subsubsection{Environment Variables} +None + +\subsubsection{Assumptions} +\begin{itemize} + \item All values provided to the fields of \texttt{Smell} conform to the expected data types and constraints. +\end{itemize} + +\subsubsection{Access Routine Semantics} + +\paragraph{\texttt{Smell()}} +\begin{itemize} + \item \textbf{transition}: Creates a dictionary-like structure with the defined attributes representing a code smell. + \item \textbf{output}: Returns a \texttt{Smell} instance. +\end{itemize} + +\subsubsection{Local Functions} +None. + + +\newpage + +\section{MIS of Base Refactorer} \label{mis:baseR} + +\texttt{BaseRefactorer} + +\subsection{Module} + +The interface that all refactorers of this system will inherit from. + +\subsection{Uses} + +None + +\subsection{Syntax} +\noindent +\textbf{Exported Constants}: None + +\noindent +\textbf{Exported Access Programs}: + +\begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} + \hline + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\\hline + \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\\hline + \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: dict, initial\_emissions: $\mathbb{R}$} & None & None \\ + \hline +\end{tabularx} + +\subsection{Semantics} + +\subsubsection{State Variables} +\begin{itemize} + \item \texttt{temp\_dir: Path}: Directory path for storing refactored files. +\end{itemize} + +\subsubsection{Environment Variables} +None + +\subsubsection{Assumptions} +\begin{itemize} + \item \texttt{output\_dir} exists or can be created, and write permissions are available. +\end{itemize} + +\subsubsection{Access Routine Semantics} + +\paragraph{\texttt{\_\_init\_\_(self, output\_dir: Path)}} +\begin{itemize} + \item \textbf{transition}: Initializes the \texttt{temp\_dir} variable within \texttt{output\_dir}. + \item \textbf{output}: \texttt{self} + \item \textbf{exception:} None. +\end{itemize} + +\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: dict, initial\_emissions: $\mathbb{R}$)}} +\begin{itemize} + \item \textbf{transition}: Abstract method. No transition defined. + \item \textbf{output}: None. + \item \textbf{exception:} None. +\end{itemize} + +\subsubsection{Local Functions} +None. + +\newpage + + +\section{MIS of Long Message Chain Refactorer} \label{mis:LMC} + +\texttt{LongMessageChainRefactorer} + +\subsection{Module} + +LongMessageChainRefactorer is a module that identifies and refactors long message chains in Python code to improve readability, maintainability, and performance. It specifically handles long chains by breaking them into separate statements, ensuring proper refactoring while maintaining the original functionality. \subsection{Uses} @@ -181,17 +311,15 @@ \subsubsection{Exported Constants} \subsubsection{Exported Access Programs} \begin{center} -\begin{tabular}{|p{4cm}|p{5cm}|p{4cm}|p{3cm}|} +\begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|p{1in}|p{1in}|} \hline \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ \hline -\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & LongMessageChainRefactorer & None \\ +\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ \hline -\texttt{remove\_unmatched\_brackets} & \texttt{input\_string: str} & \texttt{str} & None \\ +\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$} & None & \texttt{TypeError}, \texttt{IOError} \\ \hline -\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: float} & None & Logging exceptions \\ -\hline -\end{tabular} +\end{tabularx} \end{center} @@ -224,18 +352,11 @@ \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}: LongMessageChainRefactorer. +\item \textbf{Output}: \texttt{self}. \item \textbf{Exception}: None. \end{itemize} -\paragraph{\texttt{remove\_unmatched\_brackets(input\_string: str)}} -\begin{itemize} -\item \textbf{Transition}: Removes unmatched parentheses from the input string. -\item \textbf{Output}: Returns the string with unmatched parentheses removed. -\item \textbf{Exception}: None. -\end{itemize} - -\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}} +\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$)}} \begin{itemize} \item \textbf{Transition}: \begin{itemize} @@ -246,15 +367,22 @@ \subsubsection{Access Routine Semantics} \item Evaluates the refactored code’s energy efficiency and functionality. \end{itemize} \item \textbf{Output}: None. Refactored file is saved if improvements are validated. - \item \textbf{Exception}: Logs exceptions during file operations or refactoring process. + \item \textbf{Exception}: Raises \texttt{IOError} if input file cannot be read. Raises \texttt{TypeError} if source file cannot be parsed into an AST. \end{itemize} \subsubsection{Local Functions} -None +\paragraph{\texttt{remove\_unmatched\_brackets(input\_string: str)}} +\begin{itemize} +\item \textbf{Transition}: Removes unmatched parentheses from the input string. +\item \textbf{Output}: Returns the string with unmatched parentheses removed. +\item \textbf{Exception}: None. +\end{itemize} ~\newpage -\section{MIS of LongLambdaFunctionRefactorer} +\section{MIS of Long Lambda Function Refactorer} \label{mis:LLF} + +\texttt{LongLambdaFunctionRefactorer} \subsection{Module} LongLambdaFunctionRefactorer is a module that refactors @@ -275,17 +403,15 @@ \subsubsection{Exported Constants} \subsubsection{Exported Access Programs} \begin{center} -\begin{tabular}{|p{4cm}|p{5cm}|p{4cm}|p{3cm}|} +\begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|p{1in}|p{1in}|} \hline \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ \hline -\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & LongLambdaFunctionRefactorer & None \\ -\hline -\texttt{truncate\_at\_top\_level\_comma} & \texttt{body: str} & \texttt{str} & None \\ +\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ \hline -\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: float} & None & Logging exceptions \\ +\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$} & None & \texttt{TypeError}, \texttt{IOError} \\ \hline -\end{tabular} +\end{tabularx} \end{center} \subsection{Semantics} @@ -317,18 +443,11 @@ \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}: LongLambdaFunctionRefactorer. -\item \textbf{Exception}: None. -\end{itemize} - -\paragraph{\texttt{truncate\_at\_top\_level\_comma(body: str)}} -\begin{itemize} -\item \textbf{Transition}: Truncates the lambda body at the first top-level comma, ignoring commas within nested parentheses, brackets, or braces. -\item \textbf{Output}: Returns the truncated lambda body as a string. +\item \textbf{Output}: \texttt{self}. \item \textbf{Exception}: None. \end{itemize} -\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}} +\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$)}} \begin{itemize} \item \textbf{Transition}: \begin{itemize} @@ -338,25 +457,22 @@ \subsubsection{Access Routine Semantics} \item Writes the refactored code to a temporary file. \end{itemize} \item \textbf{Output}: None. Refactored file is saved if improvements are validated. - \item \textbf{Exception}: Logs exceptions during file operations or the refactoring process. + \item \textbf{Exception}: Raises \texttt{IOError} if input file cannot be read. Raises \texttt{TypeError} if source file cannot be parsed into an AST. \end{itemize} \subsubsection{Local Functions} -None +\paragraph{\texttt{truncate\_at\_top\_level\_comma(body: str)}} +\begin{itemize} +\item \textbf{Transition}: Truncates the lambda body at the first top-level comma, ignoring commas within nested parentheses, brackets, or braces. +\item \textbf{Output}: Returns the truncated lambda body as a string. +\item \textbf{Exception}: None. +\end{itemize} ~\newpage +\section{MIS of Long Parameter List Refactorer} \label{Module} - - - - -\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.} +\texttt{LongParameterListRefactorer} \subsection{Module} @@ -379,15 +495,15 @@ \subsubsection{Exported Constants} \subsubsection{Exported Access Programs} \begin{center} -\begin{tabular}{|p{3cm}|p{5cm}|p{2cm}|p{3cm}|} +\begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} \hline \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ \hline -\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\ +\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ \hline -\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: float} & None & Logging exceptions \\ +\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$} & None & \texttt{TypeError}, \texttt{IOError} \\ \hline -\end{tabular} +\end{tabularx} \end{center} \subsection{Semantics} @@ -413,14 +529,14 @@ \subsubsection{Assumptions} \subsubsection{Access Routine Semantics} -\paragraph{\texttt{init(output\_dir: Path)}} +\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{Output}: \texttt{self}. \item \textbf{Exception}: None. \end{itemize} -\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}} +\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$)}} \begin{itemize} \item \textbf{Transition}: \begin{enumerate} @@ -430,215 +546,21 @@ \subsubsection{Access Routine Semantics} \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. +\item \textbf{Exception}: Raises \texttt{IOError} if input file cannot be read. Raises \texttt{TypeError} if source file cannot be parsed into an AST. \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{get\_used\_parameters(function\_node: FuncDef, params: list[str]) -> set[str]}: Identifies parameters used within the function body. +\item \texttt{get\_parameters\_with\_default\_value(default\_values: list[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. +\item \texttt{update\_function\_signature(function\_node: FuncDef, params: dict) -> FuncDef}: Updates function signatures to use encapsulated parameter objects. +\item \texttt{update\_parameter\_usages(function\_node: FuncDef, params: dict) -> FuncDef}: Replaces parameter usages within the function body with attributes of encapsulated objects. +\item \texttt{update\_function\_calls(tree: Module, function\_node: FuncDef, params: dict) -> Module}: Updates all calls to the refactored function. \end{enumerate} -\section{MIS of \wss{Module Name}} \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} - -\wss{Short name for the module} - -\subsection{Uses} - - -\subsection{Syntax} - -\subsubsection{Exported Constants} - -\subsubsection{Exported Access Programs} - -\begin{center} -\begin{tabular}{p{2cm} p{4cm} p{4cm} p{2cm}} -\hline -\textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ -\hline -\wss{accessProg} & - & - & - \\ -\hline -\end{tabular} -\end{center} - -\subsection{Semantics} - -\subsubsection{State Variables} - -\wss{Not all modules will have state variables. State variables give the module - a memory.} - -\subsubsection{Environment Variables} - -\wss{This section is not necessary for all modules. Its purpose is to capture - when the module has external interaction with the environment, such as for a - device driver, screen interface, keyboard, file, etc.} - -\subsubsection{Assumptions} - -\wss{Try to minimize assumptions and anticipate programmer errors via - exceptions, but for practical purposes assumptions are sometimes appropriate.} - -\subsubsection{Access Routine Semantics} - -\noindent \wss{accessProg}(): -\begin{itemize} -\item transition: \wss{if appropriate} -\item output: \wss{if appropriate} -\item exception: \wss{if appropriate} -\end{itemize} - -\wss{A module without environment variables or state variables is unlikely to - have a state transition. In this case a state transition can only occur if - the module is changing the state of another module.} - -\wss{Modules rarely have both a transition and an output. In most cases you - will have one or the other.} - -\subsubsection{Local Functions} - -\wss{As appropriate} \wss{These functions are for the purpose of specification. - They are not necessarily something that is going to be implemented - explicitly. Even if they are implemented, they are not exported; they only - have local scope.} - -\newpage - -\section{MIS of Base Refactorer} \label{mis:baseR} - -\texttt{BaseRefactorer} - -\subsection{Module} - -The interface that all refactorers of this system will inherit from. - -\subsection{Uses} - -None - -\subsection{Syntax} -\noindent -\textbf{Exported Constants}: None - -\noindent -\textbf{Exported Access Programs}: - -\begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} - \toprule Name & In & Out & Exceptions \\\hline - \midrule - \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\\hline - \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: dict, initial\_emissions: float} & None & None \\ - \hline - \bottomrule -\end{tabularx} - -\subsection{Semantics} - -\subsubsection{State Variables} -\begin{itemize} - \item \texttt{temp\_dir: Path}: Directory path for storing refactored files. -\end{itemize} - -\subsubsection{Environment Variables} -None - -\subsubsection{Assumptions} -\begin{itemize} - \item \texttt{output\_dir} exists or can be created, and write permissions are available. -\end{itemize} - -\subsubsection{Access Routine Semantics} - -\paragraph{\texttt{\_\_init\_\_(self, output\_dir: Path)}} -\begin{itemize} - \item \textbf{transition}: Initializes the \texttt{temp\_dir} variable within \texttt{output\_dir}. - \item \textbf{output}: None. - \item \textbf{exception:} None. -\end{itemize} - -\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: dict, initial\_emissions: float)}} -\begin{itemize} - \item \textbf{transition}: Abstract method. No transition defined. - \item \textbf{output}: None. - \item \textbf{exception:} None. -\end{itemize} - -\subsubsection{Local Functions} -None. - -\newpage - -\section{MIS of Smell Data Type} \label{mis:smell} -\texttt{Smell} - -\subsection{Module} -Contains data related to a code smell. - -\subsection{Uses} -None - -\subsection{Syntax} -\noindent -\textbf{Exported Constants}: None - -\noindent -\textbf{Exported Access Programs}: None - -\subsection{Semantics} - -\subsubsection{State Variables} -\begin{itemize} - \item \texttt{absolutePath: str}: Absolute path to the source file containing the smell. - \item \texttt{column: int}: Starting column in the source file where the smell is detected. - \item \texttt{confidence: str}: Confidence level for the smell detection. - \item \texttt{endColumn: int | None}: Ending column for the smell location, if applicable. - \item \texttt{endLine: int | None}: Ending line number for the smell location, if applicable. - \item \texttt{occurences: dict}: Contains positional data related to where the smell is located in a code file. - \item \texttt{message: str}: Descriptive message explaining the smell. - \item \texttt{messageId: str}: Unique identifier for the specific message or warning. - \item \texttt{module: str}: Module or component name containing the smell. - \item \texttt{obj: str}: Specific object associated with the smell. - \item \texttt{path: str}: Relative path to the source file from the project root. - \item \texttt{symbol: str}: Symbol or code construct involved in the smell. - \item \texttt{type: str}: Type or category of the smell. -\end{itemize} - -\subsubsection{Environment Variables} -None - -\subsubsection{Assumptions} -\begin{itemize} - \item All values provided to the fields of \texttt{Smell} conform to the expected data types and constraints. -\end{itemize} - -\subsubsection{Access Routine Semantics} - -\paragraph{\texttt{Smell()}} -\begin{itemize} - \item \textbf{transition}: Creates a dictionary-like structure with the defined attributes representing a code smell. - \item \textbf{output}: Returns a \texttt{Smell} instance. -\end{itemize} - -\subsubsection{Local Functions} -None. - - -\newpage - \section{MIS of Use List Accumulation Refactorer} \label{mis:ListAccum} \texttt{UseListAccumulationRefactorer} @@ -667,20 +589,13 @@ \subsection{Syntax} >{\raggedright\arraybackslash}X| l| l|} - \toprule Name & In & Out & Exceptions \\ - \midrule - \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\ - \hline - \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: Real} & None & \texttt{TypeError}, \texttt{IOError} \\ \hline - \texttt{visit} & \texttt{node: nodes.NodeNG} & None & None \\ + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ \hline - \texttt{find\_last\_assignment} & \texttt{scope: nodes.NodeNG} & None & \texttt{TypeError} \\ + \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ \hline - \texttt{find\_scope} & None & None & \texttt{TypeError} \\ + \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: Real} & None & \texttt{TypeError}, \texttt{IOError} \\ \hline - \texttt{add\_node\_to\_body} & \texttt{code\_file: str} & \texttt{str} & \texttt{TypeError} \\ - \bottomrule \end{tabularx} \subsection{Semantics} @@ -710,25 +625,26 @@ \subsubsection{Access Routine Semantics} \paragraph{\texttt{\_\_init\_\_(self, output\_dir: Path)}} \begin{itemize} \item \textbf{transition}: Initializes the refactorer with \texttt{output\_dir} and sets default state variables. - \item \textbf{output}: None. + \item \textbf{output}: \texttt{self}. \item \textbf{exception}: None \end{itemize} -\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}} +\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$)}} \begin{itemize} \item \textbf{transition}: Parses \texttt{file\_path}, identifies string concatenations in loops, modifies code for list accumulation, and writes refactored code to a file. \item \textbf{output}: None. \item \textbf{exception}: Raises \texttt{IOError} if input file cannot be read. Raises \texttt{TypeError} if source file cannot be parsed into an AST. \end{itemize} -\paragraph{\texttt{find\_last\_assignment(self, scope: nodes.NodeNG)}} +\subsubsection{Local Functions} +\paragraph{\texttt{find\_last\_assignment(self, scope: ASTnode)}} \begin{itemize} \item \textbf{transition}: Identifies the last assignment of \texttt{assign\_var} within the given \texttt{scope}. \item \textbf{output}: None. \item \textbf{exception}: Raises \texttt{TypeError} if given scope is null. \end{itemize} -\paragraph{\texttt{find\_scope(self)}} +\paragraph{\texttt{find\_scope()}} \begin{itemize} \item \textbf{transition}: Finds the scope for refactoring based on AST node ancestry. \item \textbf{output}: None. @@ -741,9 +657,6 @@ \subsubsection{Access Routine Semantics} \item \textbf{output}: Returns the modified source code as a string. \item \textbf{exception}: Raises \texttt{TypeError} if \texttt{target\_node} or \texttt{outer\_loop} is not set. \end{itemize} - -\subsubsection{Local Functions} -Functions for internal AST parsing, node manipulation, and validation are defined within the class but are not exported. \newpage @@ -771,18 +684,13 @@ \subsection{Syntax} \textbf{Exported Access Programs}: \begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} - \toprule Name & In & Out & Exceptions \\ - \midrule - \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\ \hline - \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$} & None & \texttt{TypeError}, \texttt{IOError} \\ + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ \hline - \texttt{visit\_FunctionDef} & \texttt{node: FunctionDef} & \texttt{FunctionDef} & None \\ + \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ \hline - \texttt{visit\_ClassDef} & \texttt{node: ClassDef} & \texttt{ClassDef} & None \\ + \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$} & None & \texttt{TypeError}, \texttt{IOError} \\ \hline - \texttt{visit\_Call} & \texttt{node: Call} & \texttt{Call} & None \\ - \bottomrule \end{tabularx} \subsection{Semantics} @@ -808,44 +716,44 @@ \subsubsection{Access Routine Semantics} \paragraph{\texttt{\_\_init\_\_(self, output\_dir: Path)}} \begin{itemize} \item \textbf{transition}: Initializes the refactorer with \texttt{output\_dir} and sets default state variables. - \item \textbf{output}: None. + \item \textbf{output}: \texttt{self}. \item \textbf{exception}: None. \end{itemize} -\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}} +\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$)}} \begin{itemize} \item \textbf{transition}: Parses \texttt{file\_path}, identifies the target function, modifies it to be static, and validates refactoring. \item \textbf{output}: None. \item \textbf{exception}: Raises \texttt{IOError} if input file cannot be read. Raises \texttt{TypeError} if source file cannot be parsed into an AST. \end{itemize} -\paragraph{\texttt{visit\_FunctionDef(self, node: ast.FunctionDef)}} +\subsubsection{Local Functions} +\paragraph{\texttt{visit\_FunctionDef(self, node: FuncDef)}} \begin{itemize} \item \textbf{transition}: Adds the \texttt{staticmethod} decorator to the target method and removes the \texttt{self} parameter if present. \item \textbf{output}: Returns the modified \texttt{FunctionDef} node. \item \textbf{exception}: None \end{itemize} -\paragraph{\texttt{visit\_ClassDef(self, node: ast.ClassDef)}} +\paragraph{\texttt{visit\_ClassDef(self, node: ClassDef)}} \begin{itemize} \item \textbf{transition}: Identifies the class containing the target method. \item \textbf{output}: Returns the modified \texttt{ClassDef} node. \item \textbf{exception}: None. \end{itemize} -\paragraph{\texttt{visit\_Call(self, node: ast.Call)}} +\paragraph{\texttt{visit\_Call(self, node: Call)}} \begin{itemize} \item \textbf{transition}: Updates method call references to use the class name instead of \texttt{self}. \item \textbf{output}: Returns the modified \texttt{Call} node. \item \textbf{exception}: None. \end{itemize} - -\subsubsection{Local Functions} -Functions for internal AST parsing, node transformation, and validation are defined within the class but are not exported. \newpage -\section{MIS of LongElementChainRefactorer} +\section{MIS of Long Element Chain Refactorer} \label{mis:lec} + +\texttt{LongElementChainRefactorer} \subsection{Module} @@ -866,15 +774,15 @@ \subsubsection{Exported Constants} \subsubsection{Exported Access Programs} \begin{center} -\begin{tabular}{|p{3cm}|p{5cm}|p{2cm}|p{3cm}|} +\begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} \hline \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ \hline -\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\ +\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ \hline -\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: float} & None & Logging exceptions \\ +\texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$} & None & \texttt{TypeError}, \texttt{IOError} \\ \hline -\end{tabular} +\end{tabularx} \end{center} \subsection{Semantics} @@ -905,11 +813,11 @@ \subsubsection{Access Routine Semantics} \paragraph{\texttt{\_\_init\_\_(output\_dir: Path)}} \begin{itemize} \item \textbf{Transition}: Initializes the refactorer with the specified output directory and sets up internal caching structures. -\item \textbf{Output}: None. +\item \textbf{Output}: \texttt{self}. \item \textbf{Exception}: None. \end{itemize} -\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}} +\paragraph{\texttt{refactor(file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$)}} \begin{itemize} \item \textbf{Transition}: \begin{itemize} @@ -919,21 +827,21 @@ \subsubsection{Access Routine Semantics} \item Writes the refactored code to a temporary file. \end{itemize} \item \textbf{Output}: None. Refactored file is saved if improvements are validated. - \item \textbf{Exception}: Logs exceptions during file operations or refactoring. + \item \textbf{Exception}: Raises \texttt{IOError} if input file cannot be read. Raises \texttt{TypeError} if source file cannot be parsed into an AST. \end{itemize} \subsubsection{Local Functions} \begin{itemize} - \item \textbf{\_flatten\_dict(d: dict[str, Any], parent\_key: str = "")} \\ + \item \textbf{\_flatten\_dict(d: dict[str, Any], parent\_key?: str)} \\ Recursively flattens a nested dictionary by combining keys with underscores. - \item \textbf{\_extract\_dict\_literal(node: ast.AST)} \\ + \item \textbf{\_extract\_dict\_literal(node: ASTnode)} \\ Converts an Abstract Syntax Tree (AST) dictionary literal into a Python dictionary. - \item \textbf{\_find\_dict\_assignments(tree: ast.AST, name: str)} \\ + \item \textbf{\_find\_dict\_assignments(tree: ASTnode, name: str)} \\ Extracts dictionary assignments given the name of the dictionary from the AST and returns them as a dictionary. - \item \textbf{\_collect\_dict\_references(tree: ast.AST)} \\ + \item \textbf{\_collect\_dict\_references(tree: ASTnode)} \\ Identifies and stores all dictionary access patterns in the `\_reference\_map`. \item \textbf{\_generate\_flattened\_access(base\_var: str, access\_chain: list[str])} \\ @@ -942,7 +850,9 @@ \subsubsection{Local Functions} -\section{MIS of Measurements Module} +\section{MIS of Measurements Module} \label{mis:measure} + +\texttt{Measurements} \subsection{Module} @@ -964,15 +874,15 @@ \subsubsection{Exported Constants} \subsubsection{Exported Access Programs} \begin{center} -\begin{tabular}{|p{3cm}|p{5cm}|p{2cm}|p{3cm}|} +\begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} \hline \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ \hline -\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\ +\texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ \hline \texttt{measure\_energy} & \texttt{None} & None & CalledProcessError and FileReading exceptions \\ \hline -\end{tabular} +\end{tabularx} \end{center} \subsection{Semantics} @@ -1006,7 +916,7 @@ \subsubsection{Access Routine Semantics} \paragraph{\texttt{\_\_init\_\_(file\_path: Path)}} \begin{itemize} \item \textbf{Transition}: Initializes the \texttt{CodeCarbonEnergyMeter} with the specified file path and logger. It sets up the necessary internal state for energy measurement and prepares the environment. - \item \textbf{Output}: None. + \item \textbf{Output}: \texttt{self}. \item \textbf{Exception}: None. \end{itemize} @@ -1075,9 +985,9 @@ \subsection{Syntax} >{\raggedright\arraybackslash}X| l| l|} - \toprule Name & In & Out & Exceptions \\ - \midrule - \texttt{\_\_init\_\_} & \texttt{file\_path: Path, source\_code: ast.Module} & None & None \\ + \hline + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\\hline + \texttt{\_\_init\_\_} & \texttt{file\_path: Path, source\_code: Module} & \texttt{self} & None \\ \hline \texttt{build\_pylint\_options} & None & \texttt{list[str]} & None \\ \hline @@ -1087,14 +997,6 @@ \subsection{Syntax} \hline \texttt{filter\_for\_one\_code\_smell} & \texttt{pylint\_results: list[Smell], code: str} & \texttt{list[Smell]} & None \\ \hline - \texttt{detect\_long\_message\_chain} & \texttt{threshold: int = 3} & \texttt{list[Smell]} & None \\ - \hline - \texttt{detect\_long\_lambda\_expression} & \texttt{threshold\_length: int = 100, threshold\_count: int = 3} & \texttt{list[Smell]} & None \\ - \hline - \texttt{detect\_long\_element\_chain} & \texttt{threshold: int = 3} & \texttt{list[Smell]} & None \\ - \hline - \texttt{detect\_repeated\_calls} & \texttt{threshold: int = 2} & \texttt{list[Smell]} & None \\ - \bottomrule \end{tabularx} } @@ -1103,7 +1005,7 @@ \subsection{Semantics} \subsubsection{State Variables} \begin{itemize} \item \texttt{file\_path: Path}: The path to the Python file being analyzed. - \item \texttt{source\_code: ast.Module}: The parsed abstract syntax tree of the source file. + \item \texttt{source\_code: Module}: The parsed abstract syntax tree of the source file. \item \texttt{smells\_data: list[dict]}: A list of detected code smells, represented as dictionaries. \end{itemize} @@ -1118,28 +1020,28 @@ \subsubsection{Assumptions} \subsubsection{Access Routine Semantics} -\paragraph{\texttt{\_\_init\_\_(self, file\_path: Path, source\_code: ast.Module)}} +\paragraph{\texttt{\_\_init\_\_(self, file\_path: Path, source\_code: Module)}} \begin{itemize} \item \textbf{transition}: Initializes the analyzer with the provided file path and AST of the source code. - \item \textbf{output}: None. + \item \textbf{output}: \texttt{self}. \item \textbf{exception:} None. \end{itemize} -\paragraph{\texttt{build\_pylint\_options(self)}} +\paragraph{\texttt{build\_pylint\_options()}} \begin{itemize} \item \textbf{transition}: Constructs the list of Pylint options based on the file path and configuration settings. \item \textbf{output}: Returns a list of strings representing Pylint options. \item \textbf{exception:} None. \end{itemize} -\paragraph{\texttt{analyze(self)}} +\paragraph{\texttt{analyze()}} \begin{itemize} \item \textbf{transition}: Executes Pylint analysis and custom checks, populating \texttt{smells\_data} with detected smells. \item \textbf{output}: None. \item \textbf{exception:} Raises \texttt{JSONDecodeError} if Pylint's output cannot be parsed. Raises \texttt{Exception} for other runtime errors. \end{itemize} -\paragraph{\texttt{configure\_smells(self)}} +\paragraph{\texttt{configure\_smells()}} \begin{itemize} \item \textbf{transition}: Filters \texttt{smells\_data} to include only configured smells. \item \textbf{output}: None. @@ -1153,44 +1055,43 @@ \subsubsection{Access Routine Semantics} \item \textbf{exception:} None. \end{itemize} -\paragraph{\texttt{detect\_long\_message\_chain(self, threshold: int = 3)}} +\subsubsection{Local Functions} +\paragraph{\texttt{detect\_long\_message\_chain(self, threshold?: int)}} \begin{itemize} \item \textbf{transition}: Identifies method chains exceeding the specified \texttt{threshold}. \item \textbf{output}: Returns a list of smells for long method chains. \item \textbf{exception:} None. \end{itemize} -\paragraph{\texttt{detect\_long\_lambda\_expression(self, threshold\_length: int = 100, threshold\_count: int = 3)}} +\paragraph{\texttt{detect\_long\_lambda\_expression(self, threshold\_length?: int, threshold\_count?: int)}} \begin{itemize} \item \textbf{transition}: Detects lambda expressions exceeding length or expression count thresholds. \item \textbf{output}: Returns a list of smells for long lambda expressions. \item \textbf{exception:} None. \end{itemize} -\paragraph{\texttt{detect\_long\_element\_chain(self, threshold: int = 3)}} +\paragraph{\texttt{detect\_long\_element\_chain(self, threshold?: int)}} \begin{itemize} \item \textbf{transition}: Detects dictionary access chains exceeding the specified \texttt{threshold}. \item \textbf{output}: Returns a list of smells for long dictionary chains. \item \textbf{exception:} None. \end{itemize} -\paragraph{\texttt{detect\_repeated\_calls(self, threshold: int = 2)}} +\paragraph{\texttt{detect\_repeated\_calls(self, threshold?: int)}} \begin{itemize} \item \textbf{transition}: Identifies repeated function calls exceeding the \texttt{threshold}. \item \textbf{output}: Returns a list of smells for repeated function calls. \item \textbf{exception:} None. \end{itemize} - -\subsubsection{Local Functions} \begin{itemize} \item \texttt{parse\_line(file\_path: Path, line: int)}: Parses a specific line of code into an AST node. - \item \texttt{get\_lambda\_code(lambda\_node: ast.Lambda)}: Returns the string representation of a lambda expression. + \item \texttt{get\_lambda\_code(lambda\_node: Lambda)}: Returns the string representation of a lambda expression. \end{itemize} \newpage -\section{MIS of Testing Functionality} +\section{MIS of Testing Functionality} \label{mis:test} \texttt{TestRunner} @@ -1212,11 +1113,11 @@ \subsection{Syntax} \begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} \hline -Name & In & Out & Exceptions \\ +\textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ \hline -\texttt{\_\_init\_\_} & \texttt{run\_command: str, project\_path: Path} & None & None \\ +\texttt{\_\_init\_\_} & \texttt{run\_command: str, project\_path: Path} & \texttt{self} & None \\ \hline -\texttt{retained\_functionality} & None & \texttt{bool} & \texttt{CalledProcessError} \\ +\texttt{retained\_functionality} & None & $\mathbb{B}$ & \texttt{CalledProcessError} \\ \hline \end{tabularx} @@ -1242,11 +1143,11 @@ \subsubsection{Access Routine Semantics} \paragraph{\texttt{\_\_init\_\_(self, run\_command: str, project\_path: Path)}} \begin{itemize} \item \textbf{transition}: Initializes the test runner with the given \texttt{run\_command} and \texttt{project\_path}. - \item \textbf{output}: None. + \item \textbf{output}: \texttt{self}. \item \textbf{exception}: None. \end{itemize} -\paragraph{\texttt{retained\_functionality(self)}} +\paragraph{\texttt{retained\_functionality()}} \begin{itemize} \item \textbf{transition}: Runs the specified test command in the given project path. Logs success or failure, including standard output and error streams. \item \textbf{output}: Returns \texttt{True} if the tests passed; otherwise, returns \texttt{False}. @@ -1285,14 +1186,12 @@ \subsection{Syntax} >{\raggedright\arraybackslash}X| l| l|} - \toprule Name & In & Out & Exceptions \\ - \midrule - \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\ \hline - \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: float} & None & \texttt{IOError}, \texttt{TypeError} \\ + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\\hline + \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ + \hline + \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$} & None & \texttt{IOError}, \texttt{TypeError} \\ \hline - \texttt{\_replace\_node} & \texttt{tree: ast.Module, old\_node: ast.ListComp, new\_node: ast.GeneratorExp} & None & None \\ - \bottomrule \end{tabularx} \subsection{Semantics} @@ -1317,27 +1216,25 @@ \subsubsection{Access Routine Semantics} \paragraph{\texttt{\_\_init\_\_(self, output\_dir: Path)}} \begin{itemize} \item \textbf{transition}: Initializes the \texttt{temp\_dir} variable within \texttt{output\_dir}. - \item \textbf{output}: None. + \item \textbf{output}: \texttt{self}. \item \textbf{exception:} None. \end{itemize} -\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}} +\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$)}} \begin{itemize} \item \textbf{transition}: Parses \texttt{file\_path}, identifies unnecessary list comprehensions, modifies the code to use generator expressions, and validates refactoring. \item \textbf{output}: None. \item \textbf{exception}: Raises \texttt{IOError} if input file cannot be read. Raises \texttt{TypeError} if source file cannot be parsed into an AST. \end{itemize} -\paragraph{\texttt{\_replace\_node(self, tree: ast.Module, old\_node: ast.ListComp, new\_node: ast.GeneratorExp)}} +\subsubsection{Local Functions} +\paragraph{\texttt{\_replace\_node(self, tree: Module, old\_node: ListComp, new\_node: GeneratorExp)}} \begin{itemize} \item \textbf{transition}: Replaces an \texttt{old\_node} in the AST with a \texttt{new\_node}. \item \textbf{output}: None. \item \textbf{exception}: None. \end{itemize} -\subsubsection{Local Functions} -Functions for internal AST parsing, node manipulation, and validation are defined within the class but are not exported. - \newpage \section{MIS of Cache Repeated Calls Refactorer} \label{mis:CacheCalls} @@ -1362,12 +1259,12 @@ \subsection{Syntax} \noindent \textbf{Exported Access Programs}:\\ \begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} - \toprule Name & In & Out & Exceptions \\ - \midrule - \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & None & None \\ \hline - \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: float} & None & \texttt{IOError}, \texttt{TypeError} \\ - \bottomrule + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\\hline + \texttt{\_\_init\_\_} & \texttt{output\_dir: Path} & \texttt{self} & None \\ + \hline + \texttt{refactor} & \texttt{file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$} & None & \texttt{IOError}, \texttt{TypeError} \\ + \hline \end{tabularx} \subsection{Semantics} @@ -1392,11 +1289,11 @@ \subsubsection{Access Routine Semantics} \paragraph{\texttt{\_\_init\_\_(self, output\_dir: Path)}} \begin{itemize} \item \textbf{transition}: Initializes the \texttt{temp\_dir} variable within \texttt{output\_dir}. - \item \textbf{output}: None. + \item \textbf{output}: \texttt{self}. \item \textbf{exception:} None. \end{itemize} -\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: Smell, initial\_emissions: float)}} +\paragraph{\texttt{refactor(self, file\_path: Path, pylint\_smell: Smell, initial\_emissions: $\mathbb{R}$)}} \begin{itemize} \item \textbf{transition}: Parses \texttt{file\_path}, identifies repeated function calls, inserts a cached variable for the first call, updates subsequent calls to use the cached variable, and validates refactoring. \item \textbf{output}: None. @@ -1411,18 +1308,14 @@ \subsubsection{Local Functions} \item \texttt{\_find\_insert\_line(parent\_node)}: Determines the line to insert the cached variable. \end{itemize} +\newpage + \bibliographystyle {plainnat} \bibliography {../../../refs/References} \newpage -\section{Appendix} \label{Appendix} - -\wss{Extra information if required} - -\newpage{} - -\section*{Appendix --- Reflection} +\section{Appendix --- Reflection} \wss{Not required for CAS 741 projects} From 20b0aa97fbf937771dcd8b29aff560fd86af6c91 Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:00:52 -0500 Subject: [PATCH 2/5] Added Traceability between reqs and modules --- docs/Design/SoftArchitecture/MG.tex | 173 ++++++++++++++++++++++++---- 1 file changed, 153 insertions(+), 20 deletions(-) diff --git a/docs/Design/SoftArchitecture/MG.tex b/docs/Design/SoftArchitecture/MG.tex index f7655198..bbabe80e 100644 --- a/docs/Design/SoftArchitecture/MG.tex +++ b/docs/Design/SoftArchitecture/MG.tex @@ -467,26 +467,159 @@ \section{Traceability Matrix} \label{SecTM} % the table should use mref, the requirements should be named, use something % like fref \begin{table}[H] -\centering -\begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} -\toprule -\textbf{Req.} & \textbf{Modules}\\ -\midrule -R1 & \mref{mHH}, \mref{mInput}, \mref{mParams}, \mref{mControl}\\ -R2 & \mref{mInput}, \mref{mParams}\\ -R3 & \mref{mVerify}\\ -R4 & \mref{mOutput}, \mref{mControl}\\ -R5 & \mref{mOutput}, \mref{mODEs}, \mref{mControl}, \mref{mSeqDS}, \mref{mSolver}, \mref{mPlot}\\ -R6 & \mref{mOutput}, \mref{mODEs}, \mref{mControl}, \mref{mSeqDS}, \mref{mSolver}, \mref{mPlot}\\ -R7 & \mref{mOutput}, \mref{mEnergy}, \mref{mControl}, \mref{mSeqDS}, \mref{mPlot}\\ -R8 & \mref{mOutput}, \mref{mEnergy}, \mref{mControl}, \mref{mSeqDS}, \mref{mPlot}\\ -R9 & \mref{mVerifyOut}\\ -R10 & \mref{mOutput}, \mref{mODEs}, \mref{mControl}\\ -R11 & \mref{mOutput}, \mref{mODEs}, \mref{mEnergy}, \mref{mControl}\\ -\bottomrule -\end{tabular} -\caption{Trace Between Requirements and Modules} -\label{TblRT} + \centering + \begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} + \toprule + \textbf{Req.} & \textbf{Modules}\\ + \midrule + FR1 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + FR2 & \mref{mSmell}, \mref{mPyA}\\ + FR3 & \mref{mTest}\\ + FR4 & \mref{mTest}\\ + FR5 & \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}\\ + FR6 & \mref{mTest}\\ + FR7 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA},\\ + FR8 & \mref{mSmell}, \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + FR9 & To be removed\\ + FR10 & Not implemented in code\\ + FR11 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + FR12 & To be removed\\ + FR13 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}\\ + \bottomrule + \end{tabular} + \caption{Trace Between Functional Requirements and Modules} + \label{tab:fr-mod} +\end{table} + +\begin{table}[H] + \centering + \begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} + \toprule \textbf{Req.} & \textbf{Modules}\\ + \midrule + % Look and Feel + LFR-AP 1-4 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + LFR-AP 5 & To be removed\\ + LFR-ST 1-3 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + \bottomrule + \end{tabular} + \caption{Trace Between Look \& Feel Requirements and Modules} + \label{tab:LFR-mod} +\end{table} + +\begin{table}[H] + \centering + \begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} + \toprule \textbf{Req.} & \textbf{Modules}\\ + \midrule + % Usability and Humanity + UHR-PS1 1 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + UHR-PS1 2 & Not implemented in code\\ + UHR-LRN 1 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + UHR-LRN 2 & Not implemented in code\\ + UHR-ACS 1-2 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + UHR-EOU 1-2 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + UHR-UPL 1 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + \bottomrule + \end{tabular} + \caption{Trace Between Usability \& Humanity Requirements and Modules} + \label{tab:UHR-mod} +\end{table} + +\begin{table}[H] + \centering + \begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} + \toprule \textbf{Req.} & \textbf{Modules}\\ + \midrule + % Performance + PR-SL 1 & \mref{mPyA}\\ + PR-SL 2 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}\\ + PR-CR 1 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + PR-SCR 1 \mref{mTest}& \\ + PR-PAR 1 & \mref{mTest}\\ + PR-PAR 2 & \mref{mPyA}\\ + PR-PAR 3 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}\\ + PR-RFT 1 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + PR-RFT 2 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}\\ + PR-SER 1 & \mref{mBR}\\ + PR-LR 1 & \mref{mSmell}, \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + \bottomrule + \end{tabular} + \caption{Trace Between Performance Requirements and Modules} + \label{tab:PR-mod} +\end{table} + +\begin{table}[H] + \centering + \begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} + \toprule \textbf{Req.} & \textbf{Modules}\\ + \midrule + % Operational and Environmental + OER-EP 1 & N/A\\ + OER-EP 2 & N/A\\ + OER-WE 1 & \mref{mMeasure}\\ + OER-IAS 1 & To be removed\\ + OER-IAS 2 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + OER-IAS 3 & To be removed\\ + OER-PR 1 & \mref{mSmell}, \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + OER-RL 1 & \mref{mSmell}, \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + OER-RL 2 & N/A\\ + \bottomrule + \end{tabular} + \caption{Trace Between Operational \& Environmental Requirements and Modules} + \label{tab:OPE-mod} +\end{table} + +\begin{table}[H] + \centering + \begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} + \toprule \textbf{Req.} & \textbf{Modules}\\ + \midrule + % Maintenance and Support + MS-MNT 1 \mref{mBR}\\ + MS-MNT 2 & Not implemented in code\\ + MS-MNT 3 & None \\ + MS-MNT 4 & N/A\\ + MS-MNT 5 & \mref{mSmell}, \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + MS-SP 1 & Not implemented in code\\ + \bottomrule + \end{tabular} + \caption{Trace Between Maintenance \& Support Requirements and Modules} + \label{tab:MS-mod} +\end{table} + +\begin{table}[H] + \centering + \begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} + \toprule \textbf{Req.} & \textbf{Modules}\\ + \midrule + % Security + SR-AR 1 & To be removed\\ + SR-AR 2 & \mref{mMeasure}\\ + SR-IR 1 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}\\ + SR-PR 1 & N/A\\ + SR-PR 2 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + SR-AUR 1 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + SR-AUR 2 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + SR-IM 1 & N/A\\ + \bottomrule + \end{tabular} + \caption{Trace Between Security Requirements and Modules} + \label{tab:SR-mod} +\end{table} + +\begin{table}[H] + \centering + \begin{tabular}{p{0.2\textwidth} p{0.6\textwidth}} + \toprule \textbf{Req.} & \textbf{Modules}\\ + \midrule + % Cultural + CULT 1-3 & \mref{mExe}, \mref{mBac}, \mref{mDet}, \mref{mRef}, \mref{mHig}, \mref{mHov}, \mref{mMan}\\ + CL-LR 1 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + CL-SCR 1 & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLLF}, \mref{mLPL}, \mref{mLMC}, \mref{mMeasure}, \mref{mPyA}, \mref{mTest}\\ + \bottomrule + \end{tabular} + \caption{Trace Between Cultural and Compliance Requirements and Modules} + \label{tab:CUL-COMP-mod} \end{table} \begin{table}[H] From 0d7db7e0ad64c36116cd13906c0805d8975a0afb Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:53:00 -0500 Subject: [PATCH 3/5] Formatting changes --- docs/Design/SoftArchitecture/MG.tex | 58 +++++++-------- docs/Design/SoftDetailedDes/MIS.tex | 111 ++++++++++++++++------------ 2 files changed, 90 insertions(+), 79 deletions(-) diff --git a/docs/Design/SoftArchitecture/MG.tex b/docs/Design/SoftArchitecture/MG.tex index eb557942..bef64bd4 100644 --- a/docs/Design/SoftArchitecture/MG.tex +++ b/docs/Design/SoftArchitecture/MG.tex @@ -252,11 +252,11 @@ \section{Module Hierarchy} \label{SecMH} \item [\refstepcounter{mnum} \mthemnum \label{mBac}:] Backend Communicator Module \item [\refstepcounter{mnum} \mthemnum \label{mDet}:] Smell Detector Module \item [\refstepcounter{mnum} \mthemnum \label{mHig}:] File Highlighter Module - \item \item [\refstepcounter{mnum} \mthemnum \label{mHov}:] Hover Manager Module + \item [\refstepcounter{mnum} \mthemnum \label{mHov}:] Hover Manager Module \item [\refstepcounter{mnum} \mthemnum \label{mMeasure}:] Measurements Module \item [\refstepcounter{mnum} \mthemnum \label{mPyA}:] Pylint Analyzer Module \item [\refstepcounter{mnum} \mthemnum \label{mTest}:] Testing Functionality Module - \item \item [\refstepcounter{mnum} \mthemnum \label{mRef}:] Smell Refactorer Module + \item [\refstepcounter{mnum} \mthemnum \label{mRef}:] Smell Refactorer Module \item [\refstepcounter{mnum} \mthemnum \label{mMan}:] Refactor Manager Module \end{description} @@ -413,6 +413,32 @@ \subsubsection{Long Parameter List Module (\mref{mLPL})} \item[Implemented By:] EcoOptimizer \end{description} +\subsubsection{Long Message Chain Refactorer (\mref{mLMC})} + + +\begin{description} + \item[Secrets:] Understanding the syntax and structure of Python code to identify/classify long message chains, including both f-strings and non-f-string chains. This involves parsing the target file, extracting method calls from identified long chains, and systematically breaking them into separate statements while preserving the original functionality and indentation. Additionally, it ensures unmatched brackets are corrected during refactoring. + + \item[Services:] Detects long message chains in Python source code and refactors them by splitting the chain into intermediate variables and a final result. This improves code readability and maintainability while retaining the original program behavior. + + \item[Implemented By:] EcoOptimizer + \item[Type of Module:] Library: a reusable component that provides functionality for refactoring long message chains in Python code. + +\end{description} + +\subsubsection{Long Lambda Function Refactorer (\mref{mLLF})} + + +\begin{description} + \item[Secrets:] Understanding the syntax and structure of Python code to identify long lambda functions. This includes parsing the target file to locate lambda expressions, extracting their arguments and bodies, and converting them into standard Python function definitions. The module ensures proper handling of nested structures (e.g., parentheses, brackets, and braces) within the lambda body, and truncates overly complex expressions at the first top-level comma for readability. + + \item[Services:] Detects components of long lambda functions in Python source code and refactors them by converting the lambda expression into a standalone function with a unique name. This improves code readability, debugging, and maintainability. The module inserts the newly defined function in the appropriate scope, updates the original lambda usage with a function call, and validates the refactored code by maintaining its functionality and measuring energy efficiency improvements. + + \item[Implemented By:] EcoOptimizer + + \item[Type of Module:] Library: a reusable component that provides functionality for refactoring long lambda functions in Python code. +\end{description} + \subsubsection{Plugin Initiator Module (\mref{mExe})} % [Record, Library, Abstract Object, or Abstract Data Type] @@ -465,34 +491,6 @@ \subsubsection{Hover Manager Module (\mref{mHov})} \subsection{Software Decision Module} -\subsubsection{Long Message Chain Refactorer (\mref{mLMC})} - - -\begin{description} - \item[Secrets:] Understanding the syntax and structure of Python code to identify/classify long message chains, including both f-strings and non-f-string chains. This involves parsing the target file, extracting method calls from identified long chains, and systematically breaking them into separate statements while preserving the original functionality and indentation. Additionally, it ensures unmatched brackets are corrected during refactoring. - - \item[Services:] Detects long message chains in Python source code and refactors them by splitting the chain into intermediate variables and a final result. This improves code readability and maintainability while retaining the original program behavior. - - \item[Implemented By:] EcoOptimizer - \item[Type of Module:] Library: a reusable component that provides functionality for refactoring long message chains in Python code. - -\end{description} - -\subsubsection{Long Lambda Function Refactorer (\mref{mLLF})} - - -\begin{description} - \item[Secrets:] Understanding the syntax and structure of Python code to identify long lambda functions. This includes parsing the target file to locate lambda expressions, extracting their arguments and bodies, and converting them into standard Python function definitions. The module ensures proper handling of nested structures (e.g., parentheses, brackets, and braces) within the lambda body, and truncates overly complex expressions at the first top-level comma for readability. - - \item[Services:] Detects components of long lambda functions in Python source code and refactors them by converting the lambda expression into a standalone function with a unique name. This improves code readability, debugging, and maintainability. The module inserts the newly defined function in the appropriate scope, updates the original lambda usage with a function call, and validates the refactored code by maintaining its functionality and measuring energy efficiency improvements. - - \item[Implemented By:] EcoOptimizer - - \item[Type of Module:] Library: a reusable component that provides functionality for refactoring long lambda functions in Python code. -\end{description} - -\subsection{Software Decision Module} - \subsubsection{Measurements Module (\mref{mMeasure})} \begin{description} diff --git a/docs/Design/SoftDetailedDes/MIS.tex b/docs/Design/SoftDetailedDes/MIS.tex index 259603b9..f5419c6d 100644 --- a/docs/Design/SoftDetailedDes/MIS.tex +++ b/docs/Design/SoftDetailedDes/MIS.tex @@ -2,7 +2,7 @@ \usepackage{amsmath, mathtools} -\usepackage[round]{natbib} +% \usepackage[round]{natbib} \usepackage{amsfonts} \usepackage{amssymb} \usepackage{graphicx} @@ -53,8 +53,7 @@ \section{Revision History} \begin{tabularx}{\textwidth}{p{3cm}p{2cm}X} \toprule {\bf Date} & {\bf Version} & {\bf Notes}\\ \midrule -Date 1 & 1.0 & Notes\\ -Date 2 & 1.1 & Notes\\ +January 17th, 2025 & 0.1 & Initial Draft\\ \bottomrule \end{tabularx} @@ -95,6 +94,7 @@ \section{Notation} \textbf{Data Type} & \textbf{Notation} & \textbf{Description}\\ \midrule optional & ? & denotes a variable as optional\\ + any type & Any & any data type is acceptable\\ character & char & a single symbol or digit\\ String & str & a sequence of characters\\ integer & $\mathbb{Z}$ & a number without a fractional component in (-$\infty$, $\infty$) \\ @@ -135,36 +135,44 @@ \section{Module Decomposition} The following table is taken directly from the Module Guide document for this project. \begin{table}[h!] -\centering -\begin{tabular}{p{0.3\textwidth} p{0.6\textwidth}} -\toprule -\textbf{Level 1} & \textbf{Level 2}\\ -\midrule - -{Hardware-Hiding} & ~ \\ -\midrule - -\multirow{7}{0.3\textwidth}{Behaviour-Hiding} & Input Parameters\\ -& Output Format\\ -& Output Verification\\ -& Temperature ODEs\\ -& Energy Equations\\ -& Control Module\\ -& Specification Parameters Module\\ -\midrule - -\multirow{3}{0.3\textwidth}{Software Decision} & {Sequence Data Structure}\\ -& ODE Solver\\ -& Plotting\\ -\bottomrule - -\end{tabular} -\caption{Module Hierarchy} -\label{TblMH} + \centering + \begin{tabular}{p{0.3\textwidth} p{0.6\textwidth}} + \toprule + \textbf{Level 1} & \textbf{Level 2}\\ + \midrule + + {Hardware-Hiding Module} & None \\ + \midrule + + \multirow{7}{0.3\textwidth}{Behaviour-Hiding Module} & Smell Module\\ + & BaseRefactorer Module\\ + & MakeStaticRefactorer Module\\ + & UseListAccumulationRefactorer Module\\ + & UseAGeneratorRefactorer Module\\ + & CacheRepeatedCallsRefactorer Module\\ + & LongElementChainRefactorer Module\\ + & LongParameterListRefactorer Module\\ + & LongMessageChainRefactorer Module\\ + & LongLambdaFunctionRefactorer Module\\ + & PluginInitiator Module\\ + & BackendCommunicator Module\\ + & SmellDetector Module\\ + & FileHighlighter Module\\ + & HoverManager Module\\ + \midrule + + + \multirow{3}{0.3\textwidth}{Software Decision Module} & Measurements Module\\ + & PylintAnalyzer Module\\ + & Testing Functionality Module\\ + & SmellRefactorer Module\\ + & RefactorManager Module\\ + \bottomrule + \end{tabular} + \caption{Module Hierarchy} + \label{TblMH} \end{table} -\newpage - ~\newpage \section{MIS of Smell Data Type} \label{mis:smell} @@ -1369,10 +1377,11 @@ \subsection{Syntax} \noindent \textbf{Exported Access Programs:}\\ \begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} - \toprule Name & In & Out & Exceptions \\ - \midrule + \hline + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ + \hline \texttt{sendRequest} & \texttt{requestType: string, data: any} & Promise & Communication Error \\ - \bottomrule + \hline \end{tabularx} @@ -1394,7 +1403,7 @@ \subsubsection{Assumptions} \end{itemize} \subsubsection{Access Routine Semantics} -\texttt{sendRequest(requestType: string, data: any)} +\texttt{sendRequest(requestType: str, data: Any)} \begin{itemize} \item \textbf{Transition}: Sends the provided request to Source Code Optimizer and receives a response. \item \textbf{Output}: A promise that resolves with Source Code Optimizer's response. @@ -1421,10 +1430,11 @@ \subsection{Syntax} \textbf{Exported Access Programs:}\\ \begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} - \toprule Name & In & Out & Exceptions \\ - \midrule + \hline + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf{Exceptions} \\ + \hline \texttt{detect} & None & None & Active file not found \\ - \bottomrule + \hline \end{tabularx} \subsection{Semantics} @@ -1471,10 +1481,11 @@ \subsection{Syntax} \textbf{Exported Access Programs:}\\ \begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} - \toprule Name & In & Out & Exceptions \\ - \midrule + \hline + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf\\ + \hline \texttt{refactor} & {smell: Smell} & None & Invalid input \\ - \bottomrule + \hline \end{tabularx} \subsection{Semantics} @@ -1519,11 +1530,12 @@ \subsection{Syntax} \noindent \textbf{Exported Access Programs:}\\ \begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} - \toprule Name & In & Out & Exceptions \\ - \midrule + \hline + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf \\ + \hline \texttt{highlight} & \texttt{range: range[]} & None & None \\ \hline \texttt{clear} & \texttt{None} & None & None \\ - \bottomrule + \hline \end{tabularx} \subsection{Semantics} @@ -1578,11 +1590,12 @@ \subsection{Syntax} \textbf{Exported Access Programs:}\\ \begin{tabularx}{\linewidth}{|l|>{\raggedright\arraybackslash}X|l|l|} - \toprule Name & In & Out & Exceptions \\ - \midrule + \hline + \textbf{Name} & \textbf{In} & \textbf{Out} & \textbf \\ + \hline \texttt{showHover} & \texttt{position: Position} & None & None \\ \hline \texttt{clearHover} & \texttt{None} & None & None \\ - \bottomrule + \hline \end{tabularx} \subsection{Semantics} @@ -1684,8 +1697,8 @@ \subsubsection{Access Routine Semantics} \subsubsection{Local Functions} None -\bibliographystyle {plainnat} -\bibliography {../../../refs/References} +% \bibliographystyle {plainnat} +% \bibliography {../../../refs/References} \newpage From 4d272aca5cf24ec80192688eb623f1d4fefcf17f Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 17 Jan 2025 16:57:30 -0500 Subject: [PATCH 4/5] Fixed table for AC trace table --- docs/Design/SoftArchitecture/MG.tex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/Design/SoftArchitecture/MG.tex b/docs/Design/SoftArchitecture/MG.tex index 8df31420..0e6f0bc8 100644 --- a/docs/Design/SoftArchitecture/MG.tex +++ b/docs/Design/SoftArchitecture/MG.tex @@ -711,11 +711,11 @@ \section{Traceability Matrix} \label{SecTM} \toprule \textbf{AC} & \textbf{Modules}\\ \midrule - \acref{acUserInterface} & \mref{mExe}, \mref{mHig} , \mref{mHov}, \mref{mMan} \\ \hline - \acref{acVSCodePlugin} & \mref{mExe} , \mref{mRef}, \mref{mMan} \\ \hline - \acref{acRefactorers} & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLPL} \\ \hline - \acref{acSmell} & \mref{mDet}, \mref{mPyA} \\ \hline - \acref{acAnalyzer} & \mref{mM}, \mref{mPyA}, \mref{mDet} \\ \hline + \acref{acUserInterface} & \mref{mExe}, \mref{mHig} , \mref{mHov}, \mref{mMan} \\ + \acref{acVSCodePlugin} & \mref{mExe} , \mref{mRef}, \mref{mMan} \\ + \acref{acRefactorers} & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLPL} \\ + \acref{acSmell} & \mref{mDet}, \mref{mPyA} \\ + \acref{acAnalyzer} & \mref{mM}, \mref{mPyA}, \mref{mDet} \\ \acref{acTesting} & \mref{mTest} \\ \bottomrule \end{tabular} From 2d75a8865778c5a64ee5629793bb656a73dbdd6e Mon Sep 17 00:00:00 2001 From: Sevhena Walker <83547364+Sevhena@users.noreply.github.com> Date: Fri, 17 Jan 2025 17:07:15 -0500 Subject: [PATCH 5/5] little fixes --- docs/Design/SoftArchitecture/MG.tex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/Design/SoftArchitecture/MG.tex b/docs/Design/SoftArchitecture/MG.tex index 0e6f0bc8..f06e3e7e 100644 --- a/docs/Design/SoftArchitecture/MG.tex +++ b/docs/Design/SoftArchitecture/MG.tex @@ -658,7 +658,7 @@ \section{Traceability Matrix} \label{SecTM} \toprule \textbf{Req.} & \textbf{Modules}\\ \midrule % Maintenance and Support - MS-MNT 1 \mref{mBR}\\ + MS-MNT 1 & \mref{mBR}\\ MS-MNT 2 & Not implemented in code\\ MS-MNT 3 & None \\ MS-MNT 4 & N/A\\ @@ -715,7 +715,7 @@ \section{Traceability Matrix} \label{SecTM} \acref{acVSCodePlugin} & \mref{mExe} , \mref{mRef}, \mref{mMan} \\ \acref{acRefactorers} & \mref{mBR}, \mref{mMIMR}, \mref{mSCLR}, \mref{mUGENR}, \mref{mCRC}, \mref{mLEC}, \mref{mLPL} \\ \acref{acSmell} & \mref{mDet}, \mref{mPyA} \\ - \acref{acAnalyzer} & \mref{mM}, \mref{mPyA}, \mref{mDet} \\ + \acref{acAnalyzer} & \mref{mMeasure}, \mref{mPyA}, \mref{mDet} \\ \acref{acTesting} & \mref{mTest} \\ \bottomrule \end{tabular}