honor per-language code style settings in completion, not the generic ones (IDEA-83382 and more)

This commit is contained in:
peter
2012-04-13 12:36:51 +02:00
parent 5bfc55d380
commit 3f0cc0e68d
14 changed files with 131 additions and 91 deletions
@@ -0,0 +1,9 @@
public static class G {
public static void foo(String s1, String s2) {
}
public static void main(String[] args) {
String sss1 = "text";
foo(sss1,<caret>);
}
}
@@ -0,0 +1,9 @@
public static class G {
public static void foo(String s1, String s2) {
}
public static void main(String[] args) {
String sss1 = "text";
foo(ss<caret>);
}
}
@@ -5,10 +5,11 @@ import com.intellij.codeInsight.lookup.Lookup;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.codeInsight.lookup.LookupManager;
import com.intellij.codeInsight.lookup.impl.LookupManagerImpl;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.roots.LanguageLevelProjectExtension;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.statistics.StatisticsManager;
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
import com.intellij.testFramework.LightCodeInsightTestCase;
@@ -208,8 +209,9 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{
}
public void testParensInSynchronized() throws Exception{
CodeStyleSettingsManager.getSettings(getProject()).SPACE_BEFORE_SYNCHRONIZED_PARENTHESES = false;
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_SYNCHRONIZED_PARENTHESES = true;
CommonCodeStyleSettings styleSettings = getCodeStyleSettings();
styleSettings.SPACE_BEFORE_SYNCHRONIZED_PARENTHESES = false;
styleSettings.SPACE_WITHIN_SYNCHRONIZED_PARENTHESES = true;
final String path = BASE_PATH;
configureByFile(path + "/before22.java");
@@ -254,22 +256,17 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{
public void testCastParensStyle1() throws Exception{
final String path = BASE_PATH;
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
final boolean space_within_cast_parentheses = styleSettings.SPACE_WITHIN_CAST_PARENTHESES;
final boolean space_after_type_cast = styleSettings.SPACE_AFTER_TYPE_CAST;
styleSettings.SPACE_WITHIN_CAST_PARENTHESES = true;
styleSettings.SPACE_AFTER_TYPE_CAST = false;
getCodeStyleSettings().SPACE_WITHIN_CAST_PARENTHESES = true;
getCodeStyleSettings().SPACE_AFTER_TYPE_CAST = false;
configureByFile(path + "/before31.java");
performSmartCompletion();
checkResultByFile(path + "/after31.java");
styleSettings.SPACE_WITHIN_CAST_PARENTHESES = space_within_cast_parentheses;
styleSettings.SPACE_AFTER_TYPE_CAST = space_after_type_cast;
}
public void testMethodParensStyle2() throws Exception{
final String path = BASE_PATH;
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
CommonCodeStyleSettings styleSettings = getCodeStyleSettings();
final boolean space_before_method_call_parentheses = styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES;
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true;
configureByFile(path + "/before32.java");
@@ -278,9 +275,14 @@ public class CompletionStyleTest extends LightCodeInsightTestCase{
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = space_before_method_call_parentheses;
}
private static CommonCodeStyleSettings getCodeStyleSettings() {
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
}
public void testMethodParensStyle3() throws Exception{
final String path = BASE_PATH;
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
CommonCodeStyleSettings styleSettings = getCodeStyleSettings();
final boolean space_before_method_call_parentheses = styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES;
final boolean space_within_method_call_parentheses = styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES;
@@ -22,11 +22,12 @@ import com.intellij.codeInsight.lookup.Lookup
import com.intellij.codeInsight.lookup.LookupElement
import com.intellij.codeInsight.lookup.LookupElementPresentation
import com.intellij.codeInsight.lookup.LookupManager
import com.intellij.lang.java.JavaLanguage
import com.intellij.openapi.actionSystem.IdeActions
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.fileTypes.StdFileTypes
import com.intellij.psi.codeStyle.CodeStyleSettings
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
import com.intellij.psi.codeStyle.CommonCodeStyleSettings
import com.intellij.psi.*
public class NormalCompletionTest extends LightFixtureCompletionTestCase {
@@ -287,12 +288,9 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
}
public void testMethodCallBeforeAnotherStatementWithParen2() throws Exception {
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings();
boolean oldvalue = settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE;
settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
codeStyleSettings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = true;
configureByFile("MethodLookup2.java");
checkResultByFile("MethodLookup2_After2.java");
settings.METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE = oldvalue;
}
public void testSwitchEnumLabel() throws Exception {
@@ -494,16 +492,14 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
public void testPrivateInAnonymous() throws Throwable { doTest() }
public void testMethodParenthesesSpaces() throws Throwable {
final settings = CodeStyleSettingsManager.getSettings(getProject())
settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
doTest();
}
public void testMethodParenthesesSpacesArgs() throws Throwable {
final settings = CodeStyleSettingsManager.getSettings(getProject())
settings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
settings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
codeStyleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES = true
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true
doTest();
}
@@ -601,23 +597,18 @@ public class ListUtils {
}
public void testNoSpaceInParensWithoutParams() throws Throwable {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
try {
doTest();
}
finally {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
}
}
public void testTwoSpacesInParensWithParams() throws Throwable {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
try {
doTest();
}
finally {
CodeStyleSettingsManager.getSettings(getProject()).SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
}
codeStyleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
doTest();
}
public void testFillCommonPrefixOnSecondCompletion() throws Throwable {
@@ -1330,6 +1321,10 @@ public class ListUtils {
public void testInterfaceImplementationNoCast() { doTest() }
public void testStaticallyImportedMethodsBeforeExpression() { doTest() }
private CommonCodeStyleSettings getCodeStyleSettings() {
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
}
public void testCompatibleInterfacesCast() {
configure()
assert myFixture.lookupElementStrings.containsAll(['foo', 'bar'])
@@ -12,10 +12,12 @@ import com.intellij.codeInsight.template.TemplateContextType;
import com.intellij.codeInsight.template.TemplateManager;
import com.intellij.codeInsight.template.impl.TemplateImpl;
import com.intellij.codeInsight.template.impl.TemplateSettings;
import com.intellij.lang.java.JavaLanguage;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.util.containers.ContainerUtil;
public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
@@ -92,15 +94,9 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testParenAfterCall1_SpaceWithinMethodCallParens() throws Exception {
String path = "/parenAfterCall";
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
myFixture.configureByFile(path + "/before1.java");
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
try{
complete();
}
finally{
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
}
getCodeStyleSettings().SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
complete();
checkResultByFile(path + "/after1_space.java");
}
@@ -659,14 +655,8 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
public void testUseIntConstantsInOr() throws Throwable { doTest(); }
public void testExtraSemicolonAfterMethodParam() throws Throwable {
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject());
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
try{
doTest();
}
finally{
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES = false;
}
getCodeStyleSettings().SPACE_WITHIN_METHOD_CALL_PARENTHESES = true;
doTest();
}
public void testAssignFromTheSameFieldOfAnotherObject() throws Throwable {
@@ -1132,7 +1122,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
doTest(Lookup.NORMAL_SELECT_CHAR);
}
private void doTest(final char c) throws Exception {
private void doTest(final char c) {
boolean old = CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION;
if (c != Lookup.NORMAL_SELECT_CHAR) {
CodeInsightSettings.getInstance().AUTOCOMPLETE_ON_SMART_TYPE_COMPLETION = false;
@@ -1173,4 +1163,12 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
}
}
public void testSpaceAfterCommaInMethodCall() {
getCodeStyleSettings().SPACE_AFTER_COMMA = false;
doTest(',');
}
private CommonCodeStyleSettings getCodeStyleSettings() {
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE);
}
}