boolean (@Nullable PsiType expectedType, @NotNull GrExpression expression, @NotNull GroovyPsiElement elementToHighlight) { if (!(expectedType instanceof PsiClassType)) return false; if (!GroovyConfigUtils.getInstance().isVersionAtLeast(elementToHighlight, GroovyConfigUtils.GROOVY1_8)) return false; final PsiClass resolved = ((PsiClassType)expectedType).resolve(); if (resolved == null || !resolved.isEnum()) return false; final PsiType type = expression.getType(); if (type == null) return false; if (!type.equalsToText(GroovyCommonClassNames.GROOVY_LANG_GSTRING) && !type.equalsToText(CommonClassNames.JAVA_LANG_STRING)) { return false; } final Object result = GroovyConstantExpressionEvaluator.evaluate(expression); if (!(result instanceof String)) { registerError( elementToHighlight, ProblemHighlightType.WEAK_WARNING, GroovyBundle.message("cannot.assign.string.to.enum.0", expectedType.getPresentableText()) ); } else { final PsiField field = resolved.findFieldByName((String)result, true); if (!(field instanceof PsiEnumConstant)) { registerError( elementToHighlight, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, GroovyBundle.message("cannot.find.enum.constant.0.in.enum.1", result, expectedType.getPresentableText()) ); } } return true; }