varagrs supported
This commit is contained in:
@@ -182,7 +182,7 @@ public class Converter {
|
||||
@NotNull
|
||||
public static Type typeToType(@Nullable PsiType type) {
|
||||
if (type == null)
|
||||
return new EmptyType(); // TODO
|
||||
return Type.EMPTY_TYPE; // TODO
|
||||
TypeVisitor typeVisitor = new TypeVisitor();
|
||||
type.accept(typeVisitor);
|
||||
return typeVisitor.getResult();
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class EmptyType extends Type {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "UNRESOLVED_TYPE";
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,6 @@ public interface INode {
|
||||
public Kind getKind();
|
||||
|
||||
public enum Kind {
|
||||
UNDEFINED, TYPE, CONSTRUCTOR, BREAK, CONTINUE,
|
||||
UNDEFINED, TYPE, CONSTRUCTOR, BREAK, CONTINUE, VARARG,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ public class Parameter extends Expression {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin();
|
||||
String vararg = myType.getKind() == Kind.VARARG ? "vararg" + SPACE : EMPTY;
|
||||
return vararg + myIdentifier.toKotlin() + SPACE + COLON + SPACE + myType.toKotlin();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
* @author ignatov
|
||||
*/
|
||||
public abstract class Type extends Element {
|
||||
public static Type EMPTY_TYPE = new EmptyType();
|
||||
protected boolean myNullable = true;
|
||||
|
||||
@NotNull
|
||||
@@ -25,4 +26,15 @@ public abstract class Type extends Element {
|
||||
protected String isNullableStr() {
|
||||
return isNullable() ? QUESTION : EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
private static class EmptyType extends Type {
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return "UNRESOLVED_TYPE";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class VarArg extends Type {
|
||||
private Type myType;
|
||||
|
||||
public VarArg(Type type) {
|
||||
myType = type;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Type getType() {
|
||||
return myType;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Kind getKind() {
|
||||
return Kind.VARARG;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String toKotlin() {
|
||||
return myType.toKotlin();
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ import static org.jetbrains.jet.j2k.Converter.typesToTypeList;
|
||||
* @author ignatov
|
||||
*/
|
||||
public class TypeVisitor extends PsiTypeVisitor<Type> implements Visitor {
|
||||
private Type myResult = new EmptyType();
|
||||
private Type myResult = Type.EMPTY_TYPE;
|
||||
|
||||
@NotNull
|
||||
public Type getResult() {
|
||||
@@ -40,7 +40,8 @@ public class TypeVisitor extends PsiTypeVisitor<Type> implements Visitor {
|
||||
|
||||
@Override
|
||||
public Type visitArrayType(PsiArrayType arrayType) {
|
||||
myResult = new ArrayType(typeToType(arrayType.getComponentType()));
|
||||
if (myResult == Type.EMPTY_TYPE)
|
||||
myResult = new ArrayType(typeToType(arrayType.getComponentType()));
|
||||
return super.visitArrayType(arrayType);
|
||||
}
|
||||
|
||||
@@ -71,6 +72,7 @@ public class TypeVisitor extends PsiTypeVisitor<Type> implements Visitor {
|
||||
|
||||
@Override
|
||||
public Type visitEllipsisType(PsiEllipsisType ellipsisType) {
|
||||
myResult = new VarArg(typeToType(ellipsisType.getComponentType()));
|
||||
return super.visitEllipsisType(ellipsisType);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.jetbrains.jet.j2k.ast;
|
||||
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.jet.j2k.JetTestCaseBase;
|
||||
|
||||
/**
|
||||
* @author ignatov
|
||||
*/
|
||||
public class VarArgTest extends JetTestCaseBase {
|
||||
public void testEllipsisTypeSingleParams() throws Exception {
|
||||
Assert.assertEquals(
|
||||
methodToSingleLineKotlin("void pushAll(Object... objs) {}"),
|
||||
"fun pushAll(vararg objs : Object?) : Unit { }"
|
||||
);
|
||||
}
|
||||
|
||||
public void testEllipsisTypeSeveralParams() throws Exception {
|
||||
Assert.assertEquals(
|
||||
methodToSingleLineKotlin("String format(String pattern, Object... arguments);"),
|
||||
"fun format(pattern : String?, vararg arguments : Object?) : String?"
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user