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