Download
industrial project 236504 advanced programming tools for refactoring java code in eclipse n.
Skip this Video
Loading SlideShow in 5 Seconds..
Industrial Project (236504) Advanced programming tools for refactoring Java code in Eclipse PowerPoint Presentation
Download Presentation
Industrial Project (236504) Advanced programming tools for refactoring Java code in Eclipse

Industrial Project (236504) Advanced programming tools for refactoring Java code in Eclipse

127 Views Download Presentation
Download Presentation

Industrial Project (236504) Advanced programming tools for refactoring Java code in Eclipse

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. COMPUTER SCIENCE DEPARTMENT Technion - Israel Institute of Technology August 12, 2009 Industrial Project (236504)Advanced programming tools for refactoring Java code in Eclipse Student:Alexander Libov Supervisor:Dr. Ran Ettinger, IBM.

  2. Our goal • Improving code maintenance by enabling advanced refactoring methods (in Eclipse). • Implement Replace Temp with Query refactoring • Why is it important? • The benefit is increased readability (in therefactored version) and reusability (of the extracted computation) • The steps of turning procedural design to objects mainly involveintroducing new classes, extracting methods, moving variables and methods(to the new classes), inlining methods and renaming variables and methods.All those are either straightforward or already supported by modernrefactoring tools. It is the extraction of non-contiguous code (as inReplace Temp with Query) for which automation is missing and required.

  3. Definitions • Sliced Variable – the variable that serves as a base to compute a slice • Selected by the user. • It is important which of the occurrences is selected. • Slice – a piece of code that eventually calculates the sliced variable value in the location selected by the user • The slice does not include the statement which holds the sliced variable. • The relevant code starts at the head of the current block and ends immediately before the selected statement. • Co-Slice - a piece of code that calculates the rest of the calculations done inside the block apart from the sliced variable • Can contain statements from the slice. • Also located between the head of the current block and the selected statement. • Sliding – separating the slice from the co-slice in the covering block. • Must preserve the observable behavior of the program.

  4. Methodology part I The main workflow of the actions is as described below: User chooses a variable reference Use WALA to calculate the Slice Use WALA to calculate the Co-Slice Show Slice Replace temp with query

  5. Methodology part II The Replace Temp with Query in a bit more detail: Slice Check preconditions Co-Slice Duplicate the covering block’s code Leave only the slice in the first part and co-slice and rest of the code in the second part a return statement for the extracted variable will be added at the end of the extracted method, in the original block, the slice will be replaced by a declaration of that temp with a call to the extracted method for its initialization. Run extract method on the slice Run inline temp on the declaration of the sliced variable

  6. Replace Temp with Query Example The user chose sum to be the sliced variable (that is,the temp to be replaced with a query) ...{  int sum = 0;  int prod = 1;  for (int i=0; i<a.length; i++) {     sum += a[i];     prod *= a[i];  }  System.out.println("The total sum is " + sum);  System.out.println("The product is " + prod);  ... } ...

  7. Replace Temp with Query Example – Sliding …{   int sum = 0;  for (int i=0; i<a.length; i++) {     sum += a[i];  } int prod = 1;   for (int i=0; i<a.length; i++) {     prod *= a[i];  } System.out.println("The total sum is " + sum); System.out.println("The product is " + prod); } … The Slice – Extract Method fragment The Co-Slice

  8. Replace Temp with Query Example –– After Extract Method ... {  int sum = computeSum(a);  int prod = 1;  for (int i=0; i<a.length; i++) {     prod *= a[i];  }  System.out.println("The total sum is " + sum);  System.out.println("The product is " + prod);  ... } ... Inline Temp selection int computeSum(int[] a) { int sum = 0; for (int i=0; i<a.length; i++) {     sum += a[i]; } return sum; } The extracted method

  9. Replace Temp with Query Example –– After Inline Temp ... {  int prod = 1;  for (int i=0; i<a.length; i++) {     prod *= a[i];  }  System.out.println("The total sum is " + computeSum(a));  System.out.println("The product is " + prod);  ... } ... The sum variable is replaced with a computeSum query Int computeSum(int[] a) { int sum = 0; for (int i=0; i<a.length; i++) {     sum += a[i]; } return sum; }

  10. Replace Temp with Query Example - Recap ... {  int sum = computeSum(a);  int prod = 1;  for (int i=0; i<a.length; i++) {     prod *= a[i];  }  System.out.println("The total sum is " + sum);  System.out.println("The product is " + prod);  ...} ... ... {  int prod = 1;  for (int i=0; i<a.length; i++) {     prod *= a[i];  }  System.out.println("The total sum is " + computeSum(a));  System.out.println("The product is " + prod);  ...} ... …{   int sum = 0;  for (int i=0; i<a.length; i++) {     sum += a[i];  } int prod = 1;   for (int i=0; i<a.length; i++) {     prod *= a[i];  } System.out.println("The total sum is " + sum);System.out.println("The product is " + prod); … } … Int computeSum(int[] a) { int sum = 0;  for (int i=0; i<a.length; i++) {     sum += a[i];  } return sum; } ... {  int sum = 0;  int prod = 1;  for (int i=0; i<a.length; i++) {     sum += a[i];     prod *= a[i];  }  System.out.println("The total sum is " + sum);  System.out.println("The product is " + prod);  ...} ...

  11. Replace Temp with Query Example – Final result ... {  System.out.println("The total sum is " + computeSum(a));  System.out.println("The product is " + computeProd(a));  ... } ... Int computeSum(int[] a) { int sum = 0;  for (int i=0; i<a.length; i++) {     sum += a[i];  } return sum; } Int computeProd(int[] a) { int prod = 1;  for (int i=0; i<a.length; i++) {     prod *= a[i];  } return prod; }

  12. Achievements • A fully working “Show Slice” action • Generates breakpoints on the slice’s lines. • Shows pop-up with more detail about the slice. • Works on entire compilation unit (not method only). • A rudimentary “Replace temp With Query” refactoring • Works on simple examples. • more work is needed on identifying and implementing preconditions to guarantee behavior preservation. • Calculates slice and co-slice only in the covering block (as it should). • Runs existing refactoring tools – “Extract Method” and “Inline Temp”.

  13. Limitations • WALA limitations • Variable declarations are not part of the slice. • Conditional branches are part of the slice when they have nested statements that are not part of the block. • Works slowly ( to WALA's defense slicing is known to be complex, it actually analyses the whole program, not only the selected method). • Works only on methods that are reachable from the main method. • Replace Temp with Query limitations • Needs better pre-condition checking and extension to more use cases. • An import must be updated on the move from one Eclipse version to another. • Need to handle variable declarations better. • Function calls handled wrong by the slicer (probably because of the default use of the pointer analysis). • A very basic sliding algorithm is implemented -- in the spirit of the older Tucking, a transformation due to Lakhotia and Deprez.

  14. Conclusions • It is hard to work in a team (even of two) without source control • Working with large scale software is difficult • One can easily be lost inside the code. • Hard to tell what the flow is. • The refactoring framework in Eclipse/JDT is not easily ready for composition of refactoring tools • Code analysis is an interesting and complicated subject that doesn’t get enough coverage during undergraduate studies • Industrial Project course offers a real-life experience of how software development occurs • Needed experience for all software engineering students. • It can contribute to better blending of the student in the industry afterwards.