IDEA-CR-34213 IDEA-194406 @ImmutableOptions and @KnownImmutable Groovy 2.5.0 support

This commit is contained in:
alexey.afanasiev
2018-06-28 16:17:40 +03:00
parent 89bb14669b
commit daa264efff
3 changed files with 7 additions and 5 deletions
@@ -220,7 +220,7 @@ final.class.cannot.be.extended=Final class cannot be extended
#Groovy 2.5 checks
duplicating.named.parameter=Duplicate named parameter ''{0}'' occurs in parameters: {1}
field.should.be.immutable=Parameter ''{0}'' should have immutable type or be declared so with @ImmutableOptions
field.should.be.immutable=Field ''{0}'' should have immutable type or be declared so with @ImmutableOptions
#Groovy 3.0 checks
illegal.default.modifier=Modifier 'default' makes sense only in interface's methods
@@ -2,6 +2,7 @@
package org.jetbrains.plugins.groovy.annotator
import com.intellij.lang.annotation.AnnotationHolder
import com.intellij.psi.PsiModifier
import org.jetbrains.plugins.groovy.GroovyBundle
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrField
@@ -32,7 +33,7 @@ class GroovyAnnotator25(private val holder: AnnotationHolder) : GroovyElementVis
private fun immutableCheck(field: GrField) {
val containingClass = field.containingClass ?: return
if (field.isProperty && hasImmutableAnnotation(containingClass) && !isImmutable(field)) {
if (!field.hasModifierProperty(PsiModifier.STATIC) && hasImmutableAnnotation(containingClass) && !isImmutable(field)) {
holder.createErrorAnnotation(field.nameIdentifierGroovy, GroovyBundle.message("field.should.be.immutable", field.name))
}
}
@@ -6,13 +6,14 @@ import groovy.transform.KnownImmutable
@Immutable
class A {
int a
private Iterator b
Iterator <error descr="Parameter 'c' should have immutable type or be declared so with @ImmutableOptions">c</error>
private Iterator <error descr="Field 'b' should have immutable type or be declared so with @ImmutableOptions">b</error>
private static Iterator b2
Iterator <error descr="Field 'c' should have immutable type or be declared so with @ImmutableOptions">c</error>
String d
E e
URI f
Thread g
MuttableClass <error descr="Parameter 'h' should have immutable type or be declared so with @ImmutableOptions">h</error>
MuttableClass <error descr="Field 'h' should have immutable type or be declared so with @ImmutableOptions">h</error>
MuttableClass h2
ImmuttableClass i
Object[] j = new Object[1]