New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a utility method to convert a StringLiteral into a Dart String #9781
Comments
Set owner to @bwilkerson. |
Unfortunately, the class StringLiteral is an abstract class for all string literals, including literal strings with interpolation. Not all interpolated strings can be computed at compile time, so we couldn't always convert every string literal to a Dart string. However, the subclass SimpleStringLiteral, which represents a string literal that does not use interpolation, already has a method ('getValue()' in Java, probably translated into a getter named 'value' in the Dart version) that will do what you want. In addition, there is a class named ConstantEvaluator that will do partial evaluation of constant expressions. There is an internal class that does full evaluation of constant expressions given a fully resolved AST, but I haven't had time yet to provide a decent public API to it. So, we have, or will have, support for converting some string literals to native strings, just not as a method on StringLiteral. I'll leave this issue open as a reminder to add the public API for computing the values of compile time constant expressions. Let me know if that won't meet your needs. |
Removed Area-Editor label. |
Removed this from the Later milestone. |
Removed Oldschool-Milestone-Later label. |
https://github.com/dart-lang/sdk/blob/master/pkg/analyzer/lib/dart/ast/ast.dart#L6938..L6942 abstract class StringLiteral extends Literal {
/**
* Return the value of the string literal, or `null` if the string is not a
* constant string without any string interpolation.
*/
String get stringValue;
} Close? |
Once the Dart analyzer is being written in Dart, it would be useful to add a method on the StringLiteral class that converts it to a native Dart string.
The text was updated successfully, but these errors were encountered: