Extensions PsiElement.getParentOfType with reified T
1. Renamed *ByType -> *OfType (as in PsiTreeUtil.java) 2. Introduced PsiElement.getStrictParentOfType and PsiElement.getNonStrictParentOfType with reified TP 3. Replaced current usages of PsiTreeUtil.getParentOfType and current extensions 4. Made reified version of PsiElement.getParentOfTypeAndBranch with default strict value --- false (as it used)
This commit is contained in:
+3
-3
@@ -32,8 +32,8 @@ import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument
|
||||
import org.jetbrains.jet.JetNodeTypes
|
||||
import java.math.BigInteger
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class ConstantExpressionEvaluator private (val trace: BindingTrace) : JetVisitor<CompileTimeConstant<*>, JetType>() {
|
||||
|
||||
@@ -257,7 +257,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
assert (name == "minus", "Only negation should be checked for overflow")
|
||||
|
||||
if (receiver.value == result) {
|
||||
trace.report(Errors.INTEGER_OVERFLOW.on(PsiTreeUtil.getParentOfType(callExpression, javaClass<JetExpression>()) ?: callExpression))
|
||||
trace.report(Errors.INTEGER_OVERFLOW.on(callExpression.getStrictParentOfType<JetExpression>() ?: callExpression))
|
||||
}
|
||||
return result
|
||||
}
|
||||
@@ -282,7 +282,7 @@ public class ConstantExpressionEvaluator private (val trace: BindingTrace) : Jet
|
||||
val resultInBigIntegers = checker(toBigInteger(receiver.value), toBigInteger(parameter.value))
|
||||
|
||||
if (toBigInteger(actualResult) != resultInBigIntegers) {
|
||||
trace.report(Errors.INTEGER_OVERFLOW.on(PsiTreeUtil.getParentOfType(callExpression, javaClass<JetExpression>()) ?: callExpression))
|
||||
trace.report(Errors.INTEGER_OVERFLOW.on(callExpression.getStrictParentOfType<JetExpression>() ?: callExpression))
|
||||
}
|
||||
return actualResult
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public fun JetCallElement.getCallNameExpression(): JetSimpleNameExpression? {
|
||||
}
|
||||
}
|
||||
|
||||
public fun PsiElement.getParentByTypesAndPredicate<T: PsiElement>(
|
||||
public fun PsiElement.getParentOfTypesAndPredicate<T: PsiElement>(
|
||||
strict : Boolean = false, vararg parentClasses : Class<T>, predicate: (T) -> Boolean
|
||||
) : T? {
|
||||
var element = if (strict) getParent() else this
|
||||
@@ -69,8 +69,20 @@ public fun PsiElement.getParentByTypesAndPredicate<T: PsiElement>(
|
||||
return null
|
||||
}
|
||||
|
||||
public fun PsiElement.getParentByType<T: PsiElement>(parentClass : Class<T>, strict : Boolean = false) : T? {
|
||||
return PsiTreeUtil.getParentOfType(this, parentClass, strict)
|
||||
public fun PsiElement.getNonStrictParentOfType<T: PsiElement>(parentClass : Class<T>) : T? {
|
||||
return PsiTreeUtil.getParentOfType(this, parentClass, false)
|
||||
}
|
||||
|
||||
inline public fun PsiElement.getParentOfType<reified T: PsiElement>(strict: Boolean): T? {
|
||||
return PsiTreeUtil.getParentOfType(this, javaClass<T>(), strict)
|
||||
}
|
||||
|
||||
inline public fun PsiElement.getStrictParentOfType<reified T: PsiElement>(): T? {
|
||||
return PsiTreeUtil.getParentOfType(this, javaClass<T>(), true)
|
||||
}
|
||||
|
||||
inline public fun PsiElement.getNonStrictParentOfType<reified T: PsiElement>(): T? {
|
||||
return PsiTreeUtil.getParentOfType(this, javaClass<T>(), false)
|
||||
}
|
||||
|
||||
public fun PsiElement?.isAncestor(element: PsiElement, strict: Boolean = false): Boolean {
|
||||
@@ -81,9 +93,8 @@ public fun <T: PsiElement> T.getIfChildIsInBranch(element: PsiElement, branch: T
|
||||
return if (branch().isAncestor(element)) this else null
|
||||
}
|
||||
|
||||
public fun PsiElement.getParentByTypeAndBranch<T: PsiElement>(
|
||||
parentClass : Class<T>, strict : Boolean = false, branch: T.() -> PsiElement?) : T? {
|
||||
return getParentByType(parentClass, strict)?.getIfChildIsInBranch(this, branch)
|
||||
inline public fun PsiElement.getParentOfTypeAndBranch<reified T: PsiElement>(strict: Boolean = false, noinline branch: T.() -> PsiElement?) : T? {
|
||||
return getParentOfType<T>(strict)?.getIfChildIsInBranch(this, branch)
|
||||
}
|
||||
|
||||
public fun JetClassOrObject.effectiveDeclarations(): List<JetDeclaration> =
|
||||
@@ -192,7 +203,7 @@ public fun JetDeclaration.isOverridable(): Boolean {
|
||||
public fun PsiElement.isExtensionDeclaration(): Boolean {
|
||||
val callable: JetCallableDeclaration? = when (this) {
|
||||
is JetNamedFunction, is JetProperty -> this as JetCallableDeclaration
|
||||
is JetPropertyAccessor -> getParentByType(javaClass<JetProperty>())
|
||||
is JetPropertyAccessor -> getNonStrictParentOfType<JetProperty>()
|
||||
else -> null
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext.LABEL_TARGET
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext.FUNCTION
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext.DECLARATION_TO_DESCRIPTOR
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor
|
||||
@@ -34,7 +34,7 @@ public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingConte
|
||||
val targetLabel = getTargetLabel()
|
||||
if (targetLabel != null) return context[LABEL_TARGET, targetLabel]?.let { context[FUNCTION, it] }
|
||||
|
||||
val declarationDescriptor = context[DECLARATION_TO_DESCRIPTOR, getParentByType(javaClass<JetDeclarationWithBody>())]
|
||||
val declarationDescriptor = context[DECLARATION_TO_DESCRIPTOR, getNonStrictParentOfType<JetDeclarationWithBody>()]
|
||||
val containingFunctionDescriptor = DescriptorUtils.getParentOfType(declarationDescriptor, javaClass<FunctionDescriptor>(), false)
|
||||
if (containingFunctionDescriptor == null) return null
|
||||
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import com.intellij.psi.util.PsiModificationTracker
|
||||
import com.intellij.psi.util.CachedValueProvider
|
||||
import com.intellij.psi.util.CachedValue
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import com.intellij.psi.impl.light.LightTypeParameterListBuilder
|
||||
@@ -56,7 +56,7 @@ open public class KotlinLightMethodForDeclaration(
|
||||
private val typeParamsList: CachedValue<PsiTypeParameterList> by Delegates.blockingLazy {
|
||||
val cacheManager = CachedValuesManager.getManager(delegate.getProject())
|
||||
cacheManager.createCachedValue<PsiTypeParameterList>({
|
||||
val declaration = if (origin is JetPropertyAccessor) origin.getParentByType(javaClass<JetProperty>()) else origin
|
||||
val declaration = if (origin is JetPropertyAccessor) origin.getNonStrictParentOfType<JetProperty>() else origin
|
||||
|
||||
val list = if (origin is JetClassOrObject) {
|
||||
LightTypeParameterListBuilder(getManager(), getLanguage())
|
||||
|
||||
@@ -19,7 +19,7 @@ package org.jetbrains.jet.asJava
|
||||
import com.intellij.psi.*
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isExtensionDeclaration
|
||||
import org.jetbrains.jet.utils.addToStdlib.singletonOrEmptyList
|
||||
@@ -64,7 +64,7 @@ public fun PsiElement.getRepresentativeLightMethod(): PsiMethod? =
|
||||
}
|
||||
|
||||
public fun JetParameter.toPsiParameter(): PsiParameter? {
|
||||
val paramList = getParentByType(javaClass<JetParameterList>())
|
||||
val paramList = getNonStrictParentOfType<JetParameterList>()
|
||||
if (paramList == null) return null
|
||||
|
||||
val paramIndex = paramList.getParameters().indexOf(this)
|
||||
@@ -85,11 +85,11 @@ public fun JetParameter.toPsiParameter(): PsiParameter? {
|
||||
}
|
||||
|
||||
public fun JetTypeParameter.toPsiTypeParameters(): List<PsiTypeParameter> {
|
||||
val paramList = getParentByType(javaClass<JetTypeParameterList>())
|
||||
val paramList = getNonStrictParentOfType<JetTypeParameterList>()
|
||||
if (paramList == null) return listOf()
|
||||
|
||||
val paramIndex = paramList.getParameters().indexOf(this)
|
||||
val jetDeclaration = paramList.getParentByType(javaClass<JetDeclaration>()) ?: return listOf()
|
||||
val jetDeclaration = paramList.getNonStrictParentOfType<JetDeclaration>() ?: return listOf()
|
||||
val lightOwners = jetDeclaration.toLightElements()
|
||||
|
||||
return lightOwners.map { lightOwner -> (lightOwner as PsiTypeParameterListOwner).getTypeParameters()[paramIndex] }
|
||||
@@ -100,4 +100,4 @@ public val PsiElement.unwrapped: PsiElement?
|
||||
get() = if (this is KotlinLightElement<*, *>) origin else this
|
||||
|
||||
public val PsiElement.namedUnwrappedElement: PsiNamedElement?
|
||||
get() = unwrapped?.getParentByType(javaClass<PsiNamedElement>())
|
||||
get() = unwrapped?.getNonStrictParentOfType<PsiNamedElement>()
|
||||
@@ -33,13 +33,13 @@ import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.jet.lang.psi.ValueArgument
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall
|
||||
import org.jetbrains.jet.lang.resolve.calls.callUtil.getParentResolvedCall
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
override fun createEnvironment(): JetCoreEnvironment = createEnvironmentWithMockJdk(ConfigurationKind.ALL)
|
||||
@@ -51,7 +51,7 @@ public abstract class AbstractResolvedCallsTest() : JetLiteFixture() {
|
||||
val bindingContext = JvmResolveUtil.analyzeOneFileWithJavaIntegration(jetFile).bindingContext
|
||||
|
||||
val element = jetFile.findElementAt(text.indexOf("<caret>"))
|
||||
val expression = PsiTreeUtil.getParentOfType(element, javaClass<JetExpression>())
|
||||
val expression = element.getStrictParentOfType<JetExpression>()
|
||||
|
||||
val cachedCall = expression?.getParentResolvedCall(bindingContext, strict = false)
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.jet.lang.resolve.ImportPath
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getQualifiedElement
|
||||
import org.jetbrains.jet.lang.resolve.descriptorUtil.getImportableDescriptor
|
||||
import org.jetbrains.jet.plugin.caches.resolve.ResolutionFacade
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public object ShortenReferences {
|
||||
public fun process(element: JetElement) {
|
||||
@@ -192,7 +193,7 @@ public object ShortenReferences {
|
||||
}
|
||||
if (target == null) return false
|
||||
|
||||
val typeReference = PsiTreeUtil.getParentOfType(userType, javaClass<JetTypeReference>())!!
|
||||
val typeReference = userType.getStrictParentOfType<JetTypeReference>()!!
|
||||
val scope = resolutionFacade.analyze(typeReference)[BindingContext.TYPE_RESOLUTION_SCOPE, typeReference]!!
|
||||
val name = target.getName()
|
||||
val targetByName = scope.getClassifier(name)
|
||||
|
||||
@@ -19,10 +19,9 @@ package org.jetbrains.jet.plugin.findUsages
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.lang.psi.JetForExpression
|
||||
import org.jetbrains.jet.lang.psi.JetMultiDeclaration
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetReferenceExpression
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypeAndBranch
|
||||
import org.jetbrains.jet.lang.psi.JetCallableReferenceExpression
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
|
||||
@@ -39,7 +38,7 @@ import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.psi.JetDotQualifiedExpression
|
||||
import org.jetbrains.jet.lang.psi.JetSuperExpression
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorByExpressionSpecifier
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypesAndPredicate
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfTypesAndPredicate
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
@@ -62,6 +61,7 @@ import com.intellij.psi.PsiPackage
|
||||
import org.jetbrains.jet.lang.descriptors.VariableDescriptor
|
||||
import org.jetbrains.jet.plugin.findUsages.UsageTypeEnum.*
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfTypeAndBranch
|
||||
|
||||
public object UsageTypeUtils {
|
||||
public fun getUsageType(element: PsiElement?): UsageTypeEnum? {
|
||||
@@ -70,23 +70,23 @@ public object UsageTypeUtils {
|
||||
is JetMultiDeclaration -> return READ
|
||||
}
|
||||
|
||||
val refExpr = element?.getParentByType(javaClass<JetReferenceExpression>())
|
||||
val refExpr = element?.getNonStrictParentOfType<JetReferenceExpression>()
|
||||
if (refExpr == null) return null
|
||||
|
||||
val context = refExpr.analyze()
|
||||
|
||||
fun getCommonUsageType(): UsageTypeEnum? {
|
||||
return when {
|
||||
refExpr.getParentByType(javaClass<JetImportDirective>()) != null ->
|
||||
refExpr.getNonStrictParentOfType<JetImportDirective>() != null ->
|
||||
CLASS_IMPORT
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetCallableReferenceExpression>()) { getCallableReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<JetCallableReferenceExpression>(){ getCallableReference() } != null ->
|
||||
CALLABLE_REFERENCE
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
|
||||
fun getClassUsageType(): UsageTypeEnum? {
|
||||
val property = refExpr.getParentByType(javaClass<JetProperty>())
|
||||
val property = refExpr.getNonStrictParentOfType<JetProperty>()
|
||||
if (property != null) {
|
||||
when {
|
||||
property.getTypeReference().isAncestor(refExpr) ->
|
||||
@@ -97,7 +97,7 @@ public object UsageTypeUtils {
|
||||
}
|
||||
}
|
||||
|
||||
val function = refExpr.getParentByType(javaClass<JetFunction>())
|
||||
val function = refExpr.getNonStrictParentOfType<JetFunction>()
|
||||
if (function != null) {
|
||||
when {
|
||||
function.getTypeReference().isAncestor(refExpr) ->
|
||||
@@ -108,42 +108,42 @@ public object UsageTypeUtils {
|
||||
}
|
||||
|
||||
return when {
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetTypeParameter>()) { getExtendsBound() } != null
|
||||
|| refExpr.getParentByTypeAndBranch(javaClass<JetTypeConstraint>()) { getBoundTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<JetTypeParameter>(){ getExtendsBound() } != null
|
||||
|| refExpr.getParentOfTypeAndBranch<JetTypeConstraint>(){ getBoundTypeReference() } != null ->
|
||||
TYPE_CONSTRAINT
|
||||
|
||||
refExpr is JetDelegationSpecifier
|
||||
|| refExpr.getParentByTypeAndBranch(javaClass<JetDelegationSpecifier>()) { getTypeReference() } != null ->
|
||||
|| refExpr.getParentOfTypeAndBranch<JetDelegationSpecifier>(){ getTypeReference() } != null ->
|
||||
SUPER_TYPE
|
||||
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetTypedef>()) { getTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<JetTypedef>(){ getTypeReference() } != null ->
|
||||
TYPE_DEFINITION
|
||||
|
||||
refExpr.getParentByType(javaClass<JetTypeProjection>()) != null ->
|
||||
refExpr.getNonStrictParentOfType<JetTypeProjection>() != null ->
|
||||
TYPE_PARAMETER
|
||||
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetParameter>()) { getTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<JetParameter>(){ getTypeReference() } != null ->
|
||||
VALUE_PARAMETER_TYPE
|
||||
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetIsExpression>()) { getTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<JetIsExpression>(){ getTypeReference() } != null ->
|
||||
IS
|
||||
|
||||
with(refExpr.getParentByTypeAndBranch(javaClass<JetBinaryExpressionWithTypeRHS>()) { getRight() }) {
|
||||
with(refExpr.getParentOfTypeAndBranch<JetBinaryExpressionWithTypeRHS>(){ getRight() }) {
|
||||
val opType = this?.getOperationReference()?.getReferencedNameElementType()
|
||||
opType == JetTokens.AS_KEYWORD || opType == JetTokens.AS_SAFE
|
||||
} ->
|
||||
CLASS_CAST_TO
|
||||
|
||||
with(refExpr.getParentByType(javaClass<JetDotQualifiedExpression>())) {
|
||||
with(refExpr.getNonStrictParentOfType<JetDotQualifiedExpression>()) {
|
||||
if (this == null) false
|
||||
else if (getReceiverExpression() == refExpr) true
|
||||
else
|
||||
getSelectorExpression() == refExpr
|
||||
&& getParentByTypeAndBranch(javaClass<JetDotQualifiedExpression>(), true) { getReceiverExpression() } != null
|
||||
&& getParentOfTypeAndBranch<JetDotQualifiedExpression>(strict = true) { getReceiverExpression() } != null
|
||||
} ->
|
||||
CLASS_OBJECT_ACCESS
|
||||
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetSuperExpression>()) { getSuperTypeQualifier() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<JetSuperExpression>(){ getSuperTypeQualifier() } != null ->
|
||||
SUPER_TYPE_QUALIFIER
|
||||
|
||||
else -> null
|
||||
@@ -151,11 +151,11 @@ public object UsageTypeUtils {
|
||||
}
|
||||
|
||||
fun getVariableUsageType(): UsageTypeEnum? {
|
||||
if (refExpr.getParentByTypeAndBranch(javaClass<JetDelegatorByExpressionSpecifier>()) { getDelegateExpression() } != null) {
|
||||
if (refExpr.getParentOfTypeAndBranch<JetDelegatorByExpressionSpecifier>(){ getDelegateExpression() } != null) {
|
||||
return DELEGATE
|
||||
}
|
||||
|
||||
val dotQualifiedExpression = refExpr.getParentByType(javaClass<JetDotQualifiedExpression>())
|
||||
val dotQualifiedExpression = refExpr.getNonStrictParentOfType<JetDotQualifiedExpression>()
|
||||
|
||||
if (dotQualifiedExpression != null) {
|
||||
val parent = dotQualifiedExpression.getParent()
|
||||
@@ -169,11 +169,11 @@ public object UsageTypeUtils {
|
||||
}
|
||||
|
||||
return when {
|
||||
(refExpr.getParentByTypesAndPredicate(false, javaClass<JetBinaryExpression>()) { JetPsiUtil.isAssignment(it) })
|
||||
(refExpr.getParentOfTypesAndPredicate(false, javaClass<JetBinaryExpression>()) { JetPsiUtil.isAssignment(it) })
|
||||
?.getLeft().isAncestor(refExpr) ->
|
||||
WRITE
|
||||
|
||||
refExpr.getParentByType(javaClass<JetSimpleNameExpression>()) != null ->
|
||||
refExpr.getNonStrictParentOfType<JetSimpleNameExpression>() != null ->
|
||||
READ
|
||||
|
||||
else -> null
|
||||
@@ -194,21 +194,21 @@ public object UsageTypeUtils {
|
||||
}
|
||||
|
||||
return when {
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetDelegationSpecifier>()) { getTypeReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<JetDelegationSpecifier>(){ getTypeReference() } != null ->
|
||||
SUPER_TYPE
|
||||
|
||||
descriptor is ConstructorDescriptor
|
||||
&& refExpr.getParentByTypeAndBranch(javaClass<JetAnnotationEntry>()) { getTypeReference() } != null ->
|
||||
&& refExpr.getParentOfTypeAndBranch<JetAnnotationEntry>(){ getTypeReference() } != null ->
|
||||
ANNOTATION
|
||||
|
||||
with(refExpr.getParentByTypeAndBranch(javaClass<JetCallExpression>()) { getCalleeExpression() }) {
|
||||
with(refExpr.getParentOfTypeAndBranch<JetCallExpression>(){ getCalleeExpression() }) {
|
||||
this?.getCalleeExpression() is JetSimpleNameExpression
|
||||
} ->
|
||||
if (descriptor is ConstructorDescriptor) CLASS_NEW_OPERATOR else FUNCTION_CALL
|
||||
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetBinaryExpression>()) { getOperationReference() } != null,
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetUnaryExpression>()) { getOperationReference() } != null,
|
||||
refExpr.getParentByTypeAndBranch(javaClass<JetWhenConditionInRange>()) { getOperationReference() } != null ->
|
||||
refExpr.getParentOfTypeAndBranch<JetBinaryExpression>(){ getOperationReference() } != null,
|
||||
refExpr.getParentOfTypeAndBranch<JetUnaryExpression>(){ getOperationReference() } != null,
|
||||
refExpr.getParentOfTypeAndBranch<JetWhenConditionInRange>(){ getOperationReference() } != null ->
|
||||
FUNCTION_CALL
|
||||
|
||||
else -> null
|
||||
@@ -217,8 +217,8 @@ public object UsageTypeUtils {
|
||||
|
||||
fun getPackageUsageType(): UsageTypeEnum? {
|
||||
return when {
|
||||
refExpr.getParentByType(javaClass<JetPackageDirective>()) != null -> PACKAGE_DIRECTIVE
|
||||
refExpr.getParentByType(javaClass<JetQualifiedExpression>()) != null -> PACKAGE_MEMBER_ACCESS
|
||||
refExpr.getNonStrictParentOfType<JetPackageDirective>() != null -> PACKAGE_DIRECTIVE
|
||||
refExpr.getNonStrictParentOfType<JetQualifiedExpression>() != null -> PACKAGE_MEMBER_ACCESS
|
||||
else -> getClassUsageType()
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@ import org.jetbrains.jet.plugin.quickfix.KotlinSuppressIntentionAction
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.plugin.quickfix.AnnotationHostKind
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
class KotlinSuppressableWarningProblemGroup(
|
||||
private val diagnosticFactory: DiagnosticFactory<*>
|
||||
@@ -86,7 +86,7 @@ private object DeclarationKindDetector : JetVisitor<AnnotationHostKind?, Unit?>(
|
||||
override fun visitClass(d: JetClass, _: Unit?) = detect(d, if (d.isTrait()) "trait" else "class")
|
||||
|
||||
override fun visitClassObject(d: JetClassObject, _: Unit?) = detect(d, "class object",
|
||||
name = "of " + PsiTreeUtil.getParentOfType(d, javaClass<JetClass>())?.getName())
|
||||
name = "of " + d.getStrictParentOfType<JetClass>()?.getName())
|
||||
|
||||
override fun visitNamedFunction(d: JetNamedFunction, _: Unit?) = detect(d, "fun")
|
||||
|
||||
|
||||
+2
-2
@@ -21,7 +21,7 @@ import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypesAndPredicate
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfTypesAndPredicate
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
|
||||
public abstract class JetSelfTargetingIntention<T: JetElement>(protected val key: String, val elementType: Class<T>) : IntentionAction {
|
||||
@@ -37,7 +37,7 @@ public abstract class JetSelfTargetingIntention<T: JetElement>(protected val key
|
||||
|
||||
protected fun getTarget(editor: Editor, file: PsiFile): T? {
|
||||
val offset = editor.getCaretModel().getOffset()
|
||||
return file.findElementAt(offset)?.getParentByTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, editor) }
|
||||
return file.findElementAt(offset)?.getParentOfTypesAndPredicate(false, elementType) { element -> isApplicableTo(element, editor) }
|
||||
}
|
||||
|
||||
public override fun getFamilyName(): String {
|
||||
|
||||
+2
-2
@@ -17,13 +17,13 @@
|
||||
package org.jetbrains.jet.plugin.references
|
||||
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyDelegate
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class JetPropertyDelegationMethodsReference(element: JetPropertyDelegate) : JetMultiReference<JetPropertyDelegate>(element) {
|
||||
|
||||
@@ -34,7 +34,7 @@ public class JetPropertyDelegationMethodsReference(element: JetPropertyDelegate)
|
||||
}
|
||||
|
||||
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
|
||||
val property = PsiTreeUtil.getParentOfType(expression, javaClass<JetProperty>())
|
||||
val property = expression.getStrictParentOfType<JetProperty>()
|
||||
if (property == null) {
|
||||
return Collections.emptyList()
|
||||
}
|
||||
|
||||
+2
-2
@@ -33,10 +33,10 @@ import org.jetbrains.jet.lexer.JetToken
|
||||
import org.jetbrains.jet.plugin.intentions.OperatorToFunctionIntention
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import com.intellij.util.IncorrectOperationException
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypeAndBranch
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.lang.resolve.dataClassUtils.isComponentLike
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfTypeAndBranch
|
||||
|
||||
public class JetSimpleNameReference(
|
||||
jetSimpleNameExpression: JetSimpleNameExpression
|
||||
@@ -45,7 +45,7 @@ public class JetSimpleNameReference(
|
||||
override fun getRangeInElement(): TextRange = TextRange(0, getElement().getTextLength())
|
||||
|
||||
override fun canRename(): Boolean {
|
||||
if (expression.getParentByTypeAndBranch(javaClass<JetWhenConditionInRange>()) { getOperationReference() } != null) return false
|
||||
if (expression.getParentOfTypeAndBranch<JetWhenConditionInRange>(strict = true){ getOperationReference() } != null) return false
|
||||
|
||||
val elementType = expression.getReferencedNameElementType()
|
||||
if (elementType == JetTokens.PLUSPLUS || elementType == JetTokens.MINUSMINUS) return false
|
||||
|
||||
@@ -21,18 +21,19 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.jet.asJava.unwrapped
|
||||
import com.intellij.psi.PsiMethod
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
import java.util.HashSet
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.plugin.intentions.OperatorToFunctionIntention
|
||||
import org.jetbrains.jet.lang.psi.JetQualifiedExpression
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration
|
||||
import org.jetbrains.jet.lang.psi.JetClass
|
||||
import com.intellij.psi.PsiPolyVariantReference
|
||||
import org.jetbrains.jet.utils.emptyOrSingletonList
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
// Navigation element of the resolved reference
|
||||
// For property accessor return enclosing property
|
||||
@@ -42,8 +43,8 @@ public val PsiReference.unwrappedTargets: Set<PsiElement>
|
||||
fun PsiElement.adjust(): PsiElement? {
|
||||
val target = unwrapped
|
||||
return when {
|
||||
target is JetPropertyAccessor -> target.getParentByType(javaClass<JetProperty>())
|
||||
target is JetObjectDeclaration && target.isClassObject() -> target.getParentByType(javaClass<JetClass>())
|
||||
target is JetPropertyAccessor -> target.getNonStrictParentOfType<JetProperty>()
|
||||
target is JetObjectDeclaration && target.isClassObject() -> target.getNonStrictParentOfType<JetClass>()
|
||||
else -> target
|
||||
}
|
||||
}
|
||||
@@ -74,5 +75,5 @@ fun AbstractJetReference<out JetExpression>.renameImplicitConventionalCall(newNa
|
||||
|
||||
val expr = OperatorToFunctionIntention.convert(expression) as JetQualifiedExpression
|
||||
val newCallee = (expr.getSelectorExpression() as JetCallExpression).getCalleeExpression()!!.getReference()!!.handleElementRename(newName)
|
||||
return PsiTreeUtil.getParentOfType<JetQualifiedExpression>(newCallee, javaClass<JetQualifiedExpression>()) as JetExpression
|
||||
return newCallee.getStrictParentOfType<JetQualifiedExpression>() as JetExpression
|
||||
}
|
||||
@@ -54,16 +54,16 @@ fun PsiReference.checkUsageVsOriginalDescriptor(
|
||||
}
|
||||
|
||||
fun PsiReference.isImportUsage(): Boolean =
|
||||
getElement()!!.getParentByType(javaClass<JetImportDirective>()) != null
|
||||
getElement()!!.getNonStrictParentOfType<JetImportDirective>() != null
|
||||
|
||||
fun PsiReference.isConstructorUsage(jetClassOrObject: JetClassOrObject): Boolean = with (getElement()!!) {
|
||||
fun getCallDescriptor(bindingContext: BindingContext): DeclarationDescriptor? {
|
||||
val constructorCalleeExpression = getParentByType(javaClass<JetConstructorCalleeExpression>())
|
||||
val constructorCalleeExpression = getNonStrictParentOfType<JetConstructorCalleeExpression>()
|
||||
if (constructorCalleeExpression != null) {
|
||||
return bindingContext.get(BindingContext.REFERENCE_TARGET, constructorCalleeExpression.getConstructorReferenceExpression())
|
||||
}
|
||||
|
||||
val callExpression = getParentByType(javaClass<JetCallExpression>())
|
||||
val callExpression = getNonStrictParentOfType<JetCallExpression>()
|
||||
if (callExpression != null) {
|
||||
val callee = callExpression.getCalleeExpression()
|
||||
if (callee is JetReferenceExpression) {
|
||||
@@ -75,7 +75,7 @@ fun PsiReference.isConstructorUsage(jetClassOrObject: JetClassOrObject): Boolean
|
||||
}
|
||||
|
||||
fun checkJavaUsage(): Boolean {
|
||||
val call = getParentByType(javaClass<PsiConstructorCall>())
|
||||
val call = getNonStrictParentOfType<PsiConstructorCall>()
|
||||
return call == getParent() && call?.resolveConstructor()?.getContainingClass()?.getNavigationElement() == jetClassOrObject
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ fun PsiReference.isPropertyReadOnlyUsage(): Boolean {
|
||||
if (refTarget is KotlinLightMethod) {
|
||||
val origin = refTarget.origin
|
||||
val declaration: JetNamedDeclaration? = when (origin) {
|
||||
is JetPropertyAccessor -> origin.getParentByType(javaClass<JetProperty>())
|
||||
is JetPropertyAccessor -> origin.getNonStrictParentOfType<JetProperty>()
|
||||
is JetProperty, is JetParameter -> origin as JetNamedDeclaration
|
||||
else -> null
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||
import org.jetbrains.jet.lang.resolve.descriptorUtil.isExtension
|
||||
import com.intellij.openapi.progress.ProcessCanceledException
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
//NOTE: this class is based on CopyPasteReferenceProcessor and JavaCopyPasteReferenceProcessor
|
||||
public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<ReferenceTransferableData>() {
|
||||
@@ -340,7 +341,7 @@ public class KotlinCopyPasteReferenceProcessor() : CopyPastePostProcessor<Refere
|
||||
parent.replace(createQualifiedExpression(psiFactory, text))
|
||||
}
|
||||
else if (parent is JetUserType) {
|
||||
val typeReference = PsiTreeUtil.getParentOfType(expression, javaClass<JetTypeReference>())
|
||||
val typeReference = expression.getStrictParentOfType<JetTypeReference>()
|
||||
LOG.assertTrue(typeReference != null, "JetUserType is expected to have parent of type JetTypeReference:\n" +
|
||||
"At: ${DiagnosticUtils.atLocation(expression)}\nFILE:\n${expression.getContainingFile()!!.getText()}")
|
||||
typeReference!!.replace(psiFactory.createType("$prefixToInsert.${typeReference.getText()}"))
|
||||
|
||||
@@ -396,7 +396,7 @@ public class JetExpressionMover extends AbstractJetUpDownMover {
|
||||
@Nullable
|
||||
private static PsiElement getMovableElement(@NotNull PsiElement element, boolean lookRight) {
|
||||
//noinspection unchecked
|
||||
PsiElement movableElement = PsiUtilPackage.getParentByTypesAndPredicate(
|
||||
PsiElement movableElement = PsiUtilPackage.getParentOfTypesAndPredicate(
|
||||
element,
|
||||
false,
|
||||
MOVABLE_ELEMENT_CLASSES,
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
|
||||
import org.jetbrains.jet.utils.addToStdlib.firstIsInstanceOrNull
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
class CompletionSessionConfiguration(
|
||||
val completeNonImportedDeclarations: Boolean,
|
||||
@@ -202,12 +203,12 @@ class BasicCompletionSession(configuration: CompletionSessionConfiguration,
|
||||
}
|
||||
|
||||
private fun isOnlyKeywordCompletion()
|
||||
= PsiTreeUtil.getParentOfType(position, javaClass<JetModifierList>()) != null
|
||||
= position.getStrictParentOfType<JetModifierList>() != null
|
||||
|
||||
private fun shouldRunOnlyTypeCompletion(): Boolean {
|
||||
// Check that completion in the type annotation context and if there's a qualified
|
||||
// expression we are at first of it
|
||||
val typeReference = PsiTreeUtil.getParentOfType(position, javaClass<JetTypeReference>())
|
||||
val typeReference = position.getStrictParentOfType<JetTypeReference>()
|
||||
if (typeReference != null) {
|
||||
val firstPartReference = PsiTreeUtil.findChildOfType(typeReference, javaClass<JetSimpleNameExpression>())
|
||||
return firstPartReference == jetReference!!.expression
|
||||
|
||||
@@ -27,12 +27,12 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder
|
||||
import com.intellij.psi.PsiErrorElement
|
||||
import org.jetbrains.jet.lexer.JetKeywordToken
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.plugin.completion.handlers.KotlinKeywordInsertHandler
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.siblings
|
||||
|
||||
import org.jetbrains.jet.lexer.JetTokens.*
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.prevLeafSkipWhitespacesAndComments
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
class KeywordLookupObject(val keyword: String)
|
||||
|
||||
@@ -162,7 +162,7 @@ object KeywordCompletion {
|
||||
when {
|
||||
nodeType != keywordTokenType -> false
|
||||
|
||||
elementAt.getParentByType(javaClass<PsiErrorElement>(), strict = false) != null -> false
|
||||
elementAt.getNonStrictParentOfType<PsiErrorElement>() != null -> false
|
||||
|
||||
elementAt.prevLeafSkipWhitespacesAndComments() is PsiErrorElement -> false
|
||||
|
||||
|
||||
@@ -49,6 +49,7 @@ import org.jetbrains.jet.lang.psi.JetFunctionLiteral
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.prevLeafSkipWhitespacesAndComments
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgument
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgumentList
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
public class KotlinCompletionContributor : CompletionContributor() {
|
||||
|
||||
@@ -215,7 +216,7 @@ public class KotlinCompletionContributor : CompletionContributor() {
|
||||
|
||||
// no completion in comments
|
||||
// TODO: this must be changed if we will have references in doc-comments
|
||||
if (PsiTreeUtil.getParentOfType(position, javaClass<PsiComment>(), false) != null) return true
|
||||
if (position.getNonStrictParentOfType<PsiComment>() != null) return true
|
||||
|
||||
// no completion inside number literals
|
||||
if (AFTER_NUMBER_LITERAL.accepts(position)) return true
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.jetbrains.jet.plugin.completion
|
||||
|
||||
import org.jetbrains.jet.lang.psi.JetValueArgument
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetCallElement
|
||||
import org.jetbrains.jet.plugin.references.JetReference
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
@@ -40,6 +39,7 @@ import com.intellij.codeInsight.completion.InsertHandler
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.jet.plugin.completion.handlers.WithTailInsertHandler
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
object NamedParametersCompletion {
|
||||
private val positionFilter = AndFilter(
|
||||
@@ -56,9 +56,9 @@ object NamedParametersCompletion {
|
||||
public fun isOnlyNamedParameterExpected(position: PsiElement): Boolean {
|
||||
if (!positionFilter.isAcceptable(position, position)) return false
|
||||
|
||||
val thisArgument = PsiTreeUtil.getParentOfType(position, javaClass<JetValueArgument>())!!
|
||||
val thisArgument = position.getStrictParentOfType<JetValueArgument>()!!
|
||||
|
||||
val callElement = PsiTreeUtil.getParentOfType(thisArgument, javaClass<JetCallElement>()) ?: return false
|
||||
val callElement = thisArgument.getStrictParentOfType<JetCallElement>() ?: return false
|
||||
|
||||
for (argument in callElement.getValueArguments()) {
|
||||
if (argument == thisArgument) break
|
||||
@@ -71,9 +71,9 @@ object NamedParametersCompletion {
|
||||
public fun complete(position: PsiElement, collector: LookupElementsCollector) {
|
||||
if (!positionFilter.isAcceptable(position, position)) return
|
||||
|
||||
val valueArgument = PsiTreeUtil.getParentOfType(position, javaClass<JetValueArgument>())!!
|
||||
val valueArgument = position.getStrictParentOfType<JetValueArgument>()!!
|
||||
|
||||
val callElement = PsiTreeUtil.getParentOfType(valueArgument, javaClass<JetCallElement>()) ?: return
|
||||
val callElement = valueArgument.getStrictParentOfType<JetCallElement>() ?: return
|
||||
val callSimpleName = callElement.getCallNameExpression() ?: return
|
||||
|
||||
val callReference = callSimpleName.getReference() as JetReference
|
||||
|
||||
+4
-4
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.completion.InsertionContext
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective
|
||||
import com.intellij.codeInsight.AutoPopupController
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
@@ -38,6 +37,7 @@ import org.jetbrains.jet.plugin.completion.DeclarationDescriptorLookupObject
|
||||
import org.jetbrains.jet.lang.descriptors.CallableDescriptor
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public abstract class KotlinCallableInsertHandler : BaseDeclarationInsertHandler() {
|
||||
public override fun handleInsert(context: InsertionContext, item: LookupElement) {
|
||||
@@ -60,7 +60,7 @@ public abstract class KotlinCallableInsertHandler : BaseDeclarationInsertHandler
|
||||
if (file is JetFile && o is DeclarationDescriptorLookupObject) {
|
||||
val descriptor = o.descriptor as? CallableDescriptor
|
||||
if (descriptor != null) {
|
||||
if (PsiTreeUtil.getParentOfType(element, javaClass<JetQualifiedExpression>()) != null &&
|
||||
if (element.getStrictParentOfType<JetQualifiedExpression>() != null &&
|
||||
descriptor.getExtensionReceiverParameter() == null) {
|
||||
return@runReadAction
|
||||
}
|
||||
@@ -103,7 +103,7 @@ public class KotlinFunctionInsertHandler(val caretPosition : CaretPosition, val
|
||||
val element = context.getFile().findElementAt(startOffset) ?: return
|
||||
|
||||
when {
|
||||
PsiTreeUtil.getParentOfType(element, javaClass<JetImportDirective>()) != null -> return
|
||||
element.getStrictParentOfType<JetImportDirective>() != null -> return
|
||||
|
||||
isInfixCall(element) -> {
|
||||
if (context.getCompletionChar() == ' ') {
|
||||
@@ -194,7 +194,7 @@ public class KotlinFunctionInsertHandler(val caretPosition : CaretPosition, val
|
||||
public val WITH_PARAMETERS_HANDLER: KotlinFunctionInsertHandler = KotlinFunctionInsertHandler(CaretPosition.IN_BRACKETS, null)
|
||||
|
||||
private fun shouldAddBrackets(element : PsiElement) : Boolean {
|
||||
return PsiTreeUtil.getParentOfType(element, javaClass<JetImportDirective>()) == null
|
||||
return element.getStrictParentOfType<JetImportDirective>() == null
|
||||
}
|
||||
|
||||
private fun indexOfSkippingSpace(document: Document, ch : Char, startIndex : Int) : Int {
|
||||
|
||||
@@ -19,10 +19,10 @@ package org.jetbrains.jet.plugin.completion.handlers
|
||||
import com.intellij.codeInsight.completion.InsertHandler
|
||||
import com.intellij.codeInsight.completion.InsertionContext
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetFunction
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
|
||||
private val NO_SPACE_AFTER = setOf(JetTokens.THIS_KEYWORD.toString(),
|
||||
@@ -46,7 +46,7 @@ public object KotlinKeywordInsertHandler : InsertHandler<LookupElement> {
|
||||
if (keyword == JetTokens.RETURN_KEYWORD.toString()) {
|
||||
val element = context.getFile().findElementAt(context.getStartOffset())
|
||||
if (element != null) {
|
||||
val jetFunction = PsiTreeUtil.getParentOfType(element, javaClass<JetFunction>())
|
||||
val jetFunction = element.getStrictParentOfType<JetFunction>()
|
||||
if (jetFunction != null && (!jetFunction.hasDeclaredReturnType() || JetPsiUtil.isVoidType(jetFunction.getTypeReference()))) {
|
||||
// No space for void function
|
||||
return false
|
||||
|
||||
@@ -35,7 +35,6 @@ import com.intellij.debugger.settings.NodeRendererSettings
|
||||
import com.intellij.psi.PsiClass
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.debugger.SourcePosition
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.debugger.impl.DebuggerContextUtil
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import com.sun.jdi.AbsentInformationException
|
||||
@@ -46,6 +45,7 @@ import org.jetbrains.jet.lang.resolve.java.JvmClassName
|
||||
import com.sun.jdi.ReferenceType
|
||||
import org.jetbrains.jet.codegen.AsmUtil
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public open class KotlinObjectRenderer : ClassRenderer() {
|
||||
|
||||
@@ -129,7 +129,7 @@ public class KotlinObjectFieldDescriptor(
|
||||
if (position != null) {
|
||||
val element = position.getElementAt()
|
||||
if (element != null) {
|
||||
return PsiTreeUtil.getParentOfType(element, javaClass<JetClassOrObject>())
|
||||
return element.getStrictParentOfType<JetClassOrObject>()
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
@@ -22,7 +22,6 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.util.text.CharArrayUtil
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettingsManager
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiWhiteSpace
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
@@ -37,6 +36,7 @@ import com.intellij.psi.tree.TokenSet
|
||||
import org.jetbrains.jet.JetNodeTypes
|
||||
import org.jetbrains.jet.lang.psi.JetLoopExpression
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class KotlinSmartEnterHandler: SmartEnterProcessorWithFixers() {
|
||||
{
|
||||
@@ -106,7 +106,7 @@ public class KotlinSmartEnterHandler: SmartEnterProcessorWithFixers() {
|
||||
val settings = CodeStyleSettingsManager.getSettings(file.getProject())
|
||||
val old = settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE
|
||||
settings.KEEP_SIMPLE_BLOCKS_IN_ONE_LINE = false
|
||||
val elt = PsiTreeUtil.getParentOfType(file.findElementAt(caretOffset - 1), javaClass<JetBlockExpression>())
|
||||
val elt = file.findElementAt(caretOffset - 1).getStrictParentOfType<JetBlockExpression>()
|
||||
if (elt != null) {
|
||||
reformat(elt)
|
||||
}
|
||||
|
||||
+2
-2
@@ -20,13 +20,13 @@ import com.intellij.lang.SmartEnterProcessorWithFixers
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.jet.plugin.editor.KotlinSmartEnterHandler
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
import org.jetbrains.jet.lang.psi.JetFunction
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
|
||||
public class KotlinFunctionDeclarationBodyFixer : SmartEnterProcessorWithFixers.Fixer<KotlinSmartEnterHandler>() {
|
||||
@@ -34,7 +34,7 @@ public class KotlinFunctionDeclarationBodyFixer : SmartEnterProcessorWithFixers.
|
||||
if (psiElement !is JetNamedFunction) return
|
||||
if (psiElement.getBodyExpression() != null|| psiElement.getEqualsToken() != null) return
|
||||
|
||||
val parentDeclaration = PsiTreeUtil.getParentOfType(psiElement, javaClass<JetDeclaration>())
|
||||
val parentDeclaration = psiElement.getStrictParentOfType<JetDeclaration>()
|
||||
if (parentDeclaration is JetClassOrObject) {
|
||||
if (JetPsiUtil.isTrait(parentDeclaration) || psiElement.hasModifier(JetTokens.ABSTRACT_KEYWORD)) {
|
||||
return
|
||||
|
||||
@@ -23,12 +23,12 @@ import com.intellij.usages.rules.ImportFilteringRule
|
||||
import com.intellij.usages.rules.PsiElementUsage
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
public class JetImportFilteringRule : ImportFilteringRule() {
|
||||
public override fun isVisible(usage: Usage): Boolean {
|
||||
if (usage is PsiElementUsage) {
|
||||
return usage.getElement()?.getParentByType(javaClass<JetImportDirective>()) == null
|
||||
return usage.getElement()?.getNonStrictParentOfType<JetImportDirective>() == null
|
||||
}
|
||||
|
||||
return true
|
||||
|
||||
@@ -70,11 +70,11 @@ public class HierarchyUtils {
|
||||
|
||||
public static PsiElement getCallHierarchyElement(PsiElement element) {
|
||||
//noinspection unchecked
|
||||
return PsiUtilPackage.getParentByTypesAndPredicate(element, false, ArrayUtil.EMPTY_CLASS_ARRAY, IS_CALL_HIERARCHY_ELEMENT);
|
||||
return PsiUtilPackage.getParentOfTypesAndPredicate(element, false, ArrayUtil.EMPTY_CLASS_ARRAY, IS_CALL_HIERARCHY_ELEMENT);
|
||||
}
|
||||
|
||||
public static PsiElement getOverrideHierarchyElement(PsiElement element) {
|
||||
//noinspection unchecked
|
||||
return PsiUtilPackage.getParentByTypesAndPredicate(element, false, ArrayUtil.EMPTY_CLASS_ARRAY, IS_OVERRIDE_HIERARCHY_ELEMENT);
|
||||
return PsiUtilPackage.getParentOfTypesAndPredicate(element, false, ArrayUtil.EMPTY_CLASS_ARRAY, IS_OVERRIDE_HIERARCHY_ELEMENT);
|
||||
}
|
||||
}
|
||||
@@ -76,7 +76,7 @@ public abstract class KotlinCallTreeStructure extends HierarchyTreeStructure {
|
||||
@Nullable
|
||||
protected static PsiMethod getRepresentativePsiMethod(PsiElement element) {
|
||||
while (true) {
|
||||
element = PsiUtilPackage.getParentByTypesAndPredicate(element, false, ArrayUtil.EMPTY_CLASS_ARRAY, IS_NON_LOCAL_DECLARATION);
|
||||
element = PsiUtilPackage.getParentOfTypesAndPredicate(element, false, ArrayUtil.EMPTY_CLASS_ARRAY, IS_NON_LOCAL_DECLARATION);
|
||||
if (element == null) return null;
|
||||
|
||||
PsiMethod method = getRepresentativePsiMethodForNonLocalDeclaration(element);
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.progress.ProgressIndicatorProvider
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiFile
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath
|
||||
import org.jetbrains.jet.lang.resolve.name.*
|
||||
@@ -29,6 +28,7 @@ import org.jetbrains.jet.plugin.references.JetReference
|
||||
import java.util.HashSet
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.plugin.quickfix.ImportInsertHelper
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class KotlinImportOptimizer() : ImportOptimizer {
|
||||
|
||||
@@ -80,8 +80,8 @@ public class KotlinImportOptimizer() : ImportOptimizer {
|
||||
}
|
||||
|
||||
override fun visitJetElement(element: JetElement) {
|
||||
if (PsiTreeUtil.getParentOfType(element, javaClass<JetImportDirective>()) != null ||
|
||||
PsiTreeUtil.getParentOfType(element, javaClass<JetPackageDirective>()) != null) {
|
||||
if (element.getStrictParentOfType<JetImportDirective>() != null ||
|
||||
element.getStrictParentOfType<JetPackageDirective>() != null) {
|
||||
return
|
||||
}
|
||||
val reference = element.getReference()
|
||||
|
||||
@@ -20,10 +20,10 @@ import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() {
|
||||
override fun getFamilyName(): String = JetBundle.message("convert.to.block.body.action.family.name")
|
||||
@@ -76,7 +76,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() {
|
||||
}
|
||||
|
||||
private fun findDeclaration(element: PsiElement): JetDeclarationWithBody? {
|
||||
val declaration = PsiTreeUtil.getParentOfType(element, javaClass<JetDeclarationWithBody>())
|
||||
val declaration = element.getStrictParentOfType<JetDeclarationWithBody>()
|
||||
if (declaration == null || declaration is JetFunctionLiteral || declaration.hasBlockBody()) return null
|
||||
val body = declaration.getBodyExpression()
|
||||
if (body == null) return null
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
@@ -28,6 +27,7 @@ import org.jetbrains.jet.lexer.JetTokens
|
||||
import com.intellij.openapi.util.TextRange
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptorWithVisibility
|
||||
import org.jetbrains.jet.plugin.caches.resolve.resolveToDescriptor
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() {
|
||||
override fun getFamilyName(): String = JetBundle.message("convert.to.expression.body.action.family.name")
|
||||
@@ -70,7 +70,7 @@ public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() {
|
||||
private data class Data(val declaration: JetDeclarationWithBody, val value: JetExpression)
|
||||
|
||||
private fun calcData(element: PsiElement): Data? {
|
||||
val declaration = PsiTreeUtil.getParentOfType(element, javaClass<JetDeclarationWithBody>())
|
||||
val declaration = element.getStrictParentOfType<JetDeclarationWithBody>()
|
||||
if (declaration == null || declaration is JetFunctionLiteral) return null
|
||||
val body = declaration.getBodyExpression()
|
||||
if (!declaration.hasBlockBody() || body !is JetBlockExpression) return null
|
||||
|
||||
+3
-3
@@ -21,7 +21,6 @@ import com.intellij.openapi.editor.Editor
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.refactoring.rename.inplace.VariableInplaceRenameHandler
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteralExpression
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
@@ -33,10 +32,11 @@ import org.jetbrains.jet.lang.psi.JetFunctionLiteral
|
||||
import org.jetbrains.jet.plugin.references.JetReference
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class ReplaceItWithExplicitFunctionLiteralParamIntention() : PsiElementBaseIntentionAction() {
|
||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||
val simpleNameExpression = PsiTreeUtil.getParentOfType(element, javaClass<JetSimpleNameExpression>())!!
|
||||
val simpleNameExpression = element.getStrictParentOfType<JetSimpleNameExpression>()!!
|
||||
|
||||
val simpleNameReference = simpleNameExpression.getReference() as JetReference?
|
||||
val target = simpleNameReference?.resolveToDescriptors()?.first()!!
|
||||
@@ -55,7 +55,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : PsiElementBa
|
||||
}
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean {
|
||||
val simpleNameExpression = PsiTreeUtil.getParentOfType(element, javaClass<JetSimpleNameExpression>())
|
||||
val simpleNameExpression = element.getStrictParentOfType<JetSimpleNameExpression>()
|
||||
if (simpleNameExpression == null || !isAutoCreatedIt(simpleNameExpression)) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ import com.intellij.openapi.editor.Editor
|
||||
import org.jetbrains.jet.lang.psi.JetBinaryExpression
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lexer.JetTokens
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
@@ -52,7 +52,7 @@ public class SplitIfIntention : JetSelfTargetingIntention<JetExpression>("split.
|
||||
else -> element as JetSimpleNameExpression
|
||||
}
|
||||
|
||||
val ifExpression = currentElement!!.getParentByType(javaClass<JetIfExpression>())
|
||||
val ifExpression = currentElement!!.getNonStrictParentOfType<JetIfExpression>()
|
||||
val expression = currentElement.getParent() as JetBinaryExpression
|
||||
val rightExpression = getRight(expression, ifExpression!!.getCondition() as JetExpression)
|
||||
val leftExpression = expression.getLeft()
|
||||
|
||||
+3
-2
@@ -24,6 +24,7 @@ import org.jetbrains.jet.lang.descriptors.ClassKind
|
||||
import org.jetbrains.jet.lang.psi.JetClass
|
||||
import org.jetbrains.jet.lang.psi.JetParameterList
|
||||
import org.jetbrains.jet.lang.psi.JetNamedDeclaration
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
/**
|
||||
* Special <code>Expression</code> for parameter names based on its type.
|
||||
@@ -61,7 +62,7 @@ private class ParameterNameExpression(
|
||||
}
|
||||
|
||||
// add names based on selected type
|
||||
val parameter = PsiTreeUtil.getParentOfType(elementAt, javaClass<JetParameter>())
|
||||
val parameter = elementAt.getStrictParentOfType<JetParameter>()
|
||||
if (parameter != null) {
|
||||
val parameterTypeRef = parameter.getTypeReference()
|
||||
if (parameterTypeRef != null) {
|
||||
@@ -138,7 +139,7 @@ private class TypeParameterListExpression(private val mandatoryTypeParameters: L
|
||||
val editor = context.getEditor()!!
|
||||
val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()) as JetFile
|
||||
val elementAt = file.findElementAt(offset)
|
||||
val declaration = PsiTreeUtil.getParentOfType(elementAt, javaClass<JetNamedDeclaration>()) ?: return TextResult("")
|
||||
val declaration = elementAt.getStrictParentOfType<JetNamedDeclaration>() ?: return TextResult("")
|
||||
|
||||
val renderedTypeParameters = LinkedHashSet<RenderedTypeParameter>()
|
||||
renderedTypeParameters.addAll(mandatoryTypeParameters)
|
||||
|
||||
+2
-2
@@ -35,7 +35,7 @@ import kotlin.properties.Delegates
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.jet.plugin.util.makeNotNullable
|
||||
import org.jetbrains.jet.lang.psi.JetAnnotationEntry
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
private fun JetType.contains(inner: JetType): Boolean {
|
||||
return JetTypeChecker.DEFAULT.equalTypes(this, inner) || getArguments().any { inner in it.getType() }
|
||||
@@ -95,7 +95,7 @@ fun JetExpression.guessTypes(
|
||||
if (coerceUnusedToUnit
|
||||
&& this !is JetDeclaration
|
||||
&& isUsedAsStatement(context)
|
||||
&& getParentByType(javaClass<JetAnnotationEntry>()) == null) return array(builtIns.getUnitType())
|
||||
&& getNonStrictParentOfType<JetAnnotationEntry>() == null) return array(builtIns.getUnitType())
|
||||
|
||||
// if we know the actual type of the expression
|
||||
val theType1 = context[BindingContext.EXPRESSION_TYPE, this]
|
||||
|
||||
+3
-3
@@ -2,7 +2,7 @@ package org.jetbrains.jet.plugin.quickfix.createFromUsage.createClass
|
||||
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference
|
||||
import org.jetbrains.jet.lang.psi.JetCallExpression
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
@@ -21,9 +21,9 @@ import java.util.Collections
|
||||
public object CreateClassFromConstructorCallActionFactory: JetSingleIntentionActionFactory() {
|
||||
override fun createAction(diagnostic: Diagnostic): IntentionAction? {
|
||||
val diagElement = diagnostic.getPsiElement()
|
||||
if (diagElement.getParentByType(javaClass<JetTypeReference>()) != null) return null
|
||||
if (diagElement.getNonStrictParentOfType<JetTypeReference>() != null) return null
|
||||
|
||||
val inAnnotationEntry = diagElement.getParentByType(javaClass<JetAnnotationEntry>()) != null
|
||||
val inAnnotationEntry = diagElement.getNonStrictParentOfType<JetAnnotationEntry>() != null
|
||||
|
||||
val callExpr = diagElement.getParent() as? JetCallExpression ?: return null
|
||||
if (callExpr.getCalleeExpression() != diagElement) return null
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@ import org.jetbrains.jet.lang.diagnostics.Diagnostic
|
||||
import com.intellij.codeInsight.intention.IntentionAction
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetTypeReference
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.plugin.quickfix.JetIntentionActionsFactory
|
||||
@@ -32,7 +32,7 @@ import org.jetbrains.jet.utils.addToStdlib.singletonOrEmptyList
|
||||
public object CreateClassFromReferenceExpressionActionFactory : JetIntentionActionsFactory() {
|
||||
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> {
|
||||
val refExpr = diagnostic.getPsiElement() as? JetSimpleNameExpression ?: return Collections.emptyList()
|
||||
if (refExpr.getParentByType(javaClass<JetTypeReference>()) != null) return Collections.emptyList()
|
||||
if (refExpr.getNonStrictParentOfType<JetTypeReference>() != null) return Collections.emptyList()
|
||||
|
||||
val file = refExpr.getContainingFile() as? JetFile ?: return Collections.emptyList()
|
||||
|
||||
@@ -48,7 +48,7 @@ public object CreateClassFromReferenceExpressionActionFactory : JetIntentionActi
|
||||
}
|
||||
} as? JetExpression ?: return Collections.emptyList()
|
||||
|
||||
val inImport = refExpr.getParentByType(javaClass<JetImportDirective>()) != null
|
||||
val inImport = refExpr.getNonStrictParentOfType<JetImportDirective>() != null
|
||||
val qualifierExpected = refExpr.isDotReceiver() || ((refExpr.getParent() as? JetDotQualifiedExpression)?.isDotReceiver() ?: false)
|
||||
|
||||
if (inImport || qualifierExpected) {
|
||||
|
||||
+2
-2
@@ -14,7 +14,7 @@ import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.Qualifier
|
||||
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.*
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import java.util.Collections
|
||||
import org.jetbrains.jet.plugin.refactoring.getExtractionContainers
|
||||
@@ -39,7 +39,7 @@ object CreateFunctionOrPropertyFromCallActionFactory : JetSingleIntentionActionF
|
||||
}
|
||||
|
||||
Errors.NO_VALUE_FOR_PARAMETER,
|
||||
Errors.TOO_MANY_ARGUMENTS -> diagElement.getParentByType(javaClass<JetCallExpression>())
|
||||
Errors.TOO_MANY_ARGUMENTS -> diagElement.getNonStrictParentOfType<JetCallExpression>()
|
||||
|
||||
else -> throw AssertionError("Unexpected diagnostic: ${diagnostic.getFactory()}")
|
||||
} as? JetExpression ?: return null
|
||||
|
||||
+2
-2
@@ -10,7 +10,7 @@ import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.Functio
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import org.jetbrains.jet.plugin.quickfix.createFromUsage.callableBuilder.CallableInfo
|
||||
@@ -29,7 +29,7 @@ object CreatePropertyDelegateAccessorsActionFactory : JetSingleIntentionActionFa
|
||||
|
||||
val builtIns = KotlinBuiltIns.getInstance()
|
||||
|
||||
val property = expression.getParentByType(javaClass<JetProperty>()) ?: return null
|
||||
val property = expression.getNonStrictParentOfType<JetProperty>() ?: return null
|
||||
val propertyDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, property] as? PropertyDescriptor
|
||||
?: return null
|
||||
|
||||
|
||||
+4
-2
@@ -19,16 +19,18 @@ package org.jetbrains.jet.plugin.refactoring.changeSignature.usages
|
||||
import org.jetbrains.jet.lang.psi.JetEnumEntry
|
||||
import org.jetbrains.jet.plugin.refactoring.changeSignature.JetChangeInfo
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetClass
|
||||
import org.jetbrains.jet.lang.psi.JetDelegatorToSuperCall
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public class JetEnumEntryWithoutSuperCallUsage(enumEntry: JetEnumEntry) : JetUsageInfo<JetEnumEntry>(enumEntry) {
|
||||
override fun processUsage(changeInfo: JetChangeInfo, element: JetEnumEntry): Boolean {
|
||||
if (changeInfo.getNewParameters().size > 0) {
|
||||
val psiFactory = JetPsiFactory(element)
|
||||
|
||||
val enumClass = element.getParentByType(javaClass<JetClass>(), true)!!
|
||||
val enumClass = element.getStrictParentOfType<JetClass>()!!
|
||||
val delegatorToSuperCall = element.addAfter(
|
||||
psiFactory.createDelegatorToSuperCall("${enumClass.getName()}()"),
|
||||
element.getNameAsDeclaration()
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.jetbrains.jet.lang.psi.JetSuperExpression
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ThisReceiver
|
||||
import org.jetbrains.jet.lang.descriptors.ClassKind
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration
|
||||
import org.jetbrains.jet.lang.psi.JetDeclarationWithBody
|
||||
import org.jetbrains.jet.lang.psi.JetUserType
|
||||
@@ -52,6 +52,8 @@ import org.jetbrains.jet.lang.psi.JetClassInitializer
|
||||
import org.jetbrains.jet.lang.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.jet.plugin.util.psi.patternMatching.JetPsiRange
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
data class ExtractionOptions(
|
||||
val inferUnitTypeForUnusedValues: Boolean,
|
||||
@@ -84,7 +86,7 @@ data class ExtractionData(
|
||||
val project: Project = originalFile.getProject()
|
||||
val originalElements: List<PsiElement> = originalRange.elements
|
||||
|
||||
val insertBefore: Boolean = targetSibling.getParentByType(javaClass<JetDeclaration>(), true)?.let {
|
||||
val insertBefore: Boolean = targetSibling.getStrictParentOfType<JetDeclaration>()?.let {
|
||||
it is JetDeclarationWithBody || it is JetClassInitializer
|
||||
} ?: false
|
||||
|
||||
|
||||
+11
-9
@@ -24,7 +24,7 @@ import org.jetbrains.jet.plugin.refactoring.JetRefactoringBundle
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isInsideOf
|
||||
import java.util.*
|
||||
import org.jetbrains.jet.plugin.refactoring.createTempCopy
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.plugin.refactoring.JetNameSuggester
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
@@ -67,6 +67,8 @@ import org.jetbrains.jet.plugin.refactoring.getContextForContainingDeclarationBo
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.jet.plugin.caches.resolve.findModuleDescriptor
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
private val DEFAULT_FUNCTION_NAME = "myFun"
|
||||
private val DEFAULT_RETURN_TYPE = KotlinBuiltIns.getInstance().getUnitType()
|
||||
@@ -214,7 +216,7 @@ private fun ExtractionData.analyzeControlFlow(
|
||||
is ReturnValueInstruction -> {
|
||||
val returnExpression = insn.returnExpressionIfAny
|
||||
if (returnExpression == null) {
|
||||
val containingDeclaration = insn.returnedValue.element?.getParentByType(javaClass<JetDeclarationWithBody>())
|
||||
val containingDeclaration = insn.returnedValue.element?.getNonStrictParentOfType<JetDeclarationWithBody>()
|
||||
if (containingDeclaration == pseudocode.getCorrespondingElement()) {
|
||||
defaultExits.add(insn)
|
||||
}
|
||||
@@ -355,7 +357,7 @@ fun ExtractionData.createTemporaryDeclaration(functionText: String): JetNamedDec
|
||||
val tmpFile = originalFile.createTempCopy { text ->
|
||||
StringBuilder(text).insert(insertPosition, insertText).toString()
|
||||
}
|
||||
return tmpFile.findElementAt(lookupPosition)?.getParentByType(javaClass<JetNamedDeclaration>())!!
|
||||
return tmpFile.findElementAt(lookupPosition)?.getNonStrictParentOfType<JetNamedDeclaration>()!!
|
||||
}
|
||||
|
||||
private fun ExtractionData.createTemporaryCodeBlock(): JetBlockExpression =
|
||||
@@ -378,7 +380,7 @@ private fun JetType.collectReferencedTypes(processTypeArguments: Boolean): List<
|
||||
}
|
||||
|
||||
fun JetTypeParameter.collectRelevantConstraints(): List<JetTypeConstraint> {
|
||||
val typeConstraints = getParentByType(javaClass<JetTypeParameterListOwner>())?.getTypeConstraints()
|
||||
val typeConstraints = getNonStrictParentOfType<JetTypeParameterListOwner>()?.getTypeConstraints()
|
||||
if (typeConstraints == null) return Collections.emptyList()
|
||||
return typeConstraints.filter { it.getSubjectTypeParameterName()?.getReference()?.resolve() == this}
|
||||
}
|
||||
@@ -534,7 +536,7 @@ private fun ExtractionData.inferParametersInfo(
|
||||
when(it.getKind()) {
|
||||
ClassKind.OBJECT, ClassKind.ENUM_CLASS -> it as ClassDescriptor
|
||||
ClassKind.CLASS_OBJECT, ClassKind.ENUM_ENTRY -> it.getContainingDeclaration() as? ClassDescriptor
|
||||
else -> if (ref.getParentByType(javaClass<JetTypeReference>()) != null) it as ClassDescriptor else null
|
||||
else -> if (ref.getNonStrictParentOfType<JetTypeReference>() != null) it as ClassDescriptor else null
|
||||
}
|
||||
|
||||
is ConstructorDescriptor -> it.getContainingDeclaration()
|
||||
@@ -598,7 +600,7 @@ private fun ExtractionData.inferParametersInfo(
|
||||
}
|
||||
|
||||
val varNameValidator = JetNameValidatorImpl(
|
||||
commonParent.getParentByType(javaClass<JetExpression>()),
|
||||
commonParent.getNonStrictParentOfType<JetExpression>(),
|
||||
originalElements.first,
|
||||
JetNameValidatorImpl.Target.PROPERTIES
|
||||
)
|
||||
@@ -635,7 +637,7 @@ private fun ExtractionData.checkDeclarationsMovingOutOfScope(
|
||||
val target = expression.getReference()?.resolve()
|
||||
if (target is JetNamedDeclaration
|
||||
&& target.isInsideOf(originalElements)
|
||||
&& target.getParentByType(javaClass<JetDeclaration>(), true) == enclosingDeclaration) {
|
||||
&& target.getStrictParentOfType<JetDeclaration>() == enclosingDeclaration) {
|
||||
declarationsOutOfScope.add(target)
|
||||
}
|
||||
}
|
||||
@@ -681,7 +683,7 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
|
||||
val pseudocodeDeclaration = PsiTreeUtil.getParentOfType(
|
||||
commonParent, javaClass<JetDeclarationWithBody>(), javaClass<JetClassOrObject>()
|
||||
) ?: commonParent.getParentByType(javaClass<JetProperty>())
|
||||
) ?: commonParent.getNonStrictParentOfType<JetProperty>()
|
||||
?: return noContainerError
|
||||
val pseudocode = PseudocodeUtil.generatePseudocode(pseudocodeDeclaration, bindingContext)
|
||||
val localInstructions = getLocalInstructions(pseudocode)
|
||||
@@ -720,7 +722,7 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
)
|
||||
}
|
||||
|
||||
val enclosingDeclaration = commonParent.getParentByType(javaClass<JetDeclaration>(), true)!!
|
||||
val enclosingDeclaration = commonParent.getStrictParentOfType<JetDeclaration>()!!
|
||||
checkDeclarationsMovingOutOfScope(enclosingDeclaration, controlFlow, bindingContext)?.let { messages.add(it) }
|
||||
|
||||
val functionNameValidator =
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.jetbrains.jet.lang.psi.JetElement
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression
|
||||
import java.util.HashMap
|
||||
import org.jetbrains.jet.lang.psi.JetTreeVisitorVoid
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetNamedFunction
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import com.intellij.psi.PsiElement
|
||||
@@ -59,6 +59,8 @@ import org.jetbrains.jet.plugin.util.psi.patternMatching.UnificationResult.Stron
|
||||
import org.jetbrains.jet.plugin.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.parents
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
|
||||
fun ExtractableCodeDescriptor.getDeclarationText(
|
||||
options: ExtractionGeneratorOptions = ExtractionGeneratorOptions.DEFAULT,
|
||||
@@ -107,7 +109,7 @@ fun createNameCounterpartMap(from: JetElement, to: JetElement): Map<JetSimpleNam
|
||||
object: JetTreeVisitorVoid() {
|
||||
override fun visitSimpleNameExpression(expression: JetSimpleNameExpression) {
|
||||
val offset = expression.getTextRange()!!.getStartOffset() - fromOffset
|
||||
val newExpression = to.findElementAt(offset)?.getParentByType(javaClass<JetSimpleNameExpression>())
|
||||
val newExpression = to.findElementAt(offset)?.getNonStrictParentOfType<JetSimpleNameExpression>()
|
||||
assert(newExpression!= null, "Couldn't find expression at $offset in '${to.getText()}'")
|
||||
|
||||
map[expression] = newExpression!!
|
||||
@@ -200,7 +202,7 @@ private fun makeCall(
|
||||
fun insertCall(anchor: PsiElement, wrappedCall: JetExpression) {
|
||||
val firstExpression = rangeToReplace.elements.firstOrNull { it is JetExpression } as? JetExpression
|
||||
if (firstExpression?.isFunctionLiteralOutsideParentheses() ?: false) {
|
||||
val functionLiteralArgument = PsiTreeUtil.getParentOfType(firstExpression, javaClass<JetFunctionLiteralArgument>())!!
|
||||
val functionLiteralArgument = firstExpression?.getStrictParentOfType<JetFunctionLiteralArgument>()!!
|
||||
functionLiteralArgument.moveInsideParenthesesAndReplaceWith(wrappedCall, extractableDescriptor.originalContext)
|
||||
return
|
||||
}
|
||||
@@ -402,7 +404,7 @@ fun ExtractableCodeDescriptor.generateDeclaration(options: ExtractionGeneratorOp
|
||||
* before calls/types themselves
|
||||
*/
|
||||
for ((offsetInBody, resolveResult) in extractionData.refOffsetToDeclaration.entrySet().sortDescendingBy { it.key }) {
|
||||
val expr = file.findElementAt(bodyOffset + offsetInBody)?.getParentByType(javaClass<JetSimpleNameExpression>())
|
||||
val expr = file.findElementAt(bodyOffset + offsetInBody)?.getNonStrictParentOfType<JetSimpleNameExpression>()
|
||||
assert(expr != null, "Couldn't find expression at $offsetInBody in '${body.getText()}'")
|
||||
|
||||
originalOffsetByExpr[expr!!] = offsetInBody
|
||||
@@ -422,7 +424,7 @@ fun ExtractableCodeDescriptor.generateDeclaration(options: ExtractionGeneratorOp
|
||||
replacingReturn = psiFactory.createExpression(if (jumpValue.conditional) "return true" else "return")
|
||||
expressionsToReplaceWithReturn = jumpValue.elementsToReplace.map { jumpElement ->
|
||||
val offsetInBody = jumpElement.getTextRange()!!.getStartOffset() - extractionData.originalStartOffset!!
|
||||
val expr = file.findElementAt(bodyOffset + offsetInBody)?.getParentByType(jumpElement.javaClass)
|
||||
val expr = file.findElementAt(bodyOffset + offsetInBody)?.getNonStrictParentOfType(jumpElement.javaClass)
|
||||
assert(expr != null, "Couldn't find expression at $offsetInBody in '${body.getText()}'")
|
||||
|
||||
expr!!
|
||||
|
||||
@@ -56,7 +56,6 @@ import com.intellij.openapi.ui.popup.JBPopupAdapter
|
||||
import com.intellij.openapi.ui.popup.LightweightWindowEvent
|
||||
import com.intellij.psi.PsiDocumentManager
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
|
||||
import com.intellij.psi.PsiNamedElement
|
||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||
@@ -65,6 +64,9 @@ import com.intellij.openapi.util.text.StringUtil
|
||||
import javax.swing.Icon
|
||||
import org.jetbrains.jet.plugin.util.string.collapseSpaces
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
fun <T: Any> PsiElement.getAndRemoveCopyableUserData(key: Key<T>): T? {
|
||||
val data = getCopyableUserData(key)
|
||||
@@ -131,8 +133,8 @@ public fun PsiElement.getAllExtractionContainers(strict: Boolean = true): List<J
|
||||
public fun PsiElement.getExtractionContainers(strict: Boolean = true, includeAll: Boolean = false): List<JetElement> {
|
||||
if (includeAll) return getAllExtractionContainers(strict)
|
||||
|
||||
val declaration = getParentByType(javaClass<JetDeclaration>(), strict)?.let { declaration ->
|
||||
stream(declaration) { it.getParentByType(javaClass<JetDeclaration>(), true) }.firstOrNull { it !is JetFunctionLiteral }
|
||||
val declaration = getParentOfType<JetDeclaration>(strict)?.let { declaration ->
|
||||
stream(declaration) { it.getStrictParentOfType<JetDeclaration>() }.firstOrNull { it !is JetFunctionLiteral }
|
||||
} ?: return Collections.emptyList()
|
||||
|
||||
val parent = declaration.getParent()?.let {
|
||||
@@ -259,7 +261,7 @@ fun PsiElement.getLineCount(): Int {
|
||||
fun PsiElement.isMultiLine(): Boolean = getLineCount() > 1
|
||||
|
||||
public fun JetElement.getContextForContainingDeclarationBody(): BindingContext? {
|
||||
val enclosingDeclaration = getParentByType(javaClass<JetDeclaration>(), true)
|
||||
val enclosingDeclaration = getStrictParentOfType<JetDeclaration>()
|
||||
val bodyElement = when (enclosingDeclaration) {
|
||||
is JetDeclarationWithBody -> enclosingDeclaration.getBodyExpression()
|
||||
is JetWithExpressionInitializer -> enclosingDeclaration.getInitializer()
|
||||
@@ -291,7 +293,7 @@ public fun chooseContainerElement<T>(
|
||||
return (getParent() as JetProperty).renderName() + if (isGetter()) ".get" else ".set"
|
||||
}
|
||||
if (this is JetObjectDeclaration && this.isClassObject()) {
|
||||
return "Class object of ${getParentByType(javaClass<JetClassOrObject>(), true)?.renderName() ?: "<anonymous>"}"
|
||||
return "Class object of ${getStrictParentOfType<JetClassOrObject>()?.renderName() ?: "<anonymous>"}"
|
||||
}
|
||||
return (this as? PsiNamedElement)?.getName() ?: "<anonymous>"
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import com.intellij.psi.PsiReference
|
||||
import com.intellij.refactoring.util.MoveRenameUsageInfo
|
||||
import org.jetbrains.jet.plugin.references.JetReference
|
||||
import org.jetbrains.jet.asJava.namedUnwrappedElement
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective
|
||||
import java.util.ArrayList
|
||||
import com.intellij.refactoring.util.NonCodeUsageInfo
|
||||
@@ -158,7 +158,7 @@ fun createMoveUsageInfo(
|
||||
|
||||
if (reference is JetReference
|
||||
&& referencedElement.namedUnwrappedElement!!.isExtensionDeclaration()
|
||||
&& element.getParentByType(javaClass<JetImportDirective>()) == null) {
|
||||
&& element.getNonStrictParentOfType<JetImportDirective>() == null) {
|
||||
return MoveRenameUsageInfoForExtension(
|
||||
element, reference, startOffset, endOffset, referencedElement, element.getContainingFile()!!, addImportToOriginalFile
|
||||
)
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.usageView.UsageInfo
|
||||
import java.util.ArrayList
|
||||
import com.intellij.refactoring.util.MoveRenameUsageInfo
|
||||
import org.jetbrains.jet.plugin.references.JetMultiDeclarationReference
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByTypeAndBranch
|
||||
import org.jetbrains.jet.lang.psi.JetWhenConditionInRange
|
||||
import com.intellij.refactoring.rename.UnresolvableCollisionUsageInfo
|
||||
import org.jetbrains.jet.plugin.refactoring.JetRefactoringBundle
|
||||
|
||||
+2
-2
@@ -26,7 +26,7 @@ import org.jetbrains.jet.asJava.unwrapped
|
||||
import org.jetbrains.jet.lang.psi.*
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.plugin.references.JetReference
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isAncestor
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.parameterIndex
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorToSourceUtils
|
||||
@@ -40,7 +40,7 @@ public class KotlinJavaSafeDeleteDelegate : JavaSafeDeleteDelegate {
|
||||
|
||||
val element = reference.getElement() as JetElement
|
||||
|
||||
val callExpression = element.getParentByType(javaClass<JetCallExpression>())
|
||||
val callExpression = element.getNonStrictParentOfType<JetCallExpression>()
|
||||
if (callExpression == null) return
|
||||
|
||||
val calleeExpression = callExpression.getCalleeExpression()
|
||||
|
||||
+8
-8
@@ -42,7 +42,7 @@ import org.jetbrains.jet.plugin.JetBundle
|
||||
import org.jetbrains.jet.plugin.refactoring.JetRefactoringUtil
|
||||
import org.jetbrains.jet.plugin.references.JetReference
|
||||
import java.util.*
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.deleteElementAndCleanParent
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
|
||||
@@ -88,9 +88,9 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
|
||||
is SafeDeleteReferenceJavaDeleteUsageInfo ->
|
||||
usageInfo.getElement()?.let { usageElement ->
|
||||
if (usageElement.getParentByType(javaClass<JetValueArgumentName>()) != null) null
|
||||
if (usageElement.getNonStrictParentOfType<JetValueArgumentName>() != null) null
|
||||
else {
|
||||
usageElement.getParentByType(javaClass<JetImportDirective>())?.let { importDirective ->
|
||||
usageElement.getNonStrictParentOfType<JetImportDirective>()?.let { importDirective ->
|
||||
SafeDeleteImportDirectiveUsageInfo(importDirective, element.unwrapped as JetDeclaration)
|
||||
} ?: if (forceReferencedElementUnwrapping) {
|
||||
SafeDeleteReferenceJavaDeleteUsageInfo(usageElement, element.unwrapped, usageInfo.isSafeDelete())
|
||||
@@ -126,7 +126,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
.stream()
|
||||
.filterNot { reference -> getIgnoranceCondition().value(reference.getElement()) }
|
||||
.mapTo(usages) { reference ->
|
||||
reference.getElement().getParentByType(javaClass<JetImportDirective>())?.let { importDirective ->
|
||||
reference.getElement().getNonStrictParentOfType<JetImportDirective>()?.let { importDirective ->
|
||||
SafeDeleteImportDirectiveUsageInfo(importDirective, element.unwrapped as JetDeclaration)
|
||||
} ?: SafeDeleteReferenceSimpleDeleteUsageInfo(element, declaration, false)
|
||||
}
|
||||
@@ -135,7 +135,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
}
|
||||
|
||||
fun findTypeParameterUsages(parameter: JetTypeParameter) {
|
||||
val owner = parameter.getParentByType(javaClass<JetTypeParameterListOwner>())
|
||||
val owner = parameter.getNonStrictParentOfType<JetTypeParameterListOwner>()
|
||||
if (owner == null) return
|
||||
|
||||
val parameterList = owner.getTypeParameters()
|
||||
@@ -146,9 +146,9 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
|
||||
val referencedElement = reference.getElement()
|
||||
|
||||
val argList = referencedElement.getParentByType(javaClass<JetUserType>())?.let { jetType ->
|
||||
val argList = referencedElement.getNonStrictParentOfType<JetUserType>()?.let { jetType ->
|
||||
jetType.getTypeArgumentList()
|
||||
} ?: referencedElement.getParentByType(javaClass<JetCallExpression>())?.let { callExpression ->
|
||||
} ?: referencedElement.getNonStrictParentOfType<JetCallExpression>()?.let { callExpression ->
|
||||
callExpression.getTypeArgumentList()
|
||||
} ?: null
|
||||
|
||||
@@ -202,7 +202,7 @@ public class KotlinSafeDeleteProcessor : JavaSafeDeleteProcessor() {
|
||||
|
||||
override fun findConflicts(element: PsiElement, allElementsToDelete: Array<out PsiElement>): MutableCollection<String>? {
|
||||
if (element is JetNamedFunction || element is JetProperty) {
|
||||
val jetClass = element.getParentByType(javaClass<JetClass>())
|
||||
val jetClass = element.getNonStrictParentOfType<JetClass>()
|
||||
if (jetClass == null || jetClass.getBody() != element.getParent()) return null
|
||||
|
||||
val modifierList = jetClass.getModifierList()
|
||||
|
||||
@@ -37,7 +37,7 @@ public fun PsiElement.canDeleteElement(): Boolean {
|
||||
if (isObjectLiteral()) return false
|
||||
|
||||
if (this is JetParameter) {
|
||||
val declaration = getParentByType(javaClass<JetDeclaration>(), true)
|
||||
val declaration = getStrictParentOfType<JetDeclaration>()
|
||||
return declaration != null && !(declaration is JetPropertyAccessor && declaration.isSetter())
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.jetbrains.jet.completion
|
||||
import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.lang.psi.JetExpression
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import org.jetbrains.jet.plugin.completion.renderDataFlowValue
|
||||
import org.jetbrains.jet.JetTestUtils
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
@@ -29,6 +28,7 @@ import com.intellij.testFramework.LightProjectDescriptor
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.jet.lang.resolve.bindingContextUtil.getDataFlowInfo
|
||||
import org.jetbrains.jet.plugin.caches.resolve.analyze
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
public abstract class AbstractDataFlowValueRenderingTest: JetLightCodeInsightFixtureTestCase() {
|
||||
override fun getTestDataPath() : String {
|
||||
@@ -45,7 +45,7 @@ public abstract class AbstractDataFlowValueRenderingTest: JetLightCodeInsightFix
|
||||
|
||||
val jetFile = fixture.getFile() as JetFile
|
||||
val element = jetFile.findElementAt(fixture.getCaretOffset())
|
||||
val expression = PsiTreeUtil.getParentOfType(element, javaClass<JetExpression>())!!
|
||||
val expression = element.getStrictParentOfType<JetExpression>()!!
|
||||
val info = expression.analyze().getDataFlowInfo(expression)
|
||||
|
||||
val allValues = (info.getCompleteTypeInfo().keySet() + info.getCompleteNullabilityInfo().keySet()).toSet()
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.jetbrains.jet.plugin.PluginTestCaseBase
|
||||
import java.io.File
|
||||
import com.intellij.refactoring.move.moveMembers.MoveMembersProcessor
|
||||
import com.intellij.refactoring.move.moveMembers.MockMoveMembersOptions
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import com.intellij.psi.PsiMember
|
||||
import com.intellij.refactoring.BaseRefactoringProcessor.ConflictsInTestsException
|
||||
import com.google.gson.JsonObject
|
||||
@@ -141,7 +141,7 @@ public abstract class AbstractJetMoveTest : MultiFileTestCase() {
|
||||
enum class MoveAction {
|
||||
MOVE_MEMBERS {
|
||||
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementAtCaret: PsiElement?, config: JsonObject) {
|
||||
val member = elementAtCaret!!.getParentByType(javaClass<PsiMember>())!!
|
||||
val member = elementAtCaret!!.getNonStrictParentOfType<PsiMember>()!!
|
||||
val targetClassName = config.getString("targetClass")
|
||||
val visibility = config.getNullableString("visibility")
|
||||
|
||||
@@ -156,7 +156,7 @@ enum class MoveAction {
|
||||
|
||||
MOVE_TOP_LEVEL_CLASSES {
|
||||
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementAtCaret: PsiElement?, config: JsonObject) {
|
||||
val classToMove = elementAtCaret!!.getParentByType(javaClass<PsiClass>())!!
|
||||
val classToMove = elementAtCaret!!.getNonStrictParentOfType<PsiClass>()!!
|
||||
val targetPackage = config.getString("targetPackage")
|
||||
|
||||
MoveClassesOrPackagesProcessor(
|
||||
@@ -191,7 +191,7 @@ enum class MoveAction {
|
||||
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementAtCaret: PsiElement?, config: JsonObject) {
|
||||
val project = mainFile.getProject()
|
||||
|
||||
val classToMove = elementAtCaret!!.getParentByType(javaClass<PsiClass>())!!
|
||||
val classToMove = elementAtCaret!!.getNonStrictParentOfType<PsiClass>()!!
|
||||
val targetClass = config.getString("targetClass")
|
||||
|
||||
MoveClassToInnerProcessor(
|
||||
@@ -209,7 +209,7 @@ enum class MoveAction {
|
||||
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementAtCaret: PsiElement?, config: JsonObject) {
|
||||
val project = mainFile.getProject()
|
||||
|
||||
val classToMove = elementAtCaret!!.getParentByType(javaClass<PsiClass>())!!
|
||||
val classToMove = elementAtCaret!!.getNonStrictParentOfType<PsiClass>()!!
|
||||
val newClassName = config.getNullableString("newClassName") ?: classToMove.getName()!!
|
||||
val outerInstanceParameterName = config.getNullableString("outerInstanceParameterName")
|
||||
val targetPackage = config.getString("targetPackage")
|
||||
@@ -258,7 +258,7 @@ enum class MoveAction {
|
||||
MOVE_KOTLIN_TOP_LEVEL_DECLARATIONS {
|
||||
override fun runRefactoring(rootDir: VirtualFile, mainFile: PsiFile, elementAtCaret: PsiElement?, config: JsonObject) {
|
||||
val project = mainFile.getProject()
|
||||
val elementToMove = elementAtCaret!!.getParentByType(javaClass<JetNamedDeclaration>())!!
|
||||
val elementToMove = elementAtCaret!!.getNonStrictParentOfType<JetNamedDeclaration>()!!
|
||||
|
||||
val moveTarget = config.getNullableString("targetPackage")?.let { packageName ->
|
||||
MoveDestinationKotlinMoveTarget(MultipleRootsMoveDestination(PackageWrapper(mainFile.getManager(), packageName)))
|
||||
|
||||
@@ -18,7 +18,7 @@ package org.jetbrains.jet.resolve
|
||||
|
||||
import org.jetbrains.jet.plugin.JetLightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.jet.lang.psi.JetFile
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext
|
||||
import org.jetbrains.jet.JetTestCaseBuilder
|
||||
import org.jetbrains.jet.plugin.JetWithJdkAndRuntimeLightProjectDescriptor
|
||||
@@ -59,7 +59,7 @@ public abstract class AbstractPartialBodyResolveTest : JetLightCodeInsightFixtur
|
||||
else {
|
||||
val offset = editor.getCaretModel().getOffset()
|
||||
val element = file.findElementAt(offset)
|
||||
element.getParentByType(javaClass<JetSimpleNameExpression>()) ?: error("No JetSimpleNameExpression at caret")
|
||||
element.getNonStrictParentOfType<JetSimpleNameExpression>() ?: error("No JetSimpleNameExpression at caret")
|
||||
}
|
||||
|
||||
val resolutionFacade = file.getResolutionFacade()
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.jetbrains.jet.asJava.KotlinLightMethod
|
||||
import org.jetbrains.jet.lang.psi.JetProperty
|
||||
import org.jetbrains.jet.lang.psi.JetFunction
|
||||
import org.jetbrains.jet.lang.psi.JetClassOrObject
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentByType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getNonStrictParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.isExtensionDeclaration
|
||||
import org.jetbrains.jet.lang.psi.JetPropertyAccessor
|
||||
import org.jetbrains.jet.lang.psi.JetParameter
|
||||
@@ -37,6 +37,8 @@ import org.jetbrains.jet.lang.resolve.java.JvmPrimitiveType
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName
|
||||
import org.jetbrains.jet.asJava.KotlinLightField
|
||||
import org.jetbrains.jet.lang.psi.JetObjectDeclaration
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getParentOfType
|
||||
import org.jetbrains.jet.lang.psi.psiUtil.getStrictParentOfType
|
||||
|
||||
trait ExpressionConverter {
|
||||
fun convertExpression(expression: PsiExpression, codeConverter: CodeConverter): Expression
|
||||
@@ -70,7 +72,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
||||
}
|
||||
|
||||
override fun visitArrayAccessExpression(expression: PsiArrayAccessExpression) {
|
||||
val assignment = PsiTreeUtil.getParentOfType(expression, javaClass<PsiAssignmentExpression>())
|
||||
val assignment = expression.getStrictParentOfType<PsiAssignmentExpression>()
|
||||
val lvalue = assignment != null && expression == assignment.getLExpression();
|
||||
result = ArrayAccessExpression(codeConverter.convertExpression(expression.getArrayExpression()),
|
||||
codeConverter.convertExpression(expression.getIndexExpression()),
|
||||
@@ -211,7 +213,7 @@ class DefaultExpressionConverter : JavaElementVisitor(), ExpressionConverter {
|
||||
|
||||
if (target is KotlinLightMethod) {
|
||||
val origin = target.origin
|
||||
val isTopLevel = origin?.getParentByType(javaClass<JetClassOrObject>(), true) == null
|
||||
val isTopLevel = origin?.getStrictParentOfType<JetClassOrObject>() == null
|
||||
if (origin is JetProperty || origin is JetPropertyAccessor || origin is JetParameter) {
|
||||
val property = if (origin is JetPropertyAccessor)
|
||||
origin.getParent() as JetProperty
|
||||
|
||||
Reference in New Issue
Block a user