Open kittaakos opened 7 years ago
A very simple example can be found here.
One has to
.mydsl
file.generate-timestamp
option in the preference page.generate-timestamp
in the preferences.The timestamp is being generated into the output file, although I would expect the opposite. Could be that I have messed up something in the code. I will add some tests too.
this was reported here as well: https://www.eclipse.org/forums/index.php/m/1489371/
I took some time to look into the issue again. I wanted to reproduce the same (or at least a very similar) defect by only modifying Xtend preferences in my local Eclipse environment.
By default, Xtend does not generate the @Generated
annotation into the code. So I thought this preference entry would be the perfect candidate to reproduce the issue.
First, I have enabled the @Generated
annotation on the workspace level by setting the preference value to true
, then I've enabled the project-specific preferences and disabled the annotation generation. I've expected that although the annotation generation is disabled at the project-specific level, the annotation is going to be generated due to this defect. It did not happen.
Then I've looked into the code again. For this particular case, I was playing with, a subclass of the OptionsConfigurationBlock
is being used to alter the preferences. This implementation never calls setValue
but the putValue
method instead. The putValue
method does not remove the entry from the preference store if the new value equals to the default one. Only the setValue
does that. So I've changed the code in OptionsConfigurationBlock
, and instead of calling putValue
, I've invoked setValue
. Finally, I was able to reproduce the defect with pure Xtend preferences. That means there is a huge behavior difference between calling the putValue
and the setValue
.
Here is the local change I have made to break the behavior in the Xtend preference page.
diff --git a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/preferences/OptionsConfigurationBlock.java b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/preferences/OptionsConfigurationBlock.java
index 6d026f4..738821c 100755
--- a/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/preferences/OptionsConfigurationBlock.java
+++ b/org.eclipse.xtext.ui/src/org/eclipse/xtext/ui/preferences/OptionsConfigurationBlock.java
@@ -468,7 +468,7 @@
return disabledProjectSettings.put(key, value);
}
String oldValue = getValue(key);
- preferenceStore.putValue(key, value);
+ preferenceStore.setValue(key, value);
return oldValue;
}
@@ -489,7 +489,7 @@
for (int i = 0; i < keys.length; i++) {
String curr = keys[i];
String val = disabledProjectSettings.get(curr);
- preferenceStore.putValue(curr, val);
+ preferenceStore.setValue(curr, val);
}
disabledProjectSettings = null;
updateControls();
Steps to reproduce:
false
default value.true
.false
.true
although I would expectfalse
.In the
FixedScopedPreferenceStore.setValue(String, boolean)
; we remove the project-level preferences because it equals to the default one. Then later, when we are trying to get the value for the project specific preference, we invokeFixedScopedPreferenceStore.internalGet(String)
which delegates to thePreferencesService.get(String, String, Preferences[])
. Although we have the chain of preferences (starting with the project scoped one), we get the workspace level value because we have removed the preference entry from the project-level preferences earlier.