mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
removed unnecessary store/restore code style settings in tests because they're dropped automatically
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.codeInsight.AnnotationUtil;
|
||||
import com.intellij.codeInsight.ExternalAnnotationsListener;
|
||||
import com.intellij.codeInsight.ExternalAnnotationsManager;
|
||||
@@ -72,12 +71,11 @@ public class AddAnnotationFixTest extends UsefulTestCase {
|
||||
myModule = builder.getFixture().getModule();
|
||||
myProject = myFixture.getProject();
|
||||
|
||||
CodeStyle.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = true;
|
||||
JavaCodeStyleSettings.getInstance(myProject).USE_EXTERNAL_ANNOTATIONS = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CodeStyle.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = false;
|
||||
try {
|
||||
myFixture.tearDown();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.JavaModuleExternalPaths;
|
||||
import com.intellij.openapi.roots.ModuleRootModificationUtil;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
|
||||
@@ -55,12 +54,11 @@ public class ExternalAnnotationsTest extends UsefulTestCase {
|
||||
|
||||
myProject = myFixture.getProject();
|
||||
|
||||
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = true;
|
||||
JavaCodeStyleSettings.getInstance(myProject).USE_EXTERNAL_ANNOTATIONS = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class).USE_EXTERNAL_ANNOTATIONS = false;
|
||||
try {
|
||||
myFixture.tearDown();
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ public class GenerateConstructorTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@NotNull
|
||||
private JavaCodeStyleSettings getJavaSettings() {
|
||||
return CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class);
|
||||
return JavaCodeStyleSettings.getInstance(getProject());
|
||||
}
|
||||
|
||||
public void testFieldPrefixCoincidence1() {
|
||||
|
||||
@@ -69,17 +69,15 @@ public abstract class GenerateEqualsTestCase extends LightCodeInsightTestCase {
|
||||
boolean insertOverride,
|
||||
boolean useAccessors) {
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(getProject()).clone();
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS = true;
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION = insertOverride;
|
||||
CodeStyle.doWithTemporarySettings(getProject(), settings, () -> {
|
||||
PsiElement element = getFile().findElementAt(getEditor().getCaretModel().getOffset());
|
||||
if (element == null) return;
|
||||
PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
|
||||
if (aClass == null) return;
|
||||
PsiField[] fields = aClass.getFields();
|
||||
new GenerateEqualsHelper(getProject(), aClass, equals.fun(fields), hashCode.fun(fields), nonNull.fun(fields), false, useAccessors).invoke();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
});
|
||||
JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_LOCALS = true;
|
||||
JavaCodeStyleSettings.getInstance(getProject()).INSERT_OVERRIDE_ANNOTATION = insertOverride;
|
||||
PsiElement element = getFile().findElementAt(getEditor().getCaretModel().getOffset());
|
||||
if (element == null) return;
|
||||
PsiClass aClass = PsiTreeUtil.getParentOfType(element, PsiClass.class);
|
||||
if (aClass == null) return;
|
||||
PsiField[] fields = aClass.getFields();
|
||||
new GenerateEqualsHelper(getProject(), aClass, equals.fun(fields), hashCode.fun(fields), nonNull.fun(fields), false, useAccessors).invoke();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
|
||||
private static PsiField[] getIndexed(PsiField[] fields, int[] indices) {
|
||||
|
||||
+1
-8
@@ -21,7 +21,6 @@ import com.intellij.codeInsight.generation.GenerateSetterHandler
|
||||
import com.intellij.codeInsight.generation.SetterTemplatesManager
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.util.ui.UIUtil
|
||||
@@ -127,9 +126,7 @@ class X<T extends String> {
|
||||
}
|
||||
|
||||
void "test strip field prefix"() {
|
||||
def settings = CodeStyleSettingsManager.getInstance(getProject()).currentSettings.getCustomSettings(JavaCodeStyleSettings.class)
|
||||
String oldPrefix = settings.FIELD_NAME_PREFIX
|
||||
try {
|
||||
def settings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
settings.FIELD_NAME_PREFIX = "my"
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class Foo {
|
||||
@@ -148,10 +145,6 @@ class X<T extends String> {
|
||||
}
|
||||
}
|
||||
'''
|
||||
}
|
||||
finally {
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix
|
||||
}
|
||||
}
|
||||
|
||||
void "test qualified this"() {
|
||||
|
||||
+16
-35
@@ -75,47 +75,28 @@ public class OverrideImplement15Test extends LightCodeInsightTestCase {
|
||||
public void testRawInheritanceWithMethodTypeParameters() { doTest(false); }
|
||||
|
||||
public void testLongFinalParameterList() {
|
||||
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
try {
|
||||
CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.RIGHT_MARGIN = 80;
|
||||
javaSettings.KEEP_LINE_BREAKS = true;
|
||||
codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS = true;
|
||||
javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
|
||||
doTest(false);
|
||||
}
|
||||
finally {
|
||||
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
|
||||
}
|
||||
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.RIGHT_MARGIN = 80;
|
||||
javaSettings.KEEP_LINE_BREAKS = true;
|
||||
JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_PARAMETERS = true;
|
||||
javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testOverridingLibraryFunctionWithConfiguredParameterPrefix() {
|
||||
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
try {
|
||||
codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).PARAMETER_NAME_PREFIX = "in";
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
|
||||
doTest(false);
|
||||
}
|
||||
finally {
|
||||
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
|
||||
}
|
||||
JavaCodeStyleSettings.getInstance(getProject()).PARAMETER_NAME_PREFIX = "in";
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testLongParameterList() {
|
||||
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
try {
|
||||
CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.RIGHT_MARGIN = 80;
|
||||
javaSettings.KEEP_LINE_BREAKS = false;
|
||||
codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS = false;
|
||||
javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(codeStyleSettings);
|
||||
doTest(false);
|
||||
}
|
||||
finally {
|
||||
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
|
||||
}
|
||||
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaSettings = codeStyleSettings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.RIGHT_MARGIN = 80;
|
||||
javaSettings.KEEP_LINE_BREAKS = false;
|
||||
JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_PARAMETERS = false;
|
||||
javaSettings.METHOD_PARAMETERS_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM;
|
||||
doTest(false);
|
||||
}
|
||||
|
||||
public void testImplementedConstructorsExcluded() {
|
||||
|
||||
@@ -29,7 +29,6 @@ import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
|
||||
@@ -93,15 +92,9 @@ public class SuppressExternalTest extends UsefulTestCase {
|
||||
final IntentionAction action = myFixture.getAvailableIntention("Suppress for method", "src/suppressed/" + testName + ".java");
|
||||
assertNotNull(action);
|
||||
Project project = myFixture.getProject();
|
||||
JavaCodeStyleSettings javaSettings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
boolean oldUseExternalAnnotations = javaSettings.USE_EXTERNAL_ANNOTATIONS;
|
||||
try {
|
||||
javaSettings.USE_EXTERNAL_ANNOTATIONS = true;
|
||||
myFixture.launchAction(action);
|
||||
}
|
||||
finally {
|
||||
javaSettings.USE_EXTERNAL_ANNOTATIONS = oldUseExternalAnnotations;
|
||||
}
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(project);
|
||||
javaSettings.USE_EXTERNAL_ANNOTATIONS = true;
|
||||
myFixture.launchAction(action);
|
||||
myFixture.checkResultByFile("content/anno/suppressed/annotations.xml", "content/anno/suppressed/annotations" + testName + "_after.xml", true);
|
||||
}
|
||||
|
||||
|
||||
+1
-12
@@ -27,8 +27,6 @@ import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiReference
|
||||
import com.intellij.psi.PsiReferenceBase
|
||||
import com.intellij.psi.PsiReferenceProvider
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
|
||||
import com.intellij.psi.impl.source.resolve.reference.PsiReferenceRegistrarImpl
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry
|
||||
@@ -37,12 +35,10 @@ import com.intellij.util.ObjectUtils
|
||||
import com.intellij.util.ProcessingContext
|
||||
import com.intellij.util.SystemProperties
|
||||
import org.jetbrains.annotations.NotNull
|
||||
|
||||
/**
|
||||
* @author mike
|
||||
*/
|
||||
class JavadocCompletionTest extends LightFixtureCompletionTestCase {
|
||||
private CodeStyleSettings settings
|
||||
private JavaCodeStyleSettings javaSettings
|
||||
|
||||
@Override
|
||||
@@ -53,17 +49,10 @@ class JavadocCompletionTest extends LightFixtureCompletionTestCase {
|
||||
@Override
|
||||
protected void setUp() {
|
||||
super.setUp()
|
||||
settings = CodeStyleSettingsManager.getSettings(getProject())
|
||||
javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class)
|
||||
javaSettings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
myFixture.enableInspections(new JavaDocLocalInspection())
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() {
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_IF_NOT_IMPORTED
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
void testNamesInPackage() {
|
||||
myFixture.configureFromExistingVirtualFile(myFixture.copyFileToProject("package-info.java", "p/package-info.java"))
|
||||
complete()
|
||||
|
||||
+1
-6
@@ -176,18 +176,13 @@ class NormalCompletionTest extends NormalCompletionTestCase {
|
||||
|
||||
LookupManager.getInstance(getProject()).hideActiveLookup()
|
||||
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).PREFER_LONGER_NAMES = false
|
||||
try{
|
||||
JavaCodeStyleSettings.getInstance(getProject()).PREFER_LONGER_NAMES = false
|
||||
configureByFile("PreferLongerNamesOption.java")
|
||||
|
||||
assertEquals(3, myItems.length)
|
||||
assertEquals("ijk", myItems[0].getLookupString())
|
||||
assertEquals("efghIjk", myItems[1].getLookupString())
|
||||
assertEquals("abcdEfghIjk", myItems[2].getLookupString())
|
||||
}
|
||||
finally{
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).PREFER_LONGER_NAMES = true
|
||||
}
|
||||
}
|
||||
|
||||
void testSCR7208() throws Exception {
|
||||
|
||||
+4
-9
@@ -847,7 +847,7 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testInsertOverride() {
|
||||
JavaCodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings styleSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
styleSettings.INSERT_OVERRIDE_ANNOTATION = true;
|
||||
doItemTest();
|
||||
}
|
||||
@@ -1133,15 +1133,10 @@ public class SmartTypeCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
public void testInnerClassImports() {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
try {
|
||||
myFixture.addClass("package java.awt.geom; public class Point2D { public static class Double {} }");
|
||||
doActionTest();
|
||||
}
|
||||
finally {
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = false;
|
||||
}
|
||||
myFixture.addClass("package java.awt.geom; public class Point2D { public static class Double {} }");
|
||||
doActionTest();
|
||||
}
|
||||
|
||||
public void testCastWithGenerics() {
|
||||
|
||||
+4
-20
@@ -18,7 +18,6 @@ package com.intellij.java.codeInsight.completion
|
||||
import com.intellij.JavaTestUtil
|
||||
import com.intellij.codeInsight.completion.LightFixtureCompletionTestCase
|
||||
import com.intellij.ide.highlighter.JavaFileType
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings
|
||||
|
||||
class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
@@ -120,33 +119,23 @@ class VariablesCompletionTest extends LightFixtureCompletionTestCase {
|
||||
}
|
||||
|
||||
void testFieldNameCompletion1() throws Exception {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class)
|
||||
String oldPrefix = settings.FIELD_NAME_PREFIX
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
settings.FIELD_NAME_PREFIX = "my"
|
||||
try {
|
||||
doSelectTest("FieldNameCompletion1.java", "FieldNameCompletion1-result.java")
|
||||
}
|
||||
finally {
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix
|
||||
}
|
||||
}
|
||||
|
||||
void testFieldNameCompletion2() throws Exception {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class)
|
||||
String oldPrefix = settings.FIELD_NAME_PREFIX
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
settings.FIELD_NAME_PREFIX = "my"
|
||||
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion2.java")
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion2-result.java")
|
||||
}
|
||||
|
||||
void testFieldNameCompletion3() throws Exception {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class)
|
||||
String oldPrefix = settings.FIELD_NAME_PREFIX
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
settings.FIELD_NAME_PREFIX = "my"
|
||||
configureByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion3.java")
|
||||
complete()
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix
|
||||
checkResultByFile(FILE_PREFIX + "locals/" + "FieldNameCompletion3-result.java")
|
||||
}
|
||||
|
||||
@@ -244,17 +233,12 @@ class Foo {
|
||||
}
|
||||
|
||||
void testConstructorParameterNameWithPrefix() {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(project).getCustomSettings(JavaCodeStyleSettings.class)
|
||||
String oldField = settings.FIELD_NAME_PREFIX
|
||||
String oldParam = settings.PARAMETER_NAME_PREFIX
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject())
|
||||
settings.FIELD_NAME_PREFIX = "my"
|
||||
settings.PARAMETER_NAME_PREFIX = "p"
|
||||
|
||||
configure()
|
||||
|
||||
settings.FIELD_NAME_PREFIX = oldField
|
||||
settings.PARAMETER_NAME_PREFIX = oldParam
|
||||
|
||||
assertStringItems("pColor")
|
||||
}
|
||||
|
||||
|
||||
@@ -52,23 +52,11 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 100;
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
|
||||
JavaCodeStyleSettings.getInstance(getProject()).CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 100;
|
||||
DaemonCodeAnalyzer.getInstance(getProject()).setUpdateByTimerEnabled(false);
|
||||
enableInspectionTool(new UnusedImportInspection());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@WrapInCommand
|
||||
public void testImportsInsertedAlphabetically() {
|
||||
@NonNls String text = "class I {}";
|
||||
@@ -130,8 +118,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
getProject(), () -> ApplicationManager.getApplication().runWriteAction(() -> {
|
||||
try {
|
||||
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
|
||||
PackageEntryTable table = new PackageEntryTable();
|
||||
table.addEntry(PackageEntry.ALL_OTHER_IMPORTS_ENTRY);
|
||||
@@ -143,8 +130,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
table.addEntry(PackageEntry.BLANK_LINE_ENTRY);
|
||||
table.addEntry(PackageEntry.ALL_OTHER_STATIC_IMPORTS_ENTRY);
|
||||
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).IMPORT_LAYOUT_TABLE.copyFrom(table);
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
|
||||
JavaCodeStyleSettings.getInstance(getProject()).IMPORT_LAYOUT_TABLE.copyFrom(table);
|
||||
JavaCodeStyleManager.getInstance(getProject()).optimizeImports(file);
|
||||
|
||||
assertOrder(file, "java.awt.*", CommonClassNames.JAVA_UTIL_MAP, "static java.lang.Math.max", "static java.lang.Math.min",
|
||||
@@ -186,9 +172,7 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
configureByFile(path + "/x/Usage.java", path);
|
||||
assertEmpty(highlightErrors());
|
||||
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 2;
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
|
||||
JavaCodeStyleSettings.getInstance(getProject()).CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 2;
|
||||
WriteCommandAction.runWriteCommandAction(getProject(),
|
||||
() -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile()));
|
||||
|
||||
@@ -482,13 +466,11 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
configureByFile(path + "/foo/A.java", path);
|
||||
assertEmpty(highlightErrors());
|
||||
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
|
||||
javaSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 3;
|
||||
javaSettings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 3;
|
||||
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
|
||||
WriteCommandAction.runWriteCommandAction(getProject(), () -> JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile()));
|
||||
|
||||
assertEmpty(highlightErrors());
|
||||
|
||||
+2
-17
@@ -16,32 +16,17 @@
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import org.jdom.Element;
|
||||
|
||||
/**
|
||||
* @author ven
|
||||
*/
|
||||
public class AssignFieldFromParameterTest extends LightIntentionActionTestCase {
|
||||
private Element myOldSettings;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
myOldSettings = new Element("dummy2");
|
||||
settings.writeExternal(myOldSettings);
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).FIELD_NAME_PREFIX = "my";
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).STATIC_FIELD_NAME_PREFIX = "our";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.readExternal(myOldSettings);
|
||||
super.tearDown();
|
||||
JavaCodeStyleSettings.getInstance(getProject()).FIELD_NAME_PREFIX = "my";
|
||||
JavaCodeStyleSettings.getInstance(getProject()).STATIC_FIELD_NAME_PREFIX = "our";
|
||||
}
|
||||
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
+1
-13
@@ -16,34 +16,22 @@
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
|
||||
/**
|
||||
* @author Danila Ponomarenko
|
||||
*/
|
||||
public class BindFieldsFromParametersTest extends LightIntentionActionTestCase {
|
||||
private boolean myPreferLongNames;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
myPreferLongNames = settings.PREFER_LONGER_NAMES;
|
||||
if (getTestName(false).contains("SameParam")) {
|
||||
settings.PREFER_LONGER_NAMES = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
settings.FIELD_NAME_PREFIX = "";
|
||||
settings.PREFER_LONGER_NAMES = myPreferLongNames;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
@Override
|
||||
|
||||
+10
-26
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.varScopeCanBeNarrowed.FieldCanBeLocalInspection;
|
||||
@@ -25,8 +24,17 @@ import org.jetbrains.annotations.NotNull;
|
||||
|
||||
|
||||
public class ConvertFieldToLocalTest extends LightQuickFixParameterizedTestCase {
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/convert2Local";
|
||||
}
|
||||
|
||||
private boolean myGenerateFinalLocals;
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.GENERATE_FINAL_LOCALS = StringUtil.containsIgnoreCase(getTestName(true), "final");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
@@ -37,28 +45,4 @@ public class ConvertFieldToLocalTest extends LightQuickFixParameterizedTestCase
|
||||
}
|
||||
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
JavaCodeStyleSettings settings = CodeStyle.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
myGenerateFinalLocals = settings.GENERATE_FINAL_LOCALS;
|
||||
settings.GENERATE_FINAL_LOCALS = StringUtil.containsIgnoreCase(getTestName(true), "final");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
CodeStyle.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS = myGenerateFinalLocals;
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/convert2Local";
|
||||
}
|
||||
|
||||
}
|
||||
+1
-12
@@ -17,7 +17,6 @@ package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.deadCode.UnusedDeclarationInspection;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.siyeh.ig.style.MissortedModifiersInspection;
|
||||
import com.siyeh.ig.style.UnqualifiedFieldAccessInspection;
|
||||
@@ -26,26 +25,16 @@ import com.siyeh.ig.style.UnqualifiedFieldAccessInspection;
|
||||
* @author cdr
|
||||
*/
|
||||
public class CreateConstructorParameterFromFieldTest extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
private boolean myPreferLongNames;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
enableInspectionTools(new UnusedDeclarationInspection(), new MissortedModifiersInspection(), new UnqualifiedFieldAccessInspection());
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
myPreferLongNames = settings.PREFER_LONGER_NAMES;
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
if (getTestName(false).contains("SameParameter")) {
|
||||
settings.PREFER_LONGER_NAMES = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).PREFER_LONGER_NAMES = myPreferLongNames;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
@Override
|
||||
|
||||
+1
-9
@@ -16,7 +16,6 @@
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
|
||||
/**
|
||||
@@ -26,14 +25,7 @@ public class CreateFieldFromParameterTest extends LightIntentionActionTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).FIELD_NAME_PREFIX = "my";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).FIELD_NAME_PREFIX = "";
|
||||
//noinspection SuperTearDownInFinally
|
||||
super.tearDown();
|
||||
JavaCodeStyleSettings.getInstance(getProject()).FIELD_NAME_PREFIX = "my";
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
+1
-9
@@ -49,15 +49,7 @@ class CreateFromUsageOrderTest : LightCodeInsightFixtureTestCase() {
|
||||
}
|
||||
|
||||
private fun testWithSettings(theTest: (JavaCodeStyleSettings) -> Unit) {
|
||||
val parentSettings = CodeStyleSettings().getCustomSettings(JavaCodeStyleSettings::class.java)
|
||||
val copy = Element("copy")
|
||||
val settings = JavaCodeStyleSettings.getInstance(project)
|
||||
settings.writeExternal(copy, parentSettings)
|
||||
try {
|
||||
theTest(settings)
|
||||
}
|
||||
finally {
|
||||
settings.readExternal(copy)
|
||||
}
|
||||
theTest(settings)
|
||||
}
|
||||
}
|
||||
|
||||
+8
-21
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
|
||||
@@ -23,28 +22,16 @@ import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
* @author ven
|
||||
*/
|
||||
public class CreateLocalFromUsageTest extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CodeStyle.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS =
|
||||
getTestName(true).contains("final");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
CodeStyle.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS = false;
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/createLocalFromUsage";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_LOCALS = getTestName(true).contains("final");
|
||||
}
|
||||
|
||||
public void test() { doAllTests(); }
|
||||
}
|
||||
|
||||
+34
-40
@@ -151,48 +151,42 @@ class A {
|
||||
|
||||
void "test use fully qualified names with conflicting imports"() {
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(project);
|
||||
def fqClassNames = settings.useFqClassNames
|
||||
try {
|
||||
settings.setUseFqClassNames(true)
|
||||
configureFromFileText "a.java", """
|
||||
import java.awt.List;
|
||||
class A {
|
||||
void m(java.util.List<String> list){
|
||||
fo<caret>o(list);
|
||||
}
|
||||
}
|
||||
"""
|
||||
TemplateManagerImpl.setTemplateTesting(project, testRootDisposable)
|
||||
doAction("Create method 'foo' in 'A'")
|
||||
def state = TemplateManagerImpl.getTemplateState(getEditor())
|
||||
|
||||
def document = getEditor().getDocument()
|
||||
def offset = getEditor().getCaretModel().getOffset()
|
||||
|
||||
ApplicationManager.application.runWriteAction {
|
||||
def method = PsiTreeUtil.getParentOfType(getFile().findElementAt(offset), PsiMethod.class)
|
||||
method.getModifierList().setModifierProperty(PsiModifier.STATIC, false)
|
||||
PsiDocumentManager.getInstance(getFile().project).commitDocument(document)
|
||||
}
|
||||
|
||||
state.gotoEnd(false)
|
||||
|
||||
checkResultByText """
|
||||
import java.awt.List;
|
||||
class A {
|
||||
void m(java.util.List<String> list){
|
||||
foo(list);
|
||||
}
|
||||
|
||||
private void foo(java.util.List<String> list) {
|
||||
|
||||
}
|
||||
}
|
||||
"""
|
||||
settings.setUseFqClassNames(true)
|
||||
configureFromFileText "a.java", """
|
||||
import java.awt.List;
|
||||
class A {
|
||||
void m(java.util.List<String> list){
|
||||
fo<caret>o(list);
|
||||
}
|
||||
finally {
|
||||
settings.setUseFqClassNames(fqClassNames)
|
||||
}
|
||||
"""
|
||||
TemplateManagerImpl.setTemplateTesting(project, testRootDisposable)
|
||||
doAction("Create method 'foo' in 'A'")
|
||||
def state = TemplateManagerImpl.getTemplateState(getEditor())
|
||||
|
||||
def document = getEditor().getDocument()
|
||||
def offset = getEditor().getCaretModel().getOffset()
|
||||
|
||||
ApplicationManager.application.runWriteAction {
|
||||
def method = PsiTreeUtil.getParentOfType(getFile().findElementAt(offset), PsiMethod.class)
|
||||
method.getModifierList().setModifierProperty(PsiModifier.STATIC, false)
|
||||
PsiDocumentManager.getInstance(getFile().project).commitDocument(document)
|
||||
}
|
||||
|
||||
state.gotoEnd(false)
|
||||
|
||||
checkResultByText """
|
||||
import java.awt.List;
|
||||
class A {
|
||||
void m(java.util.List<String> list){
|
||||
foo(list);
|
||||
}
|
||||
|
||||
private void foo(java.util.List<String> list) {
|
||||
|
||||
}
|
||||
}
|
||||
"""
|
||||
}
|
||||
|
||||
void "test format adjusted imports"() {
|
||||
|
||||
+1
-10
@@ -18,7 +18,6 @@ package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.codeInspection.LambdaCanBeMethodReferenceInspection;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -28,18 +27,10 @@ public class Lambda2MethodReferenceInspectionTest extends LightQuickFixParameter
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
JavaCodeStyleSettings javaSettings =
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.REPLACE_CAST = javaSettings.REPLACE_INSTANCEOF = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
JavaCodeStyleSettings javaSettings =
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
javaSettings.REPLACE_CAST = javaSettings.REPLACE_INSTANCEOF = false;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected LocalInspectionTool[] configureLocalInspectionTools() {
|
||||
|
||||
+1
-20
@@ -16,17 +16,12 @@
|
||||
package com.intellij.java.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.codeInsight.daemon.quickFix.LightQuickFixParameterizedTestCase;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
|
||||
/**
|
||||
* @author Pavel.Dolgov
|
||||
*/
|
||||
public class ReplaceIteratorForEachLoopWithIteratorForLoopFixTest extends LightQuickFixParameterizedTestCase {
|
||||
|
||||
private boolean myFinalLocals;
|
||||
|
||||
public void test() { doAllTests(); }
|
||||
|
||||
@Override
|
||||
@@ -34,25 +29,11 @@ public class ReplaceIteratorForEachLoopWithIteratorForLoopFixTest extends LightQ
|
||||
super.setUp();
|
||||
if (getTestName(false).startsWith("Final")) {
|
||||
final JavaCodeStyleSettings codeStyleSettings =
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
myFinalLocals = codeStyleSettings.GENERATE_FINAL_LOCALS;
|
||||
JavaCodeStyleSettings.getInstance(getProject());
|
||||
codeStyleSettings.GENERATE_FINAL_LOCALS = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
if (getTestName(false).startsWith("Final")) {
|
||||
final CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
codeStyleSettings.getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_LOCALS = myFinalLocals;
|
||||
}
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return "/codeInsight/daemonCodeAnalyzer/quickFix/replaceIteratorForEachWithFor";
|
||||
|
||||
+5
-6
@@ -20,6 +20,7 @@ import com.intellij.lang.java.JavaLanguage
|
||||
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.codeStyle.JavaCodeStyleSettings
|
||||
import com.intellij.psi.statistics.StatisticsManager
|
||||
import com.intellij.psi.statistics.impl.StatisticsManagerImpl
|
||||
@@ -28,7 +29,7 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.siyeh.ig.style.UnnecessaryFullyQualifiedNameInspection
|
||||
|
||||
class AddImportActionTest extends LightCodeInsightFixtureTestCase {
|
||||
private CodeStyleSettings settings
|
||||
private CommonCodeStyleSettings settings
|
||||
|
||||
void testMap15() {
|
||||
IdeaTestUtil.withLevel(myModule, LanguageLevel.JDK_1_5, {
|
||||
@@ -523,7 +524,7 @@ class A {}
|
||||
|
||||
|
||||
void "test keep methods formatting on add import"() {
|
||||
settings.getCommonSettings(JavaLanguage.INSTANCE).ALIGN_GROUP_FIELD_DECLARATIONS = true
|
||||
settings.ALIGN_GROUP_FIELD_DECLARATIONS = true
|
||||
|
||||
myFixture.configureByText 'Tq.java', '''
|
||||
class Tq {
|
||||
@@ -562,15 +563,13 @@ class Tq {
|
||||
@Override
|
||||
void setUp() throws Exception {
|
||||
super.setUp()
|
||||
settings = new CodeStyleSettings()
|
||||
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
settings = CodeStyleSettingsManager.getSettings(getProject()).getCommonSettings(JavaLanguage.INSTANCE)
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.SHORTEN_NAMES_ALWAYS_AND_ADD_IMPORT
|
||||
CodeStyleSettingsManager.getInstance(myFixture.project).setTemporarySettings(settings)
|
||||
}
|
||||
|
||||
@Override
|
||||
void tearDown() throws Exception {
|
||||
CodeStyleSettingsManager.getInstance(myFixture.project).dropTemporarySettings()
|
||||
settings = null
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
+2
-9
@@ -18,7 +18,6 @@ package com.intellij.java.codeInsight.intention;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.testFramework.fixtures.JavaCodeInsightFixtureTestCase;
|
||||
|
||||
@@ -99,15 +98,9 @@ public class AddSingleStaticImportActionTest extends JavaCodeInsightFixtureTestC
|
||||
myFixture.addClass("package foo; class Foo {public static void foo(int i){}}");
|
||||
myFixture.addClass("package foo; class Bar {public static void foo(String s){}}");
|
||||
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class);
|
||||
int old = settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND;
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = 1;
|
||||
try {
|
||||
doTest("Add static import for 'foo.Foo.foo'");
|
||||
}
|
||||
finally {
|
||||
settings.NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND = old;
|
||||
}
|
||||
doTest("Add static import for 'foo.Foo.foo'");
|
||||
}
|
||||
|
||||
public void testConflictingNamesInScope() {
|
||||
|
||||
+1
-11
@@ -17,8 +17,6 @@ package com.intellij.java.codeInsight.intention;
|
||||
|
||||
import com.intellij.codeInsight.daemon.LightIntentionActionTestCase;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
|
||||
/**
|
||||
@@ -33,15 +31,7 @@ public class CopyAbstractMethodImplementationTest extends LightIntentionActionTe
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).INSERT_OVERRIDE_ANNOTATION = false;
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
|
||||
super.tearDown();
|
||||
JavaCodeStyleSettings.getInstance(getProject()).INSERT_OVERRIDE_ANNOTATION = false;
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
+2
-9
@@ -37,15 +37,8 @@ public class SurroundAutoCloseableActionTest extends LightCodeInsightFixtureTest
|
||||
public void testExpressionIncomplete() { doTest(); }
|
||||
public void testUnrelatedVariable() { doTest(); }
|
||||
public void testCommentsInVarDeclaration() {
|
||||
JavaCodeStyleSettings styleSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
boolean finalLocals = styleSettings.GENERATE_FINAL_LOCALS;
|
||||
try {
|
||||
styleSettings.GENERATE_FINAL_LOCALS = true;
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
styleSettings.GENERATE_FINAL_LOCALS = finalLocals;
|
||||
}
|
||||
JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_LOCALS = true;
|
||||
doTest();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
|
||||
+1
-17
@@ -1,8 +1,6 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.java.codeInsight.template.postfix.templates;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -14,26 +12,12 @@ public class CastVarPostfixTemplateTest extends PostfixTemplateTestCase {
|
||||
return "castvar";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
CodeStyle.dropTemporarySettings(myFixture.getProject());
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void testSingleExpression() {
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testFinalSingleExpression() {
|
||||
CodeStyleSettings codeStyleSettings = CodeStyle.getSettings(myFixture.getProject());
|
||||
CodeStyleSettings clone = codeStyleSettings.clone();
|
||||
CodeStyle.setTemporarySettings(myFixture.getProject(), clone);
|
||||
|
||||
JavaCodeStyleSettings customSettings = clone.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings customSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
customSettings.GENERATE_FINAL_LOCALS = true;
|
||||
|
||||
doTest();
|
||||
|
||||
+3
-10
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package com.intellij.java.codeInsight.template.postfix.templates;
|
||||
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -43,14 +42,8 @@ public class ForeachTemplateTest extends PostfixTemplateTestCase {
|
||||
}
|
||||
|
||||
public void testFinalLocals() {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
boolean oldGenerateFinalLocals = settings.GENERATE_FINAL_LOCALS;
|
||||
try {
|
||||
settings.GENERATE_FINAL_LOCALS = true;
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
settings.GENERATE_FINAL_LOCALS = oldGenerateFinalLocals;
|
||||
}
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.GENERATE_FINAL_LOCALS = true;
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -34,9 +34,9 @@ import java.util.List;
|
||||
public class JavaCodeStyleSettingsTest extends CodeStyleTestCase {
|
||||
|
||||
public void testSettingsClone() {
|
||||
List<String> annotations = Arrays.asList("anno1", "anno2");
|
||||
JavaCodeStyleSettings original = (JavaCodeStyleSettings)JavaCodeStyleSettings.getInstance(getProject()).clone();
|
||||
JavaCodeStyleSettings original = JavaCodeStyleSettings.getInstance(getProject());
|
||||
original.getImportLayoutTable().addEntry(new PackageEntry(false, "test", true));
|
||||
List<String> annotations = Arrays.asList("anno1", "anno2");
|
||||
original.setRepeatAnnotations(annotations);
|
||||
original.getPackagesToUseImportOnDemand().addEntry(new PackageEntry(false, "test2", true));
|
||||
original.FIELD_TYPE_TO_NAME.addPair("foo", "bar");
|
||||
|
||||
+10
-20
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.java.psi.formatter.java;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.codeInsight.AbstractEnterActionTestCase;
|
||||
import com.intellij.lang.java.JavaLanguage;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
@@ -26,10 +27,8 @@ import java.io.IOException;
|
||||
public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
|
||||
public void testEnterInsideAnnotationParameters() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.ALIGN_MULTILINE_ANNOTATION_PARAMETERS = true;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest("java",
|
||||
"public class T {\n" +
|
||||
@@ -77,10 +76,8 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
}
|
||||
|
||||
public void testEnterInsideAnnotationParameters_AfterNameValuePairBeforeLparenth() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.ALIGN_MULTILINE_ANNOTATION_PARAMETERS = true;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest("java",
|
||||
"public class T {\n" +
|
||||
@@ -143,10 +140,9 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
}
|
||||
|
||||
public void testEnter_BetweenAlignedChainedMethodCalls() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaCommon = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaCommon.ALIGN_MULTILINE_CHAINED_METHODS = true;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest("java",
|
||||
"class T {\n" +
|
||||
@@ -171,10 +167,9 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
}
|
||||
|
||||
public void testEnter_AfterLastChainedCall() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaCommon = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaCommon.ALIGN_MULTILINE_CHAINED_METHODS = true;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest("java",
|
||||
"class T {\n" +
|
||||
@@ -197,11 +192,10 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
}
|
||||
|
||||
public void testEnter_NewArgumentWithTabs() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaCommon = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaCommon.getIndentOptions().USE_TAB_CHARACTER = true;
|
||||
javaCommon.getIndentOptions().SMART_TABS = true;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest("java",
|
||||
"class T {\n" +
|
||||
@@ -347,12 +341,11 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
}
|
||||
|
||||
public void testEnter_NewArgumentWithTabsNoAlign() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaCommon = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaCommon.getIndentOptions().USE_TAB_CHARACTER = true;
|
||||
javaCommon.getIndentOptions().SMART_TABS = true;
|
||||
javaCommon.ALIGN_MULTILINE_PARAMETERS = false;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest("java",
|
||||
"class T {\n" +
|
||||
@@ -427,10 +420,9 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
}
|
||||
|
||||
public void testIdea108112() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.ALIGN_MULTILINE_BINARY_OPERATION = true;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest(
|
||||
"java",
|
||||
@@ -455,10 +447,9 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
}
|
||||
|
||||
public void testIdea153628() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.ALIGN_MULTILINE_BINARY_OPERATION = true;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest(
|
||||
"java",
|
||||
@@ -500,10 +491,9 @@ public class JavaEnterActionTest extends AbstractEnterActionTestCase {
|
||||
}
|
||||
|
||||
public void testIdea115696_Aligned() throws IOException {
|
||||
CodeStyleSettings settings = getCodeStyleSettings();
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(getProject());
|
||||
CommonCodeStyleSettings javaSettings = settings.getCommonSettings(JavaLanguage.INSTANCE);
|
||||
javaSettings.ALIGN_MULTILINE_BINARY_OPERATION = true;
|
||||
setCodeStyleSettings(settings);
|
||||
|
||||
doTextTest(
|
||||
"java",
|
||||
|
||||
+1
-1
@@ -44,6 +44,6 @@ public abstract class JavaFormatterTestCase extends FormatterTestCase {
|
||||
}
|
||||
|
||||
protected JavaCodeStyleSettings getCustomJavaSettings() {
|
||||
return getSettings().getCustomSettings(JavaCodeStyleSettings.class);
|
||||
return JavaCodeStyleSettings.getInstance(getProject());
|
||||
}
|
||||
}
|
||||
|
||||
+1
-15
@@ -17,8 +17,6 @@ package com.intellij.java.psi.impl.source.tree.java;
|
||||
|
||||
import com.intellij.java.psi.GenericsTestCase;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
|
||||
@@ -26,23 +24,11 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
* @author dsl
|
||||
*/
|
||||
public class BindToGenericClassTest extends GenericsTestCase {
|
||||
private boolean myOldFQNamesSetting;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
setupGenericSampleClasses();
|
||||
final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings();
|
||||
|
||||
myOldFQNamesSetting = currentSettings.getCustomSettings(JavaCodeStyleSettings.class).USE_FQ_CLASS_NAMES;
|
||||
currentSettings.getCustomSettings(JavaCodeStyleSettings.class).USE_FQ_CLASS_NAMES = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
final CodeStyleSettings currentSettings = CodeStyleSettingsManager.getInstance(myProject).getCurrentSettings();
|
||||
currentSettings.getCustomSettings(JavaCodeStyleSettings.class).USE_FQ_CLASS_NAMES = myOldFQNamesSetting;
|
||||
super.tearDown();
|
||||
JavaCodeStyleSettings.getInstance(getProject()).USE_FQ_CLASS_NAMES = true;
|
||||
}
|
||||
|
||||
public void testReferenceElement() {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class CopyClassTest extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testLibraryClass() throws Exception { // IDEADEV-28791
|
||||
JavaCodeStyleSettings javaSettings = getCurrentCodeStyleSettings().getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_ALWAYS;
|
||||
doTest("java.util.ArrayList", "Bar");
|
||||
}
|
||||
|
||||
+2
-11
@@ -20,7 +20,6 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.refactoring.extractMethodObject.ExtractMethodObjectHandler;
|
||||
import com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor;
|
||||
@@ -165,17 +164,9 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightRefactor
|
||||
}
|
||||
|
||||
private void doTestWithIdeaCodeStyleSettings() throws Exception {
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
String oldPrefix = settings.FIELD_NAME_PREFIX;
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
boolean oldPrefer = settings.PREFER_LONGER_NAMES;
|
||||
settings.PREFER_LONGER_NAMES = false;
|
||||
try {
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix;
|
||||
settings.PREFER_LONGER_NAMES = oldPrefer;
|
||||
}
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -270,7 +270,7 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testFinalParamUsedInsideAnon() throws Exception {
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS = false;
|
||||
JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_PARAMETERS = false;
|
||||
doTestWithJava17();
|
||||
}
|
||||
|
||||
@@ -287,7 +287,7 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testNonFinalWritableParam() throws Exception {
|
||||
CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class).GENERATE_FINAL_PARAMETERS = true;
|
||||
JavaCodeStyleSettings.getInstance(getProject()).GENERATE_FINAL_PARAMETERS = true;
|
||||
doTest();
|
||||
}
|
||||
|
||||
@@ -555,15 +555,9 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testReassignedVarAfterCall() throws Exception {
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
boolean oldGenerateFinalLocals = settings.GENERATE_FINAL_LOCALS;
|
||||
try {
|
||||
settings.GENERATE_FINAL_LOCALS = true;
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
settings.GENERATE_FINAL_LOCALS = oldGenerateFinalLocals;
|
||||
}
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.GENERATE_FINAL_LOCALS = true;
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNonPhysicalAssumptions() throws Exception {
|
||||
@@ -1003,15 +997,9 @@ public class ExtractMethodTest extends LightCodeInsightTestCase {
|
||||
}
|
||||
|
||||
public void testDefaultNamesConflictResolution() throws Exception {
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
final String oldPrefix = settings.LOCAL_VARIABLE_NAME_PREFIX;
|
||||
try {
|
||||
settings.LOCAL_VARIABLE_NAME_PREFIX = "_";
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
settings.LOCAL_VARIABLE_NAME_PREFIX = oldPrefix;
|
||||
}
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.LOCAL_VARIABLE_NAME_PREFIX = "_";
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testInferredNotNull() throws Exception {
|
||||
|
||||
+8
-15
@@ -27,7 +27,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.psi.PsiLiteralExpression;
|
||||
import com.intellij.psi.PsiLocalVariable;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -66,20 +65,14 @@ public class InplaceIntroduceVariableTest extends AbstractJavaInplaceIntroduceTe
|
||||
}
|
||||
|
||||
public void testConflictingInnerClassName() {
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
final boolean oldOption = settings.INSERT_INNER_CLASS_IMPORTS;
|
||||
try {
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
doTest(new Pass<AbstractInplaceIntroducer>() {
|
||||
@Override
|
||||
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
|
||||
type("constants");
|
||||
}
|
||||
});
|
||||
}
|
||||
finally {
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = oldOption;
|
||||
}
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
doTest(new Pass<AbstractInplaceIntroducer>() {
|
||||
@Override
|
||||
public void pass(AbstractInplaceIntroducer inplaceIntroduceFieldPopup) {
|
||||
type("constants");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testInsideInjectedString() {
|
||||
|
||||
@@ -19,7 +19,6 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.refactoring.makeStatic.MakeClassStaticProcessor;
|
||||
import com.intellij.refactoring.makeStatic.MakeStaticUtil;
|
||||
@@ -64,15 +63,9 @@ public class MakeClassStaticTest extends LightRefactoringTestCase {
|
||||
}
|
||||
|
||||
public void testFieldWithMyPrefix() {
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
String oldPrefix = settings.FIELD_NAME_PREFIX;
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
try {
|
||||
performWithFields();
|
||||
}
|
||||
finally {
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix;
|
||||
}
|
||||
performWithFields();
|
||||
}
|
||||
|
||||
private void perform() {
|
||||
|
||||
@@ -8,7 +8,6 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import com.intellij.psi.search.ProjectScope;
|
||||
@@ -47,15 +46,9 @@ public class MoveClassToInnerTest extends RefactoringTestCase {
|
||||
}
|
||||
|
||||
public void testInsertInnerClassImport() throws Exception {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(myProject).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
final boolean imports = settings.INSERT_INNER_CLASS_IMPORTS;
|
||||
try {
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
finally {
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = imports;
|
||||
}
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
doTest(new String[] { "pack1.Class1" }, "pack2.A");
|
||||
}
|
||||
|
||||
public void testSimultaneousMove() throws Exception {
|
||||
|
||||
@@ -3,11 +3,9 @@
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
@@ -16,19 +14,6 @@ import java.io.IOException;
|
||||
public abstract class AbstractEnterActionTestCase extends LightCodeInsightTestCase {
|
||||
private static final String TEST_PATH = "/codeInsight/enterAction/";
|
||||
|
||||
protected static CodeStyleSettings getCodeStyleSettings() {
|
||||
return CodeStyle.getSettings(getProject()).clone();
|
||||
}
|
||||
protected static void setCodeStyleSettings(CodeStyleSettings settings) {
|
||||
CodeStyle.setTemporarySettings(getProject(), settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CodeStyle.dropTemporarySettings(getProject());
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void doGetIndentTest(final PsiFile file, final int lineNum, final String expected) {
|
||||
final int offset = PsiDocumentManager.getInstance(getProject()).getDocument(file).getLineEndOffset(lineNum);
|
||||
final String actial = CodeStyleManager.getInstance(getProject()).getLineIndent(file, offset);
|
||||
|
||||
@@ -268,7 +268,7 @@ public class MigrateTypeSignatureTest extends TypeMigrationTestBase {
|
||||
}
|
||||
|
||||
public void testSpecJavadoc() {
|
||||
JavaCodeStyleSettings settings = getCurrentCodeStyleSettings().getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.CLASS_NAMES_IN_JAVADOC = JavaCodeStyleSettings.FULLY_QUALIFY_NAMES_ALWAYS;
|
||||
doTestFirstParamType("meth", "Spec",
|
||||
myJavaFacade.getElementFactory().createTypeFromText(CommonClassNames.JAVA_UTIL_SET, null));
|
||||
|
||||
-17
@@ -23,7 +23,6 @@ import com.intellij.openapi.editor.FoldRegion;
|
||||
import com.intellij.openapi.editor.FoldingModel;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CommonCodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.arrangement.engine.ArrangementEngine;
|
||||
import com.intellij.psi.codeStyle.arrangement.group.ArrangementGroupingRule;
|
||||
@@ -59,22 +58,6 @@ public abstract class AbstractRearrangerTest extends LightPlatformCodeInsightFix
|
||||
protected FileType fileType;
|
||||
protected Language language;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
CodeStyle.setTemporarySettings(myFixture.getProject(), new CodeStyleSettings());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
CodeStyle.dropTemporarySettings(myFixture.getProject());
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected CommonCodeStyleSettings getCommonSettings() {
|
||||
return CodeStyle.getSettings(myFixture.getProject()).getCommonSettings(language);
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Checks that {@link CodeStyleSettings} are not overwritten by a rogue test.
|
||||
* Usage: {@code setUp() { tracker = new CodeStyleSettingsTracker(...); } tearDown() { tracker.checkForSettingsDamage(); } }
|
||||
*/
|
||||
public class CodeStyleSettingsTracker {
|
||||
private final Supplier<CodeStyleSettings> myCurrentSettingsSupplier;
|
||||
private CodeStyleSettings myOldSettings;
|
||||
|
||||
public CodeStyleSettingsTracker(@NotNull Supplier<CodeStyleSettings> currentSettingsSupplier) {
|
||||
myCurrentSettingsSupplier = currentSettingsSupplier;
|
||||
CodeStyleSettings settings = currentSettingsSupplier.get();
|
||||
if (settings != null) {
|
||||
settings.getIndentOptions(StdFileTypes.JAVA);
|
||||
myOldSettings = settings.clone();
|
||||
}
|
||||
}
|
||||
public void checkForSettingsDamage() {
|
||||
CodeStyleSettings oldSettings = myOldSettings;
|
||||
if (oldSettings == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
myOldSettings = null;
|
||||
|
||||
UsefulTestCase.doCheckForSettingsDamage(oldSettings, myCurrentSettingsSupplier.get());
|
||||
}
|
||||
}
|
||||
@@ -138,6 +138,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
}
|
||||
|
||||
private VirtualFilePointerTracker myVirtualFilePointerTracker;
|
||||
private CodeStyleSettingsTracker myCodeStyleSettingsTracker;
|
||||
|
||||
/**
|
||||
* @return Project to be used in tests for example for project components retrieval.
|
||||
@@ -275,7 +276,10 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
doSetup(descriptor, configureLocalInspectionTools(), getTestRootDisposable());
|
||||
InjectedLanguageManagerImpl.pushInjectors(getProject());
|
||||
|
||||
storeSettings();
|
||||
myCodeStyleSettingsTracker = new CodeStyleSettingsTracker(
|
||||
() -> isStressTest() ||
|
||||
ApplicationManager.getApplication() == null ||
|
||||
ApplicationManager.getApplication() instanceof MockApplication ? null : CodeStyle.getDefaultSettings());
|
||||
|
||||
myThreadTracker = new ThreadTracker();
|
||||
ModuleRootManager.getInstance(ourModule).orderEntries().getAllLibrariesAndSdkClassesRoots();
|
||||
@@ -381,7 +385,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
//noinspection Convert2MethodRef
|
||||
new RunAll(
|
||||
() -> CodeStyle.dropTemporarySettings(project),
|
||||
this::checkForSettingsDamage,
|
||||
() -> myCodeStyleSettingsTracker.checkForSettingsDamage(),
|
||||
() -> doTearDown(project, ourApplication),
|
||||
() -> checkEditorsReleased(),
|
||||
() -> myOldSdks.checkForJdkTableLeaks(),
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.ide.highlighter.ProjectFileType;
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
import com.intellij.idea.IdeaLogger;
|
||||
import com.intellij.idea.IdeaTestApplication;
|
||||
import com.intellij.mock.MockApplication;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.DataProvider;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -117,6 +118,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
private static Set<VirtualFile> ourEternallyLivingFilesCache;
|
||||
private SdkLeakTracker myOldSdks;
|
||||
private VirtualFilePointerTracker myVirtualFilePointerTracker;
|
||||
private CodeStyleSettingsTracker myCodeStyleSettingsTracker;
|
||||
|
||||
|
||||
@NotNull
|
||||
@@ -215,7 +217,8 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
|
||||
setUpProject();
|
||||
|
||||
storeSettings();
|
||||
myCodeStyleSettingsTracker = new CodeStyleSettingsTracker(
|
||||
() -> isStressTest() || ApplicationManager.getApplication() == null || ApplicationManager.getApplication() instanceof MockApplication ? null : CodeStyle.getDefaultSettings());
|
||||
ourTestCase = this;
|
||||
if (myProject != null) {
|
||||
ProjectManagerEx.getInstanceEx().openTestProject(myProject);
|
||||
@@ -510,7 +513,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
})
|
||||
.append(() -> disposeProject())
|
||||
.append(() -> UIUtil.dispatchAllInvocationEvents())
|
||||
.append(() -> checkForSettingsDamage())
|
||||
.append(() -> myCodeStyleSettingsTracker.checkForSettingsDamage())
|
||||
.append(() -> {
|
||||
if (project != null) {
|
||||
InjectedLanguageManagerImpl.checkInjectorsAreDisposed(project);
|
||||
|
||||
@@ -6,10 +6,7 @@ import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.concurrency.IdeaForkJoinWorkerThreadFactory;
|
||||
import com.intellij.diagnostic.PerformanceWatcher;
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.mock.MockApplication;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.application.impl.ApplicationInfoImpl;
|
||||
import com.intellij.openapi.command.impl.StartMarkAction;
|
||||
@@ -85,7 +82,6 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
static String ourPathToKeep;
|
||||
private final List<String> myPathsToKeep = new ArrayList<>();
|
||||
|
||||
private CodeStyleSettings myOldCodeStyleSettings;
|
||||
private String myTempDir;
|
||||
|
||||
static final Key<String> CREATION_PLACE = Key.create("CREATION_PLACE");
|
||||
@@ -229,24 +225,7 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
containerMap.clear();
|
||||
}
|
||||
|
||||
protected void checkForSettingsDamage() {
|
||||
Application app = ApplicationManager.getApplication();
|
||||
if (isStressTest() || app == null || app instanceof MockApplication) {
|
||||
return;
|
||||
}
|
||||
|
||||
CodeStyleSettings oldCodeStyleSettings = myOldCodeStyleSettings;
|
||||
if (oldCodeStyleSettings == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
myOldCodeStyleSettings = null;
|
||||
|
||||
doCheckForSettingsDamage(oldCodeStyleSettings, CodeStyle.getDefaultSettings());
|
||||
}
|
||||
|
||||
public static void doCheckForSettingsDamage(@NotNull CodeStyleSettings oldCodeStyleSettings,
|
||||
@NotNull CodeStyleSettings currentCodeStyleSettings) {
|
||||
static void doCheckForSettingsDamage(@NotNull CodeStyleSettings oldCodeStyleSettings, @NotNull CodeStyleSettings currentCodeStyleSettings) {
|
||||
final CodeInsightSettings settings = CodeInsightSettings.getInstance();
|
||||
// don't use method references here to make stack trace reading easier
|
||||
//noinspection Convert2MethodRef
|
||||
@@ -283,13 +262,6 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
.run();
|
||||
}
|
||||
|
||||
void storeSettings() {
|
||||
if (!isStressTest() && ApplicationManager.getApplication() != null) {
|
||||
myOldCodeStyleSettings = CodeStyle.getDefaultSettings().clone();
|
||||
myOldCodeStyleSettings.getIndentOptions(StdFileTypes.JAVA);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected CodeStyleSettings getCurrentCodeStyleSettings() {
|
||||
return CodeStyle.getDefaultSettings();
|
||||
|
||||
+4
@@ -2,6 +2,7 @@
|
||||
package com.intellij.testFramework.fixtures.impl;
|
||||
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.codeHighlighting.RainbowHighlighter;
|
||||
import com.intellij.codeInsight.AutoPopupController;
|
||||
import com.intellij.codeInsight.TargetElementUtil;
|
||||
@@ -87,6 +88,7 @@ import com.intellij.openapi.vcs.readOnlyHandler.ReadonlyStatusHandlerImpl;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.openapi.vfs.impl.VirtualFilePointerTracker;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.impl.PsiManagerEx;
|
||||
import com.intellij.psi.impl.PsiManagerImpl;
|
||||
import com.intellij.psi.impl.cache.CacheManager;
|
||||
@@ -1055,6 +1057,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(false);
|
||||
ensureIndexesUpToDate(getProject());
|
||||
((StartupManagerImpl)StartupManagerEx.getInstanceEx(getProject())).runPostStartupActivities();
|
||||
CodeStyle.setTemporarySettings(getProject(), new CodeStyleSettings());
|
||||
});
|
||||
|
||||
for (Module module : ModuleManager.getInstance(getProject()).getModules()) {
|
||||
@@ -1075,6 +1078,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
//noinspection Convert2MethodRef
|
||||
new RunAll()
|
||||
.append(() -> EdtTestUtil.runInEdtAndWait(() -> {
|
||||
CodeStyle.dropTemporarySettings(getProject());
|
||||
AutoPopupController.getInstance(getProject()).cancelAllRequests(); // clear "show param info" delayed requests leaking project
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true); // return default value to avoid unnecessary save
|
||||
closeOpenFiles();
|
||||
|
||||
+3
-11
@@ -5,7 +5,6 @@ package com.intellij.testFramework.fixtures.impl;
|
||||
import com.intellij.application.options.CodeStyle;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.idea.IdeaTestApplication;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.newvfs.persistent.PersistentFS;
|
||||
@@ -22,8 +21,8 @@ import org.jetbrains.annotations.NotNull;
|
||||
@SuppressWarnings("TestOnlyProblems")
|
||||
public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTestFixture {
|
||||
private final LightProjectDescriptor myProjectDescriptor;
|
||||
private CodeStyleSettings myOldCodeStyleSettings;
|
||||
private SdkLeakTracker myOldSdks;
|
||||
private CodeStyleSettingsTracker myCodeStyleSettingsTracker;
|
||||
|
||||
public LightIdeaTestFixtureImpl(@NotNull LightProjectDescriptor projectDescriptor) {
|
||||
myProjectDescriptor = projectDescriptor;
|
||||
@@ -37,8 +36,7 @@ public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTe
|
||||
LightPlatformTestCase.doSetup(myProjectDescriptor, LocalInspectionTool.EMPTY_ARRAY, getTestRootDisposable());
|
||||
InjectedLanguageManagerImpl.pushInjectors(getProject());
|
||||
|
||||
myOldCodeStyleSettings = getCurrentCodeStyleSettings().clone();
|
||||
myOldCodeStyleSettings.getIndentOptions(StdFileTypes.JAVA);
|
||||
myCodeStyleSettingsTracker = new CodeStyleSettingsTracker(this::getCurrentCodeStyleSettings);
|
||||
|
||||
application.setDataProvider(new TestDataProvider(getProject()));
|
||||
myOldSdks = new SdkLeakTracker();
|
||||
@@ -48,17 +46,11 @@ public class LightIdeaTestFixtureImpl extends BaseFixture implements LightIdeaTe
|
||||
public void tearDown() {
|
||||
Project project = getProject();
|
||||
CodeStyle.dropTemporarySettings(project);
|
||||
CodeStyleSettings oldCodeStyleSettings = myOldCodeStyleSettings;
|
||||
myOldCodeStyleSettings = null;
|
||||
|
||||
// don't use method references here to make stack trace reading easier
|
||||
//noinspection Convert2MethodRef
|
||||
new RunAll()
|
||||
.append(() -> {
|
||||
if (oldCodeStyleSettings != null) {
|
||||
UsefulTestCase.doCheckForSettingsDamage(oldCodeStyleSettings, getCurrentCodeStyleSettings());
|
||||
}
|
||||
})
|
||||
.append(() -> myCodeStyleSettingsTracker.checkForSettingsDamage())
|
||||
.append(() -> super.tearDown()) // call all disposables' dispose() while the project is still open
|
||||
.append(() -> LightPlatformTestCase.doTearDown(project, LightPlatformTestCase.getApplication()))
|
||||
.append(() -> LightPlatformTestCase.checkEditorsReleased())
|
||||
|
||||
+1
-4
@@ -16,8 +16,6 @@
|
||||
package com.siyeh.ig.dataflow;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
|
||||
@@ -35,8 +33,7 @@ public class NegativelyNamedBooleanVariableInspectionTest extends LightInspectio
|
||||
}
|
||||
|
||||
public void testPrefix() {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
settings.getCustomSettings(JavaCodeStyleSettings.class).FIELD_NAME_PREFIX = "m_";
|
||||
JavaCodeStyleSettings.getInstance(getProject()).FIELD_NAME_PREFIX = "m_";
|
||||
doTest("class Y {" +
|
||||
" private boolean /*Boolean variable 'm_isNonValid' is negatively named*/m_isNonValid/**/ = false;" +
|
||||
"}");
|
||||
|
||||
+3
-11
@@ -162,17 +162,9 @@ public class UnnecessaryFullyQualifiedNameFixTest extends IGQuickFixesTestCase {
|
||||
JavaCodeStyleSettings.SHORTEN_NAMES_ALWAYS_AND_ADD_IMPORT
|
||||
}) int classNamesInJavadoc,
|
||||
String fileName) {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
final JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
|
||||
final int oldClassNamesInJavadoc = javaSettings.CLASS_NAMES_IN_JAVADOC;
|
||||
try {
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = classNamesInJavadoc;
|
||||
doTest(InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.replace.quickfix"), before, after, fileName);
|
||||
}
|
||||
finally {
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = oldClassNamesInJavadoc;
|
||||
}
|
||||
final JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = classNamesInJavadoc;
|
||||
doTest(InspectionGadgetsBundle.message("unnecessary.fully.qualified.name.replace.quickfix"), before, after, fileName);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+3
-9
@@ -16,7 +16,6 @@
|
||||
package com.siyeh.ig.javabeans;
|
||||
|
||||
import com.intellij.codeInspection.InspectionProfileEntry;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.siyeh.ig.LightInspectionTestCase;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -28,14 +27,9 @@ public class SuspiciousGetterSetterInspectionTest extends LightInspectionTestCas
|
||||
|
||||
public void testSuspiciousGetterSetter() {
|
||||
final JavaCodeStyleSettings settings =
|
||||
CodeStyleSettingsManager.getInstance(getProject()).getCurrentSettings().getCustomSettings(JavaCodeStyleSettings.class);
|
||||
final String oldPrefix = settings.FIELD_NAME_PREFIX;
|
||||
try {
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
doTest();
|
||||
} finally {
|
||||
settings.FIELD_NAME_PREFIX = oldPrefix;
|
||||
}
|
||||
JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.FIELD_NAME_PREFIX = "my";
|
||||
doTest();
|
||||
}
|
||||
|
||||
public void testNoPrefix() {
|
||||
|
||||
+3
-12
@@ -1,8 +1,6 @@
|
||||
package com.siyeh.ig.style;
|
||||
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.siyeh.ig.IGInspectionTestCase;
|
||||
@@ -33,16 +31,9 @@ public class UnnecessaryFullyQualifiedNameInspectionTest extends IGInspectionTes
|
||||
}
|
||||
|
||||
private void doTestWithFqnInJavadocSetting(String dirPath, int classNamesInJavadoc) {
|
||||
final CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject());
|
||||
JavaCodeStyleSettings javaSettings = settings.getCustomSettings(JavaCodeStyleSettings.class);
|
||||
JavaCodeStyleSettings javaSettings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
|
||||
int oldClassNamesInJavadoc = javaSettings.CLASS_NAMES_IN_JAVADOC;
|
||||
try {
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = classNamesInJavadoc;
|
||||
doTest(dirPath, new UnnecessaryFullyQualifiedNameInspection());
|
||||
}
|
||||
finally {
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = oldClassNamesInJavadoc;
|
||||
}
|
||||
javaSettings.CLASS_NAMES_IN_JAVADOC = classNamesInJavadoc;
|
||||
doTest(dirPath, new UnnecessaryFullyQualifiedNameInspection());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,8 +171,7 @@ public class AdapterToListenerIntention extends MutablyNamedIntention {
|
||||
final PsiModifierList modifierList = newMethod.getModifierList();
|
||||
modifierList.setModifierProperty(PsiModifier.ABSTRACT, false);
|
||||
final Project project = aClass.getProject();
|
||||
final JavaCodeStyleSettings codeStyleSettings =
|
||||
JavaCodeStyleSettings.getInstance(project);
|
||||
final JavaCodeStyleSettings codeStyleSettings = JavaCodeStyleSettings.getInstance(aClass.getContainingFile());
|
||||
if (codeStyleSettings.INSERT_OVERRIDE_ANNOTATION &&
|
||||
PsiUtil.isLanguageLevel6OrHigher(aClass)) {
|
||||
modifierList.addAnnotation("java.lang.Override");
|
||||
|
||||
+1
-10
@@ -19,7 +19,6 @@ import com.intellij.codeInsight.daemon.quickFix.LightQuickFixTestCase;
|
||||
import com.intellij.codeInsight.template.impl.TemplateManagerImpl;
|
||||
import com.intellij.codeInsight.template.impl.TemplateState;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -30,19 +29,11 @@ public class DataPointHolderConversionIntentionTest extends LightQuickFixTestCas
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.STATIC_FIELD_NAME_PREFIX = "qwe";
|
||||
settings.STATIC_FIELD_NAME_SUFFIX = "asd";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
settings.STATIC_FIELD_NAME_PREFIX = "";
|
||||
settings.STATIC_FIELD_NAME_SUFFIX = "";
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
private void doTest() {
|
||||
doSingleTest(getTestName(false) + ".java");
|
||||
}
|
||||
|
||||
+1
-19
@@ -48,12 +48,6 @@ abstract class GroovyFormatterTestCase extends LightCodeInsightFixtureTestCase {
|
||||
groovySettings.BRACE_STYLE = CommonCodeStyleSettings.END_OF_LINE
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
setSettingsBack()
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
protected CommonCodeStyleSettings getGroovySettings() {
|
||||
return myTempSettings.getCommonSettings(GroovyLanguage.INSTANCE)
|
||||
}
|
||||
@@ -65,7 +59,7 @@ abstract class GroovyFormatterTestCase extends LightCodeInsightFixtureTestCase {
|
||||
protected void setSettings(Project project) {
|
||||
assertNull(myTempSettings)
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(project)
|
||||
myTempSettings = settings.clone()
|
||||
myTempSettings = settings
|
||||
|
||||
CommonCodeStyleSettings.IndentOptions gr = myTempSettings.getIndentOptions(GroovyFileType.GROOVY_FILE_TYPE)
|
||||
assertNotSame(gr, settings.OTHER_INDENT_OPTIONS)
|
||||
@@ -73,18 +67,6 @@ abstract class GroovyFormatterTestCase extends LightCodeInsightFixtureTestCase {
|
||||
gr.CONTINUATION_INDENT_SIZE = 4
|
||||
gr.TAB_SIZE = 2
|
||||
myTempSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 3
|
||||
|
||||
CodeStyle.setTemporarySettings(project, myTempSettings)
|
||||
}
|
||||
|
||||
protected void setSettingsBack() {
|
||||
myTempSettings.getIndentOptions(GroovyFileType.GROOVY_FILE_TYPE).INDENT_SIZE = 200
|
||||
myTempSettings.getIndentOptions(GroovyFileType.GROOVY_FILE_TYPE).CONTINUATION_INDENT_SIZE = 200
|
||||
myTempSettings.getIndentOptions(GroovyFileType.GROOVY_FILE_TYPE).TAB_SIZE = 200
|
||||
|
||||
myTempSettings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 5
|
||||
CodeStyle.dropTemporarySettings(getProject())
|
||||
myTempSettings = null
|
||||
}
|
||||
|
||||
protected void checkFormatting(String fileText, String expected) {
|
||||
|
||||
+2
-9
@@ -159,15 +159,8 @@ public class JavaFXQuickfixTest extends LightCodeInsightFixtureTestCase {
|
||||
final String inputName,
|
||||
final String defaultVisibility,
|
||||
final String extension) {
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
String savedVisibility = settings.VISIBILITY;
|
||||
try {
|
||||
settings.VISIBILITY = defaultVisibility;
|
||||
doTest(actionName, inputName, getTestName(false), extension);
|
||||
}
|
||||
finally {
|
||||
settings.VISIBILITY = savedVisibility;
|
||||
}
|
||||
JavaCodeStyleSettings.getInstance(getProject()).VISIBILITY = defaultVisibility;
|
||||
doTest(actionName, inputName, getTestName(false), extension);
|
||||
}
|
||||
|
||||
private void doTest(final String actionName, final String extension) {
|
||||
|
||||
+3
-10
@@ -17,7 +17,6 @@ package org.jetbrains.plugins.javaFX.fxml;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import com.intellij.util.VisibilityUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -61,15 +60,9 @@ public class JavaFXUnresolvedFxIdReferenceInspectionTest extends AbstractJavaFXQ
|
||||
}
|
||||
|
||||
private void doTest(final String controllerName, final String defaultVisibility) {
|
||||
JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
String savedVisibility = settings.VISIBILITY;
|
||||
try {
|
||||
settings.VISIBILITY = defaultVisibility;
|
||||
doTest(controllerName);
|
||||
}
|
||||
finally {
|
||||
settings.VISIBILITY = savedVisibility;
|
||||
}
|
||||
JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.VISIBILITY = defaultVisibility;
|
||||
doTest(controllerName);
|
||||
}
|
||||
|
||||
private void doTest(final String controllerName) {
|
||||
|
||||
+3
-10
@@ -2,7 +2,6 @@ package org.jetbrains.plugins.javaFX.fxml;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.JavaCodeStyleSettings;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.javaFX.fxml.codeInsight.inspections.JavaFxEventHandlerInspection;
|
||||
@@ -78,15 +77,9 @@ public class JavaFxEventHandlerInspectionTest extends AbstractJavaFXTestCase {
|
||||
}
|
||||
|
||||
public void testQuickfixNoFieldNested() {
|
||||
final JavaCodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).getCustomSettings(JavaCodeStyleSettings.class);
|
||||
final boolean oldImports = settings.INSERT_INNER_CLASS_IMPORTS;
|
||||
try {
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
doQuickfixTest("Create method 'onColumnEditStart'");
|
||||
}
|
||||
finally {
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = oldImports;
|
||||
}
|
||||
final JavaCodeStyleSettings settings = JavaCodeStyleSettings.getInstance(getProject());
|
||||
settings.INSERT_INNER_CLASS_IMPORTS = true;
|
||||
doQuickfixTest("Create method 'onColumnEditStart'");
|
||||
}
|
||||
|
||||
public void testQuickfixSuper() {
|
||||
|
||||
+3
-4
@@ -5,7 +5,6 @@ import com.intellij.codeInsight.daemon.QuickFixActionRegistrar
|
||||
import com.intellij.codeInsight.quickfix.UnresolvedReferenceQuickFixProvider
|
||||
import com.intellij.lang.jvm.JvmModifier
|
||||
import com.intellij.lang.jvm.actions.*
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiJvmSubstitutor
|
||||
import com.intellij.psi.PsiModifier
|
||||
import com.intellij.psi.PsiSubstitutor
|
||||
@@ -35,7 +34,7 @@ class JavaFxEventHandlerReferenceQuickFixProvider : UnresolvedReferenceQuickFixP
|
||||
class CreateEventHandlerRequest(element: XmlAttributeValue) : CreateMethodRequest {
|
||||
|
||||
private val myProject = element.project
|
||||
private val myVisibility = getVisibility(myProject)
|
||||
private val myVisibility = getVisibility(element)
|
||||
private val myPointer = element.createSmartPointer(myProject)
|
||||
|
||||
override fun isValid(): Boolean = myPointer.element.let {
|
||||
@@ -70,8 +69,8 @@ class CreateEventHandlerRequest(element: XmlAttributeValue) : CreateMethodReques
|
||||
override fun getTargetSubstitutor(): PsiJvmSubstitutor = PsiJvmSubstitutor(myProject, PsiSubstitutor.EMPTY)
|
||||
}
|
||||
|
||||
private fun getVisibility(project: Project): JvmModifier {
|
||||
val visibility = JavaCodeStyleSettings.getInstance(project).VISIBILITY
|
||||
private fun getVisibility(element: XmlAttributeValue): JvmModifier {
|
||||
val visibility = JavaCodeStyleSettings.getInstance(element.containingFile).VISIBILITY
|
||||
if (VisibilityUtil.ESCALATE_VISIBILITY == visibility) return JvmModifier.PRIVATE
|
||||
if (visibility == PsiModifier.PACKAGE_LOCAL) return JvmModifier.PACKAGE_LOCAL
|
||||
return JvmModifier.valueOf(visibility.toUpperCase())
|
||||
|
||||
@@ -33,9 +33,8 @@ public class PyJoinLinesTest extends PyTestCase {
|
||||
}
|
||||
|
||||
private void doTestWithCodeStyleSettings() {
|
||||
CodeStyleSettings settings = new CodeStyleSettings();
|
||||
CodeStyleSettings settings = CodeStyle.getSettings(myFixture.getProject());
|
||||
settings.setRightMargin(PythonLanguage.getInstance(), 79);
|
||||
CodeStyle.setTemporarySettings(myFixture.getProject(), settings);
|
||||
|
||||
doTest();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user