[groovy] @IndexedProperty support: rename
authorDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 31 Oct 2016 15:29:39 +0000 (18:29 +0300)
committerDaniil Ovchinnikov <daniil.ovchinnikov@jetbrains.com>
Mon, 31 Oct 2016 15:31:30 +0000 (18:31 +0300)
plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/transformations/indexedProperty/impl.kt
plugins/groovy/src/META-INF/groovy-indexed-property-support.xml
plugins/groovy/src/org/jetbrains/plugins/groovy/transformations/impl/IndexedPropertyRenameHelper.kt [new file with mode: 0644]
plugins/groovy/test/org/jetbrains/plugins/groovy/transformations/indexedProperty/IndexedPropertyTest.groovy

index f8dd5f56400acecdd6658094585a85049fc32d28..8cf007577160d13b1e5222c35de5eba9fa8daaee 100644 (file)
@@ -27,7 +27,7 @@ import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder
 
 internal val indexedPropertyFqn = "groovy.transform.IndexedProperty"
 internal val indexedPropertyOriginInfo = "by @IndexedProperty"
-internal val indexedMethodKind = "groovy.transform.IndexedProperty.kind"
+val indexedMethodKind = "groovy.transform.IndexedProperty.kind"
 
 internal fun GrField.getIndexedComponentType() = CachedValuesManager.getCachedValue(this) {
   Result.create(doGetIndexedComponentType(this), containingFile)
index f7563a44df4cb4b29ea92195a767691fa74172c3..c2d701a4954deb451a8a2ba70c099a1b379f97b0 100644 (file)
@@ -3,6 +3,7 @@
     <astTransformationSupport
         implementation="org.jetbrains.plugins.groovy.transformations.indexedProperty.IndexedPropertyTransformationSupport"
     />
+    <astTransformationRenameHelper implementation="org.jetbrains.plugins.groovy.transformations.impl.IndexedPropertyRenameHelper"/>
     <customAnnotationChecker
         implementation="org.jetbrains.plugins.groovy.transformations.indexedProperty.IndexedPropertyAnnotationChecker"
     />
diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/transformations/impl/IndexedPropertyRenameHelper.kt b/plugins/groovy/src/org/jetbrains/plugins/groovy/transformations/impl/IndexedPropertyRenameHelper.kt
new file mode 100644 (file)
index 0000000..244e849
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2000-2016 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.jetbrains.plugins.groovy.transformations.impl
+
+import com.intellij.psi.PsiMember
+import org.jetbrains.plugins.groovy.lang.psi.impl.synthetic.GrLightMethodBuilder
+import org.jetbrains.plugins.groovy.transformations.AstTransformationRenameHelper
+import org.jetbrains.plugins.groovy.transformations.indexedProperty.indexedMethodKind
+
+class IndexedPropertyRenameHelper : AstTransformationRenameHelper {
+
+  override fun getNewMemberName(member: PsiMember, newName: String): String? {
+    if (member !is GrLightMethodBuilder || member.methodKind != indexedMethodKind) return null
+    arrayOf("get", "set").filter {
+      member.name.startsWith(it)
+    }.forEach {
+      return it + newName.capitalize()
+    }
+    return null
+  }
+}
\ No newline at end of file
index 43e7d73167e548321c6ed351e1cf4951a055a31f..f1664ae37f6d59d66157b7b4ab90792005ad37a5 100644 (file)
@@ -124,4 +124,36 @@ new A().getStringList(0)
       checkHighlighting()
     }
   }
+
+  void 'test indexed property rename'() {
+    fixture.with {
+      configureByText '_.groovy', '''\
+import groovy.transform.IndexedProperty
+class A {
+  @IndexedProperty List<String> strin<caret>gList
+}
+def a = new A()
+a.stringList
+a.getStringList()
+a.stringList = []
+a.setStringList([])
+a.getStringList(0)
+a.setStringList(0, "") 
+'''
+      renameElementAtCaret 'newName'
+      checkResult '''\
+import groovy.transform.IndexedProperty
+class A {
+  @IndexedProperty List<String> newName
+}
+def a = new A()
+a.newName
+a.getNewName()
+a.newName = []
+a.setNewName([])
+a.getNewName(0)
+a.setNewName(0, "") 
+'''
+    }
+  }
 }