a goal ▪ Understand the code base ▪ Set up a safety net - Tests! ▪ Refactor ▪ Go with baby steps ▪ Test ▪ Does everything still work? ▪ Repeat Slide 7 Refactor Test
helps - but never guarantees. ▪ Program Equivalence ▪ Do programs P and Q terminate on the same state when starting on the same one? ▪ Reducible to the Halting Problem. ▪ Undecidable!!! ▪ All nontrivial semantic properties are undecidable Rice’s Theorem ▪ The good news: Undecidable only in general! ▪ Show correctness for specific cases ▪ Trivial properties are decidable. Slide 8
12 ▪ Methods should not be empty ▪ Deprecated code should be removed ▪ Sections of code should not be commented out @Deprecated public static void doSomething(Object changeMe) { // throw new UnsupportedOperationException(); }
Slide 18 1 Parsing source to AST First you need a tool that w ill parse your source code like a com piler 2 M anipulating AST Use the resulting AST to adopt the code and apply fixes 3 Assure syntax still valid Verify changes result in a valid source code 4 W riting Changes Apply the changes to the source file and replace it
Slide 19 Java Grammar Java Compiler Advantages of the Framework • Open source • Integrated within Eclipse IDE 1 Eclipse JDT • Open source • Integrated within Intellij IDE 2 Javaparser.org • Mostly independent • Building a lot from scratch 3 Antlr 4