|
48 | 48 | @Data |
49 | 49 | public class Type { |
50 | 50 | public static final Type UNKNOWN = new Type("Ljava/lang/Object;", "Tunknown;"); |
| 51 | + public static final Type WILDCARD = new Type("Ljava/lang/Object;", "*"); |
51 | 52 | public static final Type OBJECT = Type.of("java.lang.Object"); |
52 | 53 | public static final Type BOOLEAN = new Type("Z"); |
53 | 54 | public static final Type DOUBLE = new Type("D"); |
54 | 55 | public static final Type FLOAT = new Type("F"); |
55 | 56 | public static final Type INT = new Type("I"); |
56 | 57 | public static final Type LONG = new Type("L"); |
| 58 | + public static final Type CHAR = new Type("C"); |
| 59 | + public static final Type STRING = Type.of("java.lang.String"); |
| 60 | + public static final Type STATIC_META_CLASS = new Type("Ljvm/STATIC;", "Ljvm/STATIC;"); |
| 61 | + public static final Type ANNOTATION = Type.of("java.lang.annotation.Annotation"); |
| 62 | + public static final Type CLAZZ = Type.of("java.lang.Class"); |
| 63 | + public static final Type LAMBDA = Type.of("Ljvm/LAMBDA;"); |
57 | 64 |
|
58 | 65 | /** |
59 | 66 | * A descriptor represents the real part of a type |
@@ -102,6 +109,10 @@ private static void checkSignature(@Nullable String signature) { |
102 | 109 | throw new TransformationException("Invalid signature '" + signature + "'. After generic bracket should either be '>' or ';'"); |
103 | 110 | } |
104 | 111 |
|
| 112 | + public static Type staticMetaclassOf(Type type) { |
| 113 | + return STATIC_META_CLASS.withTypeArgument(type); |
| 114 | + } |
| 115 | + |
105 | 116 | public static Type of(String fullClassName) { |
106 | 117 | // TODO: 23/01/2016 Handle inner classes properly? currently depend on following naming standards |
107 | 118 | // depends on: lower case package names, uppercase first letter of class name |
@@ -311,9 +322,13 @@ public Type withClassName(String name) { |
311 | 322 | return new Type(descriptor, signature); |
312 | 323 | } |
313 | 324 |
|
314 | | - public boolean isAssignableFrom(Type type) { |
315 | | - return descriptor.equals(type.descriptor) || |
316 | | - (isClassType() && getClassName().equals("java.lang.Object") && (type.isArrayType() || type.isClassType())); |
| 325 | + public static boolean isAssignableFrom(Type to, Type from) { |
| 326 | + return to.descriptor.equals(from.descriptor) || |
| 327 | + (to.isClassType() && to.getClassName().equals("java.lang.Object") && (from.isArrayType() || from.isClassType())); |
| 328 | + } |
| 329 | + |
| 330 | + public boolean isStaticMetaClass() { |
| 331 | + return descriptor == STATIC_META_CLASS.descriptor; |
317 | 332 | } |
318 | 333 |
|
319 | 334 | @AllArgsConstructor |
@@ -368,6 +383,22 @@ public static DescriptorType of(char c) { |
368 | 383 | throw new UnknownDescriptorTypeException("Unknnown descriptor type '" + c + "'"); |
369 | 384 | } |
370 | 385 |
|
| 386 | + @Nullable |
| 387 | + public Integer getByteWidth() { |
| 388 | + switch (this) { |
| 389 | + case BYTE: |
| 390 | + return 1; |
| 391 | + case CHAR: |
| 392 | + case SHORT: |
| 393 | + return 2; |
| 394 | + case INT: |
| 395 | + return 4; |
| 396 | + case LONG: |
| 397 | + return 8; |
| 398 | + } |
| 399 | + return null; |
| 400 | + } |
| 401 | + |
371 | 402 | private static class UnknownDescriptorTypeException extends RuntimeException { |
372 | 403 | private static final long serialVersionUID = 0; |
373 | 404 |
|
|
0 commit comments