mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-09 20:42:52 +07:00
corrected tests, insert spaces after '=' only if it should be there according to settings
This commit is contained in:
@@ -31,6 +31,7 @@ public class JavaReformatOnTypingTest extends LightPlatformCodeInsightFixtureTes
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
AutoFormatTypedHandler.setEnabledInTests(true);
|
||||
useSpacesAroundAssignmentOperator(true, myFixture.getProject(), JavaLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -41,21 +42,27 @@ public class JavaReformatOnTypingTest extends LightPlatformCodeInsightFixtureTes
|
||||
}
|
||||
|
||||
private static void useSpacesAroundAssignmentOperator(boolean value, Project project, Language language) {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getInstance(project).getCurrentSettings();
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project);
|
||||
CommonCodeStyleSettings common = settings.getCommonSettings(language);
|
||||
common.SPACE_AROUND_ASSIGNMENT_OPERATORS = value;
|
||||
}
|
||||
|
||||
public void test_DoNotInsertSpaceIfSettingDisabled() {
|
||||
useSpacesAroundAssignmentOperator(false, myFixture.getProject(), JavaLanguage.INSTANCE);
|
||||
doTest("class T { int<caret> }", "=", "class T { int=<caret> }");
|
||||
}
|
||||
|
||||
public void test_DoNotInsertAfterIfSettingDisabled() {
|
||||
useSpacesAroundAssignmentOperator(false, myFixture.getProject(), JavaLanguage.INSTANCE);
|
||||
doTest("class T { int a=<caret> }", "2", "class T { int a=2 }");
|
||||
}
|
||||
|
||||
public void test_AddSpacesAroundAssignmentOperator() throws Exception {
|
||||
doTest("class T { int<caret> }", "=", "class T { int =<caret> }");
|
||||
}
|
||||
|
||||
public void test_IgnoreSpacePressedAfterAssignmentOperator() {
|
||||
useSpacesAroundAssignmentOperator(true, myFixture.getProject(), JavaLanguage.INSTANCE);
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, "class T { int<caret> }");
|
||||
myFixture.type('=');
|
||||
myFixture.type(' ');
|
||||
myFixture.checkResult("class T { int = <caret> }");
|
||||
doTest("class T { int<caret> }", "= ", "class T { int = <caret> }");
|
||||
}
|
||||
|
||||
public void test_DoNotInsertDoubleSpaceBeforeAssignment() {
|
||||
@@ -63,11 +70,7 @@ public class JavaReformatOnTypingTest extends LightPlatformCodeInsightFixtureTes
|
||||
}
|
||||
|
||||
public void test_DoNotInsertDoubleSpaceAnywhere() {
|
||||
useSpacesAroundAssignmentOperator(true, myFixture.getProject(), JavaLanguage.INSTANCE);
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, "class T { int <caret> }");
|
||||
myFixture.type('=');
|
||||
myFixture.type(' ');
|
||||
myFixture.checkResult("class T { int = <caret> }");
|
||||
doTest("class T { int <caret> }", "= ", "class T { int = <caret> }");
|
||||
}
|
||||
|
||||
public void test_DoNotInsertSpaceIfNotAssignment() {
|
||||
@@ -89,7 +92,6 @@ public class JavaReformatOnTypingTest extends LightPlatformCodeInsightFixtureTes
|
||||
}
|
||||
|
||||
private void doTest(String before, String typing, String after) {
|
||||
useSpacesAroundAssignmentOperator(true, myFixture.getProject(), JavaLanguage.INSTANCE);
|
||||
myFixture.configureByText(JavaFileType.INSTANCE, before);
|
||||
myFixture.type(typing);
|
||||
myFixture.checkResult(after);
|
||||
|
||||
+8
-6
@@ -70,12 +70,14 @@ public class AutoFormatTypedHandler extends TypedActionHandlerBase {
|
||||
Document document = editor.getDocument();
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
CharSequence text = document.getImmutableCharSequence();
|
||||
|
||||
if (charTyped == '=' && isSpaceAroundAssignment(editor, dataContext) && shouldInsertBefore(caretOffset, text)) {
|
||||
EditorModificationUtil.insertStringAtCaret(editor, " ");
|
||||
}
|
||||
if (isSameDocumentAsPrevious(editor) && myLastTypedChar == '=' && charTyped != '=' && charTyped != ' ') {
|
||||
EditorModificationUtil.insertStringAtCaret(editor, " ");
|
||||
|
||||
if (isSpaceAroundAssignment(editor, dataContext)) {
|
||||
if (charTyped == '=' && shouldInsertBefore(caretOffset, text)) {
|
||||
EditorModificationUtil.insertStringAtCaret(editor, " ");
|
||||
}
|
||||
else if (isSameDocumentAsPrevious(editor) && myLastTypedChar == '=' && charTyped != '=' && charTyped != ' ') {
|
||||
EditorModificationUtil.insertStringAtCaret(editor, " ");
|
||||
}
|
||||
}
|
||||
|
||||
executeOriginalHandler(editor, charTyped, dataContext);
|
||||
|
||||
Reference in New Issue
Block a user