EMMA Coverage Report (generated Wed Aug 29 00:03:59 CDT 2007)
[all classes][org.fuwjax.jon]

COVERAGE SUMMARY FOR SOURCE FILE [ClassCastStrategy.java]

nameclass, %method, %block, %line, %
ClassCastStrategy.java100% (4/4)100% (12/12)100% (115/115)100% (19/19)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ClassCastStrategy100% (1/1)100% (6/6)100% (69/69)100% (9/9)
<static initializer> 100% (1/1)100% (34/34)100% (4/4)
ClassCastStrategy (String, int): void 100% (1/1)100% (5/5)100% (1/1)
ClassCastStrategy (String, int, ClassCastStrategy$1): void 100% (1/1)100% (5/5)100% (1/1)
read (CachedLexable, IndirectType): IndirectType 100% (1/1)100% (16/16)100% (5/5)
valueOf (String): ClassCastStrategy 100% (1/1)100% (5/5)100% (1/1)
values (): ClassCastStrategy [] 100% (1/1)100% (4/4)100% (1/1)
     
class ClassCastStrategy$1100% (1/1)100% (2/2)100% (21/21)100% (4/4)
ClassCastStrategy$1 (String, int): void 100% (1/1)100% (6/6)100% (1/1)
write (CachedAppendable, IndirectType, IndirectType): void 100% (1/1)100% (15/15)100% (3/3)
     
class ClassCastStrategy$2100% (1/1)100% (2/2)100% (18/18)100% (4/4)
ClassCastStrategy$2 (String, int): void 100% (1/1)100% (6/6)100% (1/1)
write (CachedAppendable, IndirectType, IndirectType): void 100% (1/1)100% (12/12)100% (3/3)
     
class ClassCastStrategy$3100% (1/1)100% (2/2)100% (7/7)100% (2/2)
ClassCastStrategy$3 (String, int): void 100% (1/1)100% (6/6)100% (1/1)
write (CachedAppendable, IndirectType, IndirectType): void 100% (1/1)100% (1/1)100% (1/1)

1/*
2 * This file is part of JON.
3 *
4 * JON is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * JON is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 * 
17 * Copyright 2007 Michael Doberenz
18 */
19package org.fuwjax.jon;
20 
21import org.fuwjax.jon.accessor.Symbol;
22import org.fuwjax.jon.type.AbstractIndirectType;
23import org.fuwjax.jon.type.ClassType;
24import org.fuwjax.jon.type.PrimitiveType;
25 
26/**
27 * Determines the class cast strategy.
28 * @author michaeldoberenz
29 */
30public enum ClassCastStrategy{
31        /**
32         * Always serialize a cast to the writer.
33         */
34        AlwaysCast{
35                @Override
36                public void write(final CachedAppendable writer, final IndirectType actualType, final IndirectType expectedType)
37                      throws ObjectAccessException, SerialFormatException{
38                        if(!expectedType.equals(actualType) && actualType instanceof AbstractIndirectType){
39                                Symbol.ClassCast.write(writer, ((AbstractIndirectType)actualType).getType(), ClassType.DEFAULT);
40                        }
41                }
42        },
43        /**
44         * Call an explicit method to perform tail-casting.
45         */
46        PrimitiveCast{
47                @Override
48                public void write(final CachedAppendable writer, final IndirectType actualType, final IndirectType expectedType)
49                      throws ObjectAccessException, SerialFormatException{
50                        if(!expectedType.equals(actualType) && actualType instanceof PrimitiveType){
51                                ((PrimitiveType)actualType).castNext(expectedType);
52                        }
53                }
54        },
55        /**
56         * Never serialize a cast to the writer.
57         */
58        NeverCast{
59                @Override
60                public void write(final CachedAppendable writer, final IndirectType actualType, final IndirectType expectedType)
61                      throws ObjectAccessException, SerialFormatException{
62                        // write nothing
63                }
64        };
65        /**
66         * Writes the type name to the writer according to the strategy definition.
67         * @param writer the destination for the class cast
68         * @param actualType the type the source object is casting to
69         * @param expectedType the type the source object is casting from.
70         * @throws ObjectAccessException if an object relationship cannot be followed
71         * @throws SerialFormatException if the JON format cannot be preserved
72         */
73        public abstract void write(CachedAppendable writer, IndirectType actualType, IndirectType expectedType)
74              throws ObjectAccessException, SerialFormatException;
75 
76        /**
77         * Reads an indirect type from <code>lexer</code>. If there is not a type
78         * on the input, <code>defaultType</code> is returned.
79         * @param lexer the input for the read operation
80         * @param defaultType the default type
81         * @return the type read from the input, or <code>defaultType</code> if no
82         *         type is found in the input
83         * @throws ObjectAccessException if an object relationship cannot be restored
84         * @throws SerialFormatException if the JON format has not been observed
85         */
86        public static IndirectType read(final CachedLexable lexer, final IndirectType defaultType)
87              throws ObjectAccessException, SerialFormatException{
88                final int pos = lexer.getPosition();
89                try{
90                        return (IndirectType)Symbol.ClassCast.read(lexer, null, ClassType.DEFAULT);
91                }catch(SerialFormatException e){
92                        e.assertPosition(pos);
93                        return defaultType;
94                }
95        }
96}

[all classes][org.fuwjax.jon]
EMMA 2.0.5312 (C) Vladimir Roubtsov