diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties index a8f1ea889d3..f45928dbebd 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/KotlinBundle.properties @@ -12,13 +12,13 @@ add.init.keyword.in.whole.project.modal.title=Adding 'init' keyword in whole pro add.init.keyword.in.whole.project.family=Add 'init' keyword in whole project insert.delegation.call=Insert ''{0}()'' call make.class.annotation.class=Make ''{0}'' an annotation class -make.class.annotation.class.family=Make Class an Annotation Class +make.class.annotation.class.family=Make class an annotation class add.star.projections=Add ''{0}'' change.to.star.projection=Change type arguments to {0} -change.to.star.projection.family=Change to Star Projection +change.to.star.projection.family=Change to star projection remove.parts.from.property=Remove {0} from property -remove.parts.from.property.family=Remove Parts from Property -remove.psi.element.family=Remove Element +remove.parts.from.property.family=Remove parts from property +remove.psi.element.family=Remove element remove.right.part.of.binary.expression=Remove right part of a binary expression remove.elvis.operator=Remove elvis operator remove.redundant.nullable=Remove redundant '?' @@ -54,10 +54,10 @@ change.element.type=Change ''{0}'' type to ''{1}'' change.function.parameter.type=Change parameter ''{0}'' type of function ''{1}'' to ''{2}'' change.primary.constructor.parameter.type=Change parameter ''{0}'' type of primary constructor of class ''{1}'' to ''{2}'' change.type=Change type from ''{0}'' to ''{1}'' -change.type.family=Change Type +change.type.family=Change type change.function.signature=Change the signature of function ''{0}'' cast.expression.to.type=Cast expression ''{0}'' to ''{1}'' -cast.expression.family=Cast Expression +cast.expression.family=Cast expression replace.call.error.skipped.defaults=Cannot skip default arguments. replace.call.error.undefined.returntype=Unable to determine the return type. @@ -147,10 +147,10 @@ migrate.lambda.syntax=Migrate lambda syntax migrate.lambda.syntax.family=Migrate lambda syntax remove.val.var.from.parameter=Remove ''{0}'' from parameter add.override.to.equals.hashCode.toString=Add 'override' to equals, hashCode, toString in project -add.when.else.branch.action.family.name=Add Else Branch +add.when.else.branch.action.family.name=Add else branch add.when.else.branch.action=Add else branch move.when.else.branch.to.the.end.action=Move else branch to the end -move.when.else.branch.to.the.end.family.name=Move Else Branch to the End +move.when.else.branch.to.the.end.family.name=Move else branch to the end change.to.property.name.family.name=Change to property name change.to.property.name.action=Change ''{0}'' to ''{1}'' create.from.usage.family=Create from usage diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddConstModifierFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddConstModifierFix.kt index 178c7a131f1..a542fb572c6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddConstModifierFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddConstModifierFix.kt @@ -54,7 +54,7 @@ public class AddConstModifierFix(val property: KtProperty) : AddModifierFix(prop } } -public class AddConstModifierIntention : SelfTargetingIntention(javaClass(), "Add 'const' modifier") { +public class AddConstModifierIntention : SelfTargetingIntention(KtProperty::class.java, "Add 'const' modifier") { override fun applyTo(element: KtProperty, editor: Editor) { AddConstModifierFix.addConstModifier(element) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionBodyFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionBodyFix.java index ee42b92341b..f970f409196 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionBodyFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionBodyFix.java @@ -50,12 +50,12 @@ public class AddFunctionBodyFix extends KotlinQuickFixAction { } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiFile file) { return super.isAvailable(project, editor, file) && !getElement().hasBody(); } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { KtFunction newElement = (KtFunction) getElement().copy(); KtPsiFactory psiFactory = KtPsiFactoryKt.KtPsiFactory(file); if (!(newElement.getLastChild() instanceof PsiWhiteSpace)) { @@ -71,7 +71,7 @@ public class AddFunctionBodyFix extends KotlinQuickFixAction { return new KotlinSingleIntentionActionFactory() { @Nullable @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { PsiElement element = diagnostic.getPsiElement(); KtFunction function = PsiTreeUtil.getParentOfType(element, KtFunction.class, false); if (function == null) return null; diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionParametersFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionParametersFix.kt index d7cbf8a4ea3..cb903ddc9b2 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionParametersFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionParametersFix.kt @@ -86,19 +86,19 @@ public class AddFunctionParametersFix( val validator = CollectingNameValidator() for (i in arguments.indices) { - val argument = arguments.get(i) + val argument = arguments[i] val expression = argument.getArgumentExpression() if (i < parameters.size) { - validator.addName(parameters.get(i).name.asString()) + validator.addName(parameters[i].name.asString()) val argumentType = expression?.let { val bindingContext = it.analyze() bindingContext[BindingContext.SMARTCAST, it] ?: bindingContext.getType(it) } - val parameterType = parameters.get(i).type + val parameterType = parameters[i].type if (argumentType != null && !KotlinTypeChecker.DEFAULT.isSubtypeOf(argumentType, parameterType)) { - it.parameters.get(i).currentTypeInfo = KotlinTypeInfo(false, argumentType) + it.parameters[i].currentTypeInfo = KotlinTypeInfo(false, argumentType) typesToShorten.add(argumentType) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt index ebd88dbf8c6..0b8492f0238 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddFunctionToSupertypeFix.kt @@ -69,16 +69,14 @@ class AddFunctionToSupertypeFix private constructor( override fun getFamilyName() = "Add function to supertype" override fun invoke(project: Project, editor: Editor?, file: KtFile) { - CommandProcessor.getInstance().runUndoTransparentAction(object : Runnable { - override fun run() { - if (functions.size == 1 || editor == null || !editor.component.isShowing) { - addFunction(functions.first(), project) - } - else { - JBPopupFactory.getInstance().createListPopup(createFunctionPopup(project)).showInBestPositionFor(editor) - } + CommandProcessor.getInstance().runUndoTransparentAction { + if (functions.size == 1 || editor == null || !editor.component.isShowing) { + addFunction(functions.first(), project) } - }) + else { + JBPopupFactory.getInstance().createListPopup(createFunctionPopup(project)).showInBestPositionFor(editor) + } + } } private fun addFunction(functionData: FunctionData, project: Project) { @@ -158,16 +156,16 @@ class AddFunctionToSupertypeFix private constructor( } private fun getSuperClasses(classDescriptor: ClassDescriptor): List { - val supertypes = classDescriptor.defaultType.supertypes().sortedWith(object : Comparator { - override fun compare(o1: KotlinType, o2: KotlinType): Int { - return when { - o1 == o2 -> 0 - KotlinTypeChecker.DEFAULT.isSubtypeOf(o1, o2) -> -1 - KotlinTypeChecker.DEFAULT.isSubtypeOf(o2, o1) -> 1 - else -> o1.toString().compareTo(o2.toString()) + val supertypes = classDescriptor.defaultType.supertypes().sortedWith( + Comparator { o1, o2 -> + when { + o1 == o2 -> 0 + KotlinTypeChecker.DEFAULT.isSubtypeOf(o1, o2) -> -1 + KotlinTypeChecker.DEFAULT.isSubtypeOf(o2, o1) -> 1 + else -> o1.toString().compareTo(o2.toString()) + } } - } - }) + ) return supertypes.mapNotNull { it.constructor.declarationDescriptor as? ClassDescriptor } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddLoopLabelFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddLoopLabelFix.kt index 5cb8ca53d53..592e903a358 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddLoopLabelFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddLoopLabelFix.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.parents public class AddLoopLabelFix(loop: KtLoopExpression, val jumpExpression: KtElement): KotlinQuickFixAction(loop) { override fun getText() = "Add label to loop" - override fun getFamilyName() = getText() + override fun getFamilyName() = text override fun isAvailable(project: Project, editor: Editor?, file: PsiFile): Boolean { return super.isAvailable(project, editor, file) @@ -37,12 +37,12 @@ public class AddLoopLabelFix(loop: KtLoopExpression, val jumpExpression: KtEleme val usedLabels = collectUsedLabels(element) val labelName = getUniqueLabelName(usedLabels) - val jumpWithLabel = KtPsiFactory(project).createExpression(jumpExpression.getText() + "@" + labelName) + val jumpWithLabel = KtPsiFactory(project).createExpression(jumpExpression.text + "@" + labelName) jumpExpression.replace(jumpWithLabel) // TODO(yole) use createExpressionByPattern() once it's available val labeledLoopExpression = KtPsiFactory(project).createLabeledExpression(labelName) - labeledLoopExpression.getBaseExpression()!!.replace(element) + labeledLoopExpression.baseExpression!!.replace(element) element.replace(labeledLoopExpression) // TODO(yole) We should initiate in-place rename for the label here, but in-place rename for labels is not yet implemented @@ -75,7 +75,7 @@ public class AddLoopLabelFix(loop: KtLoopExpression, val jumpExpression: KtEleme companion object: KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val element = diagnostic.getPsiElement() as? KtElement + val element = diagnostic.psiElement as? KtElement assert(element is KtBreakExpression || element is KtContinueExpression) assert((element as? KtLabeledExpression)?.getLabelName() == null) val loop = element?.getStrictParentOfType() ?: return null diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.kt index 95bf9c482f8..32284e0e046 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddNameToArgumentFix.kt @@ -49,7 +49,7 @@ public class AddNameToArgumentFix(argument: KtValueArgument) : KotlinQuickFixAct override fun invoke(project: Project, editor: Editor?, file: KtFile) { val possibleNames = calculatePossibleArgumentNames() assert(possibleNames.isNotEmpty()) { "isAvailable() should be checked before invoke()" } - if (possibleNames.size() == 1 || editor == null || !editor.component.isShowing) { + if (possibleNames.size == 1 || editor == null || !editor.component.isShowing) { addName(project, element, possibleNames.first()) } else { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.java index a0832a1ad65..06a1a667321 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddOverrideToEqualsHashCodeToStringFix.java @@ -54,7 +54,7 @@ public class AddOverrideToEqualsHashCodeToStringFix extends KotlinQuickFixAction } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiFile file) { return super.isAvailable(project, editor, file) && isEqualsHashCodeOrToString(getElement()); } @@ -78,7 +78,7 @@ public class AddOverrideToEqualsHashCodeToStringFix extends KotlinQuickFixAction } @Override - protected void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + protected void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { Collection files = PluginJetFilesProvider.allFilesInProject(file.getProject()); for (KtFile jetFile : files) { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddStarProjectionsFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddStarProjectionsFix.java index c10b575f9bc..bfe1db5d8df 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddStarProjectionsFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddStarProjectionsFix.java @@ -54,7 +54,7 @@ public abstract class AddStarProjectionsFix extends KotlinQuickFixAction diagnosticWithParameters = Errors.NO_TYPE_ARGUMENTS_ON_RHS.cast(diagnostic); KtTypeElement typeElement = diagnosticWithParameters.getPsiElement().getTypeElement(); @@ -89,7 +89,7 @@ public abstract class AddStarProjectionsFix extends KotlinQuickFixAction diagnosticWithParameters = Errors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.cast(diagnostic); Integer size = diagnosticWithParameters.getA(); @@ -99,9 +99,7 @@ public abstract class AddStarProjectionsFix extends KotlinQuickFixAction() return super.isAvailable(project, editor, file) && isZeroTypeArguments() && isInsideJavaClassCall(); } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddWhenElseBranchFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddWhenElseBranchFix.java index 40d296bb91d..6f4517c279d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AddWhenElseBranchFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AddWhenElseBranchFix.java @@ -16,7 +16,7 @@ package org.jetbrains.kotlin.idea.quickfix; -import com.intellij.codeInsight.CodeInsightUtilBase; +import com.intellij.codeInsight.CodeInsightUtilCore; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.TextRange; @@ -51,12 +51,12 @@ public class AddWhenElseBranchFix extends KotlinQuickFixAction } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiFile file) { return super.isAvailable(project, editor, file) && getElement().getCloseBrace() != null; } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { PsiElement whenCloseBrace = getElement().getCloseBrace(); assert (whenCloseBrace != null) : "isAvailable should check if close brace exist"; @@ -66,7 +66,7 @@ public class AddWhenElseBranchFix extends KotlinQuickFixAction PsiElement insertedBranch = getElement().addBefore(entry, whenCloseBrace); getElement().addAfter(psiFactory.createNewLine(), insertedBranch); - KtWhenEntry insertedWhenEntry = (KtWhenEntry) CodeInsightUtilBase.forcePsiPostprocessAndRestoreElement(insertedBranch); + KtWhenEntry insertedWhenEntry = (KtWhenEntry) CodeInsightUtilCore.forcePsiPostprocessAndRestoreElement(insertedBranch); TextRange textRange = insertedWhenEntry.getTextRange(); int indexOfOpenBrace = insertedWhenEntry.getText().indexOf('{'); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt index 07367861e98..f048f1166af 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/AutoImportFix.kt @@ -61,7 +61,7 @@ import java.util.* internal abstract class AutoImportFixBase(expression: T) : KotlinQuickFixAction(expression), HighPriorityAction, HintAction { - private val modificationCountOnCreate = PsiModificationTracker.SERVICE.getInstance(element.getProject()).getModificationCount() + private val modificationCountOnCreate = PsiModificationTracker.SERVICE.getInstance(element.project).modificationCount private val suggestionCount: Int by CachedValueProperty( calculator = { computeSuggestions().size }, @@ -73,9 +73,9 @@ internal abstract class AutoImportFixBase(expression: T) : protected abstract fun getCallTypeAndReceiver(): CallTypeAndReceiver<*, *> override fun showHint(editor: Editor): Boolean { - if (!element.isValid() || isOutdated()) return false + if (!element.isValid || isOutdated()) return false - if (ApplicationManager.getApplication().isUnitTestMode() && HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) return false + if (ApplicationManager.getApplication().isUnitTestMode && HintManager.getInstance().hasShownHintsThatWillHideByOtherHint(true)) return false if (suggestionCount == 0) return false @@ -97,15 +97,15 @@ internal abstract class AutoImportFixBase(expression: T) : override fun startInWriteAction() = true - private fun isOutdated() = modificationCountOnCreate != PsiModificationTracker.SERVICE.getInstance(element.getProject()).getModificationCount() + private fun isOutdated() = modificationCountOnCreate != PsiModificationTracker.SERVICE.getInstance(element.project).modificationCount protected open fun createAction(project: Project, editor: Editor): KotlinAddImportAction { return createSingleImportAction(project, editor, element, computeSuggestions()) } fun computeSuggestions(): Collection { - if (!element.isValid()) return listOf() - if (element.getContainingFile() !is KtFile) return emptyList() + if (!element.isValid) return listOf() + if (element.containingFile !is KtFile) return emptyList() val callTypeAndReceiver = getCallTypeAndReceiver() @@ -123,7 +123,7 @@ internal abstract class AutoImportFixBase(expression: T) : val nameStr = name.asString() if (nameStr.isEmpty()) return emptyList() - val file = element.getContainingFile() as KtFile + val file = element.containingFile as KtFile fun filterByCallType(descriptor: DeclarationDescriptor) = callTypeAndReceiver.callType.descriptorKindFilter.accepts(descriptor) @@ -131,9 +131,9 @@ internal abstract class AutoImportFixBase(expression: T) : val bindingContext = element.analyze(BodyResolveMode.PARTIAL) - val diagnostics = bindingContext.getDiagnostics().forElement(element) + val diagnostics = bindingContext.diagnostics.forElement(element) - if (!diagnostics.any { it.getFactory() in getSupportedErrors() }) return emptyList() + if (!diagnostics.any { it.factory in getSupportedErrors() }) return emptyList() val resolutionFacade = element.getResolutionFacade() @@ -193,7 +193,7 @@ internal class AutoImportFix(expression: KtSimpleNameExpression) : AutoImportFix val elementType = element.firstChild.node.elementType if (elementType in OperatorConventions.ASSIGNMENT_OPERATIONS) { val counterpart = OperatorConventions.ASSIGNMENT_OPERATION_COUNTERPARTS[elementType] - val counterpartName = OperatorConventions.BINARY_OPERATION_NAMES.get(counterpart) + val counterpartName = OperatorConventions.BINARY_OPERATION_NAMES[counterpart] if (counterpartName != null) { return@run listOf(conventionName, counterpartName) } @@ -214,7 +214,7 @@ internal class AutoImportFix(expression: KtSimpleNameExpression) : AutoImportFix companion object : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic) = - (diagnostic.getPsiElement() as? KtSimpleNameExpression)?.let { AutoImportFix(it) } + (diagnostic.psiElement as? KtSimpleNameExpression)?.let { AutoImportFix(it) } override fun isApplicableForCodeFragment() = true diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/CastExpressionFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/CastExpressionFix.java index c47341d2942..2c7bf1ed354 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/CastExpressionFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/CastExpressionFix.java @@ -62,7 +62,7 @@ public class CastExpressionFix extends KotlinQuickFixAction { } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiFile file) { if (!super.isAvailable(project, editor, file)) return false; KotlinType expressionType = ResolutionUtils.analyze(getElement()).getType(getElement()); return expressionType != null @@ -73,7 +73,7 @@ public class CastExpressionFix extends KotlinQuickFixAction { } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { String renderedType = IdeDescriptorRenderers.SOURCE_CODE.renderType(type); KtPsiFactory psiFactory = KtPsiFactoryKt.KtPsiFactory(file); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeAccessorTypeFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeAccessorTypeFix.java index 0c7643f9eb2..1c3ca760522 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeAccessorTypeFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeAccessorTypeFix.java @@ -38,7 +38,7 @@ public class ChangeAccessorTypeFix extends KotlinQuickFixAction { KtNamedDeclaration declaration = PsiTreeUtil.getParentOfType(element, KtNamedDeclaration.class); isPrimaryConstructorParameter = declaration instanceof KtPrimaryConstructor; FqName declarationFQName = declaration == null ? null : declaration.getFqName(); - containingDeclarationName = declarationFQName == null ? declaration.getName() : declarationFQName.asString(); + containingDeclarationName = declarationFQName != null ? declarationFQName.asString() + : declaration != null ? declaration.getName() + : null; } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiFile file) { return super.isAvailable(project, editor, file) && containingDeclarationName != null; } @@ -65,7 +67,7 @@ public class ChangeParameterTypeFix extends KotlinQuickFixAction { } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { KtTypeReference newTypeRef = KtPsiFactoryKt.KtPsiFactory(file).createType(IdeDescriptorRenderers.SOURCE_CODE.renderType(type)); newTypeRef = getElement().setTypeReference(newTypeRef); assert newTypeRef != null; diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToFunctionInvocationFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToFunctionInvocationFix.java index 9cc0930372d..3b4ef1c70f1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToFunctionInvocationFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToFunctionInvocationFix.java @@ -45,7 +45,7 @@ public class ChangeToFunctionInvocationFix extends KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { if (diagnostic.getPsiElement() instanceof KtExpression) { return new ChangeToFunctionInvocationFix((KtExpression) diagnostic.getPsiElement()); } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToStarProjectionFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToStarProjectionFix.java index aade2247cee..e3434c982da 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToStarProjectionFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeToStarProjectionFix.java @@ -46,7 +46,7 @@ public class ChangeToStarProjectionFix extends KotlinQuickFixAction { } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { KtTypeReference newTypeRef = (KtTypeReference) getElement().replace(KtPsiFactoryKt.KtPsiFactory(file).createType(renderedType)); ShortenReferences.DEFAULT.process(newTypeRef); } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableMutabilityFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableMutabilityFix.kt index bab6881c8d9..284294fa9ec 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableMutabilityFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableMutabilityFix.kt @@ -30,7 +30,7 @@ public class ChangeVariableMutabilityFix(element: KtNamedDeclaration, private va override fun getText() = if (makeVar) "Make variable mutable" else "Make variable immutable" - override fun getFamilyName(): String = getText() + override fun getFamilyName(): String = text override fun isAvailable(project: Project, editor: Editor?, file: PsiFile): Boolean { return when (element) { @@ -52,15 +52,15 @@ public class ChangeVariableMutabilityFix(element: KtNamedDeclaration, private va companion object { public val VAL_WITH_SETTER_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val accessor = diagnostic.getPsiElement() as KtPropertyAccessor - val property = accessor.getParent() as KtProperty + val accessor = diagnostic.psiElement as KtPropertyAccessor + val property = accessor.parent as KtProperty return ChangeVariableMutabilityFix(property, true) } } public val VAL_REASSIGNMENT_FACTORY: KotlinSingleIntentionActionFactory = object: KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val propertyDescriptor = Errors.VAL_REASSIGNMENT.cast(diagnostic).getA() + val propertyDescriptor = Errors.VAL_REASSIGNMENT.cast(diagnostic).a val declaration = DescriptorToSourceUtils.descriptorToDeclaration(propertyDescriptor) as? KtNamedDeclaration ?: return null return ChangeVariableMutabilityFix(declaration, true) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.java index 7f940e8f20f..2e4d3052678 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVariableTypeFix.java @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.idea.quickfix; import com.intellij.codeInsight.intention.IntentionAction; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; @@ -48,8 +47,6 @@ import java.util.LinkedList; import java.util.List; public class ChangeVariableTypeFix extends KotlinQuickFixAction { - private final static Logger LOG = Logger.getInstance(ChangeVariableTypeFix.class); - private final KotlinType type; public ChangeVariableTypeFix(@NotNull KtVariableDeclaration element, @NotNull KotlinType type) { @@ -75,19 +72,19 @@ public class ChangeVariableTypeFix extends KotlinQuickFixAction toShorten = new ArrayList(); + List toShorten = new ArrayList(); toShorten.add(getElement().setTypeReference(replacingTypeReference)); if (getElement() instanceof KtProperty) { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVisibilityModifierFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVisibilityModifierFix.java index 5e3a3885fc3..5e50c918d50 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVisibilityModifierFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ChangeVisibilityModifierFix.java @@ -56,20 +56,20 @@ public class ChangeVisibilityModifierFix extends KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { PsiElement element = diagnostic.getPsiElement(); if (!(element instanceof KtDeclaration)) return null; return new ChangeVisibilityModifierFix((KtDeclaration)element); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/CommaInWhenConditionWithoutArgumentFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/CommaInWhenConditionWithoutArgumentFix.kt index b140a795a7e..5b2110541fc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/CommaInWhenConditionWithoutArgumentFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/CommaInWhenConditionWithoutArgumentFix.kt @@ -22,7 +22,6 @@ import com.intellij.openapi.project.Project import com.intellij.psi.PsiElement import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.intentions.branchedTransformations.combineWhenConditions -import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.createIntentionFactory import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.* import java.util.* diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ConvertExtensionPropertyInitializerToGetterFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ConvertExtensionPropertyInitializerToGetterFix.kt index 0da8ee14c38..9f779db5d3a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ConvertExtensionPropertyInitializerToGetterFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ConvertExtensionPropertyInitializerToGetterFix.kt @@ -21,17 +21,15 @@ import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.intentions.ConvertPropertyInitializerToGetterIntention -import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention import org.jetbrains.kotlin.psi.KtExpression import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtProperty -import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.psiUtil.getParentOfType class ConvertExtensionPropertyInitializerToGetterFix(element: KtExpression) : KotlinQuickFixAction(element) { override fun getText(): String = "Convert extension property initializer to getter" - override fun getFamilyName(): String = getText() + override fun getFamilyName(): String = text override fun invoke(project: Project, editor: Editor?, file: KtFile) { val property = element.getParentOfType(true) ?: return diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt index 36d4f78564d..4c437c6aeb4 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ExclExclCallFixes.kt @@ -25,7 +25,6 @@ import com.intellij.psi.PsiFile import com.intellij.psi.impl.source.tree.LeafPsiElement import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassifierDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.KotlinBundle @@ -38,12 +37,11 @@ import org.jetbrains.kotlin.psi.KtPostfixExpression import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.resolve.lazy.BodyResolveMode import org.jetbrains.kotlin.types.TypeUtils -import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import org.jetbrains.kotlin.util.OperatorChecks import org.jetbrains.kotlin.util.OperatorNameConventions public abstract class ExclExclCallFix : IntentionAction { - override fun getFamilyName(): String = getText() + override fun getFamilyName(): String = text override fun startInWriteAction(): Boolean = true @@ -60,13 +58,13 @@ public class RemoveExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix if (!FileModificationService.getInstance().prepareFileForWrite(file)) return val postfixExpression = getExclExclPostfixExpression() ?: return - val expression = KtPsiFactory(project).createExpression(postfixExpression.getBaseExpression()!!.getText()) + val expression = KtPsiFactory(project).createExpression(postfixExpression.baseExpression!!.text) postfixExpression.replace(expression) } private fun getExclExclPostfixExpression(): KtPostfixExpression? { - val operationParent = psiElement.getParent() - if (operationParent is KtPostfixExpression && operationParent.getBaseExpression() != null) { + val operationParent = psiElement.parent + if (operationParent is KtPostfixExpression && operationParent.baseExpression != null) { return operationParent } return null @@ -74,7 +72,7 @@ public class RemoveExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix companion object : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction - = RemoveExclExclCallFix(diagnostic.getPsiElement()) + = RemoveExclExclCallFix(diagnostic.psiElement) } } @@ -87,13 +85,13 @@ public class AddExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix() override fun invoke(project: Project, editor: Editor?, file: PsiFile?) { val modifiedExpression = getExpressionForIntroduceCall() ?: return - val exclExclExpression = KtPsiFactory(project).createExpression(modifiedExpression.getText() + "!!") + val exclExclExpression = KtPsiFactory(project).createExpression(modifiedExpression.text + "!!") modifiedExpression.replace(exclExclExpression) } protected fun getExpressionForIntroduceCall(): KtExpression? { - if (psiElement is LeafPsiElement && psiElement.getElementType() == KtTokens.DOT) { - val sibling = psiElement.getPrevSibling() + if (psiElement is LeafPsiElement && psiElement.elementType == KtTokens.DOT) { + val sibling = psiElement.prevSibling if (sibling is KtExpression) { return sibling } @@ -107,7 +105,7 @@ public class AddExclExclCallFix(val psiElement: PsiElement) : ExclExclCallFix() companion object : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction - = AddExclExclCallFix(diagnostic.getPsiElement()) + = AddExclExclCallFix(diagnostic.psiElement) } } @@ -128,7 +126,7 @@ object MissingIteratorExclExclFixFactory : KotlinSingleIntentionActionFactory() val memberScope = descriptor.unsubstitutedMemberScope val functions = memberScope.getContributedFunctions(OperatorNameConventions.ITERATOR, NoLookupLocation.FROM_IDE) - return functions.any { it.isOperator() && OperatorChecks.canBeOperator(it) } + return functions.any { it.isOperator && OperatorChecks.canBeOperator(it) } } when (descriptor) { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/InsertDelegationCallQuickfix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/InsertDelegationCallQuickfix.kt index b3c5d36b4c9..2f4b33eb963 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/InsertDelegationCallQuickfix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/InsertDelegationCallQuickfix.kt @@ -49,9 +49,9 @@ public class InsertDelegationCallQuickfix(val isThis: Boolean, element: KtSecond val descriptor = element.resolveToDescriptor() // if empty call is ok and it's resolved to another constructor, do not move caret - if (resolvedCall?.isReallySuccess() ?: false && resolvedCall!!.getCandidateDescriptor().getOriginal() != descriptor) return + if (resolvedCall?.isReallySuccess() ?: false && resolvedCall!!.candidateDescriptor.original != descriptor) return - val leftParOffset = newDelegationCall.getValueArgumentList()!!.getLeftParenthesis()!!.getTextOffset() + val leftParOffset = newDelegationCall.valueArgumentList!!.leftParenthesis!!.textOffset editor?.moveCaret(leftParOffset + 1) } @@ -69,12 +69,12 @@ public class InsertDelegationCallQuickfix(val isThis: Boolean, element: KtSecond return InsertDelegationCallQuickfix(isThis = true, element = secondaryConstructor) } - private fun KtClassOrObject.getConstructorsCount() = (descriptor as ClassDescriptor).getConstructors().size() + private fun KtClassOrObject.getConstructorsCount() = (descriptor as ClassDescriptor).constructors.size } object InsertSuperDelegationCallFactory : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val secondaryConstructor = diagnostic.getPsiElement().getNonStrictParentOfType() ?: return null + val secondaryConstructor = diagnostic.psiElement.getNonStrictParentOfType() ?: return null if (!secondaryConstructor.hasImplicitDelegationCall()) return null val klass = secondaryConstructor.getContainingClassOrObject() as? KtClass ?: return null if (klass.hasPrimaryConstructor()) return null diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt index 27d5669a61c..88232b08494 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/KotlinReferenceImporter.kt @@ -89,7 +89,7 @@ public class KotlinReferenceImporter : ReferenceImporter { var suggestions = AutoImportFix(this).computeSuggestions() - if (suggestions.distinctBy { it.importableFqName!! }.size() != 1) return false + if (suggestions.distinctBy { it.importableFqName!! }.size != 1) return false // we do not auto-import nested classes because this will probably add qualification into the text and this will confuse the user if (suggestions.any { it is ClassDescriptor && it.containingDeclaration is ClassDescriptor }) return false diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeClassAnAnnotationClassFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeClassAnAnnotationClassFix.java index a4bc700b7ac..90032e4703b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeClassAnAnnotationClassFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/MakeClassAnAnnotationClassFix.java @@ -44,7 +44,7 @@ public class MakeClassAnAnnotationClassFix extends KotlinQuickFixAction 0 + return overriddenNonOverridableMembers.size > 0 } override fun getText(): String { - if (overriddenNonOverridableMembers.size() == 1) { - val name = containingDeclarationsNames.get(0) + "." + element.name + if (overriddenNonOverridableMembers.size == 1) { + val name = containingDeclarationsNames[0] + "." + element.name return "Make $name $OPEN_KEYWORD" } Collections.sort(containingDeclarationsNames) - val declarations = containingDeclarationsNames.subList(0, containingDeclarationsNames.size()-1).joinToString(", ") + " and " + + val declarations = containingDeclarationsNames.subList(0, containingDeclarationsNames.size - 1).joinToString(", ") + " and " + containingDeclarationsNames.last() return "Make '${element.name}' in $declarations open" } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/MissingConstructorKeywordFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/MissingConstructorKeywordFix.kt index ba0d8222f6d..40570c73101 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/MissingConstructorKeywordFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/MissingConstructorKeywordFix.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.KtPrimaryConstructor import org.jetbrains.kotlin.idea.quickfix.quickfixUtil.addConstructorKeyword public class MissingConstructorKeywordFix(element: KtPrimaryConstructor) : KotlinQuickFixAction(element), CleanupFix { - override fun getFamilyName(): String = getText() + override fun getFamilyName(): String = text override fun getText(): String = "Add 'constructor' keyword" override fun invoke(project: Project, editor: Editor?, file: KtFile) { @@ -40,7 +40,7 @@ public class MissingConstructorKeywordFix(element: KtPrimaryConstructor) : Kotli public fun createWholeProjectFixFactory(): KotlinSingleIntentionActionFactory = createIntentionFactory { WholeProjectForEachElementOfTypeFix.createByPredicate( - predicate = { it.getModifierList() != null && !it.hasConstructorKeyword() }, + predicate = { it.modifierList != null && !it.hasConstructorKeyword() }, taskProcessor = { it.addConstructorKeyword() }, name = "Add missing 'constructor' keyword in whole project" ) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/MoveWhenElseBranchFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/MoveWhenElseBranchFix.java index 6d9ee914053..a8df1083085 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/MoveWhenElseBranchFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/MoveWhenElseBranchFix.java @@ -16,7 +16,7 @@ package org.jetbrains.kotlin.idea.quickfix; -import com.intellij.codeInsight.CodeInsightUtilBase; +import com.intellij.codeInsight.CodeInsightUtilCore; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.project.Project; import com.intellij.psi.PsiElement; @@ -47,7 +47,7 @@ public class MoveWhenElseBranchFix extends KotlinQuickFixAction()) + val addAbstractToClassFactory = AddModifierFix.createFactory(ABSTRACT_KEYWORD, KtClass::class.java) ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS.registerFactory(removeAbstractModifierFactory, addAbstractToClassFactory) ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.registerFactory(removeAbstractModifierFactory, addAbstractToClassFactory) @@ -109,8 +109,8 @@ public class QuickFixRegistrar : QuickFixContributor { VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY.registerFactory(RemoveModifierFix.createRemoveVarianceFactory()) val removeOpenModifierFactory = RemoveModifierFix.createRemoveModifierFromListOwnerFactory(OPEN_KEYWORD) - NON_FINAL_MEMBER_IN_FINAL_CLASS.registerFactory(AddModifierFix.createFactory(OPEN_KEYWORD, javaClass()), - removeOpenModifierFactory) + NON_FINAL_MEMBER_IN_FINAL_CLASS.registerFactory(AddModifierFix.createFactory(OPEN_KEYWORD, KtClass::class.java), + removeOpenModifierFactory) val removeModifierFactory = RemoveModifierFix.createRemoveModifierFactory() GETTER_VISIBILITY_DIFFERS_FROM_PROPERTY_VISIBILITY.registerFactory(removeModifierFactory) @@ -195,7 +195,7 @@ public class QuickFixRegistrar : QuickFixContributor { UNCHECKED_CAST.registerFactory(changeToStarProjectionFactory) CANNOT_CHECK_FOR_ERASED.registerFactory(changeToStarProjectionFactory) - INACCESSIBLE_OUTER_CLASS_EXPRESSION.registerFactory(AddModifierFix.createFactory(INNER_KEYWORD, javaClass())) + INACCESSIBLE_OUTER_CLASS_EXPRESSION.registerFactory(AddModifierFix.createFactory(INNER_KEYWORD, KtClass::class.java)) FINAL_SUPERTYPE.registerFactory(AddModifierFix.MakeClassOpenFactory) FINAL_UPPER_BOUND.registerFactory(AddModifierFix.MakeClassOpenFactory) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveFunctionBodyFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveFunctionBodyFix.java index 1ece0747e91..44b8ab639af 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveFunctionBodyFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveFunctionBodyFix.java @@ -52,12 +52,12 @@ public class RemoveFunctionBodyFix extends KotlinQuickFixAction { } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiFile file) { return super.isAvailable(project, editor, file) && getElement().hasBody(); } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { KtFunction function = (KtFunction) getElement().copy(); assert function instanceof ASTDelegatePsiElement; ASTDelegatePsiElement functionElementWithAst = (ASTDelegatePsiElement) function; @@ -91,7 +91,7 @@ public class RemoveFunctionBodyFix extends KotlinQuickFixAction { public static KotlinSingleIntentionActionFactory createFactory() { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { KtFunction function = QuickFixUtil.getParentElementOfType(diagnostic, KtFunction.class); if (function == null) return null; return new RemoveFunctionBodyFix(function); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt index db6ab6bb112..e10c29b55be 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveModifierFix.kt @@ -70,7 +70,7 @@ public class RemoveModifierFix( public fun createRemoveModifierFromListOwnerFactory(modifier: KtModifierKeywordToken, isRedundant: Boolean = false): KotlinSingleIntentionActionFactory { return object : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): KotlinQuickFixAction? { - val modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null + val modifierListOwner = QuickFixUtil.getParentElementOfType(diagnostic, KtModifierListOwner::class.java) ?: return null return RemoveModifierFix(modifierListOwner, modifier, isRedundant) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNameFromFunctionExpressionFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNameFromFunctionExpressionFix.kt index cc510459439..621f1a43b8b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNameFromFunctionExpressionFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNameFromFunctionExpressionFix.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.resolve.BindingContext public class RemoveNameFromFunctionExpressionFix(element: KtNamedFunction) : KotlinQuickFixAction(element), CleanupFix { override fun getText(): String = "Remove identifier from anonymous function" - override fun getFamilyName(): String = getText() + override fun getFamilyName(): String = text override fun invoke(project: Project, editor: Editor?, file: KtFile) = removeNameFromFunction(element) @@ -38,7 +38,7 @@ public class RemoveNameFromFunctionExpressionFix(element: KtNamedFunction) : Kot private fun removeNameFromFunction(function: KtNamedFunction) { var wereAutoLabelUsages = false - val name = function.getNameAsName() ?: return + val name = function.nameAsName ?: return function.forEachDescendantOfType { if (!wereAutoLabelUsages && it.getLabelNameAsName() == name) { @@ -46,7 +46,7 @@ public class RemoveNameFromFunctionExpressionFix(element: KtNamedFunction) : Kot } } - function.getNameIdentifier()?.delete() + function.nameIdentifier?.delete() if (wereAutoLabelUsages) { val psiFactory = KtPsiFactory(function) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNullableFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNullableFix.java index 45b2aa25bb1..288832793af 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNullableFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveNullableFix.java @@ -58,7 +58,7 @@ public class RemoveNullableFix extends KotlinQuickFixAction { } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { KtTypeElement type = super.getElement().getInnerType(); assert type != null : "No inner type " + getElement().getText() + ", should have been rejected in createFactory()"; super.getElement().replace(type); @@ -67,7 +67,7 @@ public class RemoveNullableFix extends KotlinQuickFixAction { public static KotlinSingleIntentionActionFactory createFactory(final NullableKind typeOfError) { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { KtNullableType nullType = QuickFixUtil.getParentElementOfType(diagnostic, KtNullableType.class); if (nullType == null || nullType.getInnerType() == null) return null; return new RemoveNullableFix(nullType, typeOfError); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePartsFromPropertyFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePartsFromPropertyFix.java index 006b7258eb9..ad3b23416a7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePartsFromPropertyFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePartsFromPropertyFix.java @@ -84,13 +84,13 @@ public class RemovePartsFromPropertyFix extends KotlinQuickFixAction } @Override - public boolean isAvailable(@NotNull Project project, Editor editor, PsiFile file) { + public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiFile file) { KotlinType type = QuickFixUtil.getDeclarationReturnType(getElement()); return super.isAvailable(project, editor, file) && type != null && !type.isError(); } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { KotlinType type = QuickFixUtil.getDeclarationReturnType(getElement()); KtProperty newElement = (KtProperty) getElement().copy(); KtPropertyAccessor getter = newElement.getGetter(); @@ -123,7 +123,7 @@ public class RemovePartsFromPropertyFix extends KotlinQuickFixAction public static KotlinSingleIntentionActionFactory createFactory() { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { PsiElement element = diagnostic.getPsiElement(); assert element instanceof KtElement; KtProperty property = PsiTreeUtil.getParentOfType(element, KtProperty.class); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePsiElementSimpleFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePsiElementSimpleFix.java index 5cff21cf66c..9009e95db26 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePsiElementSimpleFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemovePsiElementSimpleFix.java @@ -53,14 +53,14 @@ public class RemovePsiElementSimpleFix extends KotlinQuickFixAction } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { element.delete(); } public static KotlinSingleIntentionActionFactory createRemoveImportFactory() { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { KtImportDirective directive = QuickFixUtil.getParentElementOfType(diagnostic, KtImportDirective.class); if (directive == null) return null; else { @@ -79,7 +79,7 @@ public class RemovePsiElementSimpleFix extends KotlinQuickFixAction public static KotlinSingleIntentionActionFactory createRemoveSpreadFactory() { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { PsiElement element = diagnostic.getPsiElement(); if ((element instanceof LeafPsiElement) && ((LeafPsiElement) element).getElementType() == KtTokens.MUL) { return new RemovePsiElementSimpleFix(element, KotlinBundle.message("remove.spread.sign")); @@ -92,7 +92,7 @@ public class RemovePsiElementSimpleFix extends KotlinQuickFixAction public static KotlinSingleIntentionActionFactory createRemoveTypeArgumentsFactory() { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { KtTypeArgumentList element = QuickFixUtil.getParentElementOfType(diagnostic, KtTypeArgumentList.class); if (element == null) return null; return new RemovePsiElementSimpleFix(element, @@ -104,13 +104,13 @@ public class RemovePsiElementSimpleFix extends KotlinQuickFixAction public static KotlinSingleIntentionActionFactory createRemoveVariableFactory() { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { final KtProperty expression = QuickFixUtil.getParentElementOfType(diagnostic, KtProperty.class); if (expression == null) return null; return new RemovePsiElementSimpleFix(expression, KotlinBundle.message("remove.variable.action", (expression.getName()))) { @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { KtExpression initializer = expression.getInitializer(); if (initializer != null) { expression.replace(initializer); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveRightPartOfBinaryExpressionFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveRightPartOfBinaryExpressionFix.java index e139f686d3c..e233cd65c3b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveRightPartOfBinaryExpressionFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveRightPartOfBinaryExpressionFix.java @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.diagnostics.Diagnostic; import org.jetbrains.kotlin.idea.KotlinBundle; import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil; import org.jetbrains.kotlin.psi.*; +import org.jetbrains.kotlin.psi.psiUtil.PsiUtilsKt; public class RemoveRightPartOfBinaryExpressionFix extends KotlinQuickFixAction implements CleanupFix { private final String message; @@ -34,6 +35,7 @@ public class RemoveRightPartOfBinaryExpressionFix extend this.message = message; } + @NotNull @Override public String getText() { return message; @@ -46,7 +48,7 @@ public class RemoveRightPartOfBinaryExpressionFix extend } @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { + public void invoke(@NotNull Project project, Editor editor, @NotNull KtFile file) throws IncorrectOperationException { invoke(); } @@ -67,13 +69,17 @@ public class RemoveRightPartOfBinaryExpressionFix extend newExpression = (KtExpression) parent.replace(newExpression); } + if (newExpression == null) { + throw new IncorrectOperationException("Unexpected element: " + PsiUtilsKt.getElementTextWithContext(getElement())); + } + return newExpression; } public static KotlinSingleIntentionActionFactory createRemoveTypeFromBinaryExpressionFactory(final String message) { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { KtBinaryExpressionWithTypeRHS expression = QuickFixUtil.getParentElementOfType(diagnostic, KtBinaryExpressionWithTypeRHS.class); if (expression == null) return null; return new RemoveRightPartOfBinaryExpressionFix(expression, message); @@ -84,7 +90,7 @@ public class RemoveRightPartOfBinaryExpressionFix extend public static KotlinSingleIntentionActionFactory createRemoveElvisOperatorFactory() { return new KotlinSingleIntentionActionFactory() { @Override - public KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { KtBinaryExpression expression = (KtBinaryExpression) diagnostic.getPsiElement(); return new RemoveRightPartOfBinaryExpressionFix(expression, KotlinBundle.message("remove.elvis.operator")); } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveSupertypeFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveSupertypeFix.java index 8c168552e42..f2219b44b88 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveSupertypeFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveSupertypeFix.java @@ -51,7 +51,7 @@ public class RemoveSupertypeFix extends KotlinQuickFixAction createAction(Diagnostic diagnostic) { + public KotlinQuickFixAction createAction(@NotNull Diagnostic diagnostic) { KtSuperTypeListEntry superClass = QuickFixUtil.getParentElementOfType(diagnostic, KtSuperTypeListEntry.class); if (superClass == null) return null; return new RemoveSupertypeFix(superClass); diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveValVarFromParameterFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveValVarFromParameterFix.java index 004c7deafe7..e656abac381 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveValVarFromParameterFix.java +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/RemoveValVarFromParameterFix.java @@ -52,7 +52,7 @@ public class RemoveValVarFromParameterFix extends KotlinQuickFixAction get() = javaClass() + override val classToReplace: Class get() = KtDotQualifiedExpression::class.java companion object : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction - = ReplaceWithSafeCallFix(diagnostic.getPsiElement()) + = ReplaceWithSafeCallFix(diagnostic.psiElement) } } public class ReplaceWithDotCallFix(psiElement: PsiElement): ReplaceCallFix(psiElement), CleanupFix { override fun getText(): String = KotlinBundle.message("replace.with.dot.call") override val operation: String get() = "." - override val classToReplace: Class get() = javaClass() + override val classToReplace: Class get() = KtSafeQualifiedExpression::class.java companion object : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction - = ReplaceWithDotCallFix(diagnostic.getPsiElement()) + = ReplaceWithDotCallFix(diagnostic.psiElement) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt index 7f593bea41d..7bee78786b9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceJavaAnnotationPositionedArgumentsFix.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.idea.quickfix -import com.intellij.codeInsight.intention.IntentionAction import com.intellij.openapi.editor.Editor import com.intellij.openapi.project.Project import org.jetbrains.kotlin.diagnostics.Diagnostic @@ -32,7 +31,7 @@ import org.jetbrains.kotlin.resolve.calls.model.ExpressionValueArgument public class ReplaceJavaAnnotationPositionedArgumentsFix(element: KtAnnotationEntry) : KotlinQuickFixAction(element), CleanupFix { override fun getText(): String = "Replace invalid positioned arguments for annotation" - override fun getFamilyName(): String = getText() + override fun getFamilyName(): String = text override fun invoke(project: Project, editor: Editor?, file: KtFile) { val resolvedCall = element.getResolvedCall(element.analyze()) ?: return @@ -40,10 +39,10 @@ public class ReplaceJavaAnnotationPositionedArgumentsFix(element: KtAnnotationEn getJavaAnnotationCallValueArgumentsThatShouldBeNamed(resolvedCall).forEach argumentProcessor@{ argument -> - val valueArgument = (argument.value as? ExpressionValueArgument)?.getValueArgument() ?: return@argumentProcessor + val valueArgument = (argument.value as? ExpressionValueArgument)?.valueArgument ?: return@argumentProcessor val expression = valueArgument.getArgumentExpression() ?: return@argumentProcessor - valueArgument.asElement().replace(psiFactory.createArgument(expression, argument.getKey().getName())) + valueArgument.asElement().replace(psiFactory.createArgument(expression, argument.key.name)) } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt index a93180497d8..c95fb75036f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceObsoleteLabelSyntaxFix.kt @@ -31,13 +31,13 @@ import org.jetbrains.kotlin.resolve.BindingContext public class ReplaceObsoleteLabelSyntaxFix(element: KtAnnotationEntry) : KotlinQuickFixAction(element), CleanupFix { override fun getFamilyName(): String = "Update obsolete label syntax" - override fun getText(): String = "Replace with label ${element.getCalleeExpression()?.getText() ?: ""}@" + override fun getText(): String = "Replace with label ${element.calleeExpression?.text ?: ""}@" override fun invoke(project: Project, editor: Editor?, file: KtFile) = replaceWithLabel(element) companion object : KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val annotationEntry = diagnostic.getPsiElement().getNonStrictParentOfType() ?: return null + val annotationEntry = diagnostic.psiElement.getNonStrictParentOfType() ?: return null if (!looksLikeObsoleteLabel(annotationEntry)) return null @@ -47,7 +47,7 @@ public class ReplaceObsoleteLabelSyntaxFix(element: KtAnnotationEntry) : KotlinQ public fun createWholeProjectFixFactory(): KotlinSingleIntentionActionFactory = createIntentionFactory factory@ { diagnostic -> - if (!(diagnostic.getPsiElement().getNonStrictParentOfType()?.looksLikeObsoleteLabelWithReferencesInCode() + if (!(diagnostic.psiElement.getNonStrictParentOfType()?.looksLikeObsoleteLabelWithReferencesInCode() ?: false)) return@factory null WholeProjectForEachElementOfTypeFix.createForMultiTaskOnElement( @@ -58,41 +58,41 @@ public class ReplaceObsoleteLabelSyntaxFix(element: KtAnnotationEntry) : KotlinQ } private fun collectTasks(expression: KtAnnotatedExpression) = - expression.getAnnotationEntries().filter { it.looksLikeObsoleteLabelWithReferencesInCode() } + expression.annotationEntries.filter { it.looksLikeObsoleteLabelWithReferencesInCode() } private fun KtAnnotationEntry.looksLikeObsoleteLabelWithReferencesInCode(): Boolean { if (!looksLikeObsoleteLabel(this)) return false - val baseExpression = (getParent() as? KtAnnotatedExpression)?.getBaseExpression() ?: return false + val baseExpression = (parent as? KtAnnotatedExpression)?.baseExpression ?: return false - val nameExpression = getCalleeExpression()?.getConstructorReferenceExpression() ?: return false + val nameExpression = calleeExpression?.constructorReferenceExpression ?: return false val labelName = nameExpression.getReferencedName() return baseExpression.anyDescendantOfType { (it is KtBreakExpression || it is KtContinueExpression || it is KtReturnExpression) && it.getLabelName() == labelName && it.getTargetLabel()?.analyze()?.get(BindingContext.LABEL_TARGET, it.getTargetLabel()) == null - } && analyze().getDiagnostics().forElement(nameExpression).any { it.getFactory() == Errors.UNRESOLVED_REFERENCE } + } && analyze().diagnostics.forElement(nameExpression).any { it.factory == Errors.UNRESOLVED_REFERENCE } } public fun looksLikeObsoleteLabel(entry: KtAnnotationEntry): Boolean = - entry.getAtSymbol() != null && - entry.getParent() is KtAnnotatedExpression && - (entry.getParent() as KtAnnotatedExpression).getAnnotationEntries().size() == 1 && - entry.getValueArgumentList() == null && - entry.getCalleeExpression()?.getConstructorReferenceExpression()?.getIdentifier() != null + entry.atSymbol != null && + entry.parent is KtAnnotatedExpression && + (entry.parent as KtAnnotatedExpression).annotationEntries.size == 1 && + entry.valueArgumentList == null && + entry.calleeExpression?.constructorReferenceExpression?.getIdentifier() != null private fun replaceWithLabel(annotation: KtAnnotationEntry) { - val labelName = annotation.getCalleeExpression()?.getConstructorReferenceExpression()?.getReferencedName() ?: return - val annotatedExpression = annotation.getParent() as? KtAnnotatedExpression ?: return - val expression = annotatedExpression.getBaseExpression() ?: return + val labelName = annotation.calleeExpression?.constructorReferenceExpression?.getReferencedName() ?: return + val annotatedExpression = annotation.parent as? KtAnnotatedExpression ?: return + val expression = annotatedExpression.baseExpression ?: return - if (annotatedExpression.getAnnotationEntries().size() != 1) return + if (annotatedExpression.annotationEntries.size != 1) return - val baseExpressionStart = expression.getTextRange().getStartOffset() + val baseExpressionStart = expression.textRange.startOffset - val textRangeToRetain = TextRange(annotation.getTextRange().getEndOffset(), baseExpressionStart) - val textToRetain = textRangeToRetain.substring(annotation.getContainingFile().getText()) + val textRangeToRetain = TextRange(annotation.textRange.endOffset, baseExpressionStart) + val textToRetain = textRangeToRetain.substring(annotation.containingFile.text) val labeledExpression = KtPsiFactory(annotation).createExpressionByPattern("$0@$1$2", labelName, textToRetain, expression) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceOperationInBinaryExpressionFix.java b/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceOperationInBinaryExpressionFix.java deleted file mode 100644 index 016893ad5f2..00000000000 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/ReplaceOperationInBinaryExpressionFix.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.idea.quickfix; - -import com.intellij.openapi.editor.Editor; -import com.intellij.openapi.project.Project; -import com.intellij.util.IncorrectOperationException; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.idea.KotlinBundle; -import org.jetbrains.kotlin.psi.*; - -public abstract class ReplaceOperationInBinaryExpressionFix extends KotlinQuickFixAction { - private final String operation; - - public ReplaceOperationInBinaryExpressionFix(@NotNull T element, String operation) { - super(element); - this.operation = operation; - } - - @NotNull - @Override - public String getFamilyName() { - return KotlinBundle.message("replace.operation.in.binary.expression"); - } - - @Override - public void invoke(@NotNull Project project, Editor editor, KtFile file) throws IncorrectOperationException { - if (getElement() instanceof KtBinaryExpressionWithTypeRHS) { - KtExpression left = ((KtBinaryExpressionWithTypeRHS) getElement()).getLeft(); - KtTypeReference right = ((KtBinaryExpressionWithTypeRHS) getElement()).getRight(); - if (right != null) { - KtExpression expression = KtPsiFactoryKt.KtPsiFactory(file).createExpression(left.getText() + operation + right.getText()); - getElement().replace(expression); - } - } - } -} diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt index a8f32d383da..135405971b1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/SpecifyTypeExplicitlyFix.kt @@ -25,7 +25,6 @@ import org.jetbrains.kotlin.idea.intentions.SpecifyTypeExplicitlyIntention import org.jetbrains.kotlin.psi.KtCallableDeclaration import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.KtProperty -import org.jetbrains.kotlin.psi.psiUtil.getParentOfType public class SpecifyTypeExplicitlyFix : PsiElementBaseIntentionAction() { override fun getFamilyName() = "Specify type explicitly" @@ -39,19 +38,19 @@ public class SpecifyTypeExplicitlyFix : PsiElementBaseIntentionAction() { override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean { val declaration = declarationByElement(element) if (declaration is KtProperty) { - setText("Specify type explicitly") + text = "Specify type explicitly" } else if (declaration is KtNamedFunction) { - setText("Specify return type explicitly") + text = "Specify return type explicitly" } else { return false } - return !SpecifyTypeExplicitlyIntention.getTypeForDeclaration(declaration).isError() + return !SpecifyTypeExplicitlyIntention.getTypeForDeclaration(declaration).isError } private fun declarationByElement(element: PsiElement): KtCallableDeclaration? { - return PsiTreeUtil.getParentOfType(element, javaClass(), javaClass()) as KtCallableDeclaration? + return PsiTreeUtil.getParentOfType(element, KtProperty::class.java, KtNamedFunction::class.java) as KtCallableDeclaration? } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt index bd1ec1d7c2a..e5c8fa49e05 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/SuperClassNotInitialized.kt @@ -49,39 +49,39 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() { private val DISPLAY_MAX_PARAMS = 5 override fun doCreateActions(diagnostic: Diagnostic): List { - val delegator = diagnostic.getPsiElement() as KtSuperTypeEntry - val classOrObjectDeclaration = delegator.getParent().getParent() as? KtClassOrObject ?: return emptyList() + val delegator = diagnostic.psiElement as KtSuperTypeEntry + val classOrObjectDeclaration = delegator.parent.parent as? KtClassOrObject ?: return emptyList() - val typeRef = delegator.getTypeReference() ?: return emptyList() + val typeRef = delegator.typeReference ?: return emptyList() val type = typeRef.analyze()[BindingContext.TYPE, typeRef] ?: return emptyList() - if (type.isError()) return emptyList() + if (type.isError) return emptyList() - val superClass = (type.getConstructor().getDeclarationDescriptor() as? ClassDescriptor) ?: return emptyList() + val superClass = (type.constructor.declarationDescriptor as? ClassDescriptor) ?: return emptyList() val classDescriptor = delegator.getResolutionFacade().resolveToDescriptor(classOrObjectDeclaration) as ClassDescriptor - val constructors = superClass.getConstructors().filter { it.isVisible(classDescriptor) } + val constructors = superClass.constructors.filter { it.isVisible(classDescriptor) } if (constructors.isEmpty()) return emptyList() // no accessible constructor val fixes = ArrayList() - fixes.add(AddParenthesisFix(delegator, putCaretIntoParenthesis = constructors.singleOrNull()?.getValueParameters()?.isNotEmpty() ?: true)) + fixes.add(AddParenthesisFix(delegator, putCaretIntoParenthesis = constructors.singleOrNull()?.valueParameters?.isNotEmpty() ?: true)) if (classOrObjectDeclaration is KtClass) { - val superType = classDescriptor.getTypeConstructor().getSupertypes().firstOrNull { it.getConstructor().getDeclarationDescriptor() == superClass } + val superType = classDescriptor.typeConstructor.supertypes.firstOrNull { it.constructor.declarationDescriptor == superClass } if (superType != null) { val substitutor = TypeConstructorSubstitution.create(superClass.typeConstructor, superType.arguments).buildSubstitutor() val substitutedConstructors = constructors - .filter { it.getValueParameters().isNotEmpty() } + .filter { it.valueParameters.isNotEmpty() } .map { it.substitute(substitutor) } if (substitutedConstructors.isNotEmpty()) { val parameterTypes: List> = substitutedConstructors.map { - it.getValueParameters().map { it.getType() } + it.valueParameters.map { it.type } } - fun canRenderOnlyFirstParameters(n: Int) = parameterTypes.map { it.take(n) }.toSet().size() == parameterTypes.size() + fun canRenderOnlyFirstParameters(n: Int) = parameterTypes.map { it.take(n) }.toSet().size == parameterTypes.size - val maxParams = parameterTypes.map { it.size() }.max()!! + val maxParams = parameterTypes.map { it.size }.max()!! val maxParamsToDisplay = if (maxParams <= DISPLAY_MAX_PARAMS) { maxParams } @@ -91,8 +91,8 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() { for ((constructor, types) in substitutedConstructors.zip(parameterTypes)) { val typesRendered = types.take(maxParamsToDisplay).map { DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(it) } - val parameterString = typesRendered.joinToString(", ", "(", if (types.size() <= maxParamsToDisplay) ")" else ",...)") - val text = "Add constructor parameters from " + superClass.getName().asString() + parameterString + val parameterString = typesRendered.joinToString(", ", "(", if (types.size <= maxParamsToDisplay) ")" else ",...)") + val text = "Add constructor parameters from " + superClass.name.asString() + parameterString fixes.addIfNotNull(AddParametersFix.create(delegator, classOrObjectDeclaration, constructor, text)) } } @@ -109,16 +109,16 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() { override fun getFamilyName() = "Change to constructor invocation" //TODO? - override fun getText() = getFamilyName() + override fun getText() = familyName override fun invoke(project: Project, editor: Editor?, file: KtFile) { - val newSpecifier = element.replaced(KtPsiFactory(project).createSuperTypeCallEntry(element.getText() + "()")) + val newSpecifier = element.replaced(KtPsiFactory(project).createSuperTypeCallEntry(element.text + "()")) if (putCaretIntoParenthesis) { if (editor != null) { - val offset = newSpecifier.getValueArgumentList()!!.getLeftParenthesis()!!.endOffset + val offset = newSpecifier.valueArgumentList!!.leftParenthesis!!.endOffset editor.moveCaret(offset) - if (!ApplicationManager.getApplication().isUnitTestMode()) { + if (!ApplicationManager.getApplication().isUnitTestMode) { ShowParameterInfoHandler.invoke(project, editor, file, offset - 1, null) } } @@ -141,7 +141,7 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() { superConstructor: ConstructorDescriptor, text: String ): AddParametersFix? { - val superParameters = superConstructor.getValueParameters() + val superParameters = superConstructor.valueParameters assert(superParameters.isNotEmpty()) if (superParameters.any { it.type.isError }) return null @@ -158,11 +158,11 @@ public object SuperClassNotInitialized : KotlinIntentionActionsFactory() { } argumentText.append(if (varargElementType != null) "*$nameRendered" else nameRendered) - val nameString = parameter.getName().asString() - val existingParameter = oldParameters.firstOrNull { it.getName() == nameString } + val nameString = parameter.name.asString() + val existingParameter = oldParameters.firstOrNull { it.name == nameString } if (existingParameter != null) { - val type = (existingParameter.resolveToDescriptor() as ValueParameterDescriptor).getType() - if (type.isSubtypeOf(parameter.getType())) continue // use existing parameter + val type = (existingParameter.resolveToDescriptor() as ValueParameterDescriptor).type + if (type.isSubtypeOf(parameter.type)) continue // use existing parameter } val parameterText = if (varargElementType != null) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/WholeProjectModalAction.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/WholeProjectModalAction.kt index ecb65ad9276..1d6cf5abd1e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/WholeProjectModalAction.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/WholeProjectModalAction.kt @@ -38,7 +38,7 @@ import org.jetbrains.kotlin.utils.singletonOrEmptyList import java.util.* public abstract class WholeProjectModalAction(val title: String) : IntentionAction { - private val LOG = Logger.getInstance(javaClass>()); + private val LOG = Logger.getInstance(WholeProjectModalAction::class.java); override final fun startInWriteAction() = false @@ -55,9 +55,9 @@ public abstract class WholeProjectModalAction(val title: String) : val files = PluginJetFilesProvider.allFilesInProject(project) for ((i, currentFile) in files.withIndex()) { - indicator.setText("Checking file $i of ${files.size()}...") - indicator.setText2(currentFile.getVirtualFile().getPath()) - indicator.setFraction((i + 1) / files.size().toDouble()) + indicator.text = "Checking file $i of ${files.size}..." + indicator.text2 = currentFile.virtualFile.path + indicator.fraction = (i + 1) / files.size.toDouble() try { val data = collectDataForFile(project, currentFile) if (data != null) filesToData[currentFile] = data @@ -76,11 +76,11 @@ public abstract class WholeProjectModalAction(val title: String) : private fun applyAll(project: Project, filesToData: Map) { UIUtil.invokeLaterIfNeeded { - project.executeCommand(getText()) { + project.executeCommand(text) { runWriteAction { filesToData.forEach { try { - applyChangesForFile(project, it.getKey(), it.getValue()) + applyChangesForFile(project, it.key, it.value) } catch (e: Throwable) { LOG.error(e) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt index 87b6bfa8bbe..54cfea14909 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableBuilder.kt @@ -72,12 +72,10 @@ import org.jetbrains.kotlin.resolve.scopes.utils.findClassifier import org.jetbrains.kotlin.resolve.scopes.utils.memberScopeAsImportingScope import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeProjectionImpl -import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.checker.KotlinTypeChecker import org.jetbrains.kotlin.types.typeUtil.isAnyOrNullableAny import org.jetbrains.kotlin.types.typeUtil.isUnit -import org.jetbrains.kotlin.types.typeUtil.makeNullable import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList import java.util.* import kotlin.properties.Delegates @@ -99,7 +97,7 @@ class TypeCandidate(val theType: KotlinType, scope: HierarchicalScope? = null) { fun render(typeParameterNameMap: Map, fakeFunction: FunctionDescriptor?) { renderedType = theType.renderShort(typeParameterNameMap); renderedTypeParameters = typeParameters.map { - RenderedTypeParameter(it, it.getContainingDeclaration() == fakeFunction, typeParameterNameMap[it]!!) + RenderedTypeParameter(it, it.containingDeclaration == fakeFunction, typeParameterNameMap[it]!!) } } @@ -249,24 +247,24 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } is CallablePlacement.WithReceiver -> { receiverClassDescriptor = - placement.receiverTypeCandidate.theType.getConstructor().getDeclarationDescriptor() + placement.receiverTypeCandidate.theType.constructor.declarationDescriptor val classDeclaration = receiverClassDescriptor?.let { DescriptorToSourceUtils.getSourceFromDescriptor(it) } containingElement = if (!config.isExtension && classDeclaration != null) classDeclaration else config.currentFile } else -> throw IllegalArgumentException("Unexpected placement: $placement") } - val receiverType = receiverClassDescriptor?.getDefaultType() + val receiverType = receiverClassDescriptor?.defaultType - val project = config.currentFile.getProject() + val project = config.currentFile.project - if (containingElement.getContainingFile() != config.currentFile) { + if (containingElement.containingFile != config.currentFile) { NavigationUtil.activateFileWithPsiElement(containingElement) } if (containingElement is KtElement) { jetFileToEdit = containingElement.getContainingKtFile() if (jetFileToEdit != config.currentFile) { - containingFileEditor = FileEditorManager.getInstance(project).getSelectedTextEditor()!! + containingFileEditor = FileEditorManager.getInstance(project).selectedTextEditor!! } else { containingFileEditor = config.currentEditor!! @@ -282,11 +280,11 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } } containingFileEditor = dialog.editor - with(containingFileEditor.getSettings()) { - setAdditionalColumnsCount(config.currentEditor!!.getSettings().getRightMargin(project)) - setAdditionalLinesCount(5) + with(containingFileEditor.settings) { + additionalColumnsCount = config.currentEditor!!.settings.getRightMargin(project) + additionalLinesCount = 5 } - jetFileToEdit = PsiDocumentManager.getInstance(project).getPsiFile(containingFileEditor.getDocument()) as KtFile + jetFileToEdit = PsiDocumentManager.getInstance(project).getPsiFile(containingFileEditor.document) as KtFile jetFileToEdit.analysisContext = config.currentFile dialogWithEditor = dialog } @@ -303,11 +301,11 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val typeArgumentsForFakeFunction = callableInfo.typeParameterInfos .map { val typeCandidates = computeTypeCandidates(it) - assert (typeCandidates.size() == 1) { "Ambiguous type candidates for type parameter $it: $typeCandidates" } + assert (typeCandidates.size == 1) { "Ambiguous type candidates for type parameter $it: $typeCandidates" } typeCandidates.first().theType } - .subtract(substitutionMap.keySet()) - fakeFunction = createFakeFunctionDescriptor(scope, typeArgumentsForFakeFunction.size()) + .subtract(substitutionMap.keys) + fakeFunction = createFakeFunctionDescriptor(scope, typeArgumentsForFakeFunction.size) collectSubstitutionsForCallableTypeParameters(fakeFunction, typeArgumentsForFakeFunction, substitutionMap) mandatoryTypeParametersAsCandidates = receiverTypeCandidate.singletonOrEmptyList() + typeArgumentsForFakeFunction.map { TypeCandidate(substitutionMap[it]!!, scope) } } @@ -353,7 +351,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { assert (receiverClassDescriptor is JavaClassDescriptor) { "Unexpected receiver class: $receiverClassDescriptor" } val projections = ((receiverClassDescriptor as JavaClassDescriptor).declaredTypeParameters) - .map { TypeProjectionImpl(it.getDefaultType()) } + .map { TypeProjectionImpl(it.defaultType) } val memberScope = receiverClassDescriptor.getMemberScope(projections) return LexicalScopeImpl(memberScope.memberScopeAsImportingScope(), receiverClassDescriptor, false, null, @@ -368,19 +366,19 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { ) { if (placement is CallablePlacement.NoReceiver) return - val classTypeParameters = receiverType?.getArguments() ?: Collections.emptyList() - val ownerTypeArguments = (placement as? CallablePlacement.WithReceiver)?.receiverTypeCandidate?.theType?.getArguments() + val classTypeParameters = receiverType?.arguments ?: Collections.emptyList() + val ownerTypeArguments = (placement as? CallablePlacement.WithReceiver)?.receiverTypeCandidate?.theType?.arguments ?: Collections.emptyList() - assert(ownerTypeArguments.size() == classTypeParameters.size()) - ownerTypeArguments.zip(classTypeParameters).forEach { result[it.first.getType()] = it.second.getType() } + assert(ownerTypeArguments.size == classTypeParameters.size) + ownerTypeArguments.zip(classTypeParameters).forEach { result[it.first.type] = it.second.type } } private fun collectSubstitutionsForCallableTypeParameters( fakeFunction: FunctionDescriptor, typeArguments: Set, result: MutableMap) { - for ((typeArgument, typeParameter) in typeArguments.zip(fakeFunction.getTypeParameters())) { - result[typeArgument] = typeParameter.getDefaultType() + for ((typeArgument, typeParameter) in typeArguments.zip(fakeFunction.typeParameters)) { + result[typeArgument] = typeParameter.defaultType } } @@ -481,7 +479,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val safeName = name.quoteIfNeeded() when (kind) { ClassKind.ENUM_ENTRY -> { - if (!(targetParent is KtClass && targetParent.isEnum())) throw AssertionError("Enum class expected: ${targetParent.getText()}") + if (!(targetParent is KtClass && targetParent.isEnum())) throw AssertionError("Enum class expected: ${targetParent.text}") val hasParameters = targetParent.getPrimaryConstructorParameters().isNotEmpty() psiFactory.createEnumEntry("$safeName${if (hasParameters) "()" else " "}") } @@ -506,7 +504,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } if (assignmentToReplace != null) { - (declaration as KtProperty).setInitializer(assignmentToReplace.getRight()) + (declaration as KtProperty).setInitializer(assignmentToReplace.right) return assignmentToReplace.replace(declaration) as KtCallableDeclaration } @@ -519,7 +517,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { siblingsLoop@ for (sibling in decl.siblings(forward = after, withItself = false)) { when (sibling) { - is PsiWhiteSpace -> lineBreaksPresent += (sibling.getText() ?: "").count { it == '\n' } + is PsiWhiteSpace -> lineBreaksPresent += (sibling.text ?: "").count { it == '\n' } else -> { neighbor = sibling break@siblingsLoop @@ -527,7 +525,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } } - val neighborType = neighbor?.getNode()?.getElementType() + val neighborType = neighbor?.node?.elementType val lineBreaksNeeded = when { neighborType == KtTokens.LBRACE || neighborType == KtTokens.RBRACE -> 1 neighbor is KtDeclaration && (neighbor !is KtProperty || decl !is KtProperty) -> 2 @@ -539,7 +537,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { fun addNextToOriginalElementContainer(addBefore: Boolean): KtNamedDeclaration { val actualContainer = (containingElement as? KtClassOrObject)?.getBody() ?: containingElement - val sibling = config.originalElement.parentsWithSelf.first { it.getParent() == actualContainer } + val sibling = config.originalElement.parentsWithSelf.first { it.parent == actualContainer } return if (addBefore) { actualContainer.addBefore(declaration, sibling) } @@ -552,7 +550,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { containingElement.isAncestor(config.originalElement, true) -> { val insertToBlock = containingElement is KtBlockExpression if (insertToBlock) { - val parent = containingElement.getParent() + val parent = containingElement.parent if (parent is KtFunctionLiteral) { if (!parent.isMultiLine()) { parent.addBefore(newLine, containingElement) @@ -567,9 +565,9 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { containingElement is PsiClass -> { if (declaration is KtSecondaryConstructor) { - val wrappingClass = psiFactory.createClass("class ${containingElement.getName()} {\n}") + val wrappingClass = psiFactory.createClass("class ${containingElement.name} {\n}") addDeclarationToClassOrObject(wrappingClass, declaration) - (jetFileToEdit.add(wrappingClass) as KtClass).getDeclarations().first() as KtNamedDeclaration + (jetFileToEdit.add(wrappingClass) as KtClass).declarations.first() as KtNamedDeclaration } else { jetFileToEdit.add(declaration) as KtNamedDeclaration @@ -579,10 +577,10 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { containingElement is KtClassOrObject -> { addDeclarationToClassOrObject(containingElement, declaration) } - else -> throw AssertionError("Invalid containing element: ${containingElement.getText()}") + else -> throw AssertionError("Invalid containing element: ${containingElement.text}") } - val parent = declarationInPlace.getParent() + val parent = declarationInPlace.parent calcNecessaryEmptyLines(declarationInPlace, false).let { if (it > 0) parent.addBefore(psiFactory.createNewLine(it), declarationInPlace) } @@ -599,8 +597,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val classBody = classOrObject.getOrCreateBody() return if (declaration is KtNamedFunction) { val anchor = PsiTreeUtil.skipSiblingsBackward( - classBody.rBrace ?: classBody.getLastChild()!!, - javaClass() + classBody.rBrace ?: classBody.lastChild!!, + PsiWhiteSpace::class.java ) classBody.addAfter(declaration, anchor) as KtNamedDeclaration } @@ -622,7 +620,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } val validator = CollectingNameValidator { scope.findClassifier(Name.identifier(it), NoLookupLocation.FROM_IDE) == null } - val typeParameterNames = allTypeParametersNotInScope.map { KotlinNameSuggester.suggestNameByName(it.getName().asString(), validator) } + val typeParameterNames = allTypeParametersNotInScope.map { KotlinNameSuggester.suggestNameByName(it.name.asString(), validator) } return allTypeParametersNotInScope.zip(typeParameterNames).toMap() } @@ -641,8 +639,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val returnTypeRef = declaration.getReturnTypeReference() if (returnTypeRef != null) { val returnType = typeCandidates[callableInfo.returnTypeInfo]!!.getTypeByRenderedType( - returnTypeRef.getText() - ?: throw AssertionError("Expression for return type shouldn't be empty: declaration = ${declaration.getText()}") + returnTypeRef.text + ?: throw AssertionError("Expression for return type shouldn't be empty: declaration = ${declaration.text}") ) if (returnType != null) { // user selected a given type @@ -653,13 +651,13 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val valueParameters = declaration.getValueParameters() val parameterIndicesToShorten = ArrayList() - assert(valueParameters.size() == parameterTypeExpressions.size()) + assert(valueParameters.size == parameterTypeExpressions.size) for ((i, parameter) in valueParameters.asSequence().withIndex()) { - val parameterTypeRef = parameter.getTypeReference() + val parameterTypeRef = parameter.typeReference if (parameterTypeRef != null) { val parameterType = parameterTypeExpressions[i].typeCandidates.getTypeByRenderedType( - parameterTypeRef.getText() - ?: throw AssertionError("Expression for parameter type shouldn't be empty: declaration = ${declaration.getText()}") + parameterTypeRef.text + ?: throw AssertionError("Expression for parameter type shouldn't be empty: declaration = ${declaration.text}") ) if (parameterType != null) { replaceWithLongerName(parameterTypeRef, parameterType) @@ -669,25 +667,25 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } val expandedValueParameters = declaration.getValueParameters() - parameterIndicesToShorten.mapNotNullTo(typeRefsToShorten) { expandedValueParameters[it].getTypeReference() } + parameterIndicesToShorten.mapNotNullTo(typeRefsToShorten) { expandedValueParameters[it].typeReference } return typeRefsToShorten } private fun setupFunctionBody(func: KtFunction) { - val oldBody = func.getBodyExpression() ?: return + val oldBody = func.bodyExpression ?: return val templateName = when (func) { is KtSecondaryConstructor -> TEMPLATE_FROM_USAGE_SECONDARY_CONSTRUCTOR_BODY is KtNamedFunction -> TEMPLATE_FROM_USAGE_FUNCTION_BODY else -> throw AssertionError("Unexpected declaration: " + func.getElementTextWithContext()) } - val fileTemplate = FileTemplateManager.getInstance(func.getProject())!!.getCodeTemplate(templateName) + val fileTemplate = FileTemplateManager.getInstance(func.project)!!.getCodeTemplate(templateName) val properties = Properties() - properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, if (skipReturnType) "Unit" else func.getTypeReference()!!.getText()) + properties.setProperty(FileTemplate.ATTRIBUTE_RETURN_TYPE, if (skipReturnType) "Unit" else func.typeReference!!.text) receiverClassDescriptor?.let { properties.setProperty(FileTemplate.ATTRIBUTE_CLASS_NAME, DescriptorUtils.getFqName(it).asString()) - properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, it.getName().asString()) + properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, it.name.asString()) } if (callableInfo.name.isNotEmpty()) { properties.setProperty(ATTRIBUTE_FUNCTION_NAME, callableInfo.name) @@ -709,9 +707,9 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } private fun setupCallTypeArguments(callElement: KtCallElement, typeParameters: List) { - val oldTypeArgumentList = callElement.getTypeArgumentList() ?: return + val oldTypeArgumentList = callElement.typeArgumentList ?: return val renderedTypeArgs = typeParameters.map { typeParameter -> - val type = substitutions.first { it.byType.getConstructor().getDeclarationDescriptor() == typeParameter }.forType + val type = substitutions.first { it.byType.constructor.declarationDescriptor == typeParameter }.forType IdeDescriptorRenderers.SOURCE_CODE.renderType(type) } if (renderedTypeArgs.isEmpty()) { @@ -719,7 +717,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } else { oldTypeArgumentList.replace(KtPsiFactory(callElement).createTypeArguments(renderedTypeArgs.joinToString(", ", "<", ">"))) - elementsToShorten.add(callElement.getTypeArgumentList()!!) + elementsToShorten.add(callElement.typeArgumentList!!) } } @@ -731,19 +729,19 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val expression: TypeExpression when (declaration) { is KtCallableDeclaration -> { - elementToReplace = declaration.getTypeReference() + elementToReplace = declaration.typeReference expression = TypeExpression.ForTypeReference(candidates) } is KtClassOrObject -> { elementToReplace = declaration.getSuperTypeListEntries().firstOrNull() expression = TypeExpression.ForDelegationSpecifier(candidates) } - else -> throw AssertionError("Unexpected declaration kind: ${declaration.getText()}") + else -> throw AssertionError("Unexpected declaration kind: ${declaration.text}") } if (elementToReplace == null) return null - if (candidates.size() == 1) { - builder.replaceElement(elementToReplace, (expression.calculateResult(null) as TextResult).getText()) + if (candidates.size == 1) { + builder.replaceElement(elementToReplace, (expression.calculateResult(null) as TextResult).text) return null } @@ -753,7 +751,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { private fun setupValVarTemplate(builder: TemplateBuilder, property: KtProperty) { if (!(callableInfo as PropertyInfo).writable) { - builder.replaceElement(property.getValOrVarKeyword(), ValVarExpression) + builder.replaceElement(property.valOrVarKeyword, ValVarExpression) } } @@ -763,10 +761,10 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { ): TypeParameterListExpression? { when (declaration) { is KtObjectDeclaration -> return null - !is KtTypeParameterListOwner -> throw AssertionError("Unexpected declaration kind: ${declaration.getText()}") + !is KtTypeParameterListOwner -> throw AssertionError("Unexpected declaration kind: ${declaration.text}") } - val typeParameterList = (declaration as KtTypeParameterListOwner).getTypeParameterList() ?: return null + val typeParameterList = (declaration as KtTypeParameterListOwner).typeParameterList ?: return null val typeParameterMap = HashMap>() @@ -794,12 +792,12 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } private fun setupParameterTypeTemplates(builder: TemplateBuilder, parameterList: List): List { - assert(parameterList.size() == callableInfo.parameterInfos.size()) + assert(parameterList.size == callableInfo.parameterInfos.size) val typeParameters = ArrayList() for ((parameter, jetParameter) in callableInfo.parameterInfos.zip(parameterList)) { val parameterTypeExpression = TypeExpression.ForTypeReference(typeCandidates[parameter.typeInfo]!!) - val parameterTypeRef = jetParameter.getTypeReference()!! + val parameterTypeRef = jetParameter.typeReference!! builder.replaceElement(parameterTypeRef, parameterTypeExpression) // add parameter name to the template @@ -821,7 +819,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { // add expression to builder val parameterNameExpression = ParameterNameExpression(possibleNames, parameterTypeToNamesMap) - val parameterNameIdentifier = jetParameter.getNameIdentifier()!! + val parameterNameIdentifier = jetParameter.nameIdentifier!! builder.replaceElement(parameterNameIdentifier, parameterNameExpression) typeParameters.add(parameterTypeExpression) @@ -838,15 +836,15 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { fun convertToJava(targetClass: PsiClass): PsiMember? { val psiFactory = KtPsiFactory(declaration) - psiFactory.createPackageDirectiveIfNeeded(config.currentFile.getPackageFqName())?.let { - declaration.getContainingFile().addBefore(it, null) + psiFactory.createPackageDirectiveIfNeeded(config.currentFile.packageFqName)?.let { + declaration.containingFile.addBefore(it, null) } val adjustedDeclaration = when (declaration) { is KtNamedFunction, is KtProperty -> { val klass = psiFactory.createClass("class Foo {}") klass.getBody()!!.add(declaration) - (declaration.replace(klass) as KtClass).getBody()!!.getDeclarations().first() + (declaration.replace(klass) as KtClass).getBody()!!.declarations.first() } else -> declaration } @@ -870,11 +868,11 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val targetClass = DescriptorToSourceUtils.getSourceFromDescriptor(receiverClassDescriptor) as? PsiClass if (targetClass == null || !targetClass.canRefactor()) return false - val project = declaration.getProject() + val project = declaration.project val newJavaMember = convertToJava(targetClass) ?: return false - val modifierList = newJavaMember.getModifierList()!! + val modifierList = newJavaMember.modifierList!! if (newJavaMember is PsiMethod || newJavaMember is PsiClass) { modifierList.setModifierProperty(PsiModifier.FINAL, false) } @@ -889,26 +887,26 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { JavaCodeStyleManager.getInstance(project).shortenClassReferences(newJavaMember); - val descriptor = OpenFileDescriptor(project, targetClass.getContainingFile().getVirtualFile()) + val descriptor = OpenFileDescriptor(project, targetClass.containingFile.virtualFile) val targetEditor = FileEditorManager.getInstance(project).openTextEditor(descriptor, true)!! when (newJavaMember) { is PsiMethod -> CreateFromUsageUtils.setupEditor(newJavaMember, targetEditor) - is PsiField -> targetEditor.getCaretModel().moveToOffset(newJavaMember.endOffset - 1) + is PsiField -> targetEditor.caretModel.moveToOffset(newJavaMember.endOffset - 1) is PsiClass -> { - val constructor = newJavaMember.getConstructors().firstOrNull() - val superStatement = constructor?.getBody()?.getStatements()?.firstOrNull() as? PsiExpressionStatement - val superCall = superStatement?.getExpression() as? PsiMethodCallExpression + val constructor = newJavaMember.constructors.firstOrNull() + val superStatement = constructor?.body?.statements?.firstOrNull() as? PsiExpressionStatement + val superCall = superStatement?.expression as? PsiMethodCallExpression if (superCall != null) { - val lParen = superCall.getArgumentList().getFirstChild() - targetEditor.getCaretModel().moveToOffset(lParen.endOffset) + val lParen = superCall.argumentList.firstChild + targetEditor.caretModel.moveToOffset(lParen.endOffset) } else { - targetEditor.getCaretModel().moveToOffset(newJavaMember.startOffset) + targetEditor.caretModel.moveToOffset(newJavaMember.startOffset) } } } - targetEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE) + targetEditor.scrollingModel.scrollToCaret(ScrollType.RELATIVE) return true } @@ -918,8 +916,8 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { val defaultValueType = typeCandidates[callableInfo.returnTypeInfo]!!.firstOrNull()?.theType val defaultValue = defaultValueType?.let { CodeInsightUtils.defaultInitializer(it) } ?: "null" val initializer = declaration.setInitializer(KtPsiFactory(declaration).createExpression(defaultValue))!! - val range = initializer.getTextRange() - containingFileEditor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset()) + val range = initializer.textRange + containingFileEditor.selectionModel.setSelection(range.startOffset, range.endOffset) return } setupEditorSelection(containingFileEditor, declaration) @@ -928,17 +926,17 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { // build templates fun buildAndRunTemplate(onFinish: () -> Unit) { val declarationSkeleton = createDeclarationSkeleton() - val project = declarationSkeleton.getProject() + val project = declarationSkeleton.project val declarationPointer = SmartPointerManager.getInstance(project).createSmartPsiElementPointer(declarationSkeleton) // build templates PsiDocumentManager.getInstance(project).commitAllDocuments() - PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(containingFileEditor.getDocument()) + PsiDocumentManager.getInstance(project).doPostponedOperationsAndUnblockDocument(containingFileEditor.document) - val caretModel = containingFileEditor.getCaretModel() - caretModel.moveToOffset(jetFileToEdit.getNode().getStartOffset()) + val caretModel = containingFileEditor.caretModel + caretModel.moveToOffset(jetFileToEdit.node.startOffset) - val declaration = declarationPointer.getElement()!! + val declaration = declarationPointer.element!! val declarationMarker = containingFileEditor.document.createRangeMarker(declaration.textRange) @@ -961,26 +959,26 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { // the template built by TemplateBuilderImpl is ordered by element position, but we want types to be first, so hack it val templateImpl = builder.buildInlineTemplate() as TemplateImpl - val variables = templateImpl.getVariables()!! + val variables = templateImpl.variables!! if (variables.isNotEmpty()) { - val typeParametersVar = if (expression != null) variables.remove(0) else null - for (i in 0..(callableInfo.parameterInfos.size() - 1)) { + val typeParametersVar = if (expression != null) variables.removeAt(0) else null + for (i in 0..(callableInfo.parameterInfos.size - 1)) { Collections.swap(variables, i * 2, i * 2 + 1) } typeParametersVar?.let { variables.add(it) } } // TODO: Disabled shortening names because it causes some tests fail. Refactor code to use automatic reference shortening - templateImpl.setToShortenLongNames(false) + templateImpl.isToShortenLongNames = false // run the template TemplateManager.getInstance(project).startTemplate(containingFileEditor, templateImpl, object : TemplateEditingAdapter() { private fun finishTemplate(brokenOff: Boolean) { try { - PsiDocumentManager.getInstance(project).commitDocument(containingFileEditor.getDocument()) + PsiDocumentManager.getInstance(project).commitDocument(containingFileEditor.document) dialogWithEditor?.close(DialogWrapper.OK_EXIT_CODE) - if (brokenOff && !ApplicationManager.getApplication().isUnitTestMode()) return + if (brokenOff && !ApplicationManager.getApplication().isUnitTestMode) return // file templates val newDeclaration = PsiTreeUtil.findElementOfClassAtOffset(jetFileToEdit, @@ -1025,7 +1023,7 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { } fun showDialogIfNeeded() { - if (!ApplicationManager.getApplication().isUnitTestMode() && dialogWithEditor != null && !finished) { + if (!ApplicationManager.getApplication().isUnitTestMode && dialogWithEditor != null && !finished) { dialogWithEditor.show() } } @@ -1034,9 +1032,9 @@ class CallableBuilder(val config: CallableBuilderConfiguration) { internal fun KtNamedDeclaration.getReturnTypeReference(): KtTypeReference? { return when (this) { - is KtCallableDeclaration -> getTypeReference() - is KtClassOrObject -> getSuperTypeListEntries().firstOrNull()?.getTypeReference() - else -> throw AssertionError("Unexpected declaration kind: ${getText()}") + is KtCallableDeclaration -> typeReference + is KtClassOrObject -> getSuperTypeListEntries().firstOrNull()?.typeReference + else -> throw AssertionError("Unexpected declaration kind: $text") } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableInfo.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableInfo.kt index 10213b5f78c..e55ef153303 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableInfo.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/CallableInfo.kt @@ -18,7 +18,6 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder import com.intellij.psi.PsiElement import com.intellij.util.ArrayUtil -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.idea.core.KotlinNameSuggester import org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass.ClassInfo import org.jetbrains.kotlin.psi.KtElement diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/templateExpressions.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/templateExpressions.kt index 4df7bcb0633..d25f64563c7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/templateExpressions.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/templateExpressions.kt @@ -48,7 +48,7 @@ internal class ParameterNameExpression( override fun calculateResult(context: ExpressionContext?): Result? { val lookupItems = calculateLookupItems(context)!! - return TextResult(if (lookupItems.isEmpty()) "" else lookupItems.first().getLookupString()) + return TextResult(if (lookupItems.isEmpty()) "" else lookupItems.first().lookupString) } override fun calculateQuickResult(context: ExpressionContext?) = calculateResult(context) @@ -58,25 +58,25 @@ internal class ParameterNameExpression( val names = LinkedHashSet(this.names.toList()) // find the parameter list - val project = context.getProject()!! - val offset = context.getStartOffset() + val project = context.project!! + val offset = context.startOffset PsiDocumentManager.getInstance(project).commitAllDocuments() - val editor = context.getEditor()!! - val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument()) as KtFile + val editor = context.editor!! + val file = PsiDocumentManager.getInstance(project).getPsiFile(editor.document) as KtFile val elementAt = file.findElementAt(offset) - val declaration = PsiTreeUtil.getParentOfType(elementAt, javaClass(), javaClass()) ?: return arrayOf() + val declaration = PsiTreeUtil.getParentOfType(elementAt, KtFunction::class.java, KtClass::class.java) ?: return arrayOf() val parameterList = when (declaration) { - is KtFunction -> declaration.getValueParameterList()!! + is KtFunction -> declaration.valueParameterList!! is KtClass -> declaration.getPrimaryConstructorParameterList()!! - else -> throw AssertionError("Unexpected declaration: ${declaration.getText()}") + else -> throw AssertionError("Unexpected declaration: ${declaration.text}") } // add names based on selected type val parameter = elementAt?.getStrictParentOfType() if (parameter != null) { - val parameterTypeRef = parameter.getTypeReference() + val parameterTypeRef = parameter.typeReference if (parameterTypeRef != null) { - val suggestedNamesBasedOnType = parameterTypeToNamesMap[parameterTypeRef.getText()] + val suggestedNamesBasedOnType = parameterTypeToNamesMap[parameterTypeRef.text] if (suggestedNamesBasedOnType != null) { names.addAll(suggestedNamesBasedOnType) } @@ -84,8 +84,8 @@ internal class ParameterNameExpression( } // remember other parameter names for later use - val parameterNames = parameterList.getParameters().mapNotNullTo(HashSet()) { jetParameter -> - if (jetParameter == parameter) null else jetParameter.getName() + val parameterNames = parameterList.parameters.mapNotNullTo(HashSet()) { jetParameter -> + if (jetParameter == parameter) null else jetParameter.name } // add fallback parameter name @@ -111,8 +111,8 @@ internal abstract class TypeExpression(public val typeCandidates: List) : TypeExpression(typeCandidates) { override val cachedLookupElements: Array = typeCandidates.map { - val descriptor = it.theType.getConstructor().getDeclarationDescriptor() as ClassDescriptor - val text = it.renderedType!! + if (descriptor.getKind() == ClassKind.INTERFACE) "" else "()" + val descriptor = it.theType.constructor.declarationDescriptor as ClassDescriptor + val text = it.renderedType!! + if (descriptor.kind == ClassKind.INTERFACE) "" else "()" LookupElementBuilder.create(it, text) }.toTypedArray() } @@ -121,7 +121,7 @@ internal abstract class TypeExpression(public val typeCandidates: List() ?: return TextResult("") val renderedTypeParameters = LinkedHashSet() renderedTypeParameters.addAll(mandatoryTypeParameters) for (parameter in declaration.getValueParameters()) { - val parameterTypeRef = parameter.getTypeReference() + val parameterTypeRef = parameter.typeReference if (parameterTypeRef != null) { - val typeParameterNamesFromParameter = parameterTypeToTypeParameterNamesMap[parameterTypeRef.getText()] + val typeParameterNamesFromParameter = parameterTypeToTypeParameterNamesMap[parameterTypeRef.text] if (typeParameterNamesFromParameter != null) { renderedTypeParameters.addAll(typeParameterNamesFromParameter) } @@ -164,14 +164,14 @@ internal class TypeParameterListExpression(private val mandatoryTypeParameters: } val returnTypeRef = declaration.getReturnTypeReference() if (returnTypeRef != null) { - val typeParameterNamesFromReturnType = parameterTypeToTypeParameterNamesMap[returnTypeRef.getText()] + val typeParameterNamesFromReturnType = parameterTypeToTypeParameterNamesMap[returnTypeRef.text] if (typeParameterNamesFromReturnType != null) { renderedTypeParameters.addAll(typeParameterNamesFromReturnType) } } - val sortedRenderedTypeParameters = renderedTypeParameters.sortedBy { if (it.fake) it.typeParameter.getIndex() else -1 } + val sortedRenderedTypeParameters = renderedTypeParameters.sortedBy { if (it.fake) it.typeParameter.index else -1 } currentTypeParameters = sortedRenderedTypeParameters.map { it.typeParameter } return TextResult( diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt index c08020e780f..79e65fb3ede 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/callableBuilder/typeUtils.kt @@ -43,7 +43,7 @@ import org.jetbrains.kotlin.types.typeUtil.makeNotNullable import java.util.* internal operator fun KotlinType.contains(inner: KotlinType): Boolean { - return KotlinTypeChecker.DEFAULT.equalTypes(this, inner) || getArguments().any { inner in it.getType() } + return KotlinTypeChecker.DEFAULT.equalTypes(this, inner) || arguments.any { inner in it.type } } private fun KotlinType.render(typeParameterNameMap: Map, fq: Boolean): String { @@ -122,7 +122,7 @@ fun KtExpression.guessTypes( if (coerceUnusedToUnit && this !is KtDeclaration && isUsedAsStatement(context) - && getNonStrictParentOfType() == null) return arrayOf(module.builtIns.getUnitType()) + && getNonStrictParentOfType() == null) return arrayOf(module.builtIns.unitType) // if we know the actual type of the expression val theType1 = context.getType(this) @@ -136,21 +136,21 @@ fun KtExpression.guessTypes( val theType2 = context[BindingContext.EXPECTED_EXPRESSION_TYPE, this] if (theType2 != null) return arrayOf(theType2) - val parent = getParent() + val parent = parent return when { this is KtTypeConstraint -> { // expression itself is a type assertion val constraint = this - arrayOf(context[BindingContext.TYPE, constraint.getBoundTypeReference()]!!) + arrayOf(context[BindingContext.TYPE, constraint.boundTypeReference]!!) } parent is KtTypeConstraint -> { // expression is on the left side of a type assertion val constraint = parent - arrayOf(context[BindingContext.TYPE, constraint.getBoundTypeReference()]!!) + arrayOf(context[BindingContext.TYPE, constraint.boundTypeReference]!!) } this is KtDestructuringDeclarationEntry -> { // expression is on the lhs of a multi-declaration - val typeRef = getTypeReference() + val typeRef = typeReference if (typeRef != null) { // and has a specified type arrayOf(context[BindingContext.TYPE, typeRef]!!) @@ -162,7 +162,7 @@ fun KtExpression.guessTypes( } this is KtParameter -> { // expression is a parameter (e.g. declared in a for-loop) - val typeRef = getTypeReference() + val typeRef = typeReference if (typeRef != null) { // and has a specified type arrayOf(context[BindingContext.TYPE, typeRef]!!) @@ -172,10 +172,10 @@ fun KtExpression.guessTypes( guessType(context) } } - parent is KtProperty && parent.isLocal() -> { + parent is KtProperty && parent.isLocal -> { // the expression is the RHS of a variable assignment with a specified type val variable = parent - val typeRef = variable.getTypeReference() + val typeRef = variable.typeReference if (typeRef != null) { // and has a specified type arrayOf(context[BindingContext.TYPE, typeRef]!!) @@ -186,17 +186,17 @@ fun KtExpression.guessTypes( } } parent is KtPropertyDelegate -> { - val variableDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, parent.getParent() as KtProperty] as VariableDescriptor - val delegateClassName = if (variableDescriptor.isVar()) "ReadWriteProperty" else "ReadOnlyProperty" + val variableDescriptor = context[BindingContext.DECLARATION_TO_DESCRIPTOR, parent.parent as KtProperty] as VariableDescriptor + val delegateClassName = if (variableDescriptor.isVar) "ReadWriteProperty" else "ReadOnlyProperty" val delegateClass = module.resolveTopLevelClass(FqName("kotlin.properties.$delegateClassName"), NoLookupLocation.FROM_IDE) - ?: return arrayOf(module.builtIns.getAnyType()) - val receiverType = (variableDescriptor.getExtensionReceiverParameter() ?: variableDescriptor.getDispatchReceiverParameter())?.getType() - ?: module.builtIns.getNullableNothingType() - val typeArguments = listOf(TypeProjectionImpl(receiverType), TypeProjectionImpl(variableDescriptor.getType())) + ?: return arrayOf(module.builtIns.anyType) + val receiverType = (variableDescriptor.extensionReceiverParameter ?: variableDescriptor.dispatchReceiverParameter)?.type + ?: module.builtIns.nullableNothingType + val typeArguments = listOf(TypeProjectionImpl(receiverType), TypeProjectionImpl(variableDescriptor.type)) arrayOf(TypeUtils.substituteProjectionsForParameters(delegateClass, typeArguments)) } - parent is KtStringTemplateEntryWithExpression && parent.getExpression() == this -> { - arrayOf(module.builtIns.getStringType()) + parent is KtStringTemplateEntryWithExpression && parent.expression == this -> { + arrayOf(module.builtIns.stringType) } else -> { pseudocode?.getElementValue(this)?.let { @@ -207,7 +207,7 @@ fun KtExpression.guessTypes( } private fun KtNamedDeclaration.guessType(context: BindingContext): Array { - val expectedTypes = SearchUtils.findAllReferences(this, getUseScope())!!.mapNotNullTo(HashSet()) { ref -> + val expectedTypes = SearchUtils.findAllReferences(this, useScope)!!.mapNotNullTo(HashSet()) { ref -> if (ref is KtSimpleNameReference) { context[BindingContext.EXPECTED_EXPRESSION_TYPE, ref.expression] } @@ -235,7 +235,7 @@ private fun KtNamedDeclaration.guessType(context: BindingContext): Array + val newArguments = arguments.zip(constructor.parameters).map { pair -> val (projection, typeParameter) = pair - TypeProjectionImpl(Variance.INVARIANT, projection.getType().substitute(substitution, typeParameter.getVariance())) + TypeProjectionImpl(Variance.INVARIANT, projection.type.substitute(substitution, typeParameter.variance)) } - return KotlinTypeImpl.create(getAnnotations(), getConstructor(), isMarkedNullable(), newArguments, getMemberScope()) + return KotlinTypeImpl.create(annotations, constructor, isMarkedNullable, newArguments, memberScope) } } -fun KtExpression.getExpressionForTypeGuess() = getAssignmentByLHS()?.getRight() ?: this +fun KtExpression.getExpressionForTypeGuess() = getAssignmentByLHS()?.right ?: this fun KtCallElement.getTypeInfoForTypeArguments(): List { - return getTypeArguments().mapNotNull { it.getTypeReference()?.let { TypeInfo(it, Variance.INVARIANT) } } + return typeArguments.mapNotNull { it.typeReference?.let { TypeInfo(it, Variance.INVARIANT) } } } fun KtCallExpression.getParameterInfos(): List { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt index 222cec93896..209789ed28f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromCallActionFactory.kt @@ -64,7 +64,7 @@ sealed class CreateCallableFromCallActionFactory( val diagElement = diagnostic.psiElement if (PsiTreeUtil.getParentOfType( diagElement, - javaClass(), javaClass(), javaClass() + KtTypeReference::class.java, KtAnnotationEntry::class.java, KtImportDirective::class.java ) != null) return null return when (diagnostic.factory) { @@ -108,9 +108,9 @@ sealed class CreateCallableFromCallActionFactory( } private fun getReceiverTypeInfo(context: BindingContext, project: Project, receiver: Receiver?): TypeInfo? { - return when { - receiver == null -> TypeInfo.Empty - receiver is Qualifier -> { + return when (receiver) { + null -> TypeInfo.Empty + is Qualifier -> { val qualifierType = context.getType(receiver.expression) if (qualifierType != null) return TypeInfo(qualifierType, Variance.IN_VARIANCE) @@ -123,7 +123,7 @@ sealed class CreateCallableFromCallActionFactory( if (javaClass == null || !javaClass.canRefactor()) return null TypeInfo.StaticContextRequired(TypeInfo(javaClassifier.defaultType, Variance.IN_VARIANCE)) } - receiver is ReceiverValue -> TypeInfo(receiver.type, Variance.IN_VARIANCE) + is ReceiverValue -> TypeInfo(receiver.type, Variance.IN_VARIANCE) else -> throw AssertionError("Unexpected receiver: $receiver") } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromUsageFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromUsageFix.kt index aff72f161e7..2f0191669de 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromUsageFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateCallableFromUsageFix.kt @@ -52,12 +52,12 @@ public abstract class CreateCallableFromUsageFixBase( ) : CreateFromUsageFixBase(originalExpression) { init { assert (callableInfos.isNotEmpty()) { "No CallableInfos: ${originalExpression.getElementTextWithContext()}" } - if (callableInfos.size() > 1) { + if (callableInfos.size > 1) { val receiverSet = callableInfos.mapTo(HashSet()) { it.receiverTypeInfo } - if (receiverSet.size() > 1) throw AssertionError("All functions must have common receiver: $receiverSet") + if (receiverSet.size > 1) throw AssertionError("All functions must have common receiver: $receiverSet") val possibleContainerSet = callableInfos.mapTo(HashSet>()) { it.possibleContainers } - if (possibleContainerSet.size() > 1) throw AssertionError("All functions must have common containers: $possibleContainerSet") + if (possibleContainerSet.size > 1) throw AssertionError("All functions must have common containers: $possibleContainerSet") } } @@ -88,7 +88,7 @@ public abstract class CreateCallableFromUsageFixBase( if (it.name.isNotEmpty()) "$kind '${it.name}'" else kind } - return StringBuilder { + return StringBuilder().apply { append("Create ") val receiverInfo = callableInfos.first().receiverTypeInfo diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateComponentFunctionActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateComponentFunctionActionFactory.kt index b2e691a02ac..f05763fb689 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateComponentFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateComponentFunctionActionFactory.kt @@ -30,8 +30,8 @@ import org.jetbrains.kotlin.types.Variance object CreateComponentFunctionActionFactory : CreateCallableMemberFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtDestructuringDeclaration? { - QuickFixUtil.getParentElementOfType(diagnostic, javaClass())?.let { return it } - return QuickFixUtil.getParentElementOfType(diagnostic, javaClass())?.destructuringParameter + QuickFixUtil.getParentElementOfType(diagnostic, KtDestructuringDeclaration::class.java)?.let { return it } + return QuickFixUtil.getParentElementOfType(diagnostic, KtForExpression::class.java)?.destructuringParameter } override fun createCallableInfo(element: KtDestructuringDeclaration, diagnostic: Diagnostic): CallableInfo? { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegationCallActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegationCallActionFactory.kt index d66cb017a89..ee2e3cdb15f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegationCallActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateConstructorFromDelegationCallActionFactory.kt @@ -17,17 +17,16 @@ 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 import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde -import org.jetbrains.kotlin.idea.refactoring.canRefactor import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.CallableInfo import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.ParameterInfo import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.SecondaryConstructorInfo import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo +import org.jetbrains.kotlin.idea.refactoring.canRefactor import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtConstructorDelegationCall import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateGetFunctionActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateGetFunctionActionFactory.kt index b064ebfadba..9b66fb63004 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateGetFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateGetFunctionActionFactory.kt @@ -28,7 +28,7 @@ import java.util.Collections object CreateGetFunctionActionFactory : CreateCallableMemberFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtArrayAccessExpression? { - return QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) + return QuickFixUtil.getParentElementOfType(diagnostic, KtArrayAccessExpression::class.java) } override fun createCallableInfo(element: KtArrayAccessExpression, diagnostic: Diagnostic): CallableInfo? { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateHasNextFunctionActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateHasNextFunctionActionFactory.kt index b3c94343287..010a167012e 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateHasNextFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateHasNextFunctionActionFactory.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions object CreateHasNextFunctionActionFactory : CreateCallableMemberFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtForExpression? { - return QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) + return QuickFixUtil.getParentElementOfType(diagnostic, KtForExpression::class.java) } override fun createCallableInfo(element: KtForExpression, diagnostic: Diagnostic): CallableInfo? { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateIteratorFunctionActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateIteratorFunctionActionFactory.kt index 73ad3939e7a..8e1382edebc 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateIteratorFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateIteratorFunctionActionFactory.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createCallable -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.core.quickfix.QuickFixUtil @@ -35,7 +34,7 @@ import java.util.* object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtForExpression? { - return QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) + return QuickFixUtil.getParentElementOfType(diagnostic, KtForExpression::class.java) } override fun createCallableInfo(element: KtForExpression, diagnostic: Diagnostic): CallableInfo? { @@ -48,7 +47,7 @@ object CreateIteratorFunctionActionFactory : CreateCallableMemberFromUsageFactor val returnJetType = moduleDescriptor.builtIns.iterator.defaultType val returnJetTypeParameterTypes = variableExpr.guessTypes(bindingContext, moduleDescriptor) - if (returnJetTypeParameterTypes.size() != 1) return null + if (returnJetTypeParameterTypes.size != 1) return null val returnJetTypeParameterType = TypeProjectionImpl(returnJetTypeParameterTypes[0]) val returnJetTypeArguments = Collections.singletonList(returnJetTypeParameterType) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateNextFunctionActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateNextFunctionActionFactory.kt index 28a6acc8e20..0acff220f9f 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateNextFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateNextFunctionActionFactory.kt @@ -30,7 +30,7 @@ import org.jetbrains.kotlin.util.OperatorNameConventions object CreateNextFunctionActionFactory : CreateCallableMemberFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtForExpression? { - return QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) + return QuickFixUtil.getParentElementOfType(diagnostic, KtForExpression::class.java) } override fun createCallableInfo(element: KtForExpression, diagnostic: Diagnostic): CallableInfo? { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateSetFunctionActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateSetFunctionActionFactory.kt index 11aa7d8f108..21e76b0a40a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateSetFunctionActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createCallable/CreateSetFunctionActionFactory.kt @@ -36,7 +36,7 @@ import java.util.* object CreateSetFunctionActionFactory : CreateCallableMemberFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtArrayAccessExpression? { - return QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) + return QuickFixUtil.getParentElementOfType(diagnostic, KtArrayAccessExpression::class.java) } override fun createCallableInfo(element: KtArrayAccessExpression, diagnostic: Diagnostic): CallableInfo? { @@ -48,7 +48,7 @@ object CreateSetFunctionActionFactory : CreateCallableMemberFromUsageFactory()) { ParameterInfo(TypeInfo(it, Variance.IN_VARIANCE)) } - val assignmentExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null + val assignmentExpr = QuickFixUtil.getParentElementOfType(diagnostic, KtOperationExpression::class.java) ?: return null val valType = when (assignmentExpr) { is KtBinaryExpression -> { TypeInfo(assignmentExpr.right ?: return null, Variance.IN_VARIANCE) diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromCallWithConstructorCalleeActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromCallWithConstructorCalleeActionFactory.kt index 0492e95892d..8ed60a0c1d9 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromCallWithConstructorCalleeActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromCallWithConstructorCalleeActionFactory.kt @@ -34,8 +34,8 @@ public object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClas val callElement = PsiTreeUtil.getParentOfType( diagElement, - javaClass(), - javaClass() + KtAnnotationEntry::class.java, + KtSuperTypeCallEntry::class.java ) as? KtCallElement ?: return null val callee = callElement.calleeExpression as? KtConstructorCalleeExpression ?: return null @@ -66,7 +66,7 @@ public object CreateClassFromCallWithConstructorCalleeActionFactory : CreateClas val anyType = module.builtIns.nullableAnyType val valueArguments = element.valueArguments - val defaultParamName = if (valueArguments.size() == 1) "value" else null + val defaultParamName = if (valueArguments.size == 1) "value" else null val parameterInfos = valueArguments.map { ParameterInfo( it.getArgumentExpression()?.let { TypeInfo(it, Variance.IN_VARIANCE) } ?: TypeInfo(anyType, Variance.IN_VARIANCE), diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromConstructorCallActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromConstructorCallActionFactory.kt index a1c77ec0cea..744ca99531b 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromConstructorCallActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromConstructorCallActionFactory.kt @@ -16,7 +16,6 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass -import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.diagnostics.Diagnostic import org.jetbrains.kotlin.idea.caches.resolve.analyzeFullyAndGetResult import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.ParameterInfo @@ -28,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getQualifiedExpressionForSelectorOrThis import org.jetbrains.kotlin.resolve.calls.callUtil.getCall import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.utils.addToStdlib.singletonList -import java.util.Collections +import java.util.* public object CreateClassFromConstructorCallActionFactory: CreateClassFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtCallExpression? { @@ -81,7 +80,7 @@ public object CreateClassFromConstructorCallActionFactory: CreateClassFromUsageF val inner = isInnerClassExpected(call) val valueArguments = callExpr.valueArguments - val defaultParamName = if (inAnnotationEntry && valueArguments.size() == 1) "value" else null + val defaultParamName = if (inAnnotationEntry && valueArguments.size == 1) "value" else null val anyType = moduleDescriptor.builtIns.nullableAnyType val parameterInfos = valueArguments.map { ParameterInfo( diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt index 3f880e82a78..94304e74bf6 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromTypeReferenceActionFactory.kt @@ -16,23 +16,21 @@ package org.jetbrains.kotlin.idea.quickfix.createFromUsage.createClass -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.core.quickfix.QuickFixUtil import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.TypeInfo import org.jetbrains.kotlin.psi.KtConstructorCalleeExpression -import org.jetbrains.kotlin.psi.KtSuperTypeEntry import org.jetbrains.kotlin.psi.KtFile +import org.jetbrains.kotlin.psi.KtSuperTypeEntry import org.jetbrains.kotlin.psi.KtUserType import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.types.Variance -import java.util.Collections +import java.util.* public object CreateClassFromTypeReferenceActionFactory : CreateClassFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtUserType? { - return QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) + return QuickFixUtil.getParentElementOfType(diagnostic, KtUserType::class.java) } override fun getPossibleClassKinds(element: KtUserType, diagnostic: Diagnostic): List { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromUsageFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromUsageFix.kt index 384fdbe0c5e..5b4101ffeb7 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromUsageFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/CreateClassFromUsageFix.kt @@ -87,7 +87,7 @@ public class CreateClassFromUsageFix( directories.firstOrNull { ModuleUtilCore.findModuleForPsiElement(it) == currentModule } ?: directories.firstOrNull() - val targetDirectory = if (directories.size() > 1 && !ApplicationManager.getApplication().isUnitTestMode) { + val targetDirectory = if (directories.size > 1 && !ApplicationManager.getApplication().isUnitTestMode) { DirectoryChooserUtil.chooseDirectory(directories.toTypedArray(), preferredDirectory, project, HashMap()) } else { diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/createClassUtils.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/createClassUtils.kt index 11d3e4380a2..0cb3b524c6a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/createClassUtils.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createClass/createClassUtils.kt @@ -51,44 +51,44 @@ internal fun getTargetParentByQualifier( file: KtFile, isQualified: Boolean, qualifierDescriptor: DeclarationDescriptor?): PsiElement? { - val project = file.getProject() - val targetParent: PsiElement = when { + val project = file.project + val targetParent: PsiElement? = when { !isQualified -> file qualifierDescriptor is ClassDescriptor -> DescriptorToSourceUtilsIde.getAnyDeclaration(project, qualifierDescriptor) qualifierDescriptor is PackageViewDescriptor -> - if (qualifierDescriptor.fqName != file.getPackageFqName()) { + if (qualifierDescriptor.fqName != file.packageFqName) { JavaPsiFacade.getInstance(project).findPackage(qualifierDescriptor.fqName.asString()) } - else file as PsiElement // KT-9972 + else file // KT-9972 else -> null - } ?: return null - return if (targetParent.canRefactor()) return targetParent else null + } + return if (targetParent?.canRefactor() ?: false) return targetParent else null } internal fun getTargetParentByCall(call: Call, file: KtFile, context: BindingContext): PsiElement? { - val receiver = call.getExplicitReceiver() + val receiver = call.explicitReceiver return when (receiver) { null -> getTargetParentByQualifier(file, false, null) is Qualifier -> getTargetParentByQualifier(file, true, context[BindingContext.REFERENCE_TARGET, receiver.referenceExpression]) - is ReceiverValue -> getTargetParentByQualifier(file, true, receiver.getType().getConstructor().getDeclarationDescriptor()) + is ReceiverValue -> getTargetParentByQualifier(file, true, receiver.type.constructor.declarationDescriptor) else -> throw AssertionError("Unexpected receiver: $receiver") } } -internal fun isInnerClassExpected(call: Call) = call.getExplicitReceiver() is ReceiverValue +internal fun isInnerClassExpected(call: Call) = call.explicitReceiver is ReceiverValue internal fun KtExpression.getInheritableTypeInfo( context: BindingContext, moduleDescriptor: ModuleDescriptor, containingDeclaration: PsiElement): Pair Boolean> { val types = guessTypes(context, moduleDescriptor, coerceUnusedToUnit = false) - if (types.size() != 1) return TypeInfo.Empty to { classKind -> true } + if (types.size != 1) return TypeInfo.Empty to { classKind -> true } val type = types.first() - val descriptor = type.getConstructor().getDeclarationDescriptor() ?: return TypeInfo.Empty to { classKind -> false } + val descriptor = type.constructor.declarationDescriptor ?: return TypeInfo.Empty to { classKind -> false } val canHaveSubtypes = !(type.constructor.isFinal || type.containsStarProjections()) val isEnum = DescriptorUtils.isEnumClass(descriptor) @@ -100,7 +100,7 @@ internal fun KtExpression.getInheritableTypeInfo( when (classKind) { ClassKind.ENUM_ENTRY -> isEnum && containingDeclaration == DescriptorToSourceUtils.descriptorToDeclaration(descriptor) ClassKind.INTERFACE -> containingDeclaration !is PsiClass - || (descriptor as? ClassDescriptor)?.getKind() == ClassDescriptorKind.INTERFACE + || (descriptor as? ClassDescriptor)?.kind == ClassDescriptorKind.INTERFACE else -> canHaveSubtypes } } @@ -110,21 +110,22 @@ internal fun KtSimpleNameExpression.getCreatePackageFixIfApplicable(targetParent val name = getReferencedName() if (!name.checkPackageName()) return null - val basePackage: PsiPackage? = when (targetParent) { - is KtFile -> JavaPsiFacade.getInstance(targetParent.getProject()).findPackage(targetParent.getPackageFqName().asString()) - is PsiPackage -> targetParent - else -> null - } + val basePackage: PsiPackage? = + when (targetParent) { + is KtFile -> JavaPsiFacade.getInstance(targetParent.project).findPackage(targetParent.packageFqName.asString()) + is PsiPackage -> targetParent + else -> null + } if (basePackage == null) return null - val baseName = basePackage.getQualifiedName() + val baseName = basePackage.qualifiedName val fullName = if (baseName.isNotEmpty()) "$baseName.$name" else name - val javaFix = CreateClassOrPackageFix.createFix(fullName, getResolveScope(), this, basePackage, null, null, null) ?: return null + val javaFix = CreateClassOrPackageFix.createFix(fullName, resolveScope, this, basePackage, null, null, null) ?: return null return object: DelegatingIntentionAction(javaFix) { override fun getFamilyName(): String = KotlinBundle.message("create.from.usage.family") - override fun getText(): String = "Create package '${fullName}'" + override fun getText(): String = "Create package '$fullName'" } } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt index 3bd2239c343..e3d2fbd085c 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateLocalVariableActionFactory.kt @@ -38,7 +38,7 @@ import java.util.* object CreateLocalVariableActionFactory: KotlinSingleIntentionActionFactory() { override fun createAction(diagnostic: Diagnostic): IntentionAction? { - val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null + val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, KtNameReferenceExpression::class.java) ?: return null if (refExpr.getQualifiedElement() != refExpr) return null if (refExpr.getParentOfTypeAndBranch { callableReference } != null) return null diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByNamedArgumentActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByNamedArgumentActionFactory.kt index 4b1340ec0d3..e70dec384f1 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByNamedArgumentActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByNamedArgumentActionFactory.kt @@ -32,7 +32,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns public object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtValueArgument? { - val argument = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null + val argument = QuickFixUtil.getParentElementOfType(diagnostic, KtValueArgument::class.java) ?: return null return if (argument.isNamed()) argument else null } @@ -50,7 +50,7 @@ public object CreateParameterByNamedArgumentActionFactory: CreateParameterFromUs val anyType = functionDescriptor.builtIns.anyType val paramType = argumentExpression?.guessTypes(context, result.moduleDescriptor)?.let { - when (it.size()) { + when (it.size) { 0 -> anyType 1 -> it.first() else -> return null diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt index d387f7518f3..d8c343e3c38 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/createFromUsage/createVariable/CreateParameterByRefActionFactory.kt @@ -44,7 +44,7 @@ import java.util.* object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory() { override fun getElementOfInterest(diagnostic: Diagnostic): KtSimpleNameExpression? { - val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, javaClass()) ?: return null + val refExpr = QuickFixUtil.getParentElementOfType(diagnostic, KtNameReferenceExpression::class.java) ?: return null if (refExpr.getQualifiedElement() != refExpr) return null if (refExpr.getParentOfTypeAndBranch { callableReference } != null) return null return refExpr @@ -58,7 +58,7 @@ object CreateParameterByRefActionFactory : CreateParameterFromUsageFactory moduleDescriptor.builtIns.anyType 1 -> it.first() else -> return null diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/quickfixUtil/quickfixUtil.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/quickfixUtil/quickfixUtil.kt index 050db6ed730..1474faebc01 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/quickfixUtil/quickfixUtil.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/quickfixUtil/quickfixUtil.kt @@ -27,7 +27,7 @@ import org.jetbrains.kotlin.psi.psiUtil.getNonStrictParentOfType inline fun Diagnostic.createIntentionForFirstParentOfType( factory: (T) -> KotlinQuickFixAction? -) = getPsiElement().getNonStrictParentOfType()?.let(factory) +) = psiElement.getNonStrictParentOfType()?.let(factory) fun createIntentionFactory( @@ -38,5 +38,5 @@ fun createIntentionFactory( public fun KtPrimaryConstructor.addConstructorKeyword(): PsiElement? { val keyword = KtPsiFactory(this).createConstructorKeyword() - return addAfter(keyword, getModifierList() ?: return null) + return addAfter(keyword, modifierList ?: return null) } diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/CallableUsageReplacementStrategy.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/CallableUsageReplacementStrategy.kt index 36dce4f1362..e3f12afc016 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/CallableUsageReplacementStrategy.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/CallableUsageReplacementStrategy.kt @@ -208,7 +208,7 @@ private fun ConstructedExpressionWrapper.processValueParameterUsages( //TODO: sometimes we need to add explicit type arguments here because we don't have expected type in the new context - if (argument.expression.shouldKeepValue(usages.size())) { + if (argument.expression.shouldKeepValue(usages.size)) { introduceValuesForParameters.add(IntroduceValueForParameter(parameter, argument.expression, argument.expressionType)) } } @@ -227,7 +227,7 @@ private fun ConstructedExpressionWrapper.processTypeParameterUsages(resolvedCall val callElement = resolvedCall.call.callElement val callExpression = callElement as? KtCallExpression val explicitTypeArgs = callExpression?.typeArgumentList?.arguments - if (explicitTypeArgs != null && explicitTypeArgs.size() != typeParameters.size()) return + if (explicitTypeArgs != null && explicitTypeArgs.size != typeParameters.size) return for ((index, typeParameter) in typeParameters.withIndex()) { val parameterName = typeParameter.name diff --git a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageInWholeProjectFix.kt b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageInWholeProjectFix.kt index 8dfe9db3704..8aa44c3687d 100644 --- a/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageInWholeProjectFix.kt +++ b/idea/src/org/jetbrains/kotlin/idea/quickfix/replaceWith/DeprecatedSymbolUsageInWholeProjectFix.kt @@ -100,7 +100,7 @@ public class DeprecatedSymbolUsageInWholeProjectFix( //TODO: keep the import if we don't know how to replace some of the usages val importDirective = usage.getStrictParentOfType() if (importDirective != null) { - if (!importDirective.isAllUnder && importDirective.targetDescriptors().size() == 1) { + if (!importDirective.isAllUnder && importDirective.targetDescriptors().size == 1) { importsToDelete.add(importDirective) } continue