diff options
Diffstat (limited to 'plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java')
-rw-r--r-- | plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java index c79a60d198f7..15edeedc9246 100644 --- a/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java +++ b/plugins/InspectionGadgets/src/com/siyeh/ig/psiutils/ExpressionUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2005-2012 Bas Leijdekkers + * Copyright 2005-2013 Bas Leijdekkers * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -155,6 +155,19 @@ public class ExpressionUtils { } @Nullable + public static String getLiteralString(@Nullable PsiExpression expression) { + final PsiLiteralExpression literal = getLiteral(expression); + if (literal == null) { + return null; + } + final Object value = literal.getValue(); + if (value == null) { + return null; + } + return value.toString(); + } + + @Nullable public static PsiLiteralExpression getLiteral(@Nullable PsiExpression expression) { expression = ParenthesesUtils.stripParentheses(expression); if (expression instanceof PsiLiteralExpression) { |