T value = null;
if (psiElement instanceof PsiReferenceExpression) {
final PsiElement resolved = ((PsiReferenceExpression) psiElement).resolve();
if (resolved instanceof PsiEnumConstant) {
final PsiEnumConstant psiEnumConstant = (PsiEnumConstant) resolved;
//Enums are supported as VALUE-Strings only
if (asClass.isAssignableFrom(String.class)) {
value = (T) psiEnumConstant.getName();
}
} else if (resolved instanceof PsiVariable) {
final PsiVariable psiVariable = (PsiVariable) resolved;
Object elementValue = psiVariable.computeConstantValue();
if (null != elementValue && asClass.isAssignableFrom(elementValue.getClass())) {