AllowedValues (@NotNull PsiType type, @NotNull PsiAnnotation magic, @NotNull PsiManager manager, @Nullable PsiElement context) { PsiAnnotationMemberValue[] allowedValues = PsiAnnotationMemberValue.EMPTY_ARRAY; boolean values = false; boolean flags = false; if (TypeConversionUtil.getTypeRank(type) <= TypeConversionUtil.LONG_RANK) { PsiAnnotationMemberValue intValues = magic.findAttributeValue("intValues"); if (intValues instanceof PsiArrayInitializerMemberValue) { final PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue)intValues).getInitializers(); if (initializers.length != 0) { allowedValues = initializers; values = true; } } if (!values) { PsiAnnotationMemberValue orValue = magic.findAttributeValue("flags"); if (orValue instanceof PsiArrayInitializerMemberValue) { final PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue)orValue).getInitializers(); if (initializers.length != 0) { allowedValues = initializers; flags = true; } } } } else if (type.equals(PsiType.getJavaLangString(manager, GlobalSearchScope.allScope(manager.getProject())))) { PsiAnnotationMemberValue strValuesAttr = magic.findAttributeValue("stringValues"); if (strValuesAttr instanceof PsiArrayInitializerMemberValue) { final PsiAnnotationMemberValue[] initializers = ((PsiArrayInitializerMemberValue)strValuesAttr).getInitializers(); if (initializers.length != 0) { allowedValues = initializers; values = true; } } } else { return null; //other types not supported } PsiAnnotationMemberValue[] valuesFromClass = readFromClass("valuesFromClass", magic, type, manager, context); if (valuesFromClass != null) { allowedValues = ArrayUtil.mergeArrays(allowedValues, valuesFromClass, PsiAnnotationMemberValue.ARRAY_FACTORY); values = true; } PsiAnnotationMemberValue[] flagsFromClass = readFromClass("flagsFromClass", magic, type, manager, context); if (flagsFromClass != null) { allowedValues = ArrayUtil.mergeArrays(allowedValues, flagsFromClass, PsiAnnotationMemberValue.ARRAY_FACTORY); flags = true; } if (allowedValues.length == 0) { return null; } if (values && flags) { throw new IncorrectOperationException( "Misconfiguration of @MagicConstant annotation: 'flags' and 'values' shouldn't be used at the same time"); } return new AllowedValues(allowedValues, flags); }