@@ -19,32 +19,32 @@ import parser.PlSql_Parser;
1919
2020@Aspect
2121public aspect JavaTranslationAspect {
22-
22+ 2323 List<String > code = new ArrayList<String > ();
2424 List<Integer > forIndexes = new ArrayList<Integer > ();
2525 boolean isInsideAssignment = false ;
26-
26+ 2727 // Antes de la ejecución de CompilationUnit, escribimos todo
2828 // el código anterior al bloque de la clase autogenerada.
2929 @Before (" (execution(* parser.PlSql_Parser.CompilationUnit()))" )
3030 public void beforeCompilationUnit (JoinPoint jp ) {
3131 String newCode = " public class " + PlSql_Parser . getClassName() + " {" + getIntro(1 )
32- + " public static void main(String args[]){" + getIntro(1 );
32+ + " public static void main(String args[]){" + getIntro(1 );
3333 code. add(newCode);
3434 consolePrint(" @Before" , " CompilationUnit" , print2String(code), newCode);
3535 }
3636
3737 // Después de la ejecución de ProcedureReference, tomamos las referencias,
3838 // las traducimos usando el diccionario y las insertamos en el código.
3939 @AfterReturning (pointcut = " (execution(* PlSql_Parser.ProcedureReference(..)))" ,returning = " name" )
40- public void afterProcedureReference (String name ) {
40+ public void afterProcedureReference (String name ) {
4141 if (! name. equals(" null" ) && name != null ) {
4242 String newCode = Dictionary . ProcedureReference (name);
4343 code. add(newCode);
4444 consolePrint(" @AfterReturning" , " ProcedureReference" , print2String(code), newCode);
4545 }
46- }
47-
46+ }
47+ 4848 // Después de la ejecución de ProcedureReference, abrimos el paréntesis
4949 // que contiene los parámetros.
5050 @After (" (execution(* PlSql_Parser.ProcedureReference(..)))" )
@@ -53,7 +53,7 @@ public aspect JavaTranslationAspect {
5353 code. add(newCode);
5454 consolePrint(" @After" , " ProcedureReference" , print2String(code), newCode);
5555 }
56-
56+ 5757 // Después de la ejecución de Arguments, se traducen los parámetros
5858 // usando el diccionario y se insertan.
5959 @AfterReturning (pointcut = " (execution(* PlSql_Parser.Arguments(..)))" ,returning = " arguments" )
@@ -62,7 +62,7 @@ public aspect JavaTranslationAspect {
6262 code. add(newCode);
6363 consolePrint(" @AfterReturning" , " Arguments" , print2String(code), newCode);
6464 }
65-
65+ 6666 // Después de la ejecución de ProcedureCall, se cierra el paréntesis
6767 // que contiene los argumentos.
6868 @After (" (execution(* PlSql_Parser.ProcedureCall(..)))" )
@@ -71,7 +71,7 @@ public aspect JavaTranslationAspect {
7171 code. add(newCode);
7272 consolePrint(" @After" , " ProcedureCall" , print2String(code), newCode);
7373 }
74-
74+ 7575 // Después de la ejecución de CompilationUnit, cerramos la
7676 // llave del bloque de la clase autogenerada.
7777 @After (" (execution(* PlSql_Parser.CompilationUnit(..)))" )
@@ -92,7 +92,7 @@ public aspect JavaTranslationAspect {
9292 consolePrint(" @Before" , " NumericForLoop" , print2String(code), newCode);
9393 forIndexes. add(code. size()- 1 );
9494 }
95-
95+ 9696 // Después de la ejecución de NumericForLoop, retiramos del código todo
9797 // lo que está por debajo del índice del fragmento insertado en el @Before.
9898 // Después, completamos el código del for y reinsertamos todo lo eliminado
@@ -104,7 +104,7 @@ public aspect JavaTranslationAspect {
104104 List<String > innerCode = new ArrayList<String > (code. subList(codeIndex+ 1 , code. size()));
105105 auxCode = code. subList(0 , codeIndex+ 1 );
106106 String newCode = arguments[1 ] + " , " + arguments[2 ] + " ).forEach("
107- + getIntro(1 ) + arguments[0 ] + " -> {" + getIntro(1 );
107+ + getIntro(1 ) + arguments[0 ] + " -> {" + getIntro(1 );
108108 code = auxCode;
109109 code. add(newCode);
110110 System . out. println(code. toString());
@@ -114,90 +114,81 @@ public aspect JavaTranslationAspect {
114114 consolePrint(" @AfterReturning" , " NumericForLoop" , print2String(code), newCode);
115115 forIndexes. remove(forIndexes. size()- 1 );
116116 }
117- // ////////////////////////////////////////////////////////////////
118- // en el paso anterior. Por último, insertamos la llave de cierre del bucle.
119- // ////////////////////////////////////////////////////////////////
120- @AfterReturning (pointcut = " (execution(* PlSql_Parser.VariableDeclaration(..)))" , returning = " arguments" )
121- public void afterVariableDeclaration (String [] arguments ) {
122- String dataType = Dictionary . dataType(arguments[1 ]);
123- String newCode = dataType + " " + arguments[0 ] + " = " + arguments[2 ] + " ;" + getIntro(1 );
117+ 118+ // Después de VariableDeclaration, recogemos los valores necesarios e insertamos la línea correspondiente.
119+ @AfterReturning (pointcut = " (execution(* PlSql_Parser.VariableDeclaration(..)))" , returning = " arguments" )
120+ public void afterVariableDeclaration (String [] arguments ) {
121+ String dataType = Dictionary . dataType(arguments[1 ]);
122+ String newCode = dataType + " " + arguments[0 ] + " = " + arguments[2 ] + " ;" + getIntro(1 );
123+ code. add(newCode);
124+ consolePrint(" @AfterReturning" , " VariableDeclaration" , print2String(code), newCode);
125+ }
126+ 127+ // Antes de AssingmentStatement, se habilitan los advisors de
128+ // PlSqlSimpleExpression y PlSqlMultiplicativeExpression.
129+ @Before (" (execution(* parser.PlSql_Parser.AssignmentStatement()))" )
130+ public void beforeAssignmentStatement (JoinPoint jp ) {
131+ isInsideAssignment = true ;
132+ }
133+ 134+ // Después de Assingmentstatement, se captura el nombre de la variable que recibe
135+ // el resultado y se coloca, seguida de "=", delante de los dos últimos token.
136+ // Por último, se deshabilitan los advisors de PlSqlSimpleExpression y PlSqlMultiplicativeExpression.
137+ @AfterReturning (pointcut = " (execution(* parser.PlSql_Parser.AssignmentStatement()))" , returning = " variable" )
138+ public void afterAssignmentStatement (String variable ) {
139+ String temp = code. get(code. size()- 1 );
140+ code = new ArrayList<String > (code. subList(0 , code. size()- 1 ));
141+ String newCode = variable + " " + " =" + temp + " ;" + getIntro(1 );
142+ code. add(newCode);
143+ consolePrint(" @AfterReturning" , " AssignmentStatement" , print2String(code), newCode);
144+ isInsideAssignment = false ;
145+ }
146+ 147+ // Después de PlSqlSimpleExpression se captura el operador de la expresión y se coloca entre los operandos.
148+ @AfterReturning (pointcut = " (execution(* PlSql_Parser.PlSqlSimpleExpression(..)))" , returning = " operation" )
149+ public void afterPlSqlSimpleExpression (String operation ) {
150+ if (isInsideAssignment) {
151+ List<String > temp = new ArrayList<String > (code. subList(code. size()- 2 , code. size()));
152+ code = new ArrayList<String > (code. subList(0 , code. size()- 2 ));
153+ String newCode = temp. get(0 ) + " " + operation + " " + temp. get(1 );
124154 code. add(newCode);
125- consolePrint(" @AfterReturning" , " VariableDeclaration " , print2String(code), newCode);
155+ consolePrint(" @AfterReturning" , " PlSqlSimpleExpression " , print2String(code), newCode);
126156 }
157+ }
127158
128- // ////////////////////////////////////////////////////////////////
129- // Antes de AssingmentStatement, se habilitan los advisors de
130- // PlSqlSimpleExpression y PlSqlMultiplicativeExpression.
131- // ////////////////////////////////////////////////////////////////
132- @Before (" (execution(* parser.PlSql_Parser.AssignmentStatement()))" )
133- public void beforeAssignmentStatement (JoinPoint jp ) {
134- isInsideAssignment = true ;
135- }
136- 137- // ////////////////////////////////////////////////////////////////
138- // Después de Assingmentstatement pillar el nombre de la variable que recibe
139- // el resultado
140- // y deshabilitar los dos métodos de abajo para su funcionamiento
141- // ////////////////////////////////////////////////////////////////
142- @AfterReturning (pointcut = " (execution(* parser.PlSql_Parser.AssignmentStatement()))" , returning = " variable" )
143- public void afterAssignmentStatement (String variable ) {
144- String temp = code. get(code. size()- 1 );
145- code = new ArrayList<String > (code. subList(0 , code. size()- 1 ));
146- String newCode = variable + " " + " =" + temp + " ;" + getIntro(1 );
159+ // Después de PlSqlMultiplicativeExpression se captura el operando de la expresión.
160+ @AfterReturning (pointcut = " (execution(* PlSql_Parser.PlSqlMultiplicativeExpression(..)))" , returning = " operator" )
161+ public void afterPlSQLMultiplicativeExpression (String operator ) {
162+ if (isInsideAssignment) {
163+ String newCode = " " + operator + " " ;
147164 code. add(newCode);
148- consolePrint(" @AfterReturning" , " AssignmentStatement" , print2String(code), newCode);
149- isInsideAssignment = false ;
150- }
151- 152- // ////////////////////////////////////////////////////////////////
153- // plsqlsimpleexpression pillar operando1 operador operando2
154- // ////////////////////////////////////////////////////////////////
155- @AfterReturning (pointcut = " (execution(* PlSql_Parser.PlSqlSimpleExpression(..)))" , returning = " operation" )
156- public void afterPlSqlSimpleExpression (String operation ) {
157- if (isInsideAssignment) {
158- List<String > temp = new ArrayList<String > (code. subList(code. size()- 2 , code. size()));
159- code = new ArrayList<String > (code. subList(0 , code. size()- 2 ));
160- String newCode = temp. get(0 ) + " " + operation + " " + temp. get(1 );
161- code. add(newCode);
162- consolePrint(" @AfterReturning" , " PlSqlSimpleExpression" , print2String(code), newCode);
163- }
165+ consolePrint(" @AfterReturning" , " PlSqlMultiplicativeExpression" , print2String(code), newCode);
164166 }
165- 166- // ////////////////////////////////////////////////////////////////
167- // En multiplicativeExression cazar los valores a operar
168- // ////////////////////////////////////////////////////////////////
169- @AfterReturning (pointcut = " (execution(* PlSql_Parser.PlSqlMultiplicativeExpression(..)))" , returning = " operator" )
170- public void afterPlSQLMultiplicativeExpression (String operator ) {
171- if (isInsideAssignment) {
172- String newCode = " " + operator + " " ;
173- code. add(newCode);
174- consolePrint(" @AfterReturning" , " PlSqlMultiplicativeExpression" , print2String(code), newCode);
175- }
176- }
177- 167+ }
168+ 178169 // /////////////////////// Auxiliary methods /////////////////////////////
179-
170+ 180171 private void consolePrint (String moment , String construct , String oldCode , String newCode ) {
181172 System . out. println(moment + " " + construct + " , inserting: " + getIntro(1 ) + newCode + getIntro(1 ));
182173 System . out. println(oldCode + getIntro(1 ));
183174 }
184-
175+ 185176 private String getIntro (int n ) {
186177 String tabs = " " ;
187178 for (int i = 0 ; i< n; i++ ) {
188179 tabs + = " \r\n " ;
189180 }
190181 return tabs;
191182 }
192-
183+ 193184 private void addAll (List<String > to , List<String > from ) {
194185 Iterator<String > iterator = from. iterator();
195186 while (iterator. hasNext()) {
196187 String item = iterator. next();
197188 to. add(item);
198189 }
199190 }
200-
191+ 201192 private String print2String (List<String > code ) {
202193 String output = " " ;
203194 Iterator<String > iterator = code. iterator();
@@ -207,4 +198,4 @@ public aspect JavaTranslationAspect {
207198 }
208199 return output;
209200 }
210- }
201+ }
0 commit comments