| /******************************************************************************* |
| * Copyright (c) 2000, 2004 IBM Corporation and others. |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Common Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/cpl-v10.html |
| * |
| * Contributors: |
| * IBM Corporation - initial API and implementation |
| *******************************************************************************/ |
| package org.eclipse.jdt.ui.tests.refactoring; |
| |
| import junit.framework.Test; |
| import junit.framework.TestSuite; |
| |
| import org.eclipse.jdt.core.ICompilationUnit; |
| import org.eclipse.jdt.core.IPackageFragment; |
| import org.eclipse.jdt.core.ISourceRange; |
| import org.eclipse.jdt.internal.corext.SourceRange; |
| import org.eclipse.jdt.internal.corext.refactoring.rename.RenameTempRefactoring; |
| import org.eclipse.jdt.ui.tests.refactoring.infra.TextRangeUtil; |
| |
| import org.eclipse.ltk.core.refactoring.RefactoringStatus; |
| |
| public class RenameTempTests extends RefactoringTest{ |
| |
| private static final Class clazz= RenameTempTests.class; |
| private static final String REFACTORING_PATH= "RenameTemp/"; |
| |
| public RenameTempTests(String name){ |
| super(name); |
| } |
| |
| protected String getRefactoringPath() { |
| return REFACTORING_PATH; |
| } |
| |
| public static Test suite() { |
| return new RefactoringTestSetup(new TestSuite(clazz)); |
| } |
| |
| public static Test setUpTest(Test test) { |
| return new RefactoringTestSetup(test); |
| } |
| |
| private String getSimpleTestFileName(boolean canRename, boolean input){ |
| String fileName = "A_" + getName(); |
| if (canRename) |
| fileName += input ? "_in": "_out"; |
| return fileName + ".java"; |
| } |
| |
| private String getTestFileName(boolean canRename, boolean input){ |
| String fileName= TEST_PATH_PREFIX + getRefactoringPath(); |
| fileName += (canRename ? "canRename/": "cannotRename/"); |
| return fileName + getSimpleTestFileName(canRename, input); |
| } |
| |
| //------------ |
| protected ICompilationUnit createCUfromTestFile(IPackageFragment pack, boolean canRename, boolean input) throws Exception { |
| return createCU(pack, getSimpleTestFileName(canRename, input), getFileContents(getTestFileName(canRename, input))); |
| } |
| |
| private ISourceRange getSelection(ICompilationUnit cu) throws Exception{ |
| String source= cu.getSource(); |
| int offset= source.indexOf(AbstractSelectionTestCase.SQUARE_BRACKET_OPEN); |
| int end= source.indexOf(AbstractSelectionTestCase.SQUARE_BRACKET_CLOSE); |
| return new SourceRange(offset, end - offset); |
| } |
| |
| private void helper1(String newName, boolean updateReferences, ISourceRange selection, ICompilationUnit cu) throws Exception{ |
| // IType classA= getType(cu, "A"); |
| RenameTempRefactoring ref= RenameTempRefactoring.create(cu, selection.getOffset(), selection.getLength()); |
| ref.setUpdateReferences(updateReferences); |
| ref.setNewElementName(newName); |
| |
| RefactoringStatus result= performRefactoring(ref); |
| assertEquals("precondition was supposed to pass", null, result); |
| |
| IPackageFragment pack= (IPackageFragment)cu.getParent(); |
| String newCuName= getSimpleTestFileName(true, true); |
| ICompilationUnit newcu= pack.getCompilationUnit(newCuName); |
| assertTrue(newCuName + " does not exist", newcu.exists()); |
| assertEqualLines("incorrect renaming", getFileContents(getTestFileName(true, false)), newcu.getSource()); |
| } |
| |
| private void helper1(String newName, boolean updateReferences) throws Exception{ |
| ICompilationUnit cu= createCUfromTestFile(getPackageP(), true, true); |
| helper1(newName, updateReferences, getSelection(cu), cu); |
| } |
| |
| private void helper1(String newName, boolean updateReferences, int startLine, int startColumn, int endLine, int endColumn) throws Exception{ |
| ICompilationUnit cu= createCUfromTestFile(getPackageP(), true, true); |
| ISourceRange selection= TextRangeUtil.getSelection(cu, startLine, startColumn, endLine, endColumn); |
| helper1(newName, updateReferences, selection, cu); |
| } |
| |
| private void helper1(String newName) throws Exception{ |
| helper1(newName, true); |
| } |
| |
| private void helper2(String newName, boolean updateReferences) throws Exception{ |
| ICompilationUnit cu= createCUfromTestFile(getPackageP(), false, true); |
| ISourceRange selection= getSelection(cu); |
| failTestHelper(newName, updateReferences, cu, selection); |
| } |
| |
| private void helper2(String newName, boolean updateReferences, int startLine, int startColumn, int endLine, int endColumn) throws Exception{ |
| ICompilationUnit cu= createCUfromTestFile(getPackageP(), false, true); |
| ISourceRange selection= TextRangeUtil.getSelection(cu, startLine, startColumn, endLine, endColumn); |
| failTestHelper(newName, updateReferences, cu, selection); |
| } |
| |
| private void failTestHelper(String newName, boolean updateReferences, ICompilationUnit cu, ISourceRange selection) throws Exception { |
| RenameTempRefactoring ref= RenameTempRefactoring.create(cu, selection.getOffset(), selection.getLength()); |
| ref.setUpdateReferences(updateReferences); |
| ref.setNewElementName(newName); |
| |
| RefactoringStatus result= performRefactoring(ref); |
| assertNotNull("precondition was supposed to fail", result); |
| } |
| |
| private void helper2(String newName) throws Exception{ |
| helper2(newName, true); |
| } |
| |
| public void test0() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test1() throws Exception{ |
| helper1("j"); |
| } |
| |
| // public void test2() throws Exception{ |
| // Map renaming= new HashMap(); |
| // renaming.put("x", "j"); |
| // renaming.put("y", "k"); |
| // helper1(renaming, new String[0]); |
| // } |
| |
| public void test3() throws Exception{ |
| helper1("j1"); |
| } |
| |
| public void test4() throws Exception{ |
| helper1("k"); |
| } |
| |
| public void test5() throws Exception{ |
| helper1("k"); |
| } |
| |
| public void test6() throws Exception{ |
| helper1("k"); |
| } |
| |
| public void test7() throws Exception{ |
| helper1("k"); |
| } |
| // |
| // //8, 9, 10 removed |
| // |
| // |
| public void test11() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test12() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test13() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test14() throws Exception{ |
| helper1("j"); |
| } |
| |
| // disabled |
| // public void test15() throws Exception{ |
| // Map renaming= new HashMap(); |
| // renaming.put("i", "j"); |
| // renaming.put("j", "i"); |
| // helper1(renaming, new String[0]); |
| // } |
| // |
| public void test16() throws Exception{ |
| helper1("j"); |
| } |
| |
| // disabled |
| // public void test17() throws Exception{ |
| // Map renaming= new HashMap(); |
| // renaming.put("i", "j"); |
| // renaming.put("j", "i"); |
| // helper1(renaming, new String[0]); |
| // } |
| // |
| public void test18() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test19() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test20() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test21() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test22() throws Exception{ |
| helper1("j"); |
| } |
| |
| // disabled |
| // public void test23() throws Exception{ |
| // Map renaming= new HashMap(); |
| // renaming.put("i", "j"); |
| // renaming.put("j", "i"); |
| // helper1(renaming, new String[0]); |
| // } |
| |
| public void test24() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test25() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test26() throws Exception{ |
| helper1("j"); |
| } |
| |
| // deleted - incorrect. see testFail26 |
| // public void test27() throws Exception{ |
| // helper1("j"); |
| // } |
| |
| public void test28() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test29() throws Exception{ |
| helper1("b"); |
| } |
| |
| public void test30() throws Exception{ |
| helper1("k"); |
| } |
| |
| public void test31() throws Exception{ |
| helper1("kk"); |
| } |
| |
| public void test32() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test33() throws Exception{ |
| helper1("b", false); |
| } |
| |
| public void test34() throws Exception{ |
| helper1("j"); |
| } |
| |
| public void test35() throws Exception{ |
| // printTestDisabledMessage("regression test for bug#9001"); |
| helper1("test2"); |
| } |
| |
| public void test36() throws Exception{ |
| // printTestDisabledMessage("regression test for bug#7630"); |
| helper1("j", true, 5, 13, 5, 14); |
| } |
| |
| public void test37() throws Exception{ |
| // printTestDisabledMessage("regression test for bug#7630"); |
| helper1("j", true, 5, 16, 5, 17); |
| } |
| |
| public void test38() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#11453"); |
| helper1("i", true, 7, 12, 7, 13); |
| } |
| |
| public void test39() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#11440"); |
| helper1("j", true, 7, 16, 7, 18); |
| } |
| |
| public void test40() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#10660"); |
| helper1("j", true, 4, 12, 4, 17); |
| } |
| |
| public void test41() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#10660"); |
| helper1("j", true, 3, 13, 3, 18); |
| } |
| |
| public void test42() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#10660"); |
| helper1("j", true, 3, 25, 3, 26); |
| } |
| |
| public void test43() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#10660"); |
| helper1("j", true, 4, 19, 4, 24); |
| } |
| |
| public void test44() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#12200"); |
| helper1("j", true, 6, 11, 6, 14); |
| } |
| |
| public void test45() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#12210"); |
| helper1("j", true, 4, 14, 4, 14); |
| } |
| |
| public void test46() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#12210"); |
| helper1("j", true, 5, 18, 5, 18); |
| } |
| |
| public void test47() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#17922"); |
| helper1("newname", true, 7, 13, 7, 17); |
| } |
| |
| public void test48() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#22938"); |
| helper1("newname", true, 4, 16, 4, 20); |
| } |
| |
| public void test49() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#30923 "); |
| helper1("newname", true, 4, 16, 4, 20); |
| } |
| |
| public void test50() throws Exception{ |
| // printTestDisabledMessage("regression test for Bug#30923 "); |
| helper1("newname", true, 4, 16, 4, 20); |
| } |
| |
| public void test51() throws Exception { |
| // printTestDisabledMessage("regression test for Bug#47822"); |
| helper1("qwerty", true, 5, 19, 5, 20); |
| } |
| |
| // ----- |
| public void testFail0() throws Exception{ |
| printTestDisabledMessage("fails - must revisit"); |
| // helper2("j"); |
| } |
| |
| public void testFail1() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail2() throws Exception{ |
| helper2("i"); |
| } |
| |
| public void testFail3() throws Exception{ |
| helper2("9"); |
| } |
| |
| public void testFail4() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail5() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail6() throws Exception{ |
| printTestDisabledMessage("fails - must revisit"); |
| // helper2("j"); |
| } |
| |
| public void testFail7() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail8() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail9() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail10() throws Exception{ |
| helper2("uu"); |
| } |
| |
| // disabled - it's allowed now |
| // public void testFail11() throws Exception{ |
| // helper2("uu"); |
| // } |
| |
| public void testFail12() throws Exception{ |
| // printTestDisabledMessage("http://dev.eclipse.org/bugs/show_bug.cgi?id=11638"); |
| helper2("j"); |
| } |
| |
| public void testFail13() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail14() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail15() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail16() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail17() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail18() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail19() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail20() throws Exception{ |
| helper2("j"); |
| } |
| |
| // disabled - it's allowed now |
| // public void testFail21() throws Exception{ |
| // helper2("j"); |
| // } |
| |
| public void testFail22() throws Exception{ |
| helper2("j"); |
| } |
| |
| // disabled - it's allowed now |
| // public void testFail23() throws Exception{ |
| // helper2("j"); |
| // } |
| |
| public void testFail24() throws Exception{ |
| printTestDisabledMessage("compile errors are ok now"); |
| //helper2("j"); |
| } |
| |
| public void testFail25() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail26() throws Exception{ |
| printTestDisabledMessage("Test disable until it is clear how 1.4 treats this"); |
| // helper2("j"); |
| } |
| |
| public void testFail27() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail28() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail29() throws Exception{ |
| helper2("j"); |
| } |
| |
| public void testFail30() throws Exception{ |
| // printTestDisabledMessage("bug#19851"); |
| helper2("j"); |
| } |
| public void testFail31() throws Exception{ |
| helper2("j", true, 3, 9, 3, 13); |
| } |
| |
| public void testFail32() throws Exception { |
| // printTestDisabledMessage("bug#47822"); |
| helper2("j", true, 6, 19, 6, 20); |
| } |
| } |