KT-2864
This commit is contained in:
@@ -222,11 +222,11 @@ public class JsToStringGenerationVisitor extends JsVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void printExpressions(List<JsExpression> expressions) {
|
private void printExpressions(List<JsExpression> expressions) {
|
||||||
boolean sep = false;
|
boolean notFirst = false;
|
||||||
for (JsExpression arg : expressions) {
|
for (JsExpression expression : expressions) {
|
||||||
sep = sepCommaOptSpace(sep);
|
notFirst = sepCommaOptSpace(notFirst) && !(expression instanceof JsDocComment);
|
||||||
boolean isEnclosed = parenPushIfCommaExpression(arg);
|
boolean isEnclosed = parenPushIfCommaExpression(expression);
|
||||||
accept(arg);
|
accept(expression);
|
||||||
if (isEnclosed) {
|
if (isEnclosed) {
|
||||||
rightParen();
|
rightParen();
|
||||||
}
|
}
|
||||||
@@ -556,10 +556,10 @@ public class JsToStringGenerationVisitor extends JsVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
leftParen();
|
leftParen();
|
||||||
boolean sep = false;
|
boolean notFirst = false;
|
||||||
for (Object element : x.getParameters()) {
|
for (Object element : x.getParameters()) {
|
||||||
JsParameter param = (JsParameter) element;
|
JsParameter param = (JsParameter) element;
|
||||||
sep = sepCommaOptSpace(sep);
|
notFirst = sepCommaOptSpace(notFirst);
|
||||||
accept(param);
|
accept(param);
|
||||||
}
|
}
|
||||||
rightParen();
|
rightParen();
|
||||||
@@ -610,8 +610,7 @@ public class JsToStringGenerationVisitor extends JsVisitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean visit(JsInvocation x, JsContext ctx) {
|
public boolean visit(JsInvocation x, JsContext ctx) {
|
||||||
JsExpression qualifier = x.getQualifier();
|
printPair(x, x.getQualifier());
|
||||||
printPair(x, qualifier);
|
|
||||||
|
|
||||||
leftParen();
|
leftParen();
|
||||||
printExpressions(x.getArguments());
|
printExpressions(x.getArguments());
|
||||||
@@ -697,20 +696,20 @@ public class JsToStringGenerationVisitor extends JsVisitor {
|
|||||||
p.indentIn();
|
p.indentIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isNotFirst = false;
|
boolean notFirst = false;
|
||||||
for (JsPropertyInitializer item : objectLiteral.getPropertyInitializers()) {
|
for (JsPropertyInitializer item : objectLiteral.getPropertyInitializers()) {
|
||||||
if (isNotFirst) {
|
if (notFirst) {
|
||||||
p.print(',');
|
p.print(',');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (objectLiteral.isMultiline()) {
|
if (objectLiteral.isMultiline()) {
|
||||||
newlineOpt();
|
newlineOpt();
|
||||||
}
|
}
|
||||||
else if (isNotFirst) {
|
else if (notFirst) {
|
||||||
spaceOpt();
|
spaceOpt();
|
||||||
}
|
}
|
||||||
|
|
||||||
isNotFirst = true;
|
notFirst = true;
|
||||||
|
|
||||||
JsExpression labelExpr = item.getLabelExpr();
|
JsExpression labelExpr = item.getLabelExpr();
|
||||||
// labels can be either string, integral, or decimal literals
|
// labels can be either string, integral, or decimal literals
|
||||||
@@ -907,7 +906,65 @@ public class JsToStringGenerationVisitor extends JsVisitor {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void _newline() {
|
@Override
|
||||||
|
public boolean visit(JsDocComment comment, JsContext context) {
|
||||||
|
boolean asSingleLine = comment.getTags().size() == 1;
|
||||||
|
if (!asSingleLine) {
|
||||||
|
newlineOpt();
|
||||||
|
}
|
||||||
|
p.print("/**");
|
||||||
|
if (asSingleLine) {
|
||||||
|
space();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newline();
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean notFirst = false;
|
||||||
|
for (Map.Entry<String, Object> entry : comment.getTags().entrySet()) {
|
||||||
|
if (notFirst) {
|
||||||
|
newline();
|
||||||
|
p.print(' ');
|
||||||
|
p.print('*');
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
notFirst = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.print('@');
|
||||||
|
p.print(entry.getKey());
|
||||||
|
Object value = entry.getValue();
|
||||||
|
if (value != null) {
|
||||||
|
space();
|
||||||
|
if (value instanceof CharSequence) {
|
||||||
|
p.print((CharSequence) value);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
visit((JsNameRef) value, context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!asSingleLine) {
|
||||||
|
newline();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (asSingleLine) {
|
||||||
|
space();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newlineOpt();
|
||||||
|
}
|
||||||
|
|
||||||
|
p.print('*');
|
||||||
|
p.print('/');
|
||||||
|
if (asSingleLine) {
|
||||||
|
spaceOpt();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void newline() {
|
||||||
p.newline();
|
p.newline();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -977,7 +1034,7 @@ public class JsToStringGenerationVisitor extends JsVisitor {
|
|||||||
newlineOpt();
|
newlineOpt();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_newline();
|
newline();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -1,13 +1,49 @@
|
|||||||
package com.google.dart.compiler.backend.js.ast;
|
package com.google.dart.compiler.backend.js.ast;
|
||||||
|
|
||||||
public class JsDocComment extends JsNodeImpl implements JsStatement {
|
import java.util.Collections;
|
||||||
@Override
|
import java.util.Map;
|
||||||
public NodeKind getKind() {
|
|
||||||
return null; //To change body of implemented methods use File | Settings | File Templates.
|
public class JsDocComment extends JsExpressionImpl implements JsExpression {
|
||||||
|
private final Map<String, Object> tags;
|
||||||
|
|
||||||
|
public JsDocComment(Map<String, Object> tags) {
|
||||||
|
this.tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getTags() {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsDocComment(String tagName, JsNameRef tagValue) {
|
||||||
|
tags = Collections.<String, Object>singletonMap(tagName, tagValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsDocComment(String tagName, String tagValue) {
|
||||||
|
tags = Collections.<String, Object>singletonMap(tagName, tagValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void traverse(JsVisitor visitor, JsContext context) {
|
public NodeKind getKind() {
|
||||||
//To change body of implemented methods use File | Settings | File Templates.
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void traverse(JsVisitor v, JsContext context) {
|
||||||
|
v.visit(this, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasSideEffects() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefinitelyNotNull() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDefinitelyNull() {
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ import java.util.List;
|
|||||||
* Implemented by nodes that will visit child nodes.
|
* Implemented by nodes that will visit child nodes.
|
||||||
*/
|
*/
|
||||||
public class JsVisitor {
|
public class JsVisitor {
|
||||||
|
|
||||||
protected static final JsContext LVALUE_CONTEXT = new JsContext() {
|
protected static final JsContext LVALUE_CONTEXT = new JsContext() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canInsert() {
|
public boolean canInsert() {
|
||||||
return false;
|
return false;
|
||||||
@@ -403,6 +401,10 @@ public class JsVisitor {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean visit(JsDocComment x, JsContext context) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
protected <T extends JsVisitable> T doAccept(T node) {
|
protected <T extends JsVisitable> T doAccept(T node) {
|
||||||
doTraverse(node, UNMODIFIABLE_CONTEXT);
|
doTraverse(node, UNMODIFIABLE_CONTEXT);
|
||||||
return node;
|
return node;
|
||||||
|
|||||||
Reference in New Issue
Block a user