/** * Return if the Fantom Type is represented as a Java class such as sys::Int as java.lang.Long. */ public static boolean isJavaRepresentation(Type t) { if (t.pod() != Sys.sysPod) return false; return t == Sys.ObjType || t == Sys.BoolType || t == Sys.StrType || t == Sys.IntType || t == Sys.FloatType || t == Sys.NumType || t == Sys.DecimalType; }
/** Given a Fantom type, get its stack type: 'A', 'I', 'J', etc */ public static int toJavaStackType(Type t) { if (!t.isNullable()) { if (t == Sys.VoidType) return 'V'; if (t == Sys.BoolType) return 'I'; if (t == Sys.IntType) return 'J'; if (t == Sys.FloatType) return 'D'; if (t.isJava() && t.podName().equals("[java]")) { // FFI primitives if (t.name().equals("byte")) return 'I'; if (t.name().equals("char")) return 'I'; if (t.name().equals("short")) return 'I'; if (t.name().equals("int")) return 'I'; if (t.name().equals("float")) return 'F'; // fail-safe if (t.name().equals("long")) return 'L'; if (t.name().equals("boolean")) return 'F'; if (t.name().equals("double")) return 'D'; } } return 'A'; }
/** Given a Fantom type, get the Java type signature: fan/sys/Duration */ public static String toJavaTypeSig(Type t) { return toJavaTypeSig(t.podName(), t.name(), t.isNullable()); }