Add utility functions for conversion to light elements

This commit is contained in:
Alexey Sedunov
2014-01-16 17:10:50 +04:00
parent 2c707ec801
commit 75f67d5336
4 changed files with 79 additions and 1 deletions
@@ -50,6 +50,7 @@ public class JetParameterList extends JetElementImplStub<PsiJetParameterListStub
return visitor.visitParameterList(this, data);
}
@NotNull
public List<JetParameter> getParameters() {
return Arrays.asList(getStubOrPsiChildren(JetStubElementTypes.VALUE_PARAMETER, JetParameter.ARRAY_FACTORY));
}
@@ -34,6 +34,7 @@ public class JetTypeParameterList extends JetElementImplStub<PsiJetTypeParameter
super(stub, nodeType);
}
@NotNull
public List<JetTypeParameter> getParameters() {
return Arrays.asList(getStubOrPsiChildren(JetStubElementTypes.TYPE_PARAMETER, JetTypeParameter.ARRAY_FACTORY));
}
@@ -42,6 +42,10 @@ import org.jetbrains.jet.lang.psi.JetParameterList
import org.jetbrains.jet.lang.psi.JetNamedDeclaration
import com.intellij.psi.PsiNamedElement
import org.jetbrains.jet.lang.psi.JetObjectDeclaration
import org.jetbrains.jet.lang.psi.JetNamedFunction
import org.jetbrains.jet.lang.psi.JetProperty
import org.jetbrains.jet.lang.psi.JetCallableDeclaration
import org.jetbrains.jet.lang.psi.JetPropertyAccessor
fun PsiElement.getParentByTypesAndPredicate<T: PsiElement>(
strict : Boolean = false, vararg parentClasses : Class<T>, predicate: (T) -> Boolean
@@ -178,4 +182,14 @@ fun JetDeclaration.isOverridable(): Boolean {
val PsiElement.namedNavigationElement: PsiNamedElement?
get() = getNavigationElement()?.getParentByType(javaClass<PsiNamedElement>())
fun PsiElement.isExtensionDeclaration(): Boolean {
val callable: JetCallableDeclaration? = when (this) {
is JetNamedFunction, is JetProperty -> this as JetCallableDeclaration
is JetPropertyAccessor -> getParentByType(javaClass<JetProperty>())
else -> null
}
return callable?.getReceiverTypeRef() != null
}
fun PsiElement.isObjectLiteral(): Boolean = this is JetObjectDeclaration && isObjectLiteral()