diff --git a/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/ext/spock/SpockCantBeStaticExtension.kt b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/ext/spock/SpockCantBeStaticExtension.kt new file mode 100644 index 000000000000..040de8216205 --- /dev/null +++ b/plugins/groovy/groovy-psi/src/org/jetbrains/plugins/groovy/ext/spock/SpockCantBeStaticExtension.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2000-2017 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.ext.spock + +import com.intellij.openapi.util.Condition +import com.intellij.psi.PsiElement +import org.jetbrains.plugins.groovy.ext.spock.SpockUtils.* +import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod + +class SpockCantBeStaticExtension : Condition { + + override fun value(element: PsiElement?): Boolean { + return element is GrMethod + && isSpecification(element.containingClass) + && (isFeatureMethod(element) || isFixtureMethod(element)) + } +} \ No newline at end of file diff --git a/plugins/groovy/src/META-INF/spock-support.xml b/plugins/groovy/src/META-INF/spock-support.xml index 770c423608e3..6fae11a91044 100644 --- a/plugins/groovy/src/META-INF/spock-support.xml +++ b/plugins/groovy/src/META-INF/spock-support.xml @@ -6,5 +6,6 @@ + \ No newline at end of file diff --git a/plugins/groovy/test/org/jetbrains/plugins/groovy/ext/spock/SpockTest.groovy b/plugins/groovy/test/org/jetbrains/plugins/groovy/ext/spock/SpockTest.groovy index 34c221561ea5..a5817910f511 100644 --- a/plugins/groovy/test/org/jetbrains/plugins/groovy/ext/spock/SpockTest.groovy +++ b/plugins/groovy/test/org/jetbrains/plugins/groovy/ext/spock/SpockTest.groovy @@ -22,6 +22,7 @@ import com.intellij.psi.PsiVariable import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import com.intellij.util.containers.ContainerUtil import org.jetbrains.plugins.groovy.codeInspection.assignment.GroovyAssignabilityCheckInspection +import org.jetbrains.plugins.groovy.codeInspection.declaration.GrMethodMayBeStaticInspection import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection /** @@ -244,4 +245,20 @@ class FooSpec extends spock.lang.Specification { assert !elements.contains("_") } + void 'test method may be static'() { + myFixture.configureByText 'specs.groovy', '''\ +class SomeSpec extends spock.lang.Specification { + def cleanup() {} + def setupSpec() {} + def regularMethod() {} + def featureMethod() { + expect: 1 == 1 + } +} +''' + def inspection = new GrMethodMayBeStaticInspection() + inspection.myIgnoreEmptyMethods = false + myFixture.enableInspections inspection + myFixture.checkHighlighting() + } }