IDEA-52997: Groovy: good code is red. A field and a property of the same name are...
[idea/community.git] / plugins / groovy / test / org / jetbrains / plugins / groovy / lang / resolve / ResolvePropertyTest.groovy
index d75a7e2f73650422584c509225e6e1de10388191..4e04155adbeee073ff7c8c2effcc8562afaf8690 100644 (file)
@@ -352,8 +352,112 @@ print ba<caret>r
 
   public void testStaticFieldAndNonStaticGetter() {
     myFixture.configureByText("Abc.groovy", "print Float.N<caret>aN")
-    def ref=findReference()
-    def resolved=ref.resolve()
+    def ref = findReference()
+    def resolved = ref.resolve()
     assertInstanceOf resolved, PsiField.class
   }
+
+  public void testPropertyAndFieldDeclarationInsideClass() {
+    myFixture.configureByText("a.groovy", """class Foo {
+  def foo
+  public def foo
+
+  def bar() {
+    print fo<caret>o
+  }
+}""")
+    def ref = findReference()
+    def resolved = ref.resolve();
+    assertInstanceOf resolved, GrField.class
+    assertTrue resolved.getModifierList().hasExplicitVisibilityModifiers()
+  }
+
+  public void testPropertyAndFieldDeclarationOutsideClass() {
+    myFixture.configureByText("a.groovy", """class Foo {
+  def foo
+  public def foo
+
+  def bar() {
+    print foo
+  }
+}
+print new Foo().fo<caret>o""")
+    def ref = findReference()
+    def resolved = ref.resolve();
+    assertInstanceOf resolved, GrAccessorMethod.class
+  }
+
+  public void testPropertyAndFieldDeclarationWithSuperClass1() {
+    myFixture.configureByText("a.groovy", """
+class Bar{
+  def foo
+}
+class Foo extends Bar {
+  public def foo
+
+  def bar() {
+    print foo
+  }
+}
+print new Foo().fo<caret>o""")
+    def ref = findReference()
+    def resolved = ref.resolve();
+    assertInstanceOf resolved, GrAccessorMethod.class
+  }
+
+  public void testPropertyAndFieldDeclarationWithSuperClass2() {
+    myFixture.configureByText("a.groovy", """
+class Bar{
+  def foo
+}
+class Foo extends Bar {
+  public def foo
+
+  def bar() {
+    print f<caret>oo
+  }
+}
+print new Foo().foo""")
+    def ref = findReference()
+    def resolved = ref.resolve();
+    assertInstanceOf resolved, GrField.class
+    assertTrue resolved.getModifierList().hasExplicitVisibilityModifiers()
+  }
+
+  public void testPropertyAndFieldDeclarationWithSuperClass3() {
+    myFixture.configureByText("a.groovy", """
+class Bar{
+  public def foo
+}
+class Foo extends Bar {
+  def foo
+
+  def bar() {
+    print foo
+  }
+}
+print new Foo().fo<caret>o""")
+    def ref = findReference()
+    def resolved = ref.resolve();
+    assertInstanceOf resolved, GrAccessorMethod.class
+  }
+  
+  public void testPropertyAndFieldDeclarationWithSuperClass4() {
+    myFixture.configureByText("a.groovy", """
+class Bar{
+  public def foo
+}
+class Foo extends Bar {
+  def foo
+
+  def bar() {
+    print f<caret>oo
+  }
+}
+print new Foo().foo""")
+    def ref = findReference()
+    def resolved = ref.resolve();
+    assertInstanceOf resolved, GrField.class
+    assertTrue !resolved.getModifierList().hasExplicitVisibilityModifiers()
+  }
 }
\ No newline at end of file