1/*
2 * [The "BSD licence"]
3 * Copyright (c) 2011 Ben Gruver
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.dexlib.Code;
30
31import java.util.HashMap;
32
33public enum VerificationErrorType {
34    None(0, "no-error"),
35    Generic(1, "generic-error"),
36    NoClass(2, "no-such-class"),
37    NoField(3, "no-such-field"),
38    NoMethod(4, "no-such-method"),
39    AccessClass(5, "illegal-class-access"),
40    AccessField(6, "illegal-field-access"),
41    AccessMethod(7, "illegal-method-access"),
42    ClassChange(8, "class-change-error"),
43    Instantiation(9, "instantiation-error");
44
45    private static HashMap<String, VerificationErrorType> verificationErrorTypesByName;
46
47    static {
48        verificationErrorTypesByName = new HashMap<String, VerificationErrorType>();
49
50        for (VerificationErrorType verificationErrorType: VerificationErrorType.values()) {
51            verificationErrorTypesByName.put(verificationErrorType.getName(), verificationErrorType);
52        }
53    }
54
55    private int value;
56    private String name;
57    private VerificationErrorType(int value, String name) {
58        this.value = value;
59        this.name = name;
60    }
61
62    public int getValue() {
63        return value;
64    }
65
66    public String getName() {
67        return name;
68    }
69
70    public static VerificationErrorType fromString(String validationErrorType) {
71        return verificationErrorTypesByName.get(validationErrorType);
72    }
73
74    public static VerificationErrorType getValidationErrorType(int validationErrorType) {
75        switch (validationErrorType) {
76            case 0:
77                return None;
78            case 1:
79                return Generic;
80            case 2:
81                return NoClass;
82            case 3:
83                return NoField;
84            case 4:
85                return NoMethod;
86            case 5:
87                return AccessClass;
88            case 6:
89                return AccessField;
90            case 7:
91                return AccessMethod;
92            case 8:
93                return ClassChange;
94            case 9:
95                return Instantiation;
96        }
97        return null;
98    }
99}
100