ArrayType added

This commit is contained in:
Sergey Ignatov
2011-10-31 21:01:31 +04:00
parent ef3abfd10d
commit 01c0d11ccc
3 changed files with 61 additions and 0 deletions
@@ -0,0 +1,22 @@
package org.jetbrains.jet.j2k.ast;
import org.jetbrains.annotations.NotNull;
/**
* @author ignatov
*/
public class ArrayType extends Type {
private final Type myType;
public ArrayType(Type type) {
myType = type;
}
@NotNull
@Override
public String toKotlin() {
if (PRIMITIVE_TYPES.contains(myType.toKotlin().toLowerCase()))
return myType.toKotlin() + "Array" + QUESTION; // TODO
return "Array" + "<" + myType.toKotlin() + ">" + QUESTION;
}
}
@@ -2,6 +2,7 @@ package org.jetbrains.jet.j2k.visitors;
import com.intellij.psi.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.j2k.Converter;
import org.jetbrains.jet.j2k.ast.*;
import org.jetbrains.jet.j2k.util.AstUtil;
@@ -36,6 +37,7 @@ public class TypeVisitor extends PsiTypeVisitor<Type> implements Visitor {
@Override
public Type visitArrayType(PsiArrayType arrayType) {
myResult = new ArrayType(Converter.typeToType(arrayType.getComponentType()));
return super.visitArrayType(arrayType);
}
@@ -0,0 +1,37 @@
package org.jetbrains.jet.j2k.ast;
import junit.framework.Assert;
import org.jetbrains.jet.j2k.JetTestCaseBase;
/**
* @author ignatov
*/
public class ArrayTypeTest extends JetTestCaseBase {
public void testNewStringArray() throws Exception {
Assert.assertEquals(
statementToKotlin("String[] a = new String[]{\"abc\"}"),
"var a : Array<String?>? = array(\"abc\")"
);
}
public void testNewIntArray() throws Exception {
Assert.assertEquals(
statementToKotlin("int[] a = new int[]{1, 2, 3}"),
"var a : IntArray? = array(1, 2, 3)"
);
}
public void testDoubleArray() throws Exception {
Assert.assertEquals(
statementToKotlin("double[] a = new double[]{1, 2, 3}"),
"var a : DoubleArray? = array(1, 2, 3)"
);
}
public void testLongArray() throws Exception {
Assert.assertEquals(
statementToKotlin("long[] a = new long[]{1, 2, 3}"),
"var a : LongArray? = array(1, 2, 3)"
);
}
}