|
8 | 8 | package org.jd.core.v1.model.javasyntax.type; |
9 | 9 |
|
10 | 10 | public class ObjectType implements Type { |
11 | | - public static final ObjectType TYPE_BOOLEAN = new ObjectType("java/lang/Boolean", "java.lang.Boolean", "Boolean"); |
12 | | - public static final ObjectType TYPE_BYTE = new ObjectType("java/lang/Byte", "java.lang.Byte", "Byte"); |
13 | | - public static final ObjectType TYPE_CHARACTER = new ObjectType("java/lang/Character", "java.lang.Character", "Character"); |
14 | | - public static final ObjectType TYPE_CLASS = new ObjectType("java/lang/Class", "java.lang.Class", "Class"); |
15 | | - public static final ObjectType TYPE_DOUBLE = new ObjectType("java/lang/Double", "java.lang.Double", "Double"); |
16 | | - public static final ObjectType TYPE_FLOAT = new ObjectType("java/lang/Float", "java.lang.Float", "Float"); |
17 | | - public static final ObjectType TYPE_INTEGER = new ObjectType("java/lang/Integer", "java.lang.Integer", "Integer"); |
18 | | - public static final ObjectType TYPE_LONG = new ObjectType("java/lang/Long", "java.lang.Long", "Long"); |
19 | | - public static final ObjectType TYPE_MATH = new ObjectType("java/lang/Math", "java.lang.Math", "Math"); |
20 | | - public static final ObjectType TYPE_OBJECT = new ObjectType("java/lang/Object", "java.lang.Object", "Object"); |
21 | | - public static final ObjectType TYPE_SHORT = new ObjectType("java/lang/Short", "java.lang.Short", "Short"); |
22 | | - public static final ObjectType TYPE_STRING = new ObjectType("java/lang/String", "java.lang.String", "String"); |
23 | | - public static final ObjectType TYPE_THROWABLE = new ObjectType("java/lang/Throwable", "java.lang.Throwable", "Throwable"); |
| 11 | + public static final ObjectType TYPE_BOOLEAN = new ObjectType("java/lang/Boolean", "java.lang.Boolean", "Boolean"); |
| 12 | + public static final ObjectType TYPE_BYTE = new ObjectType("java/lang/Byte", "java.lang.Byte", "Byte"); |
| 13 | + public static final ObjectType TYPE_CHARACTER = new ObjectType("java/lang/Character", "java.lang.Character", "Character"); |
| 14 | + public static final ObjectType TYPE_CLASS = new ObjectType("java/lang/Class", "java.lang.Class", "Class"); |
| 15 | + public static final ObjectType TYPE_DOUBLE = new ObjectType("java/lang/Double", "java.lang.Double", "Double"); |
| 16 | + public static final ObjectType TYPE_EXCEPTION = new ObjectType("java/lang/Exception", "java.lang.Exception", "Exception"); |
| 17 | + public static final ObjectType TYPE_FLOAT = new ObjectType("java/lang/Float", "java.lang.Float", "Float"); |
| 18 | + public static final ObjectType TYPE_INTEGER = new ObjectType("java/lang/Integer", "java.lang.Integer", "Integer"); |
| 19 | + public static final ObjectType TYPE_LONG = new ObjectType("java/lang/Long", "java.lang.Long", "Long"); |
| 20 | + public static final ObjectType TYPE_MATH = new ObjectType("java/lang/Math", "java.lang.Math", "Math"); |
| 21 | + public static final ObjectType TYPE_OBJECT = new ObjectType("java/lang/Object", "java.lang.Object", "Object"); |
| 22 | + public static final ObjectType TYPE_RUNTIME_EXCEPTION = new ObjectType("java/lang/RuntimeException", "java.lang.RuntimeException", "RuntimeException"); |
| 23 | + public static final ObjectType TYPE_SHORT = new ObjectType("java/lang/Short", "java.lang.Short", "Short"); |
| 24 | + public static final ObjectType TYPE_STRING = new ObjectType("java/lang/String", "java.lang.String", "String"); |
| 25 | + public static final ObjectType TYPE_STRING_BUFFER = new ObjectType("java/lang/StringBuffer", "java.lang.StringBuffer", "StringBuffer"); |
| 26 | + public static final ObjectType TYPE_STRING_BUILDER = new ObjectType("java/lang/StringBuilder", "java.lang.StringBuilder", "StringBuilder"); |
| 27 | + public static final ObjectType TYPE_SYSTEM = new ObjectType("java/lang/System", "java.lang.System", "System"); |
| 28 | + public static final ObjectType TYPE_THREAD = new ObjectType("java/lang/Thread", "java.lang.Thread", "Thread"); |
| 29 | + public static final ObjectType TYPE_THROWABLE = new ObjectType("java/lang/Throwable", "java.lang.Throwable", "Throwable"); |
| 30 | + |
| 31 | + public static final ObjectType TYPE_PRIMITIVE_BOOLEAN = new ObjectType("Z"); |
| 32 | + public static final ObjectType TYPE_PRIMITIVE_BYTE = new ObjectType("B"); |
| 33 | + public static final ObjectType TYPE_PRIMITIVE_CHAR = new ObjectType("C"); |
| 34 | + public static final ObjectType TYPE_PRIMITIVE_DOUBLE = new ObjectType("D"); |
| 35 | + public static final ObjectType TYPE_PRIMITIVE_FLOAT = new ObjectType("F"); |
| 36 | + public static final ObjectType TYPE_PRIMITIVE_INT = new ObjectType("I"); |
| 37 | + public static final ObjectType TYPE_PRIMITIVE_LONG = new ObjectType("J"); |
| 38 | + public static final ObjectType TYPE_PRIMITIVE_SHORT = new ObjectType("S"); |
| 39 | + public static final ObjectType TYPE_PRIMITIVE_VOID = new ObjectType("V"); |
24 | 40 |
|
25 | 41 | public static final ObjectType TYPE_UNDEFINED_OBJECT = new ObjectType("java/lang/Object", "java.lang.Object", "Object") { |
26 | 42 | @Override public String toString() { return "UndefinedObjectType"; } |
@@ -52,22 +68,32 @@ public ObjectType(String internalName, String qualifiedName, String name, BaseTy |
52 | 68 | this.name = name; |
53 | 69 | this.typeArguments = typeArguments; |
54 | 70 | this.dimension = dimension; |
| 71 | + this.descriptor = createDescriptor("L" + internalName + ';', dimension); |
55 | 72 |
|
56 | 73 | assert (internalName != null) && !internalName.endsWith(";"); |
| 74 | + } |
| 75 | + |
| 76 | + public ObjectType(String primitiveDescriptor) { |
| 77 | + this(primitiveDescriptor, 0); |
| 78 | + } |
| 79 | + |
| 80 | + public ObjectType(String primitiveDescriptor, int dimension) { |
| 81 | + this.internalName = primitiveDescriptor; |
| 82 | + this.qualifiedName = this.name = PrimitiveType.getPrimitiveType(primitiveDescriptor.charAt(0)).getName(); |
| 83 | + this.dimension = dimension; |
| 84 | + this.descriptor = createDescriptor(primitiveDescriptor, dimension); |
| 85 | + } |
57 | 86 |
|
| 87 | + protected static String createDescriptor(String descriptor, int dimension) { |
58 | 88 | switch (dimension) { |
59 | 89 | case 0: |
60 | | - this.descriptor = "L" + internalName + ';'; |
61 | | - break; |
| 90 | + return descriptor; |
62 | 91 | case 1: |
63 | | - this.descriptor = "[L" + internalName + ';'; |
64 | | - break; |
| 92 | + return "[" + descriptor; |
65 | 93 | case 2: |
66 | | - this.descriptor = "[[L" + internalName + ';'; |
67 | | - break; |
| 94 | + return "[[" + descriptor; |
68 | 95 | default: |
69 | | - this.descriptor = new String(new char[dimension]).replaceAll("\0", "[") + 'L' + internalName + ';'; |
70 | | - break; |
| 96 | + return new String(new char[dimension]).replaceAll("\0", "[") + descriptor; |
71 | 97 | } |
72 | 98 | } |
73 | 99 |
|
@@ -109,11 +135,21 @@ public int getDimension() { |
109 | 135 |
|
110 | 136 | @Override |
111 | 137 | public Type createType(int dimension) { |
112 | | - assert dimension >= 0; |
113 | | - if (this.dimension == dimension) |
| 138 | + assert dimension >= 0 : "ObjectType.createType(dim) : create type with zero or negative dimension"; |
| 139 | + |
| 140 | + if (this.dimension == dimension) { |
114 | 141 | return this; |
115 | | - else |
| 142 | + } else if (descriptor.charAt(descriptor.length()-1) != ';') { |
| 143 | + // Array of primitive types |
| 144 | + if (dimension == 0) { |
| 145 | + return PrimitiveType.getPrimitiveType(descriptor.charAt(this.dimension)); |
| 146 | + } else { |
| 147 | + return new ObjectType(internalName, dimension); |
| 148 | + } |
| 149 | + } else { |
| 150 | + // Object type or array of object types |
116 | 151 | return new ObjectType(internalName, qualifiedName, name, typeArguments, dimension); |
| 152 | + } |
117 | 153 | } |
118 | 154 |
|
119 | 155 | public ObjectType createType(BaseTypeArgument typeArguments) { |
|
0 commit comments