private String getValue() { TypeSpec ts = const_type.symbol.typeSpec(); while (ts instanceof AliasTypeSpec) { ts = ((AliasTypeSpec) ts).originalType(); } if (logger.isDebugEnabled()) { logger.debug("ConstDecl(" + name + ": " + ts.getClass() + ") = " + const_type.toString()); } // Bugzilla #851 - Infinity values wrapping String exprStr = const_expr.toString(); if (exprStr != null && exprStr.contains("Infinity")) { logger.warn( "[" + token.line_no + ":" + token.char_pos + "]" + "Infinity value used in const declaration"); if (exprStr.startsWith("-")) { exprStr = "Double.NEGATIVE_INFINITY"; } else { exprStr = "Double.POSITIVE_INFINITY"; } } if (ts instanceof ShortType) { // short constant values have to be cast explicitly return ("(short)(" + exprStr + ")"); } else if (ts instanceof FloatType) { // float constant values have to be cast explicitly return ("(float)(" + exprStr + ")"); } else if (ts instanceof OctetType) { // byte constant values have to be cast explicitly return ("(byte)(" + exprStr + ")"); } else if (ts instanceof FixedPointConstType || ts instanceof FixedPointType) { return ("new java.math.BigDecimal (" + exprStr + ")"); } else if (ts instanceof LongLongType) { String cast = ""; try { if (const_expr.or_expr.xor_expr.and_expr.shift_expr.operator != null || const_expr.or_expr.xor_expr.and_expr.shift_expr.add_expr.operator != null || const_expr.or_expr.xor_expr.and_expr.shift_expr.add_expr.mult_expr.operator != null) { cast = "(long)"; } } catch (Exception e) { // Don't care if any of the above cause null ptr - just won't do cast. } return (cast + const_expr.toString()); } else { return exprStr; } }
/** prints a constant declaration outside of an enclosing interface into a separate interface */ public void print(PrintWriter ps) { if (contained() || (included && !generateIncluded())) return; try { String fullName = ScopedName.unPseudoName(full_name()); String className; if (fullName.indexOf('.') > 0) { pack_name = fullName.substring(0, fullName.lastIndexOf('.')); className = fullName.substring(fullName.lastIndexOf('.') + 1); } else { pack_name = ""; className = fullName; } String path = parser.out_dir + fileSeparator + pack_name.replace('.', fileSeparator); File dir = new File(path); if (!dir.exists()) { if (!dir.mkdirs()) { org.jacorb.idl.parser.fatal_error("Unable to create " + path, null); } } String fname = className + ".java"; File f = new File(dir, fname); if (GlobalInputStream.isMoreRecentThan(f)) { PrintWriter pw = new PrintWriter(new java.io.FileWriter(f)); if (logger.isDebugEnabled()) logger.debug("ConstDecl.print " + fname); if (!pack_name.equals("")) pw.println("package " + pack_name + ";"); printClassComment("const", className, pw); pw.println("public interface " + className); pw.println("{"); pw.print("\t" + const_type.toString() + " value = "); pw.print(getValue()); pw.println(";"); pw.println("}"); pw.close(); } } catch (java.io.IOException i) { throw new RuntimeException("File IO error" + i); } }