Skip to content
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

Closed
nex3 opened this issue Apr 8, 2013 · 10 comments
Closed

Add a utility method to convert a StringLiteral into a Dart String #9781

nex3 opened this issue Apr 8, 2013 · 10 comments
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@nex3
Copy link
Member

nex3 commented Apr 8, 2013

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.

@clayberg
Copy link

clayberg commented Apr 9, 2013

Set owner to @bwilkerson.
Added this to the M5 milestone.
Removed Type-Defect label.
Added Type-Enhancement label.

@bwilkerson
Copy link
Member

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.

@bwilkerson
Copy link
Member

Removed Area-Editor label.
Added Area-Analyzer label.

@bwilkerson
Copy link
Member

Removed this from the M5 milestone.
Added this to the M6 milestone.

@bwilkerson
Copy link
Member

Removed this from the M6 milestone.
Added this to the M7 milestone.

@jwren
Copy link
Member

jwren commented Sep 19, 2013

M7 -> M8


Removed this from the M7 milestone.
Added this to the M8 milestone.

@bwilkerson
Copy link
Member

Removed this from the M8 milestone.
Added this to the Later milestone.

@kasperl
Copy link

kasperl commented Jul 10, 2014

Removed this from the Later milestone.
Added Oldschool-Milestone-Later label.

@kasperl
Copy link

kasperl commented Aug 4, 2014

Removed Oldschool-Milestone-Later label.

@nex3 nex3 added Type-Enhancement area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Aug 4, 2014
@kevmoo kevmoo added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug and removed triaged labels Feb 29, 2016
@srawlins
Copy link
Member

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

7 participants