CodeCleanup plugin ReSharper 8.2
Hallo there!
Im trying to write a Code Cleanup plugin, but can't get it to work. It only fixes the first hit and skips the rest. I did think that I did something wrong so I did go back to the SamplePlugin and trying to find out what I did wrong. But before that I just tested out the SamplePlugin/CodeCleanup and noticed the same problem there.
So when running this code with the sample
var int1 = 2147483647;
var int2 = 2147483647;
var int3 = 2147483647;
var int4 = 2147483647;
the result will be
var int1 = int.MaxValue;
var int2 = 2147483647;
var int3 = 2147483647;
var int4 = 2147483647;
I would expect it to be
var int1 = int.MaxValue;
var int2 = int.MaxValue;
var int3 = int.MaxValue;
var int4 = int.MaxValue;
The code from the sample plugin looks like this.
file.GetPsiServices().Transactions.Execute("Code cleanup",
() =>
{
using (_shellLocks.UsingWriteLock())
file.ProcessChildren<IExpression>(
expression =>
{
ConstantValue value = expression.ConstantValue;
if (value.IsInteger() && Convert.ToInt32(value.Value) == int.MaxValue)
ModificationUtil.ReplaceChild(expression, elementFactory.CreateExpression("int.MaxValue"));
}
);
});
}
Anyone knows if there is a bug in the sample code or in the SDK? Because I cant get ProcessChildren to change more then one child :(
Please sign in to leave a comment.
I have added this to ReSharpers YouTracker now: https://youtrack.jetbrains.com/issue/RSRP-426173