PROPOSAL: Multiline strings
Joseph D. Darcy
Joe.Darcy at Sun.COM
Mon Mar 2 22:44:11 PST 2009
Ruslan,
This proposal is missing many important details.
rssh at gradsoft.com.ua wrote:
> AUTHOR(s): Ruslan Shevchenko
>
> OVERVIEW:
> FEATURE SUMMARY:
> add multiline strings to java language.
> MAJOR ADVANTAGE:
> Possibility more elegant to write code part of codes in other languages,
> such as sql constructions or rendering of html components.
> MAJOR DISADVANTAGE
> I don't know
> ALTERNATIVES:
> use String "+=" operator.
> using groovy instead java in utility classes.
>
"This is \n" +
"an alternative \n" +
"too.\n"
As is
concat("If you save on \"\\n\",
"you might still pay ",
"with a comma.");
public static concat(String... args) {
// concat args together separated by newlines
}
> EXAMPLES
>
> SIMPLE EXAMPLE:
>
> StringBuilder sb = new StringBuilder();
> sb.append("""select a from Area a, CountryCodes cc
> where
> cc.isoCode='UA'
> and
> a.owner = cc.country
> """);
> if (question.getAreaName()!=null) {
> sb.append("""and
> a.name like ?
> """);
> sqlParams.setString(++i,question.getAreaName());
> }
>
> instead:
> StringBuilder sb = new StringBuilder();
> sb.append("select a from Area a, CountryCodes cc\n");
> sb.append("where cc.isoCode='UA'\n");
> sb.append("and a.owner=cc.country'\n");
> if (question.getAreaName()!=null) {
> sb.append("and a.name like ?");
> sqlParams.setString(++i,question.getAreaName());
> }
>
>
> DETAILS:
> Multiline strings are part of program text, which begin and ends
> by three double quotes. (as in groovy and scala) Text withing such
> brackets processed as multiline string with all rulles as normal Java
> string literals, except it can be multiline. After parsing multiline
> string is concatenation of lines with inserted value of system property
> 'line.separator' between thems.
>
What are the grammar changes?
Is are three consecutive quote characters escaped in a multi-line string?
As has been mentioned in earlier responses, how is whitespace handed?
> COMPILATION:
> Multiline strings created and used in .class files exactly as ordinary
> strings.
>
What is the desugaring?
Regards,
-Joe
> TESTING:
> Nothing special. add multiline strings to test-cases.
>
> LIBRARY SUPPORT:
> None.
> (May be exists sence add simple template processing to standard library, but
> I think this is goal of next janguage iteration. Now exists many good
> external
> frameworks, such as velocity: better wait and standartize support of
> winner)
>
> REFLECTIVE APIS: None
>
> OTHER CHANGES: None
>
> MIGRATION: None
>
> COMPABILITY
> None
>
> REFERENCES
>
> http://bugs.sun.com/view_bug.do?bug_id=4165111
>
>
>
>
>
>
>
>
More information about the coin-dev
mailing list