Extraction Engine: Generate function/property accessor with expression body (whenever applicable)
#KT-6405 Fixed
This commit is contained in:
@@ -630,6 +630,15 @@ public class JetPsiFactory(private val project: Project) {
|
||||
return this
|
||||
}
|
||||
|
||||
public fun expressionBody(body: String): CallableBuilder {
|
||||
assert(state == State.BODY || state == State.TYPE_CONSTRAINTS)
|
||||
|
||||
sb.append(bodyPrefix()).append(" = ").append(body)
|
||||
state = State.DONE
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
public fun initializer(body: String): CallableBuilder {
|
||||
assert(target == Target.READ_ONLY_PROPERTY && (state == State.BODY || state == State.TYPE_CONSTRAINTS))
|
||||
|
||||
|
||||
+5
-5
@@ -101,11 +101,11 @@ fun getFunctionForExtractedFragment(
|
||||
throw EvaluateExceptionUtil.createEvaluateException("Following declarations are unavailable in debug scope: ${validationResult.conflicts.keySet().map { it.getText() }.joinToString(",")}")
|
||||
}
|
||||
|
||||
val config = ExtractionGeneratorConfiguration(
|
||||
validationResult.descriptor,
|
||||
ExtractionGeneratorOptions(inTempFile = true, flexibleTypesAllowed = true, allowDummyName = true)
|
||||
)
|
||||
return config.generateDeclaration()
|
||||
val generatorOptions = ExtractionGeneratorOptions(inTempFile = true,
|
||||
flexibleTypesAllowed = true,
|
||||
allowDummyName = true,
|
||||
allowExpressionBody = false)
|
||||
return ExtractionGeneratorConfiguration(validationResult.descriptor, generatorOptions).generateDeclaration()
|
||||
}
|
||||
|
||||
return runReadAction { generateFunction() }
|
||||
|
||||
@@ -32,13 +32,17 @@ import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType
|
||||
public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() {
|
||||
override fun getFamilyName(): String = JetBundle.message("convert.to.expression.body.action.family.name")
|
||||
|
||||
override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean {
|
||||
setText(JetBundle.message("convert.to.expression.body.action.name"))
|
||||
public fun isAvailable(element: PsiElement): Boolean {
|
||||
val data = calcData(element)
|
||||
return data != null && !containsReturn(data.value)
|
||||
}
|
||||
|
||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||
override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean {
|
||||
setText(JetBundle.message("convert.to.expression.body.action.name"))
|
||||
return isAvailable(element)
|
||||
}
|
||||
|
||||
public fun invoke(element: PsiElement, editor: Editor? = null) {
|
||||
val (declaration, value) = calcData(element)!!
|
||||
|
||||
if (!declaration.hasDeclaredReturnType() && declaration is JetNamedFunction) {
|
||||
@@ -55,12 +59,21 @@ public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() {
|
||||
if (declaration.hasDeclaredReturnType() && declaration is JetCallableDeclaration && canOmitType(declaration)) {
|
||||
val typeRef = declaration.getTypeReference()!!
|
||||
val colon = declaration.getColon()!!
|
||||
val range = TextRange(colon.getTextRange().getStartOffset(), typeRef.getTextRange().getEndOffset())
|
||||
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset())
|
||||
editor.getCaretModel().moveToOffset(range.getEndOffset())
|
||||
if (editor != null) {
|
||||
val range = TextRange(colon.getTextRange().getStartOffset(), typeRef.getTextRange().getEndOffset())
|
||||
editor.getSelectionModel().setSelection(range.getStartOffset(), range.getEndOffset())
|
||||
editor.getCaretModel().moveToOffset(range.getEndOffset())
|
||||
}
|
||||
else {
|
||||
(declaration : PsiElement).deleteChildRange(colon, typeRef)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun invoke(project: Project, editor: Editor, element: PsiElement) {
|
||||
invoke(element, editor)
|
||||
}
|
||||
|
||||
private fun canOmitType(declaration: JetCallableDeclaration): Boolean {
|
||||
if (declaration.getModifierList()?.hasModifier(JetTokens.OVERRIDE_KEYWORD) ?: false) return true
|
||||
val descriptor = declaration.resolveToDescriptor()
|
||||
|
||||
+2
-1
@@ -364,7 +364,8 @@ data class ExtractionGeneratorOptions(
|
||||
val inTempFile: Boolean = false,
|
||||
val target: ExtractionTarget = ExtractionTarget.FUNCTION,
|
||||
val flexibleTypesAllowed: Boolean = false,
|
||||
val allowDummyName: Boolean = false
|
||||
val allowDummyName: Boolean = false,
|
||||
val allowExpressionBody: Boolean = true
|
||||
) {
|
||||
default object {
|
||||
val DEFAULT = ExtractionGeneratorOptions()
|
||||
|
||||
+6
-2
@@ -72,6 +72,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.*
|
||||
import org.jetbrains.kotlin.diagnostics.*
|
||||
import java.util.logging.*
|
||||
import com.intellij.openapi.diagnostic.Logger
|
||||
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfTypeAndBranch
|
||||
|
||||
private val DEFAULT_RETURN_TYPE = KotlinBuiltIns.getInstance().getUnitType()
|
||||
@@ -881,11 +882,14 @@ fun ExtractableCodeDescriptor.validate(): ExtractableCodeDescriptorWithConflicts
|
||||
|
||||
val conflicts = MultiMap<PsiElement, String>()
|
||||
|
||||
val result = ExtractionGeneratorConfiguration(this, ExtractionGeneratorOptions(inTempFile = true)).generateDeclaration()
|
||||
val result = ExtractionGeneratorConfiguration(
|
||||
this,
|
||||
ExtractionGeneratorOptions(inTempFile = true, allowExpressionBody = false)
|
||||
).generateDeclaration()
|
||||
|
||||
val valueParameterList = (result.declaration as? JetNamedFunction)?.getValueParameterList()
|
||||
val body = result.declaration.getGeneratedBody()
|
||||
val bindingContext = body.analyze()
|
||||
val bindingContext = body.analyzeFully()
|
||||
|
||||
fun validateBody() {
|
||||
for ((originalOffset, resolveResult) in extractionData.refOffsetToDeclaration) {
|
||||
|
||||
+15
-23
@@ -17,32 +17,17 @@
|
||||
package org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.psi.JetDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetProperty
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory.CallableBuilder
|
||||
import org.jetbrains.kotlin.psi.JetNamedDeclaration
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory
|
||||
import java.util.LinkedHashMap
|
||||
import java.util.Collections
|
||||
import org.jetbrains.kotlin.psi.psiUtil.isFunctionLiteralOutsideParentheses
|
||||
import org.jetbrains.kotlin.psi.JetFunctionLiteralArgument
|
||||
import org.jetbrains.kotlin.idea.util.psiModificationUtil.moveInsideParenthesesAndReplaceWith
|
||||
import org.jetbrains.kotlin.psi.psiUtil.appendElement
|
||||
import org.jetbrains.kotlin.psi.psiUtil.replaced
|
||||
import org.jetbrains.kotlin.psi.JetBlockExpression
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.ParameterUpdate
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.Jump
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.Initializer
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.ExpressionValue
|
||||
import org.jetbrains.kotlin.psi.JetReturnExpression
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.idea.intentions.ConvertToExpressionBodyAction
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetNameSuggester
|
||||
import org.jetbrains.kotlin.idea.refactoring.JetNameValidatorImpl
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.*
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.refactoring.isMultiLine
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.ExpressionValue
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.Initializer
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.Jump
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValue.ParameterUpdate
|
||||
import org.jetbrains.kotlin.idea.refactoring.introduce.extractionEngine.OutputValueBoxer.AsTuple
|
||||
import org.jetbrains.kotlin.idea.refactoring.isMultiLine
|
||||
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
|
||||
import org.jetbrains.kotlin.idea.util.ShortenReferences
|
||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange
|
||||
import org.jetbrains.kotlin.idea.util.psi.patternMatching.JetPsiRange.Match
|
||||
@@ -53,7 +38,6 @@ import org.jetbrains.kotlin.idea.util.psi.patternMatching.UnifierParameter
|
||||
import org.jetbrains.kotlin.idea.util.psiModificationUtil.moveInsideParenthesesAndReplaceWith
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory.CallableBuilder
|
||||
import org.jetbrains.kotlin.psi.JetPsiFactory.CallableBuilder.Target
|
||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.DEBUG_TYPE_REFERENCE_STRING
|
||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.debugTypeInfo
|
||||
import org.jetbrains.kotlin.psi.codeFragmentUtil.suppressDiagnosticsInDebugMode
|
||||
@@ -526,6 +510,14 @@ fun ExtractionGeneratorConfiguration.generateDeclaration(
|
||||
!defaultValue.callSiteReturn ->
|
||||
replaceWithReturn(lastExpression!!, returnExpression, expressionToUnifyWith)
|
||||
}
|
||||
|
||||
if (generatorOptions.allowExpressionBody) {
|
||||
val convertToExpressionBody = ConvertToExpressionBodyAction()
|
||||
val bodyExpression = body.getStatements().singleOrNull()
|
||||
if (bodyExpression != null && !bodyExpression.isMultiLine() && convertToExpressionBody.isAvailable(body)) {
|
||||
convertToExpressionBody.invoke(body)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun insertDeclaration(declaration: JetNamedDeclaration, anchor: PsiElement): JetNamedDeclaration {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
fun foo(a: Int): Int {
|
||||
// SIBLING:
|
||||
fun i(): Int {
|
||||
return a + 10
|
||||
}
|
||||
fun i() = a + 10
|
||||
|
||||
return i()
|
||||
}
|
||||
+1
-3
@@ -1,9 +1,7 @@
|
||||
fun foo() {
|
||||
val a = 1
|
||||
// SIBLING:
|
||||
fun b1(): Boolean {
|
||||
return a > 0
|
||||
}
|
||||
fun b1() = a > 0
|
||||
|
||||
if (b1()) {
|
||||
fun b(): Int { return 0 }
|
||||
|
||||
@@ -3,7 +3,5 @@ trait T{
|
||||
return i()
|
||||
}
|
||||
|
||||
fun i(): Int {
|
||||
return 1
|
||||
}
|
||||
fun i() = 1
|
||||
}
|
||||
+1
-3
@@ -8,6 +8,4 @@ fun foo(a: Int): Int {
|
||||
return if (b(a, b)) 1 else if (a - b < 0) 2 else b
|
||||
}
|
||||
|
||||
private fun b(a: Int, b: Int): Boolean {
|
||||
return a + b > 0
|
||||
}
|
||||
private fun b(a: Int, b: Int) = a + b > 0
|
||||
|
||||
+1
-3
@@ -8,6 +8,4 @@ fun foo(a: Int): Int {
|
||||
return if (a + b > 0) 1 else i(a, b)
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return if (a - b < 0) 2 else b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = if (a - b < 0) 2 else b
|
||||
|
||||
+1
-3
@@ -4,6 +4,4 @@ fun foo(a: Int): Int {
|
||||
return if (a + b > 0) i() else if (a - b < 0) 2 else b
|
||||
}
|
||||
|
||||
private fun i(): Int {
|
||||
return 1
|
||||
}
|
||||
private fun i() = 1
|
||||
|
||||
+1
-3
@@ -10,6 +10,4 @@ fun foo(a: Int): Int {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(b: Int): Int {
|
||||
return b
|
||||
}
|
||||
private fun i(b: Int) = b
|
||||
|
||||
+1
-3
@@ -8,6 +8,4 @@ fun foo(a: Int): Int {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(): Int {
|
||||
return 0
|
||||
}
|
||||
private fun i() = 0
|
||||
|
||||
+1
-3
@@ -12,6 +12,4 @@ fun foo(a: Int): Int {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
|
||||
+1
-3
@@ -5,6 +5,4 @@
|
||||
// SIBLING:
|
||||
fun foo(a: Int, b: Int): Int = i(a, b)
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
|
||||
+1
-3
@@ -8,6 +8,4 @@ fun foo(a: Int): Int {
|
||||
return i(a, b)
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return if (a + b > 0) 1 else if (a - b < 0) 2 else b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = if (a + b > 0) 1 else if (a - b < 0) 2 else b
|
||||
+1
-3
@@ -8,6 +8,4 @@ fun foo(a: Int): Int {
|
||||
return i(a, b)
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
+1
-3
@@ -5,6 +5,4 @@ fun foo(t: Array<Int>) {
|
||||
t.check(function())
|
||||
}
|
||||
|
||||
private fun function(): (Int) -> Boolean {
|
||||
return { it + 1 > 1 }
|
||||
}
|
||||
private fun function() = { it + 1 > 1 }
|
||||
+1
-3
@@ -5,6 +5,4 @@ fun foo(t: Array<Int>) {
|
||||
t.check(function())
|
||||
}
|
||||
|
||||
private fun function(): (Int) -> Boolean {
|
||||
return { it + 1 > 1 }
|
||||
}
|
||||
private fun function() = { it + 1 > 1 }
|
||||
+1
-3
@@ -5,6 +5,4 @@ fun foo(t: Array<Int>) {
|
||||
t.check(1, 2, function())
|
||||
}
|
||||
|
||||
private fun function(): (Int) -> Boolean {
|
||||
return { it + 1 > 1 }
|
||||
}
|
||||
private fun function() = { it + 1 > 1 }
|
||||
+1
-3
@@ -5,6 +5,4 @@ fun foo(t: Array<Int>) {
|
||||
t.check(a = 1, b = 2, f = function())
|
||||
}
|
||||
|
||||
private fun function(): (Int) -> Boolean {
|
||||
return { it + 1 > 1 }
|
||||
}
|
||||
private fun function() = { it + 1 > 1 }
|
||||
+1
-3
@@ -11,6 +11,4 @@ fun foo(a: Int): Int {
|
||||
return t
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return if (a > 0) throw Exception("") else a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = if (a > 0) throw Exception("") else a + b
|
||||
|
||||
@@ -5,9 +5,7 @@ class A {
|
||||
return i()
|
||||
}
|
||||
|
||||
private fun i(): Int {
|
||||
return a + b - 1
|
||||
}
|
||||
private fun i() = a + b - 1
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,6 @@ class A {
|
||||
return i(a, b)
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b - 1
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b - 1
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,5 @@ class A {
|
||||
}.invoke()
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b - 1
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b - 1
|
||||
}
|
||||
@@ -5,9 +5,7 @@ class A {
|
||||
return i()
|
||||
}
|
||||
|
||||
private fun i(): Int {
|
||||
return a + b - 1
|
||||
}
|
||||
private fun i() = a + b - 1
|
||||
}
|
||||
|
||||
return L().invoke()
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
fun foo(a: Int, b: Int): Int {
|
||||
fun i(): Int {
|
||||
return a + b - 1
|
||||
}
|
||||
fun i() = a + b - 1
|
||||
|
||||
fun bar() {
|
||||
return i()
|
||||
|
||||
@@ -9,7 +9,5 @@ class A {
|
||||
}.invoke()
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b - 1
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b - 1
|
||||
}
|
||||
+1
-3
@@ -6,6 +6,4 @@ fun foo(a: Int, b: Int): Int {
|
||||
return i(a, b)
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b - 1
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b - 1
|
||||
+1
-3
@@ -8,6 +8,4 @@ class A(a: Int, b: Int): T
|
||||
|
||||
class B(a: Int, b: Int): T by A(i(a, b), a - b)
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
+1
-3
@@ -6,6 +6,4 @@ class A(a: Int, b: Int): T
|
||||
|
||||
class B(t: T): T by t(t)
|
||||
|
||||
private fun t(t: T): T {
|
||||
return t
|
||||
}
|
||||
private fun t(t: T) = t
|
||||
@@ -6,6 +6,4 @@ open class A(a: Int, b: Int)
|
||||
|
||||
class B(a: Int, b: Int): A(i(a, b), a - b)
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
@@ -3,7 +3,5 @@ class A {
|
||||
val x = i()
|
||||
val y = i()
|
||||
|
||||
private fun i(): Int {
|
||||
return 1 + 1
|
||||
}
|
||||
private fun i() = 1 + 1
|
||||
}
|
||||
+1
-3
@@ -4,6 +4,4 @@ fun foo() {
|
||||
val y = i()
|
||||
}
|
||||
|
||||
private fun i(): Int {
|
||||
return 1 + 1
|
||||
}
|
||||
private fun i() = 1 + 1
|
||||
|
||||
@@ -5,6 +5,4 @@ fun main(args: Array<String>) {
|
||||
val y = i()
|
||||
}
|
||||
|
||||
private fun i(): Int {
|
||||
return 1 + 1
|
||||
}
|
||||
private fun i() = 1 + 1
|
||||
|
||||
@@ -11,6 +11,4 @@ fun foo(): Int {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(s: String?): Int {
|
||||
return s!!.length
|
||||
}
|
||||
private fun i(s: String?) = s!!.length
|
||||
@@ -24,6 +24,4 @@ fun bar() {
|
||||
i(f(), f())
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b * a
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b * a
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
class A(val a: Int, val b: Int) {
|
||||
val foo: Int get() = i() - 1
|
||||
|
||||
private fun i(): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i() = a + b
|
||||
}
|
||||
+1
-3
@@ -1,7 +1,5 @@
|
||||
class A(val a: Int, val b: Int) {
|
||||
val foo: Int get() = { i() - 1 }.invoke()
|
||||
|
||||
private fun i(): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i() = a + b
|
||||
}
|
||||
+1
-3
@@ -2,6 +2,4 @@ val a = 1
|
||||
val b = 1
|
||||
val foo: Int get() = i() - 1
|
||||
|
||||
private fun i(): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i() = a + b
|
||||
+1
-3
@@ -2,6 +2,4 @@ val a = 1
|
||||
val b = 1
|
||||
val foo: Int get() = { i() - 1 }.invoke()
|
||||
|
||||
private fun i(): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i() = a + b
|
||||
+1
-3
@@ -5,7 +5,5 @@ class A(val a: Int, b: Int) {
|
||||
println(i(b) - 1)
|
||||
}
|
||||
|
||||
private fun i(b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(b: Int) = a + b
|
||||
}
|
||||
+1
-3
@@ -5,7 +5,5 @@ class A(val a: Int, b: Int) {
|
||||
println({ i(b) - 1 }.invoke())
|
||||
}
|
||||
|
||||
private fun i(b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(b: Int) = a + b
|
||||
}
|
||||
+1
-3
@@ -3,6 +3,4 @@
|
||||
val n = 1
|
||||
class A(val a: Int, val b: Int = i(a))
|
||||
|
||||
private fun i(a: Int): Int {
|
||||
return a + n
|
||||
}
|
||||
private fun i(a: Int) = a + n
|
||||
+1
-3
@@ -3,6 +3,4 @@
|
||||
val n = 1
|
||||
class A(val a: Int, val b: Int = { i(a) }.invoke())
|
||||
|
||||
private fun i(a: Int): Int {
|
||||
return a + n
|
||||
}
|
||||
private fun i(a: Int) = a + n
|
||||
+1
-3
@@ -3,9 +3,7 @@
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in bar.foo
|
||||
// PARAM_DESCRIPTOR: value-parameter val b: kotlin.Int defined in bar.foo
|
||||
fun bar(n: Int) {
|
||||
fun i(a: Int, b: Int): Int {
|
||||
return a + b - n
|
||||
}
|
||||
fun i(a: Int, b: Int) = a + b - n
|
||||
|
||||
fun foo(a: Int, b: Int) = i(a, b) - 1
|
||||
}
|
||||
+1
-3
@@ -3,9 +3,7 @@
|
||||
// PARAM_DESCRIPTOR: value-parameter val a: kotlin.Int defined in bar.foo
|
||||
// PARAM_DESCRIPTOR: value-parameter val b: kotlin.Int defined in bar.foo
|
||||
fun bar(n: Int) {
|
||||
fun i(a: Int, b: Int): Int {
|
||||
return a + b - n
|
||||
}
|
||||
fun i(a: Int, b: Int) = a + b - n
|
||||
|
||||
fun foo(a: Int, b: Int) = { i(a, b) - 1 }.invoke()
|
||||
}
|
||||
+1
-3
@@ -5,7 +5,5 @@
|
||||
class A(val n: Int) {
|
||||
fun foo(a: Int, b: Int) = i(a, b) - 1
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b - n
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b - n
|
||||
}
|
||||
+1
-3
@@ -3,7 +3,5 @@
|
||||
class A(val n: Int) {
|
||||
fun foo(a: Int, b: Int = i(a)) = a + b - n - 1
|
||||
|
||||
private fun i(a: Int): Int {
|
||||
return a + n
|
||||
}
|
||||
private fun i(a: Int) = a + n
|
||||
}
|
||||
+1
-3
@@ -3,7 +3,5 @@
|
||||
class A(val n: Int) {
|
||||
fun foo(a: Int, b: Int = { i(a) }.invoke()) = a + b - n - 1
|
||||
|
||||
private fun i(a: Int): Int {
|
||||
return a + n
|
||||
}
|
||||
private fun i(a: Int) = a + n
|
||||
}
|
||||
+1
-3
@@ -5,7 +5,5 @@
|
||||
class A(val n: Int) {
|
||||
fun foo(a: Int, b: Int) = { i(a, b) - 1 }.invoke()
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b - n
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b - n
|
||||
}
|
||||
+1
-3
@@ -4,6 +4,4 @@
|
||||
// PARAM_DESCRIPTOR: value-parameter val b: kotlin.Int defined in foo
|
||||
fun foo(a: Int, b: Int) = i(a, b) - 1
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
+1
-3
@@ -3,6 +3,4 @@
|
||||
val n = 1
|
||||
fun foo(a: Int, b: Int = i(a)) = a + b - 1
|
||||
|
||||
private fun i(a: Int): Int {
|
||||
return a + n
|
||||
}
|
||||
private fun i(a: Int) = a + n
|
||||
+1
-3
@@ -3,6 +3,4 @@
|
||||
val n = 1
|
||||
fun foo(a: Int, b: Int = { i(a) }) = a + b - 1
|
||||
|
||||
private fun i(a: Int): Int {
|
||||
return a + n
|
||||
}
|
||||
private fun i(a: Int) = a + n
|
||||
+1
-3
@@ -4,6 +4,4 @@
|
||||
// PARAM_DESCRIPTOR: value-parameter val b: kotlin.Int defined in foo
|
||||
fun foo(a: Int, b: Int) = { i(a, b) - 1 }.invoke()
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
+1
-3
@@ -6,6 +6,4 @@ fun bar(a: Int, b: Int) {
|
||||
val foo = i(a, b) - 1
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
+1
-3
@@ -6,6 +6,4 @@ fun bar(a: Int, b: Int) {
|
||||
val foo = { i(a, b) - 1 }.invoke()
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(a: Int, b: Int) = a + b
|
||||
+1
-3
@@ -3,7 +3,5 @@
|
||||
class A(val a: Int, b: Int) {
|
||||
val foo = i(b) - 1
|
||||
|
||||
private fun i(b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(b: Int) = a + b
|
||||
}
|
||||
+1
-3
@@ -3,7 +3,5 @@
|
||||
class A(val a: Int, b: Int) {
|
||||
val foo = { i(b) - 1 }.invoke()
|
||||
|
||||
private fun i(b: Int): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i(b: Int) = a + b
|
||||
}
|
||||
+1
-3
@@ -4,6 +4,4 @@ fun foo() {
|
||||
val (a, b) = pair()
|
||||
}
|
||||
|
||||
private fun pair(): Pair<Int, Int> {
|
||||
return 1 to 2
|
||||
}
|
||||
private fun pair() = 1 to 2
|
||||
+1
-3
@@ -2,6 +2,4 @@ val a = 1
|
||||
val b = 1
|
||||
val foo = i() - 1
|
||||
|
||||
private fun i(): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i() = a + b
|
||||
+1
-3
@@ -2,6 +2,4 @@ val a = 1
|
||||
val b = 1
|
||||
val foo = { i() - 1 }.invoke()
|
||||
|
||||
private fun i(): Int {
|
||||
return a + b
|
||||
}
|
||||
private fun i() = a + b
|
||||
+1
-3
@@ -7,6 +7,4 @@ fun test() {
|
||||
val n = i(property)
|
||||
}
|
||||
|
||||
private fun i(property: String?): Int? {
|
||||
return property?.length()
|
||||
}
|
||||
private fun i(property: String?) = property?.length()
|
||||
|
||||
+1
-3
@@ -7,6 +7,4 @@ fun test() {
|
||||
val n = i(property)
|
||||
}
|
||||
|
||||
private fun i(property: String): Int {
|
||||
return property.length()
|
||||
}
|
||||
private fun i(property: String) = property.length()
|
||||
|
||||
+1
-3
@@ -19,6 +19,4 @@ public class A(): Z() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(a1: A, b1: A.B): Int {
|
||||
return a1.a + b1.b + a1.z + b1.z
|
||||
}
|
||||
private fun i(a1: A, b1: A.B) = a1.a + b1.b + a1.z + b1.z
|
||||
|
||||
+1
-3
@@ -7,6 +7,4 @@ fun Z.foo(): Int {
|
||||
return i() + 1
|
||||
}
|
||||
|
||||
private fun Z.i(): Int {
|
||||
return this.a
|
||||
}
|
||||
private fun Z.i() = this.a
|
||||
|
||||
+1
-3
@@ -19,6 +19,4 @@ public class A(): Z() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(a1: A, b1: A.B): Int {
|
||||
return a1.a + b1.b + b1.z
|
||||
}
|
||||
private fun i(a1: A, b1: A.B) = a1.a + b1.b + b1.z
|
||||
|
||||
+1
-3
@@ -19,6 +19,4 @@ public class A(): Z() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(a1: A, b1: A.B): Int {
|
||||
return a1.a + b1.b + a1.z + b1.z
|
||||
}
|
||||
private fun i(a1: A, b1: A.B) = a1.a + b1.b + a1.z + b1.z
|
||||
|
||||
+1
-3
@@ -7,6 +7,4 @@ fun Z.foo(): Int {
|
||||
return i() + 1
|
||||
}
|
||||
|
||||
private fun Z.i(): Int {
|
||||
return this.a + a
|
||||
}
|
||||
private fun Z.i() = this.a + a
|
||||
|
||||
+1
-3
@@ -7,6 +7,4 @@ fun Z.foo(): Int {
|
||||
return i() + 1
|
||||
}
|
||||
|
||||
private fun Z.i(): Int {
|
||||
return a
|
||||
}
|
||||
private fun Z.i() = a
|
||||
|
||||
+1
-3
@@ -19,6 +19,4 @@ public class A(): Z() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(a1: A, b1: A.B): Int {
|
||||
return a1.a + b1.b + b1.z
|
||||
}
|
||||
private fun i(a1: A, b1: A.B) = a1.a + b1.b + b1.z
|
||||
|
||||
+1
-3
@@ -9,9 +9,7 @@ class A {
|
||||
fun B.foo() = i(this@A, this)
|
||||
}
|
||||
|
||||
private fun i(a1: A, b: B): Int {
|
||||
return a1.a + b.b
|
||||
}
|
||||
private fun i(a1: A, b: B) = a1.a + b.b
|
||||
|
||||
class B {
|
||||
val b = 1
|
||||
|
||||
@@ -9,6 +9,4 @@ fun foo(t: Array<Array<Int>>) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(it: Int): Int {
|
||||
return it + 1
|
||||
}
|
||||
private fun i(it: Int) = it + 1
|
||||
@@ -9,6 +9,4 @@ fun foo(t: Array<Int>) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun b(t: Array<Int>): Boolean {
|
||||
return t.check { it + 1 > 1 }
|
||||
}
|
||||
private fun b(t: Array<Int>) = t.check { it + 1 > 1 }
|
||||
@@ -9,6 +9,4 @@ fun foo(t: Array<Array<Int>>) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun b(it: Array<Int>): Boolean {
|
||||
return it.check { it + 1 > 1 }
|
||||
}
|
||||
private fun b(it: Array<Int>) = it.check { it + 1 > 1 }
|
||||
@@ -9,6 +9,4 @@ fun foo(t: Array<Int>) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(it: Int): Int {
|
||||
return it + 1
|
||||
}
|
||||
private fun i(it: Int) = it + 1
|
||||
+1
-3
@@ -9,6 +9,4 @@ fun foo(a: Int, b: Int, c: Int): Int {
|
||||
return i(a, b, c)
|
||||
}
|
||||
|
||||
private fun i(a: Int, b: Int, c: Int): Int {
|
||||
return (a + b * a - c) + b * c
|
||||
}
|
||||
private fun i(a: Int, b: Int, c: Int) = (a + b * a - c) + b * c
|
||||
|
||||
@@ -13,9 +13,7 @@ public class A() {
|
||||
}
|
||||
}
|
||||
|
||||
private fun i(a: A, t: Int, u: Int, x: Int): Int {
|
||||
return a.bar(t - x, u + x)
|
||||
}
|
||||
private fun i(a: A, t: Int, u: Int, x: Int) = a.bar(t - x, u + x)
|
||||
|
||||
fun foo(a: A, x: Int): Int {
|
||||
val t = 10
|
||||
|
||||
+1
-3
@@ -9,6 +9,4 @@ fun foo<V: Data>(v: V): Pair<Int, V> {
|
||||
return pair(v)
|
||||
}
|
||||
|
||||
private fun <V : Data> pair(v: V): Pair<Int, V> {
|
||||
return Pair(v.x + 10, v)
|
||||
}
|
||||
private fun <V : Data> pair(v: V) = Pair(v.x + 10, v)
|
||||
+1
-3
@@ -10,6 +10,4 @@ fun foo<V: Data>(v: V): Pair<Int, V> where V: DataEx {
|
||||
return pair(v)
|
||||
}
|
||||
|
||||
private fun <V : Data> pair(v: V): Pair<Int, V> where V : DataEx {
|
||||
return Pair(v.x + 10, v)
|
||||
}
|
||||
private fun <V : Data> pair(v: V) where V : DataEx = Pair(v.x + 10, v)
|
||||
+1
-3
@@ -9,6 +9,4 @@ class A<T> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> i(d: Data<T>): Int {
|
||||
return d.t + 1
|
||||
}
|
||||
private fun <T> i(d: Data<T>) = d.t + 1
|
||||
+1
-3
@@ -17,6 +17,4 @@ class A<T: Data>(val t: T) where T: DataEx {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : Data, U : Data, V : Data> i(a: A<T>, b: A.B<U>, v: V): Int where T : DataEx, U : DataExEx, V : DataEx {
|
||||
return a.t.x + b.u.x + v.x
|
||||
}
|
||||
private fun <T : Data, U : Data, V : Data> i(a: A<T>, b: A.B<U>, v: V) where T : DataEx, U : DataExEx, V : DataEx = a.t.x + b.u.x + v.x
|
||||
+1
-3
@@ -14,7 +14,5 @@ class A<T: Data>(val t: T) where T: DataEx {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <U : Data, V : Data> B<U>.i(v: V): Int where U : DataExEx, V : DataEx {
|
||||
return t.x + u.x + v.x
|
||||
}
|
||||
private fun <U : Data, V : Data> B<U>.i(v: V) where U : DataExEx, V : DataEx = t.x + u.x + v.x
|
||||
}
|
||||
+1
-3
@@ -11,8 +11,6 @@ class A<T: Data>(val t: T) where T: DataEx {
|
||||
return i(v)
|
||||
}
|
||||
|
||||
private fun <V : Data> i(v: V): Int where V : DataEx {
|
||||
return t.x + u.x + v.x
|
||||
}
|
||||
private fun <V : Data> i(v: V) where V : DataEx = t.x + u.x + v.x
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -15,6 +15,4 @@ class A<T: Data>(val t: T) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : Data, U : Data, V : Data> i(a: A<T>, b: A.B<U>, v: V): Int {
|
||||
return a.t.x + b.u.x + v.x
|
||||
}
|
||||
private fun <T : Data, U : Data, V : Data> i(a: A<T>, b: A.B<U>, v: V) = a.t.x + b.u.x + v.x
|
||||
+1
-3
@@ -12,7 +12,5 @@ class A<T: Data>(val t: T) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <U : Data, V : Data> B<U>.i(v: V): Int {
|
||||
return t.x + u.x + v.x
|
||||
}
|
||||
private fun <U : Data, V : Data> B<U>.i(v: V) = t.x + u.x + v.x
|
||||
}
|
||||
+1
-3
@@ -9,8 +9,6 @@ class A<T: Data>(val t: T) {
|
||||
return i(v)
|
||||
}
|
||||
|
||||
private fun <V : Data> i(v: V): Int {
|
||||
return t.x + u.x + v.x
|
||||
}
|
||||
private fun <V : Data> i(v: V) = t.x + u.x + v.x
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -12,6 +12,4 @@ class A<T: Data>(val t: T) where T: DataEx {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T : Data, V : Data> A<T>.i(v: V): Int where T : DataEx {
|
||||
return t.x + v.x
|
||||
}
|
||||
private fun <T : Data, V : Data> A<T>.i(v: V) where T : DataEx = t.x + v.x
|
||||
@@ -3,9 +3,7 @@ class A(val n: Int = 1) {
|
||||
val m: Int = 2
|
||||
|
||||
private val i: Int
|
||||
get() {
|
||||
return m + n + 1
|
||||
}
|
||||
get() = m + n + 1
|
||||
|
||||
fun foo(): Int {
|
||||
return i
|
||||
|
||||
@@ -2,9 +2,7 @@
|
||||
val n: Int = 1
|
||||
|
||||
private val i: Int
|
||||
get() {
|
||||
return n + 1
|
||||
}
|
||||
get() = n + 1
|
||||
|
||||
fun foo(): Int {
|
||||
return i
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
// EXTRACTION_TARGET: property with getter
|
||||
trait T {
|
||||
val i: Int
|
||||
get() {
|
||||
return 1
|
||||
}
|
||||
get() = 1
|
||||
|
||||
fun foo(): Int {
|
||||
return i
|
||||
|
||||
Reference in New Issue
Block a user