Implement "Safe Delete" refactoring for classes and objects
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.safeDelete;
|
||||
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.LangDataKeys;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor;
|
||||
import com.intellij.refactoring.safeDelete.SafeDeleteHandler;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetElement;
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclarationName;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class AbstractJetSafeDeleteTest extends LightCodeInsightTestCase {
|
||||
public void doClassTest(@NotNull String path) throws Exception {
|
||||
doTest(path, JetClass.class);
|
||||
}
|
||||
|
||||
public void doObjectTest(@NotNull String path) throws Exception {
|
||||
doTest(path, JetObjectDeclarationName.class);
|
||||
}
|
||||
|
||||
private <T extends JetElement> void doTest(@NotNull String path, @NotNull Class<T> elementClass) throws Exception {
|
||||
configureByFile(path);
|
||||
|
||||
DataContext dataContext = getCurrentEditorDataContext();
|
||||
PsiElement element = PsiTreeUtil.getParentOfType(LangDataKeys.PSI_ELEMENT.getData(dataContext), elementClass, false);
|
||||
|
||||
try {
|
||||
new SafeDeleteHandler().invoke(getProject(), new PsiElement[] {element}, dataContext);
|
||||
checkResultByFile(path + ".after");
|
||||
}
|
||||
catch (BaseRefactoringProcessor.ConflictsInTestsException e) {
|
||||
List<String> messages = new ArrayList<String>(e.getMessages());
|
||||
Collections.sort(messages);
|
||||
|
||||
File messageFile = new File(path + ".messages");
|
||||
String expectedMessage = FileUtil.loadFile(messageFile, CharsetToolkit.UTF8, true);
|
||||
assertEquals(expectedMessage, StringUtil.join(messages, "\n"));
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
* Copyright 2010-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.jetbrains.jet.safeDelete;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.regex.Pattern;
|
||||
import org.jetbrains.jet.JetTestUtils;
|
||||
import org.jetbrains.jet.test.InnerTestClasses;
|
||||
import org.jetbrains.jet.test.TestMetadata;
|
||||
|
||||
import org.jetbrains.jet.safeDelete.AbstractJetSafeDeleteTest;
|
||||
|
||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
|
||||
@SuppressWarnings("all")
|
||||
@InnerTestClasses({JetSafeDeleteTestGenerated.DeleteClass.class, JetSafeDeleteTestGenerated.DeleteObject.class})
|
||||
public class JetSafeDeleteTestGenerated extends AbstractJetSafeDeleteTest {
|
||||
@TestMetadata("idea/testData/safeDelete/deleteClass")
|
||||
public static class DeleteClass extends AbstractJetSafeDeleteTest {
|
||||
public void testAllFilesPresentInDeleteClass() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/safeDelete/deleteClass"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("class1.kt")
|
||||
public void testClass1() throws Exception {
|
||||
doClassTest("idea/testData/safeDelete/deleteClass/class1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("class2.kt")
|
||||
public void testClass2() throws Exception {
|
||||
doClassTest("idea/testData/safeDelete/deleteClass/class2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClass1.kt")
|
||||
public void testNestedClass1() throws Exception {
|
||||
doClassTest("idea/testData/safeDelete/deleteClass/nestedClass1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedClass2.kt")
|
||||
public void testNestedClass2() throws Exception {
|
||||
doClassTest("idea/testData/safeDelete/deleteClass/nestedClass2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noUsages.kt")
|
||||
public void testNoUsages() throws Exception {
|
||||
doClassTest("idea/testData/safeDelete/deleteClass/noUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("trait1.kt")
|
||||
public void testTrait1() throws Exception {
|
||||
doClassTest("idea/testData/safeDelete/deleteClass/trait1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("trait2.kt")
|
||||
public void testTrait2() throws Exception {
|
||||
doClassTest("idea/testData/safeDelete/deleteClass/trait2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeImport.kt")
|
||||
public void testUnsafeImport() throws Exception {
|
||||
doClassTest("idea/testData/safeDelete/deleteClass/unsafeImport.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/safeDelete/deleteObject")
|
||||
public static class DeleteObject extends AbstractJetSafeDeleteTest {
|
||||
public void testAllFilesPresentInDeleteObject() throws Exception {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/safeDelete/deleteObject"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("nestedObject1.kt")
|
||||
public void testNestedObject1() throws Exception {
|
||||
doObjectTest("idea/testData/safeDelete/deleteObject/nestedObject1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("nestedObject2.kt")
|
||||
public void testNestedObject2() throws Exception {
|
||||
doObjectTest("idea/testData/safeDelete/deleteObject/nestedObject2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("noUsages.kt")
|
||||
public void testNoUsages() throws Exception {
|
||||
doObjectTest("idea/testData/safeDelete/deleteObject/noUsages.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("object1.kt")
|
||||
public void testObject1() throws Exception {
|
||||
doObjectTest("idea/testData/safeDelete/deleteObject/object1.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("object2.kt")
|
||||
public void testObject2() throws Exception {
|
||||
doObjectTest("idea/testData/safeDelete/deleteObject/object2.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("unsafeImport.kt")
|
||||
public void testUnsafeImport() throws Exception {
|
||||
doObjectTest("idea/testData/safeDelete/deleteObject/unsafeImport.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test suite() {
|
||||
TestSuite suite = new TestSuite("JetSafeDeleteTestGenerated");
|
||||
suite.addTestSuite(DeleteClass.class);
|
||||
suite.addTestSuite(DeleteObject.class);
|
||||
return suite;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user