blob: cf4100120f4516e73cef93cf38b8d6b415808eaf (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*******************************************************************************
* Copyright (c) 2014 Jeff Martin.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Public License v3.0
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/gpl.html
*
* Contributors:
* Jeff Martin - initial API and implementation
******************************************************************************/
package cuchaz.enigma.mapping;
import java.io.Serializable;
public class ClassEntry implements Entry, Serializable {
private static final long serialVersionUID = 4235460580973955811L;
private String m_name;
public ClassEntry(String className) {
if (className == null) {
throw new IllegalArgumentException("Class name cannot be null!");
}
if (className.indexOf('.') >= 0) {
throw new IllegalArgumentException("Class name must be in JVM format. ie, path/to/package/class$inner : " + className);
}
m_name = className;
if (isInnerClass() && getInnerClassName().indexOf('/') >= 0) {
throw new IllegalArgumentException("Inner class must not have a package: " + className);
}
}
public ClassEntry(ClassEntry other) {
m_name = other.m_name;
}
@Override
public String getName() {
return m_name;
}
@Override
public String getClassName() {
return m_name;
}
@Override
public ClassEntry getClassEntry() {
return this;
}
@Override
public ClassEntry cloneToNewClass(ClassEntry classEntry) {
return classEntry;
}
@Override
public int hashCode() {
return m_name.hashCode();
}
@Override
public boolean equals(Object other) {
if (other instanceof ClassEntry) {
return equals((ClassEntry)other);
}
return false;
}
public boolean equals(ClassEntry other) {
return m_name.equals(other.m_name);
}
@Override
public String toString() {
return m_name;
}
public boolean isInnerClass() {
return m_name.lastIndexOf('$') >= 0;
}
public String getOuterClassName() {
if (isInnerClass()) {
return m_name.substring(0, m_name.lastIndexOf('$'));
}
return m_name;
}
public String getInnerClassName() {
if (!isInnerClass()) {
throw new Error("This is not an inner class!");
}
return m_name.substring(m_name.lastIndexOf('$') + 1);
}
public ClassEntry getOuterClassEntry() {
return new ClassEntry(getOuterClassName());
}
public boolean isInDefaultPackage() {
return m_name.indexOf('/') < 0;
}
public String getPackageName() {
int pos = m_name.lastIndexOf('/');
if (pos > 0) {
return m_name.substring(0, pos);
}
return null;
}
public String getSimpleName() {
int pos = m_name.lastIndexOf('/');
if (pos > 0) {
return m_name.substring(pos + 1);
}
return m_name;
}
}
|