more statements
This commit is contained in:
committed by
Pavel V. Talanov
parent
feab374ee3
commit
c7a4236d93
@@ -1,41 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class ForeachStatement extends Statement {
|
|
||||||
private final Parameter myVariable;
|
|
||||||
private final Expression myExpression;
|
|
||||||
private final Statement myStatement;
|
|
||||||
|
|
||||||
public ForeachStatement(Parameter variable, Expression expression, Statement statement) {
|
|
||||||
myVariable = variable;
|
|
||||||
myExpression = expression;
|
|
||||||
myStatement = statement;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return "for" + SPACE + "(" + myVariable.toKotlin() + SPACE + IN + SPACE + myExpression.toKotlin() + ")" + N +
|
|
||||||
myStatement.toKotlin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2010-2012 JetBrains s.r.o.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.jetbrains.jet.j2k.ast;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author ignatov
|
|
||||||
*/
|
|
||||||
public class ForeachWithRangeStatement extends Statement {
|
|
||||||
private final Expression myStart;
|
|
||||||
private final Identifier myIdentifier;
|
|
||||||
private final Expression myEnd;
|
|
||||||
private final Statement myBody;
|
|
||||||
|
|
||||||
public ForeachWithRangeStatement(Identifier identifier, Expression start, Expression end, Statement body) {
|
|
||||||
myStart = start;
|
|
||||||
myIdentifier = identifier;
|
|
||||||
myEnd = end;
|
|
||||||
myBody = body;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
@Override
|
|
||||||
public String toKotlin() {
|
|
||||||
return "for" + SPACE + "(" +
|
|
||||||
myIdentifier.toKotlin() + SPACE + "in" + SPACE + myStart.toKotlin() + ".." + myEnd.toKotlin() +
|
|
||||||
")" + SPACE +
|
|
||||||
myBody.toKotlin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
package org.jetbrains.jet.j2k.ast
|
|
||||||
|
|
||||||
|
|
||||||
public open class IfStatement(val condition: Expression, val thenStatement: Statement, val elseStatement: Statement): Expression() {
|
|
||||||
public override fun toKotlin(): String {
|
|
||||||
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n"
|
|
||||||
if (elseStatement != Statement.EMPTY_STATEMENT) {
|
|
||||||
return result + "else\n" + elseStatement.toKotlin()
|
|
||||||
}
|
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -28,6 +28,17 @@ public open class ReturnStatement(val expression: Expression): Statement() {
|
|||||||
public override fun toKotlin() = "return " + expression.toKotlin()
|
public override fun toKotlin() = "return " + expression.toKotlin()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public open class IfStatement(val condition: Expression, val thenStatement: Statement, val elseStatement: Statement): Expression() {
|
||||||
|
public override fun toKotlin(): String {
|
||||||
|
val result: String = "if (" + condition.toKotlin() + ")\n" + thenStatement.toKotlin() + "\n"
|
||||||
|
if (elseStatement != Statement.EMPTY_STATEMENT) {
|
||||||
|
return result + "else\n" + elseStatement.toKotlin()
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Loops --------------------------------------------------------------------------------------------------
|
// Loops --------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
public open class WhileStatement(val condition: Expression, val statement: Statement): Statement() {
|
public open class WhileStatement(val condition: Expression, val statement: Statement): Statement() {
|
||||||
@@ -38,6 +49,21 @@ public open class DoWhileStatement(condition: Expression, statement: Statement):
|
|||||||
public override fun toKotlin() = "do\n" + statement.toKotlin() + "\nwhile (" + condition.toKotlin() + ")"
|
public override fun toKotlin() = "do\n" + statement.toKotlin() + "\nwhile (" + condition.toKotlin() + ")"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public open class ForeachStatement(val variable: Parameter,
|
||||||
|
val expression: Expression,
|
||||||
|
val statement: Statement): Statement() {
|
||||||
|
public override fun toKotlin() = "for (" + variable.toKotlin() + " in " +
|
||||||
|
expression.toKotlin() + ")\n" + statement.toKotlin()
|
||||||
|
}
|
||||||
|
|
||||||
|
public open class ForeachWithRangeStatement(val identifier: Identifier,
|
||||||
|
val start: Expression,
|
||||||
|
val end: Expression,
|
||||||
|
val body: Statement): Statement() {
|
||||||
|
public override fun toKotlin() = "for (" + identifier.toKotlin() + " in " +
|
||||||
|
start.toKotlin() + ".." + end.toKotlin() + ") " + body.toKotlin()
|
||||||
|
}
|
||||||
|
|
||||||
public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() {
|
public open class BreakStatement(val label: Identifier = Identifier.EMPTY_IDENTIFIER) : Statement() {
|
||||||
public override fun toKotlin() = "break" + label.withPrefix("@")
|
public override fun toKotlin() = "break" + label.withPrefix("@")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user