Minor: Fix warnings
This commit is contained in:
+6
-6
@@ -63,7 +63,7 @@ public class ExtractKotlinFunctionHandler(
|
||||
public val allContainersEnabled: Boolean = false,
|
||||
private val helper: ExtractKotlinFunctionHandlerHelper = ExtractKotlinFunctionHandlerHelper.DEFAULT) : RefactoringActionHandler {
|
||||
private fun adjustElements(elements: List<PsiElement>): List<PsiElement> {
|
||||
if (elements.size != 1) return elements
|
||||
if (elements.size() != 1) return elements
|
||||
|
||||
val e = elements.first()
|
||||
if (e is JetBlockExpression && e.getParent() is JetFunctionLiteral) return e.getStatements()
|
||||
@@ -108,7 +108,7 @@ public class ExtractKotlinFunctionHandler(
|
||||
}
|
||||
}
|
||||
|
||||
val message = analysisResult.messages.map { it.renderMessage() }.makeString("\n")
|
||||
val message = analysisResult.messages.map { it.renderMessage() }.joinToString("\n")
|
||||
when (analysisResult.status) {
|
||||
Status.CRITICAL_ERROR -> {
|
||||
showErrorHint(project, editor, message)
|
||||
@@ -179,7 +179,7 @@ fun selectElements(
|
||||
|
||||
fun onSelectionComplete(parent: PsiElement, elements: List<PsiElement>, targetContainer: JetElement) {
|
||||
if (parent == targetContainer) {
|
||||
continuation(elements, elements.first!!)
|
||||
continuation(elements, elements.first())
|
||||
return
|
||||
}
|
||||
|
||||
@@ -194,10 +194,10 @@ fun selectElements(
|
||||
|
||||
fun selectTargetContainer(elements: List<PsiElement>) {
|
||||
val parent = PsiTreeUtil.findCommonParent(elements)
|
||||
?: throw AssertionError("Should have at least one parent: ${elements.makeString("\n")}")
|
||||
?: throw AssertionError("Should have at least one parent: ${elements.joinToString("\n")}")
|
||||
|
||||
val containers = parent.getExtractionContainers(elements.size == 1, allContainersEnabled)
|
||||
if (containers.empty) {
|
||||
val containers = parent.getExtractionContainers(elements.size() == 1, allContainersEnabled)
|
||||
if (containers.isEmpty()) {
|
||||
noContainerError()
|
||||
return
|
||||
}
|
||||
|
||||
+11
-10
@@ -176,7 +176,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
|
||||
else -> null
|
||||
}
|
||||
val arguments = call?.getValueArguments()
|
||||
if (arguments == null || arguments.size <= index) return null
|
||||
if (arguments == null || arguments.size() <= index) return null
|
||||
|
||||
return arguments[index].getArgumentExpression()
|
||||
}
|
||||
@@ -195,7 +195,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
|
||||
val module: ModuleDescriptor
|
||||
) : OutputValueBoxer(outputValues) {
|
||||
{
|
||||
assert(outputValues.size <= 3, "At most 3 output values are supported")
|
||||
assert(outputValues.size() <= 3, "At most 3 output values are supported")
|
||||
}
|
||||
|
||||
class object {
|
||||
@@ -204,7 +204,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
|
||||
|
||||
override val returnType: JetType by Delegates.lazy {
|
||||
fun getType(): JetType {
|
||||
val boxingClass = when (outputValues.size) {
|
||||
val boxingClass = when (outputValues.size()) {
|
||||
1 -> return outputValues.first().valueType
|
||||
2 -> ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.Pair")).first()
|
||||
3 -> ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.Triple")).first()
|
||||
@@ -216,10 +216,10 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
|
||||
getType()
|
||||
}
|
||||
|
||||
override val boxingRequired: Boolean = outputValues.size > 1
|
||||
override val boxingRequired: Boolean = outputValues.size() > 1
|
||||
|
||||
override fun getBoxingExpressionText(arguments: List<String>): String? {
|
||||
return when (arguments.size) {
|
||||
return when (arguments.size()) {
|
||||
0 -> null
|
||||
1 -> arguments.first()
|
||||
else -> {
|
||||
@@ -235,7 +235,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
|
||||
}
|
||||
|
||||
override fun getUnboxingExpressions(boxedText: String): Map<OutputValue, String> {
|
||||
return when (outputValues.size) {
|
||||
return when (outputValues.size()) {
|
||||
0 -> Collections.emptyMap()
|
||||
1 -> Collections.singletonMap(outputValues.first(), boxedText)
|
||||
else -> {
|
||||
@@ -255,7 +255,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
|
||||
)
|
||||
}
|
||||
|
||||
override val boxingRequired: Boolean = outputValues.size > 0
|
||||
override val boxingRequired: Boolean = outputValues.size() > 0
|
||||
|
||||
override fun getBoxingExpressionText(arguments: List<String>): String? {
|
||||
if (arguments.isEmpty()) return null
|
||||
@@ -281,14 +281,15 @@ data class ControlFlow(
|
||||
val outputValueBoxer = boxerFactory(outputValues)
|
||||
|
||||
val defaultOutputValue: ExpressionValue? = with(outputValues.filterIsInstance<ExpressionValue>()) {
|
||||
if (size > 1) throw IllegalArgumentException("Multiple expression values: ${outputValues.joinToString()}") else firstOrNull()
|
||||
if (size() > 1) throw IllegalArgumentException("Multiple expression values: ${outputValues.joinToString()}") else firstOrNull()
|
||||
}
|
||||
|
||||
val jumpOutputValue: Jump? = with(outputValues.filterIsInstance<Jump>()) {
|
||||
val jumpCount = size()
|
||||
when {
|
||||
isEmpty() ->
|
||||
null
|
||||
outputValues.size > size || size > 1 ->
|
||||
outputValues.size() > jumpCount || jumpCount > 1 ->
|
||||
throw IllegalArgumentException("Jump values must be the only value if it's present: ${outputValues.joinToString()}")
|
||||
else ->
|
||||
first()
|
||||
@@ -384,7 +385,7 @@ class ExtractableCodeDescriptorWithConflicts(
|
||||
)
|
||||
|
||||
fun ExtractableCodeDescriptor.canGenerateProperty(): Boolean {
|
||||
if (!parameters.empty) return false
|
||||
if (!parameters.isEmpty()) return false
|
||||
if (controlFlow.outputValueBoxer.returnType.isUnit()) return false
|
||||
|
||||
val parent = extractionData.targetSibling.getParent()
|
||||
|
||||
@@ -92,12 +92,12 @@ data class ExtractionData(
|
||||
|
||||
fun getCodeFragmentTextRange(): TextRange? {
|
||||
val originalElements = originalElements
|
||||
return when (originalElements.size) {
|
||||
return when (originalElements.size()) {
|
||||
0 -> null
|
||||
1 -> originalElements.first!!.getTextRange()
|
||||
1 -> originalElements.first().getTextRange()
|
||||
else -> {
|
||||
val from = originalElements.first!!.getTextRange()!!.getStartOffset()
|
||||
val to = originalElements.last!!.getTextRange()!!.getEndOffset()
|
||||
val from = originalElements.first().getTextRange()!!.getStartOffset()
|
||||
val to = originalElements.last().getTextRange()!!.getEndOffset()
|
||||
TextRange(from, to)
|
||||
}
|
||||
}
|
||||
@@ -106,7 +106,7 @@ data class ExtractionData(
|
||||
fun getCodeFragmentText(): String =
|
||||
getCodeFragmentTextRange()?.let { originalFile.getText()?.substring(it.getStartOffset(), it.getEndOffset()) } ?: ""
|
||||
|
||||
val originalStartOffset = originalElements.first?.let { e -> e.getTextRange()!!.getStartOffset() }
|
||||
val originalStartOffset = originalElements.firstOrNull()?.let { e -> e.getTextRange()!!.getStartOffset() }
|
||||
|
||||
private val itFakeDeclaration by Delegates.lazy { JetPsiFactory(originalFile).createParameter("it: Any?") }
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ public fun JetPsiRange.preview(project: Project, editor: Editor): RangeHighlight
|
||||
CodeFoldingManager.getInstance(project)
|
||||
.getFoldRegionsAtOffset(editor, startOffset)
|
||||
.filter { !it.isExpanded() }
|
||||
if (!foldedRegions.empty) {
|
||||
if (!foldedRegions.isEmpty()) {
|
||||
editor.getFoldingModel().runBatchFoldingOperation { foldedRegions.forEach { it.setExpanded(true) } }
|
||||
}
|
||||
editor.getScrollingModel().scrollTo(editor.offsetToLogicalPosition(startOffset), ScrollType.MAKE_VISIBLE)
|
||||
@@ -67,7 +67,7 @@ public fun processDuplicates(
|
||||
project: Project,
|
||||
editor: Editor
|
||||
) {
|
||||
val size = duplicateReplacers.size
|
||||
val size = duplicateReplacers.size()
|
||||
if (size == 0) return
|
||||
|
||||
if (size == 1) {
|
||||
@@ -90,7 +90,7 @@ public fun processDuplicates(
|
||||
if (answer != Messages.YES) return
|
||||
|
||||
var showAll = false
|
||||
for ((i, entry) in duplicateReplacers.entrySet().withIndices()) {
|
||||
for ((i, entry) in duplicateReplacers.entrySet().withIndex()) {
|
||||
val (pattern, replacer) = entry
|
||||
if (!pattern.isValid()) continue
|
||||
|
||||
|
||||
+11
-11
@@ -299,7 +299,7 @@ private fun ExtractionData.analyzeControlFlow(
|
||||
parameters.filter { it.mirrorVarName != null && modifiedVarDescriptors[it.originalDescriptor] != null }.sortBy { it.nameForRef }
|
||||
val outDeclarations =
|
||||
declarationsToCopy.filter { modifiedVarDescriptors[bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it]] != null }
|
||||
val modifiedValueCount = outParameters.size + outDeclarations.size
|
||||
val modifiedValueCount = outParameters.size() + outDeclarations.size()
|
||||
|
||||
val outputValues = ArrayList<OutputValue>()
|
||||
|
||||
@@ -316,9 +316,9 @@ private fun ExtractionData.analyzeControlFlow(
|
||||
|
||||
if (defaultExits.isNotEmpty()) {
|
||||
if (modifiedValueCount != 0) return outputAndExitsError
|
||||
if (valuedReturnExits.size != 1) return multipleExitsError
|
||||
if (valuedReturnExits.size() != 1) return multipleExitsError
|
||||
|
||||
val element = valuedReturnExits.first!!.element as JetExpression
|
||||
val element = valuedReturnExits.first().element as JetExpression
|
||||
return controlFlow.copy(outputValues = Collections.singletonList(Jump(listOf(element), element, true))) to null
|
||||
}
|
||||
|
||||
@@ -336,7 +336,7 @@ private fun ExtractionData.analyzeControlFlow(
|
||||
if (jumpExits.isNotEmpty()) return outputAndExitsError
|
||||
|
||||
val boxerFactory: (List<OutputValue>) -> OutputValueBoxer = when {
|
||||
outputValues.size > 3 -> {
|
||||
outputValues.size() > 3 -> {
|
||||
if (!options.enableListBoxing) {
|
||||
val outValuesStr =
|
||||
(outParameters.map { it.originalDescriptor.renderForMessage() }
|
||||
@@ -581,9 +581,9 @@ private fun ExtractionData.inferParametersInfo(
|
||||
when (it) {
|
||||
is ClassDescriptor ->
|
||||
when(it.getKind()) {
|
||||
ClassKind.OBJECT, ClassKind.ENUM_CLASS -> it as ClassDescriptor
|
||||
ClassKind.OBJECT, ClassKind.ENUM_CLASS -> it : ClassDescriptor
|
||||
ClassKind.CLASS_OBJECT, ClassKind.ENUM_ENTRY -> it.getContainingDeclaration() as? ClassDescriptor
|
||||
else -> if (ref.getNonStrictParentOfType<JetTypeReference>() != null) it as ClassDescriptor else null
|
||||
else -> if (ref.getNonStrictParentOfType<JetTypeReference>() != null) it : ClassDescriptor else null
|
||||
}
|
||||
|
||||
is ConstructorDescriptor -> it.getContainingDeclaration()
|
||||
@@ -648,7 +648,7 @@ private fun ExtractionData.inferParametersInfo(
|
||||
|
||||
val varNameValidator = JetNameValidatorImpl(
|
||||
commonParent.getNonStrictParentOfType<JetExpression>(),
|
||||
originalElements.first,
|
||||
originalElements.firstOrNull(),
|
||||
JetNameValidatorImpl.Target.PROPERTIES
|
||||
)
|
||||
|
||||
@@ -717,7 +717,7 @@ fun ExtractionData.isVisibilityApplicable(): Boolean {
|
||||
}
|
||||
|
||||
fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
if (originalElements.empty) {
|
||||
if (originalElements.isEmpty()) {
|
||||
return AnalysisResult(null, Status.CRITICAL_ERROR, listOf(ErrorMessage.NO_EXPRESSION))
|
||||
}
|
||||
|
||||
@@ -793,7 +793,7 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
val adjustedParameters = paramsInfo.parameters.filterTo(HashSet<Parameter>()) { it.refCount > 0 }
|
||||
|
||||
val receiverCandidates = adjustedParameters.filterTo(HashSet<Parameter>()) { it.receiverCandidate }
|
||||
val receiverParameter = if (receiverCandidates.size == 1) receiverCandidates.first() else null
|
||||
val receiverParameter = if (receiverCandidates.size() == 1) receiverCandidates.first() else null
|
||||
receiverParameter?.let { adjustedParameters.remove(it) }
|
||||
|
||||
return AnalysisResult(
|
||||
@@ -806,9 +806,9 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
|
||||
receiverParameter,
|
||||
paramsInfo.typeParameters.sortBy { it.originalDeclaration.getName()!! },
|
||||
paramsInfo.replacementMap,
|
||||
if (messages.empty) controlFlow else controlFlow.toDefault()
|
||||
if (messages.isEmpty()) controlFlow else controlFlow.toDefault()
|
||||
),
|
||||
if (messages.empty) Status.SUCCESS else Status.NON_CRITICAL_ERROR,
|
||||
if (messages.isEmpty()) Status.SUCCESS else Status.NON_CRITICAL_ERROR,
|
||||
messages
|
||||
)
|
||||
}
|
||||
|
||||
@@ -126,7 +126,7 @@ class DuplicateInfo(
|
||||
|
||||
fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo> {
|
||||
fun processWeakMatch(match: Match, newControlFlow: ControlFlow): Boolean {
|
||||
val valueCount = controlFlow.outputValues.size
|
||||
val valueCount = controlFlow.outputValues.size()
|
||||
|
||||
val weakMatches = HashMap((match.result as WeaklyMatched).weakMatches)
|
||||
val currentValuesToNew = HashMap<OutputValue, OutputValue>()
|
||||
@@ -152,7 +152,7 @@ fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo> {
|
||||
}
|
||||
}
|
||||
|
||||
return currentValuesToNew.size == valueCount && weakMatches.isEmpty()
|
||||
return currentValuesToNew.size() == valueCount && weakMatches.isEmpty()
|
||||
}
|
||||
|
||||
fun getControlFlowIfMatched(match: Match): ControlFlow? {
|
||||
@@ -161,7 +161,7 @@ fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo> {
|
||||
|
||||
val newControlFlow = analysisResult.descriptor!!.controlFlow
|
||||
if (newControlFlow.outputValues.isEmpty()) return newControlFlow
|
||||
if (controlFlow.outputValues.size != newControlFlow.outputValues.size) return null
|
||||
if (controlFlow.outputValues.size() != newControlFlow.outputValues.size()) return null
|
||||
|
||||
val matched = when (match.result) {
|
||||
is StronglyMatched -> true
|
||||
@@ -231,7 +231,7 @@ private fun makeCall(
|
||||
val psiFactory = JetPsiFactory(anchor.getProject())
|
||||
val newLine = psiFactory.createNewLine()
|
||||
|
||||
if (controlFlow.outputValueBoxer is AsTuple && controlFlow.outputValues.size > 1 && controlFlow.outputValues.all { it is Initializer }) {
|
||||
if (controlFlow.outputValueBoxer is AsTuple && controlFlow.outputValues.size() > 1 && controlFlow.outputValues.all { it is Initializer }) {
|
||||
val declarationsToMerge = controlFlow.outputValues.map { (it as Initializer).initializedDeclaration }
|
||||
val isVar = declarationsToMerge.first().isVar()
|
||||
if (declarationsToMerge.all { it.isVar() == isVar }) {
|
||||
@@ -249,7 +249,7 @@ private fun makeCall(
|
||||
}
|
||||
}
|
||||
|
||||
val inlinableCall = controlFlow.outputValues.size <= 1
|
||||
val inlinableCall = controlFlow.outputValues.size() <= 1
|
||||
val unboxingExpressions =
|
||||
if (inlinableCall) {
|
||||
controlFlow.outputValueBoxer.getUnboxingExpressions(callText)
|
||||
@@ -319,7 +319,7 @@ private fun makeCall(
|
||||
controlFlow.outputValues
|
||||
.filter { it != defaultValue }
|
||||
.flatMap { wrapCall(it, unboxingExpressions[it]!!) }
|
||||
.withIndices()
|
||||
.withIndex()
|
||||
.forEach {
|
||||
val (i, e) = it
|
||||
|
||||
|
||||
Reference in New Issue
Block a user