extract getStringAttributeValue(PsiAnnotationMemberValue)

This commit is contained in:
Daniil Ovchinnikov
2018-02-14 17:02:26 +03:00
parent 20200ec5e1
commit b6dbb1a1b2
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.codeInsight;
import com.intellij.openapi.project.Project;
@@ -480,9 +478,9 @@ public class AnnotationUtil {
@Nullable
public static String getStringAttributeValue(@NotNull PsiAnnotation anno, @Nullable final String attributeName) {
PsiAnnotationMemberValue attrValue = anno.findAttributeValue(attributeName);
Object constValue = JavaPsiFacade.getInstance(anno.getProject()).getConstantEvaluationHelper().computeConstantExpression(attrValue);
return constValue instanceof String ? (String)constValue : null;
return attrValue == null ? null : getStringAttributeValue(attrValue);
}
@Nullable
public static Boolean getBooleanAttributeValue(@NotNull PsiAnnotation anno, @Nullable final String attributeName) {
PsiAnnotationMemberValue attrValue = anno.findAttributeValue(attributeName);
@@ -500,7 +498,13 @@ public class AnnotationUtil {
@Nullable
public static String getDeclaredStringAttributeValue(@NotNull PsiAnnotation anno, @Nullable final String attributeName) {
PsiAnnotationMemberValue attrValue = anno.findDeclaredAttributeValue(attributeName);
Object constValue = JavaPsiFacade.getInstance(anno.getProject()).getConstantEvaluationHelper().computeConstantExpression(attrValue);
return attrValue == null ? null : getStringAttributeValue(attrValue);
}
@Nullable
public static String getStringAttributeValue(@NotNull PsiAnnotationMemberValue attrValue) {
PsiConstantEvaluationHelper evaluationHelper = JavaPsiFacade.getInstance(attrValue.getProject()).getConstantEvaluationHelper();
Object constValue = evaluationHelper.computeConstantExpression(attrValue);
return constValue instanceof String ? (String)constValue : null;
}