diff --git a/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/after.groovy.template b/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/after.groovy.template new file mode 100644 index 000000000000..480978ef6ab2 --- /dev/null +++ b/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/after.groovy.template @@ -0,0 +1 @@ +def getName() {name} \ No newline at end of file diff --git a/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/before.groovy.template b/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/before.groovy.template new file mode 100644 index 000000000000..f4c46019e906 --- /dev/null +++ b/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/before.groovy.template @@ -0,0 +1 @@ +def getName() {return name} \ No newline at end of file diff --git a/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/description.html b/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/description.html new file mode 100644 index 000000000000..27201e0535fd --- /dev/null +++ b/plugins/groovy/resources/intentionDescriptions/RemoveUnnecessaryReturnIntention/description.html @@ -0,0 +1,5 @@ + + +This intention removes unnecessary 'return' keyword from return statement. + + \ No newline at end of file diff --git a/plugins/groovy/src/META-INF/plugin.xml b/plugins/groovy/src/META-INF/plugin.xml index 7caedb96b48c..0dd2a5fb8a66 100644 --- a/plugins/groovy/src/META-INF/plugin.xml +++ b/plugins/groovy/src/META-INF/plugin.xml @@ -1200,6 +1200,11 @@ intention.category.groovy/intention.category.groovy.style org.jetbrains.plugins.groovy.intentions.style.ConvertFromGeeseBracesIntention + + org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle + intention.category.groovy/intention.category.groovy.style + org.jetbrains.plugins.groovy.intentions.style.RemoveUnnecessaryReturnIntention + org.jetbrains.plugins.groovy.intentions.GroovyIntentionsBundle intention.category.groovy/intention.category.groovy.style diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties index 424a55828ecb..b950eb295eb1 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/GroovyIntentionsBundle.properties @@ -177,4 +177,6 @@ gr.create.missing.switch.branches.intention.family.name=Create missing 'switch' remove.redundant.class.property.intention.name=Remove redundant .class remove.redundant.class.property.intention.family.name=Remove redundant .class convert.simple.getter.to.property.intention.name=Convert to property -convert.simple.getter.to.property.intention.family.name=Convert simple getter to property \ No newline at end of file +convert.simple.getter.to.property.intention.family.name=Convert simple getter to property +remove.unnecessary.return.intention.name=Remove 'return' keyword +remove.unnecessary.return.intention.family.name=Remove unnecessary 'return' keyword \ No newline at end of file diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/RemoveUnnecessaryReturnIntention.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/RemoveUnnecessaryReturnIntention.java new file mode 100644 index 000000000000..f02c0ce54ee3 --- /dev/null +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/intentions/style/RemoveUnnecessaryReturnIntention.java @@ -0,0 +1,51 @@ +/* + * Copyright 2000-2012 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.plugins.groovy.intentions.style; + +import com.intellij.openapi.editor.Editor; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiElement; +import com.intellij.util.IncorrectOperationException; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.plugins.groovy.intentions.base.Intention; +import org.jetbrains.plugins.groovy.intentions.base.PsiElementPredicate; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.branch.GrReturnStatement; +import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression; + +/** + * @author Max Medvedev + */ +public class RemoveUnnecessaryReturnIntention extends Intention { + @Override + protected void processIntention(@NotNull PsiElement element, Project project, Editor editor) throws IncorrectOperationException { + if (element instanceof GrReturnStatement && ((GrReturnStatement)element).getReturnValue() != null) { + GrExpression value = ((GrReturnStatement)element).getReturnValue(); + + ((GrReturnStatement)element).replaceWithStatement(value); + } + } + + @NotNull + @Override + protected PsiElementPredicate getElementPredicate() { + return new PsiElementPredicate() { + @Override + public boolean satisfiedBy(PsiElement element) { + return element instanceof GrReturnStatement && ((GrReturnStatement)element).getReturnValue() != null; + } + }; + } +}