Basic local val inlining support.

#KT-2637 in progress
This commit is contained in:
Evgeny Gerashchenko
2013-07-05 22:05:55 +04:00
parent 0126ee4e2a
commit a9a960fd38
18 changed files with 275 additions and 0 deletions
@@ -0,0 +1,41 @@
package org.jetbrains.jet.plugin.refactoring.inline;
import com.intellij.codeInsight.TargetElementUtilBase;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.psi.PsiElement;
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.IOException;
import static com.intellij.codeInsight.TargetElementUtilBase.ELEMENT_NAME_ACCEPTED;
import static com.intellij.codeInsight.TargetElementUtilBase.REFERENCED_ELEMENT_ACCEPTED;
public abstract class AbstractInlineTest extends LightCodeInsightFixtureTestCase {
protected void doTest(@NotNull String path) throws IOException {
File afterFile = new File(path + ".after");
myFixture.configureByFile(path);
boolean afterFileExists = afterFile.exists();
final PsiElement targetElement =
TargetElementUtilBase.findTargetElement(myFixture.getEditor(), ELEMENT_NAME_ACCEPTED | REFERENCED_ELEMENT_ACCEPTED);
final KotlinInlineLocalHandler handler = new KotlinInlineLocalHandler();
assertEquals(afterFileExists, handler.canInlineElement(targetElement));
if (!afterFileExists) {
return;
}
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
handler.inlineElement(myFixture.getProject(), myFixture.getEditor(), targetElement);
}
});
myFixture.checkResult(FileUtil.loadFile(afterFile));
}
}
@@ -0,0 +1,79 @@
/*
* 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.plugin.refactoring.inline;
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.plugin.refactoring.inline.AbstractInlineTest;
/** This class is generated by {@link org.jetbrains.jet.generators.tests.GenerateTests}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("idea/testData/refactoring/inline")
public class InlineTestGenerated extends AbstractInlineTest {
public void testAllFilesPresentInInline() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("idea/testData/refactoring/inline"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("Basic.kt")
public void testBasic() throws Exception {
doTest("idea/testData/refactoring/inline/Basic.kt");
}
@TestMetadata("BasicCaretOnDeclaration.kt")
public void testBasicCaretOnDeclaration() throws Exception {
doTest("idea/testData/refactoring/inline/BasicCaretOnDeclaration.kt");
}
@TestMetadata("InFunctionLiteral.kt")
public void testInFunctionLiteral() throws Exception {
doTest("idea/testData/refactoring/inline/InFunctionLiteral.kt");
}
@TestMetadata("MethodReference.kt")
public void testMethodReference() throws Exception {
doTest("idea/testData/refactoring/inline/MethodReference.kt");
}
@TestMetadata("MultipleUsages.kt")
public void testMultipleUsages() throws Exception {
doTest("idea/testData/refactoring/inline/MultipleUsages.kt");
}
@TestMetadata("Parameter.kt")
public void testParameter() throws Exception {
doTest("idea/testData/refactoring/inline/Parameter.kt");
}
@TestMetadata("ValWithoutInitializer.kt")
public void testValWithoutInitializer() throws Exception {
doTest("idea/testData/refactoring/inline/ValWithoutInitializer.kt");
}
@TestMetadata("Var.kt")
public void testVar() throws Exception {
doTest("idea/testData/refactoring/inline/Var.kt");
}
}