java: convert to atomic: workaround for AtomicBoolean api (IDEA-268471)

GitOrigin-RevId: e5476aeac6558b3ce43cb9039673af88cf06a2dc
This commit is contained in:
Anna Kozlova
2021-05-03 23:05:58 +02:00
committed by intellij-monorepo-bot
parent 47579c0891
commit a03762b5eb
3 changed files with 17 additions and 1 deletions

View File

@@ -218,7 +218,7 @@ public class AtomicConversionRule extends TypeConversionRule {
}
return new TypeConversionDescriptor("$qualifier$ = $val$", "$qualifier$.set($val$)");
}
if (PsiUtil.isLanguageLevel8OrHigher(context)) {
if (PsiUtil.isLanguageLevel8OrHigher(context) && !PsiType.BOOLEAN.equals(from)) {
final String name =
JavaCodeStyleManager.getInstance(context.getProject()).suggestUniqueVariableName("v", context, false);
return new TypeConversionDescriptor("$qualifier$" + sign + "$val$",

View File

@@ -0,0 +1,9 @@
import java.util.concurrent.atomic.AtomicBoolean;
// "Convert to atomic" "true"
class A {
final AtomicBoolean bool = new AtomicBoolean(false);
void testAtomicBool() {
bool.set(bool.get() | Math.random() > 0.5);
}
}

View File

@@ -0,0 +1,7 @@
// "Convert to atomic" "true"
class A {
boolean bo<caret>ol = false;
void testAtomicBool() {
bool |= Math.random() > 0.5;
}
}