EMMA Coverage Report (generated Mon Mar 20 21:34:30 PST 2006)
[all classes][com.moesol.generator.printer]

COVERAGE SUMMARY FOR SOURCE FILE [JavaValuePrinter.java]

nameclass, %method, %block, %line, %
JavaValuePrinter.java100% (1/1)100% (11/11)91%  (210/231)89%  (66/74)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class JavaValuePrinter100% (1/1)100% (11/11)91%  (210/231)89%  (66/74)
printString (String, Writer): void 100% (1/1)80%  (28/35)80%  (8/10)
print (Object, Writer): void 100% (1/1)86%  (83/97)83%  (29/35)
<static initializer> 100% (1/1)100% (5/5)100% (1/1)
JavaValuePrinter (): void 100% (1/1)100% (3/3)100% (1/1)
getInstance (): JavaValuePrinter 100% (1/1)100% (2/2)100% (1/1)
printArray (Object, Writer): void 100% (1/1)100% (35/35)100% (9/9)
printByte (Byte, Writer): void 100% (1/1)100% (11/11)100% (3/3)
printCharacter (Character, Writer): void 100% (1/1)100% (11/11)100% (4/4)
printInteger (Integer, Writer): void 100% (1/1)100% (9/9)100% (3/3)
printLong (Long, Writer): void 100% (1/1)100% (12/12)100% (4/4)
printShort (Short, Writer): void 100% (1/1)100% (11/11)100% (3/3)

1//
2// (c) Copyright, Moebius Solutions, 2002
3//
4//                       All Rights Reserved
5//
6// This material may be reproduced by or for the U. S. Government
7// pursuant to the copyright license under the clause at
8// DFARS 252.227-7013 (OCT 1988).
9//
10/*
11 * $Id: JavaValuePrinter.java,v 1.1.1.5 2004/05/25 20:23:30 hastings Exp $
12 */
13package com.moesol.generator.printer;
14 
15import java.io.*;
16import java.lang.reflect.*;
17 
18/**
19 * Print types out in a manner suitable for Java programs.
20 */
21public class JavaValuePrinter extends ValuePrinter {
22    protected JavaValuePrinter() { }
23    private static JavaValuePrinter instance = new JavaValuePrinter();
24    public static JavaValuePrinter getInstance() {
25        return instance;
26    }
27    public void print(Object value, Writer out) throws IOException {
28        if (value == null) {
29            out.write("null");
30            return;
31        }
32        if (value instanceof String) {
33            printString(value.toString(), out);
34            return;
35        }
36        if (value instanceof Long) {
37            printLong((Long)value, out);
38            return;
39        }
40        if (value instanceof Integer) {
41            printInteger((Integer)value, out);
42            return;
43        }
44        if (value instanceof Short) {
45            printShort((Short)value, out);
46            return;
47        }
48        if (value instanceof Byte) {
49            printByte((Byte)value, out);
50            return;
51        }
52        if (value instanceof Character) {
53            printCharacter((Character)value, out);
54            return;
55        }
56        if (value instanceof Float) {
57            out.write(value.toString());
58            return;
59        }
60        if (value instanceof Double) {
61            out.write(value.toString());
62            return;
63        }
64        if (value instanceof Boolean) {
65                out.write(value.toString());
66                return;
67        }
68        if (value.getClass().isArray()) {
69            printArray(value, out);
70            return;
71        }
72        // Uncle
73        out.write("null /* unable to print object as value */");
74    }
75    private void printString(String s, Writer out) throws IOException {
76        out.write('"');
77        for (int i = 0; i < s.length(); i++) {
78            char c = s.charAt(i);
79            // TODO The escapes below are really for the generator not java.
80            if (c == '\\') {
81                out.write("\\\\\\");
82            } else if (c == '"') {
83                out.write('\\');
84            }
85            out.write(c);
86        }
87        out.write('"');
88        return;
89    }
90    private void printLong(Long value, Writer out) throws IOException {
91        out.write("0x");
92        out.write(Long.toHexString(value.longValue()));
93        out.write("L");
94    }
95    private void printInteger(Integer value, Writer out) throws IOException {
96        out.write("0x");
97        out.write(Integer.toHexString(value.intValue()));
98    }
99    private void printShort(Short value, Writer out) throws IOException {
100        out.write("0x");
101        out.write(Integer.toHexString(value.intValue() & 0xFFFF));
102    }
103    private void printByte(Byte value, Writer out) throws IOException {
104        out.write("0x");
105        out.write(Integer.toHexString(value.intValue() & 0xFF));
106    }
107    private void printCharacter(Character value, Writer out) throws IOException {
108        out.write("'");
109        out.write(value.toString());
110        out.write("'");
111    }
112    private void printArray(Object value, Writer out) throws IOException {
113        out.write("{ ");
114        int length = Array.getLength(value);
115        if (0 < length) {
116            print(Array.get(value, 0), out);
117        }
118        for (int i = 1; i < length; i++) {
119            out.write(", ");
120            print(Array.get(value, i), out);
121        }
122        out.write(" }");
123    }
124}

[all classes][com.moesol.generator.printer]
EMMA 2.0.5312 (C) Vladimir Roubtsov