SpecialFormat.java revision 579d7739c53a2707ad711a2d2cae46d7d782f061
1/*
2 * Copyright (C) 2007 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.dx.dex.code.form;
18
19import com.android.dx.dex.code.DalvInsn;
20import com.android.dx.dex.code.InsnFormat;
21import com.android.dx.util.AnnotatedOutput;
22
23/**
24 * Instruction format for nonstandard format instructions, which aren't
25 * generally real instructions but do end up appearing in instruction
26 * lists. Most of the overridden methods on this class end up throwing
27 * exceptions, as code should know (implicitly or explicitly) to avoid
28 * using this class. The one exception is {@link #isCompatible}, which
29 * always returns {@code true}.
30 */
31public final class SpecialFormat extends InsnFormat {
32    /** {@code non-null;} unique instance of this class */
33    public static final InsnFormat THE_ONE = new SpecialFormat();
34
35    /**
36     * Constructs an instance. This class is not publicly
37     * instantiable. Use {@link #THE_ONE}.
38     */
39    private SpecialFormat() {
40        // This space intentionally left blank.
41    }
42
43    /** {@inheritDoc} */
44    @Override
45    public String insnArgString(DalvInsn insn) {
46        throw new RuntimeException("unsupported");
47    }
48
49    /** {@inheritDoc} */
50    @Override
51    public String insnCommentString(DalvInsn insn, boolean noteIndices) {
52        throw new RuntimeException("unsupported");
53    }
54
55    /** {@inheritDoc} */
56    @Override
57    public int codeSize() {
58        throw new RuntimeException("unsupported");
59    }
60
61    /** {@inheritDoc} */
62    @Override
63    public boolean isCompatible(DalvInsn insn) {
64        return true;
65    }
66
67    /** {@inheritDoc} */
68    @Override
69    public void writeTo(AnnotatedOutput out, DalvInsn insn) {
70        throw new RuntimeException("unsupported");
71    }
72}
73