mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
ConvertFieldToAtomicIntention#isAvailable: check that getVariable() actually returns something
Should fix EA-107511 - assert: ConvertFieldToAtomicIntention.invoke
This commit is contained in:
+1
-2
@@ -148,7 +148,6 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction
|
||||
else if (var instanceof PsiField) {
|
||||
((PsiField)var).setInitializer(newInitializer);
|
||||
}
|
||||
JavaCodeStyleManager.getInstance(var.getProject()).shortenClassReferences(var.getInitializer());
|
||||
}
|
||||
|
||||
modifierList.setModifierProperty(PsiModifier.FINAL, true);
|
||||
@@ -219,7 +218,7 @@ public class ConvertFieldToAtomicIntention extends PsiElementBaseIntentionAction
|
||||
|
||||
@Override
|
||||
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
|
||||
return myContext.isValid();
|
||||
return getVariable(element) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
// "Convert to atomic" "true"
|
||||
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.*;
|
||||
|
||||
public class InLambdas
|
||||
{
|
||||
public void test()
|
||||
{
|
||||
AtomicInteger x = new AtomicInteger();
|
||||
// Also active at write point if it causes a compilation error
|
||||
Runnable r1 = () -> x.getAndIncrement();
|
||||
Runnable r2 = () -> x.addAndGet(2);
|
||||
Runnable r3 = () -> x.updateAndGet(v -> v * 2);
|
||||
Runnable r4 = () -> x.set(5);
|
||||
System.out.println(x.updateAndGet(v -> v / 3));
|
||||
IntSupplier s = () -> {
|
||||
return x.updateAndGet(v -> v * 2);
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
// "Convert to atomic" "true"
|
||||
|
||||
import java.util.function.*;
|
||||
|
||||
public class InLambdas
|
||||
{
|
||||
public void test()
|
||||
{
|
||||
int x = 0;
|
||||
// Also active at write point if it causes a compilation error
|
||||
Runnable r1 = () -> <caret>x++;
|
||||
Runnable r2 = () -> x+=2;
|
||||
Runnable r3 = () -> x*=2;
|
||||
Runnable r4 = () -> x = 5;
|
||||
System.out.println(x /= 3);
|
||||
IntSupplier s = () -> {
|
||||
return x *= 2;
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user