Minor: Fix warnings

This commit is contained in:
Alexey Sedunov
2015-01-13 14:45:57 +03:00
parent 8d40ca1a74
commit 941e08b80f
6 changed files with 42 additions and 41 deletions
@@ -63,7 +63,7 @@ public class ExtractKotlinFunctionHandler(
public val allContainersEnabled: Boolean = false, public val allContainersEnabled: Boolean = false,
private val helper: ExtractKotlinFunctionHandlerHelper = ExtractKotlinFunctionHandlerHelper.DEFAULT) : RefactoringActionHandler { private val helper: ExtractKotlinFunctionHandlerHelper = ExtractKotlinFunctionHandlerHelper.DEFAULT) : RefactoringActionHandler {
private fun adjustElements(elements: List<PsiElement>): List<PsiElement> { private fun adjustElements(elements: List<PsiElement>): List<PsiElement> {
if (elements.size != 1) return elements if (elements.size() != 1) return elements
val e = elements.first() val e = elements.first()
if (e is JetBlockExpression && e.getParent() is JetFunctionLiteral) return e.getStatements() 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) { when (analysisResult.status) {
Status.CRITICAL_ERROR -> { Status.CRITICAL_ERROR -> {
showErrorHint(project, editor, message) showErrorHint(project, editor, message)
@@ -179,7 +179,7 @@ fun selectElements(
fun onSelectionComplete(parent: PsiElement, elements: List<PsiElement>, targetContainer: JetElement) { fun onSelectionComplete(parent: PsiElement, elements: List<PsiElement>, targetContainer: JetElement) {
if (parent == targetContainer) { if (parent == targetContainer) {
continuation(elements, elements.first!!) continuation(elements, elements.first())
return return
} }
@@ -194,10 +194,10 @@ fun selectElements(
fun selectTargetContainer(elements: List<PsiElement>) { fun selectTargetContainer(elements: List<PsiElement>) {
val parent = PsiTreeUtil.findCommonParent(elements) 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) val containers = parent.getExtractionContainers(elements.size() == 1, allContainersEnabled)
if (containers.empty) { if (containers.isEmpty()) {
noContainerError() noContainerError()
return return
} }
@@ -176,7 +176,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
else -> null else -> null
} }
val arguments = call?.getValueArguments() val arguments = call?.getValueArguments()
if (arguments == null || arguments.size <= index) return null if (arguments == null || arguments.size() <= index) return null
return arguments[index].getArgumentExpression() return arguments[index].getArgumentExpression()
} }
@@ -195,7 +195,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
val module: ModuleDescriptor val module: ModuleDescriptor
) : OutputValueBoxer(outputValues) { ) : 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 { class object {
@@ -204,7 +204,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
override val returnType: JetType by Delegates.lazy { override val returnType: JetType by Delegates.lazy {
fun getType(): JetType { fun getType(): JetType {
val boxingClass = when (outputValues.size) { val boxingClass = when (outputValues.size()) {
1 -> return outputValues.first().valueType 1 -> return outputValues.first().valueType
2 -> ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.Pair")).first() 2 -> ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.Pair")).first()
3 -> ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.Triple")).first() 3 -> ResolveSessionUtils.getClassDescriptorsByFqName(module, FqName("kotlin.Triple")).first()
@@ -216,10 +216,10 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
getType() getType()
} }
override val boxingRequired: Boolean = outputValues.size > 1 override val boxingRequired: Boolean = outputValues.size() > 1
override fun getBoxingExpressionText(arguments: List<String>): String? { override fun getBoxingExpressionText(arguments: List<String>): String? {
return when (arguments.size) { return when (arguments.size()) {
0 -> null 0 -> null
1 -> arguments.first() 1 -> arguments.first()
else -> { else -> {
@@ -235,7 +235,7 @@ abstract class OutputValueBoxer(val outputValues: List<OutputValue>) {
} }
override fun getUnboxingExpressions(boxedText: String): Map<OutputValue, String> { override fun getUnboxingExpressions(boxedText: String): Map<OutputValue, String> {
return when (outputValues.size) { return when (outputValues.size()) {
0 -> Collections.emptyMap() 0 -> Collections.emptyMap()
1 -> Collections.singletonMap(outputValues.first(), boxedText) 1 -> Collections.singletonMap(outputValues.first(), boxedText)
else -> { 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? { override fun getBoxingExpressionText(arguments: List<String>): String? {
if (arguments.isEmpty()) return null if (arguments.isEmpty()) return null
@@ -281,14 +281,15 @@ data class ControlFlow(
val outputValueBoxer = boxerFactory(outputValues) val outputValueBoxer = boxerFactory(outputValues)
val defaultOutputValue: ExpressionValue? = with(outputValues.filterIsInstance<ExpressionValue>()) { 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 jumpOutputValue: Jump? = with(outputValues.filterIsInstance<Jump>()) {
val jumpCount = size()
when { when {
isEmpty() -> isEmpty() ->
null 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()}") throw IllegalArgumentException("Jump values must be the only value if it's present: ${outputValues.joinToString()}")
else -> else ->
first() first()
@@ -384,7 +385,7 @@ class ExtractableCodeDescriptorWithConflicts(
) )
fun ExtractableCodeDescriptor.canGenerateProperty(): Boolean { fun ExtractableCodeDescriptor.canGenerateProperty(): Boolean {
if (!parameters.empty) return false if (!parameters.isEmpty()) return false
if (controlFlow.outputValueBoxer.returnType.isUnit()) return false if (controlFlow.outputValueBoxer.returnType.isUnit()) return false
val parent = extractionData.targetSibling.getParent() val parent = extractionData.targetSibling.getParent()
@@ -92,12 +92,12 @@ data class ExtractionData(
fun getCodeFragmentTextRange(): TextRange? { fun getCodeFragmentTextRange(): TextRange? {
val originalElements = originalElements val originalElements = originalElements
return when (originalElements.size) { return when (originalElements.size()) {
0 -> null 0 -> null
1 -> originalElements.first!!.getTextRange() 1 -> originalElements.first().getTextRange()
else -> { else -> {
val from = originalElements.first!!.getTextRange()!!.getStartOffset() val from = originalElements.first().getTextRange()!!.getStartOffset()
val to = originalElements.last!!.getTextRange()!!.getEndOffset() val to = originalElements.last().getTextRange()!!.getEndOffset()
TextRange(from, to) TextRange(from, to)
} }
} }
@@ -106,7 +106,7 @@ data class ExtractionData(
fun getCodeFragmentText(): String = fun getCodeFragmentText(): String =
getCodeFragmentTextRange()?.let { originalFile.getText()?.substring(it.getStartOffset(), it.getEndOffset()) } ?: "" 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?") } 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) CodeFoldingManager.getInstance(project)
.getFoldRegionsAtOffset(editor, startOffset) .getFoldRegionsAtOffset(editor, startOffset)
.filter { !it.isExpanded() } .filter { !it.isExpanded() }
if (!foldedRegions.empty) { if (!foldedRegions.isEmpty()) {
editor.getFoldingModel().runBatchFoldingOperation { foldedRegions.forEach { it.setExpanded(true) } } editor.getFoldingModel().runBatchFoldingOperation { foldedRegions.forEach { it.setExpanded(true) } }
} }
editor.getScrollingModel().scrollTo(editor.offsetToLogicalPosition(startOffset), ScrollType.MAKE_VISIBLE) editor.getScrollingModel().scrollTo(editor.offsetToLogicalPosition(startOffset), ScrollType.MAKE_VISIBLE)
@@ -67,7 +67,7 @@ public fun processDuplicates(
project: Project, project: Project,
editor: Editor editor: Editor
) { ) {
val size = duplicateReplacers.size val size = duplicateReplacers.size()
if (size == 0) return if (size == 0) return
if (size == 1) { if (size == 1) {
@@ -90,7 +90,7 @@ public fun processDuplicates(
if (answer != Messages.YES) return if (answer != Messages.YES) return
var showAll = false var showAll = false
for ((i, entry) in duplicateReplacers.entrySet().withIndices()) { for ((i, entry) in duplicateReplacers.entrySet().withIndex()) {
val (pattern, replacer) = entry val (pattern, replacer) = entry
if (!pattern.isValid()) continue if (!pattern.isValid()) continue
@@ -299,7 +299,7 @@ private fun ExtractionData.analyzeControlFlow(
parameters.filter { it.mirrorVarName != null && modifiedVarDescriptors[it.originalDescriptor] != null }.sortBy { it.nameForRef } parameters.filter { it.mirrorVarName != null && modifiedVarDescriptors[it.originalDescriptor] != null }.sortBy { it.nameForRef }
val outDeclarations = val outDeclarations =
declarationsToCopy.filter { modifiedVarDescriptors[bindingContext[BindingContext.DECLARATION_TO_DESCRIPTOR, it]] != null } 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>() val outputValues = ArrayList<OutputValue>()
@@ -316,9 +316,9 @@ private fun ExtractionData.analyzeControlFlow(
if (defaultExits.isNotEmpty()) { if (defaultExits.isNotEmpty()) {
if (modifiedValueCount != 0) return outputAndExitsError 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 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 if (jumpExits.isNotEmpty()) return outputAndExitsError
val boxerFactory: (List<OutputValue>) -> OutputValueBoxer = when { val boxerFactory: (List<OutputValue>) -> OutputValueBoxer = when {
outputValues.size > 3 -> { outputValues.size() > 3 -> {
if (!options.enableListBoxing) { if (!options.enableListBoxing) {
val outValuesStr = val outValuesStr =
(outParameters.map { it.originalDescriptor.renderForMessage() } (outParameters.map { it.originalDescriptor.renderForMessage() }
@@ -581,9 +581,9 @@ private fun ExtractionData.inferParametersInfo(
when (it) { when (it) {
is ClassDescriptor -> is ClassDescriptor ->
when(it.getKind()) { 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 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() is ConstructorDescriptor -> it.getContainingDeclaration()
@@ -648,7 +648,7 @@ private fun ExtractionData.inferParametersInfo(
val varNameValidator = JetNameValidatorImpl( val varNameValidator = JetNameValidatorImpl(
commonParent.getNonStrictParentOfType<JetExpression>(), commonParent.getNonStrictParentOfType<JetExpression>(),
originalElements.first, originalElements.firstOrNull(),
JetNameValidatorImpl.Target.PROPERTIES JetNameValidatorImpl.Target.PROPERTIES
) )
@@ -717,7 +717,7 @@ fun ExtractionData.isVisibilityApplicable(): Boolean {
} }
fun ExtractionData.performAnalysis(): AnalysisResult { fun ExtractionData.performAnalysis(): AnalysisResult {
if (originalElements.empty) { if (originalElements.isEmpty()) {
return AnalysisResult(null, Status.CRITICAL_ERROR, listOf(ErrorMessage.NO_EXPRESSION)) 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 adjustedParameters = paramsInfo.parameters.filterTo(HashSet<Parameter>()) { it.refCount > 0 }
val receiverCandidates = adjustedParameters.filterTo(HashSet<Parameter>()) { it.receiverCandidate } 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) } receiverParameter?.let { adjustedParameters.remove(it) }
return AnalysisResult( return AnalysisResult(
@@ -806,9 +806,9 @@ fun ExtractionData.performAnalysis(): AnalysisResult {
receiverParameter, receiverParameter,
paramsInfo.typeParameters.sortBy { it.originalDeclaration.getName()!! }, paramsInfo.typeParameters.sortBy { it.originalDeclaration.getName()!! },
paramsInfo.replacementMap, 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 messages
) )
} }
@@ -126,7 +126,7 @@ class DuplicateInfo(
fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo> { fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo> {
fun processWeakMatch(match: Match, newControlFlow: ControlFlow): Boolean { 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 weakMatches = HashMap((match.result as WeaklyMatched).weakMatches)
val currentValuesToNew = HashMap<OutputValue, OutputValue>() 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? { fun getControlFlowIfMatched(match: Match): ControlFlow? {
@@ -161,7 +161,7 @@ fun ExtractableCodeDescriptor.findDuplicates(): List<DuplicateInfo> {
val newControlFlow = analysisResult.descriptor!!.controlFlow val newControlFlow = analysisResult.descriptor!!.controlFlow
if (newControlFlow.outputValues.isEmpty()) return newControlFlow 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) { val matched = when (match.result) {
is StronglyMatched -> true is StronglyMatched -> true
@@ -231,7 +231,7 @@ private fun makeCall(
val psiFactory = JetPsiFactory(anchor.getProject()) val psiFactory = JetPsiFactory(anchor.getProject())
val newLine = psiFactory.createNewLine() 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 declarationsToMerge = controlFlow.outputValues.map { (it as Initializer).initializedDeclaration }
val isVar = declarationsToMerge.first().isVar() val isVar = declarationsToMerge.first().isVar()
if (declarationsToMerge.all { it.isVar() == 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 = val unboxingExpressions =
if (inlinableCall) { if (inlinableCall) {
controlFlow.outputValueBoxer.getUnboxingExpressions(callText) controlFlow.outputValueBoxer.getUnboxingExpressions(callText)
@@ -319,7 +319,7 @@ private fun makeCall(
controlFlow.outputValues controlFlow.outputValues
.filter { it != defaultValue } .filter { it != defaultValue }
.flatMap { wrapCall(it, unboxingExpressions[it]!!) } .flatMap { wrapCall(it, unboxingExpressions[it]!!) }
.withIndices() .withIndex()
.forEach { .forEach {
val (i, e) = it val (i, e) = it