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

COVERAGE SUMMARY FOR SOURCE FILE [Literal.java]

nameclass, %method, %block, %line, %
Literal.java100% (6/6)100% (20/20)98%  (221/225)98%  (46/47)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class Literal$5100% (1/1)100% (3/3)93%  (52/56)94%  (16/17)
write (CachedAppendable, Object, LiteralAccessor): void 100% (1/1)76%  (13/17)83%  (5/6)
Literal$5 (String, int): void 100% (1/1)100% (6/6)100% (1/1)
read (CachedLexable, Object, LiteralAccessor): Object 100% (1/1)100% (33/33)100% (10/10)
     
class Literal100% (1/1)100% (9/9)100% (108/108)100% (15/15)
<static initializer> 100% (1/1)100% (58/58)100% (6/6)
Literal (String, int): void 100% (1/1)100% (8/8)100% (3/3)
Literal (String, int, Literal$1): void 100% (1/1)100% (5/5)100% (1/1)
Literal (String, int, String): void 100% (1/1)100% (9/9)100% (3/3)
Literal (String, int, String, Literal$1): void 100% (1/1)100% (6/6)100% (1/1)
getPattern (): Pattern 100% (1/1)100% (3/3)100% (1/1)
read (CachedLexable, Object, LiteralAccessor): Object 100% (1/1)100% (10/10)100% (2/2)
valueOf (String): Literal 100% (1/1)100% (5/5)100% (1/1)
values (): Literal [] 100% (1/1)100% (4/4)100% (1/1)
     
class Literal$1100% (1/1)100% (2/2)100% (16/16)100% (4/4)
Literal$1 (String, int, String): void 100% (1/1)100% (7/7)100% (1/1)
write (CachedAppendable, Object, LiteralAccessor): void 100% (1/1)100% (9/9)100% (3/3)
     
class Literal$2100% (1/1)100% (2/2)100% (13/13)100% (3/3)
Literal$2 (String, int, String): void 100% (1/1)100% (7/7)100% (1/1)
write (CachedAppendable, Object, LiteralAccessor): void 100% (1/1)100% (6/6)100% (2/2)
     
class Literal$3100% (1/1)100% (2/2)100% (13/13)100% (3/3)
Literal$3 (String, int, String): void 100% (1/1)100% (7/7)100% (1/1)
write (CachedAppendable, Object, LiteralAccessor): void 100% (1/1)100% (6/6)100% (2/2)
     
class Literal$4100% (1/1)100% (2/2)100% (19/19)100% (5/5)
Literal$4 (String, int, String): void 100% (1/1)100% (7/7)100% (1/1)
write (CachedAppendable, Object, LiteralAccessor): void 100% (1/1)100% (12/12)100% (4/4)

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.accessor;
20 
21import java.util.regex.Pattern;
22 
23import org.fuwjax.jon.CachedAppendable;
24import org.fuwjax.jon.CachedLexable;
25import org.fuwjax.jon.ObjectAccessException;
26import org.fuwjax.jon.SerialFormatException;
27import org.fuwjax.jon.type.StringType;
28 
29/**
30 * Contains the format for turning a particular kind of datatype into a string
31 * literal.
32 * @author michaeldoberenz
33 */
34public enum Literal{
35        /**
36         * Writes the sequence as a reference identifier.
37         */
38        Reference("&(\\w+)"){ //$NON-NLS-1$
39                @Override
40                public void write(final CachedAppendable writer, final Object object, final LiteralAccessor type)
41                      throws ObjectAccessException, SerialFormatException{
42                        Token.ReferenceIdentifierStart.write(writer);
43                        writer.write(type.toString(object));
44                }
45        },
46        /**
47         * Writes the sequence as an identifier.
48         */
49        Identifier("[-\\w.$_]+"){ //$NON-NLS-1$
50                @Override
51                public void write(final CachedAppendable writer, final Object object, final LiteralAccessor type)
52                      throws ObjectAccessException, SerialFormatException{
53                        writer.write(type.toString(object));
54                }
55        },
56        /**
57         * Writes the sequence as a class.
58         */
59        Class("\\w+(?:\\.\\w+)*(?:\\$\\w+)*(?:\\[\\])*"){ //$NON-NLS-1$
60                @Override
61                public void write(final CachedAppendable writer, final Object object, final LiteralAccessor type)
62                      throws ObjectAccessException, SerialFormatException{
63                        writer.write(type.toString(object));
64                }
65        },
66        /**
67         * Writes the sequence as a string.
68         */
69        String("\"((?:[^\\\\\"]|\\\\.)*)\""){ //$NON-NLS-1$
70                @Override
71                public void write(final CachedAppendable writer, final Object object, final LiteralAccessor type)
72                      throws ObjectAccessException, SerialFormatException{
73                        Token.StringDelimiter.write(writer);
74                        writer.write(type.toString(object));
75                        Token.StringDelimiter.write(writer);
76                }
77        },
78        /**
79         * reads an unknown literal.
80         */
81        Unknown(){
82                @Override
83                public void write(final CachedAppendable writer, final Object object, final LiteralAccessor type)
84                      throws ObjectAccessException, SerialFormatException{
85                        if(Object.class.equals(object.getClass())){
86                                Token.ObjectStart.write(writer);
87                                Token.ObjectStop.write(writer);
88                        }else{
89                                throw new UnsupportedOperationException();
90                        }
91                }
92 
93                @Override
94                public Object read(final CachedLexable lexer, final Object object, final LiteralAccessor type)
95                      throws ObjectAccessException, SerialFormatException{
96                        final int pos = lexer.getPosition();
97                        try{
98                                return String.read(lexer, object, StringType.DEFAULT);
99                        }catch(SerialFormatException e){
100                                e.assertPosition(pos);
101                                try{
102                                        Token.ObjectStart.read(lexer);
103                                        Token.ObjectStop.read(lexer);
104                                        return new Object();
105                                }catch(SerialFormatException ute){
106                                        ute.assertPosition(pos);
107                                        return Identifier.read(lexer, object, type);
108                                }
109                        }
110                }
111        };
112        private final Pattern pattern;
113 
114        private Literal(final String pattern){
115                this.pattern = Pattern.compile(pattern);
116        }
117 
118        private Literal(){
119                pattern = null;
120        }
121 
122        /**
123         * Returns the pattern matching this literal.
124         * @return the pattern for this literal
125         */
126        public Pattern getPattern(){
127                return pattern;
128        }
129 
130        /**
131         * Sends the specified character sequence to the writer according to this
132         * literal format.
133         * @param writer the destination for the literal.
134         * @param object the source for the literal.
135         * @param type the type of the object.
136         * @throws ObjectAccessException if an object relationship cannot be followed
137         * @throws SerialFormatException if the JON format cannot be preserved
138         */
139        public abstract void write(CachedAppendable writer, Object object, LiteralAccessor type)
140              throws ObjectAccessException, SerialFormatException;
141 
142        /**
143         * Reads the next literal character sequence from the lexer according to this
144         * literal format.
145         * @param lexer the source for the input.
146         * @param object the storage for the parse
147         * @param type the type of the literal
148         * @return the literal.
149         * @throws ObjectAccessException if an object relationship cannot be restored
150         * @throws SerialFormatException if the JON format has not been observed
151         */
152        public Object read(final CachedLexable lexer, final Object object, final LiteralAccessor type)
153              throws ObjectAccessException, SerialFormatException{
154                final CharSequence seq = lexer.read(getPattern());
155                return type.createInstance(seq, object);
156        }
157}

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