diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/ChameleonJsExpression.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/ChameleonJsExpression.java
index c6494317329..0b2ec0adba7 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/ChameleonJsExpression.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/ChameleonJsExpression.java
@@ -1,4 +1,7 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.NotNull;
@@ -56,4 +59,10 @@ public class ChameleonJsExpression implements JsExpression {
public void traverse(JsVisitorWithContext visitor, JsContext ctx) {
expression.traverse(visitor, ctx);
}
+
+ @NotNull
+ @Override
+ public ChameleonJsExpression deepCopy() {
+ return new ChameleonJsExpression(AstUtil.deepCopy(expression));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java
index 95bd6afc081..b3585dc038b 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayAccess.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents a javascript expression for array access.
*/
@@ -55,4 +58,13 @@ public final class JsArrayAccess extends JsExpressionImpl {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsArrayAccess deepCopy() {
+ JsExpression arrayCopy = AstUtil.deepCopy(arrayExpression);
+ JsExpression indexCopy = AstUtil.deepCopy(indexExpression);
+
+ return new JsArrayAccess(arrayCopy, indexCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java
index e6f2a2612ca..5e3e4cfaa6b 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsArrayLiteral.java
@@ -4,7 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
import com.intellij.util.SmartList;
+import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -43,4 +45,10 @@ public final class JsArrayLiteral extends JsLiteral {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsArrayLiteral deepCopy() {
+ return new JsArrayLiteral(AstUtil.deepCopy(expressions));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java
index 681100fe92c..959e6022882 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBinaryOperation.java
@@ -4,6 +4,8 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public final class JsBinaryOperation extends JsExpressionImpl {
@@ -29,6 +31,14 @@ public final class JsBinaryOperation extends JsExpressionImpl {
return arg2;
}
+ public void setArg1(JsExpression arg1) {
+ this.arg1 = arg1;
+ }
+
+ public void setArg2(JsExpression arg2) {
+ this.arg2 = arg2;
+ }
+
public JsBinaryOperator getOperator() {
return op;
}
@@ -61,4 +71,10 @@ public final class JsBinaryOperation extends JsExpressionImpl {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsExpression deepCopy() {
+ return new JsBinaryOperation(op, AstUtil.deepCopy(arg1), AstUtil.deepCopy(arg2));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBlock.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBlock.java
index 4e251ba5ba5..e5463b360b7 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBlock.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBlock.java
@@ -4,6 +4,7 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
import org.jetbrains.annotations.NotNull;
import com.intellij.util.SmartList;
@@ -63,4 +64,10 @@ public class JsBlock extends SourceInfoAwareJsNode implements JsStatement {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsBlock deepCopy() {
+ return new JsBlock(AstUtil.deepCopy(statements));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBreak.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBreak.java
index 135fb4f629d..ab311418aa8 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBreak.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsBreak.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents the JavaScript break statement.
*/
@@ -31,4 +34,10 @@ public final class JsBreak extends JsContinue {
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsBreak deepCopy() {
+ return new JsBreak(AstUtil.deepCopy(label));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCase.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCase.java
index d459e480c56..03daaec4e3a 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCase.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCase.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents the JavaScript case statement.
*/
@@ -41,4 +44,14 @@ public final class JsCase extends JsSwitchMember {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsCase deepCopy() {
+ JsCase caseCopy = new JsCase();
+ caseCopy.caseExpression = AstUtil.deepCopy(caseExpression);
+ caseCopy.statements.addAll(AstUtil.deepCopy(statements));
+
+ return caseCopy;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatch.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatch.java
index 7ed65734801..ba5e1bdbacc 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatch.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatch.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents a JavaScript catch clause.
*/
@@ -72,4 +75,22 @@ public class JsCatch extends SourceInfoAwareJsNode implements HasCondition {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsCatch deepCopy() {
+ JsCatchScope scopeCopy = scope.copy();
+ JsBlock bodyCopy = AstUtil.deepCopy(body);
+ JsExpression conditionCopy = AstUtil.deepCopy(condition);
+ JsParameter paramCopy = AstUtil.deepCopy(param);
+
+ return new JsCatch(scopeCopy, bodyCopy, conditionCopy, paramCopy);
+ }
+
+ private JsCatch(JsCatchScope scope, JsBlock body, JsExpression condition, JsParameter param) {
+ this.scope = scope;
+ this.body = body;
+ this.condition = condition;
+ this.param = param;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java
index af8fc20af5d..671f4dd0daf 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsCatchScope.java
@@ -30,6 +30,11 @@ public class JsCatchScope extends JsScope {
return findOwnName(name) != null;
}
+ @NotNull
+ public JsCatchScope copy() {
+ return new JsCatchScope(getParent(), name.getIdent());
+ }
+
@Override
protected JsName findOwnName(@NotNull String ident) {
return name.getIdent().equals(ident) ? name : null;
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsConditional.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsConditional.java
index 97fb3b890fb..3f412125caa 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsConditional.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsConditional.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
public final class JsConditional extends JsExpressionImpl {
private JsExpression testExpression;
private JsExpression elseExpression;
@@ -63,4 +66,14 @@ public final class JsConditional extends JsExpressionImpl {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsConditional deepCopy() {
+ JsExpression testCopy = AstUtil.deepCopy(testExpression);
+ JsExpression thenCopy = AstUtil.deepCopy(thenExpression);
+ JsExpression elseCopy = AstUtil.deepCopy(elseExpression);
+
+ return new JsConditional(testCopy, thenCopy, elseCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsContinue.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsContinue.java
index 9fd01c61fcd..32bf5ee934a 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsContinue.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsContinue.java
@@ -4,6 +4,8 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public class JsContinue extends SourceInfoAwareJsNode implements JsStatement {
@@ -44,4 +46,12 @@ public class JsContinue extends SourceInfoAwareJsNode implements JsStatement {
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsContinue deepCopy() {
+ if (label == null) return new JsContinue();
+
+ return new JsContinue(AstUtil.deepCopy(label));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java
index eeecf1e8a68..89b63ddde37 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDebugger.java
@@ -4,6 +4,8 @@
package com.google.dart.compiler.backend.js.ast;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents a JavaScript debugger statement.
*/
@@ -26,4 +28,10 @@ public class JsDebugger extends SourceInfoAwareJsNode implements JsStatement {
v.visit(this, ctx);
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsDebugger deepCopy() {
+ return this;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDefault.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDefault.java
index f9e85515556..1cf13da1d6f 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDefault.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDefault.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents the default option in a JavaScript swtich statement.
*/
@@ -20,4 +23,12 @@ public final class JsDefault extends JsSwitchMember {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsDefault deepCopy() {
+ JsDefault defaultCopy = new JsDefault();
+ defaultCopy.statements.addAll(AstUtil.deepCopy(statements));
+ return defaultCopy;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java
index 4007ea30dc0..24d31bf7bfe 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDoWhile.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents a JavaScript do..while statement.
*/
@@ -28,4 +31,13 @@ public class JsDoWhile extends JsWhile {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsDoWhile deepCopy() {
+ JsExpression conditionCopy = AstUtil.deepCopy(condition);
+ JsStatement bodyCopy = AstUtil.deepCopy(body);
+
+ return new JsDoWhile(conditionCopy, bodyCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java
index 8a9aea83762..9b895a27108 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsDocComment.java
@@ -1,5 +1,7 @@
package com.google.dart.compiler.backend.js.ast;
+import org.jetbrains.annotations.NotNull;
+
import java.util.Collections;
import java.util.Map;
@@ -30,4 +32,10 @@ public class JsDocComment extends JsExpressionImpl {
@Override
public void traverse(JsVisitorWithContext v, JsContext ctx) {
}
+
+ @NotNull
+ @Override
+ public JsDocComment deepCopy() {
+ return new JsDocComment(tags);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java
index 8d852e41049..699bc06f7d4 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmpty.java
@@ -4,6 +4,8 @@
package com.google.dart.compiler.backend.js.ast;
+import org.jetbrains.annotations.NotNull;
+
public class JsEmpty extends SourceInfoAwareJsNode implements JsStatement {
JsEmpty() {
}
@@ -18,4 +20,10 @@ public class JsEmpty extends SourceInfoAwareJsNode implements JsStatement {
v.visit(this, ctx);
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsEmpty deepCopy() {
+ return this;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmptyExpression.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmptyExpression.java
index 43d84b7622a..9f58fe96dfb 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmptyExpression.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsEmptyExpression.java
@@ -38,4 +38,10 @@ public class JsEmptyExpression extends JsExpressionImpl {
public void traverse(JsVisitorWithContext visitor, JsContext ctx) {
throw new IllegalArgumentException("empty expression should not be here during generating Javascript code");
}
+
+ @NotNull
+ @Override
+ public JsEmptyExpression deepCopy() {
+ return new JsEmptyExpression();
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpression.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpression.java
index b2486988cc7..bf20bec3d4a 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpression.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpression.java
@@ -10,4 +10,8 @@ public interface JsExpression extends JsNode {
@Override
JsExpression source(Object info);
+
+ @NotNull
+ @Override
+ JsExpression deepCopy();
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java
index b90a3636014..0d5bbdebb44 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsExpressionStatement.java
@@ -4,6 +4,8 @@
package com.google.dart.compiler.backend.js.ast;
+import org.jetbrains.annotations.NotNull;
+
public final class JsExpressionStatement extends AbstractNode implements JsStatement {
@NotNull
private JsExpression expression;
@@ -49,4 +51,10 @@ public final class JsExpressionStatement extends AbstractNode implements JsState
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsExpressionStatement deepCopy() {
+ return new JsExpressionStatement(expression.deepCopy());
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFor.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFor.java
index 76e25578aba..638917e933d 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFor.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFor.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* A for statement. If specified at all, the initializer part is
* either a declaration of one or more variables, in which case
@@ -118,4 +121,24 @@ public class JsFor extends SourceInfoAwareJsNode implements JsStatement {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsFor deepCopy() {
+ JsStatement bodyCopy = AstUtil.deepCopy(body);
+ JsExpression conditionCopy = AstUtil.deepCopy(condition);
+ JsExpression incrementalExprCopy = AstUtil.deepCopy(incrementExpression);
+
+ if (initVars != null) {
+ return new JsFor(initVars.deepCopy(),
+ conditionCopy,
+ incrementalExprCopy,
+ bodyCopy);
+ } else {
+ return new JsFor(initExpression.deepCopy(),
+ conditionCopy,
+ incrementExpression,
+ bodyCopy);
+ }
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsForIn.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsForIn.java
index 167d9068a18..2f50cb1da1a 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsForIn.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsForIn.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
public class JsForIn extends SourceInfoAwareJsNode implements JsStatement {
private JsStatement body;
private JsExpression iterExpression;
@@ -20,6 +23,14 @@ public class JsForIn extends SourceInfoAwareJsNode implements JsStatement {
this.iterVarName = iterVarName;
}
+ public JsForIn(JsName iterVarName, JsExpression iterExpression, JsExpression objectExpression, JsStatement body) {
+
+ this.iterVarName = iterVarName;
+ this.iterExpression = iterExpression;
+ this.objectExpression = objectExpression;
+ this.body = body;
+ }
+
public JsStatement getBody() {
return body;
}
@@ -73,4 +84,14 @@ public class JsForIn extends SourceInfoAwareJsNode implements JsStatement {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsForIn deepCopy() {
+ JsStatement bodyCopy = AstUtil.deepCopy(body);
+ JsExpression iterCopy = AstUtil.deepCopy(iterExpression);
+ JsExpression objectCopy = AstUtil.deepCopy(objectExpression);
+
+ return new JsForIn(iterVarName, iterCopy, objectCopy, bodyCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFunction.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFunction.java
index 917fb801a25..ed100f70a94 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFunction.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsFunction.java
@@ -5,6 +5,7 @@
package com.google.dart.compiler.backend.js.ast;
import com.google.dart.compiler.common.Symbol;
+import com.google.dart.compiler.util.AstUtil;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -88,4 +89,15 @@ public final class JsFunction extends JsLiteral implements HasName {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsFunction deepCopy() {
+ JsFunction functionCopy = new JsFunction(scope.getParent(), scope.getDescription(), name);
+ functionCopy.getScope().copyOwnNames(scope);
+ functionCopy.setBody(body.deepCopy());
+ functionCopy.params = AstUtil.deepCopy(params);
+
+ return functionCopy;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsGlobalBlock.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsGlobalBlock.java
index 11bbd10d86e..0a408c28758 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsGlobalBlock.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsGlobalBlock.java
@@ -4,6 +4,11 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.List;
+
/**
* Represents a JavaScript block in the global scope.
*/
@@ -16,4 +21,13 @@ public class JsGlobalBlock extends JsBlock {
public boolean isGlobalBlock() {
return true;
}
+
+ @NotNull
+ @Override
+ public JsGlobalBlock deepCopy() {
+ JsGlobalBlock globalBlockCopy = new JsGlobalBlock();
+ List statementscopy = AstUtil.deepCopy(getStatements());
+ globalBlockCopy.getStatements().addAll(statementscopy);
+ return globalBlockCopy;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsIf.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsIf.java
index 1fbfcb437ad..1c0431c560b 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsIf.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsIf.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* Represents a JavaScript if statement.
*/
@@ -75,4 +78,14 @@ public final class JsIf extends SourceInfoAwareJsNode implements JsStatement {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsIf deepCopy() {
+ JsExpression ifCopy = AstUtil.deepCopy(ifExpression);
+ JsStatement thenCopy = AstUtil.deepCopy(thenStatement);
+ JsStatement elseCopy = AstUtil.deepCopy(elseStatement);
+
+ return new JsIf(ifCopy, thenCopy, elseCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java
index 6469732b87e..f86e51ae90a 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsInvocation.java
@@ -4,6 +4,7 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
import com.intellij.util.SmartList;
import org.jetbrains.annotations.NotNull;
@@ -68,4 +69,14 @@ public final class JsInvocation extends JsExpressionImpl.JsExpressionHasArgument
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsInvocation deepCopy() {
+ JsExpression qualifierCopy = AstUtil.deepCopy(qualifier);
+ List argumentsCopy = AstUtil.deepCopy(arguments);
+ JsInvocation copy = new JsInvocation(qualifierCopy, argumentsCopy);
+ copy.setInlineStatus(getInlineStatus());
+ return copy;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLabel.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLabel.java
index 6dd5fa2bdb8..7af18b648f2 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLabel.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLabel.java
@@ -5,6 +5,8 @@
package com.google.dart.compiler.backend.js.ast;
import com.google.dart.compiler.common.Symbol;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
/**
* Represents a JavaScript label statement.
@@ -58,4 +60,10 @@ public class JsLabel extends SourceInfoAwareJsNode implements JsStatement, HasNa
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsLabel deepCopy() {
+ return new JsLabel(label, AstUtil.deepCopy(statement.deepCopy()));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java
index 1385457bdeb..13d77faf31c 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsLiteral.java
@@ -4,6 +4,8 @@
package com.google.dart.compiler.backend.js.ast;
+import org.jetbrains.annotations.NotNull;
+
public abstract class JsLiteral extends JsExpressionImpl {
public static final JsValueLiteral THIS = new JsThisRef();
public static final JsNameRef UNDEFINED = new JsNameRef("undefined");
@@ -69,5 +71,11 @@ public abstract class JsLiteral extends JsExpressionImpl {
public final boolean isLeaf() {
return true;
}
+
+ @NotNull
+ @Override
+ public JsExpression deepCopy() {
+ return this;
+ }
}
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java
index 8cf549b79c2..e07414cccbe 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNameRef.java
@@ -5,6 +5,8 @@
package com.google.dart.compiler.backend.js.ast;
import com.google.dart.compiler.common.Symbol;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
/**
* Represents a JavaScript expression that references a name.
@@ -89,4 +91,14 @@ public final class JsNameRef extends JsExpressionImpl implements HasName {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsNameRef deepCopy() {
+ JsExpression qualifierCopy = AstUtil.deepCopy(qualifier);
+
+ if (name != null) return new JsNameRef(name, qualifierCopy);
+
+ return new JsNameRef(ident, qualifierCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNew.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNew.java
index 3c7597059ff..2722a451281 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNew.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNew.java
@@ -4,7 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
import com.intellij.util.SmartList;
+import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -43,4 +45,12 @@ public final class JsNew extends JsExpressionImpl.JsExpressionHasArguments {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsNew deepCopy() {
+ JsExpression constructorCopy = AstUtil.deepCopy(constructorExpression);
+ List argumentsCopy = AstUtil.deepCopy(arguments);
+ return new JsNew(constructorCopy, argumentsCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNode.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNode.java
index d6abdf60976..f6f6358c37e 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNode.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsNode.java
@@ -4,6 +4,8 @@
package com.google.dart.compiler.backend.js.ast;
+import org.jetbrains.annotations.NotNull;
+
public interface JsNode {
/**
* Causes this object to have the visitor visit itself and its children.
@@ -28,6 +30,9 @@ public interface JsNode {
JsNode source(Object info);
+ @NotNull
+ JsNode deepCopy();
+
/**
* Causes this object to have the visitor visit itself and its children.
*
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java
index cf0288f0a39..8efda04a24a 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsObjectLiteral.java
@@ -4,7 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
import com.intellij.util.SmartList;
+import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -55,4 +57,10 @@ public final class JsObjectLiteral extends JsLiteral {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsObjectLiteral deepCopy() {
+ return new JsObjectLiteral(AstUtil.deepCopy(properties), multiline);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsParameter.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsParameter.java
index 3893c8290ad..c1328666bb0 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsParameter.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsParameter.java
@@ -40,4 +40,12 @@ public final class JsParameter extends SourceInfoAwareJsNode implements HasName
v.visit(this, ctx);
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsParameter deepCopy() {
+ JsParameter parameter = new JsParameter(name);
+ parameter.setHasDefaultValue(hasDefaultValue);
+ return parameter;
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java
index 3e6ff5a804a..39bdc3d7f66 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPostfixOperation.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
public final class JsPostfixOperation extends JsUnaryOperation {
public JsPostfixOperation(JsUnaryOperator op) {
this(op, null);
@@ -25,4 +28,10 @@ public final class JsPostfixOperation extends JsUnaryOperation {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsPostfixOperation deepCopy() {
+ return new JsPostfixOperation(getOperator(), AstUtil.deepCopy(getArg()));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java
index 4ffac01d0a4..0cce595ff4b 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPrefixOperation.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
public final class JsPrefixOperation extends JsUnaryOperation {
public JsPrefixOperation(JsUnaryOperator op) {
this(op, null);
@@ -25,4 +28,10 @@ public final class JsPrefixOperation extends JsUnaryOperation {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsPrefixOperation deepCopy() {
+ return new JsPrefixOperation(getOperator(), AstUtil.deepCopy(getArg()));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsProgram.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsProgram.java
index 5a709d7576b..9156e3dacde 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsProgram.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsProgram.java
@@ -8,6 +8,7 @@ import gnu.trove.TDoubleObjectHashMap;
import gnu.trove.THashMap;
import gnu.trove.TIntObjectHashMap;
import org.jetbrains.annotations.NotNull;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
import java.util.Map;
@@ -139,4 +140,10 @@ public final class JsProgram extends SourceInfoAwareJsNode {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsProgram deepCopy() {
+ throw new NotImplementedException();
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java
index fe871bbc78e..32310d0314f 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsProgramFragment.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import org.jetbrains.annotations.NotNull;
+import sun.reflect.generics.reflectiveObjects.NotImplementedException;
+
/**
* One independently loadable fragment of a {@link JsProgram}.
*/
@@ -35,4 +38,10 @@ public class JsProgramFragment extends SourceInfoAwareJsNode {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsProgramFragment deepCopy() {
+ throw new NotImplementedException();
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java
index 2acfea7243c..869d5d9d039 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsPropertyInitializer.java
@@ -53,4 +53,10 @@ public class JsPropertyInitializer extends SourceInfoAwareJsNode {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsPropertyInitializer deepCopy() {
+ return new JsPropertyInitializer(labelExpr.deepCopy(), valueExpr.deepCopy());
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsReturn.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsReturn.java
index 0632fd84bbb..d18fda77e80 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsReturn.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsReturn.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* A JavaScript return statement.
*/
@@ -46,4 +49,10 @@ public final class JsReturn extends SourceInfoAwareJsNode implements JsStatement
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsReturn deepCopy() {
+ return new JsReturn(AstUtil.deepCopy(expression));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsScope.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsScope.java
index 11cdab7c3df..01ddf652872 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsScope.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsScope.java
@@ -9,6 +9,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Map;
import static com.google.dart.compiler.backend.js.ast.AstPackage.JsObjectScope;
@@ -154,6 +155,16 @@ public abstract class JsScope {
}
}
+ public void copyOwnNames(JsScope other) {
+ names = new HashMap(names);
+ names.putAll(other.names);
+ }
+
+ @NotNull
+ public String getDescription() {
+ return description;
+ }
+
@NotNull
protected JsName doCreateName(String ident) {
JsName name = new JsName(this, ident);
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsStatement.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsStatement.java
index a3ea11cec92..a064c7f8c81 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsStatement.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsStatement.java
@@ -4,5 +4,10 @@
package com.google.dart.compiler.backend.js.ast;
+import org.jetbrains.annotations.NotNull;
+
public interface JsStatement extends JsNode {
+ @NotNull
+ @Override
+ JsStatement deepCopy();
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java
index 5459f880ee5..e8b9562412b 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsSwitch.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
import java.util.ArrayList;
import java.util.List;
@@ -12,11 +15,17 @@ import java.util.List;
*/
public class JsSwitch extends SourceInfoAwareJsNode implements JsStatement {
- private final List cases = new ArrayList();
+ private final List cases;
private JsExpression expression;
public JsSwitch() {
super();
+ cases = new ArrayList();
+ }
+
+ public JsSwitch(JsExpression expression, List cases) {
+ this.expression = expression;
+ this.cases = cases;
}
public List getCases() {
@@ -50,4 +59,13 @@ public class JsSwitch extends SourceInfoAwareJsNode implements JsStatement {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsSwitch deepCopy() {
+ JsExpression expressionCopy = AstUtil.deepCopy(expression);
+ List casesCopy = AstUtil.deepCopy(cases);
+
+ return new JsSwitch(expressionCopy, casesCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java
index 225369525ff..8d923fa9e4e 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsSwitchMember.java
@@ -5,6 +5,7 @@
package com.google.dart.compiler.backend.js.ast;
import com.intellij.util.SmartList;
+import org.jetbrains.annotations.NotNull;
import java.util.List;
@@ -26,4 +27,8 @@ public abstract class JsSwitchMember extends SourceInfoAwareJsNode {
public void acceptChildren(JsVisitor visitor) {
visitor.acceptWithInsertRemove(statements);
}
+
+ @NotNull
+ @Override
+ public abstract JsSwitchMember deepCopy();
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsThrow.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsThrow.java
index 2648f4a4cbc..da780d9622c 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsThrow.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsThrow.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
public class JsThrow extends SourceInfoAwareJsNode implements JsStatement {
private JsExpression expression;
@@ -39,4 +42,10 @@ public class JsThrow extends SourceInfoAwareJsNode implements JsStatement {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsThrow deepCopy() {
+ return new JsThrow(AstUtil.deepCopy(expression));
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsTry.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsTry.java
index 568b49861a0..6416d8cf251 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsTry.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsTry.java
@@ -4,7 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
import com.intellij.util.SmartList;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
@@ -72,4 +74,14 @@ public class JsTry extends SourceInfoAwareJsNode implements JsStatement {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsTry deepCopy() {
+ JsBlock tryCopy = AstUtil.deepCopy(tryBlock);
+ List catchCopy = AstUtil.deepCopy(catches);
+ JsBlock finallyCopy = AstUtil.deepCopy(finallyBlock);
+
+ return new JsTry(tryCopy, catchCopy, finallyCopy);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsVars.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsVars.java
index cdf4461c768..96a1996ad07 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsVars.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsVars.java
@@ -5,7 +5,9 @@
package com.google.dart.compiler.backend.js.ast;
import com.google.dart.compiler.common.Symbol;
+import com.google.dart.compiler.util.AstUtil;
import com.intellij.util.SmartList;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.*;
@@ -98,6 +100,14 @@ public class JsVars extends SourceInfoAwareJsNode implements JsStatement, Iterab
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsVar deepCopy() {
+ if (initExpression == null) return new JsVar(name);
+
+ return new JsVar(name, initExpression.deepCopy());
+ }
}
public void add(JsVar var) {
@@ -127,6 +137,10 @@ public class JsVars extends SourceInfoAwareJsNode implements JsStatement, Iterab
return vars.iterator();
}
+ public List getVars() {
+ return vars;
+ }
+
@Override
public void accept(JsVisitor v) {
v.visitVars(this);
@@ -144,4 +158,10 @@ public class JsVars extends SourceInfoAwareJsNode implements JsStatement, Iterab
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsVars deepCopy() {
+ return new JsVars(AstUtil.deepCopy(vars), multiline);
+ }
}
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsWhile.java b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsWhile.java
index 0e4c2a845fd..3755e77f254 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsWhile.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/backend/js/ast/JsWhile.java
@@ -4,6 +4,9 @@
package com.google.dart.compiler.backend.js.ast;
+import com.google.dart.compiler.util.AstUtil;
+import org.jetbrains.annotations.NotNull;
+
/**
* A JavaScript while statement.
*/
@@ -54,4 +57,13 @@ public class JsWhile extends SourceInfoAwareJsNode implements JsStatement {
}
v.endVisit(this, ctx);
}
+
+ @NotNull
+ @Override
+ public JsWhile deepCopy() {
+ JsExpression conditionCopy = AstUtil.deepCopy(condition);
+ JsStatement bodyCopy = AstUtil.deepCopy(body);
+
+ return new JsWhile(conditionCopy, bodyCopy);
+ }
}
\ No newline at end of file
diff --git a/js/js.dart-ast/src/com/google/dart/compiler/util/AstUtil.java b/js/js.dart-ast/src/com/google/dart/compiler/util/AstUtil.java
index f50c4c0e0f0..f5935d59343 100644
--- a/js/js.dart-ast/src/com/google/dart/compiler/util/AstUtil.java
+++ b/js/js.dart-ast/src/com/google/dart/compiler/util/AstUtil.java
@@ -5,6 +5,12 @@
package com.google.dart.compiler.util;
import com.google.dart.compiler.backend.js.ast.*;
+import com.intellij.util.SmartList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+import java.util.ArrayList;
+import java.util.List;
public final class AstUtil {
private AstUtil() {
@@ -26,4 +32,24 @@ public final class AstUtil {
}
return (JsBinaryOperation) result;
}
+
+ @Nullable
+ public static T deepCopy(@Nullable T node) {
+ if (node == null) return null;
+
+ //noinspection unchecked
+ return (T) node.deepCopy();
+ }
+
+ @NotNull
+ public static List deepCopy(@Nullable List nodes) {
+ if (nodes == null) return new SmartList();
+
+ List nodesCopy = new ArrayList(nodes.size());
+ for (T node : nodes) {
+ nodesCopy.add(deepCopy(node));
+ }
+
+ return nodesCopy;
+ }
}