IDEA-97643 don't highlight methods of @Category annotated class with 'Method may be static'

This commit is contained in:
Max Medvedev
2012-12-17 18:56:25 +04:00
parent ab70904aa3
commit 116b8ce362
3 changed files with 55 additions and 0 deletions
+2
View File
@@ -346,6 +346,8 @@
order="last"/>
<completion.contributor language="Groovy" implementationClass="org.jetbrains.plugins.groovy.geb.GebPageFieldNameCompletionContributor"/>
<cantBeStatic implementation="org.jetbrains.plugins.groovy.codeInspection.declaration.GrCategoryMethodsCantBeStaticExtension" />
<psi.referenceContributor language="Properties" implementation="org.jetbrains.plugins.groovy.dgm.DGMReferenceContributor"/>
<weigher key="completion" implementationClass="org.jetbrains.plugins.groovy.lang.completion.weighers.GrWithWeigher"
@@ -0,0 +1,36 @@
/*
* 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.codeInspection.declaration;
import com.intellij.openapi.util.Condition;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
import org.jetbrains.plugins.groovy.lang.psi.util.GdkMethodUtil;
public class GrCategoryMethodsCantBeStaticExtension implements Condition<PsiElement> {
@Override
public boolean value(PsiElement t) {
if (t instanceof GrMethod) {
final PsiClass clazz = ((GrMethod)t).getContainingClass();
if (clazz != null && GdkMethodUtil.getCategoryType(clazz) != null) {
return true;
}
}
return false;
}
}
@@ -21,6 +21,7 @@ import org.jetbrains.plugins.groovy.codeInspection.confusing.*
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialConditionalInspection
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyTrivialIfInspection
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyUnnecessaryReturnInspection
import org.jetbrains.plugins.groovy.codeInspection.declaration.GrMethodMayBeStaticInspection
import org.jetbrains.plugins.groovy.codeInspection.metrics.GroovyOverlyLongMethodInspection
import org.jetbrains.plugins.groovy.codeInspection.noReturnMethod.MissingReturnInspection
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GrUnresolvedAccessInspection
@@ -184,4 +185,20 @@ print foo+<warning descr="Access to 'bar' exceeds its access rights">bar</warnin
public void testUntypedAccess() { doTest(new GroovyUntypedAccessInspection()) }
public void testMethodMayBeStaticForCategoryClasses() {
testHighlighting('''\
class Cat{
def <warning descr="Method may be static">foo</warning>() {
print 2
}
}
@groovy.lang.Category(Cat)
class I{
def foo() {
print 2
}
}
''', GrMethodMayBeStaticInspection)
}
}