<html>
<head>
<style><!--
  body {background-color:#ffffff;}
  .file {border:1px solid #eeeeee;margin-top:1em;margin-bottom:1em;}
  .pathname {font-family:monospace; float:right;}
  .fileheader {margin-bottom:.5em;}
  .diff {margin:0;}
  .tasklist {padding:4px;border:1px dashed #000000;margin-top:1em;}
  .tasklist ul {margin-top:0;margin-bottom:0;}
  tr.alt {background-color:#eeeeee}
  #added {background-color:#ddffdd;}
  #addedchars {background-color:#99ff99;font-weight:bolder;}
  tr.alt #added {background-color:#ccf7cc;}
  #removed {background-color:#ffdddd;}
  #removedchars {background-color:#ff9999;font-weight:bolder;}
  tr.alt #removed {background-color:#f7cccc;}
  #copied {background-color:#ccccff;}
  tr.alt #copied {background-color:#bbbbf7;}
  #info {color:#888888;}
  #context {background-color:#eeeeee;}
  td {padding-left:.3em;padding-right:.3em;}
  tr.head {border-bottom-width:1px;border-bottom-style:solid;}
  tr.head td {padding:0;padding-top:.2em;}
  .task {background-color:#ffff00;}
  .comment {white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;white-space:pre-wrap;word-wrap:break-word;padding:4px;border:1px dashed #000000;background-color:#ffffdd}
  .error {color:red;}
  hr {border-width:0px;height:2px;background:black;}
--></style>
</head>
<body>
<table cellspacing="0" cellpadding="0" border="0" rules="cols">
<tr class="head"><td colspan="5">Commit in <b><tt>metaas/trunk/src</tt></b></td></tr>
<tr><td><tt>main/java/uk/co/badgersinfoil/metaas/<a href="#file1">ActionScriptFactory.java</a></tt> </td><td></td><td align="right" id="added">+5</td><td></td><td nowrap="nowrap" align="center">696 -&gt; 697</td></tr>
<tr class="alt"><td><tt>main/java/uk/co/badgersinfoil/metaas/impl/<a href="#file2">ASTBuilder.java</a></tt> </td><td></td><td align="right" id="added">+54</td><td></td><td nowrap="nowrap" align="center">696 -&gt; 697</td></tr>
<tr><td><tt>test/java/uk/co/badgersinfoil/metaas/impl/<a href="#file3"><span id="added">ASTBuilderTest.java</span></a></tt> </td><td></td><td align="right" id="added">+17</td><td></td><td nowrap="nowrap" align="right">added 697</td></tr>
<tr><td></td><td></td><td align="right" id="added">+76</td><td></td><td></td></tr>
</table>
<small id="info">1 added + 2 modified, total 3 files</small><br />
<pre class="comment">
Support for entirely duplicating an expression (inc. the underlying token substream).

This is required if we ever want to copy an expression from one part of the
AST to another without breaking things (i.e. parent/child relationships).

Might generalise this to work for all ScriptElements in future.
</pre>
<hr /><a name="file1" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas</span><br />
<div class="fileheader"><big><b>ActionScriptFactory.java</b></big> <small id="info">696 -&gt; 697</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/ActionScriptFactory.java        2008-03-25 23:02:23 UTC (rev 696)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/ActionScriptFactory.java        2008-03-25 23:16:54 UTC (rev 697)
@@ -535,6 +535,11 @@
</small></pre><pre class="diff" id="context">                 return result.toString();
         }
 
</pre><pre class="diff" id="added">+        public Expression dup(Expression expr) {
+                LinkedListTree ast = ASTUtils.ast(expr);
+                return ExpressionBuilder.build(ASTBuilder.dup(ast));
+        }
+
</pre><pre class="diff" id="context">         public ASDescendantExpression newDescendantExpression(Expression target,
                                                               Expression selector)
         {
</pre></div>
<hr /><a name="file2" /><div class="file">
<span class="pathname">metaas/trunk/src/main/java/uk/co/badgersinfoil/metaas/impl</span><br />
<div class="fileheader"><big><b>ASTBuilder.java</b></big> <small id="info">696 -&gt; 697</small></div>
<pre class="diff"><small id="info">--- trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ASTBuilder.java        2008-03-25 23:02:23 UTC (rev 696)
+++ trunk/src/main/java/uk/co/badgersinfoil/metaas/impl/ASTBuilder.java        2008-03-25 23:16:54 UTC (rev 697)
@@ -18,7 +18,9 @@
</small></pre><pre class="diff" id="context"> 
 package uk.co.badgersinfoil.metaas.impl;
 
</pre><pre class="diff" id="added">+import java.util.HashMap;
</pre><pre class="diff" id="context"> import java.util.List;
</pre><pre class="diff" id="added">+import java.util.Map;
</pre><pre class="diff" id="context"> import org.asdt.core.internal.antlr.AS3Parser;
 import uk.co.badgersinfoil.metaas.ActionScriptFactory;
 import uk.co.badgersinfoil.metaas.SyntaxException;
</pre><pre class="diff"><small id="info">@@ -29,6 +31,7 @@
</small></pre><pre class="diff" id="context"> import uk.co.badgersinfoil.metaas.dom.Visibility;
 import uk.co.badgersinfoil.metaas.impl.antlr.LinkedListToken;
 import uk.co.badgersinfoil.metaas.impl.antlr.LinkedListTree;
</pre><pre class="diff" id="added">+import uk.co.badgersinfoil.metaas.impl.antlr.PlaceholderLinkedListToken;
</pre><pre class="diff" id="context"> 
 
 /**
</pre><pre class="diff"><small id="info">@@ -640,6 +643,57 @@
</small></pre><pre class="diff" id="context">                 return thrw;
         }
 
</pre><pre class="diff" id="added">+        public static LinkedListTree dup(LinkedListTree ast) {
+                Map tokens = dupTokStream(ast);
+                return dupTree(ast, tokens);
+        }
+
+        private static LinkedListTree dupTree(LinkedListTree ast, Map tokens) {
+                LinkedListToken newTok = (LinkedListToken)tokens.get(ast.getToken());
+                LinkedListTree result = new LinkedListTree(newTok);
+                result.setStartToken((LinkedListToken)tokens.get(ast.getStartToken()));
+                result.setStopToken((LinkedListToken)tokens.get(ast.getStopToken()));
+                result.setTokenListUpdater(ast.getTokenListUpdater());
+                result.setInitialInsertionAfter(ast.getInitialInsertionAfter());
+                result.setInitialInsertionBefore(ast.getInitialInsertionBefore());
+                for (ASTIterator i=new ASTIterator(ast); i.hasNext(); ) {
+                        LinkedListTree newChild = dupTree(i.next(), tokens);
+                        result.addChild(newChild);
+                }
+                return result;
+        }
+
+        private static Map dupTokStream(LinkedListTree ast) {
+                Map tokens = new HashMap();
+                LinkedListToken last = null;
+                for (LinkedListToken tok=ast.getStartToken(); tok!=null&amp;&amp;tok.getType()!=-1; tok=tok.getNext()) {
+                        LinkedListToken newTok = dupTok(tok);
+                        tokens.put(tok, newTok);
+                        if (last != null) {
+                                last.setNext(newTok);
+                        }
+                        if (tok == ast.getStopToken()) {
+                                break;
+                        }
+                        last = newTok;
+                }
+                return tokens;
+        }
+
+        private static LinkedListToken dupTok(LinkedListToken tok) {
+                LinkedListToken result;
+                if (tok instanceof PlaceholderLinkedListToken) {
+                        result = new PlaceholderLinkedListToken(((PlaceholderLinkedListToken)tok).getHeld());
+                } else {
+                        result = new LinkedListToken(tok.getType(),
+                                                     tok.getText());
+                }
+                result.setChannel(tok.getChannel());
+                result.setCharPositionInLine(tok.getCharPositionInLine());
+                result.setLine(tok.getLine());
+                return result;
+        }
+
</pre><pre class="diff" id="context">         public static LinkedListTree newDescendantExpression(LinkedListTree target,
                                                              LinkedListTree selector)
         {
</pre></div>
<hr /><a name="file3" /><div class="file">
<span class="pathname" id="added">metaas/trunk/src/test/java/uk/co/badgersinfoil/metaas/impl</span><br />
<div class="fileheader" id="added"><big><b>ASTBuilderTest.java</b></big> <small id="info">added at 697</small></div>
<pre class="diff"><small id="info">--- trunk/src/test/java/uk/co/badgersinfoil/metaas/impl/ASTBuilderTest.java                                (rev 0)
+++ trunk/src/test/java/uk/co/badgersinfoil/metaas/impl/ASTBuilderTest.java        2008-03-25 23:16:54 UTC (rev 697)
@@ -0,0 +1,17 @@
</small></pre><pre class="diff" id="added">+package uk.co.badgersinfoil.metaas.impl;
+
+import org.asdt.core.internal.antlr.AS3Parser;
+import uk.co.badgersinfoil.metaas.CodeMirror;
+import uk.co.badgersinfoil.metaas.impl.antlr.LinkedListTree;
+import junit.framework.TestCase;
+
+public class ASTBuilderTest extends TestCase {
+
+        public void testDup() {
+                LinkedListTree src = AS3FragmentParser.parseExpr("1 + 1");
+                LinkedListTree dst = ASTBuilder.dup(src);
+                assertEquals(AS3Parser.DECIMAL_LITERAL, dst.getStartToken().getType());
+                assertEquals(AS3Parser.WS, dst.getStartToken().getNext().getType());
+                CodeMirror.assertASTMatch(src, dst);
+        }
+}
</pre></div>
<center><small><a href="http://www.badgers-in-foil.co.uk/projects/cvsspam/" title="commit -&gt; email">CVSspam</a> 0.2.12</small></center>
</body></html>