void (@NotNull GrReferenceExpression ref) { final PsiElement resolved = ref.resolve(); if (resolved instanceof GrField field && resolved.isPhysical() && ((GrField)resolved).hasModifierProperty(PsiModifier.FINAL) && PsiUtil.isLValue(ref)) { final PsiClass containingClass = field.getContainingClass(); if (containingClass != null && PsiTreeUtil.isAncestor(containingClass, ref, true)) { GrMember container = GrHighlightUtil.findClassMemberContainer(ref, containingClass); if (field.hasModifierProperty(PsiModifier.STATIC)) { if (container instanceof GrClassInitializer && ((GrClassInitializer)container).isStatic()) { return; } } else { if (container instanceof GrMethod && ((GrMethod)container).isConstructor() || container instanceof GrClassInitializer && !((GrClassInitializer)container).isStatic()) { return; } } myHolder.newAnnotation(HighlightSeverity.ERROR, GroovyBundle.message("cannot.assign.a.value.to.final.field.0", field.getName())).create(); } } }