IDEA-CR-4183 undeprecate setValue(name, string) Null value as default value

This commit is contained in:
Vladimir Krivosheev
2015-08-26 12:32:51 +02:00
parent b12633ef85
commit 9e45c660cf
23 changed files with 64 additions and 70 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,6 +27,7 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.MultiLineLabelUI;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.util.ArrayUtil;
@@ -129,19 +130,13 @@ public class GenerateAntBuildDialog extends DialogWrapper {
private void saveSettings() {
final PropertiesComponent properties = PropertiesComponent.getInstance(myProject);
properties.setValue(SINGLE_FILE_PROPERTY, Boolean.toString(myRbGenerateSingleFileBuild.isSelected()));
properties.setValue(UI_FORM_PROPERTY, Boolean.toString(myCbEnableUIFormsCompilation.isSelected()));
properties.setValue(FORCE_TARGET_JDK_PROPERTY, Boolean.toString(myCbForceTargetJdk.isSelected()));
properties.setValue(BACKUP_FILES_PROPERTY, Boolean.toString(myRbBackupFiles.isSelected()));
properties.setValue(INLINE_RUNTIME_CLASSPATH_PROPERTY, Boolean.toString(myCbInlineRuntimeClasspath.isSelected()));
properties.setValue(GENERATE_IDEA_HOME_PROPERTY, Boolean.toString(myGenerateIdeaHomeProperty.isSelected()));
final String outputFileName = getOutputFileName();
if (outputFileName.length() > 0) {
properties.setValue(OUTPUT_FILE_NAME_PROPERTY, outputFileName);
}
else {
properties.unsetValue(OUTPUT_FILE_NAME_PROPERTY);
}
properties.setValue(SINGLE_FILE_PROPERTY, myRbGenerateSingleFileBuild.isSelected());
properties.setValue(UI_FORM_PROPERTY, myCbEnableUIFormsCompilation.isSelected());
properties.setValue(FORCE_TARGET_JDK_PROPERTY, myCbForceTargetJdk.isSelected());
properties.setValue(BACKUP_FILES_PROPERTY, myRbBackupFiles.isSelected());
properties.setValue(INLINE_RUNTIME_CLASSPATH_PROPERTY, myCbInlineRuntimeClasspath.isSelected());
properties.setValue(GENERATE_IDEA_HOME_PROPERTY, myGenerateIdeaHomeProperty.isSelected());
properties.setValue(OUTPUT_FILE_NAME_PROPERTY, StringUtil.nullize(getOutputFileName()));
}
public void dispose() {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,6 +31,7 @@ import java.awt.*;
*/
public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogBase {
@NonNls private static final String MARK_ALL_REFERENCED_VALUES_KEY = "debugger.mark.all.referenced.values";
private static final boolean MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE = true;
private JCheckBox myCbMarkAdditionalFields;
private final boolean mySuggestAdditionalMarkup;
private JPanel myAdditionalPropertiesPanel;
@@ -41,14 +42,14 @@ public class ObjectMarkupPropertiesDialog extends ValueMarkerPresentationDialogB
mySuggestAdditionalMarkup = suggestAdditionalMarkup;
myDescriptionLabel.setText("If the value is referenced by a constant field of an abstract class,\n" +
"IDEA could additionally mark all values referenced from this class with the names of referencing fields.");
myCbMarkAdditionalFields.setSelected(PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, true));
myCbMarkAdditionalFields.setSelected(PropertiesComponent.getInstance().getBoolean(MARK_ALL_REFERENCED_VALUES_KEY, MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE));
init();
}
@Override
protected void doOKAction() {
if (mySuggestAdditionalMarkup) {
PropertiesComponent.getInstance().setValue(MARK_ALL_REFERENCED_VALUES_KEY, Boolean.toString(myCbMarkAdditionalFields.isSelected()));
PropertiesComponent.getInstance().setValue(MARK_ALL_REFERENCED_VALUES_KEY, myCbMarkAdditionalFields.isSelected(), MARK_ALL_REFERENCED_VALUES_DEFAULT_VALUE);
}
super.doOKAction();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@ public class AnonymousTargetClassPreselectionUtil {
public static void rememberSelection(PsiClass aClass, PsiClass firstClass) {
if (firstClass instanceof PsiAnonymousClass) {
PropertiesComponent.getInstance().setValue(PRESELECT_ANONYMOUS, String.valueOf(aClass == firstClass));
PropertiesComponent.getInstance().setValue(PRESELECT_ANONYMOUS, aClass == firstClass);
}
}
@@ -86,7 +86,7 @@ public class JavaOverrideImplementMemberChooser extends MemberChooser<PsiMethodM
final JavaOverrideImplementMemberChooser javaOverrideImplementMemberChooser =
new JavaOverrideImplementMemberChooser(all, onlyPrimary, lazyElementsWithPercent, project, PsiUtil.isLanguageLevel5OrHigher(aClass),
merge, toImplement, PropertiesComponent.getInstance(project)
.getBoolean(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT, false));
.getBoolean(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT));
javaOverrideImplementMemberChooser.setTitle(getChooserTitle(toImplement, merge));
javaOverrideImplementMemberChooser.setCopyJavadocVisible(true);
@@ -151,8 +151,8 @@ public class JavaOverrideImplementMemberChooser extends MemberChooser<PsiMethodM
@Override
protected void doOKAction() {
super.doOKAction();
PropertiesComponent.getInstance(myProject).setValue(PROP_COMBINED_OVERRIDE_IMPLEMENT, String.valueOf(myMerge));
PropertiesComponent.getInstance(myProject).setValue(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT, String.valueOf(mySortedByOverriding));
PropertiesComponent.getInstance(myProject).setValue(PROP_COMBINED_OVERRIDE_IMPLEMENT, myMerge, true);
PropertiesComponent.getInstance(myProject).setValue(PROP_OVERRIDING_SORTED_OVERRIDE_IMPLEMENT, mySortedByOverriding);
}
@Override
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,7 +21,10 @@ import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.ComboBox;
import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.psi.*;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiNameHelper;
import com.intellij.psi.PsiType;
import com.intellij.refactoring.ui.TypeSelector;
import com.intellij.ui.DocumentAdapter;
import org.jetbrains.annotations.NonNls;
@@ -64,7 +67,7 @@ public class CreateFieldFromParameterDialog extends DialogWrapper {
@Override
protected void doOKAction() {
if (myCbFinal.isEnabled()) {
PropertiesComponent.getInstance().setValue(PROPERTY_NAME, String.valueOf(myCbFinal.isSelected()));
PropertiesComponent.getInstance().setValue(PROPERTY_NAME, myCbFinal.isSelected());
}
final PsiField[] fields = myTargetClass.getFields();
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -78,7 +78,7 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
@Override
protected void analyze(@NotNull final Project project, @NotNull final AnalysisScope scope) {
PropertiesComponent.getInstance().setValue(ANNOTATE_LOCAL_VARIABLES, String.valueOf(myAnnotateLocalVariablesCb.isSelected()));
PropertiesComponent.getInstance().setValue(ANNOTATE_LOCAL_VARIABLES, myAnnotateLocalVariablesCb.isSelected());
final ProgressManager progressManager = ProgressManager.getInstance();
final Set<Module> modulesWithoutAnnotations = new HashSet<Module>();
@@ -344,7 +344,7 @@ public class InferNullityAnnotationsAction extends BaseAnalysisAction {
protected JComponent getAdditionalActionSettings(Project project, BaseAnalysisActionDialog dialog) {
final JPanel panel = new JPanel(new VerticalFlowLayout());
panel.add(new TitledSeparator());
myAnnotateLocalVariablesCb = new JCheckBox("Annotate local variables", PropertiesComponent.getInstance().getBoolean(ANNOTATE_LOCAL_VARIABLES, false));
myAnnotateLocalVariablesCb = new JCheckBox("Annotate local variables", PropertiesComponent.getInstance().getBoolean(ANNOTATE_LOCAL_VARIABLES));
panel.add(myAnnotateLocalVariablesCb);
return panel;
}
@@ -202,7 +202,7 @@ public class PackageChooserDialog extends PackageChooser {
private void toggleShowPathComponent(JPanel northPanel, TextFieldAction fieldAction) {
boolean toShowTextField = !isPathShowing();
PropertiesComponent.getInstance().setValue(FileChooserDialogImpl.FILE_CHOOSER_SHOW_PATH_PROPERTY, Boolean.toString(toShowTextField));
PropertiesComponent.getInstance().setValue(FileChooserDialogImpl.FILE_CHOOSER_SHOW_PATH_PROPERTY, toShowTextField, true);
myPathEditor.setVisible(toShowTextField);
fieldAction.update();
northPanel.revalidate();
@@ -193,7 +193,7 @@ public class ExtractMethodDialog extends DialogWrapper implements AbstractExtrac
}
if (myGenerateAnnotations != null && myGenerateAnnotations.isEnabled()) {
PropertiesComponent.getInstance(myProject).setValue(EXTRACT_METHOD_GENERATE_ANNOTATIONS, String.valueOf(myGenerateAnnotations.isSelected()));
PropertiesComponent.getInstance(myProject).setValue(EXTRACT_METHOD_GENERATE_ANNOTATIONS, myGenerateAnnotations.isSelected(), true);
}
super.doOKAction();
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -272,10 +272,10 @@ class IntroduceConstantDialog extends DialogWrapper {
LanguageLevelProjectExtension.getInstance(psiManager.getProject()).getLanguageLevel().isAtLeast(LanguageLevel.JDK_1_5) &&
JavaPsiFacade.getInstance(psiManager.getProject()).findClass(AnnotationUtil.NON_NLS, myParentClass.getResolveScope()) != null) {
final PropertiesComponent component = PropertiesComponent.getInstance(myProject);
myCbNonNls.setSelected(component.isTrueValue(NONNLS_SELECTED_PROPERTY));
myCbNonNls.setSelected(component.getBoolean(NONNLS_SELECTED_PROPERTY));
myCbNonNls.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
component.setValue(NONNLS_SELECTED_PROPERTY, Boolean.toString(myCbNonNls.isSelected()));
component.setValue(NONNLS_SELECTED_PROPERTY, myCbNonNls.isSelected());
}
});
} else {
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -329,7 +329,7 @@ public abstract class IntroduceFieldCentralPanel {
public void saveFinalState() {
if (myCbFinal != null && myCbFinal.isEnabled()) {
ourLastCbFinalState = myCbFinal.isSelected();
PropertiesComponent.getInstance().setValue(INTRODUCE_FIELD_FINAL_CHECKBOX, String.valueOf(ourLastCbFinalState));
PropertiesComponent.getInstance().setValue(INTRODUCE_FIELD_FINAL_CHECKBOX, ourLastCbFinalState, true);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,7 @@ public abstract class MoveDialogBase extends RefactoringDialog {
protected void saveOpenInEditorOption() {
if (myOpenEditorCb != null) {
PropertiesComponent.getInstance().setValue("Move" + getMovePropertySuffix() +".OpenInEditor", String.valueOf(myOpenEditorCb.isSelected()));
PropertiesComponent.getInstance().setValue("Move" + getMovePropertySuffix() +".OpenInEditor", myOpenEditorCb.isSelected(), isEnabledByDefault());
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -112,7 +112,7 @@ public class CreateTestAction extends PsiElementBaseIntentionAction {
return;
}
propertiesComponent.setValue(CREATE_TEST_IN_THE_SAME_ROOT, String.valueOf(true));
propertiesComponent.setValue(CREATE_TEST_IN_THE_SAME_ROOT, true);
}
final CreateTestDialog d = createTestDialog(project, srcModule, srcClass, srcPackage);
@@ -186,13 +186,11 @@ public class CreateTestDialog extends DialogWrapper {
}
private void restoreShowInheritedMembersStatus() {
String v = getProperties().getValue(SHOW_INHERITED_MEMBERS_PROPERTY);
myShowInheritedMethodsBox.setSelected(v != null && v.equals("true"));
myShowInheritedMethodsBox.setSelected(getProperties().getBoolean(SHOW_INHERITED_MEMBERS_PROPERTY));
}
private void saveShowInheritedMembersStatus() {
boolean v = myShowInheritedMethodsBox.isSelected();
getProperties().setValue(SHOW_INHERITED_MEMBERS_PROPERTY, Boolean.toString(v));
getProperties().setValue(SHOW_INHERITED_MEMBERS_PROPERTY, myShowInheritedMethodsBox.isSelected());
}
private PropertiesComponent getProperties() {
@@ -42,7 +42,7 @@ public abstract class PropertiesComponent {
public abstract String getValue(@NonNls String name);
/**
* @deprecated Use {@link #setValue(String, String, String)} to avoid write defaults.
* Consider to use {@link #setValue(String, String, String)} to avoid write defaults.
*/
public abstract void setValue(@NotNull String name, @Nullable String value);
@@ -64,10 +64,12 @@ public abstract class PropertiesComponent {
/**
* Set value or unset if equals to false
*/
public abstract void setValue(@NotNull String name, boolean value);
public final void setValue(@NotNull String name, boolean value) {
setValue(name, value, false);
}
/**
* Set value or unset if equals to false
* Set value or unset if equals to default
*/
public abstract void setValue(@NotNull String name, boolean value, boolean defaultValue);
@@ -88,10 +90,14 @@ public abstract class PropertiesComponent {
return Boolean.valueOf(getValue(name)).booleanValue();
}
public final boolean getBoolean(@NonNls String name, boolean defaultValue) {
public final boolean getBoolean(@NotNull String name, boolean defaultValue) {
return isValueSet(name) ? isTrueValue(name) : defaultValue;
}
public final boolean getBoolean(@NotNull String name) {
return getBoolean(name, false);
}
@NotNull
public String getValue(@NonNls String name, @NotNull String defaultValue) {
if (!isValueSet(name)) {
@@ -117,16 +117,6 @@ public class PropertiesComponentImpl extends PropertiesComponent implements Pers
}
}
@Override
public void setValue(@NotNull String name, boolean value) {
if (value) {
setValue(name, "true");
}
else {
myMap.remove(name);
}
}
@Override
public void setValue(@NotNull String name, boolean value, boolean defaultValue) {
if (value == defaultValue) {
@@ -70,6 +70,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
@SuppressWarnings({"unchecked"})
public class DirDiffPanel implements Disposable, DataProvider {
public static final String DIVIDER_PROPERTY = "dir.diff.panel.divider.location";
private static final int DIVIDER_PROPERTY_DEFAULT_VALUE = 200;
private JPanel myDiffPanel;
private JBTable myTable;
private JPanel myComponent;
@@ -506,7 +507,7 @@ public class DirDiffPanel implements Disposable, DataProvider {
public void dispose() {
myModel.stopUpdating();
PropertiesComponent.getInstance().setValue(DIVIDER_PROPERTY, String.valueOf(mySplitPanel.getDividerLocation()));
PropertiesComponent.getInstance().setValue(DIVIDER_PROPERTY, mySplitPanel.getDividerLocation(), DIVIDER_PROPERTY_DEFAULT_VALUE);
clearDiffPanel();
}
@@ -528,7 +529,7 @@ public class DirDiffPanel implements Disposable, DataProvider {
}
public void setupSplitter() {
mySplitPanel.setDividerLocation(Integer.valueOf(PropertiesComponent.getInstance().getValue(DIVIDER_PROPERTY, "200")));
mySplitPanel.setDividerLocation(Integer.valueOf(PropertiesComponent.getInstance().getInt(DIVIDER_PROPERTY, DIVIDER_PROPERTY_DEFAULT_VALUE)));
}
@Override
@@ -37,10 +37,10 @@ public class WarnOnDeletion extends ToggleAction implements DumbAware {
}
public static boolean isWarnWhenDeleteItems() {
return !PropertiesComponent.getInstance().isTrueValue(PROPERTY_NAME);
return PropertiesComponent.getInstance().getBoolean(PROPERTY_NAME, false);
}
public static void setWarnWhenDeleteItems(boolean warn) {
PropertiesComponent.getInstance().setValue(PROPERTY_NAME, Boolean.valueOf(!warn).toString());
PropertiesComponent.getInstance().setValue(PROPERTY_NAME, warn);
}
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -135,7 +135,7 @@ public class DomGenPanel {
}
private static String getValue(String name, String defaultValue) {
return PropertiesComponent.getInstance().getOrInit(PREFIX + name, defaultValue);
return PropertiesComponent.getInstance().getValue(PREFIX + name, defaultValue);
}
private static void setValue(String name, String value) {
@@ -53,7 +53,7 @@ public class EditorConfigNotifierProvider extends EditorNotifications.Provider<E
panel.createActionLabel("OK", new Runnable() {
@Override
public void run() {
PropertiesComponent.getInstance(project).setValue(EDITOR_CONFIG_ACCEPTED, "true");
PropertiesComponent.getInstance(project).setValue(EDITOR_CONFIG_ACCEPTED, true);
EditorNotifications.getInstance(project).updateAllNotifications();
}
});
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -111,7 +111,7 @@ public class GradleStartupActivity implements StartupActivity {
}
}
else if (DO_NOT_SHOW_EVENT_DESCRIPTION.equals(e.getDescription())) {
PropertiesComponent.getInstance(project).setValue(SHOW_UNLINKED_GRADLE_POPUP, Boolean.FALSE.toString());
PropertiesComponent.getInstance(project).setValue(SHOW_UNLINKED_GRADLE_POPUP, false, true);
}
}
}
@@ -329,7 +329,7 @@ public class IdeaDecompiler extends ClassFileDecompilers.Light {
@Override
protected void doOKAction() {
super.doOKAction();
PropertiesComponent.getInstance().setValue(LEGAL_NOTICE_KEY, Boolean.TRUE.toString());
PropertiesComponent.getInstance().setValue(LEGAL_NOTICE_KEY, true);
myLegalNoticeAccepted = true;
}
@@ -93,11 +93,11 @@ public class CreateResourceBundleDialogComponent {
myUseXMLBasedPropertiesCheckBox.setVisible(false);
} else {
final String checkBoxSelectedStateKey = getClass() + ".useXmlPropertiesFiles";
myUseXMLBasedPropertiesCheckBox.setSelected(PropertiesComponent.getInstance().getBoolean(checkBoxSelectedStateKey, false));
myUseXMLBasedPropertiesCheckBox.setSelected(PropertiesComponent.getInstance().getBoolean(checkBoxSelectedStateKey));
myUseXMLBasedPropertiesCheckBox.addContainerListener(new ContainerAdapter() {
@Override
public void componentRemoved(ContainerEvent e) {
PropertiesComponent.getInstance().setValue(checkBoxSelectedStateKey, myUseXMLBasedPropertiesCheckBox.isSelected(), false);
PropertiesComponent.getInstance().setValue(checkBoxSelectedStateKey, myUseXMLBasedPropertiesCheckBox.isSelected());
}
});
}
@@ -47,7 +47,7 @@ public class PyStudyShowTutorial extends AbstractProjectComponent {
notification.whenExpired(new Runnable() {
@Override
public void run() {
PropertiesComponent.getInstance().setValue(ourShowPopup, String.valueOf(false));
PropertiesComponent.getInstance().setValue(ourShowPopup, false, true);
}
});
}