when inferring purity, honor class initializers (IDEA-CR-15144)

This commit is contained in:
peter
2016-11-03 14:46:40 +01:00
parent d7122e10d0
commit 0ccc7cdbc7
2 changed files with 50 additions and 1 deletions
@@ -163,6 +163,55 @@ public Foo() {
"""
}
void "test anonymous class initializer"() {
assertPure false, """
Object smth() {
return new I(){{ created++; }};
}
private static int created = 0;
interface I {}
"""
}
void "test simple anonymous class creation"() {
assertPure true, """
Object smth() {
return new I(){};
}
interface I {}
"""
}
void "test anonymous class with arguments"() {
assertPure false, """
Object smth() {
return new I(unknown()){};
}
class I {
I(int a) {}
}
"""
}
void "test class with impure initializer creation"() {
assertPure false, """
Object smth() {
return new I(42);
}
class I {
I(int answer) {}
{
launchMissiles();
}
}
"""
}
private void assertPure(boolean expected, String classBody) {
def clazz = myFixture.addClass("final class Foo { $classBody }")
assert !((PsiFileImpl) clazz.containingFile).contentsLoaded