| /* |
| * Copyright 2000-2011 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 com.intellij.refactoring; |
| |
| import com.intellij.codeInsight.template.impl.TemplateManagerImpl; |
| import com.intellij.codeInsight.template.impl.TemplateState; |
| import com.intellij.openapi.util.Pass; |
| import com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer; |
| import com.intellij.testFramework.LightPlatformCodeInsightTestCase; |
| |
| /** |
| * User: anna |
| * Date: 8/25/11 |
| */ |
| public abstract class AbstractInplaceIntroduceTest extends LightPlatformCodeInsightTestCase { |
| |
| protected abstract String getBasePath(); |
| |
| protected void doTestEscape() { |
| String name = getTestName(true); |
| configureByFile(getBasePath() + name + getExtension()); |
| final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); |
| try { |
| TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); |
| getEditor().getSettings().setVariableInplaceRenameEnabled(true); |
| |
| invokeRefactoring(); |
| TemplateState state = TemplateManagerImpl.getTemplateState(getEditor()); |
| assert state != null; |
| state.gotoEnd(true); |
| checkResultByFile(getBasePath() + name + "_after" + getExtension()); |
| } |
| finally { |
| getEditor().getSettings().setVariableInplaceRenameEnabled(enabled); |
| } |
| } |
| |
| protected abstract String getExtension(); |
| |
| protected void doTest(final Pass<AbstractInplaceIntroducer> pass) { |
| String name = getTestName(true); |
| configureByFile(getBasePath() + name + getExtension()); |
| final boolean enabled = getEditor().getSettings().isVariableInplaceRenameEnabled(); |
| try { |
| TemplateManagerImpl.setTemplateTesting(getProject(), getTestRootDisposable()); |
| getEditor().getSettings().setVariableInplaceRenameEnabled(true); |
| |
| final AbstractInplaceIntroducer introducer = invokeRefactoring(); |
| pass.pass(introducer); |
| TemplateState state = TemplateManagerImpl.getTemplateState(getEditor()); |
| assert state != null; |
| state.gotoEnd(false); |
| checkResultByFile(getBasePath() + name + "_after" + getExtension()); |
| } |
| finally { |
| getEditor().getSettings().setVariableInplaceRenameEnabled(enabled); |
| } |
| } |
| |
| protected abstract AbstractInplaceIntroducer invokeRefactoring(); |
| |
| @Override |
| protected boolean isRunInWriteAction() { |
| return false; |
| } |
| } |