SynchronizedStatement added
This commit is contained in:
@@ -105,12 +105,17 @@ public class Converter {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Block blockToBlock(PsiCodeBlock block, boolean notEmpty) {
|
||||
public static Block blockToBlock(@Nullable PsiCodeBlock block, boolean notEmpty) {
|
||||
if (block == null)
|
||||
return Block.EMPTY_BLOCK;
|
||||
return new Block(statementsToStatementList(block.getStatements()), notEmpty);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Block blockToBlock(@Nullable PsiCodeBlock block) {
|
||||
return blockToBlock(block, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static List<Statement> statementsToStatementList(PsiStatement[] statements) {
|
||||
List<Statement> result = new LinkedList<Statement>();
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SynchronizedStatement extends Statement {
|
||||
private final Expression myExpression;
|
||||
private final Block myBlock;
|
||||
|
||||
public SynchronizedStatement(Expression expression, Block block) {
|
||||
myExpression = expression;
|
||||
myBlock = block;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "synchronized" + SPACE + "(" + myExpression.toKotlin() + ")" + SPACE + myBlock.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -165,6 +165,10 @@ public class StatementVisitor extends ElementVisitor implements Visitor {
|
||||
@Override
|
||||
public void visitSynchronizedStatement(PsiSynchronizedStatement statement) {
|
||||
super.visitSynchronizedStatement(statement);
|
||||
myResult = new SynchronizedStatement(
|
||||
expressionToExpression(statement.getLockExpression()),
|
||||
blockToBlock(statement.getBody())
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.jet.j2k.JetTestCaseBase;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class SynchronizedStatementTest extends JetTestCaseBase {
|
||||
public void testSingleLineExample() throws Exception {
|
||||
Assert.assertEquals(
|
||||
statementToSingleLineKotlin("synchronized (s) { doSomething(s); }"),
|
||||
"synchronized (s) { doSomething(s) }"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user