Merge remote-tracking branch 'origin/master'

This commit is contained in:
Alexandr Evstigneev
2017-02-13 19:21:49 +03:00
3 changed files with 48 additions and 0 deletions
@@ -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<PsiElement> {
override fun value(element: PsiElement?): Boolean {
return element is GrMethod
&& isSpecification(element.containingClass)
&& (isFeatureMethod(element) || isFixtureMethod(element))
}
}
@@ -6,5 +6,6 @@
<extensions defaultExtensionNs="com.intellij">
<testFramework implementation="org.jetbrains.plugins.groovy.ext.spock.SpockTestFramework" order="first"/>
<pom.declarationSearcher implementation="org.jetbrains.plugins.groovy.ext.spock.SpockPomDeclarationSearcher"/>
<cantBeStatic implementation="org.jetbrains.plugins.groovy.ext.spock.SpockCantBeStaticExtension"/>
</extensions>
</idea-plugin>
@@ -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 <warning descr="Method may be static">regularMethod</warning>() {}
def featureMethod() {
expect: 1 == 1
}
}
'''
def inspection = new GrMethodMayBeStaticInspection()
inspection.myIgnoreEmptyMethods = false
myFixture.enableInspections inspection
myFixture.checkHighlighting()
}
}