map the remaining primitive PSI types to ASM
This commit is contained in:
@@ -344,7 +344,7 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
private String getMethodDescriptor(PsiMethod method) {
|
||||
private static String getMethodDescriptor(PsiMethod method) {
|
||||
Type returnType = psiTypeToAsm(method.getReturnType());
|
||||
PsiParameter[] parameters = method.getParameterList().getParameters();
|
||||
Type[] parameterTypes = new Type[parameters.length];
|
||||
@@ -354,7 +354,7 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
return Type.getMethodDescriptor(returnType, parameterTypes);
|
||||
}
|
||||
|
||||
private Type psiTypeToAsm(PsiType type) {
|
||||
private static Type psiTypeToAsm(PsiType type) {
|
||||
if (type instanceof PsiPrimitiveType) {
|
||||
if (type == PsiType.VOID) {
|
||||
return Type.VOID_TYPE;
|
||||
@@ -368,6 +368,21 @@ public class ExpressionCodegen extends JetVisitor {
|
||||
if (type == PsiType.BOOLEAN) {
|
||||
return Type.BOOLEAN_TYPE;
|
||||
}
|
||||
if (type == PsiType.BYTE) {
|
||||
return Type.BYTE_TYPE;
|
||||
}
|
||||
if (type == PsiType.SHORT) {
|
||||
return Type.SHORT_TYPE;
|
||||
}
|
||||
if (type == PsiType.CHAR) {
|
||||
return Type.CHAR_TYPE;
|
||||
}
|
||||
if (type == PsiType.FLOAT) {
|
||||
return Type.FLOAT_TYPE;
|
||||
}
|
||||
if (type == PsiType.DOUBLE) {
|
||||
return Type.DOUBLE_TYPE;
|
||||
}
|
||||
}
|
||||
if (type instanceof PsiClassType) {
|
||||
PsiClass psiClass = ((PsiClassType) type).resolve();
|
||||
|
||||
@@ -65,7 +65,7 @@ public class JetTypeMapper {
|
||||
if (jetType.equals(TypeUtils.makeNullable(standardLibrary.getBooleanType()))) {
|
||||
return Type.getObjectType("java/lang/Boolean");
|
||||
}
|
||||
if (jetType.equals(standardLibrary.getStringType())) {
|
||||
if (jetType.equals(standardLibrary.getStringType()) || jetType.equals(standardLibrary.getNullableStringType())) {
|
||||
return Type.getType(String.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -308,6 +308,12 @@ public class NamespaceGenTest extends LightCodeInsightFixtureTestCase {
|
||||
binOpTest("fun foo(a: Double, b: Double): Boolean = a == b", 1.0, 2.0, false);
|
||||
}
|
||||
|
||||
public void testDoubleToJava() throws Exception {
|
||||
loadText("fun foo(d: Double): String? = Double.toString(d)");
|
||||
final Method main = generateFunction();
|
||||
assertEquals("1.0", main.invoke(null, 1.0));
|
||||
}
|
||||
|
||||
private void binOpTest(final String text, final Object arg1, final Object arg2, final Object expected) throws Exception {
|
||||
loadText(text);
|
||||
System.out.println(generateToText());
|
||||
|
||||
Reference in New Issue
Block a user