Project: JDT
Bug 211529 [extract constant] misses case statement expression
Reported: 2007-11-29 18:08:05 | Status: verified fixed

Extracting a constant, and replacing all occurrences of the expr with the new constant, misses case labels. Initial code: public static String revCompl(String seq) { StringBuffer buf = new StringBuffer(); for (int i = seq.length() - 1; i >= 0; --i) { char c = seq.charAt(i); switch (c) { case 'A': buf.append('T'); break; case 'T': buf.append('A'); break; case 'G': buf.append('C'); break; case 'C': buf.append('G'); break; default: buf.append(c); System.out.println("Invalid nucleotide: " + c + " in sequence " + seq); break; } } return buf.toString(); } After refactoring: private static final char A = 'A'; private static final char T = 'T'; private static final char G = 'G'; private static final char C = 'C'; public static String revCompl(String seq) { StringBuffer buf = new StringBuffer(); for (int i = seq.length() - 1; i >= 0; --i) { char c = seq.charAt(i); switch (c) { case 'A': // This should be case A: buf.append(T); break; case 'T': buf.append(A); break; case 'G': buf.append(C); break; case 'C': buf.append(G); break; default: buf.append(c); System.out.println("Invalid nucleotide: " + c + " in sequence " + seq); break; } } return buf.toString(); }

Files changed in fix:
org.eclipse.jdt.ui.tests.refactoring/resources/ExtractConstant/canExtract/A_test44_in.java org.eclipse.jdt.ui.tests.refactoring/resources/ExtractConstant/canExtract/A_test44_out.java org.eclipse.jdt.ui.tests.refactoring/test cases/org/eclipse/jdt/ui/tests/refactoring/ExtractConstantTests.java org.eclipse.jdt.ui/core refactoring/org/eclipse/jdt/internal/corext/refactoring/code/ExtractConstantRefactoring.java