LocalQuickFix (@NotNull PsiExpression argument, @NotNull AllowedValues allowedValues) { Object argumentValue = JavaConstantExpressionEvaluator.computeConstantExpression(argument, null, false); if (argumentValue == null) return null; if (!allowedValues.isFlagSet()) { for (PsiAnnotationMemberValue value : allowedValues.getValues()) { if (value instanceof PsiExpression expression) { Object constantValue = JavaConstantExpressionEvaluator.computeConstantExpression(expression, null, false); if (argumentValue.equals(constantValue)) { return LocalQuickFix.from(new ReplaceWithMagicConstantFix(argument, value)); } } } } else { Long longArgument = evaluateLongConstant(argument); if (longArgument == null) { return null; } // try to find ored flags long remainingFlags = longArgument.longValue(); List<PsiAnnotationMemberValue> flags = new ArrayList<>(); for (PsiAnnotationMemberValue value : allowedValues.getValues()) { if (value instanceof PsiExpression expression) { Long constantValue = evaluateLongConstant(expression); if (constantValue == null) { continue; } if ((remainingFlags & constantValue) == constantValue) { flags.add(value); remainingFlags &= ~constantValue; } } } if (remainingFlags == 0) { // found flags to combine with OR, suggest the fix if (flags.size() > 1) { for (int i = flags.size() - 1; i >= 0; i--) { PsiAnnotationMemberValue flag = flags.get(i); Long flagValue = evaluateLongConstant((PsiExpression)flag); if (flagValue != null && flagValue == 0) { // no sense in ORing with '0' flags.remove(i); } } } if (!flags.isEmpty()) { return LocalQuickFix.from(new ReplaceWithMagicConstantFix(argument, flags.toArray(PsiAnnotationMemberValue.EMPTY_ARRAY))); } } } return null; }