Code Insight: Format generated declarations

#KT-11176 Fixed
(cherry picked from commit 3641ad6)
This commit is contained in:
Alexey Sedunov
2016-06-30 15:02:14 +03:00
parent a33f946c14
commit 3ba776fffa
51 changed files with 57 additions and 69 deletions
+1
View File
@@ -123,6 +123,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
###### Issues fixed
- [`KT-11176`](https://youtrack.jetbrains.com/issue/KT-11176) Add a space before '{' in functions generated "Generate hashCode/equals/toString"
- [`KT-12294`](https://youtrack.jetbrains.com/issue/KT-12294) Introduce Property: Fix extraction of expressions referring to primary constructor parameters
- [`KT-12413`](https://youtrack.jetbrains.com/issue/KT-12413) Change Signature: Fix bogus warning about unresolved type parameters/invalid functional type replacement
- [`KT-12084`](https://youtrack.jetbrains.com/issue/KT-12084) Introduce Property: Do not skip outer classes if extractable expression is contained in object literal
@@ -23,9 +23,9 @@ import com.intellij.psi.PsiDocumentManager
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiWhiteSpace
import com.intellij.psi.SmartPointerManager
import com.intellij.psi.codeStyle.CodeStyleManager
import com.intellij.psi.util.PsiTreeUtil
import com.intellij.util.SmartList
import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.util.application.runWriteAction
import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.*
@@ -174,7 +174,7 @@ fun <T : KtDeclaration> insertMembersAfter(
if (otherMembers.isNotEmpty()) {
val body = classOrObject.getOrCreateBody()
var afterAnchor = anchor ?: findInsertAfterAnchor(editor, body) ?: return@runWriteAction emptyList()
var afterAnchor = anchor ?: findInsertAfterAnchor(editor, body) ?: return@runWriteAction emptyList<T>()
otherMembers.mapNotNullTo(insertedMembers) {
if (classOrObject is KtClass && classOrObject.isEnum()) {
val enumEntries = classOrObject.declarations.filterIsInstance<KtEnumEntry>()
@@ -204,6 +204,9 @@ fun <T : KtDeclaration> insertMembersAfter(
}
insertedMembers
}.apply {
val codeStyleManager = CodeStyleManager.getInstance(classOrObject.project)
forEach { codeStyleManager.reformat(it) }
}
}
@@ -45,13 +45,13 @@ private class Visitor(var range: TextRange) : KtTreeVisitorVoid() {
val nextEntry = declaration.nextSiblingOfSameType()
if (nextEntry != null && !declaration.containsToken(KtTokens.COMMA)) {
classBody.addAfter(comma, declaration)
declaration.add(comma)
delta += comma.textLength
}
val prevEntry = declaration.prevSiblingOfSameType()
if (prevEntry != null && !prevEntry.containsToken(KtTokens.COMMA)) {
classBody.addAfter(comma, prevEntry)
prevEntry.add(comma)
delta += comma.textLength
}
}
@@ -7,7 +7,7 @@ class A(val n: IntArray, val s: Array<String>) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -20,7 +20,7 @@ class A(val n: IntArray, val s: Array<String>) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result = Arrays.hashCode(n)
result = 31 * result + Arrays.hashCode(s)
result = 31 * result + f.hashCode()
@@ -4,7 +4,7 @@ class Test {
field = value.toUpperCase()
}
var name: String = ""
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -16,7 +16,7 @@ class Test {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result = serial.hashCode()
result = 31 * result + name.hashCode()
return result
@@ -5,13 +5,13 @@ class Test {
var name: String = ""
get
override fun equals(other: Any?): Boolean{
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
return 0
}
@@ -3,7 +3,7 @@ class A<T>(val n: T) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -14,7 +14,7 @@ class A<T>(val n: T) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
return n?.hashCode() ?: 0
}
}
@@ -4,7 +4,7 @@ class A<T>(val n: T) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is A<*>) return false
@@ -13,7 +13,7 @@ class A<T>(val n: T) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
return n?.hashCode() ?: 0
}
}
@@ -5,7 +5,7 @@ class A(val n: Int, val s: String) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -18,7 +18,7 @@ class A(val n: Int, val s: String) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result = n
result = 31 * result + s.hashCode()
result = 31 * result + f.hashCode()
@@ -5,7 +5,7 @@ class A(val n: Int?, val s: String) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -18,7 +18,7 @@ class A(val n: Int?, val s: String) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result = n ?: 0
result = 31 * result + s.hashCode()
result = 31 * result + (f?.hashCode() ?: 0)
@@ -10,7 +10,7 @@ class A(val n: Int, val s: String) : X() {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
if (!super.equals(other)) return false
@@ -24,7 +24,7 @@ class A(val n: Int, val s: String) : X() {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + n
result = 31 * result + s.hashCode()
@@ -3,7 +3,7 @@ class A(val result: Int, val s: String) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -15,7 +15,7 @@ class A(val result: Int, val s: String) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result1 = result
result1 = 31 * result1 + s.hashCode()
return result1
@@ -4,13 +4,13 @@ class A {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
return 0
}
}
@@ -9,14 +9,14 @@ class A : X() {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
if (!super.equals(other)) return false
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
return super.hashCode()
}
}
@@ -7,7 +7,7 @@ class A(val n: IntArray?, val s: Array<String>?) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -20,7 +20,7 @@ class A(val n: IntArray?, val s: Array<String>?) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result = n?.let { Arrays.hashCode(it) } ?: 0
result = 31 * result + (s?.let { Arrays.hashCode(it) } ?: 0)
result = 31 * result + f.hashCode()
@@ -3,7 +3,7 @@ class A(val n: Int) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -14,7 +14,7 @@ class A(val n: Int) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
return n
}
}
@@ -3,7 +3,7 @@ class A(val n: Int?) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
@@ -14,7 +14,7 @@ class A(val n: Int?) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
return n ?: 0
}
}
@@ -4,7 +4,7 @@ class A(val n: Int) {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other !is A) return false
@@ -13,7 +13,7 @@ class A(val n: Int) {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
return n
}
}
@@ -3,7 +3,7 @@ class A(val n: Int) : X() {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
if (!super.equals(other)) return false
@@ -15,7 +15,7 @@ class A(val n: Int) : X() {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + n
return result
@@ -8,7 +8,7 @@ class A(val n: Int) : X() {
}
<caret>override fun equals(other: Any?): Boolean{
<caret>override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other?.javaClass != javaClass) return false
if (!super.equals(other)) return false
@@ -20,7 +20,7 @@ class A(val n: Int) : X() {
return true
}
override fun hashCode(): Int{
override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + n
return result
@@ -8,7 +8,7 @@ class A(val n: IntArray, val s: Array<String>) {
}
override fun toString(): String{
override fun toString(): String {
return "A(" +
"n=${Arrays.toString(n)}," +
"s=${Arrays.toString(s)}," +
@@ -5,7 +5,7 @@ class Test {
field = value.toUpperCase()
}
var name: String = ""
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "Test(" +
"serial='$serial'," +
"name='$name'" +
@@ -6,7 +6,7 @@ class A(val n: Int, val s: String) {
}
override fun toString(): String{
override fun toString(): String {
return "A(" +
"n=$n," +
"s='$s'," +
@@ -11,7 +11,7 @@ class A(val n: Int, val s: String) : X() {
}
override fun toString(): String{
override fun toString(): String {
return "A(" +
"n=$n," +
"s='$s'," +
@@ -4,7 +4,7 @@ class A {
}
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "A()"
}
}
@@ -4,7 +4,7 @@ class A(val n: Int) {
}
override fun toString(): String{
override fun toString(): String {
return "A(" +
"n=$n" +
")"
@@ -9,7 +9,7 @@ class A : X() {
}
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "A()" +
" ${super.toString()}"
}
@@ -8,7 +8,7 @@ class A(val n: IntArray, val s: Array<String>) {
}
override fun toString(): String{
override fun toString(): String {
return "A(n=${Arrays.toString(n)}, s=${Arrays.toString(s)}, f=$f)"
}
}
@@ -4,7 +4,7 @@ class Test {
field = value.toUpperCase()
}
var name: String = ""
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "Test(serial='$serial', name='$name')"
}
@@ -5,7 +5,7 @@ class Test {
var name: String = ""
get
override fun toString(): String{
override fun toString(): String {
return "Test()"
}
@@ -6,7 +6,7 @@ class A(val n: Int, val s: String) {
}
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "A(n=$n, s='$s', f=$f)"
}
}
@@ -11,7 +11,7 @@ class A(val n: Int, val s: String) : X() {
}
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "A(n=$n, s='$s', f=$f) ${super.toString()}"
}
}
@@ -4,7 +4,7 @@ class A {
}
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "A()"
}
}
@@ -4,7 +4,7 @@ class A(val n: Int) {
}
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "A(n=$n)"
}
}
@@ -9,7 +9,7 @@ class A : X() {
}
<caret>override fun toString(): String{
<caret>override fun toString(): String {
return "A() ${super.toString()}"
}
}
@@ -2,7 +2,6 @@
class A<T>(val n: T) {
operator fun unaryPlus(): A<T> = throw Exception()
infix operator fun plus(t: T): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -2,7 +2,6 @@
class A<T>(val n: T) {
fun plus(i: Int, s: String): A<T> = throw Exception()
infix operator fun plus(t: T): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -2,7 +2,6 @@
class A<T>(val n: T) {
fun foo(a: Int): A<T> = throw Exception()
fun foo(a: T, s: String): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -2,7 +2,6 @@
class A<T>(val n: T) {
fun foo(i: Int, s: String): A<T> = throw Exception()
fun foo(i: T): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -2,7 +2,6 @@
class Foo<T> {
operator fun component1(): Int { return 0 }
operator fun component2(): Int { return 0 }
operator fun component3(): Any {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -2,7 +2,6 @@
class Foo<T> {
operator fun component1(): Int { return 0 }
operator fun component2(): Int { return 0 }
operator fun component3(): String {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -3,7 +3,6 @@ import kotlin.reflect.KProperty
class F {
operator fun setValue(x: X, property: KProperty<*>, i: Int) { }
operator fun getValue(x: X, property: KProperty<*>): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -3,7 +3,6 @@ import kotlin.reflect.KProperty
class F {
operator fun getValue(x: X, property: KProperty<*>): Int = 1
operator fun setValue(x: X, property: KProperty<*>, i: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -1,7 +1,6 @@
// "Create member function 'next'" "true"
class FooIterator<T> {
operator fun hasNext(): Boolean { return false }
operator fun next(): Any {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -1,7 +1,6 @@
// "Create member function 'next'" "true"
class FooIterator<T> {
operator fun hasNext(): Boolean { return false }
operator fun next(): Int {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -1,7 +1,6 @@
// "Create member function 'next'" "true"
class FooIterator<T> {
operator fun hasNext(): Boolean { return false }
operator fun next(): T {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -1,7 +1,6 @@
// "Create member function 'set'" "true"
class A {
operator fun get(s: String): Int = 1
operator fun set(s: String, value: Int) {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -2,7 +2,6 @@
class A<T>(val n: T) {
operator fun minus(n: Int): A<T> = throw Exception()
operator fun unaryMinus(): A<T> {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
}
@@ -3,7 +3,6 @@ open class Base()
class Creation {
constructor(f: Int)
constructor()
}
val v = Creation()
@@ -5,7 +5,6 @@ open class Base(val f: Int)
class Creation: Base {
constructor(f: Int): super(f)
constructor() : super(<caret>)
}
val v = Creation()
@@ -3,7 +3,6 @@
class CtorSecondary() {
constructor(p: Int) : this()
constructor<caret>(i: Int, i1: Int)
}