/** * Evaluates the given node and returns the constant string it resolves to, if any. Convenience * wrapper which creates a new {@linkplain ConstantEvaluator}, evaluates the node and returns * the result if the result is a string. * * @param context the context to use to resolve field references, if any * @param node the node to compute the constant value for * @param allowUnknown whether we should construct the string even if some parts of it are * unknown * @return the corresponding string, if any * @deprecated Use {@link #evaluateString(JavaContext, PsiElement, boolean)} instead */ @Deprecated @Nullable public static String evaluateString(@NonNull JavaContext context, @NonNull Node node, boolean allowUnknown) { ConstantEvaluator evaluator = new ConstantEvaluator(context); if (allowUnknown) { evaluator.allowUnknowns(); } Object value = evaluator.evaluate(node); return value instanceof String ? (String) value : null; }
/** * Evaluates the given node and returns the constant string it resolves to, if any. Convenience * wrapper which creates a new {@linkplain ConstantEvaluator}, evaluates the node and returns * the result if the result is a string. * * @param context the context to use to resolve field references, if any * @param node the node to compute the constant value for * @param allowUnknown whether we should construct the string even if some parts of it are * unknown * @return the corresponding string, if any */ @Nullable public static String evaluateString(@Nullable JavaContext context, @NonNull PsiElement node, boolean allowUnknown) { ConstantEvaluator evaluator = new ConstantEvaluator(context); if (allowUnknown) { evaluator.allowUnknowns(); } Object value = evaluator.evaluate(node); return value instanceof String ? (String) value : null; } }