New J2K: call reformat code & shorten references processings only single time

This commit is contained in:
Ilya Kirillov
2020-02-17 19:23:32 +03:00
parent ee0ec421ce
commit 810966e408
48 changed files with 22 additions and 89 deletions
@@ -274,13 +274,6 @@ private val processings: List<NamedPostProcessingGroup> = listOf(
ClearUnknownLabelsProcessing() ClearUnknownLabelsProcessing()
) )
), ),
NamedPostProcessingGroup(
"Formatting code",
listOf(
FormatCodeProcessing(),
ShortenReferenceProcessing()
)
),
NamedPostProcessingGroup( NamedPostProcessingGroup(
"Cleaning up code", "Cleaning up code",
listOf( listOf(
@@ -301,10 +294,10 @@ private val processings: List<NamedPostProcessingGroup> = listOf(
) )
), ),
NamedPostProcessingGroup( NamedPostProcessingGroup(
"Optimizing imports", "Optimizing imports and formatting code",
listOf( listOf(
OptimizeImportsProcessing(),
ShortenReferenceProcessing(), ShortenReferenceProcessing(),
OptimizeImportsProcessing(),
FormatCodeProcessing() FormatCodeProcessing()
) )
) )
@@ -263,10 +263,11 @@ private class ConvertGettersAndSettersToPropertyStatefulProcessing(
private fun KtExpression.isReferenceToThis() = private fun KtExpression.isReferenceToThis() =
when (this) { when (this) {
is KtThisExpression -> instanceReference.resolve() == getStrictParentOfType<KtClassOrObject>() is KtThisExpression -> instanceReference
is KtReferenceExpression -> resolve() == getStrictParentOfType<KtClassOrObject>() is KtReferenceExpression -> this
else -> false is KtQualifiedExpression -> selectorExpression as? KtReferenceExpression
} else -> null
}?.resolve() == getStrictParentOfType<KtClassOrObject>()
private fun KtElement.usages(scope: PsiElement? = null) = private fun KtElement.usages(scope: PsiElement? = null) =
searcher.search(this, scope) searcher.search(this, scope)
@@ -19,14 +19,13 @@ import org.jetbrains.kotlin.idea.references.KtSimpleNameReference
import org.jetbrains.kotlin.idea.references.mainReference import org.jetbrains.kotlin.idea.references.mainReference
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType import org.jetbrains.kotlin.psi.psiUtil.collectDescendantsOfType
import org.jetbrains.kotlin.psi.psiUtil.getPossiblyQualifiedCallExpression
import org.jetbrains.kotlin.psi.psiUtil.isAncestor import org.jetbrains.kotlin.psi.psiUtil.isAncestor
fun KtExpression.unpackedReferenceToProperty(): KtProperty? = fun KtExpression.unpackedReferenceToProperty(): KtProperty? =
when (this) { when (this) {
is KtDotQualifiedExpression -> is KtDotQualifiedExpression -> selectorExpression as? KtNameReferenceExpression
if (receiverExpression is KtThisExpression) selectorExpression as? KtNameReferenceExpression
else null
is KtNameReferenceExpression -> this is KtNameReferenceExpression -> this
else -> null else -> null
}?.references }?.references
@@ -3,15 +3,12 @@ package test
open class B { open class B {
val fromB1: String val fromB1: String
get() = "" get() = ""
var fromB2: String? var fromB2: String?
get() = "" get() = ""
set(value) {} set(value) {}
var fromB3: String? var fromB3: String?
get() = "" get() = ""
set(value) {} set(value) {}
var fromB4: String? var fromB4: String?
get() = "" get() = ""
set(value) {} set(value) {}
@@ -2,10 +2,8 @@ package test
abstract class C internal constructor(override val something1: Int) : B(), I { abstract class C internal constructor(override val something1: Int) : B(), I {
private var mySomething6 = 0 private var mySomething6 = 0
override val something2: Int override val something2: Int
get() = 0 get() = 0
override var something3: Int override var something3: Int
get() = 0 get() = 0
set(value) {} set(value) {}
@@ -30,5 +28,4 @@ abstract class C internal constructor(override val something1: Int) : B(), I {
override fun setFromB5(value: String?) { override fun setFromB5(value: String?) {
super.setFromB5(value) super.setFromB5(value)
} }
} }
@@ -1,7 +1,6 @@
class SomeServiceUsage { class SomeServiceUsage {
val service: SomeService val service: SomeService
get() = SomeService.getInstanceNotNull() get() = SomeService.getInstanceNotNull()
val serviceNullable: SomeService val serviceNullable: SomeService
get() = SomeService.getInstanceNullable() get() = SomeService.getInstanceNullable()
@@ -10,6 +10,5 @@ internal open class ClassWithStatics {
@JvmField @JvmField
var staticNonFinalField = 1 var staticNonFinalField = 1
var value = 0 var value = 0
} }
} }
@@ -3,5 +3,4 @@ class Test {
@get:An(value = "get") @get:An(value = "get")
@set:An(value = "set") @set:An(value = "set")
var id = 0 var id = 0
} }
+1 -1
View File
@@ -2,7 +2,7 @@ import javaApi.SpecialExternal
//Annotation class: //Annotation class:
annotation class Special(val names: Array<String> //array is used annotation class Special(val names: Array<String> //array is used
) //Class with annotation: ) //Class with annotation:
@Special(names = ["name1"]) @Special(names = ["name1"])
class JClass class JClass
+2 -5
View File
@@ -6,24 +6,21 @@ internal class A // this is a primary constructor
// this is a secondary constructor 2 // this is a secondary constructor 2
constructor(s: String) : this(s.length) {} // end of secondary constructor 2 body constructor(s: String) : this(s.length) {} // end of secondary constructor 2 body
// end of secondary constructor 1 body // end of secondary constructor 1 body
} }
internal class B // this constructor will disappear internal class B // this constructor will disappear
// end of constructor body // end of constructor body
(private val x: Int) { (private val x: Int) {
fun foo() {} fun foo() {}
} }
internal class CtorComment /* internal class CtorComment /*
* The magic of comments * The magic of comments
*/ */
// single line magic comments // single line magic comments
{ {
var myA = "a" var myA = "a"
} }
internal class CtorComment2 /* internal class CtorComment2 /*
@@ -8,5 +8,4 @@ class Foo {
//some comment 2 //some comment 2
if (state == 2) println("2") if (state == 2) println("2")
} }
} }
-1
View File
@@ -11,7 +11,6 @@ internal class C(val myArg1: Int) {
myArg2 = arg2 myArg2 = arg2
myArg3 = 0 myArg3 = 0
} }
} }
object User { object User {
@@ -1,13 +1,11 @@
import javaApi.Anon5 import javaApi.Anon5
internal class A @Anon5(10) constructor(private val a: Int, private val b: Int) { internal class A @Anon5(10) constructor(private val a: Int, private val b: Int) {
// this constructor will not be replaced by default parameter value in primary because of this annotation // this constructor will not be replaced by default parameter value in primary because of this annotation
@Deprecated("") @Deprecated("")
constructor(a: Int) : this(a, 1) { constructor(a: Int) : this(a, 1) {
} }
} }
internal class B @Anon5(11) constructor() internal class B @Anon5(11) constructor()
internal class C @Anon5(12) private constructor() internal class C @Anon5(12) private constructor()
@@ -1,5 +1,4 @@
internal class C(private val field: Int) { internal class C(private val field: Int) {
init { init {
println(field) println(field)
} }
@@ -17,7 +17,6 @@ class Identifier<T> {
myHasDollar = hasDollar myHasDollar = hasDollar
myNullable = isNullable myNullable = isNullable
} }
} }
object User { object User {
-1
View File
@@ -17,7 +17,6 @@ class Identifier {
myHasDollar = hasDollar myHasDollar = hasDollar
myNullable = isNullable myNullable = isNullable
} }
} }
object User { object User {
@@ -16,5 +16,4 @@ internal class C(private val arg1: Int, private val arg2: Int, private val arg3:
return 0 return 0
} }
} }
} }
@@ -1,9 +1,7 @@
internal class C(private val arg1: Int, private val arg2: Int, private val arg3: Int) { internal class C(private val arg1: Int, private val arg2: Int, private val arg3: Int) {
constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) { constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) {
println(this.arg1 + other.arg2) println(this.arg1 + other.arg2)
} }
} }
internal class User { internal class User {
@@ -1,4 +1,3 @@
class C { class C {
var x: String? = null var x: String? = null
} }
+1 -1
View File
@@ -1,4 +1,4 @@
internal class A(// comment for field2 setter internal class A( // comment for field2 setter
// comment for field2 getter // comment for field2 getter
var field2 // comment for field2 var field2 // comment for field2
: Int) { : Int) {
@@ -3,5 +3,4 @@ class Test(var count: Int) {
fun inc() { fun inc() {
count++ count++
} }
} }
@@ -1,4 +1,3 @@
class AAA { class AAA {
var x = 42 var x = 42
} }
-1
View File
@@ -3,5 +3,4 @@ class AAA {
set(x) { set(x) {
field += x field += x
} }
} }
@@ -4,5 +4,4 @@ class C {
println("getter invoked") println("getter invoked")
return field return field
} }
} }
@@ -4,5 +4,4 @@ class C {
println("getter invoked") println("getter invoked")
return field return field
} }
} }
@@ -5,6 +5,5 @@ class AAA {
companion object { companion object {
var x = 42 var x = 42
} }
} }
-1
View File
@@ -5,7 +5,6 @@ object AAA {
set(z) { set(z) {
Other.z = z Other.z = z
} }
} }
internal object Other { internal object Other {
-9
View File
@@ -18,15 +18,12 @@ internal interface I1 : I {
internal open class B { internal open class B {
open val fromB1: String open val fromB1: String
get() = "" get() = ""
open var fromB2: String? open var fromB2: String?
get() = "" get() = ""
set(value) {} set(value) {}
open var fromB3: String? open var fromB3: String?
get() = "" get() = ""
set(value) {} set(value) {}
open var fromB4: String? open var fromB4: String?
get() = "" get() = ""
set(value) {} set(value) {}
@@ -36,10 +33,8 @@ internal open class B {
internal abstract class C(override val something1: Int) : B(), I { internal abstract class C(override val something1: Int) : B(), I {
private var mySomething6 = 0 private var mySomething6 = 0
override val something2: Int override val something2: Int
get() = 0 get() = 0
override var something3: Int override var something3: Int
get() = 0 get() = 0
set(value) {} set(value) {}
@@ -59,19 +54,16 @@ internal abstract class C(override val something1: Int) : B(), I {
override val fromB1: String override val fromB1: String
get() = super.fromB1 get() = super.fromB1
override var fromB2: String? override var fromB2: String?
get() = super.fromB2 get() = super.fromB2
set(value) { set(value) {
super.fromB2 = value super.fromB2 = value
} }
override var fromB3: String? override var fromB3: String?
get() = super.fromB3 get() = super.fromB3
set(fromB3) { set(fromB3) {
super.fromB3 = fromB3 super.fromB3 = fromB3
} }
override var fromB4: String? override var fromB4: String?
get() = super.fromB4 get() = super.fromB4
set(value) { set(value) {
@@ -85,5 +77,4 @@ internal abstract class C(override val something1: Int) : B(), I {
override fun setFromB5(value: String?) { override fun setFromB5(value: String?) {
super.setFromB5(value) super.setFromB5(value)
} }
} }
@@ -8,25 +8,21 @@ internal open class A : KotlinClassWithProperties() {
set(s) { set(s) {
super.someVar1 = s super.someVar1 = s
} }
override var someVar2: String override var someVar2: String
get() = super.someVar2 get() = super.someVar2
set(someVar2) { set(someVar2) {
super.someVar2 = someVar2 super.someVar2 = someVar2
} }
override var someVar3: String override var someVar3: String
get() = super.someVar3 get() = super.someVar3
set(s) { set(s) {
super.someVar3 = s super.someVar3 = s
} }
override var someVar4: String override var someVar4: String
get() = super.someVar4 get() = super.someVar4
set(someVar4) { set(someVar4) {
super.someVar4 = someVar4 super.someVar4 = someVar4
} }
override val someVal: String override val someVal: String
get() = super.someVal get() = super.someVal
@@ -4,5 +4,4 @@ class C {
println("setter invoked") println("setter invoked")
field = value field = value
} }
} }
@@ -4,5 +4,4 @@ class C {
println("setter invoked") println("setter invoked")
field = x field = x
} }
} }
@@ -4,5 +4,4 @@ class C {
println("old value: " + this.x) println("old value: " + this.x)
field = x field = x
} }
} }
@@ -1,3 +1,3 @@
class Nya /*comment before*/ class Nya /*comment before*/
/* comment after*/ // and after again /* comment after*/ // and after again
(/*1*/ /*3*/ /*4*/private val i: Int) ( /*1*/ /*3*/ /*4*/private val i: Int)
@@ -4,7 +4,6 @@ internal class CtorComment
*/ */
{ {
var myA = "str" var myA = "str"
} }
internal class CtorComment2 internal class CtorComment2
-1
View File
@@ -11,5 +11,4 @@ enum class E(private val p: Int) {
fun foo(p: Int) {} fun foo(p: Int) {}
abstract fun bar() abstract fun bar()
} }
@@ -4,5 +4,4 @@ internal class `$$`(val `$$$`: `$$$$$`) : `$`() {
fun `$$$$$$`(): `$$$$$` { fun `$$$$$$`(): `$$$$$` {
return `$$$` return `$$$`
} }
} }
-1
View File
@@ -6,5 +6,4 @@ class TestValReassign(private val s1: String?) {
constructor(s1: String?, s2: String?) : this(s1) { constructor(s1: String?, s2: String?) : this(s1) {
this.s2 = s2 this.s2 = s2
} }
} }
+1 -2
View File
@@ -4,5 +4,4 @@ class TestNumberConversionInSetter {
fun init() { fun init() {
d = 1.0 d = 1.0
} }
}
}
-2
View File
@@ -1,5 +1,3 @@
internal class X(private val list: List<Y>) { internal class X(private val list: List<Y>) {
internal inner class Y internal inner class Y
} }
-1
View File
@@ -17,7 +17,6 @@ class Identifier<T> {
myHasDollar = hasDollar myHasDollar = hasDollar
myNullable = isNullable myNullable = isNullable
} }
} }
object User { object User {
-1
View File
@@ -6,7 +6,6 @@ class Language(protected var code: String) : Serializable {
override fun toString(): String { override fun toString(): String {
return code return code
} }
} }
internal open class Base { internal open class Base {
-1
View File
@@ -12,5 +12,4 @@ class Language(protected var code: String) : Serializable {
var SWEDISH = Language("sv") var SWEDISH = Language("sv")
private const val serialVersionUID = -2442762969929206780L private const val serialVersionUID = -2442762969929206780L
} }
} }
@@ -4,5 +4,4 @@ internal class C(private val s: String?) {
print("not null") print("not null")
} }
} }
} }
@@ -1,5 +1,4 @@
internal class C(private val s: String?) { internal class C(private val s: String?) {
init { init {
if (s == null) { if (s == null) {
print("null") print("null")
@@ -8,7 +8,6 @@ class Test {
private val isD: Boolean private val isD: Boolean
private get() = true private get() = true
private val e = E() private val e = E()
class E { class E {
@@ -1,7 +1,7 @@
class Test { class Test {
var s = """ var s = """
asdf asdf
nadfadsf nadfadsf
asdfasdf asdfasdf
""".trimIndent() """.trimIndent()
} }
-1
View File
@@ -1,7 +1,6 @@
package test package test
abstract class Base(protected var field: Int) abstract class Base(protected var field: Int)
class Derived(value: Int) : Base(value) { class Derived(value: Int) : Base(value) {
private val usage: View = object : View() { private val usage: View = object : View() {
override fun click() { override fun click() {
@@ -1,6 +1,6 @@
// !specifyLocalVariableTypeByDefault: true // !specifyLocalVariableTypeByDefault: true
fun foo(list: List<String?>) { fun foo(list: List<String?>) {
val array = IntArray(10) val array: IntArray = IntArray(10)
for (i: Int in 0..9) { for (i: Int in 0..9) {
array[i] = i array[i] = i
} }