Create From Usage: Add ability to select val/var when creating property
This commit is contained in:
+7
@@ -410,6 +410,10 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
return returnTypeExpression
|
||||
}
|
||||
|
||||
private fun setupValVarTemplate(builder: TemplateBuilder, property: JetProperty) {
|
||||
builder.replaceElement(property.getValOrVarNode().getPsi()!!, ValVarExpression)
|
||||
}
|
||||
|
||||
private fun setupTypeParameterListTemplate(builder: TemplateBuilderImpl, declaration: JetCallableDeclaration): TypeParameterListExpression {
|
||||
val typeParameterMap = HashMap<String, Array<String>>()
|
||||
val receiverTypeParameterNames = receiverTypeCandidate?.let { it.typeParameterNames!! } ?: ArrayUtil.EMPTY_STRING_ARRAY
|
||||
@@ -481,6 +485,9 @@ class CallableBuilder(val config: CallableBuilderConfiguration) {
|
||||
caretModel.moveToOffset(containingFile.getNode().getStartOffset())
|
||||
|
||||
val builder = TemplateBuilderImpl(containingFile)
|
||||
if (declaration is JetProperty) {
|
||||
setupValVarTemplate(builder, declaration)
|
||||
}
|
||||
val returnTypeExpression = if (isUnit) null else setupReturnTypeTemplate(builder, declaration)
|
||||
val parameterTypeExpressions =
|
||||
setupParameterTypeTemplates(builder, declaration.getValueParameterList()?.getParameters() ?: Collections.emptyList())
|
||||
|
||||
+10
@@ -140,3 +140,13 @@ private class TypeParameterListExpression(private val typeParameterNamesFromRece
|
||||
// do not offer the user any choices
|
||||
override fun calculateLookupItems(context: ExpressionContext?) = array<LookupElement>()
|
||||
}
|
||||
|
||||
private object ValVarExpression: Expression() {
|
||||
private val cachedLookupElements = listOf("val", "var").map { LookupElementBuilder.create(it) }.copyToArray<LookupElement>()
|
||||
|
||||
override fun calculateResult(context: ExpressionContext?): Result? = TextResult("val")
|
||||
|
||||
override fun calculateQuickResult(context: ExpressionContext?): Result? = calculateResult(context)
|
||||
|
||||
override fun calculateLookupItems(context: ExpressionContext?): Array<LookupElement>? = cachedLookupElements
|
||||
}
|
||||
Reference in New Issue
Block a user