EncodedValueAdaptor.java revision 4b72225e9d81201838f387171a68a832486903f9
1/*
2 * [The "BSD licence"]
3 * Copyright (c) 2010 Ben Gruver (JesusFreke)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 *    notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 *    notice, this list of conditions and the following disclaimer in the
13 *    documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 *    derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29package org.jf.baksmali.Adaptors.EncodedValue;
30
31import org.jf.baksmali.Adaptors.ReferenceFormatter;
32import org.jf.util.IndentingWriter;
33import org.jf.baksmali.Renderers.*;
34import org.jf.dexlib.EncodedValue.*;
35
36import java.io.IOException;
37
38public abstract class EncodedValueAdaptor {
39    public static void writeTo(IndentingWriter writer, EncodedValue encodedValue) throws IOException {
40        switch (encodedValue.getValueType()) {
41            case VALUE_ANNOTATION:
42                AnnotationEncodedValueAdaptor.writeTo(writer, (AnnotationEncodedValue)encodedValue);
43                return;
44            case VALUE_ARRAY:
45                ArrayEncodedValueAdaptor.writeTo(writer, (ArrayEncodedValue)encodedValue);
46                return;
47            case VALUE_BOOLEAN:
48                BooleanRenderer.writeTo(writer, ((BooleanEncodedValue)encodedValue).value);
49                return;
50            case VALUE_BYTE:
51                ByteRenderer.writeTo(writer, ((ByteEncodedValue)encodedValue).value);
52                return;
53            case VALUE_CHAR:
54                CharRenderer.writeTo(writer, ((CharEncodedValue)encodedValue).value);
55                return;
56            case VALUE_DOUBLE:
57                DoubleRenderer.writeTo(writer, ((DoubleEncodedValue)encodedValue).value);
58                return;
59            case VALUE_ENUM:
60                EnumEncodedValueAdaptor.writeTo(writer, ((EnumEncodedValue)encodedValue).value);
61                return;
62            case VALUE_FIELD:
63                ReferenceFormatter.writeFieldReference(writer, ((FieldEncodedValue)encodedValue).value);
64                return;
65            case VALUE_FLOAT:
66                FloatRenderer.writeTo(writer, ((FloatEncodedValue)encodedValue).value);
67                return;
68            case VALUE_INT:
69                IntegerRenderer.writeTo(writer, ((IntEncodedValue)encodedValue).value);
70                return;
71            case VALUE_LONG:
72                LongRenderer.writeTo(writer, ((LongEncodedValue)encodedValue).value);
73                return;
74            case VALUE_METHOD:
75                ReferenceFormatter.writeMethodReference(writer, ((MethodEncodedValue)encodedValue).value);
76                return;
77            case VALUE_NULL:
78                writer.write("null");
79                return;
80            case VALUE_SHORT:
81                ShortRenderer.writeTo(writer, ((ShortEncodedValue)encodedValue).value);
82                return;
83            case VALUE_STRING:
84                ReferenceFormatter.writeStringReference(writer, ((StringEncodedValue)encodedValue).value);
85                return;
86            case VALUE_TYPE:
87                ReferenceFormatter.writeTypeReference(writer, ((TypeEncodedValue)encodedValue).value);
88        }
89    }
90}
91