New J2K: make initial generating code formatting better

This commit is contained in:
Ilya Kirillov
2019-09-26 17:28:16 +03:00
parent f3b53a9532
commit c000f33955
192 changed files with 396 additions and 625 deletions
@@ -1,11 +1,8 @@
import kotlin.reflect.KClass
annotation class Ann(vararg val value: Inner, val test1: Array<InnerParam> = [InnerParam(C::class)])
annotation class Inner
annotation class InnerParam(val value: KClass<*>)
@Ann(value = [Inner(), Inner()], test1 = [InnerParam(C::class)])
class C
@@ -16,4 +13,4 @@ class D
class E
@Ann(value = [Inner()], test1 = [InnerParam(value = C::class)])
class F
class F
+1 -2
View File
@@ -1,6 +1,5 @@
import kotlin.reflect.KClass
annotation class Ann(val i: Int = 1, val i2: IntArray = [1], val i3: IntArray = [1], val klass: KClass<*> = A::class, val klass2: Array<KClass<*>> = [A::class], val klass3: Array<KClass<*>> = [A::class], val ann: Inner = Inner(), val ann2: Array<Inner> = [Inner()], val ann3: Array<Inner> = [Inner(), Inner()])
class A
annotation class Inner
annotation class Inner
+2 -2
View File
@@ -1,4 +1,4 @@
internal annotation class Anon(val stringArray: Array<String>, val intArray: IntArray, // string
internal annotation class Anon(val stringArray: Array<String>, val intArray: IntArray, // string
val string: String)
@Anon(string = "a", stringArray = ["a", "b"], intArray = [1, 2])
@@ -9,4 +9,4 @@ internal annotation class I
internal annotation class J
@Target
internal annotation class K
internal annotation class K
+1 -2
View File
@@ -1,4 +1,3 @@
internal annotation class Anon(val s: String = "a", val stringArray: Array<String> = ["a", "b"], val intArray: IntArray)
@Anon(intArray = [1, 2])
internal class A
internal class A
+4 -1
View File
@@ -1,5 +1,8 @@
internal annotation class Anon(val value: String) {
enum class E { A, B }
enum class E {
A, B
}
companion object {
var field = E.A
}
+1 -2
View File
@@ -1,5 +1,4 @@
internal annotation class Anon(vararg val value: String, val x: Int = 1)
@Anon("a", "b")
internal interface I1
@@ -10,4 +9,4 @@ internal interface I2
internal interface I3
@Anon(value = ["c", "d"])
internal interface I4
internal interface I4
+1 -4
View File
@@ -23,13 +23,10 @@ internal class C {
@Anon5(1)
@Deprecated("")
private val field1 = 0
@Anon5(1)
private val field2 = 0
@Anon5(1)
var field3 = 0
@Anon5(1)
var field4 = 0
@@ -41,4 +38,4 @@ internal class C {
@Anon5(1)
fun bar() {
}
}
}
@@ -1,8 +1,7 @@
internal annotation class An(val value: String)
class Test {
@get:An(value = "get")
@set:An(value = "set")
var id = 0
}
}
+1 -2
View File
@@ -1,6 +1,5 @@
import kotlin.reflect.KClass
internal annotation class Ann(val value: KClass<*>, val other: KClass<*>)
@Ann(other = String::class, value = Any::class)
internal class C
internal class C
+1 -2
View File
@@ -1,9 +1,8 @@
import kotlin.reflect.KClass
internal annotation class Ann(vararg val value: KClass<*>)
@Ann(String::class, Any::class)
internal class C
@Ann
internal class D
internal class D
+1 -3
View File
@@ -5,9 +5,7 @@ package test
class Test(str: String) {
internal var myStr = "String2"
fun sout(str: String) {
// UNNECESSARY_NOT_NULL_ASSERTION heuristic does not work any more, instead we can skip generating !! altogether
fun sout(str: String) { // UNNECESSARY_NOT_NULL_ASSERTION heuristic does not work any more, instead we can skip generating !! altogether
println(str)
}
+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
@@ -1,2 +1 @@
internal class C @Deprecated("")
constructor()
internal class C @Deprecated("") constructor()
+1 -5
View File
@@ -1,8 +1,4 @@
class A {
var b = 0
fun a(i: Int) {
}
fun a(i: Int) {}
}
-1
View File
@@ -1,7 +1,6 @@
internal abstract class C {
fun foo() {
val s1 = f()!!
val s2 = g() ?: error("g should not return null")
val h = s2.hashCode()
}
@@ -1,7 +1,6 @@
class AssignmentAsExpression {
private var field = 0
private var field2 = 0
fun assign(value: Int) {
field = value
val v = field
@@ -11,21 +11,13 @@ internal object Test {
b += c
a = b
//-----
a = b
//-----
a += b
//-----
b = c
a += b
//-----
b += c
a = b
}
@@ -10,21 +10,13 @@ internal object Test {
b += c
a = b
//-----
a = b
//-----
a += b
//-----
b = c
a += b
//-----
a = c.let { b += it; b }
}
}
}
@@ -7,27 +7,20 @@ internal object Test {
var d = 0
val e = 0
//-----
d *= e
c = d
b += c
a = b
val f = a
//-----
//-----
val g = a
//-----
a = b
val h = a
//-----
a += b
val i = a
//-----
b = c
a += b
val j = a
@@ -15,7 +15,6 @@ class Test {
}
companion object {
@JvmStatic
fun main(args: Array<String>) {
val p = Test().toString() + "123"
@@ -17,10 +17,7 @@ object A {
* 2
* 3)
val DIV = (1
/ 2
/ 3)
val PERC = (1
% 2
-2
View File
@@ -4,11 +4,9 @@ fun foo() {
val a = 1
bar(a)
}
run {
val a = 2
bar(a)
}
run { bar(3) }
}
@@ -6,7 +6,6 @@ internal object Library {
internal class User {
fun main() {
Library.ourOut!!.print(1)
}
}
@@ -1,9 +1,7 @@
internal object Library {
fun call() {}
val string: String
get() = ""
}
internal class User {
@@ -1,9 +1,7 @@
internal class Library {
fun call() {}
val string: String
get() = ""
}
internal class User {
@@ -11,7 +9,6 @@ internal class User {
val lib = Library()
lib.call()
lib.string.isEmpty()
Library().call()
Library().string.isEmpty()
}
-1
View File
@@ -1,6 +1,5 @@
internal abstract class A {
internal abstract fun callme()
fun callmetoo() {
print("This is a concrete method.")
}
+1
View File
@@ -1,4 +1,5 @@
internal abstract class Shape {
var color: String? = null
abstract fun area(): Double
}
+1 -3
View File
@@ -1,7 +1,5 @@
internal class A {
internal enum class E {
A,
B,
C
A, B, C
}
}
-1
View File
@@ -3,7 +3,6 @@ object Util {
internal const val protectedStr = ""
internal const val packageStr = ""
private const val privateStr = ""
fun publicMethod() {}
internal fun protectedMethod() {}
internal fun packageMethod() {}
+3 -7
View File
@@ -3,13 +3,9 @@ package test
object Test {
@JvmStatic
fun main(args: Array<String>) {
println()
// Comment
foo()
// Comment1
// Comment2
println() // Comment
foo() // Comment1
// Comment2
.indexOf("s")
}
+3 -10
View File
@@ -2,27 +2,20 @@
package foo
// we use package 'foo'
// imports:
// we need ArrayList
// let's declare a class:
internal class A /* just a sample name*/ : Runnable /* let's implement Runnable */ {
fun foo /* again a sample name */(p: Int /* parameter p */, c: Char /* parameter c */) {
// let's print something:
fun foo /* again a sample name */(p: Int /* parameter p */, c: Char /* parameter c */) { // let's print something:
println("1") // print 1
println("2") // print 2
println("3") // print 3
// end of printing
if (p > 0) { // do this only when p > 0
// we print 4 and return
// we print 4 and return
println("3")
return // do not continue
}
// some code to be added
}
} // end of class A
} // end of class A
+2 -2
View File
@@ -26,7 +26,7 @@ internal class A {
*/
fun foo(param1: String?, param2: String?, param3: String?) {}
companion object { /*it's public*/ /*and static*/ /*and final*/
const val C = 1
companion object {
/*it's public*/ /*and static*/ /*and final*/ const val C = 1
}
}
+15 -17
View File
@@ -1,34 +1,32 @@
internal class A // end of primary constructor body
internal class A // this is a primary constructor
// this is a secondary constructor 1
// end of primary constructor body
@JvmOverloads constructor(p: Int = 1) {
private val v = 1
// this is a secondary constructor 2
constructor(s: String) : this(s.length) {} // end of secondary constructor 2 body
// this is a primary constructor
// this is a secondary constructor 1
// end of secondary constructor 1 body
}
internal class B // end of constructor body
internal class B // this constructor will disappear
// end of constructor body
(private val x: Int) {
fun foo() {}
// this constructor will disappear
}
internal class CtorComment {
var myA = "a"
/*
* The magic of comments
*/
// single line magic comments
}
internal class CtorComment2 /*
internal class CtorComment /*
* The magic of comments
*/
// single line magic comments
{
var myA = "a"
}
internal class CtorComment2 /*
* The magic of comments
*/
// single line magic comments
@@ -1,6 +1,5 @@
class Check {
fun a() {
val d = String() as Int
}
}
+1 -4
View File
@@ -1,6 +1,3 @@
fun foo(b: Boolean) {
if (b)
println("true")
else
println("false")
if (b) println("true") else println("false")
}
-1
View File
@@ -1,7 +1,6 @@
package pack
internal class C @JvmOverloads constructor(arg1: Int, arg2: Int = 0, arg3: Int = 0)
object User {
fun main() {
val c1 = C(100, 100, 100)
-1
View File
@@ -1,5 +1,4 @@
internal class C(arg1: Int, arg2: Int, arg3: Int) {
constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) {
println()
}
@@ -6,7 +6,8 @@ internal class A @Anon5(10) constructor(private val a: Int, private val b: Int)
@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,2 +1,2 @@
internal open class Base(o: Any?, l: Int)
internal class C(private val string: String) : Base(string, string.length)
internal class C(private val string: String) : Base(string, string.length)
+1
View File
@@ -17,6 +17,7 @@ class Identifier {
myHasDollar = hasDollar
myNullable = isNullable
}
}
object User {
@@ -1,7 +1,6 @@
internal class C1(arg1: Int,
arg2: Int,
arg3: Int) {
constructor(x: Int,
y: Int) : this(x, x + y, 0) {
}
@@ -9,4 +8,4 @@ internal class C1(arg1: Int,
internal class C2(private val arg1: Int,
private val arg2: Int,
arg3: Int)
arg3: Int)
@@ -1,5 +1,4 @@
internal class C(private val arg1: Int, private val arg2: Int, private val arg3: Int) {
fun foo(p: Int): Int {
return p
}
@@ -17,4 +16,5 @@ internal class C(private val arg1: Int, private val arg2: Int, private val arg3:
return 0
}
}
}
}
-2
View File
@@ -1,8 +1,6 @@
internal open class Base
internal class C : Base {
constructor(arg1: Int, arg2: Int, arg3: Int) {}
constructor(arg1: Int, arg2: Int) : this(arg1, arg2, 0) {
println()
}
+1 -2
View File
@@ -1,6 +1,5 @@
package pack
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
constructor(a: Int) : this(a, 0, 0, 0, 1) {}
}
}
+1 -3
View File
@@ -1,8 +1,6 @@
package pack
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
constructor(a1: Int, b1: Int, c1: Int) : this(a1, b1, c1, 0, 0) {}
constructor(b: Byte) : this(b.toInt(), 0, 0, 0, 0) {}
}
}
@@ -1,6 +1,5 @@
package pack
internal class C @JvmOverloads constructor(a: Int = 0, b: Int = 0, c: Int = 0, d: Int = 0, e: Int = 0) {
constructor(a: Int, b: Int, c: Int) : this(b, a, c, 0, 0) {}
}
+1 -2
View File
@@ -1,4 +1,3 @@
internal class C private constructor(arg1: Int, arg2: Int, arg3: Int = 0) {
constructor(arg1: Int) : this(arg1, 0, 0) {}
}
}
@@ -3,6 +3,7 @@ internal class C(private val arg1: Int, private val arg2: Int, private val arg3:
constructor(arg1: Int, arg2: Int, other: C) : this(arg1, arg2, 0) {
println(this.arg1 + other.arg2)
}
}
internal class User {
@@ -3,7 +3,6 @@ internal class A {
private var x = 0
constructor() {}
@JvmOverloads
constructor(p: Int, s: String, x: Int = 1) {
this.s = s
@@ -1,38 +1,25 @@
internal class Outer {
private inner class Inner1() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
private constructor(b: Boolean) : this() {}
}
protected inner class Inner2() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
private constructor(b: Boolean) : this() {}
}
internal inner class Inner3() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
private constructor(b: Boolean) : this() {}
}
inner class Inner4() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
private constructor(b: Boolean) : this() {}
}
@@ -42,4 +29,4 @@ internal class Outer {
val inner3 = Inner3(3)
val inner4 = Inner4(4)
}
}
}
@@ -8,39 +8,26 @@ internal object Outer {
}
private class Nested1() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
private constructor(b: Boolean) : this() {}
}
protected class Nested2() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
private constructor(b: Boolean) : this() {}
}
internal class Nested3() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
private constructor(b: Boolean) : this() {}
}
class Nested4() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
private constructor(b: Boolean) : this() {}
}
}
}
@@ -1,21 +1,13 @@
internal class A() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
constructor(f: Float) : this() {}
private constructor(d: Double) : this() {}
}
class B() {
constructor(a: Int) : this() {}
protected constructor(c: Char) : this() {}
internal constructor(f: Float) : this() {}
private constructor(d: Double) : this() {}
}
@@ -1,5 +1,4 @@
internal class C() {
constructor(p: Int) : this() {
println(staticField1 + staticField2)
}
@@ -2,6 +2,7 @@ class X {
internal fun foo() {
val runnable: Runnable = object : Runnable {
var value = 10
override fun run() {
println(value)
}
@@ -1,4 +1,5 @@
class C {
var x: String? = null
internal set
}
@@ -1,7 +1,6 @@
class C {
private var x = ""
internal var other: C? = null
fun getX(): String {
return x
}
@@ -1,7 +1,6 @@
class AAA {
private var x = 42
fun setX(x: Int) {
this.x = x
}
}
}
+2 -2
View File
@@ -1,11 +1,12 @@
internal class A(// comment for field2 setter
// comment for field2 getter
var field2 // comment for field2
: Int) { // Comment for field1
: Int) {
/**
* Comment for field1 setter
*/
// Comment for field1 getter
// Comment for field1
var field1 = 0
// comment for field3 setter
// comment for field3 getter
@@ -21,5 +22,4 @@ internal class A(// comment for field2 setter
get() = 1
set(value) {}
}
@@ -4,6 +4,7 @@ internal interface I {
val isSomething1: Boolean
val isSomething2: Boolean?
val isSomething3: Int
fun isSomething4(): Boolean
fun setSomething4(value: Boolean)
fun isSomething5(): Boolean
+1
View File
@@ -1,4 +1,5 @@
class Test(var id: String, val name: String, val age: Int) {
init {
println(age)
}
@@ -1,3 +1,4 @@
class AAA {
var x = 42
}
}
+1 -2
View File
@@ -1,7 +1,6 @@
class AAA {
private val x = 42
private val other = AAA()
fun getX(): Int {
return other.x
}
@@ -9,4 +8,4 @@ class AAA {
fun issue(): Boolean {
return true
}
}
}
+2 -1
View File
@@ -3,4 +3,5 @@ class AAA {
set(x) {
field += x
}
}
}
@@ -1,6 +1,5 @@
internal class A {
private val s: String? = null
val value: Any?
get() = s
}
@@ -1,6 +1,5 @@
class C {
private var myX = ""
var x: String
get() {
println("getter invoked")
@@ -1,6 +1,5 @@
class C {
private var x = ""
fun getX(): String {
println("getter invoked")
return x
@@ -1,6 +1,5 @@
class C {
var x = ""
fun getX(): String {
println("getter invoked")
return x
@@ -9,4 +8,4 @@ class C {
fun setX(x: String) {
this.x = x
}
}
}
@@ -4,4 +4,5 @@ class C {
println("getter invoked")
return field
}
}
}
@@ -4,4 +4,5 @@ class C {
println("getter invoked")
return field
}
}
}
+2 -2
View File
@@ -4,7 +4,7 @@ class AAA {
}
companion object {
var x = 42
}
}
}
+2
View File
@@ -1,9 +1,11 @@
internal interface I {
val something1: Int
var something2: Int
fun setSomething3(value: Int)
fun getSomething4(): Int
fun setSomething4(value: String?)
val something5: Int
fun setSomething5(value: Int): Int
}
+2 -1
View File
@@ -5,8 +5,9 @@ object AAA {
set(z) {
Other.z = z
}
}
internal object Other {
var z = 0
}
}
+1
View File
@@ -2,6 +2,7 @@ internal interface I {
val isSomething1: Boolean
val isSomething2: Boolean?
val isSomething3: Int
fun isSomething4(): Boolean
fun setSomething4(value: Boolean)
fun isSomething5(): Boolean
+1
View File
@@ -2,6 +2,7 @@ internal interface I {
val something1: Int
val something2: Int
var something3: Int
fun getSomething4(): Int
fun setSomething4(value: Int)
fun getSomething5(): Int
@@ -3,7 +3,6 @@ internal class C {
private val bbb = 0
private val ccc = 0
private val ddd = 0
fun getAaa(): Int {
return bbb
}
@@ -1,6 +1,5 @@
class C {
private var myX = ""
var x: String
get() = myX
set(x) {
@@ -11,4 +10,4 @@ class C {
internal fun foo() {
myX = "a"
}
}
}
@@ -1,6 +1,5 @@
class C {
private var x = ""
fun getX(): String {
return x
}
@@ -13,4 +12,4 @@ class C {
internal fun foo() {
x = "a"
}
}
}
@@ -1,6 +1,5 @@
class C {
protected var x = ""
fun getX(): String {
return x
}
@@ -9,4 +8,4 @@ class C {
println("setter invoked")
this.x = x
}
}
}
@@ -4,4 +4,5 @@ class C {
println("setter invoked")
field = value
}
}
@@ -4,4 +4,5 @@ class C {
println("setter invoked")
field = x
}
}
@@ -4,4 +4,5 @@ class C {
println("old value: " + this.x)
field = x
}
}
}
@@ -1,2 +1,3 @@
class Nya /*comment before*/ /* comment after*/ // and after again
class Nya /*comment before*/
/* comment after*/ // and after again
(/*1*/ /*3*/ /*4*/private val i: Int)
+1 -2
View File
@@ -1,9 +1,8 @@
//Interface
interface Parent {
val x: Unit
}
} //Subclass
//Subclass
class Child : Parent {
override val x: Unit get() {}
}
@@ -1,7 +1,2 @@
@Deprecated("Ph'nglui mglw'nafh\n" +
" Cthulhu R'lyeh wgah'nagl fhtagn.\n" +
" 'In His House at R'lyeh\n" +
" Dead Cthulhu waits dreaming,\n" +
" yet He shall rise and His kingdom\n" +
" shall cover the Earth.'")
class TestDeprecatedInJavadocWithMultilineMessage
@Deprecated("Ph'nglui mglw'nafh\n" + " Cthulhu R'lyeh wgah'nagl fhtagn.\n" + " 'In His House at R'lyeh\n" + " Dead Cthulhu waits dreaming,\n" + " yet He shall rise and His kingdom\n" + " shall cover the Earth.'")
class TestDeprecatedInJavadocWithMultilineMessage
+1
View File
@@ -2,4 +2,5 @@ package demo
internal enum class MyEnum(val color: Int) {
RED(10), BLUE(20);
}
+2 -5
View File
@@ -1,10 +1,7 @@
enum class TestEnum {
A,
B;
A, B;
companion object {
fun parse(): TestEnum {
return A
}
@@ -15,4 +12,4 @@ internal class Go {
fun fn() {
val x = TestEnum.parse()
}
}
}
+2 -4
View File
@@ -1,9 +1,7 @@
enum class E {
A,
B {
A, B {
override fun bar() {}
};
internal open fun bar() {}
}
}
+2 -3
View File
@@ -5,12 +5,11 @@ enum class E(private val p: Int) {
foo(p)
}
},
B(2) {
override fun bar() {}
};
internal fun foo(p: Int) {}
internal abstract fun bar()
}
}
+4 -1
View File
@@ -1,4 +1,7 @@
internal enum class E { FOO }
internal enum class E {
FOO
}
internal object A {
@JvmStatic
fun main(args: Array<String>) {
@@ -1,3 +1,4 @@
internal enum class Color(val code: Int) {
WHITE(21), BLACK(22), RED(23), YELLOW(24), BLUE(25);
}
+1 -6
View File
@@ -1,9 +1,6 @@
internal interface I
internal class C
internal class O
internal class E {
override fun equals(o: Any?): Boolean {
return super.equals(o)
@@ -17,7 +14,6 @@ internal open class B {
}
internal class BB : B()
internal enum class EE {
A, B, C
}
@@ -35,8 +31,7 @@ internal class X {
if (bb1 === bb2) return
if (arr1 == arr2) return
if (ee1 == ee2 || ee1 == null) return
if (s1 !== s2) return
if (c1 != c2) return
}
}
}
-1
View File
@@ -1,5 +1,4 @@
internal interface I
internal class C {
fun foo1(i1: I, i2: I): Boolean {
return i1 == i2
-1
View File
@@ -1,5 +1,4 @@
internal interface I
internal class C {
fun foo1(i1: I?, i2: I?): Boolean {
return i1 == i2
-2
View File
@@ -1,12 +1,10 @@
internal class A {
private var i = byte.toInt()
fun foo() {
i = 10
}
companion object {
val byte: Byte
get() = 0
}
-1
View File
@@ -1,5 +1,4 @@
internal class Foo(a: Int, b: Int)
internal class C {
val f = Foo(1, 2)
}
-1
View File
@@ -1,5 +1,4 @@
internal class Foo(a: Int, b: Int)
internal class C {
var f = Foo(1, 2)
}
@@ -3,10 +3,8 @@ internal class A {
@Deprecated("")
@Volatile
var field1 = 0
@Transient
var field2 = 1
// Should work even for bad modifiers
@Strictfp
var field3 = 2.0
+1 -2
View File
@@ -7,11 +7,10 @@ internal class A {
i *= 2
}
}
var i = 1
while (i < 2000) {
println(i)
i *= 2
}
}
}
}
+1 -2
View File
@@ -9,11 +9,10 @@ internal class A {
j++
}
}
var j = 1
while (j < 2000) {
println(j)
j *= 2
}
}
}
}
+1 -3
View File
@@ -1,6 +1,5 @@
internal class A {
var i = 1
fun foo() {
run {
var i = 1
@@ -9,7 +8,6 @@ internal class A {
i *= 2
}
}
i = 10
}
}
}

Some files were not shown because too many files have changed in this diff Show More