This commit is contained in:
Roman Shevchenko
2012-07-09 17:48:16 +02:00
parent e912413705
commit 142e9c8c74
3 changed files with 73 additions and 77 deletions
@@ -1,17 +1,32 @@
/*
* @author ven
* Copyright 2000-2012 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.codeInsight;
import com.intellij.codeInsight.generation.ClassMember;
import com.intellij.codeInsight.generation.GenerateConstructorHandler;
import com.intellij.openapi.project.Project;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.testFramework.LightCodeInsightTestCase;
import java.util.List;
/**
* @author ven
*/
public class GenerateConstructorTest extends LightCodeInsightTestCase {
public void testAbstractClass() throws Exception { doTest(); }
public void testPackageLocalClass() throws Exception { doTest(); }
@@ -22,25 +37,22 @@ public class GenerateConstructorTest extends LightCodeInsightTestCase {
public void testNoMoreConstructorsCanBeGenerated() throws Exception { doTest(); }
public void testImmediatelyAfterRBrace() throws Exception { // IDEADEV-28811
final CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
final int old = settings.CLASS_BRACE_STYLE;
settings.CLASS_BRACE_STYLE = CodeStyleSettings.NEXT_LINE;
try {
doTest();
}
finally {
settings.CLASS_BRACE_STYLE = old;
}
}
public void testBoundCommentsKeepsBlankLine() throws Exception {
CodeStyleSettingsManager styleSettingsManager = CodeStyleSettingsManager.getInstance(getProject());
final CodeStyleSettings settings = styleSettingsManager.getCurrentSettings();
settings.BLANK_LINES_AFTER_CLASS_HEADER = 1;
CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().CLASS_BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE;
doTest();
}
public void testFinalFieldPreselection() throws Exception {
public void testBoundCommentsKeepsBlankLine() throws Exception {
CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().BLANK_LINES_AFTER_CLASS_HEADER = 1;
doTest();
}
public void testFinalFieldPreselection() throws Exception { doTest(true); }
private void doTest() throws Exception {
doTest(false);
}
private void doTest(final boolean preSelect) throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/generateConstructor/before" + name + ".java");
new GenerateConstructorHandler() {
@@ -49,30 +61,15 @@ public class GenerateConstructorTest extends LightCodeInsightTestCase {
boolean allowEmptySelection,
boolean copyJavadocCheckbox,
Project project) {
final List<ClassMember> preselection = GenerateConstructorHandler.preselect(members);
return preselection.toArray(new ClassMember[preselection.size()]);
if (preSelect) {
final List<ClassMember> preselection = GenerateConstructorHandler.preselect(members);
return preselection.toArray(new ClassMember[preselection.size()]);
}
else {
return members;
}
}
}.invoke(getProject(), getEditor(), getFile());
checkResultByFile("/codeInsight/generateConstructor/after" + name +".java");
}
private void doTest() throws Exception {
String name = getTestName(false);
configureByFile("/codeInsight/generateConstructor/before" +
name +
".java");
new GenerateConstructorHandler(){
@Override
protected ClassMember[] chooseMembers(ClassMember[] members,
boolean allowEmptySelection,
boolean copyJavadocCheckbox,
Project project) {
return members;
}
}.invoke(getProject(), getEditor(), getFile());
checkResultByFile("/codeInsight/generateConstructor/after" +
name +
".java");
checkResultByFile("/codeInsight/generateConstructor/after" + name + ".java");
}
}