diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyAccessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyAccessor.java index fccd30ce566..a79c273865b 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyAccessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPropertyAccessor.java @@ -73,7 +73,12 @@ public class JetPropertyAccessor extends JetDeclarationImpl @Override public boolean hasBlockBody() { - return findChildByType(JetTokens.EQ) == null; + return getEqualsToken() == null; + } + + @Nullable + public PsiElement getEqualsToken() { + return findChildByType(JetTokens.EQ); } @Override @@ -104,6 +109,6 @@ public class JetPropertyAccessor extends JetDeclarationImpl @Nullable @Override public JetExpression getInitializer() { - return PsiTreeUtil.getNextSiblingOfType(findChildByType(JetTokens.EQ), JetExpression.class); + return PsiTreeUtil.getNextSiblingOfType(getEqualsToken(), JetExpression.class); } } diff --git a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt index 25e373d6978..a9ea0665d50 100644 --- a/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/jet/generators/tests/GenerateTests.kt @@ -274,6 +274,10 @@ fun main(args: Array) { model("intentions/convertToExpressionBody", pattern = "^before(\\w+)\\.kt$") } + testClass(javaClass(), "ConvertToBlockBodyTestGenerated") { + model("intentions/convertToBlockBody", pattern = "^before(\\w+)\\.kt$") + } + testClass(javaClass()) { model("completion/basic/common") model("completion/basic/js") diff --git a/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/after.kt.template b/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/after.kt.template new file mode 100644 index 00000000000..08215d4cf58 --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/after.kt.template @@ -0,0 +1,3 @@ +fun foo(): String { + return "abc" +} \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/before.kt.template b/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/before.kt.template new file mode 100644 index 00000000000..830d7bea5c8 --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/before.kt.template @@ -0,0 +1 @@ +fun foo() = "abc" \ No newline at end of file diff --git a/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/description.html b/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/description.html new file mode 100644 index 00000000000..a233bf91a9d --- /dev/null +++ b/idea/resources/intentionDescriptions/ConvertToBlockBodyAction/description.html @@ -0,0 +1,5 @@ + + +This intention converts expression body (single expression after '=' sign) to block body with return statement. + + \ No newline at end of file diff --git a/idea/src/META-INF/plugin.xml b/idea/src/META-INF/plugin.xml index 56d55d7d6ba..b2e2b5a1ddc 100644 --- a/idea/src/META-INF/plugin.xml +++ b/idea/src/META-INF/plugin.xml @@ -381,6 +381,11 @@ Kotlin + + org.jetbrains.jet.plugin.intentions.ConvertToBlockBodyAction + Kotlin + + org.jetbrains.jet.plugin.ktSignature.KotlinSignatureAnnotationIntention Kotlin diff --git a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties index b0a8ee79a46..cff849d0a22 100644 --- a/idea/src/org/jetbrains/jet/plugin/JetBundle.properties +++ b/idea/src/org/jetbrains/jet/plugin/JetBundle.properties @@ -55,6 +55,8 @@ specify.type.explicitly.add.action.name=Specify type explicitly specify.type.explicitly.remove.action.name=Remove explicitly specified type convert.to.expression.body.action.family.name=Convert to Expression Body convert.to.expression.body.action.name=Convert to expression body +convert.to.block.body.action.family.name=Convert to Block Body +convert.to.block.body.action.name=Convert to block body rename.parameter.to.match.overridden.method=Rename parameter to match overridden method rename.family=Rename rename.kotlin.package.class.error="Can't rename kotlin package class" diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt new file mode 100644 index 00000000000..a7363316e5c --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt @@ -0,0 +1,80 @@ +package org.jetbrains.jet.plugin.intentions + +import com.intellij.codeInsight.intention.PsiElementBaseIntentionAction +import com.intellij.openapi.project.Project +import com.intellij.openapi.editor.Editor +import com.intellij.psi.PsiElement +import com.intellij.psi.util.PsiTreeUtil +import org.jetbrains.jet.lang.psi.JetBlockExpression +import org.jetbrains.jet.plugin.JetBundle +import org.jetbrains.jet.lang.psi.* +import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache +import org.jetbrains.jet.lang.resolve.BindingContext +import org.jetbrains.jet.lang.types.TypeUtils +import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns +import org.jetbrains.jet.lexer.JetTokens +import org.jetbrains.jet.lang.types.JetType + +public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() { + override fun getFamilyName(): String = JetBundle.message("convert.to.block.body.action.family.name") + + override fun isAvailable(project: Project, editor: Editor, element: PsiElement): Boolean { + setText(JetBundle.message("convert.to.block.body.action.name")) + return findDeclaration(element) != null + } + + override fun invoke(project: Project, editor: Editor, element: PsiElement) { + val declaration = findDeclaration(element)!! + val body = declaration.getBodyExpression()!! + + fun generateBody(returnsValue: Boolean): JetExpression { + val bodyType = expressionType(body) + val needReturn = returnsValue && + (bodyType == null || (!KotlinBuiltIns.getInstance().isUnit(bodyType) && !KotlinBuiltIns.getInstance().isNothing(bodyType))) + + val oldBodyText = body.getText()!! + val newBodyText = if (needReturn) "return ${oldBodyText}" else oldBodyText + return JetPsiFactory.createFunctionBody(project, newBodyText) + } + + if (declaration is JetNamedFunction) { + val returnType = functionReturnType(declaration)!! + if (!declaration.hasDeclaredReturnType() && !KotlinBuiltIns.getInstance().isUnit(returnType)) { + specifyTypeExplicitly(declaration, returnType) + } + + val newBody = generateBody(!KotlinBuiltIns.getInstance().isUnit(returnType) && !KotlinBuiltIns.getInstance().isNothing(returnType)) + + declaration.getEqualsToken()!!.delete() + body.replace(newBody) + } + else if (declaration is JetPropertyAccessor) { + val newBody = generateBody(declaration.isGetter()) + declaration.getEqualsToken()!!.delete() + body.replace(newBody) + } + else { + throw RuntimeException("Unknown declaration type: $declaration") + } + } + + private fun findDeclaration(element: PsiElement): JetDeclarationWithBody? { + val declaration = PsiTreeUtil.getParentOfType(element, javaClass()) + if (declaration == null || declaration is JetFunctionLiteral || declaration.hasBlockBody()) return null + val body = declaration.getBodyExpression() + if (body == null) return null + + return when (declaration) { + is JetNamedFunction -> { + val returnType = functionReturnType(declaration) + if (returnType == null) return null + if (!declaration.hasDeclaredReturnType() && returnType.isError()) return null // do not convert when type is implicit and unknown + declaration + } + + is JetPropertyAccessor -> declaration + + else -> throw RuntimeException("Unknown declaration type: $declaration") + } + } +} diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToExpressionBodyAction.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToExpressionBodyAction.kt index ec8536752c4..6eb8c1ee9d6 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToExpressionBodyAction.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToExpressionBodyAction.kt @@ -30,7 +30,7 @@ public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() { if (!declaration.hasDeclaredReturnType() && declaration is JetNamedFunction) { val valueType = expressionType(value) if (valueType == null || !KotlinBuiltIns.getInstance().isUnit(valueType)) { - specifyUnitTypeExplicitly(declaration) + specifyTypeExplicitly(declaration, "Unit") } } @@ -75,20 +75,6 @@ public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() { } } - private fun expressionType(expression: JetExpression): JetType? { - val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(expression.getContainingFile() as JetFile) - val bindingContext = resolveSession.resolveToElement(expression) - return bindingContext.get(BindingContext.EXPRESSION_TYPE, expression) - } - - private fun specifyUnitTypeExplicitly(declaration: JetNamedFunction) { - val project = declaration.getProject() - val typeReference = JetPsiFactory.createType(project, "Unit") - val anchor = declaration.getValueParameterList() ?: return/*incomplete declaration*/ - declaration.addAfter(typeReference, anchor) - declaration.addAfter(JetPsiFactory.createColon(project), anchor) - } - private fun containsReturn(element: PsiElement): Boolean { if (element is JetReturnExpression) return true //TODO: would be better to have some interface of declaration where return can be used diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/Utils.kt b/idea/src/org/jetbrains/jet/plugin/intentions/Utils.kt new file mode 100644 index 00000000000..2763ea4b6b0 --- /dev/null +++ b/idea/src/org/jetbrains/jet/plugin/intentions/Utils.kt @@ -0,0 +1,41 @@ +package org.jetbrains.jet.plugin.intentions + +import org.jetbrains.jet.lang.psi.* +import org.jetbrains.jet.lang.types.JetType +import org.jetbrains.jet.plugin.project.AnalyzerFacadeWithCache +import org.jetbrains.jet.lang.resolve.BindingContext +import org.jetbrains.jet.lang.descriptors.FunctionDescriptor +import org.jetbrains.jet.renderer.DescriptorRenderer +import org.jetbrains.jet.plugin.codeInsight.ShortenReferences + +fun specifyTypeExplicitly(declaration: JetNamedFunction, typeText: String) { + specifyTypeExplicitly(declaration, JetPsiFactory.createType(declaration.getProject(), typeText)) +} + +fun specifyTypeExplicitly(declaration: JetNamedFunction, `type`: JetType) { + if (`type`.isError()) return + val typeReference = JetPsiFactory.createType(declaration.getProject(), DescriptorRenderer.SOURCE_CODE.renderType(`type`)) + specifyTypeExplicitly(declaration, typeReference) + ShortenReferences.process(declaration.getReturnTypeRef()!!) +} + +fun specifyTypeExplicitly(declaration: JetNamedFunction, typeReference: JetTypeReference) { + val project = declaration.getProject() + val anchor = declaration.getValueParameterList() ?: return/*incomplete declaration*/ + declaration.addAfter(typeReference, anchor) + declaration.addAfter(JetPsiFactory.createColon(project), anchor) +} + +fun expressionType(expression: JetExpression): JetType? { + val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(expression.getContainingFile() as JetFile) + val bindingContext = resolveSession.resolveToElement(expression) + return bindingContext.get(BindingContext.EXPRESSION_TYPE, expression) +} + +fun functionReturnType(function: JetNamedFunction): JetType? { + val resolveSession = AnalyzerFacadeWithCache.getLazyResolveSessionForFile(function.getContainingFile() as JetFile) + val bindingContext = resolveSession.resolveToElement(function) + val descriptor = bindingContext.get(BindingContext.DECLARATION_TO_DESCRIPTOR, function) + if (descriptor == null) return null + return (descriptor as FunctionDescriptor).getReturnType() +} diff --git a/idea/testData/intentions/convertToBlockBody/afterExplicitlyNonUnitFun.kt b/idea/testData/intentions/convertToBlockBody/afterExplicitlyNonUnitFun.kt new file mode 100644 index 00000000000..e5ccc8d2fcb --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterExplicitlyNonUnitFun.kt @@ -0,0 +1,4 @@ +// "Convert to block body" "true" +fun foo(): String { + return "abc" +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/afterExplicitlyTypedFunWithUnresolvedExpression.kt b/idea/testData/intentions/convertToBlockBody/afterExplicitlyTypedFunWithUnresolvedExpression.kt new file mode 100644 index 00000000000..e9e5dc494f0 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterExplicitlyTypedFunWithUnresolvedExpression.kt @@ -0,0 +1,5 @@ +// "Convert to block body" "true" +// ERROR: Unresolved reference: bar +fun foo(): String { + return bar() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/afterExplicitlyTypedFunWithUnresolvedType.kt b/idea/testData/intentions/convertToBlockBody/afterExplicitlyTypedFunWithUnresolvedType.kt new file mode 100644 index 00000000000..4250fa599da --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterExplicitlyTypedFunWithUnresolvedType.kt @@ -0,0 +1,6 @@ +// "Convert to block body" "true" +// ERROR: Unresolved reference: XXX +// ERROR: Unresolved reference: bar +fun foo(): XXX { + return bar() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/afterExplicitlyUnitFun.kt b/idea/testData/intentions/convertToBlockBody/afterExplicitlyUnitFun.kt new file mode 100644 index 00000000000..863820e77f9 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterExplicitlyUnitFun.kt @@ -0,0 +1,6 @@ +// "Convert to block body" "true" +fun foo(): Unit { + bar() +} + +fun bar() { } \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/afterExplicitlyUnitFunWithUnresolvedExpression.kt b/idea/testData/intentions/convertToBlockBody/afterExplicitlyUnitFunWithUnresolvedExpression.kt new file mode 100644 index 00000000000..89be834b5ce --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterExplicitlyUnitFunWithUnresolvedExpression.kt @@ -0,0 +1,5 @@ +// "Convert to block body" "true" +// ERROR: Unresolved reference: bar +fun foo(): Unit { + bar() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/afterFunWithThrow.kt b/idea/testData/intentions/convertToBlockBody/afterFunWithThrow.kt new file mode 100644 index 00000000000..2575862c23d --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterFunWithThrow.kt @@ -0,0 +1,4 @@ +// "Convert to block body" "true" +fun foo(): String { + throw UnsupportedOperationException() +} diff --git a/idea/testData/intentions/convertToBlockBody/afterGetter.kt b/idea/testData/intentions/convertToBlockBody/afterGetter.kt new file mode 100644 index 00000000000..7283bddc24f --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterGetter.kt @@ -0,0 +1,5 @@ +// "Convert to block body" "true" +val foo: String + get() { + return "abc" + } diff --git a/idea/testData/intentions/convertToBlockBody/afterGetterWithThrow.kt b/idea/testData/intentions/convertToBlockBody/afterGetterWithThrow.kt new file mode 100644 index 00000000000..38c6f520198 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterGetterWithThrow.kt @@ -0,0 +1,5 @@ +// "Convert to block body" "true" +val foo: String + get() { + throw UnsupportedOperationException() + } diff --git a/idea/testData/intentions/convertToBlockBody/afterImplicitlyNonUnitFun.kt b/idea/testData/intentions/convertToBlockBody/afterImplicitlyNonUnitFun.kt new file mode 100644 index 00000000000..67fee5fc663 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterImplicitlyNonUnitFun.kt @@ -0,0 +1,6 @@ +// "Convert to block body" "true" +import java.net.URI + +fun foo(): URI { + return java.io.File("x").toURI() +} \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/afterImplicitlyUnitFun.kt b/idea/testData/intentions/convertToBlockBody/afterImplicitlyUnitFun.kt new file mode 100644 index 00000000000..ca221f8f45d --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterImplicitlyUnitFun.kt @@ -0,0 +1,6 @@ +// "Convert to block body" "true" +fun foo() { + bar() +} + +fun bar() { } \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/afterNothingFun.kt b/idea/testData/intentions/convertToBlockBody/afterNothingFun.kt new file mode 100644 index 00000000000..5b860e242b8 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterNothingFun.kt @@ -0,0 +1,4 @@ +// "Convert to block body" "true" +fun foo(): Nothing { + throw UnsupportedOperationException() +} diff --git a/idea/testData/intentions/convertToBlockBody/afterSetter.kt b/idea/testData/intentions/convertToBlockBody/afterSetter.kt new file mode 100644 index 00000000000..1dd47224ffd --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/afterSetter.kt @@ -0,0 +1,8 @@ +// "Convert to block body" "true" +var foo: String + get() = "abc" + set(value) { + doSet(value) + } + +fun doSet(value: String){} \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeExplicitlyNonUnitFun.kt b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyNonUnitFun.kt new file mode 100644 index 00000000000..62c70de650f --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyNonUnitFun.kt @@ -0,0 +1,2 @@ +// "Convert to block body" "true" +fun foo(): String = "abc" \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeExplicitlyTypedFunWithUnresolvedExpression.kt b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyTypedFunWithUnresolvedExpression.kt new file mode 100644 index 00000000000..f0cd89549fa --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyTypedFunWithUnresolvedExpression.kt @@ -0,0 +1,3 @@ +// "Convert to block body" "true" +// ERROR: Unresolved reference: bar +fun foo(): String = bar() \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeExplicitlyTypedFunWithUnresolvedType.kt b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyTypedFunWithUnresolvedType.kt new file mode 100644 index 00000000000..6adedad467e --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyTypedFunWithUnresolvedType.kt @@ -0,0 +1,4 @@ +// "Convert to block body" "true" +// ERROR: Unresolved reference: XXX +// ERROR: Unresolved reference: bar +fun foo(): XXX = bar() \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeExplicitlyUnitFun.kt b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyUnitFun.kt new file mode 100644 index 00000000000..1a4fd1c965e --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyUnitFun.kt @@ -0,0 +1,4 @@ +// "Convert to block body" "true" +fun foo(): Unit = bar() + +fun bar() { } \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeExplicitlyUnitFunWithUnresolvedExpression.kt b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyUnitFunWithUnresolvedExpression.kt new file mode 100644 index 00000000000..9b04cc50eb6 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeExplicitlyUnitFunWithUnresolvedExpression.kt @@ -0,0 +1,3 @@ +// "Convert to block body" "true" +// ERROR: Unresolved reference: bar +fun foo(): Unit = bar() \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeFunWithThrow.kt b/idea/testData/intentions/convertToBlockBody/beforeFunWithThrow.kt new file mode 100644 index 00000000000..690a5b74894 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeFunWithThrow.kt @@ -0,0 +1,2 @@ +// "Convert to block body" "true" +fun foo(): String = throw UnsupportedOperationException() diff --git a/idea/testData/intentions/convertToBlockBody/beforeGetter.kt b/idea/testData/intentions/convertToBlockBody/beforeGetter.kt new file mode 100644 index 00000000000..4a43535a1cf --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeGetter.kt @@ -0,0 +1,3 @@ +// "Convert to block body" "true" +val foo: String + get() = "abc" diff --git a/idea/testData/intentions/convertToBlockBody/beforeGetterWithThrow.kt b/idea/testData/intentions/convertToBlockBody/beforeGetterWithThrow.kt new file mode 100644 index 00000000000..89f3627c261 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeGetterWithThrow.kt @@ -0,0 +1,3 @@ +// "Convert to block body" "true" +val foo: String + get() = throw UnsupportedOperationException() diff --git a/idea/testData/intentions/convertToBlockBody/beforeImplicitlyNonUnitFun.kt b/idea/testData/intentions/convertToBlockBody/beforeImplicitlyNonUnitFun.kt new file mode 100644 index 00000000000..a2fda239325 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeImplicitlyNonUnitFun.kt @@ -0,0 +1,2 @@ +// "Convert to block body" "true" +fun foo() = java.io.File("x").toURI() \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeImplicitlyTypedFunWithUnresolvedType.kt b/idea/testData/intentions/convertToBlockBody/beforeImplicitlyTypedFunWithUnresolvedType.kt new file mode 100644 index 00000000000..9d67eb2d2a6 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeImplicitlyTypedFunWithUnresolvedType.kt @@ -0,0 +1,3 @@ +// "Convert to block body" "false" +// ERROR: Unresolved reference: bar +fun foo() = bar() \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeImplicitlyUnitFun.kt b/idea/testData/intentions/convertToBlockBody/beforeImplicitlyUnitFun.kt new file mode 100644 index 00000000000..9a219f8eb80 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeImplicitlyUnitFun.kt @@ -0,0 +1,4 @@ +// "Convert to block body" "true" +fun foo() = bar() + +fun bar() { } \ No newline at end of file diff --git a/idea/testData/intentions/convertToBlockBody/beforeNothingFun.kt b/idea/testData/intentions/convertToBlockBody/beforeNothingFun.kt new file mode 100644 index 00000000000..a0bf8315cbd --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeNothingFun.kt @@ -0,0 +1,2 @@ +// "Convert to block body" "true" +fun foo(): Nothing = throw UnsupportedOperationException() diff --git a/idea/testData/intentions/convertToBlockBody/beforeSetter.kt b/idea/testData/intentions/convertToBlockBody/beforeSetter.kt new file mode 100644 index 00000000000..11a54d01b05 --- /dev/null +++ b/idea/testData/intentions/convertToBlockBody/beforeSetter.kt @@ -0,0 +1,6 @@ +// "Convert to block body" "true" +var foo: String + get() = "abc" + set(value) = doSet(value) + +fun doSet(value: String){} \ No newline at end of file diff --git a/idea/tests/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyTestGenerated.java b/idea/tests/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyTestGenerated.java new file mode 100644 index 00000000000..a27985ee716 --- /dev/null +++ b/idea/tests/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyTestGenerated.java @@ -0,0 +1,104 @@ +/* + * 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 junit.framework.Assert; +import junit.framework.Test; +import junit.framework.TestSuite; + +import java.io.File; +import java.util.regex.Pattern; +import org.jetbrains.jet.JetTestUtils; +import org.jetbrains.jet.test.InnerTestClasses; +import org.jetbrains.jet.test.TestMetadata; + +import org.jetbrains.jet.plugin.intentions.AbstractIntentionTest; + +/** This class is generated by {@link org.jetbrains.jet.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +@SuppressWarnings("all") +@TestMetadata("idea/testData/intentions/convertToBlockBody") +public class ConvertToBlockBodyTestGenerated extends AbstractIntentionTest { + public void testAllFilesPresentInConvertToBlockBody() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("idea/testData/intentions/convertToBlockBody"), Pattern.compile("^before(\\w+)\\.kt$"), true); + } + + @TestMetadata("beforeExplicitlyNonUnitFun.kt") + public void testExplicitlyNonUnitFun() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeExplicitlyNonUnitFun.kt"); + } + + @TestMetadata("beforeExplicitlyTypedFunWithUnresolvedExpression.kt") + public void testExplicitlyTypedFunWithUnresolvedExpression() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeExplicitlyTypedFunWithUnresolvedExpression.kt"); + } + + @TestMetadata("beforeExplicitlyTypedFunWithUnresolvedType.kt") + public void testExplicitlyTypedFunWithUnresolvedType() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeExplicitlyTypedFunWithUnresolvedType.kt"); + } + + @TestMetadata("beforeExplicitlyUnitFun.kt") + public void testExplicitlyUnitFun() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeExplicitlyUnitFun.kt"); + } + + @TestMetadata("beforeExplicitlyUnitFunWithUnresolvedExpression.kt") + public void testExplicitlyUnitFunWithUnresolvedExpression() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeExplicitlyUnitFunWithUnresolvedExpression.kt"); + } + + @TestMetadata("beforeFunWithThrow.kt") + public void testFunWithThrow() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeFunWithThrow.kt"); + } + + @TestMetadata("beforeGetter.kt") + public void testGetter() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeGetter.kt"); + } + + @TestMetadata("beforeGetterWithThrow.kt") + public void testGetterWithThrow() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeGetterWithThrow.kt"); + } + + @TestMetadata("beforeImplicitlyNonUnitFun.kt") + public void testImplicitlyNonUnitFun() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeImplicitlyNonUnitFun.kt"); + } + + @TestMetadata("beforeImplicitlyTypedFunWithUnresolvedType.kt") + public void testImplicitlyTypedFunWithUnresolvedType() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeImplicitlyTypedFunWithUnresolvedType.kt"); + } + + @TestMetadata("beforeImplicitlyUnitFun.kt") + public void testImplicitlyUnitFun() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeImplicitlyUnitFun.kt"); + } + + @TestMetadata("beforeNothingFun.kt") + public void testNothingFun() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeNothingFun.kt"); + } + + @TestMetadata("beforeSetter.kt") + public void testSetter() throws Exception { + doTest("idea/testData/intentions/convertToBlockBody/beforeSetter.kt"); + } + +}