add utility methods for Kotlin code

This commit is contained in:
Daniil Ovchinnikov
2017-08-28 13:33:37 +03:00
parent 931f706bf4
commit da76ef31ba
2 changed files with 54 additions and 0 deletions
@@ -0,0 +1,24 @@
/*
* Copyright 2000-2017 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 com.intellij.psi.util
import com.intellij.psi.PsiElement
import com.intellij.psi.SmartPointerManager
import com.intellij.psi.SmartPsiElementPointer
fun <T : PsiElement> T.createSmartPointer(): SmartPsiElementPointer<T> {
return SmartPointerManager.getInstance(project).createSmartPsiElementPointer(this)
}
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2017 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 com.intellij.psi.util
import com.intellij.psi.PsiElement
inline fun <reified T : PsiElement> PsiElement.parentOfType(): T? {
return PsiTreeUtil.getParentOfType(this, T::class.java)
}
inline fun <reified T : PsiElement> PsiElement?.parentsOfType(): Sequence<T> {
return parentsOfType(T::class.java)
}
fun <T : PsiElement> PsiElement?.parentsOfType(clazz: Class<T>): Sequence<T> {
return generateSequence(this) { it.parent }.filterIsInstance(clazz)
}