mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[groovy] do not allow modifier 'static' on toplevel classes (IDEA-162294)
This commit is contained in:
@@ -180,6 +180,7 @@ illegal.combination.of.modifiers=Illegal combination of modifiers
|
||||
illegal.combination.of.modifiers.abstract.and.final=Illegal combination of modifiers 'abstract' and 'final'
|
||||
modifier.volatile.not.allowed.here=Modifier 'volatile' not allowed here
|
||||
modifier.transient.not.allowed.here=Modifier 'transient' not allowed here
|
||||
modifier.0.not.allowed=Modifier ''{0}'' not allowed here
|
||||
intarface.cannot.have.modifier.final=Interface cannot have modifier 'final'
|
||||
script.method.cannot.have.modifier.abstract=Script method cannot have modifier 'abstract'
|
||||
script.cannot.have.modifier.native=Script cannot have modifier 'native'
|
||||
|
||||
+6
@@ -1906,6 +1906,12 @@ public class GroovyAnnotator extends GroovyElementVisitor {
|
||||
if (typeDefinition.isInterface()) {
|
||||
checkModifierIsNotAllowed(modifiersList, PsiModifier.FINAL, GroovyBundle.message("intarface.cannot.have.modifier.final"), holder);
|
||||
}
|
||||
|
||||
if (GroovyConfigUtils.getInstance().isVersionAtLeast(typeDefinition, GroovyConfigUtils.GROOVY1_8)) {
|
||||
if (typeDefinition.getContainingClass() == null && !(typeDefinition instanceof GrTraitTypeDefinition)) {
|
||||
checkModifierIsNotAllowed(modifiersList, PsiModifier.STATIC, holder);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void checkDuplicateModifiers(AnnotationHolder holder, @NotNull GrModifierList list, PsiMember member) {
|
||||
|
||||
@@ -38,6 +38,12 @@ internal fun checkVariableModifiers(holder: AnnotationHolder, variableDeclaratio
|
||||
}
|
||||
}
|
||||
|
||||
internal fun checkModifierIsNotAllowed(modifierList: GrModifierList,
|
||||
@GrModifierConstant modifier: String,
|
||||
holder: AnnotationHolder) {
|
||||
checkModifierIsNotAllowed(modifierList, modifier, GroovyBundle.message("modifier.0.not.allowed", modifier), holder)
|
||||
}
|
||||
|
||||
internal fun checkModifierIsNotAllowed(modifierList: GrModifierList,
|
||||
@GrModifierConstant modifier: String,
|
||||
message: String?,
|
||||
|
||||
+9
@@ -62,4 +62,13 @@ class Groovy16HighlightingTest extends LightCodeInsightFixtureTestCase {
|
||||
void testSlashyStrings() { doTest() }
|
||||
|
||||
void testDiamonds() { doTest() }
|
||||
|
||||
void 'test static modifier on toplevel definition is allowed'() {
|
||||
myFixture.with {
|
||||
configureByText '_.groovy', '''\
|
||||
static class A {}
|
||||
static interface A {}
|
||||
'''
|
||||
}
|
||||
}
|
||||
}
|
||||
+8
-1
@@ -17,7 +17,6 @@ package org.jetbrains.plugins.groovy.lang.highlighting
|
||||
|
||||
import com.intellij.codeInsight.generation.OverrideImplementExploreUtil
|
||||
import com.intellij.codeInspection.InspectionProfileEntry
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.util.PsiTreeUtil
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.annotations.NotNull
|
||||
@@ -270,5 +269,13 @@ class A {
|
||||
}
|
||||
}
|
||||
|
||||
void 'test static modifier on toplevel definition (not trait) is not allowed'() {
|
||||
testHighlighting '''\
|
||||
<error descr="Modifier 'static' not allowed here">static</error> class A {}
|
||||
<error descr="Modifier 'static' not allowed here">static</error> interface I {}
|
||||
static trait T {}
|
||||
'''
|
||||
}
|
||||
|
||||
final InspectionProfileEntry[] customInspections = [new GroovyAssignabilityCheckInspection(), new GrUnresolvedAccessInspection()]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user