void (@NotNull GrReferenceExpression referenceExpression) { final PsiElement resolved = referenceExpression.resolve(); if (resolved instanceof PsiVariable) { if (!isStaticFinalField((PsiVariable)resolved)) { if (expr instanceof GrClosableBlock) { if (!PsiTreeUtil.isContextAncestor(scope, resolved, true)) { throw new GrRefactoringError(GroovyRefactoringBundle.message("closure.uses.external.variables")); } } else { throw new GrRefactoringError(JavaRefactoringBundle.message("selected.expression.cannot.be.a.constant.initializer")); } } } else if (resolved instanceof PsiMethod && ((PsiMethod)resolved).getContainingClass() != null) { final GrExpression qualifier = referenceExpression.getQualifierExpression(); if (qualifier == null || (qualifier instanceof GrReferenceExpression && ((GrReferenceExpression)qualifier).resolve() instanceof PsiClass)) { if (!((PsiMethod)resolved).hasModifierProperty(PsiModifier.STATIC)) { throw new GrRefactoringError(JavaRefactoringBundle.message("selected.expression.cannot.be.a.constant.initializer")); } } } }