<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-4219011375701224053</id><updated>2009-07-31T15:01:09.226-07:00</updated><title type='text'>PeterReilly</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://peter-reilly.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default'/><link rel='alternate' type='text/html' href='http://peter-reilly.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>PeterReilly</name><uri>http://www.blogger.com/profile/14129679572021092943</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4219011375701224053.post-3336281566796016599</id><published>2006-12-22T14:59:00.000-08:00</published><updated>2006-12-23T11:38:52.251-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Ant.'/><title type='text'>Some features of Ant 1.7.0</title><content type='html'>Ant 1.7.0  has just been released. It includes a long&lt;br /&gt;list of fixes and it includes a new resource framework.&lt;br /&gt;&lt;br /&gt;Some of the new features that have not got highlighed&lt;br /&gt;are:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;Support for junit.jar in the &amp;lt;junit&gt; classpath element, this means that there is now &lt;span style="font-weight: bold;"&gt;no&lt;/span&gt; need to place the junit.jar in $ANT_HOME/lib.&lt;/li&gt;&lt;li&gt;Support for junit4.&lt;/li&gt;&lt;li&gt;Support for javax scripting. This is done by using a 'manager="javax"' attribute in the &amp;lt;script&gt; task.&lt;/li&gt;&lt;li&gt;Scripting language jars can now be placed in the &amp;lt;script&gt; classpath element. This means that these jars do not need to be placed in $ANT_HOME/lib. (This does not work for javascript and jython jars - will be fixed in Ant 1.7.1)&lt;/li&gt;&lt;li&gt;Script support for conditions, filters, mappers, selectors added.&lt;/li&gt;&lt;li&gt;Antversion condition added - scripts can how make sure that they are run by a supported version of ant.&lt;/li&gt;&lt;li&gt;Memory leakages plugged for &lt;*ant*&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4219011375701224053-3336281566796016599?l=peter-reilly.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://peter-reilly.blogspot.com/feeds/3336281566796016599/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4219011375701224053&amp;postID=3336281566796016599' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/3336281566796016599'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/3336281566796016599'/><link rel='alternate' type='text/html' href='http://peter-reilly.blogspot.com/2006/12/some-features-of-ant-170.html' title='Some features of Ant 1.7.0'/><author><name>PeterReilly</name><uri>http://www.blogger.com/profile/14129679572021092943</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07377012234385747784'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4219011375701224053.post-8602004855377359179</id><published>2006-11-28T08:01:00.000-08:00</published><updated>2006-11-28T08:18:49.657-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><category scheme='http://www.blogger.com/atom/ns#' term='Ant.'/><title type='text'>Javax scripting for ant 1.7.0</title><content type='html'>It looks like I am be able to persuade my ant&lt;br /&gt;collegues to have javax.scripting in ant 1.7.0.&lt;br /&gt;&lt;br /&gt;There are two options to specify javax.scripting&lt;br /&gt;rather than bsf, have an extra attribute on the script&lt;br /&gt;task:&lt;br /&gt;&lt;pre&gt;&amp;lt;script language="javascript" engine="jsr"&gt;&lt;br /&gt; print("hello world\n");&lt;br /&gt;&amp;lt;/script&gt;&lt;br /&gt;&lt;/pre&gt;or use a prefix in the language tag:&lt;br /&gt;&lt;pre&gt;&amp;lt;script language="jsr:javascript"&gt;&lt;br /&gt; print("hello world\n");&lt;br /&gt;&amp;lt;/script&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The nice thing is that with this, one can use&lt;br /&gt;javascript scripting in ant with java6 &lt;span style="color: rgb(255, 0, 0);"&gt;*without* &lt;/span&gt;any configuration.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4219011375701224053-8602004855377359179?l=peter-reilly.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://peter-reilly.blogspot.com/feeds/8602004855377359179/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4219011375701224053&amp;postID=8602004855377359179' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/8602004855377359179'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/8602004855377359179'/><link rel='alternate' type='text/html' href='http://peter-reilly.blogspot.com/2006/11/javax-scripting-for-ant-170.html' title='Javax scripting for ant 1.7.0'/><author><name>PeterReilly</name><uri>http://www.blogger.com/profile/14129679572021092943</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07377012234385747784'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4219011375701224053.post-682541328267520592</id><published>2006-11-27T14:45:00.000-08:00</published><updated>2006-11-27T14:46:37.365-08:00</updated><title type='text'>Multiline strings in java - more python like</title><content type='html'>I have modified the python string patch so that the patch&lt;br /&gt;behaves more like python.&lt;br /&gt;r" is now a raw string &lt;br /&gt;ur" is now a string that denotes a raw string with unicode&lt;br /&gt;escape handing.&lt;br /&gt;&lt;br /&gt;On a side note, I see that F3 has a JSR222 implemenation,&lt;br /&gt;http://blogs.sun.com/chrisoliver/entry/f3_and_jsr-223&lt;br /&gt;the example given is:&lt;br /&gt;    String script = &lt;br /&gt;        "import java.util.Date;" +&lt;br /&gt;        "import java.lang.System;" +&lt;br /&gt;        " " +&lt;br /&gt;        "System.out.println(now:Date);";      &lt;br /&gt;    engine.eval(script);&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;This could be written a little nicer like (this adds in new lines):&lt;br /&gt;    String script = """&lt;br /&gt;        import java.util.Date;&lt;br /&gt;        import java.lang.System;&lt;br /&gt;&lt;br /&gt;        System.out.println(now:Date);&lt;br /&gt;    """;&lt;br /&gt;    engine.eval(script);&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4219011375701224053-682541328267520592?l=peter-reilly.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://peter-reilly.blogspot.com/feeds/682541328267520592/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4219011375701224053&amp;postID=682541328267520592' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/682541328267520592'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/682541328267520592'/><link rel='alternate' type='text/html' href='http://peter-reilly.blogspot.com/2006/11/multiline-strings-in-java-more-python.html' title='Multiline strings in java - more python like'/><author><name>PeterReilly</name><uri>http://www.blogger.com/profile/14129679572021092943</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07377012234385747784'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4219011375701224053.post-4531093578876051503</id><published>2006-11-26T14:29:00.000-08:00</published><updated>2006-11-26T14:31:11.469-08:00</updated><title type='text'>Multiline strings in java - Part 2</title><content type='html'>After a little more messing around with Scanner.java in the&lt;br /&gt;compiler source code, I now have the string handling similar to&lt;br /&gt;pythons.  """ denotes a multiline string, the code normalizes&lt;br /&gt;end of line characters (CRNL -&gt; NL) (CR -&gt; NL) (a bit like XML&lt;br /&gt;handling), and raw strings are added. r" or r""" denotes a raw string&lt;br /&gt;with unicode escape handling (equilvant to pythons ur", ur""")&lt;br /&gt;and R" or R""" denotes a raw string without unicode handling.&lt;br /&gt;&lt;br /&gt;Raw strings are usefull for regular expressions and&lt;br /&gt;for evalulating script strings.&lt;br /&gt;&lt;br /&gt;The grammar is something like: (copied in part from python grammar)&lt;br /&gt;&lt;br /&gt;stringliteral   ::= [stringprefix](shortstring | longstring)&lt;br /&gt;stringprefix  ::= "r" | "R"&lt;br /&gt;shortstring  ::= '"' shortstringitem* '"'&lt;br /&gt;longstring  ::= '"""' longstringitem* '"""'&lt;br /&gt;shortstringitem ::= shortstringchar | escapeseq&lt;br /&gt;longstringitem  ::= longstringchar | escapeseq&lt;br /&gt;shortstringchar ::= &lt;any source character except "\" or newline or '"'&gt;&lt;br /&gt;longstringchar  ::= &lt;any source character except "\"&gt;&lt;br /&gt;escapeseq  ::= "\" &lt;any ASCII character&gt;&lt;br /&gt;&lt;br /&gt;So the following now compiles and runs:&lt;br /&gt;&lt;br /&gt;import javax.script.*;&lt;br /&gt;&lt;br /&gt;public class ScriptExample {&lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        ScriptEngineManager m = new ScriptEngineManager();&lt;br /&gt;        ScriptEngine engine = m.getEngineByName("javascript");&lt;br /&gt;        engine.eval(r"""&lt;br /&gt;          print("This is the world ");&lt;br /&gt;          print("calling\n");&lt;br /&gt;        """);&lt;br /&gt;        String x = R"\u";&lt;br /&gt;        System.out.println("No escape " + x);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/f/src/compiler &gt; java -jar dist/lib/javac.jar ScriptExample.java&lt;br /&gt;/f/src/compiler &gt; java -cp . ScriptExample&lt;br /&gt;This is the world calling&lt;br /&gt;No escape \u&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;The code is *NOT* fully tested .... but&lt;br /&gt;here is the diff file (-Nua) for Scanner.java to Scanner.java.orig&lt;br /&gt;&lt;br /&gt;--- Scanner.java.orig Sun Nov 26 12:57:25 2006&lt;br /&gt;+++ Scanner.java Sun Nov 26 21:49:59 2006&lt;br /&gt;@@ -52,6 +52,13 @@&lt;br /&gt; @Version("@(#)Scanner.java 1.73 06/11/11")&lt;br /&gt; public class Scanner implements Lexer {&lt;br /&gt; &lt;br /&gt;+    /** Enumerated type on how to handle decoding \ in string */&lt;br /&gt;+    private enum EscapeHandling {&lt;br /&gt;+        FULL,    // decode all \&lt;br /&gt;+        UNICODE, // only decode unicode escape&lt;br /&gt;+        RAW,     // completely raw&lt;br /&gt;+    }&lt;br /&gt;+&lt;br /&gt;     private static boolean scannerDebug = false;&lt;br /&gt; &lt;br /&gt;     /** A factory for creating scanners. */&lt;br /&gt;@@ -291,6 +298,101 @@&lt;br /&gt;      convertUnicode();&lt;br /&gt;  }&lt;br /&gt;     }&lt;br /&gt;+    /** Read next character.&lt;br /&gt;+     * @param escapeHandling how to handle \ in strings&lt;br /&gt;+     */&lt;br /&gt;+    private void scanChar(EscapeHandling escapeHandling) {&lt;br /&gt;+        ch = buf[++bp];&lt;br /&gt;+        if (escapeHandling != EscapeHandling.RAW &amp;&amp; ch == '\\') {&lt;br /&gt;+            convertUnicode();&lt;br /&gt;+        }&lt;br /&gt;+    }&lt;br /&gt;+&lt;br /&gt;+    /**&lt;br /&gt;+     * Look ahead for a character.&lt;br /&gt;+     * @param count the number to look ahead by.&lt;br /&gt;+     * @return the character of the future... or (char) 0 for&lt;br /&gt;+     *         characters beyond the buffer.&lt;br /&gt;+     */&lt;br /&gt;+    private char peekAhead(int count) {&lt;br /&gt;+        if (count + bp &gt;= buflen) {&lt;br /&gt;+            return (char) 0;&lt;br /&gt;+        }&lt;br /&gt;+        return buf[count + bp];&lt;br /&gt;+    }&lt;br /&gt;+&lt;br /&gt;+    /** Check if we are at a triple double quote.&lt;br /&gt;+     * @return true if the next two characters are quotes.&lt;br /&gt;+     */&lt;br /&gt;+    private boolean atTripleQuote() {&lt;br /&gt;+        return peekAhead(1) == '"' &amp;&amp; peekAhead(2) == '"';&lt;br /&gt;+    }&lt;br /&gt;+&lt;br /&gt;+    /** Scan a triple quoted string.&lt;br /&gt;+     * @param escapeHandling how to handle \ in strings&lt;br /&gt;+     */&lt;br /&gt;+    private void scanTripleQuotedString(EscapeHandling escapeHandling) {&lt;br /&gt;+        // read in the """ characters&lt;br /&gt;+        scanChar();&lt;br /&gt;+        scanChar();&lt;br /&gt;+        scanChar(escapeHandling);&lt;br /&gt;+        while (true) {&lt;br /&gt;+            while (ch != '"' &amp;&amp; ch != CR &amp;&amp; bp &amp;lt; buflen) {&lt;br /&gt;+                scanLitChar(escapeHandling);&lt;br /&gt;+            }&lt;br /&gt;+            if (bp &gt;= buflen) {&lt;br /&gt;+                lexError(pos, "unclosed.str.lit");&lt;br /&gt;+                return;&lt;br /&gt;+            }&lt;br /&gt;+            if (ch == CR) {&lt;br /&gt;+                if (peekAhead(1) == LF) {&lt;br /&gt;+                    scanChar();&lt;br /&gt;+                    continue; // Normalize CRLF to LF&lt;br /&gt;+                }&lt;br /&gt;+                ch = LF; // Normalize CR to LF&lt;br /&gt;+                continue;&lt;br /&gt;+            }&lt;br /&gt;+            // Character is a ", is the the triple?&lt;br /&gt;+            if (atTripleQuote()) {&lt;br /&gt;+                // yes - end of the string&lt;br /&gt;+                scanChar();&lt;br /&gt;+                scanChar();&lt;br /&gt;+                scanChar();&lt;br /&gt;+                token = STRINGLITERAL;&lt;br /&gt;+                return;&lt;br /&gt;+            } else {&lt;br /&gt;+                // no - add it to the string.&lt;br /&gt;+                scanLitChar(escapeHandling);&lt;br /&gt;+            }&lt;br /&gt;+        }&lt;br /&gt;+    }&lt;br /&gt;+&lt;br /&gt;+    /** Scan a quoted string.&lt;br /&gt;+     * @param escapeHandling how to handle \ in strings&lt;br /&gt;+     */&lt;br /&gt;+    private void scanQuotedString(EscapeHandling escapeHandling) {&lt;br /&gt;+        scanChar(escapeHandling);&lt;br /&gt;+        while (ch != '"' &amp;&amp; ch != CR &amp;&amp; ch != LF &amp;&amp; bp &amp;lt; buflen) {&lt;br /&gt;+            scanLitChar(escapeHandling);&lt;br /&gt;+        }&lt;br /&gt;+        if (ch == '"') {&lt;br /&gt;+            token = STRINGLITERAL;&lt;br /&gt;+            scanChar();&lt;br /&gt;+        } else {&lt;br /&gt;+            lexError(pos, "unclosed.str.lit");&lt;br /&gt;+        }&lt;br /&gt;+    }&lt;br /&gt;+&lt;br /&gt;+    /** Scan a string.&lt;br /&gt;+     * @param escapeHandling how to handle \ in strings&lt;br /&gt;+     */&lt;br /&gt;+    private void scanString(EscapeHandling escapeHandling) {&lt;br /&gt;+        if (atTripleQuote()) {&lt;br /&gt;+            scanTripleQuotedString(escapeHandling);&lt;br /&gt;+        } else {&lt;br /&gt;+            scanQuotedString(escapeHandling);&lt;br /&gt;+        }&lt;br /&gt;+    }&lt;br /&gt; &lt;br /&gt;     /** Read next character in comment, skipping over double '\' characters.&lt;br /&gt;      */&lt;br /&gt;@@ -323,9 +425,10 @@&lt;br /&gt;     }&lt;br /&gt; &lt;br /&gt;     /** Read next character in character or string literal and copy into sbuf.&lt;br /&gt;+     * @param escapeHandling how to handle \ in strings&lt;br /&gt;      */&lt;br /&gt;-    private void scanLitChar() {&lt;br /&gt;-        if (ch == '\\') {&lt;br /&gt;+    private void scanLitChar(EscapeHandling escapeHandling) {&lt;br /&gt;+        if (escapeHandling == EscapeHandling.FULL &amp;&amp; ch == '\\') {&lt;br /&gt;      if (buf[bp+1] == '\\' &amp;&amp; unicodeConversionBp != bp) {&lt;br /&gt;   bp++;&lt;br /&gt;   putChar('\\');&lt;br /&gt;@@ -369,7 +472,8 @@&lt;br /&gt;   }&lt;br /&gt;      }&lt;br /&gt;  } else if (bp != buflen) {&lt;br /&gt;-            putChar(ch); scanChar();&lt;br /&gt;+            putChar(ch);&lt;br /&gt;+            scanChar(escapeHandling);&lt;br /&gt;         }&lt;br /&gt;     }&lt;br /&gt; &lt;br /&gt;@@ -779,16 +883,30 @@&lt;br /&gt;       endPos = bp;&lt;br /&gt;       processLineTerminator();&lt;br /&gt;       break;&lt;br /&gt;+                case 'r':&lt;br /&gt;+                    if ('"' == peekAhead(1)) {&lt;br /&gt;+                        scanChar();&lt;br /&gt;+                        scanString(EscapeHandling.UNICODE);&lt;br /&gt;+                        return;&lt;br /&gt;+                    }&lt;br /&gt;+                    // Fall Tru&lt;br /&gt;+                case 'R':&lt;br /&gt;+                    if ('"' == peekAhead(1)) {&lt;br /&gt;+                        scanChar();&lt;br /&gt;+                        scanString(EscapeHandling.RAW);&lt;br /&gt;+                        return;&lt;br /&gt;+                    }&lt;br /&gt;+                    // FALL TRU&lt;br /&gt;   case 'A': case 'B': case 'C': case 'D': case 'E':&lt;br /&gt;   case 'F': case 'G': case 'H': case 'I': case 'J':&lt;br /&gt;   case 'K': case 'L': case 'M': case 'N': case 'O':&lt;br /&gt;-  case 'P': case 'Q': case 'R': case 'S': case 'T':&lt;br /&gt;+  case 'P': case 'Q':           case 'S': case 'T':&lt;br /&gt;   case 'U': case 'V': case 'W': case 'X': case 'Y':&lt;br /&gt;   case 'Z':&lt;br /&gt;   case 'a': case 'b': case 'c': case 'd': case 'e':&lt;br /&gt;   case 'f': case 'g': case 'h': case 'i': case 'j':&lt;br /&gt;   case 'k': case 'l': case 'm': case 'n': case 'o':&lt;br /&gt;-  case 'p': case 'q': case 'r': case 's': case 't':&lt;br /&gt;+  case 'p': case 'q':           case 's': case 't':&lt;br /&gt;   case 'u': case 'v': case 'w': case 'x': case 'y':&lt;br /&gt;   case 'z':&lt;br /&gt;   case '$': case '_':&lt;br /&gt;@@ -902,7 +1020,7 @@&lt;br /&gt;       } else {&lt;br /&gt;    if (ch == CR || ch == LF)&lt;br /&gt;        lexError(pos, "illegal.line.end.in.char.lit");&lt;br /&gt;-   scanLitChar();&lt;br /&gt;+   scanLitChar(EscapeHandling.FULL);&lt;br /&gt;    if (ch == '\'') {&lt;br /&gt;        scanChar();&lt;br /&gt;        token = CHARLITERAL;&lt;br /&gt;@@ -911,17 +1029,9 @@&lt;br /&gt;    }&lt;br /&gt;       }&lt;br /&gt;       return;&lt;br /&gt;-  case '\"':&lt;br /&gt;-      scanChar();&lt;br /&gt;-      while (ch != '\"' &amp;&amp; ch != CR &amp;&amp; ch != LF &amp;&amp; bp &amp;lt; buflen)&lt;br /&gt;-   scanLitChar();&lt;br /&gt;-      if (ch == '\"') {&lt;br /&gt;-   token = STRINGLITERAL;&lt;br /&gt;-   scanChar();&lt;br /&gt;-      } else {&lt;br /&gt;-   lexError(pos, "unclosed.str.lit");&lt;br /&gt;-      }&lt;br /&gt;-      return;&lt;br /&gt;+  case '"':&lt;br /&gt;+                    scanString(EscapeHandling.FULL);&lt;br /&gt;+                    return;&lt;br /&gt;   default:&lt;br /&gt;       if (isSpecial(ch)) {&lt;br /&gt;    scanOperator();&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4219011375701224053-4531093578876051503?l=peter-reilly.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://peter-reilly.blogspot.com/feeds/4531093578876051503/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4219011375701224053&amp;postID=4531093578876051503' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/4531093578876051503'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/4531093578876051503'/><link rel='alternate' type='text/html' href='http://peter-reilly.blogspot.com/2006/11/multiline-strings-in-java-part-2.html' title='Multiline strings in java - Part 2'/><author><name>PeterReilly</name><uri>http://www.blogger.com/profile/14129679572021092943</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07377012234385747784'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4219011375701224053.post-3914479455426859335</id><published>2006-11-25T13:27:00.000-08:00</published><updated>2006-11-25T14:09:21.211-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Java'/><title type='text'>Multiline strings in java - solved (sort of)</title><content type='html'>There has been an long outstanding request for&lt;br /&gt;multiline stings in java. See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4472509&lt;br /&gt;and http://www.mrchucho.net/index.php/archives/2005/06/01/multi-line-strings-in-java/&lt;br /&gt;&lt;br /&gt;With all the new 1.5 stuff being added - annotations, printf, varargs&lt;br /&gt;it is quite annoying that java still has to do&lt;br /&gt;"aaa\n"&lt;br /&gt;+ "bbb\n"&lt;br /&gt;...&lt;br /&gt;for multiline strings.&lt;br /&gt;There is especially annoying when - writing unit tests  (xml strings for example)&lt;br /&gt;and for doc and SQL annotations.&lt;br /&gt;With JSR Scripting being added in jdk6, it has become completely stupid,&lt;br /&gt;It would be nice to something like the pythonic -&lt;br /&gt;&lt;br /&gt;engine = manager.getEngineByName("beanshell");&lt;br /&gt;engine.eval("""&lt;br /&gt;  map = new HashMap(); &lt;br /&gt;  map.put("foo", "bar"); &lt;br /&gt;&lt;br /&gt;  importObject( map ); &lt;br /&gt;&lt;br /&gt;  print( get("foo") ); // bar &lt;br /&gt;""");&lt;br /&gt;&lt;br /&gt;With the GPL release of javac, one can have a look at the&lt;br /&gt;javac code - and see what needs to be done to add this much&lt;br /&gt;needed extension.&lt;br /&gt;&lt;br /&gt;A quick look at the code shows that it should be relatively easy&lt;br /&gt;to add this - but I do not have the time at the moment&lt;br /&gt;to add """.&lt;br /&gt;&lt;br /&gt;However, one can add multiline strings easily&lt;br /&gt;by relaxing the check for NL and CR.&lt;br /&gt;&lt;br /&gt;$COMPILER_HOME/src/share/classes/com/sun/tools/javac/parser/Scanner.java&lt;br /&gt;Line: 916 Change to&lt;br /&gt;    while (ch != '\"' /*&amp;&amp; ch != CR &amp;&amp; ch != LF*/ &amp;&amp; bp &amp;lt; buflen)&lt;br /&gt;&lt;br /&gt;and presto the following compiles:&lt;br /&gt;&lt;br /&gt;public class HelloWorld {&lt;br /&gt;    public static void main(String[] args) {&lt;br /&gt;        System.out.println("&lt;br /&gt;    Hello world&lt;br /&gt;");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/f/src/compiler &gt; java -jar dist/lib/javac.jar HelloWorld.java&lt;br /&gt;/f/src/compiler &gt; java -cp . HelloWorld&lt;br /&gt;&lt;br /&gt;    Hello world&lt;br /&gt;&lt;br /&gt;/f/src/compiler &gt; &lt;br /&gt;&lt;br /&gt;The script example is a little ropy as one needs to escape&lt;br /&gt;the " and \.&lt;br /&gt;&lt;br /&gt;import javax.script.*;&lt;br /&gt;&lt;br /&gt;public class ScriptExample {&lt;br /&gt;    public static void main(String[] args) throws Exception {&lt;br /&gt;        ScriptEngineManager m = new ScriptEngineManager();&lt;br /&gt;        ScriptEngine engine = m.getEngineByName("javascript");&lt;br /&gt;        engine.eval("&lt;br /&gt;  print(\"This is the world \");&lt;br /&gt;  print(\"calling\\n\");&lt;br /&gt;");&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;/f/src/compiler &gt; java -jar dist/lib/javac.jar ScriptExample.java&lt;br /&gt;/f/src/compiler &gt; java -cp . ScriptExample&lt;br /&gt;This is the world calling&lt;br /&gt;/f/src/compiler &gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4219011375701224053-3914479455426859335?l=peter-reilly.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://peter-reilly.blogspot.com/feeds/3914479455426859335/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4219011375701224053&amp;postID=3914479455426859335' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/3914479455426859335'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/3914479455426859335'/><link rel='alternate' type='text/html' href='http://peter-reilly.blogspot.com/2006/11/multiline-strings-in-java-solved-sort.html' title='Multiline strings in java - solved (sort of)'/><author><name>PeterReilly</name><uri>http://www.blogger.com/profile/14129679572021092943</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07377012234385747784'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-4219011375701224053.post-2756214073694816638</id><published>2006-08-15T07:09:00.001-07:00</published><updated>2006-08-15T07:09:25.947-07:00</updated><title type='text'></title><content type='html'>Some xml:&lt;br /&gt;&lt;br /&gt;&amp;lt;abc&amp;gt;&lt;br /&gt;&amp;lt;/abc&amp;gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4219011375701224053-2756214073694816638?l=peter-reilly.blogspot.com'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://peter-reilly.blogspot.com/feeds/2756214073694816638/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=4219011375701224053&amp;postID=2756214073694816638' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/2756214073694816638'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4219011375701224053/posts/default/2756214073694816638'/><link rel='alternate' type='text/html' href='http://peter-reilly.blogspot.com/2006/08/some-xml.html' title=''/><author><name>PeterReilly</name><uri>http://www.blogger.com/profile/14129679572021092943</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='07377012234385747784'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>