ContinueStatement and BreakStatement added
This commit is contained in:
@@ -2,6 +2,7 @@ package org.jetbrains.jet.j2k;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.j2k.ast.*;
|
||||
import org.jetbrains.jet.j2k.ast.Class;
|
||||
import org.jetbrains.jet.j2k.ast.Enum;
|
||||
@@ -120,12 +121,12 @@ public class Converter {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Statement statementToStatement(PsiStatement t) {
|
||||
if (t == null)
|
||||
public static Statement statementToStatement(@Nullable PsiStatement s) {
|
||||
if (s == null)
|
||||
return Statement.EMPTY_STATEMENT;
|
||||
final StatementVisitor statementVisitor = new StatementVisitor();
|
||||
t.accept(statementVisitor);
|
||||
System.out.println(t.getClass());
|
||||
s.accept(statementVisitor);
|
||||
System.out.println(s.getClass());
|
||||
return statementVisitor.getStatement();
|
||||
}
|
||||
|
||||
@@ -139,7 +140,7 @@ public class Converter {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Expression expressionToExpression(PsiExpression e) {
|
||||
public static Expression expressionToExpression(@Nullable PsiExpression e) {
|
||||
if (e == null)
|
||||
return new EmptyExpression();
|
||||
final ExpressionVisitor expressionVisitor = new ExpressionVisitor();
|
||||
@@ -215,4 +216,11 @@ public class Converter {
|
||||
typeToType(parameter.getType())
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Identifier identifierToIdentifier(@Nullable PsiIdentifier identifier) {
|
||||
if (identifier == null)
|
||||
return Identifier.EMPTY_IDENTIFIER;
|
||||
return new IdentifierImpl(identifier.getText());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class BreakStatement extends Statement {
|
||||
private Identifier myLabel = Identifier.EMPTY_IDENTIFIER;
|
||||
|
||||
public BreakStatement(Identifier label) {
|
||||
myLabel = label;
|
||||
}
|
||||
|
||||
public BreakStatement() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.BREAK;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myLabel.isEmpty())
|
||||
return "break";
|
||||
return "break" + AT + myLabel.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ContinueStatement extends Statement {
|
||||
private Identifier myLabel = Identifier.EMPTY_IDENTIFIER;
|
||||
|
||||
public ContinueStatement(Identifier label) {
|
||||
myLabel = label;
|
||||
}
|
||||
|
||||
public ContinueStatement() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.CONTINUE;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
if (myLabel.isEmpty())
|
||||
return "continue";
|
||||
return "continue" + AT + myLabel.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ public interface INode {
|
||||
public Kind getKind();
|
||||
|
||||
public enum Kind {
|
||||
UNDEFINED, TYPE, CONSTRUCTOR,
|
||||
UNDEFINED, TYPE, CONSTRUCTOR, BREAK, CONTINUE,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ package org.jetbrains.jet.j2k.ast;
|
||||
* @author ignatov
|
||||
*/
|
||||
public interface Identifier extends INode {
|
||||
public static Identifier EMPTY_IDENTIFIER = new IdentifierImpl("");
|
||||
public String getName();
|
||||
|
||||
public boolean isEmpty();
|
||||
|
||||
@@ -39,11 +39,23 @@ public class StatementVisitor extends ElementVisitor implements Visitor {
|
||||
@Override
|
||||
public void visitBreakStatement(PsiBreakStatement statement) {
|
||||
super.visitBreakStatement(statement);
|
||||
if (statement.getLabelIdentifier() == null)
|
||||
myResult = new BreakStatement();
|
||||
else
|
||||
myResult = new BreakStatement(
|
||||
identifierToIdentifier(statement.getLabelIdentifier())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitContinueStatement(PsiContinueStatement statement) {
|
||||
super.visitContinueStatement(statement);
|
||||
if (statement.getLabelIdentifier() == null)
|
||||
myResult = new ContinueStatement();
|
||||
else
|
||||
myResult = new ContinueStatement(
|
||||
identifierToIdentifier(statement.getLabelIdentifier())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.jet.j2k.JetTestCaseBase;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class BreakStatementTest extends JetTestCaseBase {
|
||||
public void testBreakWithoutLabel() throws Exception {
|
||||
Assert.assertEquals(
|
||||
statementToSingleLineKotlin("break;"),
|
||||
"break"
|
||||
);
|
||||
}
|
||||
|
||||
public void testBreakWithLabel() throws Exception {
|
||||
Assert.assertEquals(
|
||||
statementToSingleLineKotlin("break label;"),
|
||||
"break@label"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.jet.j2k.JetTestCaseBase;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class ContinueStatementTest extends JetTestCaseBase {
|
||||
public void testContinueWithoutLabel() throws Exception {
|
||||
Assert.assertEquals(
|
||||
statementToSingleLineKotlin("continue;"),
|
||||
"continue"
|
||||
);
|
||||
}
|
||||
|
||||
public void testContinueWithLabel() throws Exception {
|
||||
Assert.assertEquals(
|
||||
statementToSingleLineKotlin("continue label;"),
|
||||
"continue@label"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user