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:35:14 +02:00
parent 5bfc55d380
commit 3f0cc0e68d
14 changed files with 131 additions and 91 deletions

View File

@@ -20,25 +20,26 @@ import com.intellij.codeInsight.completion.simple.ParenthesesTailType;
import com.intellij.codeInsight.completion.simple.RParenthTailType;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
public class TailTypes {
public static final TailType CALL_RPARENTH = new RParenthTailType(){
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && editor.getDocument().getCharsSequence().charAt(tailOffset - 1) != '(';
}
};
public static final TailType IF_RPARENTH = new RParenthTailType(){
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_IF_PARENTHESES;
}
};
public static final TailType WHILE_RPARENTH = new RParenthTailType(){
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_WHILE_PARENTHESES;
}
};
public static final TailType CALL_RPARENTH_SEMICOLON = new RParenthTailType(){
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES;
}
@@ -48,56 +49,56 @@ public class TailTypes {
};
public static final TailType SYNCHRONIZED_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_SYNCHRONIZED_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_SYNCHRONIZED_PARENTHESES;
}
};
public static final TailType CATCH_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_CATCH_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_CATCH_PARENTHESES;
}
};
public static final TailType SWITCH_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_SWITCH_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_SWITCH_PARENTHESES;
}
};
public static final TailType WHILE_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_WHILE_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_WHILE_PARENTHESES;
}
};
public static final TailType FOR_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_FOR_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_FOR_PARENTHESES;
}
};
public static final TailType IF_LPARENTH = new ParenthesesTailType() {
protected boolean isSpaceBeforeParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceBeforeParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_BEFORE_IF_PARENTHESES;
}
protected boolean isSpaceWithinParentheses(final CodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
protected boolean isSpaceWithinParentheses(final CommonCodeStyleSettings styleSettings, final Editor editor, final int tailOffset) {
return styleSettings.SPACE_WITHIN_IF_PARENTHESES;
}
};

View File

@@ -20,8 +20,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.util.ClassConditionKey;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiType;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.Nullable;
/**
@@ -64,7 +63,7 @@ public class CastingLookupElementDecorator extends LookupElementDecorator<Lookup
@Override
public void handleInsert(InsertionContext context) {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(context.getProject());
final CommonCodeStyleSettings settings = context.getCodeStyleSettings();
String spaceWithin = settings.SPACE_WITHIN_CAST_PARENTHESES ? " " : "";
String spaceAfter = settings.SPACE_AFTER_TYPE_CAST ? " " : "";
final Editor editor = context.getEditor();

View File

@@ -27,8 +27,7 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import org.jetbrains.annotations.NotNull;
public class DefaultInsertHandler extends TemplateInsertHandler implements Cloneable {
@@ -94,7 +93,7 @@ public class DefaultInsertHandler extends TemplateInsertHandler implements Clone
}
}
else{
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
final CommonCodeStyleSettings styleSettings = context.getCodeStyleSettings();
myState.tailOffset = context.getSelectionEndOffset();
myState.caretOffset = context.getSelectionEndOffset();

View File

@@ -30,7 +30,10 @@ import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.RangeMarker;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.*;
import com.intellij.openapi.util.Condition;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.NullableLazyKey;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.patterns.PsiJavaPatterns;
@@ -66,7 +69,10 @@ import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import static com.intellij.patterns.PlatformPatterns.psiElement;
@@ -272,7 +278,7 @@ public class JavaCompletionUtil {
if (element instanceof PsiWhiteSpace &&
( !element.textContains('\n') ||
CodeStyleSettingsManager.getInstance(project).getCurrentSettings().METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
CodeStyleSettingsManager.getSettings(project).getCommonSettings(JavaLanguage.INSTANCE).METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE
)
){
element = file.findElementAt(element.getTextRange().getEndOffset());
@@ -541,7 +547,7 @@ public class JavaCompletionUtil {
if (ref != null) {
final PsiElement qualifier = ref.getQualifier();
if (qualifier != null) {
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(qualifier.getProject());
final CommonCodeStyleSettings settings = context.getCodeStyleSettings();
final String parenSpace = settings.SPACE_WITHIN_PARENTHESES ? " " : "";
document.insertString(qualifier.getTextRange().getEndOffset(), parenSpace + ")");
@@ -821,7 +827,7 @@ public class JavaCompletionUtil {
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getDocument());
final CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(context.getProject());
final CommonCodeStyleSettings styleSettings = context.getCodeStyleSettings();
ParenthesesInsertHandler.getInstance(hasParams,
styleSettings.SPACE_BEFORE_METHOD_CALL_PARENTHESES,
styleSettings.SPACE_WITHIN_METHOD_CALL_PARENTHESES && hasParams,

View File

@@ -14,8 +14,7 @@ import com.intellij.openapi.editor.ScrollType;
import com.intellij.patterns.PlatformPatterns;
import com.intellij.patterns.PsiElementPattern;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
import com.intellij.psi.impl.source.tree.java.PsiEmptyExpressionImpl;
import com.intellij.psi.util.PsiTreeUtil;
@@ -100,7 +99,7 @@ class SmartCastProvider extends CompletionProvider<CompletionParameters> {
context.getOffsetMap().getOffset(CompletionInitializationContext.IDENTIFIER_END_OFFSET));
}
final CodeStyleSettings csSettings = CodeStyleSettingsManager.getSettings(context.getProject());
final CommonCodeStyleSettings csSettings = context.getCodeStyleSettings();
final int oldTail = context.getTailOffset();
context.setTailOffset(RParenthTailType.addRParenth(editor, oldTail, csSettings.SPACE_WITHIN_CAST_PARENTHESES));

View File

@@ -18,20 +18,19 @@ package com.intellij.codeInsight.completion.simple;
import com.intellij.codeInsight.TailType;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
/**
* @author peter
*/
public abstract class ParenthesesTailType extends TailType {
protected abstract boolean isSpaceBeforeParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset);
protected abstract boolean isSpaceBeforeParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset);
protected abstract boolean isSpaceWithinParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset);
protected abstract boolean isSpaceWithinParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset);
public int processTail(final Editor editor, int tailOffset) {
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject());
CommonCodeStyleSettings styleSettings = getLocalCodeStyleSettings(editor, tailOffset);
if (isSpaceBeforeParentheses(styleSettings, editor, tailOffset)) {
tailOffset = insertChar(editor, tailOffset, ' ');
}

View File

@@ -24,8 +24,7 @@ import com.intellij.openapi.editor.highlighter.EditorHighlighter;
import com.intellij.openapi.editor.highlighter.HighlighterIterator;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.impl.source.tree.ElementType;
import com.intellij.psi.tree.IElementType;
import com.intellij.psi.tree.java.IJavaElementType;
@@ -50,10 +49,10 @@ public abstract class RParenthTailType extends TailType {
return element == null ? new TextRange(0, document.getTextLength()) : element.getTextRange();
}
protected abstract boolean isSpaceWithinParentheses(CodeStyleSettings styleSettings, Editor editor, final int tailOffset);
protected abstract boolean isSpaceWithinParentheses(CommonCodeStyleSettings styleSettings, Editor editor, final int tailOffset);
public int processTail(final Editor editor, int tailOffset) {
return addRParenth(editor, tailOffset, isSpaceWithinParentheses(CodeStyleSettingsManager.getSettings(editor.getProject()), editor, tailOffset));
return addRParenth(editor, tailOffset, isSpaceWithinParentheses(getLocalCodeStyleSettings(editor, tailOffset), editor, tailOffset));
}
public static int addRParenth(Editor editor, int offset, boolean spaceWithinParens) {

View File

@@ -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>);
}
}

View File

@@ -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>);
}
}

View File

@@ -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;

View File

@@ -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'])

View File

@@ -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);
}
}

View File

@@ -16,11 +16,16 @@
package com.intellij.codeInsight;
import com.intellij.codeInsight.completion.InsertionContext;
import com.intellij.lang.Language;
import com.intellij.openapi.editor.CaretModel;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.util.PsiUtilBase;
import org.jetbrains.annotations.NotNull;
/**
@@ -72,11 +77,11 @@ public abstract class TailType {
};
public static final TailType SEMICOLON = new CharTailType(';');
public static final TailType EXCLAMATION = new CharTailType('!');
@Deprecated public static final TailType EXCLAMATION = new CharTailType('!');
public static final TailType COMMA = new TailType(){
public int processTail(final Editor editor, int tailOffset) {
CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject());
CommonCodeStyleSettings styleSettings = getLocalCodeStyleSettings(editor, tailOffset);
if (styleSettings.SPACE_BEFORE_COMMA) tailOffset = insertChar(editor, tailOffset, ' ');
tailOffset = insertChar(editor, tailOffset, ',');
if (styleSettings.SPACE_AFTER_COMMA) tailOffset = insertChar(editor, tailOffset, ' ');
@@ -87,6 +92,17 @@ public abstract class TailType {
return "COMMA";
}
};
protected static CommonCodeStyleSettings getLocalCodeStyleSettings(Editor editor, int tailOffset) {
Project project = editor.getProject();
assert project != null;
PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
assert psiFile != null;
Language language = PsiUtilBase.getLanguageAtOffset(psiFile, tailOffset);
return CodeStyleSettingsManager.getSettings(project).getCommonSettings(language);
}
/**
* insert a space, overtype if already present
*/

View File

@@ -16,11 +16,15 @@
package com.intellij.codeInsight.completion;
import com.intellij.codeInsight.lookup.LookupElement;
import com.intellij.lang.Language;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDocumentManager;
import com.intellij.psi.PsiFile;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
import com.intellij.psi.util.PsiUtilBase;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -132,4 +136,9 @@ public class InsertionContext {
public boolean shouldAddCompletionChar() {
return myAddCompletionChar;
}
public CommonCodeStyleSettings getCodeStyleSettings() {
Language lang = PsiUtilBase.getLanguageAtOffset(getFile(), getTailOffset());
return CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(lang);
}
}