mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
Detectable indent options provider implementation
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
public class Main {
|
||||
public void main() {
|
||||
try {
|
||||
System.out.println();<caret>
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
public class Main {
|
||||
public void main() {
|
||||
try {
|
||||
System.out.println();
|
||||
<caret>
|
||||
} catch (Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
public class Main {
|
||||
public void main() {
|
||||
try {
|
||||
System.out.println();<caret>
|
||||
} catch (java.lang.Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
public class Main {
|
||||
public void main() {
|
||||
try {
|
||||
System.out.println();
|
||||
<caret>
|
||||
} catch (java.lang.Exception exception) {
|
||||
exception.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Copyright 2000-2014 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.editorActions;
|
||||
|
||||
import com.intellij.psi.codeStyle.autodetect.DetectableIndentOptionsProvider;
|
||||
import com.intellij.testFramework.EditorTestUtil;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
|
||||
/**
|
||||
* @author Rustam Vishnyakov
|
||||
*/
|
||||
public class JavaDetectableIndentsTest extends LightCodeInsightTestCase {
|
||||
private static final String BASE_PATH = "/codeInsight/editorActions/detectableIndents/";
|
||||
|
||||
public void testSpaceIndent() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testTabIndent() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
DetectableIndentOptionsProvider provider = DetectableIndentOptionsProvider.getInstance();
|
||||
assertNotNull("DetectableIndentOptionsProvider not found", provider);
|
||||
String testName = getTestName(true);
|
||||
provider.setEnabledInTest(true);
|
||||
try {
|
||||
configureByFile(BASE_PATH + testName + ".java");
|
||||
EditorTestUtil.performTypingAction(getEditor(), '\n');
|
||||
checkResultByFile(BASE_PATH + testName + "_after.java");
|
||||
}
|
||||
finally {
|
||||
provider.setEnabledInTest(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -22,6 +22,7 @@ import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.FileIndentOptionsProvider;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
@@ -79,7 +80,7 @@ public class FileIndentProviderTest extends LightPlatformCodeInsightFixtureTestC
|
||||
private static class TestIndentOptionsProvider extends FileIndentOptionsProvider {
|
||||
@Nullable
|
||||
@Override
|
||||
public CommonCodeStyleSettings.IndentOptions getIndentOptions(@NotNull PsiFile file) {
|
||||
public CommonCodeStyleSettings.IndentOptions getIndentOptions(@NotNull CodeStyleSettings settings, @NotNull PsiFile file) {
|
||||
return myTestIndentOptions;
|
||||
}
|
||||
|
||||
|
||||
+13
@@ -31,6 +31,7 @@ import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.*;
|
||||
import com.intellij.psi.codeStyle.autodetect.DetectableIndentOptionsProvider;
|
||||
import com.intellij.testFramework.LightIdeaTestCase;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.text.LineReader;
|
||||
@@ -135,6 +136,18 @@ public abstract class AbstractJavaFormatterTest extends LightIdeaTestCase {
|
||||
doTextTest(Action.REFORMAT, loadFile(fileNameBefore), loadFile(fileNameAfter));
|
||||
}
|
||||
|
||||
public void doTestWithDetectableIndentOptions(@NonNls String text, @NonNls String textAfter) {
|
||||
DetectableIndentOptionsProvider provider = DetectableIndentOptionsProvider.getInstance();
|
||||
assertNotNull("DetectableIndentOptionsProvider not found", provider);
|
||||
provider.setEnabledInTest(true);
|
||||
try {
|
||||
doTextTest(text, textAfter);
|
||||
}
|
||||
finally {
|
||||
provider.setEnabledInTest(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void doTextTest(@NonNls final String text, @NonNls String textAfter) throws IncorrectOperationException {
|
||||
doTextTest(Action.REFORMAT, text, textAfter);
|
||||
}
|
||||
|
||||
@@ -3049,4 +3049,44 @@ public void testSCR260() throws Exception {
|
||||
"}"
|
||||
);
|
||||
}
|
||||
|
||||
public void testDetectableIndentOptions() {
|
||||
final String original =
|
||||
"public class Main {\n" +
|
||||
"\tpublic void main() {\n" +
|
||||
"try {\n" +
|
||||
"\t\t\tSystem.out.println();\n" +
|
||||
"\t} catch (java.lang.Exception exception) {\n" +
|
||||
"\t\t\texception.printStackTrace();\n" +
|
||||
"\t}\n" +
|
||||
"}\n" +
|
||||
"}";
|
||||
// Enabled but full reformat (no detection)
|
||||
doTestWithDetectableIndentOptions(
|
||||
original,
|
||||
"public class Main {\n" +
|
||||
" public void main() {\n" +
|
||||
" try {\n" +
|
||||
" System.out.println();\n" +
|
||||
" } catch (java.lang.Exception exception) {\n" +
|
||||
" exception.printStackTrace();\n" +
|
||||
" }\n" +
|
||||
" }\n" +
|
||||
"}"
|
||||
);
|
||||
// Reformat with a smaller text range (detection is on)
|
||||
myTextRange = new TextRange(1, original.length());
|
||||
doTestWithDetectableIndentOptions(
|
||||
original,
|
||||
"public class Main {\n" +
|
||||
"\tpublic void main() {\n" +
|
||||
"\t\ttry {\n" +
|
||||
"\t\t\tSystem.out.println();\n" +
|
||||
"\t\t} catch (java.lang.Exception exception) {\n" +
|
||||
"\t\t\texception.printStackTrace();\n" +
|
||||
"\t\t}\n" +
|
||||
"\t}\n" +
|
||||
"}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user