ArrayType 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 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 com.intellij.psi.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.j2k.Converter;
|
||||||
import org.jetbrains.jet.j2k.ast.*;
|
import org.jetbrains.jet.j2k.ast.*;
|
||||||
import org.jetbrains.jet.j2k.util.AstUtil;
|
import org.jetbrains.jet.j2k.util.AstUtil;
|
||||||
|
|
||||||
@@ -36,6 +37,7 @@ public class TypeVisitor extends PsiTypeVisitor<Type> implements Visitor {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Type visitArrayType(PsiArrayType arrayType) {
|
public Type visitArrayType(PsiArrayType arrayType) {
|
||||||
|
myResult = new ArrayType(Converter.typeToType(arrayType.getComponentType()));
|
||||||
return super.visitArrayType(arrayType);
|
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)"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user