mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
when inferring purity, honor class initializers (IDEA-CR-15144)
This commit is contained in:
+49
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user