Misc: Use TODO() consistently in implementation stubs

#KT-13589 Fixed
This commit is contained in:
Alexey Sedunov
2016-08-25 17:23:11 +03:00
parent 639186ddae
commit 89c39b9762
34 changed files with 119 additions and 53 deletions
+1
View File
@@ -100,6 +100,7 @@ These artifacts include extensions for the types available in the latter JDKs, s
- [`KT-13542`](https://youtrack.jetbrains.com/issue/KT-13542) Rename: Do not search parameter text occurrences outside of its containing declaration - [`KT-13542`](https://youtrack.jetbrains.com/issue/KT-13542) Rename: Do not search parameter text occurrences outside of its containing declaration
- [`KT-8672`](https://youtrack.jetbrains.com/issue/KT-8672) Rename: Optimize search of parameter references in calls with named arguments - [`KT-8672`](https://youtrack.jetbrains.com/issue/KT-8672) Rename: Optimize search of parameter references in calls with named arguments
- [`KT-9285`](https://youtrack.jetbrains.com/issue/KT-9285) Rename: Optimize search of private class members - [`KT-9285`](https://youtrack.jetbrains.com/issue/KT-9285) Rename: Optimize search of private class members
- [`KT-13589`](https://youtrack.jetbrains.com/issue/KT-13589) Use TODO() consistently in implementation stubs
#### Intention actions, inspections and quickfixes #### Intention actions, inspections and quickfixes
@@ -4,7 +4,7 @@ interface I {
class A : I { class A : I {
override val someVal: String? override val someVal: String?
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
// ELEMENT_TEXT: "override val someVal: String?" // ELEMENT_TEXT: "override val someVal: String?"
@@ -4,7 +4,7 @@ interface I {
class A : I { class A : I {
override val someVal: String? override val someVal: String?
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
// ELEMENT_TEXT: "override val someVal: String?" // ELEMENT_TEXT: "override val someVal: String?"
@@ -4,7 +4,7 @@ interface I {
class A : I { class A : I {
override var someVar: String override var someVar: String
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
set(value) { set(value) {
} }
} }
@@ -182,9 +182,9 @@ fun generateUnsupportedOrSuperCall(
bodyType: OverrideMemberChooserObject.BodyType bodyType: OverrideMemberChooserObject.BodyType
): String { ): String {
if (bodyType == OverrideMemberChooserObject.BodyType.EMPTY) { if (bodyType == OverrideMemberChooserObject.BodyType.EMPTY) {
if (descriptor !is FunctionDescriptor) return "throw UnsupportedOperationException()" val templateKind = if (descriptor is FunctionDescriptor) TemplateKind.FUNCTION else TemplateKind.PROPERTY_INITIALIZER
return getFunctionBodyTextFromTemplate(project, return getFunctionBodyTextFromTemplate(project,
TemplateKind.FUNCTION, templateKind,
descriptor.name.asString(), descriptor.name.asString(),
descriptor.returnType?.let { IdeDescriptorRenderers.SOURCE_CODE.renderType(it) } ?: "Unit", descriptor.returnType?.let { IdeDescriptorRenderers.SOURCE_CODE.renderType(it) } ?: "Unit",
null) null)
@@ -25,11 +25,15 @@ import org.jetbrains.kotlin.name.FqName
import java.util.* import java.util.*
private val FUNCTION_BODY_TEMPLATE = "New Kotlin Function Body.kt" private val FUNCTION_BODY_TEMPLATE = "New Kotlin Function Body.kt"
private val PROPERTY_INITIALIZER_TEMPLATE = "New Kotlin Property Initializer.kt"
private val SECONDARY_CONSTRUCTOR_BODY_TEMPLATE = "New Kotlin Secondary Constructor Body.kt" private val SECONDARY_CONSTRUCTOR_BODY_TEMPLATE = "New Kotlin Secondary Constructor Body.kt"
private val ATTRIBUTE_FUNCTION_NAME = "FUNCTION_NAME" private val ATTRIBUTE_FUNCTION_NAME = "FUNCTION_NAME"
private val ATTRIBUTE_PROPERTY_NAME = "PROPERTY_NAME"
enum class TemplateKind(val templateFileName: String) { enum class TemplateKind(val templateFileName: String) {
FUNCTION(FUNCTION_BODY_TEMPLATE), SECONDARY_CONSTRUCTOR(SECONDARY_CONSTRUCTOR_BODY_TEMPLATE) FUNCTION(FUNCTION_BODY_TEMPLATE),
SECONDARY_CONSTRUCTOR(SECONDARY_CONSTRUCTOR_BODY_TEMPLATE),
PROPERTY_INITIALIZER(PROPERTY_INITIALIZER_TEMPLATE)
} }
fun getFunctionBodyTextFromTemplate( fun getFunctionBodyTextFromTemplate(
@@ -48,7 +52,11 @@ fun getFunctionBodyTextFromTemplate(
properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, classFqName.shortName().asString()) properties.setProperty(FileTemplate.ATTRIBUTE_SIMPLE_CLASS_NAME, classFqName.shortName().asString())
} }
if (name != null) { if (name != null) {
properties.setProperty(ATTRIBUTE_FUNCTION_NAME, name) val attribute = when (kind) {
TemplateKind.FUNCTION, TemplateKind.SECONDARY_CONSTRUCTOR -> ATTRIBUTE_FUNCTION_NAME
TemplateKind.PROPERTY_INITIALIZER -> ATTRIBUTE_PROPERTY_NAME
}
properties.setProperty(attribute, name)
} }
return try { return try {
@@ -0,0 +1 @@
TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
@@ -0,0 +1,38 @@
<html>
<body>
<table border="0" cellpadding="2" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td colspan="3"><font face="verdana" size="-1">This is a built-in template used for filling the initializer of a Kotlin property
each time it is generated by the program, e.g. when using the <b>Create Property from Usage</b> intention action.<br>
The template is editable. Along with Kotlin expressions and comments, you can also use the predefined variables
that will be then expanded into the corresponding values.</font>
</td>
</tr>
</table>
<table border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
<tr>
<td colspan="3"><font face="verdana" size="-1">Predefined variables will take the following values:</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${RETURN_TYPE}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">a type of a created property</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${PROPERTY_NAME}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">name of the created property</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${CLASS_NAME}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">qualified name of the class where property is created</font></td>
</tr>
<tr>
<td valign="top"><nobr><font face="verdana" size="-2" color="#7F0000"><b><i>${SIMPLE_CLASS_NAME}</i></b></font></nobr></td>
<td width="10">&nbsp;</td>
<td valign="top"><font face="verdana" size="-1">non-qualified name of the class where property is created</font></td>
</tr>
</table>
</body>
</html>
@@ -28,14 +28,18 @@ import com.intellij.util.SmartList
import org.jetbrains.kotlin.asJava.toLightMethods import org.jetbrains.kotlin.asJava.toLightMethods
import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.intentions.SelfTargetingRangeIntention import org.jetbrains.kotlin.idea.core.TemplateKind
import org.jetbrains.kotlin.idea.intentions.setReceiverType import org.jetbrains.kotlin.idea.core.getFunctionBodyTextFromTemplate
import org.jetbrains.kotlin.idea.core.moveCaret import org.jetbrains.kotlin.idea.core.moveCaret
import org.jetbrains.kotlin.idea.core.unblockDocument import org.jetbrains.kotlin.idea.core.unblockDocument
import org.jetbrains.kotlin.idea.intentions.SelfTargetingRangeIntention
import org.jetbrains.kotlin.idea.intentions.setReceiverType
import org.jetbrains.kotlin.idea.quickfix.createFromUsage.callableBuilder.getReturnTypeReference
import org.jetbrains.kotlin.idea.references.KtReference import org.jetbrains.kotlin.idea.references.KtReference
import org.jetbrains.kotlin.idea.util.ImportInsertHelper import org.jetbrains.kotlin.idea.util.ImportInsertHelper
import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.containingClassOrObject
import org.jetbrains.kotlin.utils.addIfNotNull import org.jetbrains.kotlin.utils.addIfNotNull
class ConvertMemberToExtensionIntention : SelfTargetingRangeIntention<KtCallableDeclaration>(KtCallableDeclaration::class.java, "Convert member to extension"), LowPriorityAction { class ConvertMemberToExtensionIntention : SelfTargetingRangeIntention<KtCallableDeclaration>(KtCallableDeclaration::class.java, "Convert member to extension"), LowPriorityAction {
@@ -110,17 +114,25 @@ class ConvertMemberToExtensionIntention : SelfTargetingRangeIntention<KtCallable
} }
} }
val bodyText = getFunctionBodyTextFromTemplate(
project,
if (extension is KtFunction) TemplateKind.FUNCTION else TemplateKind.PROPERTY_INITIALIZER,
extension.name,
extension.getReturnTypeReference()?.text ?: "Unit",
extension.containingClassOrObject?.fqName
)
when (extension) { when (extension) {
is KtFunction -> { is KtFunction -> {
if (!extension.hasBody()) { if (!extension.hasBody()) {
//TODO: methods in PSI for setBody //TODO: methods in PSI for setBody
extension.add(psiFactory.createBlock(THROW_UNSUPPORTED_OPERATION_EXCEPTION)) extension.add(psiFactory.createBlock(bodyText))
selectBody(extension) selectBody(extension)
} }
} }
is KtProperty -> { is KtProperty -> {
val templateProperty = psiFactory.createDeclaration<KtProperty>("var v: Any\nget()=$THROW_UNSUPPORTED_OPERATION_EXCEPTION\nset(value){$THROW_UNSUPPORTED_OPERATION_EXCEPTION}") val templateProperty = psiFactory.createDeclaration<KtProperty>("var v: Any\nget()=$bodyText\nset(value){\n$bodyText\n}")
val templateGetter = templateProperty.getter!! val templateGetter = templateProperty.getter!!
val templateSetter = templateProperty.setter!! val templateSetter = templateProperty.setter!!
@@ -185,9 +197,6 @@ class ConvertMemberToExtensionIntention : SelfTargetingRangeIntention<KtCallable
} }
} }
//TODO: reuse TEMPLATE_FROM_USAGE_FUNCTION_BODY
private val THROW_UNSUPPORTED_OPERATION_EXCEPTION = "throw UnsupportedOperationException()"
private fun newTypeParameterList(member: KtCallableDeclaration): KtTypeParameterList? { private fun newTypeParameterList(member: KtCallableDeclaration): KtTypeParameterList? {
val classElement = member.parent.parent as KtClass val classElement = member.parent.parent as KtClass
val classParams = classElement.typeParameters val classParams = classElement.typeParameters
@@ -33,6 +33,9 @@ import org.jetbrains.kotlin.idea.caches.resolve.resolveToDescriptor
import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde import org.jetbrains.kotlin.idea.codeInsight.DescriptorToSourceUtilsIde
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
import org.jetbrains.kotlin.idea.core.ShortenReferences import org.jetbrains.kotlin.idea.core.ShortenReferences
import org.jetbrains.kotlin.idea.core.TemplateKind
import org.jetbrains.kotlin.idea.core.getFunctionBodyTextFromTemplate
import org.jetbrains.kotlin.idea.imports.importableFqName
import org.jetbrains.kotlin.idea.util.application.executeWriteCommand import org.jetbrains.kotlin.idea.util.application.executeWriteCommand
import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinType
@@ -127,7 +130,14 @@ class AddFunctionToSupertypeFix private constructor(
if (classDescriptor.kind != ClassKind.INTERFACE && functionDescriptor.modality != Modality.ABSTRACT) { if (classDescriptor.kind != ClassKind.INTERFACE && functionDescriptor.modality != Modality.ABSTRACT) {
val returnType = functionDescriptor.returnType val returnType = functionDescriptor.returnType
if (returnType == null || !KotlinBuiltIns.isUnit(returnType)) { if (returnType == null || !KotlinBuiltIns.isUnit(returnType)) {
sourceCode += "{ throw UnsupportedOperationException() }" val bodyText = getFunctionBodyTextFromTemplate(
project,
TemplateKind.FUNCTION,
functionDescriptor.name.asString(),
functionDescriptor.returnType?.let { IdeDescriptorRenderers.SOURCE_CODE.renderType(it) } ?: "Unit",
classDescriptor.importableFqName
)
sourceCode += "{ $bodyText }"
} }
else { else {
sourceCode += "{}" sourceCode += "{}"
@@ -6,7 +6,7 @@ interface A {
fun some() : A { fun some() : A {
return object : A { return object : A {
override val method: () -> Unit? override val method: () -> Unit?
get() = <selection><caret>throw UnsupportedOperationException()</selection> get() = <selection><caret>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
} }
@@ -4,5 +4,5 @@ interface A {
class B : A { class B : A {
override val String.prop: Int override val String.prop: Int
get() = <selection><caret>throw UnsupportedOperationException()</selection> get() = <selection><caret>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -4,7 +4,7 @@ interface A {
class B : A { class B : A {
override var Int.foo: Double override var Int.foo: Double
get() = <selection><caret>throw UnsupportedOperationException()</selection> get() = <selection><caret>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
set(value) { set(value) {
} }
} }
@@ -11,19 +11,19 @@ interface T {
class C : T { class C : T {
override val a1: Byte override val a1: Byte
get() = <selection><caret>throw UnsupportedOperationException()</selection> get() = <selection><caret>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
override val a2: Short override val a2: Short
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override val a3: Int override val a3: Int
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override val a4: Long override val a4: Long
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override val a5: Float override val a5: Float
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override val a6: Double override val a6: Double
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override val a7: Char override val a7: Char
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override val a8: Boolean override val a8: Boolean
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -4,5 +4,5 @@ interface T {
class GC() : T { class GC() : T {
override val v: Int override val v: Int
get() = <selection><caret>throw UnsupportedOperationException()</selection> get() = <selection><caret>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -10,7 +10,7 @@ class SomeTest : Test {
} }
override val testProp: Int override val testProp: Int
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
/** /**
* test * test
@@ -3,5 +3,5 @@ abstract class Owner {
} }
fun Owner.f() { fun Owner.f() {
<caret><selection>throw UnsupportedOperationException()</selection> <caret><selection>TODO("not implemented")</selection> //To change body of created functions use File | Settings | File Templates.
} }
@@ -3,4 +3,4 @@ abstract class Owner {
} }
val Owner.p: Int val Owner.p: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
@@ -4,4 +4,4 @@ class Owner {
} }
val Owner.p: Int val Owner.p: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
@@ -4,7 +4,7 @@ class Owner {
} }
var Owner.p: Int var Owner.p: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
set(value) { set(value) {
throw UnsupportedOperationException() TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -6,5 +6,5 @@ class Owner {
var Owner.p: Int var Owner.p: Int
get() = 1 get() = 1
set(value) { set(value) {
<caret><selection>throw UnsupportedOperationException()</selection> <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -6,5 +6,5 @@ class Owner {
var Owner.p: Int var Owner.p: Int
get() { return 1 } get() { return 1 }
set(value) { set(value) {
<caret><selection>throw UnsupportedOperationException()</selection> <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -5,5 +5,5 @@ class Owner {
} }
var Owner.p: Int var Owner.p: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
set(v) {} set(v) {}
@@ -8,5 +8,5 @@ enum class E : T<Int> {
A, B, C; A, B, C;
override val foo: Int override val foo: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -8,5 +8,5 @@ enum class E : T<Int> {
A, B, C; A, B, C;
override val foo: Int override val foo: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -8,7 +8,7 @@ enum class E : T<Int> {
A, B, C; A, B, C;
override val foo: Int override val foo: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
val bar = 1 val bar = 1
@@ -3,13 +3,13 @@
enum class E { enum class E {
A { A {
override val foo: Int override val foo: Int
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
}, B { }, B {
override val foo: Int override val foo: Int
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
}, C { }, C {
override val foo: Int override val foo: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
}; };
abstract val foo: Int abstract val foo: Int
@@ -3,13 +3,13 @@
enum class E(n: Int) { enum class E(n: Int) {
A(1) { A(1) {
override val foo: Int override val foo: Int
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
}, B(2) { }, B(2) {
override val foo: Int override val foo: Int
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
}, C(3) { }, C(3) {
override val foo: Int override val foo: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
}; };
abstract val foo: Int abstract val foo: Int
@@ -6,13 +6,13 @@ interface T<X> {
class U : T<String> { class U : T<String> {
override val foo: String override val foo: String
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
} }
class V : T<Int> { class V : T<Int> {
override val foo: Int override val foo: Int
get() = <caret><selection>throw UnsupportedOperationException()</selection> get() = <caret><selection>TODO("not implemented")</selection> //To change initializer of created properties use File | Settings | File Templates.
} }
@@ -4,5 +4,5 @@ interface A {
} }
fun A.foo(n: Int) { fun A.foo(n: Int) {
throw UnsupportedOperationException() TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
} }
+1 -1
View File
@@ -10,7 +10,7 @@ private abstract class Base {
private class BaseImpl : Base() { private class BaseImpl : Base() {
override var x: Int override var x: Int
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
set(value) { set(value) {
} }
+1 -1
View File
@@ -17,7 +17,7 @@ class Container {
class BaseImpl : Container.Base { class BaseImpl : Container.Base {
override val x: Boolean override val x: Boolean
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
override fun bar(z: Int): String { override fun bar(z: Int): String {
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
@@ -9,7 +9,7 @@ class Container {
class BaseImpl : Base { class BaseImpl : Base {
override var z: Double override var z: Double
get() = throw UnsupportedOperationException() get() = TODO("not implemented") //To change initializer of created properties use File | Settings | File Templates.
set(value) { set(value) {
} }
} }
@@ -2,8 +2,7 @@
// WITH_RUNTIME // WITH_RUNTIME
open class A { open class A {
open fun f(): Int { open fun f(): Int {
throw UnsupportedOperationException() TODO("not implemented") //To change body of created functions use File | Settings | File Templates. }
}
} }
class B : A() { class B : A() {
<caret>override fun f(): Int = 5 <caret>override fun f(): Int = 5