rename PSI classes according to current terminology:

KtMultiDeclaration(Entry) -> KtDestructuringDeclaration(Entry)
KtFunctionLiteralExpression -> KtLambdaExpression
KtFunctionLiteralArgument -> KtLambdaArgument
KtDelegationSpecifierList -> KtSuperTypeList
KtDelegationSpecifier -> KtSuperTypeListEntry
KtDelegatorToSuperClass -> KtSuperTypeEntry
KtDelegatorToSuperCall -> KtSuperTypeCallEntry
KtDelegationByExpressionSpecifier ->KtDelegatedSuperTypeEntry
This commit is contained in:
Dmitry Jemerov
2015-12-09 19:30:38 +01:00
parent ef4b3c99f4
commit 009e3f9cd7
302 changed files with 1375 additions and 1391 deletions
@@ -177,7 +177,7 @@ public class ShadowedDeclarationsFilter(
override fun getValueArguments() = arguments
override fun getFunctionLiteralArguments() = emptyList<FunctionLiteralArgument>()
override fun getFunctionLiteralArguments() = emptyList<LambdaArgument>()
override fun getTypeArguments() = emptyList<KtTypeProjection>()
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
public fun KtFunctionLiteral.findLabelAndCall(): Pair<Name?, KtCallExpression?> {
val literalParent = (this.getParent() as KtFunctionLiteralExpression).getParent()
val literalParent = (this.getParent() as KtLambdaExpression).getParent()
fun KtValueArgument.callExpression(): KtCallExpression? {
val parent = getParent()
@@ -90,7 +90,7 @@ class PartialBodyResolveFilter(
statementMarks.mark(statement, MarkLevel.NEED_REFERENCE_RESOLVE)
}
}
else if (statement is KtMultiDeclaration) {
else if (statement is KtDestructuringDeclaration) {
if (statement.getEntries().any {
val name = it.getName()
name != null && nameFilter(name)
@@ -119,7 +119,7 @@ private object KotlinResolveDataProvider {
// TODO: Non-analyzable so far, add more granular analysis
javaClass<KtAnnotationEntry>(),
javaClass<KtTypeConstraint>(),
javaClass<KtDelegationSpecifierList>(),
javaClass<KtSuperTypeList>(),
javaClass<KtTypeParameter>(),
javaClass<KtParameter>()
)
@@ -133,7 +133,7 @@ private object KotlinResolveDataProvider {
val analyzableElement = when (topmostElement) {
is KtAnnotationEntry,
is KtTypeConstraint,
is KtDelegationSpecifierList,
is KtSuperTypeList,
is KtTypeParameter,
is KtParameter -> PsiTreeUtil.getParentOfType(topmostElement, javaClass<KtClassOrObject>(), javaClass<KtCallableDeclaration>())
else -> topmostElement
@@ -24,8 +24,8 @@ import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.psi.KtClassBody
import org.jetbrains.kotlin.psi.KtDelegationSpecifierList
import org.jetbrains.kotlin.psi.KtDelegatorToSuperClass
import org.jetbrains.kotlin.psi.KtSuperTypeEntry
import org.jetbrains.kotlin.psi.KtSuperTypeList
import org.jetbrains.kotlin.psi.stubs.elements.KtClassElementType
import org.jetbrains.kotlin.psi.stubs.elements.KtStubElementTypes
import org.jetbrains.kotlin.psi.stubs.impl.KotlinClassStubImpl
@@ -144,11 +144,11 @@ private class ClassClsStubBuilder(
if (supertypeIds.isEmpty()) return
val delegationSpecifierListStub =
KotlinPlaceHolderStubImpl<KtDelegationSpecifierList>(classOrObjectStub, KtStubElementTypes.DELEGATION_SPECIFIER_LIST)
KotlinPlaceHolderStubImpl<KtSuperTypeList>(classOrObjectStub, KtStubElementTypes.SUPER_TYPE_LIST)
classProto.supertypes(c.typeTable).forEach { type ->
val superClassStub = KotlinPlaceHolderStubImpl<KtDelegatorToSuperClass>(
delegationSpecifierListStub, KtStubElementTypes.DELEGATOR_SUPER_CLASS
val superClassStub = KotlinPlaceHolderStubImpl<KtSuperTypeEntry>(
delegationSpecifierListStub, KtStubElementTypes.SUPER_TYPE_ENTRY
)
typeStubBuilder.createTypeReferenceStub(superClassStub, type)
}
@@ -35,7 +35,7 @@ public class KotlinFindUsagesProvider : FindUsagesProvider {
is KtClass -> "class"
is KtParameter -> "parameter"
is KtProperty -> if (element.isLocal()) "variable" else "property"
is KtMultiDeclarationEntry -> "variable"
is KtDestructuringDeclarationEntry -> "variable"
is KtTypeParameter -> "type parameter"
is KtSecondaryConstructor -> "constructor"
is KtObjectDeclaration -> "object"
@@ -34,7 +34,7 @@ public object UsageTypeUtils {
public fun getUsageType(element: PsiElement?): UsageTypeEnum? {
when (element) {
is KtForExpression -> return IMPLICIT_ITERATION
is KtMultiDeclaration -> return READ
is KtDestructuringDeclaration -> return READ
is KtPropertyDelegate -> return PROPERTY_DELEGATION
is KtStringTemplateExpression -> return USAGE_IN_STRING_LITERAL
}
@@ -83,8 +83,8 @@ public object UsageTypeUtils {
|| refExpr.getParentOfTypeAndBranch<KtTypeConstraint>(){ getBoundTypeReference() } != null ->
TYPE_CONSTRAINT
refExpr is KtDelegationSpecifier
|| refExpr.getParentOfTypeAndBranch<KtDelegationSpecifier>(){ getTypeReference() } != null ->
refExpr is KtSuperTypeListEntry
|| refExpr.getParentOfTypeAndBranch<KtSuperTypeListEntry>(){ getTypeReference() } != null ->
SUPER_TYPE
refExpr.getParentOfTypeAndBranch<KtTypedef>(){ getTypeReference() } != null ->
@@ -120,7 +120,7 @@ public object UsageTypeUtils {
}
fun getVariableUsageType(): UsageTypeEnum? {
if (refExpr.getParentOfTypeAndBranch<KtDelegatorByExpressionSpecifier>(){ getDelegateExpression() } != null) {
if (refExpr.getParentOfTypeAndBranch<KtDelegatedSuperTypeEntry>(){ getDelegateExpression() } != null) {
return DELEGATE
}
@@ -158,7 +158,7 @@ public object UsageTypeUtils {
}
return when {
refExpr.getParentOfTypeAndBranch<KtDelegationSpecifier>(){ getTypeReference() } != null ->
refExpr.getParentOfTypeAndBranch<KtSuperTypeListEntry>(){ getTypeReference() } != null ->
SUPER_TYPE
descriptor is ConstructorDescriptor
@@ -47,7 +47,7 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
}
@Override
public void visitDelegationToSuperCallSpecifier(@NotNull KtDelegatorToSuperCall call) {
public void visitSuperTypeCallEntry(@NotNull KtSuperTypeCallEntry call) {
KtConstructorCalleeExpression calleeExpression = call.getCalleeExpression();
KtTypeReference typeRef = calleeExpression.getTypeReference();
if (typeRef != null) {
@@ -59,7 +59,7 @@ public class FunctionsHighlightingVisitor extends AfterAnalysisHighlightingVisit
}
}
}
super.visitDelegationToSuperCallSpecifier(call);
super.visitSuperTypeCallEntry(call);
}
@Override
@@ -54,7 +54,7 @@ fun createSuppressWarningActions(element: PsiElement, diagnosticFactory: Diagnos
var current: PsiElement? = element
var suppressAtStatementAllowed = true
while (current != null) {
if (current is KtDeclaration && current !is KtMultiDeclaration) {
if (current is KtDeclaration && current !is KtDestructuringDeclaration) {
val declaration = current
val kind = DeclarationKindDetector.detect(declaration)
if (kind != null) {
@@ -64,7 +64,7 @@ fun createSuppressWarningActions(element: PsiElement, diagnosticFactory: Diagnos
}
else if (current is KtExpression && suppressAtStatementAllowed) {
// Add suppress action at first statement
if (current.parent is KtBlockExpression || current.parent is KtMultiDeclaration) {
if (current.parent is KtBlockExpression || current.parent is KtDestructuringDeclaration) {
val kind = if (current.parent is KtBlockExpression) "statement" else "initializer"
actions.add(KotlinSuppressIntentionAction(current, diagnosticFactory,
AnnotationHostKind(kind, "", true)))
@@ -89,8 +89,8 @@ private object DeclarationKindDetector : KtVisitor<AnnotationHostKind?, Unit?>()
override fun visitProperty(d: KtProperty, data: Unit?) = detect(d, d.getValOrVarKeyword().getText()!!)
override fun visitMultiDeclaration(d: KtMultiDeclaration, data: Unit?) = detect(d, d.getValOrVarKeyword()?.getText() ?: "val",
name = d.getEntries().map { it.getName()!! }.joinToString(", ", "(", ")"))
override fun visitDestructuringDeclaration(d: KtDestructuringDeclaration, data: Unit?) = detect(d, d.getValOrVarKeyword()?.getText() ?: "val",
name = d.getEntries().map { it.getName()!! }.joinToString(", ", "(", ")"))
override fun visitTypeParameter(d: KtTypeParameter, data: Unit?) = detect(d, "type parameter", newLineNeeded = false)
@@ -25,7 +25,7 @@ import com.intellij.psi.tree.IElementType;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.psi.KtFunctionLiteral;
import org.jetbrains.kotlin.psi.KtFunctionLiteralExpression;
import org.jetbrains.kotlin.psi.KtLambdaExpression;
import org.jetbrains.kotlin.psi.KtVisitorVoid;
class SoftKeywordsHighlightingVisitor extends KtVisitorVoid {
@@ -53,9 +53,9 @@ class SoftKeywordsHighlightingVisitor extends KtVisitorVoid {
}
@Override
public void visitFunctionLiteralExpression(@NotNull KtFunctionLiteralExpression expression) {
public void visitLambdaExpression(@NotNull KtLambdaExpression lambdaExpression) {
if (ApplicationManager.getApplication().isUnitTestMode()) return;
KtFunctionLiteral functionLiteral = expression.getFunctionLiteral();
KtFunctionLiteral functionLiteral = lambdaExpression.getFunctionLiteral();
holder.createInfoAnnotation(functionLiteral.getLBrace(), null).setTextAttributes(KotlinHighlightingColors.FUNCTION_LITERAL_BRACES_AND_ARROW);
PsiElement closingBrace = functionLiteral.getRBrace();
if (closingBrace != null) {
@@ -73,7 +73,7 @@ public class OperatorToFunctionIntention : SelfTargetingIntention<KtExpression>(
private fun isApplicableCall(element: KtCallExpression, caretOffset: Int): Boolean {
val lbrace = (element.getValueArgumentList()?.getLeftParenthesis()
?: element.getFunctionLiteralArguments().firstOrNull()?.getFunctionLiteral()?.getLeftCurlyBrace()
?: element.getLambdaArguments().firstOrNull()?.getLambdaExpression()?.getLeftCurlyBrace()
?: return false) as PsiElement
if (!lbrace.getTextRange().containsOffset(caretOffset)) return false
@@ -82,7 +82,7 @@ public class OperatorToFunctionIntention : SelfTargetingIntention<KtExpression>(
if (descriptor is FunctionDescriptor && descriptor.getName() == OperatorNameConventions.INVOKE) {
if (element.getParent() is KtDotQualifiedExpression &&
element.getCalleeExpression()?.getText() == OperatorNameConventions.INVOKE.asString()) return false
return element.getValueArgumentList() != null || element.getFunctionLiteralArguments().isNotEmpty()
return element.getValueArgumentList() != null || element.getLambdaArguments().isNotEmpty()
}
return false
}
@@ -196,7 +196,7 @@ public class OperatorToFunctionIntention : SelfTargetingIntention<KtExpression>(
val callee = element.getCalleeExpression()!!
val arguments = element.getValueArgumentList()
val argumentString = arguments?.getText()?.removeSurrounding("(", ")")
val funcLitArgs = element.getFunctionLiteralArguments()
val funcLitArgs = element.getLambdaArguments()
val calleeText = callee.getText()
val transformation = "$calleeText.${OperatorNameConventions.INVOKE.asString()}" +
(if (argumentString == null) "" else "($argumentString)")
@@ -209,7 +209,7 @@ public class ResolveElementCache(
javaClass<KtSecondaryConstructor>(),
javaClass<KtProperty>(),
javaClass<KtParameter>(),
javaClass<KtDelegationSpecifierList>(),
javaClass<KtSuperTypeList>(),
javaClass<KtInitializerList>(),
javaClass<KtImportList>(),
javaClass<KtAnnotationEntry>(),
@@ -269,7 +269,7 @@ public class ResolveElementCache(
is KtProperty -> propertyAdditionalResolve(resolveSession, resolveElement, file, createStatementFilter())
is KtDelegationSpecifierList -> delegationSpecifierAdditionalResolve(resolveSession, resolveElement, resolveElement.getParent() as KtClassOrObject, file)
is KtSuperTypeList -> delegationSpecifierAdditionalResolve(resolveSession, resolveElement, resolveElement.getParent() as KtClassOrObject, file)
is KtInitializerList -> delegationSpecifierAdditionalResolve(resolveSession, resolveElement, resolveElement.getParent() as KtEnumEntry, file)
@@ -401,12 +401,12 @@ public class ResolveElementCache(
ForceResolveUtil.forceResolveAllContents(descriptor.getTypeConstructor().getSupertypes())
val bodyResolver = createBodyResolver(resolveSession, trace, file, StatementFilter.NONE)
bodyResolver.resolveDelegationSpecifierList(DataFlowInfo.EMPTY,
classOrObject,
descriptor,
descriptor.unsubstitutedPrimaryConstructor,
descriptor.scopeForConstructorHeaderResolution,
descriptor.scopeForMemberDeclarationResolution)
bodyResolver.resolveSuperTypeEntryList(DataFlowInfo.EMPTY,
classOrObject,
descriptor,
descriptor.getUnsubstitutedPrimaryConstructor(),
descriptor.scopeForConstructorHeaderResolution,
descriptor.getScopeForMemberDeclarationResolution())
return trace
}
@@ -61,8 +61,8 @@ public class KotlinReferenceContributor() : PsiReferenceContributor() {
KtPropertyDelegationMethodsReference(it)
}
registerProvider(javaClass<KtMultiDeclaration>()) {
KtMultiDeclarationReference(it)
registerProvider(javaClass<KtDestructuringDeclaration>()) {
KtDestructuringDeclarationReference(it)
}
registerProvider(javaClass<KDocName>()) {
@@ -16,16 +16,16 @@
package org.jetbrains.kotlin.idea.references
import org.jetbrains.kotlin.psi.KtMultiDeclaration
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import com.intellij.openapi.util.TextRange
import com.intellij.psi.PsiElement
import com.intellij.util.IncorrectOperationException
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
import org.jetbrains.kotlin.resolve.BindingContext
class KtMultiDeclarationReference(element: KtMultiDeclaration) : KtMultiReference<KtMultiDeclaration>(element) {
class KtDestructuringDeclarationReference(element: KtDestructuringDeclaration) : KtMultiReference<KtDestructuringDeclaration>(element) {
override fun getTargetDescriptors(context: BindingContext): Collection<DeclarationDescriptor> {
return expression.getEntries().mapNotNull { entry ->
context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry)?.getCandidateDescriptor()
@@ -83,9 +83,9 @@ public class KtInvokeFunctionReference extends KtSimpleReference<KtCallExpressio
}
}
List<KtFunctionLiteralArgument> functionLiteralArguments = getExpression().getFunctionLiteralArguments();
for (KtFunctionLiteralArgument functionLiteralArgument : functionLiteralArguments) {
KtFunctionLiteralExpression functionLiteralExpression = functionLiteralArgument.getFunctionLiteral();
List<KtLambdaArgument> functionLiteralArguments = getExpression().getLambdaArguments();
for (KtLambdaArgument functionLiteralArgument : functionLiteralArguments) {
KtLambdaExpression functionLiteralExpression = functionLiteralArgument.getLambdaExpression();
list.add(getRange(functionLiteralExpression.getLeftCurlyBrace()));
ASTNode rightCurlyBrace = functionLiteralExpression.getRightCurlyBrace();
if (rightCurlyBrace != null) {
@@ -77,7 +77,7 @@ public fun PsiReference.matchesTarget(candidateTarget: PsiElement): Boolean {
is KtInvokeFunctionReference -> {
if (candidateTarget !is KtNamedFunction) return false
}
is KtMultiDeclarationReference -> {
is KtDestructuringDeclarationReference -> {
if (candidateTarget !is KtNamedFunction && candidateTarget !is KtParameter) return false
}
}
@@ -169,8 +169,8 @@ private fun processClassDelegationCallsToSpecifiedConstructor(
if (!klass.isEnum()) return true
for (declaration in klass.declarations) {
if (declaration is KtEnumEntry) {
val delegationCall = declaration.getDelegationSpecifiers().firstOrNull()
if (delegationCall is KtDelegatorToSuperCall && constructor == delegationCall.calleeExpression.getConstructorCallDescriptor()) {
val delegationCall = declaration.getSuperTypeListEntries().firstOrNull()
if (delegationCall is KtSuperTypeCallEntry && constructor == delegationCall.calleeExpression.getConstructorCallDescriptor()) {
if (!process(delegationCall)) return false
}
}
@@ -34,8 +34,8 @@ public class UnfocusedPossibleFunctionParameter extends CompletionConfidence {
// 2. The same but for the case when first expression is additionally surrounded with brackets
PsiElement position = parameters.getPosition();
KtFunctionLiteralExpression functionLiteral = PsiTreeUtil.getParentOfType(
position, KtFunctionLiteralExpression.class);
KtLambdaExpression functionLiteral = PsiTreeUtil.getParentOfType(
position, KtLambdaExpression.class);
if (functionLiteral != null) {
PsiElement expectedReference = position.getParent();
@@ -29,7 +29,7 @@ import org.jetbrains.kotlin.idea.core.ExpectedInfos
import org.jetbrains.kotlin.idea.core.completion.DeclarationLookupObject
import org.jetbrains.kotlin.idea.util.CallTypeAndReceiver
import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptorKindExclude
import org.jetbrains.kotlin.psi.FunctionLiteralArgument
import org.jetbrains.kotlin.psi.LambdaArgument
import org.jetbrains.kotlin.psi.KtCodeFragment
import org.jetbrains.kotlin.psi.ValueArgumentName
import org.jetbrains.kotlin.resolve.BindingContext
@@ -177,8 +177,8 @@ class SmartCompletionSession(
val callTypeAndReceiver = CallTypeAndReceiver.detect(nameExpression) as? CallTypeAndReceiver.INFIX ?: return
val call = callTypeAndReceiver.receiver.getCall(bindingContext)
if (call != null && call.getFunctionLiteralArguments().isEmpty()) {
val dummyArgument = object : FunctionLiteralArgument {
override fun getFunctionLiteral() = throw UnsupportedOperationException()
val dummyArgument = object : LambdaArgument {
override fun getLambdaExpression() = throw UnsupportedOperationException()
override fun getArgumentExpression() = throw UnsupportedOperationException()
override fun getArgumentName(): ValueArgumentName? = null
override fun isNamed() = false
@@ -170,9 +170,9 @@ class ExpectedInfos(
}
private fun calculateForFunctionLiteralArgument(expressionWithType: KtExpression): Collection<ExpectedInfo>? {
val functionLiteralArgument = expressionWithType.getParent() as? KtFunctionLiteralArgument
val functionLiteralArgument = expressionWithType.getParent() as? KtLambdaArgument
val callExpression = functionLiteralArgument?.getParent() as? KtCallExpression ?: return null
val literalArgument = callExpression.getFunctionLiteralArguments().firstOrNull() ?: return null
val literalArgument = callExpression.getLambdaArguments().firstOrNull() ?: return null
if (literalArgument.getArgumentExpression() != expressionWithType) return null
return calculateForArgument(callExpression, literalArgument)
}
@@ -228,7 +228,7 @@ class ExpectedInfos(
val arguments = call.getValueArguments().subList(0, argumentIndex)
override fun getValueArguments() = arguments
override fun getFunctionLiteralArguments() = emptyList<FunctionLiteralArgument>()
override fun getFunctionLiteralArguments() = emptyList<LambdaArgument>()
override fun getValueArgumentList() = null
}
@@ -276,7 +276,7 @@ class ExpectedInfos(
}
val argumentName = argument.getArgumentName()?.asName
val isFunctionLiteralArgument = argument is FunctionLiteralArgument
val isFunctionLiteralArgument = argument is LambdaArgument
val callType = call.callType
val isArrayAccess = callType == Call.CallType.ARRAY_GET_METHOD || callType == Call.CallType.ARRAY_SET_METHOD
@@ -471,7 +471,7 @@ class ExpectedInfos(
val functionLiteral = block.parent as? KtFunctionLiteral
if (functionLiteral != null) {
val literalExpression = functionLiteral.parent as KtFunctionLiteralExpression
val literalExpression = functionLiteral.parent as KtLambdaExpression
return calculate(literalExpression)
.mapNotNull { it.fuzzyType }
.filter { KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(it.type) }
@@ -57,7 +57,7 @@ public fun Call.mapArgumentsToParameters(targetDescriptor: CallableDescriptor):
var positionalArgumentIndex: Int? = 0
for (argument in getValueArguments()) {
if (argument is FunctionLiteralArgument) {
if (argument is LambdaArgument) {
map[argument] = parameters.last()
}
else {
@@ -26,7 +26,7 @@ import org.jetbrains.kotlin.lexer.KtModifierKeywordToken
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getFunctionLiteralArgumentName
import org.jetbrains.kotlin.psi.psiUtil.getLambdaArgumentName
import org.jetbrains.kotlin.psi.psiUtil.visibilityModifierType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.OverridingUtil
@@ -44,16 +44,16 @@ public inline fun <reified T: PsiElement> PsiElement.replaced(newElement: T): T
@Suppress("UNCHECKED_CAST")
public fun <T: PsiElement> T.copied(): T = copy() as T
public fun KtFunctionLiteralArgument.moveInsideParentheses(bindingContext: BindingContext): KtCallExpression {
public fun KtLambdaArgument.moveInsideParentheses(bindingContext: BindingContext): KtCallExpression {
return moveInsideParenthesesAndReplaceWith(this.getArgumentExpression(), bindingContext)
}
public fun KtFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
public fun KtLambdaArgument.moveInsideParenthesesAndReplaceWith(
replacement: KtExpression,
bindingContext: BindingContext
): KtCallExpression = moveInsideParenthesesAndReplaceWith(replacement, getFunctionLiteralArgumentName(bindingContext))
): KtCallExpression = moveInsideParenthesesAndReplaceWith(replacement, getLambdaArgumentName(bindingContext))
public fun KtFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
public fun KtLambdaArgument.moveInsideParenthesesAndReplaceWith(
replacement: KtExpression,
functionLiteralArgumentName: Name?
): KtCallExpression {
@@ -68,7 +68,7 @@ public fun KtFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
psiFactory.createArgument(replacement)
}
val functionLiteralArgument = newCallExpression.getFunctionLiteralArguments().firstOrNull()!!
val functionLiteralArgument = newCallExpression.getLambdaArguments().firstOrNull()!!
val valueArgumentList = newCallExpression.getValueArgumentList() ?: psiFactory.createCallArguments("()")
valueArgumentList.addArgument(argument)
@@ -84,14 +84,14 @@ public fun KtFunctionLiteralArgument.moveInsideParenthesesAndReplaceWith(
}
public fun KtCallExpression.moveFunctionLiteralOutsideParentheses() {
assert(getFunctionLiteralArguments().isEmpty())
assert(getLambdaArguments().isEmpty())
val argumentList = getValueArgumentList()!!
val argument = argumentList.getArguments().last()
val expression = argument.getArgumentExpression()!!
assert(expression.unpackFunctionLiteral() != null)
val dummyCall = KtPsiFactory(this).createExpressionByPattern("foo()$0:'{}'", expression) as KtCallExpression
val functionLiteralArgument = dummyCall.getFunctionLiteralArguments().single()
val functionLiteralArgument = dummyCall.getLambdaArguments().single()
this.add(functionLiteralArgument)
if (argumentList.getArguments().size() > 1) {
argumentList.removeArgument(argument)
@@ -182,7 +182,7 @@ class KotlinGenerateSecondaryConstructorAction : KotlinGenerateMemberActionBase<
delegationCallArguments.add(if (isVararg) "*$paramName" else paramName)
}
val delegationCall = psiFactory.createConstructorDelegationCall(delegationCallArguments.joinToString(prefix = "super(", postfix = ")"))
val delegationCall = psiFactory.creareDelegatedSuperTypeEntry(delegationCallArguments.joinToString(prefix = "super(", postfix = ")"))
constructor.replaceImplicitDelegationCallWithExplicit(false).replace(delegationCall)
}
@@ -43,7 +43,7 @@ public class KotlinFunctionLiteralSurrounder extends KotlinStatementsSurrounder
callExpression = (KtCallExpression) container.addAfter(callExpression, statements[statements.length - 1]);
container.addBefore(psiFactory.createWhiteSpace(), callExpression);
KtFunctionLiteralExpression bodyExpression = callExpression.getFunctionLiteralArguments().get(0).getFunctionLiteral();
KtLambdaExpression bodyExpression = callExpression.getLambdaArguments().get(0).getLambdaExpression();
assert bodyExpression != null : "Body expression should exists for " + callExpression.getText();
KtBlockExpression blockExpression = bodyExpression.getBodyExpression();
assert blockExpression != null : "JetBlockExpression should exists for " + callExpression.getText();
@@ -27,7 +27,7 @@ public class KotlinLambdaUnwrapper extends KotlinUnwrapRemoveBase {
super(key);
}
private static KtElement getLambdaEnclosingElement(@NotNull KtFunctionLiteralExpression lambda) {
private static KtElement getLambdaEnclosingElement(@NotNull KtLambdaExpression lambda) {
PsiElement parent = lambda.getParent();
if (parent instanceof KtValueArgument) {
@@ -47,11 +47,11 @@ public class KotlinLambdaUnwrapper extends KotlinUnwrapRemoveBase {
@Override
public boolean isApplicableTo(PsiElement e) {
if (!(e instanceof KtFunctionLiteralExpression)) return false;
if (!(e instanceof KtLambdaExpression)) return false;
KtFunctionLiteralExpression lambda = (KtFunctionLiteralExpression) e;
KtLambdaExpression lambda = (KtLambdaExpression) e;
KtBlockExpression body = lambda.getBodyExpression();
KtElement enclosingElement = getLambdaEnclosingElement((KtFunctionLiteralExpression) e);
KtElement enclosingElement = getLambdaEnclosingElement((KtLambdaExpression) e);
if (body == null || enclosingElement == null) return false;
@@ -60,7 +60,7 @@ public class KotlinLambdaUnwrapper extends KotlinUnwrapRemoveBase {
@Override
protected void doUnwrap(PsiElement element, Context context) throws IncorrectOperationException {
KtFunctionLiteralExpression lambda = (KtFunctionLiteralExpression) element;
KtLambdaExpression lambda = (KtLambdaExpression) element;
KtBlockExpression body = lambda.getBodyExpression();
KtElement enclosingExpression = getLambdaEnclosingElement(lambda);
@@ -227,10 +227,10 @@ public class KotlinExpressionMover extends AbstractKotlinUpDownMover {
(KtCallExpression) KtPsiUtil.getOutermostDescendantElement(element, down, IS_CALL_EXPRESSION);
if (callExpression == null) return null;
List<KtFunctionLiteralArgument> functionLiterals = callExpression.getFunctionLiteralArguments();
List<KtLambdaArgument> functionLiterals = callExpression.getLambdaArguments();
if (functionLiterals.isEmpty()) return null;
return functionLiterals.get(0).getFunctionLiteral().getBodyExpression();
return functionLiterals.get(0).getLambdaExpression().getBodyExpression();
}
@Nullable
@@ -188,7 +188,7 @@ private class VariablesCollector(
// Do not show expressions used in anonymous objects
}
override fun visitFunctionLiteralExpression(expression: KtFunctionLiteralExpression) {
override fun visitLambdaExpression(lambdaExpression: KtLambdaExpression) {
// Do not show expressions used in lambdas
}
}
@@ -299,5 +299,5 @@ private fun wrapInRunFun(expression: KtExpression): PsiElement? {
// Increment modification tracker to clear ResolveCache after changes in function body
(PsiManager.getInstance(expression.project).modificationTracker as PsiModificationTrackerImpl).incCounter()
return replacedBody.functionLiteralArguments.first().getFunctionLiteral().bodyExpression?.firstChild
return replacedBody.lambdaArguments.first().getLambdaExpression().bodyExpression?.firstChild
}
@@ -65,8 +65,8 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
// TODO support class initializers, local functions, delegated properties with specified type, setter for properties
element.accept(object: KtTreeVisitorVoid() {
override fun visitFunctionLiteralExpression(expression: KtFunctionLiteralExpression) {
recordFunctionLiteral(expression.functionLiteral)
override fun visitLambdaExpression(lambdaExpression: KtLambdaExpression) {
recordFunctionLiteral(lambdaExpression.functionLiteral)
}
override fun visitNamedFunction(function: KtNamedFunction) {
@@ -91,7 +91,7 @@ public class KotlinSmartStepIntoHandler : JvmSmartStepIntoHandler() {
return false
}
private fun getArgumentExpression(it: ValueArgument) = (it.getArgumentExpression() as? KtFunctionLiteralExpression)?.functionLiteral ?: it.getArgumentExpression()
private fun getArgumentExpression(it: ValueArgument) = (it.getArgumentExpression() as? KtLambdaExpression)?.functionLiteral ?: it.getArgumentExpression()
override fun visitObjectLiteralExpression(expression: KtObjectLiteralExpression) {
// skip calls in object declarations
@@ -234,7 +234,7 @@ public class KotlinSteppingCommandProvider: JvmSteppingCommandProvider() {
}
}
private fun getArgumentExpression(it: ValueArgument) = (it.getArgumentExpression() as? KtFunctionLiteralExpression)?.functionLiteral ?: it.getArgumentExpression()
private fun getArgumentExpression(it: ValueArgument) = (it.getArgumentExpression() as? KtLambdaExpression)?.functionLiteral ?: it.getArgumentExpression()
private fun getInlineFunctionCallsIfAny(sourcePosition: SourcePosition): List<KtCallExpression> {
val file = sourcePosition.file as? KtFile ?: return emptyList()
@@ -400,7 +400,7 @@ private fun SuspendContextImpl.getNextPositionWithFilter(
}
private fun getInlineArgumentIfAny(elementAt: PsiElement?): KtFunctionLiteral? {
val functionLiteralExpression = elementAt?.getParentOfType<KtFunctionLiteralExpression>(false) ?: return null
val functionLiteralExpression = elementAt?.getParentOfType<KtLambdaExpression>(false) ?: return null
val context = functionLiteralExpression.analyze(BodyResolveMode.PARTIAL)
if (!InlineUtil.isInlinedArgument(functionLiteralExpression.functionLiteral, context, false)) return null
@@ -23,7 +23,7 @@ public class KotlinForConditionFixer: MissingConditionFixer<KtForExpression>() {
override val keyword = "for"
override fun getElement(element: PsiElement?) = element as? KtForExpression
override fun getCondition(element: KtForExpression) =
element.getLoopRange() ?: element.getLoopParameter() ?: element.getMultiParameter()
element.getLoopRange() ?: element.getLoopParameter() ?: element.getDestructuringParameter()
override fun getLeftParenthesis(element: KtForExpression) = element.getLeftParenthesis()
override fun getRightParenthesis(element: KtForExpression) = element.getRightParenthesis()
override fun getBody(element: KtForExpression) = element.getBody()
@@ -25,7 +25,7 @@ import java.util.ArrayList
import org.jetbrains.kotlin.psi.psiUtil.siblings
import com.intellij.psi.PsiComment
import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.psi.KtMultiDeclaration
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.psiUtil.startOffset
@@ -34,7 +34,7 @@ public class KotlinDeclarationSelectioner : ExtendWordSelectionHandlerBase() {
= e is KtDeclaration
override fun select(e: PsiElement, editorText: CharSequence, cursorOffset: Int, editor: Editor): List<TextRange>? {
if (e is KtMultiDeclaration) {
if (e is KtDestructuringDeclaration) {
return selectMultiDeclaration(editorText, e)
}
@@ -58,7 +58,7 @@ public class KotlinDeclarationSelectioner : ExtendWordSelectionHandlerBase() {
return result
}
private fun selectMultiDeclaration(editorText: CharSequence, e: KtMultiDeclaration): ArrayList<TextRange> {
private fun selectMultiDeclaration(editorText: CharSequence, e: KtDestructuringDeclaration): ArrayList<TextRange> {
val result = ArrayList<TextRange>()
val lpar = e.lPar
val rpar = e.rPar
@@ -43,7 +43,7 @@ public class KotlinElementDescriptionProvider : ElementDescriptionProvider {
is KtProperty -> if (targetElement.isLocal()) "variable" else "property"
is KtTypeParameter -> "type parameter"
is KtParameter -> "parameter"
is KtMultiDeclarationEntry -> "variable"
is KtDestructuringDeclarationEntry -> "variable"
else -> null
}
@@ -294,7 +294,7 @@ public class KotlinBlock extends AbstractBlock {
return NodeAlignmentStrategy.fromTypes(AlignmentStrategy.wrap(
createAlignment(jetCommonSettings.ALIGN_MULTILINE_BINARY_OPERATION, getAlignment())));
}
else if (parentType == DELEGATION_SPECIFIER_LIST || parentType == INITIALIZER_LIST) {
else if (parentType == SUPER_TYPE_LIST || parentType == INITIALIZER_LIST) {
return NodeAlignmentStrategy.fromTypes(AlignmentStrategy.wrap(
createAlignment(jetCommonSettings.ALIGN_MULTILINE_EXTENDS_LIST, getAlignment())));
}
@@ -396,7 +396,7 @@ public class KotlinBlock extends AbstractBlock {
.set(Indent.getNormalIndent()),
strategy("Indent for parts")
.in(PROPERTY, FUN, MULTI_VARIABLE_DECLARATION)
.in(PROPERTY, FUN, DESTRUCTURING_DECLARATION)
.notForType(BLOCK, FUN_KEYWORD, VAL_KEYWORD, VAR_KEYWORD)
.set(Indent.getContinuationWithoutFirstIndent()),
@@ -405,7 +405,7 @@ public class KotlinBlock extends AbstractBlock {
.set(Indent.getContinuationWithoutFirstIndent(false)),
strategy("Delegation list")
.in(DELEGATION_SPECIFIER_LIST, INITIALIZER_LIST)
.in(SUPER_TYPE_LIST, INITIALIZER_LIST)
.set(Indent.getContinuationIndent(false)),
strategy("Indices")
@@ -199,10 +199,10 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
betweenInside(WHEN_KEYWORD, LPAR, WHEN).spacing(1, 1, 0, false, 0)
betweenInside(LPAR, VALUE_PARAMETER, FOR).spaces(0)
betweenInside(LPAR, MULTI_VARIABLE_DECLARATION, FOR).spaces(0)
betweenInside(LPAR, DESTRUCTURING_DECLARATION, FOR).spaces(0)
betweenInside(LOOP_RANGE, RPAR, FOR).spaces(0)
val TYPE_COLON_ELEMENTS = TokenSet.create(PROPERTY, FUN, VALUE_PARAMETER, MULTI_VARIABLE_DECLARATION_ENTRY, FUNCTION_LITERAL)
val TYPE_COLON_ELEMENTS = TokenSet.create(PROPERTY, FUN, VALUE_PARAMETER, DESTRUCTURING_DECLARATION_ENTRY, FUNCTION_LITERAL)
beforeInside(COLON, TYPE_COLON_ELEMENTS) { spaceIf(jetSettings.SPACE_BEFORE_TYPE_COLON) }
afterInside(COLON, TYPE_COLON_ELEMENTS) { spaceIf(jetSettings.SPACE_AFTER_TYPE_COLON) }
@@ -215,9 +215,9 @@ fun createSpacingBuilder(settings: CodeStyleSettings): KotlinSpacingBuilder {
aroundInside(ARROW, FUNCTION_TYPE).spaceIf(jetSettings.SPACE_AROUND_FUNCTION_TYPE_ARROW)
between(VALUE_ARGUMENT_LIST, FUNCTION_LITERAL_ARGUMENT).spaces(1)
betweenInside(REFERENCE_EXPRESSION, FUNCTION_LITERAL_ARGUMENT, CALL_EXPRESSION).spaces(1)
betweenInside(TYPE_ARGUMENT_LIST, FUNCTION_LITERAL_ARGUMENT, CALL_EXPRESSION).spaces(1)
between(VALUE_ARGUMENT_LIST, LAMBDA_ARGUMENT).spaces(1)
betweenInside(REFERENCE_EXPRESSION, LAMBDA_ARGUMENT, CALL_EXPRESSION).spaces(1)
betweenInside(TYPE_ARGUMENT_LIST, LAMBDA_ARGUMENT, CALL_EXPRESSION).spaces(1)
}
custom {
@@ -63,7 +63,7 @@ public class KotlinCalleeMethodsTreeStructure extends KotlinCallTreeStructure {
}
} else {
KtClassOrObject classOrObject = (KtClassOrObject) rootElement;
for (KtDelegationSpecifier specifier : classOrObject.getDelegationSpecifiers()) {
for (KtSuperTypeListEntry specifier : classOrObject.getSuperTypeListEntries()) {
if (specifier instanceof KtCallElement) {
elementsToAnalyze.add(specifier);
}
@@ -77,7 +77,7 @@ class EqualsOrHashCodeInspection : AbstractKotlinInspection() {
when (classDescriptor.kind) {
ClassKind.OBJECT -> {
if (classOrObject.getDelegationSpecifiers().isNotEmpty()) return
if (classOrObject.getSuperTypeListEntries().isNotEmpty()) return
holder.registerProblem(nameIdentifier, "equals()/hashCode() in object declaration", DeleteEqualsAndHashCodeFix)
}
ClassKind.CLASS -> {
@@ -204,7 +204,7 @@ public class RedundantSamConstructorInspection : AbstractKotlinInspection() {
= argument.toCallExpression()?.samConstructorValueArgument() != null
private fun KtCallExpression.samConstructorValueArgument(): KtValueArgument? {
return valueArguments.singleOrNull()?.check { it.getArgumentExpression() is KtFunctionLiteralExpression }
return valueArguments.singleOrNull()?.check { it.getArgumentExpression() is KtLambdaExpression }
}
private fun ValueArgument.toCallExpression(): KtCallExpression? {
@@ -62,7 +62,7 @@ public class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpre
loopRange.replace(createWithIndexExpression(loopRange))
var multiParameter = (psiFactory.createExpressionByPattern("for((index, $0) in x){}", loopParameter.text) as KtForExpression).multiParameter!!
var multiParameter = (psiFactory.createExpressionByPattern("for((index, $0) in x){}", loopParameter.text) as KtForExpression).destructuringParameter!!
multiParameter = loopParameter.replaced(multiParameter)
@@ -72,7 +72,7 @@ public class AddForLoopIndicesIntention : SelfTargetingRangeIntention<KtForExpre
runTemplate(editor, element, indexVariable)
}
private fun runTemplate(editor: Editor, forExpression: KtForExpression, indexVariable: KtMultiDeclarationEntry) {
private fun runTemplate(editor: Editor, forExpression: KtForExpression, indexVariable: KtDestructuringDeclarationEntry) {
PsiDocumentManager.getInstance(forExpression.project).doPostponedOperationsAndUnblockDocument(editor.document)
val templateBuilder = TemplateBuilderImpl(forExpression)
@@ -40,7 +40,7 @@ public class AddNameToArgumentIntention
setText("Add '$name =' to argument")
if (expression is KtFunctionLiteralExpression) {
if (expression is KtLambdaExpression) {
val range = expression.getTextRange()
return caretOffset == range.start || caretOffset == range.end
}
@@ -59,7 +59,7 @@ public class AddNameToArgumentIntention
private fun detectNameToAdd(argument: KtValueArgument): Name? {
if (argument.isNamed()) return null
if (argument is KtFunctionLiteralArgument) return null
if (argument is KtLambdaArgument) return null
val argumentList = argument.getParent() as? KtValueArgumentList ?: return null
if (argument != argumentList.arguments.last { !it.isNamed() }) return null
@@ -37,7 +37,7 @@ public class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCall
val argumentSize = element.getValueArguments().size()
if (argumentSize !in 1..2) return false
val functionLiterals = element.getFunctionLiteralArguments()
val functionLiterals = element.getLambdaArguments()
if (functionLiterals.size() > 1) return false
if (functionLiterals.size() == 1 && argumentSize == 1) return false // "assert {...}" is incorrect
@@ -48,17 +48,17 @@ public class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCall
override fun applyTo(element: KtCallExpression, editor: Editor) {
val args = element.getValueArguments()
val conditionText = args[0]?.getArgumentExpression()?.getText() ?: return
val functionLiteralArgument = element.functionLiteralArguments.singleOrNull()
val functionLiteralArgument = element.lambdaArguments.singleOrNull()
val bindingContext = element.analyze(BodyResolveMode.PARTIAL)
val psiFactory = KtPsiFactory(element)
val messageFunctionExpr = when {
args.size == 2 -> args[1]?.getArgumentExpression() ?: return
functionLiteralArgument != null -> functionLiteralArgument.getFunctionLiteral()
functionLiteralArgument != null -> functionLiteralArgument.getLambdaExpression()
else -> null
}
val extractedMessageSingleExpr = (messageFunctionExpr as? KtFunctionLiteralExpression)?.let { extractMessageSingleExpression(it, bindingContext) }
val extractedMessageSingleExpr = (messageFunctionExpr as? KtLambdaExpression)?.let { extractMessageSingleExpression(it, bindingContext) }
val messageIsFunction = extractedMessageSingleExpr == null && messageIsFunction(element, bindingContext)
val messageExpr = extractedMessageSingleExpr ?: messageFunctionExpr ?: psiFactory.createExpression("\"Assertion failed\"")
@@ -93,7 +93,7 @@ public class ConvertAssertToIfWithThrowIntention : SelfTargetingIntention<KtCall
simplifyConditionIfPossible(ifExpression)
}
private fun extractMessageSingleExpression(functionLiteral: KtFunctionLiteralExpression, bindingContext: BindingContext): KtExpression? {
private fun extractMessageSingleExpression(functionLiteral: KtLambdaExpression, bindingContext: BindingContext): KtExpression? {
return functionLiteral.bodyExpression?.statements?.singleOrNull()?.let { singleStatement ->
singleStatement.check { it.isUsedAsExpression(bindingContext) }
}
@@ -49,7 +49,7 @@ public class ConvertForEachToForLoopIntention : SelfTargetingOffsetIndependentIn
private data class Data(
val expressionToReplace: KtExpression,
val receiver: KtExpression,
val functionLiteral: KtFunctionLiteralExpression
val functionLiteral: KtLambdaExpression
)
private fun extractData(nameExpr: KtSimpleNameExpression): Data? {
@@ -65,11 +65,11 @@ public class ConvertForEachToForLoopIntention : SelfTargetingOffsetIndependentIn
val receiver = resolvedCall.getCall().getExplicitReceiver() as? ExpressionReceiver ?: return null
val argument = resolvedCall.getCall().getValueArguments().singleOrNull() ?: return null
val functionLiteral = argument.getArgumentExpression() as? KtFunctionLiteralExpression ?: return null
val functionLiteral = argument.getArgumentExpression() as? KtLambdaExpression ?: return null
return Data(expression, receiver.expression, functionLiteral)
}
private fun generateLoop(functionLiteral: KtFunctionLiteralExpression, receiver: KtExpression): KtExpression {
private fun generateLoop(functionLiteral: KtLambdaExpression, receiver: KtExpression): KtExpression {
val factory = KtPsiFactory(functionLiteral)
val loopRange = KtPsiUtil.safeDeparenthesize(receiver)
val body = functionLiteral.getBodyExpression()!!
@@ -34,7 +34,7 @@ public class InfixCallToOrdinaryIntention : SelfTargetingIntention<KtBinaryExpre
public fun convert(element: KtBinaryExpression): KtExpression {
val argument = KtPsiUtil.safeDeparenthesize(element.getRight()!!)
val pattern = "$0.$1" + when (argument) {
is KtFunctionLiteralExpression -> " $2:'{}'"
is KtLambdaExpression -> " $2:'{}'"
else -> "($2)"
}
val replacement = KtPsiFactory(element).createExpressionByPattern(pattern, element.getLeft()!!, element.getOperationReference().getText(), argument)
@@ -21,16 +21,16 @@ import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.idea.core.moveInsideParentheses
import org.jetbrains.kotlin.psi.KtFunctionLiteralArgument
import org.jetbrains.kotlin.psi.KtLambdaArgument
import org.jetbrains.kotlin.psi.psiUtil.containsInside
public class MoveLambdaInsideParenthesesIntention : SelfTargetingIntention<KtFunctionLiteralArgument>(javaClass(), "Move lambda argument into parentheses"), LowPriorityAction {
override fun isApplicableTo(element: KtFunctionLiteralArgument, caretOffset: Int): Boolean {
val body = element.getFunctionLiteral().getBodyExpression() ?: return true
public class MoveLambdaInsideParenthesesIntention : SelfTargetingIntention<KtLambdaArgument>(javaClass(), "Move lambda argument into parentheses"), LowPriorityAction {
override fun isApplicableTo(element: KtLambdaArgument, caretOffset: Int): Boolean {
val body = element.getLambdaExpression().getBodyExpression() ?: return true
return !body.getTextRange().containsInside(caretOffset)
}
override fun applyTo(element: KtFunctionLiteralArgument, editor: Editor) {
override fun applyTo(element: KtLambdaArgument, editor: Editor) {
element.moveInsideParentheses(element.analyze())
}
}
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode
public class MoveLambdaOutsideParenthesesIntention : SelfTargetingIntention<KtCallExpression>(javaClass(), "Move lambda argument out of parentheses") {
override fun isApplicableTo(element: KtCallExpression, caretOffset: Int): Boolean {
if (element.getFunctionLiteralArguments().isNotEmpty()) return false
if (element.getLambdaArguments().isNotEmpty()) return false
val argument = element.getValueArguments().lastOrNull() ?: return false
val expression = argument.getArgumentExpression() ?: return false
val functionLiteral = expression.unpackFunctionLiteral() ?: return false
@@ -118,7 +118,7 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention<KtObjectLiter
val callee = replaced.getCalleeExpressionIfAny()!! as KtNameReferenceExpression
val callExpression = callee.parent as KtCallExpression
val functionLiteral = callExpression.functionLiteralArguments.single().getFunctionLiteral()
val functionLiteral = callExpression.lambdaArguments.single().getLambdaExpression()
val lambdaBody = functionLiteral.bodyExpression!!
@@ -190,7 +190,7 @@ class ObjectLiteralToLambdaIntention : SelfTargetingRangeIntention<KtObjectLiter
val singleFunction = objectDeclaration.declarations.singleOrNull() as? KtNamedFunction ?: return null
if (!singleFunction.hasModifier(KtTokens.OVERRIDE_KEYWORD)) return null
val delegationSpecifier = objectDeclaration.getDelegationSpecifiers().singleOrNull() ?: return null
val delegationSpecifier = objectDeclaration.getSuperTypeListEntries().singleOrNull() ?: return null
val typeRef = delegationSpecifier.typeReference ?: return null
val bindingContext = typeRef.analyze(BodyResolveMode.PARTIAL)
val baseType = bindingContext[BindingContext.TYPE, typeRef] ?: return null
@@ -17,19 +17,19 @@
package org.jetbrains.kotlin.idea.intentions
import com.intellij.openapi.editor.Editor
import org.jetbrains.kotlin.psi.KtFunctionLiteralExpression
import org.jetbrains.kotlin.psi.KtLambdaExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.psiUtil.endOffset
public class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention<KtFunctionLiteralExpression>(javaClass(), "Remove explicit lambda parameter types (may break code)") {
override fun isApplicableTo(element: KtFunctionLiteralExpression, caretOffset: Int): Boolean {
public class RemoveExplicitLambdaParameterTypesIntention : SelfTargetingIntention<KtLambdaExpression>(javaClass(), "Remove explicit lambda parameter types (may break code)") {
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
if (element.getValueParameters().none { it.getTypeReference() != null }) return false
val arrow = element.getFunctionLiteral().getArrow() ?: return false
return caretOffset <= arrow.endOffset
}
override fun applyTo(element: KtFunctionLiteralExpression, editor: Editor) {
override fun applyTo(element: KtLambdaExpression, editor: Editor) {
val oldParameterList = element.getFunctionLiteral().getValueParameterList()!!
val parameterString = oldParameterList.getParameters().map { it.getName() }.joinToString(", ")
@@ -45,7 +45,7 @@ public class RemoveForLoopIndicesIntention : SelfTargetingRangeIntention<KtForEx
override fun applicabilityRange(element: KtForExpression): TextRange? {
val loopRange = element.loopRange as? KtDotQualifiedExpression ?: return null
val multiParameter = element.multiParameter ?: return null
val multiParameter = element.destructuringParameter ?: return null
if (multiParameter.entries.size() != 2) return null
val bindingContext = element.analyze(BodyResolveMode.PARTIAL)
@@ -60,7 +60,7 @@ public class RemoveForLoopIndicesIntention : SelfTargetingRangeIntention<KtForEx
}
override fun applyTo(element: KtForExpression, editor: Editor) {
val multiParameter = element.multiParameter!!
val multiParameter = element.destructuringParameter!!
val loopRange = element.loopRange as KtDotQualifiedExpression
val elementVar = multiParameter.entries[1]
@@ -37,7 +37,7 @@ public class ReplaceItWithExplicitFunctionLiteralParamIntention() : SelfTargetin
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(target.getContainingDeclaration()!!) as KtFunctionLiteral
val newExpr = KtPsiFactory(element).createExpression("{ it -> }") as KtFunctionLiteralExpression
val newExpr = KtPsiFactory(element).createExpression("{ it -> }") as KtLambdaExpression
functionLiteral.addRangeAfter(
newExpr.getFunctionLiteral().getValueParameterList(),
newExpr.getFunctionLiteral().getArrow()!!,
@@ -22,14 +22,14 @@ import com.intellij.psi.PsiWhiteSpace
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.util.ShortenReferences
import org.jetbrains.kotlin.psi.KtFunctionLiteralExpression
import org.jetbrains.kotlin.psi.KtLambdaExpression
import org.jetbrains.kotlin.psi.KtPsiFactory
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.resolve.BindingContext
public class SpecifyExplicitLambdaSignatureIntention : SelfTargetingIntention<KtFunctionLiteralExpression>(javaClass(), "Specify explicit lambda signature"), LowPriorityAction {
public class SpecifyExplicitLambdaSignatureIntention : SelfTargetingIntention<KtLambdaExpression>(javaClass(), "Specify explicit lambda signature"), LowPriorityAction {
override fun isApplicableTo(element: KtFunctionLiteralExpression, caretOffset: Int): Boolean {
override fun isApplicableTo(element: KtLambdaExpression, caretOffset: Int): Boolean {
val arrow = element.getFunctionLiteral().getArrow()
if (arrow != null) {
if (caretOffset > arrow.endOffset) return false
@@ -43,7 +43,7 @@ public class SpecifyExplicitLambdaSignatureIntention : SelfTargetingIntention<Kt
return functionDescriptor.getValueParameters().none { it.getType().isError() }
}
override fun applyTo(element: KtFunctionLiteralExpression, editor: Editor) {
override fun applyTo(element: KtLambdaExpression, editor: Editor) {
val psiFactory = KtPsiFactory(element)
val functionLiteral = element.getFunctionLiteral()
val functionDescriptor = element.analyze()[BindingContext.FUNCTION, functionLiteral]!!
@@ -129,7 +129,7 @@ class UsePropertyAccessSyntaxIntention : SelfTargetingOffsetIndependentIntention
override fun getCalleeExpression() = newCallee
override fun getValueArgumentList(): KtValueArgumentList? = null
override fun getValueArguments(): List<ValueArgument> = emptyList()
override fun getFunctionLiteralArguments(): List<FunctionLiteralArgument> = emptyList()
override fun getFunctionLiteralArguments(): List<LambdaArgument> = emptyList()
}
val bindingTrace = DelegatingBindingTrace(bindingContext, "Temporary trace")
@@ -61,7 +61,7 @@ public class ReplaceContainsIntention : SelfTargetingRangeIntention<KtDotQualifi
}
// Append semicolon to previous statement if needed
if (argument is KtFunctionLiteralExpression) {
if (argument is KtLambdaExpression) {
val previousElement = KtPsiUtil.skipSiblingsBackwardByPredicate(expression) {
it.getNode().getElementType() in KtTokens.WHITE_SPACE_OR_COMMENT_BIT_SET
}
@@ -188,7 +188,7 @@ abstract class KotlinParameterInfoWithCallHandlerBase<TArgumentList : KtElement,
}
for (argument in call.valueArguments) {
if (argument is FunctionLiteralArgument) continue
if (argument is LambdaArgument) continue
val parameter = argumentToParameter(argument) ?: continue
if (!usedParameterIndices.add(parameter.index)) continue
@@ -336,7 +336,7 @@ abstract class KotlinParameterInfoWithCallHandlerBase<TArgumentList : KtElement,
val arguments = call.valueArguments + currentArgument
override fun getValueArguments() = arguments
override fun getFunctionLiteralArguments() = emptyList<FunctionLiteralArgument>()
override fun getFunctionLiteralArguments() = emptyList<LambdaArgument>()
override fun getValueArgumentList() = null
}
}
@@ -48,12 +48,12 @@ import java.util.List;
import static org.jetbrains.kotlin.idea.project.PlatformKt.getPlatform;
public class ChangeFunctionLiteralReturnTypeFix extends KotlinQuickFixAction<KtFunctionLiteralExpression> {
public class ChangeFunctionLiteralReturnTypeFix extends KotlinQuickFixAction<KtLambdaExpression> {
private final KotlinType type;
private final KtTypeReference functionLiteralReturnTypeRef;
private IntentionAction appropriateQuickFix = null;
public ChangeFunctionLiteralReturnTypeFix(@NotNull KtFunctionLiteralExpression functionLiteralExpression, @NotNull KotlinType type) {
public ChangeFunctionLiteralReturnTypeFix(@NotNull KtLambdaExpression functionLiteralExpression, @NotNull KotlinType type) {
super(functionLiteralExpression);
this.type = type;
functionLiteralReturnTypeRef = functionLiteralExpression.getFunctionLiteral().getTypeReference();
@@ -150,8 +150,8 @@ public class ChangeFunctionLiteralReturnTypeFix extends KotlinQuickFixAction<KtF
@Nullable
@Override
public IntentionAction createAction(@NotNull Diagnostic diagnostic) {
KtFunctionLiteralExpression
functionLiteralExpression = QuickFixUtil.getParentElementOfType(diagnostic, KtFunctionLiteralExpression.class);
KtLambdaExpression
functionLiteralExpression = QuickFixUtil.getParentElementOfType(diagnostic, KtLambdaExpression.class);
if (functionLiteralExpression == null) return null;
return new ChangeFunctionLiteralReturnTypeFix(functionLiteralExpression, getPlatform(functionLiteralExpression).getBuiltIns().getUnitType());
}
@@ -62,7 +62,7 @@ public class ChangeFunctionReturnTypeFix extends KotlinQuickFixAction<KtFunction
super(element);
this.type = type;
if (element instanceof KtFunctionLiteral) {
KtFunctionLiteralExpression functionLiteralExpression = PsiTreeUtil.getParentOfType(element, KtFunctionLiteralExpression.class);
KtLambdaExpression functionLiteralExpression = PsiTreeUtil.getParentOfType(element, KtLambdaExpression.class);
assert functionLiteralExpression != null : "FunctionLiteral outside any FunctionLiteralExpression: " +
PsiUtilsKt.getElementTextWithContext(element);
changeFunctionLiteralReturnTypeFix = new ChangeFunctionLiteralReturnTypeFix(functionLiteralExpression, type);
@@ -125,10 +125,10 @@ public class ChangeFunctionReturnTypeFix extends KotlinQuickFixAction<KtFunction
}
@NotNull
public static KtMultiDeclarationEntry getMultiDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) {
public static KtDestructuringDeclarationEntry getDestructuringDeclarationEntryThatTypeMismatchComponentFunction(Diagnostic diagnostic) {
Name componentName = COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH.cast(diagnostic).getA();
int componentIndex = DataClassUtilsKt.getComponentIndex(componentName);
KtMultiDeclaration multiDeclaration = QuickFixUtil.getParentElementOfType(diagnostic, KtMultiDeclaration.class);
KtDestructuringDeclaration multiDeclaration = QuickFixUtil.getParentElementOfType(diagnostic, KtDestructuringDeclaration.class);
assert multiDeclaration != null : "COMPONENT_FUNCTION_RETURN_TYPE_MISMATCH reported on expression that is not within any multi declaration";
return multiDeclaration.getEntries().get(componentIndex - 1);
}
@@ -139,7 +139,7 @@ public class ChangeFunctionReturnTypeFix extends KotlinQuickFixAction<KtFunction
@Nullable
@Override
public IntentionAction createAction(@NotNull Diagnostic diagnostic) {
KtMultiDeclarationEntry entry = getMultiDeclarationEntryThatTypeMismatchComponentFunction(diagnostic);
KtDestructuringDeclarationEntry entry = getDestructuringDeclarationEntryThatTypeMismatchComponentFunction(diagnostic);
BindingContext context = ResolutionUtils.analyze(entry);
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
if (resolvedCall == null) return null;
@@ -114,8 +114,8 @@ public class ChangeVariableTypeFix extends KotlinQuickFixAction<KtVariableDeclar
@Nullable
@Override
public IntentionAction createAction(@NotNull Diagnostic diagnostic) {
KtMultiDeclarationEntry
entry = ChangeFunctionReturnTypeFix.getMultiDeclarationEntryThatTypeMismatchComponentFunction(diagnostic);
KtDestructuringDeclarationEntry
entry = ChangeFunctionReturnTypeFix.getDestructuringDeclarationEntryThatTypeMismatchComponentFunction(diagnostic);
BindingContext context = ResolutionUtils.analyze(entry);
ResolvedCall<FunctionDescriptor> resolvedCall = context.get(BindingContext.COMPONENT_RESOLVED_CALL, entry);
if (resolvedCall == null) return null;
@@ -259,8 +259,8 @@ public class QuickFixRegistrar : QuickFixContributor {
NO_VALUE_FOR_PARAMETER.registerFactory(CreateConstructorFromDelegationCallActionFactory)
TOO_MANY_ARGUMENTS.registerFactory(CreateConstructorFromDelegationCallActionFactory)
NO_VALUE_FOR_PARAMETER.registerFactory(CreateConstructorFromDelegatorToSuperCallActionFactory)
TOO_MANY_ARGUMENTS.registerFactory(CreateConstructorFromDelegatorToSuperCallActionFactory)
NO_VALUE_FOR_PARAMETER.registerFactory(CreateConstructorFromSuperTypeCallActionFactory)
TOO_MANY_ARGUMENTS.registerFactory(CreateConstructorFromSuperTypeCallActionFactory)
UNRESOLVED_REFERENCE_WRONG_RECEIVER.registerFactory(CreateClassFromConstructorCallActionFactory)
UNRESOLVED_REFERENCE.registerFactory(CreateClassFromConstructorCallActionFactory)
@@ -27,13 +27,13 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic;
import org.jetbrains.kotlin.idea.KotlinBundle;
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil;
import org.jetbrains.kotlin.lexer.KtTokens;
import org.jetbrains.kotlin.psi.KtDelegationSpecifier;
import org.jetbrains.kotlin.psi.KtSuperTypeListEntry;
import org.jetbrains.kotlin.psi.KtFile;
public class RemoveSupertypeFix extends KotlinQuickFixAction<KtDelegationSpecifier> {
private final KtDelegationSpecifier superClass;
public class RemoveSupertypeFix extends KotlinQuickFixAction<KtSuperTypeListEntry> {
private final KtSuperTypeListEntry superClass;
public RemoveSupertypeFix(@NotNull KtDelegationSpecifier superClass) {
public RemoveSupertypeFix(@NotNull KtSuperTypeListEntry superClass) {
super(superClass);
this.superClass = superClass;
}
@@ -67,8 +67,8 @@ public class RemoveSupertypeFix extends KotlinQuickFixAction<KtDelegationSpecifi
public static KotlinSingleIntentionActionFactory createFactory() {
return new KotlinSingleIntentionActionFactory() {
@Override
public KotlinQuickFixAction<KtDelegationSpecifier> createAction(Diagnostic diagnostic) {
KtDelegationSpecifier superClass = QuickFixUtil.getParentElementOfType(diagnostic, KtDelegationSpecifier.class);
public KotlinQuickFixAction<KtSuperTypeListEntry> createAction(Diagnostic diagnostic) {
KtSuperTypeListEntry superClass = QuickFixUtil.getParentElementOfType(diagnostic, KtSuperTypeListEntry.class);
if (superClass == null) return null;
return new RemoveSupertypeFix(superClass);
}
@@ -49,7 +49,7 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() {
private val DISPLAY_MAX_PARAMS = 5
override fun doCreateActions(diagnostic: Diagnostic): List<IntentionAction> {
val delegator = diagnostic.getPsiElement() as KtDelegatorToSuperClass
val delegator = diagnostic.getPsiElement() as KtSuperTypeEntry
val classOrObjectDeclaration = delegator.getParent().getParent() as? KtClassOrObject ?: return emptyList()
val typeRef = delegator.getTypeReference() ?: return emptyList()
@@ -103,16 +103,16 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() {
}
private class AddParenthesisFix(
element: KtDelegatorToSuperClass,
element: KtSuperTypeEntry,
val putCaretIntoParenthesis: Boolean
) : KotlinQuickFixAction<KtDelegatorToSuperClass>(element), HighPriorityAction {
) : KotlinQuickFixAction<KtSuperTypeEntry>(element), HighPriorityAction {
override fun getFamilyName() = "Change to constructor invocation" //TODO?
override fun getText() = getFamilyName()
override fun invoke(project: Project, editor: Editor?, file: KtFile) {
val newSpecifier = element.replaced(KtPsiFactory(project).createDelegatorToSuperCall(element.getText() + "()"))
val newSpecifier = element.replaced(KtPsiFactory(project).createSuperTypeCallEntry(element.getText() + "()"))
if (putCaretIntoParenthesis) {
if (editor != null) {
@@ -127,16 +127,16 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() {
}
private class AddParametersFix(
element: KtDelegatorToSuperClass,
element: KtSuperTypeEntry,
private val classDeclaration: KtClass,
private val parametersToAdd: Collection<KtParameter>,
private val argumentText: String,
private val text: String
) : KotlinQuickFixAction<KtDelegatorToSuperClass>(element) {
) : KotlinQuickFixAction<KtSuperTypeEntry>(element) {
companion object {
fun create(
element: KtDelegatorToSuperClass,
element: KtSuperTypeEntry,
classDeclaration: KtClass,
superConstructor: ConstructorDescriptor,
text: String
@@ -191,7 +191,7 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() {
typeRefsToShorten.add(newParameter.typeReference!!)
}
val delegatorCall = factory.createDelegatorToSuperCall(element.text + "(" + argumentText + ")")
val delegatorCall = factory.createSuperTypeCallEntry(element.text + "(" + argumentText + ")")
element.replace(delegatorCall)
ShortenReferences.DEFAULT.process(typeRefsToShorten)
@@ -733,7 +733,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
expression = TypeExpression.ForTypeReference(candidates)
}
is KtClassOrObject -> {
elementToReplace = declaration.getDelegationSpecifiers().firstOrNull()
elementToReplace = declaration.getSuperTypeListEntries().firstOrNull()
expression = TypeExpression.ForDelegationSpecifier(candidates)
}
else -> throw AssertionError("Unexpected declaration kind: ${declaration.getText()}")
@@ -1033,7 +1033,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
internal fun KtNamedDeclaration.getReturnTypeReference(): KtTypeReference? {
return when (this) {
is KtCallableDeclaration -> getTypeReference()
is KtClassOrObject -> getDelegationSpecifiers().firstOrNull()?.getTypeReference()
is KtClassOrObject -> getSuperTypeListEntries().firstOrNull()?.getTypeReference()
else -> throw AssertionError("Unexpected declaration kind: ${getText()}")
}
}
@@ -148,7 +148,7 @@ fun KtExpression.guessTypes(
val constraint = parent
arrayOf(context[BindingContext.TYPE, constraint.getBoundTypeReference()]!!)
}
this is KtMultiDeclarationEntry -> {
this is KtDestructuringDeclarationEntry -> {
// expression is on the lhs of a multi-declaration
val typeRef = getTypeReference()
if (typeRef != null) {
@@ -23,18 +23,18 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.Callab
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.FunctionInfo
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
import org.jetbrains.kotlin.psi.KtForExpression
import org.jetbrains.kotlin.psi.KtMultiDeclaration
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
import org.jetbrains.kotlin.resolve.dataClassUtils.getComponentIndex
import org.jetbrains.kotlin.resolve.dataClassUtils.isComponentLike
import org.jetbrains.kotlin.types.Variance
object CreateComponentFunctionActionFactory : CreateCallableMemberFromUsageFactory<KtMultiDeclaration>() {
override fun getElementOfInterest(diagnostic: Diagnostic): KtMultiDeclaration? {
QuickFixUtil.getParentElementOfType(diagnostic, javaClass<KtMultiDeclaration>())?.let { return it }
return QuickFixUtil.getParentElementOfType(diagnostic, javaClass<KtForExpression>())?.multiParameter
object CreateComponentFunctionActionFactory : CreateCallableMemberFromUsageFactory<KtDestructuringDeclaration>() {
override fun getElementOfInterest(diagnostic: Diagnostic): KtDestructuringDeclaration? {
QuickFixUtil.getParentElementOfType(diagnostic, javaClass<KtDestructuringDeclaration>())?.let { return it }
return QuickFixUtil.getParentElementOfType(diagnostic, javaClass<KtForExpression>())?.destructuringParameter
}
override fun createCallableInfo(element: KtMultiDeclaration, diagnostic: Diagnostic): CallableInfo? {
override fun createCallableInfo(element: KtDestructuringDeclaration, diagnostic: Diagnostic): CallableInfo? {
val diagnosticWithParameters = Errors.COMPONENT_FUNCTION_MISSING.cast(diagnostic)
val name = diagnosticWithParameters.a
@@ -17,7 +17,6 @@
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable
import com.intellij.psi.PsiClass
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.diagnostics.Diagnostic
@@ -29,18 +28,18 @@ import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.Parame
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.SecondaryConstructorInfo
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
import org.jetbrains.kotlin.psi.KtClass
import org.jetbrains.kotlin.psi.KtDelegatorToSuperCall
import org.jetbrains.kotlin.psi.KtSuperTypeCallEntry
import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.types.Variance
object CreateConstructorFromDelegatorToSuperCallActionFactory : CreateCallableMemberFromUsageFactory<KtDelegatorToSuperCall>() {
override fun getElementOfInterest(diagnostic: Diagnostic): KtDelegatorToSuperCall? {
return diagnostic.psiElement.getStrictParentOfType<KtDelegatorToSuperCall>()
object CreateConstructorFromSuperTypeCallActionFactory : CreateCallableMemberFromUsageFactory<KtSuperTypeCallEntry>() {
override fun getElementOfInterest(diagnostic: Diagnostic): KtSuperTypeCallEntry? {
return diagnostic.psiElement.getStrictParentOfType<KtSuperTypeCallEntry>()
}
override fun createCallableInfo(element: KtDelegatorToSuperCall, diagnostic: Diagnostic): CallableInfo? {
override fun createCallableInfo(element: KtSuperTypeCallEntry, diagnostic: Diagnostic): CallableInfo? {
val typeReference = element.calleeExpression.typeReference ?: return null
val project = element.project
@@ -41,7 +41,7 @@ object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactor
override fun createCallableInfo(element: KtForExpression, diagnostic: Diagnostic): CallableInfo? {
val file = diagnostic.psiFile as? KtFile ?: return null
val iterableExpr = element.loopRange ?: return null
val variableExpr: KtExpression = ((element.loopParameter ?: element.multiParameter) ?: return null) as KtExpression
val variableExpr: KtExpression = ((element.loopParameter ?: element.destructuringParameter) ?: return null) as KtExpression
val iterableType = TypeInfo(iterableExpr, Variance.IN_VARIANCE)
val (bindingContext, moduleDescriptor) = file.analyzeFullyAndGetResult()
@@ -37,7 +37,7 @@ object CreateNextFunctionActionFactory : CreateCallableMemberFromUsageFactory<Kt
val diagnosticWithParameters = DiagnosticFactory.cast(diagnostic, Errors.NEXT_MISSING, Errors.NEXT_NONE_APPLICABLE)
val ownerType = TypeInfo(diagnosticWithParameters.a, Variance.IN_VARIANCE)
val variableExpr = element.loopParameter ?: element.multiParameter ?: return null
val variableExpr = element.loopParameter ?: element.destructuringParameter ?: return null
val returnType = TypeInfo(variableExpr as KtExpression, Variance.OUT_VARIANCE)
return FunctionInfo(OperatorNameConventions.NEXT.asString(), ownerType, returnType, isOperator = true)
}
@@ -17,9 +17,7 @@
package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass
import com.intellij.psi.util.PsiTreeUtil
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.idea.caches.resolve.analyze
import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.ParameterInfo
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
@@ -28,7 +26,7 @@ import org.jetbrains.kotlin.psi.psiUtil.isAncestor
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.singletonList
import java.util.Collections
import java.util.*
public object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClassFromUsageFactory<KtCallElement>() {
override fun getElementOfInterest(diagnostic: Diagnostic): KtCallElement? {
@@ -37,7 +35,7 @@ public object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClas
val callElement = PsiTreeUtil.getParentOfType(
diagElement,
javaClass<KtAnnotationEntry>(),
javaClass<KtDelegatorToSuperCall>()
javaClass<KtSuperTypeCallEntry>()
) as? KtCallElement ?: return null
val callee = callElement.calleeExpression as? KtConstructorCalleeExpression ?: return null
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.idea.caches.resolve.analyzeAndGetResult
import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo
import org.jetbrains.kotlin.psi.KtConstructorCalleeExpression
import org.jetbrains.kotlin.psi.KtDelegatorToSuperClass
import org.jetbrains.kotlin.psi.KtSuperTypeEntry
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtUserType
import org.jetbrains.kotlin.resolve.BindingContext
@@ -39,7 +39,7 @@ public object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFa
val typeRefParent = element.parent?.parent
if (typeRefParent is KtConstructorCalleeExpression) return Collections.emptyList()
val interfaceExpected = typeRefParent is KtDelegatorToSuperClass
val interfaceExpected = typeRefParent is KtSuperTypeEntry
val isQualifier = (element.parent as? KtUserType)?.let { it.qualifier == element } ?: false
@@ -83,7 +83,7 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<KtSim
return element.parents
.filter {
it is KtNamedFunction || it is KtSecondaryConstructor || it is KtPropertyAccessor ||
it is KtClassBody || it is KtAnonymousInitializer || it is KtDelegationSpecifier
it is KtClassBody || it is KtAnonymousInitializer || it is KtSuperTypeListEntry
}
.firstOrNull()
?.let {
@@ -91,7 +91,7 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory<KtSim
(it is KtNamedFunction || it is KtSecondaryConstructor) && varExpected,
it is KtPropertyAccessor -> chooseContainingClass(it)
it is KtAnonymousInitializer -> it.parent?.parent as? KtClass
it is KtDelegationSpecifier -> {
it is KtSuperTypeListEntry -> {
val klass = it.getStrictParentOfType<KtClassOrObject>()
if (klass is KtClass && !klass.isInterface() && klass !is KtEnumEntry) klass else null
}
@@ -342,7 +342,7 @@ private fun argumentForParameter(
val valueArgument = resolvedArgument.valueArgument!!
val expression = valueArgument.getArgumentExpression()!!
expression.mark(USER_CODE_KEY)
if (valueArgument is FunctionLiteralArgument) {
if (valueArgument is LambdaArgument) {
expression.mark(WAS_FUNCTION_LITERAL_ARGUMENT_KEY)
}
return Argument(expression, bindingContext.getType(expression), isNamed = valueArgument.isNamed())
@@ -464,7 +464,7 @@ private fun introduceNamedArguments(result: KtElement) {
val argumentsToMakeNamed = callExpression.valueArguments.dropWhile { !it[MAKE_ARGUMENT_NAMED_KEY] }
for (argument in argumentsToMakeNamed) {
if (argument.isNamed()) continue
if (argument is KtFunctionLiteralArgument) continue
if (argument is KtLambdaArgument) continue
val argumentMatch = resolvedCall.getArgumentMapping(argument) as ArgumentMatch
val name = argumentMatch.valueParameter.name
//TODO: not always correct for vararg's
@@ -499,7 +499,7 @@ private fun dropArgumentsForDefaultValues(result: KtElement) {
argumentList.removeArgument(argument)
if (argumentList.arguments.isEmpty()) {
val callExpression = argumentList.parent as KtCallExpression
if (callExpression.functionLiteralArguments.isNotEmpty()) {
if (callExpression.lambdaArguments.isNotEmpty()) {
argumentList.delete()
}
}
@@ -570,12 +570,12 @@ private fun restoreFunctionLiteralArguments(expression: KtElement) {
assert(expr.unpackFunctionLiteral() != null)
val argument = expr.parent as? KtValueArgument ?: return
if (argument is KtFunctionLiteralArgument) return
if (argument is KtLambdaArgument) return
if (argument.isNamed()) return
val argumentList = argument.parent as? KtValueArgumentList ?: return
if (argument != argumentList.arguments.last()) return
val callExpression = argumentList.parent as? KtCallExpression ?: return
if (callExpression.functionLiteralArguments.isNotEmpty()) return
if (callExpression.lambdaArguments.isNotEmpty()) return
val resolvedCall = callExpression.getResolvedCall(callExpression.analyze(BodyResolveMode.PARTIAL)) ?: return
if (!resolvedCall.isReallySuccess()) return
@@ -54,7 +54,7 @@ public class KotlinRefactoringSupportProvider : RefactoringSupportProvider() {
is KtProperty -> {
if (element.isLocal()) return true
}
is KtMultiDeclarationEntry -> return true
is KtDestructuringDeclarationEntry -> return true
is KtFunction -> {
if (element.isLocal() && element.nameIdentifier != null) return true
}
@@ -101,7 +101,7 @@ public class KotlinChangeSignatureHandler : ChangeSignatureHandler {
val call: KtCallElement? = PsiTreeUtil.getParentOfType(element,
javaClass<KtCallExpression>(),
javaClass<KtDelegatorToSuperCall>(),
javaClass<KtSuperTypeCallEntry>(),
javaClass<KtConstructorDelegationCall>())
val calleeExpr = call?.let {
val callee = it.getCalleeExpression()
@@ -249,8 +249,8 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
parent is KtUserType && parent.parent is KtTypeReference -> {
parent = parent.parent.parent
if (parent is KtConstructorCalleeExpression && parent.parent is KtDelegatorToSuperCall)
result.add(KotlinFunctionCallUsage(parent.parent as KtDelegatorToSuperCall, functionUsageInfo))
if (parent is KtConstructorCalleeExpression && parent.parent is KtSuperTypeCallEntry)
result.add(KotlinFunctionCallUsage(parent.parent as KtSuperTypeCallEntry, functionUsageInfo))
}
element is KtSimpleNameExpression && (functionPsi is KtProperty || functionPsi is KtParameter) ->
@@ -293,7 +293,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
if (functionPsi is KtClass && functionPsi.isEnum()) {
for (declaration in functionPsi.declarations) {
if (declaration is KtEnumEntry && declaration.getDelegationSpecifiers().isEmpty()) {
if (declaration is KtEnumEntry && declaration.getSuperTypeListEntries().isEmpty()) {
result.add(KotlinEnumEntryWithoutSuperCallUsage(declaration))
}
}
@@ -302,7 +302,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
functionPsi.processDelegationCallConstructorUsages(functionPsi.useScope) {
when (it) {
is KtConstructorDelegationCall -> result.add(KotlinConstructorDelegationCallUsage(it, changeInfo))
is KtDelegatorToSuperCall -> result.add(KotlinFunctionCallUsage(it, functionUsageInfo))
is KtSuperTypeCallEntry -> result.add(KotlinFunctionCallUsage(it, functionUsageInfo))
}
true
}
@@ -404,7 +404,7 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
if (arguments.size != 1) continue
val argExpression = arguments[0].getArgumentExpression()
if (argExpression !is KtFunctionLiteralExpression) continue
if (argExpression !is KtLambdaExpression) continue
val context = callExpression.analyze(BodyResolveMode.FULL)
@@ -34,8 +34,8 @@ import org.jetbrains.kotlin.types.substitutions.getCallableSubstitutor
fun KtNamedDeclaration.getDeclarationBody(): KtElement? {
return when {
this is KtClassOrObject -> getDelegationSpecifierList()
this is KtPrimaryConstructor -> getContainingClassOrObject().getDelegationSpecifierList()
this is KtClassOrObject -> getSuperTypeList()
this is KtPrimaryConstructor -> getContainingClassOrObject().getSuperTypeList()
this is KtSecondaryConstructor -> getDelegationCall()
this is KtNamedFunction -> getBodyExpression()
else -> null
@@ -89,7 +89,7 @@ class KotlinCallableDefinitionUsage<T : PsiElement>(
val functionLiteral = DescriptorToSourceUtils.descriptorToDeclaration(callableDescriptor) as KtFunctionLiteral?
assert(functionLiteral != null) { "No declaration found for " + callableDescriptor }
val parent = functionLiteral!!.parent as? KtFunctionLiteralExpression ?: return false
val parent = functionLiteral!!.parent as? KtLambdaExpression ?: return false
return parent.analyze(BodyResolveMode.PARTIAL)[BindingContext.EXPECTED_EXPRESSION_TYPE, parent] != null
}
@@ -41,7 +41,7 @@ public class KotlinConstructorDelegationCallUsage(
if (changeInfo.getNewParametersCount() == 0 && !isThisCall && !elementToWorkWith.isImplicit()) {
(elementToWorkWith.getParent() as? KtSecondaryConstructor)?.getColon()?.delete()
elementToWorkWith.replace(KtPsiFactory(element).createConstructorDelegationCall(""))
elementToWorkWith.replace(KtPsiFactory(element).creareDelegatedSuperTypeEntry(""))
}
return result
@@ -28,7 +28,7 @@ public class KotlinEnumEntryWithoutSuperCallUsage(enumEntry: KtEnumEntry) : Kotl
val delegatorToSuperCall = (element.addAfter(
psiFactory.createEnumEntryInitializerList(),
element.nameIdentifier
) as KtInitializerList).initializers[0] as KtDelegatorToSuperCall
) as KtInitializerList).initializers[0] as KtSuperTypeCallEntry
return KotlinFunctionCallUsage(delegatorToSuperCall, changeInfo.methodDescriptor.originalPrimaryCallable)
.processUsage(changeInfo, delegatorToSuperCall, allUsages)
@@ -74,7 +74,7 @@ class KotlinFunctionCallUsage(
}
}
if (changeInfo.getNewParametersCount() == 0 && element is KtDelegatorToSuperCall) {
if (changeInfo.getNewParametersCount() == 0 && element is KtSuperTypeCallEntry) {
val enumEntry = element.getStrictParentOfType<KtEnumEntry>()
if (enumEntry != null && enumEntry.initializerList == element.parent) {
val initializerList = enumEntry.initializerList
@@ -87,11 +87,11 @@ class KotlinFunctionCallUsage(
private fun shouldSkipUsage(element: KtCallElement): Boolean {
// TODO: We probable need more clever processing of invalid calls, but for now default to Java-like behaviour
if (resolvedCall == null && element !is KtDelegatorToSuperCall) return true
if (resolvedCall == null && element !is KtSuperTypeCallEntry) return true
if (resolvedCall == null || resolvedCall.isReallySuccess()) return false
// TODO: investigate why arguments are not recorded for enum constructor call
if (element is KtDelegatorToSuperCall && element.parent.parent is KtEnumEntry) return false
if (element is KtSuperTypeCallEntry && element.parent.parent is KtEnumEntry) return false
if (!resolvedCall.call.valueArguments.all{ resolvedCall.getArgumentMapping(it) is ArgumentMatch }) return true
@@ -202,7 +202,7 @@ class KotlinFunctionCallUsage(
if (needSeparateVariable(argumentExpression)
&& PsiTreeUtil.getNonStrictParentOfType(element,
KtConstructorDelegationCall::class.java,
KtDelegationSpecifier::class.java,
KtSuperTypeListEntry::class.java,
KtParameter::class.java) == null) {
KotlinIntroduceVariableHandler.doRefactoring(project, null, argumentExpression, listOf(argumentExpression)) {
@@ -358,7 +358,7 @@ class KotlinFunctionCallUsage(
val valueArgument = resolvedArgument.valueArgument
val newValueArgument: KtValueArgument = when {
valueArgument == null -> argInfo.getArgumentByDefaultValue(element, allUsages, psiFactory)
valueArgument is KtFunctionLiteralArgument -> psiFactory.createArgument(valueArgument.getArgumentExpression(), name)
valueArgument is KtLambdaArgument -> psiFactory.createArgument(valueArgument.getArgumentExpression(), name)
valueArgument is KtValueArgument && valueArgument.getArgumentName()?.asName == name -> valueArgument
else -> psiFactory.createArgument(valueArgument.getArgumentExpression(), name)
}
@@ -386,10 +386,10 @@ class KotlinFunctionCallUsage(
val lastNewArgument = newArgumentList.arguments.lastOrNull()
val oldLastResolvedArgument = getResolvedValueArgument(lastNewParameter?.oldIndex ?: -1) as? ExpressionValueArgument
val lambdaArgumentNotTouched =
lastOldArgument is KtFunctionLiteralArgument && oldLastResolvedArgument?.valueArgument == lastOldArgument
lastOldArgument is KtLambdaArgument && oldLastResolvedArgument?.valueArgument == lastOldArgument
val newLambdaArgumentAddedLast = lastNewParameter != null
&& lastNewParameter.isNewParameter
&& lastNewParameter.defaultValueForCall is KtFunctionLiteralExpression
&& lastNewParameter.defaultValueForCall is KtLambdaExpression
&& lastNewArgument != null
&& !lastNewArgument.isNamed()
@@ -397,7 +397,7 @@ class KotlinFunctionCallUsage(
newArgumentList.removeArgument(newArgumentList.arguments.last())
}
else {
val lambdaArguments = element.functionLiteralArguments
val lambdaArguments = element.lambdaArguments
if (lambdaArguments.isNotEmpty()) {
element.deleteChildRange(lambdaArguments.first(), lambdaArguments.last())
}
@@ -228,11 +228,11 @@ class KotlinInlineValHandler : InlineActionHandler() {
}
private fun needToAddParameterTypes(
functionLiteralExpression: KtFunctionLiteralExpression,
lambdaExpression: KtLambdaExpression,
resolutionFacade: ResolutionFacade
): Boolean {
val functionLiteral = functionLiteralExpression.functionLiteral
val context = resolutionFacade.analyze(functionLiteralExpression, BodyResolveMode.PARTIAL)
val functionLiteral = lambdaExpression.functionLiteral
val context = resolutionFacade.analyze(lambdaExpression, BodyResolveMode.PARTIAL)
return context.diagnostics.any { diagnostic ->
val factory = diagnostic.factory
val element = diagnostic.psiElement
@@ -106,7 +106,7 @@ abstract class WrapInWithReplacement : Replacement {
val call = (e as? KtSimpleNameExpression)?.getQualifiedElement() ?: return e
val replacingExpression = KtPsiFactory(e).createExpressionByPattern("with($0) { $1 }", argumentText, call)
val replace = call.replace(replacingExpression)
return (replace as KtCallExpression).functionLiteralArguments.first().getFunctionLiteral().bodyExpression!!.statements.first()
return (replace as KtCallExpression).lambdaArguments.first().getLambdaExpression().bodyExpression!!.statements.first()
}
}
@@ -731,7 +731,7 @@ internal fun KtNamedDeclaration.getGeneratedBody() =
// We assume lazy property here with delegate expression 'by Delegates.lazy { body }'
property.delegateExpression?.let {
val call = it.getCalleeExpressionIfAny()?.parent as? KtCallExpression
call?.functionLiteralArguments?.singleOrNull()?.getFunctionLiteral()?.bodyExpression
call?.lambdaArguments?.singleOrNull()?.getLambdaExpression()?.bodyExpression
}
}
} ?: throw AssertionError("Couldn't get block body for this declaration: ${getElementTextWithContext()}")
@@ -240,8 +240,8 @@ private fun makeCall(
arguments: List<String>) {
fun insertCall(anchor: PsiElement, wrappedCall: KtExpression): KtExpression? {
val firstExpression = rangeToReplace.elements.firstOrNull { it is KtExpression } as? KtExpression
if (firstExpression?.isFunctionLiteralOutsideParentheses() ?: false) {
val functionLiteralArgument = firstExpression?.getStrictParentOfType<KtFunctionLiteralArgument>()!!
if (firstExpression?.isLambdaOutsideParentheses() ?: false) {
val functionLiteralArgument = firstExpression?.getStrictParentOfType<KtLambdaArgument>()!!
return functionLiteralArgument.moveInsideParenthesesAndReplaceWith(wrappedCall, extractableDescriptor.originalContext)
}
@@ -194,7 +194,7 @@ private fun ExtractionData.extractReceiver(
else {
val extractThis = (hasThisReceiver && refInfo.smartCast == null) || thisExpr != null
val extractOrdinaryParameter =
originalDeclaration is KtMultiDeclarationEntry ||
originalDeclaration is KtDestructuringDeclarationEntry ||
originalDeclaration is KtProperty ||
originalDeclaration is KtParameter
@@ -265,7 +265,7 @@ public open class KotlinIntroduceParameterHandler(
fun() {
val isTestMode = ApplicationManager.getApplication().isUnitTestMode()
val haveLambdaArgumentsToReplace = occurrencesToReplace.any {
it.elements.any { it is KtFunctionLiteralExpression && it.parent is KtFunctionLiteralArgument }
it.elements.any { it is KtLambdaExpression && it.parent is KtLambdaArgument }
}
val inplaceIsAvailable = editor.settings.isVariableInplaceRenameEnabled
&& !isTestMode
@@ -291,9 +291,9 @@ public open class KotlinIntroduceParameterHandler(
val replacingExpression = psiFactory.createExpression(newParameterName)
val substringInfo = expressionToReplace.extractableSubstringInfo
val result = when {
expressionToReplace.isFunctionLiteralOutsideParentheses() -> {
expressionToReplace.isLambdaOutsideParentheses() -> {
expressionToReplace
.getStrictParentOfType<KtFunctionLiteralArgument>()!!
.getStrictParentOfType<KtLambdaArgument>()!!
.moveInsideParenthesesAndReplaceWith(replacingExpression, context)
}
substringInfo != null -> substringInfo.replaceWith(replacingExpression)
@@ -114,8 +114,8 @@ object KotlinIntroduceVariableHandler : KotlinIntroduceHandlerBase() {
val replacement = psiFactory.createExpression(nameSuggestions.single().first())
val substringInfo = expressionToReplace.extractableSubstringInfo
var result = when {
expressionToReplace.isFunctionLiteralOutsideParentheses() -> {
val functionLiteralArgument = expressionToReplace.getStrictParentOfType<KtFunctionLiteralArgument>()!!
expressionToReplace.isLambdaOutsideParentheses() -> {
val functionLiteralArgument = expressionToReplace.getStrictParentOfType<KtLambdaArgument>()!!
val newCallExpression = functionLiteralArgument.moveInsideParenthesesAndReplaceWith(replacement, bindingContext)
newCallExpression.valueArguments.last().getArgumentExpression()!!
}
@@ -144,7 +144,7 @@ object KotlinIntroduceVariableHandler : KotlinIntroduceHandlerBase() {
componentFunctions.indices.joinTo(this, prefix = "val (", postfix = ")") { nameSuggestions[it].first() }
append(" = ")
append(initializer.text)
}.let { psiFactory.createMultiDeclaration(it) }
}.let { psiFactory.createDestructuringDeclaration(it) }
}
else {
buildString {
@@ -408,7 +408,7 @@ object KotlinIntroduceVariableHandler : KotlinIntroduceHandlerBase() {
private fun executeMultiDeclarationTemplate(
project: Project,
editor: Editor,
declaration: KtMultiDeclaration,
declaration: KtDestructuringDeclaration,
suggestedNames: List<Collection<String>>) {
StartMarkAction.canStart(project)?.let { return }
@@ -590,7 +590,7 @@ object KotlinIntroduceVariableHandler : KotlinIntroduceHandlerBase() {
).startInplaceIntroduceTemplate()
}
is KtMultiDeclaration -> {
is KtDestructuringDeclaration -> {
executeMultiDeclarationTemplate(project, editor, property, suggestedNames)
}
@@ -660,7 +660,7 @@ object KotlinIntroduceVariableHandler : KotlinIntroduceHandlerBase() {
var container = firstContainer
do {
var lambda: KtExpression = container.getNonStrictParentOfType<KtFunction>()!!
if (lambda is KtFunctionLiteral) lambda = lambda.parent as? KtFunctionLiteralExpression ?: return@apply
if (lambda is KtFunctionLiteral) lambda = lambda.parent as? KtLambdaExpression ?: return@apply
if (!isResolvableNextTo(lambda)) return@apply
container = lambda.getContainer() ?: return@apply
add(lambda to container)
@@ -330,11 +330,11 @@ public fun KtElement.getContextForContainingDeclarationBody(): BindingContext? {
val bodyElement = when (enclosingDeclaration) {
is KtDeclarationWithBody -> enclosingDeclaration.getBodyExpression()
is KtWithExpressionInitializer -> enclosingDeclaration.getInitializer()
is KtMultiDeclaration -> enclosingDeclaration.getInitializer()
is KtDestructuringDeclaration -> enclosingDeclaration.getInitializer()
is KtParameter -> enclosingDeclaration.getDefaultValue()
is KtAnonymousInitializer -> enclosingDeclaration.body
is KtClass -> {
val delegationSpecifierList = enclosingDeclaration.getDelegationSpecifierList()
val delegationSpecifierList = enclosingDeclaration.getSuperTypeList()
if (delegationSpecifierList.isAncestor(this)) this else null
}
else -> null
@@ -80,8 +80,8 @@ public class KotlinMemberInfoStorage(
&& myFilter.includeMember(it) }
.mapTo(temp) { KotlinMemberInfo(it as KtNamedDeclaration) }
if (aClass == myClass) {
aClass.getDelegationSpecifiers()
.filterIsInstance<KtDelegatorToSuperClass>()
aClass.getSuperTypeListEntries()
.filterIsInstance<KtSuperTypeEntry>()
.map {
val type = context[BindingContext.TYPE, it.typeReference]
val classDescriptor = type?.constructor?.declarationDescriptor as? ClassDescriptor
@@ -53,7 +53,7 @@ public class MoveJavaInnerClassKotlinUsagesHandler: MoveInnerClassUsagesHandler
argumentList.replace(psiFactory.createCallArguments(newArguments.joinToString(prefix = "(", postfix = ")")))
}
else {
innerCall.getFunctionLiteralArguments().firstOrNull()?.let { lambdaArg ->
innerCall.getLambdaArguments().firstOrNull()?.let { lambdaArg ->
val anchor = PsiTreeUtil.skipSiblingsBackward(lambdaArg, javaClass<PsiWhiteSpace>())
innerCall.addAfter(psiFactory.createCallArguments("(${outerCall.getText()})"), anchor)
}
@@ -114,7 +114,7 @@ public class JavaToKotlinPreconversionPullUpHelper(
if (getCurrentSuperInterfaceCount() == superInterfaceCount) return
val typeText = RefactoringUtil.findReferenceToClass(dummyTargetClass.implementsList, member as PsiClass)?.j2kText() ?: return
targetClass.addDelegationSpecifier(psiFactory.createDelegatorToSuperClass(typeText))
targetClass.addSuperTypeListEntry(psiFactory.createSuperTypeEntry(typeText))
return
}
@@ -198,7 +198,7 @@ class KotlinPullUpHelper(
}
}
override fun visitDelegationToSuperCallSpecifier(specifier: KtDelegatorToSuperCall) {
override fun visitSuperTypeCallEntry(specifier: KtSuperTypeCallEntry) {
val constructorRef = specifier.calleeExpression.constructorReferenceExpression ?: return
val containingClass = specifier.getStrictParentOfType<KtClassOrObject>() ?: return
val callingConstructorElement = containingClass.getPrimaryConstructor() ?: containingClass
@@ -326,11 +326,11 @@ class KotlinPullUpHelper(
private fun moveSuperInterface(member: KtClass, substitutor: PsiSubstitutor) {
val classDescriptor = data.memberDescriptors[member] as? ClassDescriptor ?: return
val currentSpecifier = data.sourceClass.getDelegatorToSuperClassByDescriptor(classDescriptor, data.sourceClassContext) ?: return
val currentSpecifier = data.sourceClass.getSuperTypeEntryByDescriptor(classDescriptor, data.sourceClassContext) ?: return
when (data.targetClass) {
is KtClass -> {
data.sourceClass.removeDelegationSpecifier(currentSpecifier)
addDelegatorToSuperClass(currentSpecifier, data.targetClass, data.targetClassDescriptor, data.sourceClassContext, data.sourceToTargetClassSubstitutor)
data.sourceClass.removeSuperTypeListEntry(currentSpecifier)
addSuperTypeEntry(currentSpecifier, data.targetClass, data.targetClassDescriptor, data.sourceClassContext, data.sourceToTargetClassSubstitutor)
}
is PsiClass -> {
@@ -343,7 +343,7 @@ class KotlinPullUpHelper(
?: return
val superTypeForTarget = substitutor.substitute(elementFactory.createType(superRef))
data.sourceClass.removeDelegationSpecifier(currentSpecifier)
data.sourceClass.removeSuperTypeListEntry(currentSpecifier)
if (DescriptorUtils.isSubclass(data.targetClassDescriptor, classDescriptor)) return
@@ -523,8 +523,8 @@ class KotlinPullUpHelper(
} as? KtBlockExpression
}
fun KtClassOrObject.getDelegatorToSuperCall(): KtDelegatorToSuperCall? {
return getDelegationSpecifiers().singleOrNull { it is KtDelegatorToSuperCall } as? KtDelegatorToSuperCall
fun KtClassOrObject.getDelegatorToSuperCall(): KtSuperTypeCallEntry? {
return getSuperTypeListEntries().singleOrNull { it is KtSuperTypeCallEntry } as? KtSuperTypeCallEntry
}
fun addUsedParameters(constructorElement: KtElement, info: InitializerInfo) {
@@ -88,12 +88,12 @@ fun KtClass.makeAbstract() {
}
}
fun KtClassOrObject.getDelegatorToSuperClassByDescriptor(
fun KtClassOrObject.getSuperTypeEntryByDescriptor(
descriptor: ClassDescriptor,
context: BindingContext
): KtDelegatorToSuperClass? {
return getDelegationSpecifiers()
.filterIsInstance<KtDelegatorToSuperClass>()
): KtSuperTypeEntry? {
return getSuperTypeListEntries()
.filterIsInstance<KtSuperTypeEntry>()
.firstOrNull {
val referencedType = context[BindingContext.TYPE, it.typeReference]
referencedType?.constructor?.declarationDescriptor == descriptor
@@ -141,8 +141,8 @@ fun makeAbstract(member: KtCallableDeclaration,
}
}
fun addDelegatorToSuperClass(
delegator: KtDelegatorToSuperClass,
fun addSuperTypeEntry(
delegator: KtSuperTypeEntry,
targetClass: KtClassOrObject,
targetClassDescriptor: ClassDescriptor,
context: BindingContext,
@@ -157,6 +157,6 @@ fun addDelegatorToSuperClass(
if (!(typeInTargetClass != null && !typeInTargetClass.isError)) return
val renderedType = IdeDescriptorRenderers.SOURCE_CODE.renderType(typeInTargetClass)
val newSpecifier = KtPsiFactory(targetClass).createDelegatorToSuperClass(renderedType)
targetClass.addDelegationSpecifier(newSpecifier).addToShorteningWaitSet()
val newSpecifier = KtPsiFactory(targetClass).createSuperTypeEntry(renderedType)
targetClass.addSuperTypeListEntry(newSpecifier).addToShorteningWaitSet()
}
@@ -164,11 +164,11 @@ public class KotlinPushDownProcessor(
is KtClassOrObject -> {
if (memberInfo.overrides != null) {
context.sourceClass.getDelegatorToSuperClassByDescriptor(
context.sourceClass.getSuperTypeEntryByDescriptor(
memberDescriptor as ClassDescriptor,
context.sourceClassContext
)?.let {
addDelegatorToSuperClass(it, targetClass, targetClassDescriptor, context.sourceClassContext, substitutor)
addSuperTypeEntry(it, targetClass, targetClassDescriptor, context.sourceClassContext, substitutor)
}
continue@members
}
@@ -205,11 +205,11 @@ public class KotlinPushDownProcessor(
}
is KtClassOrObject -> {
if (memberInfo.overrides != null) {
context.sourceClass.getDelegatorToSuperClassByDescriptor(
context.sourceClass.getSuperTypeEntryByDescriptor(
memberDescriptor as ClassDescriptor,
context.sourceClassContext
)?.let {
context.sourceClass.removeDelegationSpecifier(it)
context.sourceClass.removeSuperTypeListEntry(it)
}
}
else {
@@ -74,7 +74,7 @@ public class KotlinJavaSafeDeleteDelegate : JavaSafeDeleteDelegate {
if (parameterIndex < argCount) {
usages.add(SafeDeleteValueArgumentListUsageInfo((args.get(parameterIndex) as KtValueArgument), parameter))
} else {
val lambdaArgs = callExpression.getFunctionLiteralArguments()
val lambdaArgs = callExpression.getLambdaArguments()
val lambdaIndex = parameterIndex - argCount
if (lambdaIndex < lambdaArgs.size()) {
usages.add(SafeDeleteReferenceSimpleDeleteUsageInfo(lambdaArgs.get(lambdaIndex), parameter, true))
@@ -65,7 +65,7 @@ class KotlinCreateTestIntention : SelfTargetingRangeIntention<KtNamedDeclaration
return TextRange(
element.startOffset,
element.getDelegationSpecifierList()?.startOffset ?: element.getBody()?.startOffset ?: element.endOffset
element.getSuperTypeList()?.startOffset ?: element.getBody()?.startOffset ?: element.endOffset
)
}
@@ -140,10 +140,10 @@ object DebuggerUtils {
checkResolveCall(resolvedCall)
}
override fun visitMultiDeclaration(multiDeclaration: KtMultiDeclaration) {
super.visitMultiDeclaration(multiDeclaration)
override fun visitDestructuringDeclaration(destructuringDeclaration: KtDestructuringDeclaration) {
super.visitDestructuringDeclaration(destructuringDeclaration)
for (entry in multiDeclaration.entries) {
for (entry in destructuringDeclaration.entries) {
val resolvedCall = bindingContext.get(BindingContext.COMPONENT_RESOLVED_CALL, entry)
checkResolveCall(resolvedCall)
}
@@ -42,9 +42,8 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.kotlin.resolve.calls.tasks.ExplicitReceiverKind
import org.jetbrains.kotlin.resolve.scopes.receivers.ExpressionReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitReceiver
import org.jetbrains.kotlin.resolve.scopes.receivers.Receiver
import org.jetbrains.kotlin.resolve.source.getPsi
import org.jetbrains.kotlin.types.ErrorUtils
import org.jetbrains.kotlin.types.KotlinType
@@ -425,7 +424,7 @@ public class KotlinPsiUnifier(
return matchDescriptors(d1, d2)
}
private fun matchMultiDeclarations(e1: KtMultiDeclaration, e2: KtMultiDeclaration): Boolean {
private fun matchDestructuringDeclarations(e1: KtDestructuringDeclaration, e2: KtDestructuringDeclaration): Boolean {
val entries1 = e1.getEntries()
val entries2 = e2.getEntries()
if (entries1.size() != entries2.size()) return false
@@ -552,8 +551,8 @@ public class KotlinPsiUnifier(
return OrderInfo(orderSensitive, orderInsensitive)
}
fun getDelegationOrderInfo(cls: KtClassOrObject): OrderInfo<KtDelegationSpecifier> {
val (orderInsensitive, orderSensitive) = cls.getDelegationSpecifiers().partition { it is KtDelegatorToSuperClass }
fun getDelegationOrderInfo(cls: KtClassOrObject): OrderInfo<KtSuperTypeListEntry> {
val (orderInsensitive, orderSensitive) = cls.getSuperTypeListEntries().partition { it is KtSuperTypeEntry }
return OrderInfo(orderSensitive, orderInsensitive)
}
@@ -666,8 +665,8 @@ public class KotlinPsiUnifier(
e1 !is KtElement, e2 !is KtElement ->
null
e1 is KtMultiDeclaration && e2 is KtMultiDeclaration ->
if (matchMultiDeclarations(e1, e2)) null else UNMATCHED
e1 is KtDestructuringDeclaration && e2 is KtDestructuringDeclaration ->
if (matchDestructuringDeclarations(e1, e2)) null else UNMATCHED
e1 is KtAnonymousInitializer && e2 is KtAnonymousInitializer ->
null
+5 -5
View File
@@ -7,14 +7,14 @@ PsiJetFileStubImpl[package=kotlin]
PRIMARY_CONSTRUCTOR:
MODIFIER_LIST:[private]
VALUE_PARAMETER_LIST:
DELEGATION_SPECIFIER_LIST:
DELEGATOR_SUPER_CLASS:
SUPER_TYPE_LIST:
SUPER_TYPE_ENTRY:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=Number]
DELEGATOR_SUPER_CLASS:
SUPER_TYPE_ENTRY:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
@@ -30,8 +30,8 @@ PsiJetFileStubImpl[package=kotlin]
CLASS_BODY:
OBJECT_DECLARATION:[fqName=kotlin.Int.Companion, isCompanion=true, isLocal=false, isObjectLiteral=false, isTopLevel=false, name=Companion, superNames=[IntegerConstants]]
MODIFIER_LIST:[public companion]
DELEGATION_SPECIFIER_LIST:
DELEGATOR_SUPER_CLASS:
SUPER_TYPE_LIST:
SUPER_TYPE_ENTRY:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
@@ -21,8 +21,8 @@ PsiJetFileStubImpl[package=test.a]
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=kotlin]
REFERENCE_EXPRESSION:[referencedName=String]
DELEGATION_SPECIFIER_LIST:
DELEGATOR_SUPER_CLASS:
SUPER_TYPE_LIST:
SUPER_TYPE_ENTRY:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
@@ -117,8 +117,8 @@ PsiJetFileStubImpl[package=test.class_object]
PRIMARY_CONSTRUCTOR:
MODIFIER_LIST:[public]
VALUE_PARAMETER_LIST:
DELEGATION_SPECIFIER_LIST:
DELEGATOR_SUPER_CLASS:
SUPER_TYPE_LIST:
SUPER_TYPE_ENTRY:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
@@ -130,8 +130,8 @@ PsiJetFileStubImpl[package=test.class_object]
PRIMARY_CONSTRUCTOR:
MODIFIER_LIST:[private]
VALUE_PARAMETER_LIST:
DELEGATION_SPECIFIER_LIST:
DELEGATOR_SUPER_CLASS:
SUPER_TYPE_LIST:
SUPER_TYPE_ENTRY:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]
@@ -16,8 +16,8 @@ PsiJetFileStubImpl[package=]
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=A]
DELEGATION_SPECIFIER_LIST:
DELEGATOR_SUPER_CLASS:
SUPER_TYPE_LIST:
SUPER_TYPE_ENTRY:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
REFERENCE_EXPRESSION:[referencedName=T]
@@ -7,8 +7,8 @@ PsiJetFileStubImpl[package=test]
PRIMARY_CONSTRUCTOR:
MODIFIER_LIST:[public]
VALUE_PARAMETER_LIST:
DELEGATION_SPECIFIER_LIST:
DELEGATOR_SUPER_CLASS:
SUPER_TYPE_LIST:
SUPER_TYPE_ENTRY:
TYPE_REFERENCE:
USER_TYPE:[isAbsoluteInRootPackage=false]
USER_TYPE:[isAbsoluteInRootPackage=false]

Some files were not shown because too many files have changed in this diff Show More