List of usage examples for javax.lang.model.type TypeKind LONG
TypeKind LONG
To view the source code for javax.lang.model.type TypeKind LONG.
Click Source Link
From source file:org.jsweet.transpiler.Java2TypeScriptTranslator.java
@Override public void visitBinary(JCBinary binary) { if (Util.isIntegral(binary.type) && binary.getKind() == Kind.DIVIDE) { if (binary.type.getKind() == TypeKind.LONG) { print("Math.floor("); } else {/*from www . ja va 2s. co m*/ print("("); } } boolean charWrapping = Util.isArithmeticOperator(binary.getKind()) || Util.isComparisonOperator(binary.getKind()); boolean actualCharWrapping = false; if (charWrapping && binary.lhs.type.isPrimitive() && context.symtab.charType.tsym == binary.lhs.type.tsym && !(binary.rhs.type.tsym == context.symtab.stringType.tsym)) { actualCharWrapping = true; if (binary.lhs instanceof JCLiteral) { print(binary.lhs).print(".charCodeAt(0)"); } else { print("(c => c.charCodeAt==null?<any>c:c.charCodeAt(0))(").print(binary.lhs).print(")"); } } else { print(binary.lhs); } String op = binary.operator.name.toString(); if (binary.lhs.type.getKind() == TypeKind.BOOLEAN) { if ("|".equals(op)) { op = "||"; } else if ("&".equals(op)) { op = "&&"; } else if ("^".equals(op)) { op = "!=="; } } if ("==".equals(op) || "!=".equals(op)) { if (charWrapping && binary.rhs.type.isPrimitive() && context.symtab.charType.tsym == binary.rhs.type.tsym && !(binary.lhs.type.tsym == context.symtab.stringType.tsym)) { actualCharWrapping = true; } } if ("==".equals(op) && !(Util.isNullLiteral(binary.lhs) || Util.isNullLiteral(binary.rhs))) { op = actualCharWrapping ? "==" : "==="; } else if ("!=".equals(op) && !(Util.isNullLiteral(binary.lhs) || Util.isNullLiteral(binary.rhs))) { op = actualCharWrapping ? "!=" : "!=="; } space().print(op).space(); if (charWrapping && binary.rhs.type.isPrimitive() && context.symtab.charType.tsym == binary.rhs.type.tsym && !(binary.lhs.type.tsym == context.symtab.stringType.tsym)) { if (binary.rhs instanceof JCLiteral) { print(binary.rhs).print(".charCodeAt(0)"); } else { print("(c => c.charCodeAt==null?<any>c:c.charCodeAt(0))(").print(binary.rhs).print(")"); } } else { print(binary.rhs); } if (Util.isIntegral(binary.type) && binary.getKind() == Kind.DIVIDE) { if (binary.type.getKind() == TypeKind.LONG) { print(")"); } else { print("|0)"); } } }
From source file:org.jsweet.transpiler.Java2TypeScriptTranslator.java
@Override public void visitTypeCast(JCTypeCast cast) { if (substituteAssignedExpression(cast.type, cast.expr)) { return;//from ww w.j a v a2 s . c o m } if (Util.isIntegral(cast.type)) { if (cast.type.getKind() == TypeKind.LONG) { print("Math.floor("); } else { print("("); } } if (!context.hasAnnotationType(cast.clazz.type.tsym, ANNOTATION_ERASED, ANNOTATION_OBJECT_TYPE, ANNOTATION_FUNCTIONAL_INTERFACE)) { // Java is more permissive than TypeScript when casting type // variables if (cast.expr.type.getKind() == TypeKind.TYPEVAR) { print("<any>"); } else { print("<"); substituteAndPrintType(cast.clazz).print(">"); } } print(cast.expr); if (Util.isIntegral(cast.type)) { if (cast.type.getKind() == TypeKind.LONG) { print(")"); } else { print("|0)"); } } }