Add example algorithm
BIN
images/ASTClass.png
Normal file
After Width: | Height: | Size: 27 KiB |
BIN
images/ASTCondition.png
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
images/ASTConditionEx.png
Normal file
After Width: | Height: | Size: 73 KiB |
BIN
images/ASTConditionField.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
images/ASTField.png
Normal file
After Width: | Height: | Size: 31 KiB |
BIN
images/ASTFinish.png
Normal file
After Width: | Height: | Size: 88 KiB |
BIN
images/ASTLoop.png
Normal file
After Width: | Height: | Size: 55 KiB |
BIN
images/ASTLoopField.png
Normal file
After Width: | Height: | Size: 60 KiB |
BIN
images/ASTMetArgs.png
Normal file
After Width: | Height: | Size: 49 KiB |
BIN
images/ASTMethod1.png
Normal file
After Width: | Height: | Size: 37 KiB |
BIN
images/ASTMethod2.png
Normal file
After Width: | Height: | Size: 45 KiB |
BIN
images/ExampleAST.png
Normal file
After Width: | Height: | Size: 60 KiB |
Before Width: | Height: | Size: 12 KiB |
95
paper.tex
@ -112,54 +112,117 @@ We developed an algorithm to extract the structure of the project in the source
|
||||
\begin{equation*}
|
||||
N^{Class} = \lbrace N_{i} \in N | F \left( N_{i}.data \right) = \text{`Class'} \rbrace,
|
||||
\end{equation*}
|
||||
|
||||
|
||||
\begin{table}[]
|
||||
\begin{tabular}{|l|c|}
|
||||
\hline
|
||||
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
|
||||
public class Main \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTClass.png}} \\ \hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\item Select nodes with the `Class field' as the $N^{Vars}$ set from the $N^{Class}$ set:
|
||||
\begin{equation*}
|
||||
N^{Vars} = \lbrace N_{i}^{Class} \in N^{Class} | F \left( N_{i}^{Class}.data \right) = \text{`Field'} \rbrace,
|
||||
\end{equation*}
|
||||
|
||||
\begin{table}[]
|
||||
\begin{tabular}{|l|c|}
|
||||
\hline
|
||||
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
|
||||
private String a; & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTField.png}} \\ \hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\item Select nodes with the `Methods' type as the $N^{Methods}$ set from the $N^{Class}$ set:
|
||||
\begin{equation*}
|
||||
N^{Methods} = \lbrace N_{i}^{Class} \in N^{Class} | F \left( N_{i}^{Class}.data \right) = \text{`Method'} \rbrace,
|
||||
\end{equation*}
|
||||
|
||||
\begin{table}[]
|
||||
\begin{tabular}{|l|c|}
|
||||
\hline
|
||||
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
|
||||
void run() \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTMethod1.png}} \\ \hline
|
||||
void show(String text) \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTMethod2.png}} \\ \hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\item Select nodes with the `Method Argument' type as the $N^{MethodsArgs}$ set from the $N^{Methods}$ set:
|
||||
\begin{equation*}
|
||||
N^{MethodsArgs} = \lbrace N_{i}^{Methods} \in N^{Methods} | F \left( N_{i}^{Methods}.data \right) = \text{`Arg'} \rbrace,
|
||||
\end{equation*}
|
||||
|
||||
\begin{table}[]
|
||||
\begin{tabular}{|l|c|}
|
||||
\hline
|
||||
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
|
||||
void show(String text) \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTMetArgs.png}} \\ \hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\item Select nodes with the `Operator' type as the $N^{MethodsOps}$ from the $N^{Methods}$ set:
|
||||
\begin{equation*}
|
||||
N^{MethodsOps} = \lbrace N_{i}^{Methods} \in N^{Methods} | F \left( N_{i}^{Methods}.data \right) = \text{`Operator'} \rbrace,
|
||||
\end{equation*}
|
||||
|
||||
\begin{table}[]
|
||||
\begin{tabular}{|l|c|}
|
||||
\hline
|
||||
\multicolumn{1}{|c|}{Source code string} & Nodes \\ \hline
|
||||
while(true) \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTLoop.png}} \\ \hline
|
||||
int a = 1; & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTLoopField.png}} \\ \hline
|
||||
if (a == 1) \{ & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTCondition.png}} \\ \hline
|
||||
this.show("Hello") & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTConditionEx.png}} \\ \hline
|
||||
int c = "Foo"; & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTConditionField.png}} \\ \hline
|
||||
System.out.println(text); & \raisebox{-\totalheight}{\includegraphics[width=10cm]{images/ASTFinish.png}} \\ \hline
|
||||
\end{tabular}
|
||||
\end{table}
|
||||
|
||||
\item Create the set of ties $R$ between the nodes from sets obtained in previous steps.
|
||||
\item Save the resulting AST in a graph database (GDB).
|
||||
\end{enumerate}
|
||||
|
||||
In this algorithm, F (*) is a search function that finds nested nodes. The function input is a node or subtree, and the output is a node of the desired type.
|
||||
|
||||
Figure \ref{fig:SourceCodeAndAST} shows the resulting AST for the following source code:
|
||||
Figure 1\ref{fig:ExampleAST} shows the resulting ACT for the following source code:
|
||||
|
||||
\begin{lstlisting}
|
||||
package com.example.demo.simple;
|
||||
public class Main {
|
||||
private String a;
|
||||
void run() {
|
||||
while(true) {
|
||||
int a = 1;
|
||||
if (a == 1) {
|
||||
this.show("Hello")
|
||||
}
|
||||
package laba1;
|
||||
public class Scheduler {
|
||||
private final int time = 5;
|
||||
private ArrayList<Thread> threads = new ArrayList<Thread>();
|
||||
|
||||
void scheduler() {
|
||||
for (int i=0; i<threads.size(); i++) {
|
||||
threads.get(i).run(time);
|
||||
System.out.println(threads.get(i).toString());
|
||||
}
|
||||
int c = "Foo";
|
||||
}
|
||||
void show(String text) {
|
||||
System.out.println(text);
|
||||
}
|
||||
\end{lstlisting}
|
||||
|
||||
This source code looks different, but the AST is the same:
|
||||
|
||||
\begin{lstlisting}
|
||||
package os-lab-1;
|
||||
public class Planing {
|
||||
private final int QUANT = 10;
|
||||
private List<Stream> streams = new ArrayList<>();
|
||||
|
||||
void plan() {
|
||||
for (Stream stream: streams) {
|
||||
stream.run(QUANT);
|
||||
System.out.println(stream.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
\end{lstlisting}
|
||||
|
||||
\begin{figure}
|
||||
\centering
|
||||
\includegraphics[width=0.71\textwidth]{images/AST.png}
|
||||
\caption{Sample source code and its AST.} \label{fig:SourceCodeAndAST}
|
||||
\includegraphics[width=0.71\textwidth]{images/ExampleAST.png}
|
||||
\caption{Sample AST.} \label{fig:ExampleAST}
|
||||
\end{figure}
|
||||
|
||||
|
||||
|