LabelStatement added
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class LabelStatement extends Statement {
|
||||
private final Identifier myName;
|
||||
private final Statement myStatement;
|
||||
|
||||
public LabelStatement(Identifier name, Statement statement) {
|
||||
myName = name;
|
||||
myStatement = statement;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return AT + myName.toKotlin() + SPACE + myStatement.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -141,6 +141,10 @@ public class StatementVisitor extends ElementVisitor implements Visitor {
|
||||
@Override
|
||||
public void visitLabeledStatement(PsiLabeledStatement statement) {
|
||||
super.visitLabeledStatement(statement);
|
||||
myResult = new LabelStatement(
|
||||
identifierToIdentifier(statement.getLabelIdentifier()),
|
||||
statementToStatement(statement.getStatement())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.jet.j2k.JetTestCaseBase;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class LabelStatementTest extends JetTestCaseBase {
|
||||
public void testComplicatedExampleFromJavaTutorial() throws Exception {
|
||||
Assert.assertEquals(
|
||||
statementToKotlin(
|
||||
" test:" +
|
||||
" for (int i = 0; i <= max; i++) {" +
|
||||
" int n = substring.length();" +
|
||||
" int j = i;" +
|
||||
" int k = 0;" +
|
||||
" while (n-- != 0) {" +
|
||||
" if (searchMe.charAt(j++) != substring.charAt(k++)) {" +
|
||||
" continue test;" +
|
||||
" }" +
|
||||
" } " +
|
||||
" foundIt = true;" +
|
||||
" break test;" +
|
||||
" }" +
|
||||
" System.out.println(foundIt ? \"Found it\" : \"Didn't find it\");" +
|
||||
" }" +
|
||||
"}"),
|
||||
"@test {\n" +
|
||||
"var i : Int = 0\n" +
|
||||
"while ((i <= max))\n" +
|
||||
"{\n" +
|
||||
"{\n" +
|
||||
"var n : Int = substring.length()\n" +
|
||||
"var j : Int = i\n" +
|
||||
"var k : Int = 0\n" +
|
||||
"while (((n--) != 0))\n" +
|
||||
"{\n" +
|
||||
"if ((searchMe.charAt((j++)) != substring.charAt((k++))))\n" +
|
||||
"{\n" +
|
||||
"continue@test\n" +
|
||||
"}\n" +
|
||||
"}\n" +
|
||||
"foundIt = true\n" +
|
||||
"break@test\n" +
|
||||
"}\n" +
|
||||
"{\n" +
|
||||
"(i++)\n" +
|
||||
"}\n" +
|
||||
"}\n" +
|
||||
"}\n" +
|
||||
"System.out.println((if (foundIt)\n" +
|
||||
"\"Found it\"\n" +
|
||||
"else\n" +
|
||||
"\"Didn't find it\"))"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user