KT-4562 New Intention: Add and Remove braces from control statements that have single line bodies
This commit is contained in:
committed by
Evgeny Gerashchenko
parent
b6a9772508
commit
2f613638c2
@@ -120,6 +120,7 @@ public fun JetElement.wrapInBlock(): JetBlockExpression {
|
|||||||
block.appendElement(this)
|
block.appendElement(this)
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the list of unqualified names that are indexed as the superclass names of this class. For the names that might be imported
|
* Returns the list of unqualified names that are indexed as the superclass names of this class. For the names that might be imported
|
||||||
* via an aliased import, includes both the original and the aliased name (reference resolution during inheritor search will sort this out).
|
* via an aliased import, includes both the original and the aliased name (reference resolution during inheritor search will sort this out).
|
||||||
|
|||||||
@@ -372,6 +372,8 @@ fun main(args: Array<String>) {
|
|||||||
model("intentions/moveLambdaOutsideParentheses", testMethod = "doTestMoveLambdaOutsideParentheses")
|
model("intentions/moveLambdaOutsideParentheses", testMethod = "doTestMoveLambdaOutsideParentheses")
|
||||||
model("intentions/replaceExplicitFunctionLiteralParamWithIt", testMethod = "doTestReplaceExplicitFunctionLiteralParamWithIt")
|
model("intentions/replaceExplicitFunctionLiteralParamWithIt", testMethod = "doTestReplaceExplicitFunctionLiteralParamWithIt")
|
||||||
model("intentions/replaceItWithExplicitFunctionLiteralParam", testMethod = "doTestReplaceItWithExplicitFunctionLiteralParam")
|
model("intentions/replaceItWithExplicitFunctionLiteralParam", testMethod = "doTestReplaceItWithExplicitFunctionLiteralParam")
|
||||||
|
model("intentions/removeBraces", testMethod = "doTestRemoveBraces")
|
||||||
|
model("intentions/addBraces", testMethod = "doTestAddBraces")
|
||||||
}
|
}
|
||||||
|
|
||||||
testClass(javaClass<AbstractHierarchyTest>()) {
|
testClass(javaClass<AbstractHierarchyTest>()) {
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
if (b) <spot>{
|
||||||
|
return 1
|
||||||
|
}</spot>
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
if (b) return 1
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
This intention adds braces to control flow statements without braces.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
if (b) return 1
|
||||||
|
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
if (b) <spot>{
|
||||||
|
return 1
|
||||||
|
}</spot>
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<html>
|
||||||
|
<body>
|
||||||
|
This intention removes braces from control flow statements with only a single statement in their code block.
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
@@ -538,6 +538,17 @@
|
|||||||
<category>Kotlin</category>
|
<category>Kotlin</category>
|
||||||
</intentionAction>
|
</intentionAction>
|
||||||
|
|
||||||
|
<intentionAction>
|
||||||
|
<className>org.jetbrains.jet.plugin.intentions.RemoveBracesIntention</className>
|
||||||
|
<category>Kotlin</category>
|
||||||
|
</intentionAction>
|
||||||
|
|
||||||
|
<intentionAction>
|
||||||
|
<className>org.jetbrains.jet.plugin.intentions.AddBracesIntention</className>
|
||||||
|
<category>Kotlin</category>
|
||||||
|
</intentionAction>
|
||||||
|
|
||||||
|
|
||||||
<project.converterProvider implementation="org.jetbrains.jet.plugin.converters.JetRunConfigurationSettingsFormatConverterProvider"/>
|
<project.converterProvider implementation="org.jetbrains.jet.plugin.converters.JetRunConfigurationSettingsFormatConverterProvider"/>
|
||||||
|
|
||||||
</extensions>
|
</extensions>
|
||||||
|
|||||||
@@ -241,6 +241,10 @@ move.lambda.outside.parentheses=Move lambda expression out of parentheses
|
|||||||
move.lambda.outside.parentheses.family=Move lambda expression out of parentheses
|
move.lambda.outside.parentheses.family=Move lambda expression out of parentheses
|
||||||
replace.it.with.explicit.function.literal.param=Replace 'it' with explicit parameter
|
replace.it.with.explicit.function.literal.param=Replace 'it' with explicit parameter
|
||||||
replace.it.with.explicit.function.literal.param.family=Replace 'it' With Explicit Parameter
|
replace.it.with.explicit.function.literal.param.family=Replace 'it' With Explicit Parameter
|
||||||
|
remove.braces=Remove braces
|
||||||
|
remove.braces.family=Remove Braces
|
||||||
|
add.braces=Add braces
|
||||||
|
add.braces.family=Add Braces
|
||||||
|
|
||||||
property.is.implemented.too.many=Has implementations
|
property.is.implemented.too.many=Has implementations
|
||||||
property.is.overridden.too.many=Is overridden in subclasses
|
property.is.overridden.too.many=Is overridden in subclasses
|
||||||
|
|||||||
@@ -0,0 +1,80 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.intentions
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.psi.JetIfExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetWhileExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetForExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetDoWhileExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpressionImpl
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||||
|
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.psi.PsiFile
|
||||||
|
import com.intellij.lang.ASTNode
|
||||||
|
import org.jetbrains.jet.JetNodeTypes
|
||||||
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
|
|
||||||
|
public class AddBracesIntention : JetSelfTargetingIntention<JetExpressionImpl>("add.braces", javaClass()) {
|
||||||
|
private var expressionKind: ExpressionKind? = null
|
||||||
|
private var caretLocation: Int = 1
|
||||||
|
|
||||||
|
override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean {
|
||||||
|
caretLocation = editor.getCaretModel().getOffset()
|
||||||
|
return getTarget(editor, file) != null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isApplicableTo(element: JetExpressionImpl): Boolean {
|
||||||
|
expressionKind = element.getExpressionKind(caretLocation)
|
||||||
|
if (expressionKind == null) return false
|
||||||
|
|
||||||
|
val jetBlockElement = element.findBlockInExpression(expressionKind)
|
||||||
|
if (jetBlockElement != null) return false
|
||||||
|
|
||||||
|
setText("Add braces to '${expressionKind!!.text}' statement")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyTo(element: JetExpressionImpl, editor: Editor) {
|
||||||
|
val bodyNode = when (expressionKind) {
|
||||||
|
ExpressionKind.ELSE -> element.getNode().findChildByType(JetNodeTypes.ELSE)
|
||||||
|
ExpressionKind.IF -> element.getNode().findChildByType(JetNodeTypes.THEN)
|
||||||
|
else -> element.getNode().findChildByType(JetNodeTypes.BODY)
|
||||||
|
}
|
||||||
|
generateCleanOutput(element, bodyNode)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun generateCleanOutput(element: JetExpressionImpl, bodyNode: ASTNode?) {
|
||||||
|
if (element.getNextSibling()?.getText() == ";") {
|
||||||
|
element.getNextSibling()!!.delete()
|
||||||
|
}
|
||||||
|
val newElement = bodyNode!!.getPsi()!!.replace(JetPsiFactory.createFunctionBody(element.getProject(), bodyNode.getText()))
|
||||||
|
|
||||||
|
//handles the case of the block statement being on a new line
|
||||||
|
if (newElement.getPrevSibling() is PsiWhiteSpace) {
|
||||||
|
newElement.getPrevSibling()!!.replace(JetPsiFactory.createWhiteSpace(element.getProject()))
|
||||||
|
} else {
|
||||||
|
//handles the case of no space between condition and statement
|
||||||
|
newElement.addBefore(JetPsiFactory.createWhiteSpace(element.getProject()), newElement.getFirstChild())
|
||||||
|
}
|
||||||
|
if (expressionKind == ExpressionKind.DOWHILE) {
|
||||||
|
newElement.getNextSibling()?.delete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -32,7 +32,7 @@ public abstract class JetSelfTargetingIntention<T: JetElement>(val key: String,
|
|||||||
protected abstract fun isApplicableTo(element: T): Boolean
|
protected abstract fun isApplicableTo(element: T): Boolean
|
||||||
protected abstract fun applyTo(element: T, editor: Editor)
|
protected abstract fun applyTo(element: T, editor: Editor)
|
||||||
|
|
||||||
private fun getTarget(editor: Editor, file: PsiFile): T? {
|
protected fun getTarget(editor: Editor, file: PsiFile): T? {
|
||||||
val offset = editor.getCaretModel().getOffset()
|
val offset = editor.getCaretModel().getOffset()
|
||||||
return file.findElementAt(offset)?.getParentByTypesAndPredicate(false, elementType) { element -> isApplicableTo(element) }
|
return file.findElementAt(offset)?.getParentByTypesAndPredicate(false, elementType) { element -> isApplicableTo(element) }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.jet.plugin.intentions
|
||||||
|
|
||||||
|
import org.jetbrains.jet.lang.psi.JetBlockExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiFactory
|
||||||
|
import org.jetbrains.jet.lang.psi.JetWhileExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetIfExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetDoWhileExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetForExpression
|
||||||
|
import org.jetbrains.jet.lang.psi.JetExpressionImpl
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.openapi.editor.Editor
|
||||||
|
import com.intellij.psi.PsiFile
|
||||||
|
import com.intellij.psi.PsiWhiteSpace
|
||||||
|
import com.intellij.psi.PsiComment
|
||||||
|
|
||||||
|
public class RemoveBracesIntention : JetSelfTargetingIntention<JetExpressionImpl>("remove.braces", javaClass()) {
|
||||||
|
private var expressionKind: ExpressionKind? = null
|
||||||
|
private var caretLocation: Int = 1
|
||||||
|
|
||||||
|
override fun isAvailable(project: Project, editor: Editor, file: PsiFile): Boolean {
|
||||||
|
caretLocation = editor.getCaretModel().getOffset()
|
||||||
|
return getTarget(editor, file) != null
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun isApplicableTo(element: JetExpressionImpl): Boolean {
|
||||||
|
expressionKind = element.getExpressionKind(caretLocation)
|
||||||
|
if (expressionKind == null) return false
|
||||||
|
|
||||||
|
val jetBlockElement = element.findBlockInExpression(expressionKind)
|
||||||
|
if (jetBlockElement == null) return false
|
||||||
|
|
||||||
|
if (jetBlockElement!!.getStatements().size == 1) {
|
||||||
|
setText("Remove braces from '${expressionKind!!.text}' statement")
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun applyTo(element: JetExpressionImpl, editor: Editor) {
|
||||||
|
val jetBlockElement = element.findBlockInExpression(expressionKind)
|
||||||
|
val firstStatement = jetBlockElement!!.getStatements().first()
|
||||||
|
|
||||||
|
handleComments(element, jetBlockElement)
|
||||||
|
|
||||||
|
val newElement = jetBlockElement.replace(JetPsiFactory.createExpression(element.getProject(), firstStatement.getText()))
|
||||||
|
|
||||||
|
if (expressionKind == ExpressionKind.DOWHILE) {
|
||||||
|
newElement.getParent()!!.addAfter(JetPsiFactory.createNewLine(element.getProject()), newElement)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fun handleComments(element: JetExpressionImpl, blockElement: JetBlockExpression) {
|
||||||
|
var sibling = blockElement.getFirstChild()?.getNextSibling()
|
||||||
|
|
||||||
|
while (sibling != null) {
|
||||||
|
if (sibling is PsiComment) {
|
||||||
|
//cleans up extra whitespace
|
||||||
|
if (element.getPrevSibling() is PsiWhiteSpace) {
|
||||||
|
element.getPrevSibling()!!.replace(JetPsiFactory.createNewLine(element.getProject()))
|
||||||
|
}
|
||||||
|
val commentElement = element.getParent()!!.addBefore(sibling as PsiComment, element.getPrevSibling())
|
||||||
|
element.getParent()!!.addBefore(JetPsiFactory.createNewLine(element.getProject()), commentElement)
|
||||||
|
}
|
||||||
|
sibling = sibling!!.getNextSibling()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,6 +7,8 @@ import org.jetbrains.jet.lang.resolve.BindingContext
|
|||||||
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.jet.renderer.DescriptorRenderer
|
import org.jetbrains.jet.renderer.DescriptorRenderer
|
||||||
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
|
import org.jetbrains.jet.plugin.codeInsight.ShortenReferences
|
||||||
|
import org.jetbrains.jet.JetNodeTypes
|
||||||
|
import org.jetbrains.jet.lexer.JetTokens
|
||||||
|
|
||||||
fun specifyTypeExplicitly(declaration: JetNamedFunction, typeText: String) {
|
fun specifyTypeExplicitly(declaration: JetNamedFunction, typeText: String) {
|
||||||
specifyTypeExplicitly(declaration, JetPsiFactory.createType(declaration.getProject(), typeText))
|
specifyTypeExplicitly(declaration, JetPsiFactory.createType(declaration.getProject(), typeText))
|
||||||
@@ -39,3 +41,44 @@ fun functionReturnType(function: JetNamedFunction): JetType? {
|
|||||||
if (descriptor == null) return null
|
if (descriptor == null) return null
|
||||||
return (descriptor as FunctionDescriptor).getReturnType()
|
return (descriptor as FunctionDescriptor).getReturnType()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
enum class ExpressionKind(val text: String) {
|
||||||
|
IF : ExpressionKind("if")
|
||||||
|
ELSE : ExpressionKind("else")
|
||||||
|
WHILE : ExpressionKind("while")
|
||||||
|
DOWHILE : ExpressionKind("do...while")
|
||||||
|
FOR : ExpressionKind("for")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun JetExpressionImpl.findBlockInExpression(expressionKind: ExpressionKind?): JetBlockExpression? {
|
||||||
|
val bodyNode = when (expressionKind) {
|
||||||
|
ExpressionKind.IF -> this.getNode().findChildByType(JetNodeTypes.THEN)
|
||||||
|
ExpressionKind.ELSE -> this.getNode().findChildByType(JetNodeTypes.ELSE)
|
||||||
|
else -> this.getNode().findChildByType(JetNodeTypes.BODY)
|
||||||
|
}
|
||||||
|
return bodyNode!!.getPsi()!!.getFirstChild() as? JetBlockExpression
|
||||||
|
}
|
||||||
|
|
||||||
|
fun JetExpressionImpl.getExpressionKind(caretLocation: Int): ExpressionKind? {
|
||||||
|
when (this) {
|
||||||
|
is JetIfExpression -> {
|
||||||
|
if (this.getElse() != null) {
|
||||||
|
val elseLocation = this.getNode().findChildByType(JetTokens.ELSE_KEYWORD)!!.getPsi()!!.getTextOffset()
|
||||||
|
if (caretLocation >= elseLocation) return ExpressionKind.ELSE
|
||||||
|
}
|
||||||
|
return ExpressionKind.IF
|
||||||
|
}
|
||||||
|
is JetWhileExpression -> {
|
||||||
|
return ExpressionKind.WHILE
|
||||||
|
}
|
||||||
|
is JetDoWhileExpression -> {
|
||||||
|
return ExpressionKind.DOWHILE
|
||||||
|
}
|
||||||
|
is JetForExpression -> {
|
||||||
|
return ExpressionKind.FOR
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>do println("test")
|
||||||
|
while(true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
do {
|
||||||
|
println("test")
|
||||||
|
} while(true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) println("test")
|
||||||
|
<caret>else println("test2")
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) println("test")
|
||||||
|
else {
|
||||||
|
println("test2")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo() {
|
||||||
|
for (i in 1..4)
|
||||||
|
<caret>println("test")
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
for (i in 1..4) {
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>if (true) println("test") else println("test2")
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) {
|
||||||
|
println("test")
|
||||||
|
} else println("test2")
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>if (true)println("test")
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) {
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>if (true) println("test");
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) {
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>while (true)
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
while (true) {
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun foo() {
|
||||||
|
<caret>if (true) {
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
do {
|
||||||
|
println("test")
|
||||||
|
<caret>} while(true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo() {
|
||||||
|
do println("test")
|
||||||
|
while(true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun foo() {
|
||||||
|
do {
|
||||||
|
println("test")
|
||||||
|
println("test2")
|
||||||
|
<caret>} while(true)
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) {
|
||||||
|
println("test")
|
||||||
|
} <caret>else {
|
||||||
|
println("test2")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) {
|
||||||
|
println("test")
|
||||||
|
} else println("test2")
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
for<caret> (i in 1..4) {
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
for (i in 1..4) println("test")
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>if (true) {
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) println("test")
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>if (true) {
|
||||||
|
//comment
|
||||||
|
println("test")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun foo() {
|
||||||
|
//comment
|
||||||
|
if (true) println("test")
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun foo() {
|
||||||
|
if (true) { }
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
<caret>if (true) {
|
||||||
|
println("test");
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
if (true) println("test")
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun foo() {
|
||||||
|
if (true) {
|
||||||
|
println("test")
|
||||||
|
println("test2")
|
||||||
|
<caret>}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
fun foo() {
|
||||||
|
while (true) {
|
||||||
|
println("test")
|
||||||
|
<caret>}
|
||||||
|
}
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun foo() {
|
||||||
|
while (true) println("test")
|
||||||
|
}
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
// IS_APPLICABLE: false
|
||||||
|
fun foo() {
|
||||||
|
while (true) {
|
||||||
|
println("test")
|
||||||
|
println("test2")
|
||||||
|
<caret>}
|
||||||
|
}
|
||||||
@@ -151,6 +151,14 @@ public abstract class AbstractCodeTransformationTest extends LightCodeInsightTes
|
|||||||
doTestIntention(path, new ReplaceItWithExplicitFunctionLiteralParamIntention());
|
doTestIntention(path, new ReplaceItWithExplicitFunctionLiteralParamIntention());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void doTestRemoveBraces(@NotNull String path) throws Exception {
|
||||||
|
doTestIntention(path, new RemoveBracesIntention());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doTestAddBraces(@NotNull String path) throws Exception {
|
||||||
|
doTestIntention(path, new AddBracesIntention());
|
||||||
|
}
|
||||||
|
|
||||||
private void doTestIntention(@NotNull String path, @NotNull IntentionAction intentionAction) throws Exception {
|
private void doTestIntention(@NotNull String path, @NotNull IntentionAction intentionAction) throws Exception {
|
||||||
configureByFile(path);
|
configureByFile(path);
|
||||||
|
|
||||||
|
|||||||
+114
-1
@@ -30,7 +30,7 @@ import org.jetbrains.jet.plugin.intentions.AbstractCodeTransformationTest;
|
|||||||
|
|
||||||
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */
|
||||||
@SuppressWarnings("all")
|
@SuppressWarnings("all")
|
||||||
@InnerTestClasses({CodeTransformationTestGenerated.IfToAssignment.class, CodeTransformationTestGenerated.IfToReturn.class, CodeTransformationTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationTestGenerated.WhenToAssignment.class, CodeTransformationTestGenerated.WhenToReturn.class, CodeTransformationTestGenerated.AssignmentToIf.class, CodeTransformationTestGenerated.AssignmentToWhen.class, CodeTransformationTestGenerated.PropertyToIf.class, CodeTransformationTestGenerated.PropertyToWhen.class, CodeTransformationTestGenerated.ReturnToIf.class, CodeTransformationTestGenerated.ReturnToWhen.class, CodeTransformationTestGenerated.IfToWhen.class, CodeTransformationTestGenerated.WhenToIf.class, CodeTransformationTestGenerated.Flatten.class, CodeTransformationTestGenerated.Merge.class, CodeTransformationTestGenerated.IntroduceSubject.class, CodeTransformationTestGenerated.EliminateSubject.class, CodeTransformationTestGenerated.Split.class, CodeTransformationTestGenerated.Join.class, CodeTransformationTestGenerated.ConvertMemberToExtension.class, CodeTransformationTestGenerated.ReconstructedType.class, CodeTransformationTestGenerated.RemoveUnnecessaryParentheses.class, CodeTransformationTestGenerated.ReplaceWithDotQualifiedMethodCall.class, CodeTransformationTestGenerated.ReplaceWithInfixFunctionCall.class, CodeTransformationTestGenerated.RemoveCurlyBracesFromTemplate.class, CodeTransformationTestGenerated.MoveLambdaInsideParentheses.class, CodeTransformationTestGenerated.MoveLambdaOutsideParentheses.class, CodeTransformationTestGenerated.ReplaceExplicitFunctionLiteralParamWithIt.class, CodeTransformationTestGenerated.ReplaceItWithExplicitFunctionLiteralParam.class})
|
@InnerTestClasses({CodeTransformationTestGenerated.IfToAssignment.class, CodeTransformationTestGenerated.IfToReturn.class, CodeTransformationTestGenerated.IfToReturnAsymmetrically.class, CodeTransformationTestGenerated.WhenToAssignment.class, CodeTransformationTestGenerated.WhenToReturn.class, CodeTransformationTestGenerated.AssignmentToIf.class, CodeTransformationTestGenerated.AssignmentToWhen.class, CodeTransformationTestGenerated.PropertyToIf.class, CodeTransformationTestGenerated.PropertyToWhen.class, CodeTransformationTestGenerated.ReturnToIf.class, CodeTransformationTestGenerated.ReturnToWhen.class, CodeTransformationTestGenerated.IfToWhen.class, CodeTransformationTestGenerated.WhenToIf.class, CodeTransformationTestGenerated.Flatten.class, CodeTransformationTestGenerated.Merge.class, CodeTransformationTestGenerated.IntroduceSubject.class, CodeTransformationTestGenerated.EliminateSubject.class, CodeTransformationTestGenerated.Split.class, CodeTransformationTestGenerated.Join.class, CodeTransformationTestGenerated.ConvertMemberToExtension.class, CodeTransformationTestGenerated.ReconstructedType.class, CodeTransformationTestGenerated.RemoveUnnecessaryParentheses.class, CodeTransformationTestGenerated.ReplaceWithDotQualifiedMethodCall.class, CodeTransformationTestGenerated.ReplaceWithInfixFunctionCall.class, CodeTransformationTestGenerated.RemoveCurlyBracesFromTemplate.class, CodeTransformationTestGenerated.MoveLambdaInsideParentheses.class, CodeTransformationTestGenerated.MoveLambdaOutsideParentheses.class, CodeTransformationTestGenerated.ReplaceExplicitFunctionLiteralParamWithIt.class, CodeTransformationTestGenerated.ReplaceItWithExplicitFunctionLiteralParam.class, CodeTransformationTestGenerated.RemoveBraces.class, CodeTransformationTestGenerated.AddBraces.class})
|
||||||
public class CodeTransformationTestGenerated extends AbstractCodeTransformationTest {
|
public class CodeTransformationTestGenerated extends AbstractCodeTransformationTest {
|
||||||
@TestMetadata("idea/testData/intentions/branched/folding/ifToAssignment")
|
@TestMetadata("idea/testData/intentions/branched/folding/ifToAssignment")
|
||||||
public static class IfToAssignment extends AbstractCodeTransformationTest {
|
public static class IfToAssignment extends AbstractCodeTransformationTest {
|
||||||
@@ -1559,6 +1559,117 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/intentions/removeBraces")
|
||||||
|
public static class RemoveBraces extends AbstractCodeTransformationTest {
|
||||||
|
public void testAllFilesPresentInRemoveBraces() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/removeBraces"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForDoWhile.kt")
|
||||||
|
public void testRemoveBracesForDoWhile() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForDoWhile.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForDoWhileWithTwoStatements.kt")
|
||||||
|
public void testRemoveBracesForDoWhileWithTwoStatements() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForDoWhileWithTwoStatements.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForElse.kt")
|
||||||
|
public void testRemoveBracesForElse() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForElse.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForFor.kt")
|
||||||
|
public void testRemoveBracesForFor() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForFor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForIf.kt")
|
||||||
|
public void testRemoveBracesForIf() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForIf.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForIfWithComment.kt")
|
||||||
|
public void testRemoveBracesForIfWithComment() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForIfWithComment.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForIfWithNoStatement.kt")
|
||||||
|
public void testRemoveBracesForIfWithNoStatement() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForIfWithNoStatement.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForIfWithSemicolon.kt")
|
||||||
|
public void testRemoveBracesForIfWithSemicolon() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForIfWithSemicolon.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForIfWithTwoStatements.kt")
|
||||||
|
public void testRemoveBracesForIfWithTwoStatements() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForIfWithTwoStatements.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForWhile.kt")
|
||||||
|
public void testRemoveBracesForWhile() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForWhile.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("removeBracesForWhileWithTwoStatements.kt")
|
||||||
|
public void testRemoveBracesForWhileWithTwoStatements() throws Exception {
|
||||||
|
doTestRemoveBraces("idea/testData/intentions/removeBraces/removeBracesForWhileWithTwoStatements.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("idea/testData/intentions/addBraces")
|
||||||
|
public static class AddBraces extends AbstractCodeTransformationTest {
|
||||||
|
@TestMetadata("addBracesForDoWhile.kt")
|
||||||
|
public void testAddBracesForDoWhile() throws Exception {
|
||||||
|
doTestAddBraces("idea/testData/intentions/addBraces/addBracesForDoWhile.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addBracesForElse.kt")
|
||||||
|
public void testAddBracesForElse() throws Exception {
|
||||||
|
doTestAddBraces("idea/testData/intentions/addBraces/addBracesForElse.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addBracesForFor.kt")
|
||||||
|
public void testAddBracesForFor() throws Exception {
|
||||||
|
doTestAddBraces("idea/testData/intentions/addBraces/addBracesForFor.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addBracesForIf.kt")
|
||||||
|
public void testAddBracesForIf() throws Exception {
|
||||||
|
doTestAddBraces("idea/testData/intentions/addBraces/addBracesForIf.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addBracesForIfWithNoSpace.kt")
|
||||||
|
public void testAddBracesForIfWithNoSpace() throws Exception {
|
||||||
|
doTestAddBraces("idea/testData/intentions/addBraces/addBracesForIfWithNoSpace.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addBracesForIfWithSemicolon.kt")
|
||||||
|
public void testAddBracesForIfWithSemicolon() throws Exception {
|
||||||
|
doTestAddBraces("idea/testData/intentions/addBraces/addBracesForIfWithSemicolon.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addBracesForWhile.kt")
|
||||||
|
public void testAddBracesForWhile() throws Exception {
|
||||||
|
doTestAddBraces("idea/testData/intentions/addBraces/addBracesForWhile.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("addBracesWithBraces.kt")
|
||||||
|
public void testAddBracesWithBraces() throws Exception {
|
||||||
|
doTestAddBraces("idea/testData/intentions/addBraces/addBracesWithBraces.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInAddBraces() throws Exception {
|
||||||
|
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/addBraces"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
TestSuite suite = new TestSuite("CodeTransformationTestGenerated");
|
TestSuite suite = new TestSuite("CodeTransformationTestGenerated");
|
||||||
suite.addTestSuite(IfToAssignment.class);
|
suite.addTestSuite(IfToAssignment.class);
|
||||||
@@ -1590,6 +1701,8 @@ public class CodeTransformationTestGenerated extends AbstractCodeTransformationT
|
|||||||
suite.addTestSuite(MoveLambdaOutsideParentheses.class);
|
suite.addTestSuite(MoveLambdaOutsideParentheses.class);
|
||||||
suite.addTestSuite(ReplaceExplicitFunctionLiteralParamWithIt.class);
|
suite.addTestSuite(ReplaceExplicitFunctionLiteralParamWithIt.class);
|
||||||
suite.addTestSuite(ReplaceItWithExplicitFunctionLiteralParam.class);
|
suite.addTestSuite(ReplaceItWithExplicitFunctionLiteralParam.class);
|
||||||
|
suite.addTestSuite(RemoveBraces.class);
|
||||||
|
suite.addTestSuite(AddBraces.class);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user