unguarded field access: support sync expressions (IDEA-153399)

This commit is contained in:
Anna.Kozlova
2016-03-23 17:20:32 +01:00
parent a3b5e864db
commit 0d30474e77
3 changed files with 46 additions and 1 deletions
@@ -0,0 +1,21 @@
import javax.annotation.concurrent.GuardedBy;
class Example
{
private final Distribution distribution = new Distribution();
public void add(long value)
{
synchronized (distribution) {
distribution.total += value;
<error descr="Cannot resolve symbol 'total'">total</error> += value;
}
}
protected static class Distribution
{
@GuardedBy("this")
private long total = 0;
}
}
@@ -24,11 +24,20 @@ import org.jetbrains.annotations.NotNull;
public class FieldAccessedNotGuardedInspectionTest extends LightCodeInsightFixtureTestCase {
public void testItself() throws Exception {
myFixture.addClass("package net.jcip.annotations;\n" + getGuardedByAnnotationText());
myFixture.testHighlighting(true, false, false, getTestName(true) + ".java");
doTest();
}
public void testJavax_itself() throws Exception {
myFixture.addClass("package javax.annotation.concurrent;\n" + getGuardedByAnnotationText());
doTest();
}
public void testSyncOnFieldQualifier() throws Exception {
myFixture.addClass("package javax.annotation.concurrent;\n" + getGuardedByAnnotationText());
doTest();
}
private void doTest() {
myFixture.testHighlighting(true, false, false, getTestName(true) + ".java");
}