mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
parent
4ef231c7fa
commit
e46f204b4e
|
@ -257,6 +257,8 @@ public class AnnotationDependencyListener extends AbstractDependencyListener {
|
||||||
switch (value.getType()) {
|
switch (value.getType()) {
|
||||||
case AnnotationValue.BOOLEAN:
|
case AnnotationValue.BOOLEAN:
|
||||||
return pe.constant(value.getBoolean() ? 1 : 0);
|
return pe.constant(value.getBoolean() ? 1 : 0);
|
||||||
|
case AnnotationValue.CHAR:
|
||||||
|
return pe.constant(value.getChar());
|
||||||
case AnnotationValue.BYTE:
|
case AnnotationValue.BYTE:
|
||||||
return pe.constant(value.getByte());
|
return pe.constant(value.getByte());
|
||||||
case AnnotationValue.SHORT:
|
case AnnotationValue.SHORT:
|
||||||
|
|
|
@ -93,6 +93,9 @@ public class AnnotationIO {
|
||||||
case AnnotationValue.BOOLEAN:
|
case AnnotationValue.BOOLEAN:
|
||||||
output.writeUnsigned(value.getBoolean() ? 1 : 0);
|
output.writeUnsigned(value.getBoolean() ? 1 : 0);
|
||||||
break;
|
break;
|
||||||
|
case AnnotationValue.CHAR:
|
||||||
|
output.writeSigned(value.getChar());
|
||||||
|
break;
|
||||||
case AnnotationValue.BYTE:
|
case AnnotationValue.BYTE:
|
||||||
output.writeSigned(value.getByte());
|
output.writeSigned(value.getByte());
|
||||||
break;
|
break;
|
||||||
|
@ -139,6 +142,8 @@ public class AnnotationIO {
|
||||||
return new AnnotationValue(readAnnotation(input));
|
return new AnnotationValue(readAnnotation(input));
|
||||||
case AnnotationValue.BOOLEAN:
|
case AnnotationValue.BOOLEAN:
|
||||||
return new AnnotationValue(input.readUnsigned() != 0);
|
return new AnnotationValue(input.readUnsigned() != 0);
|
||||||
|
case AnnotationValue.CHAR:
|
||||||
|
return new AnnotationValue((char) input.readUnsigned());
|
||||||
case AnnotationValue.BYTE:
|
case AnnotationValue.BYTE:
|
||||||
return new AnnotationValue((byte) input.readSigned());
|
return new AnnotationValue((byte) input.readSigned());
|
||||||
case AnnotationValue.CLASS:
|
case AnnotationValue.CLASS:
|
||||||
|
|
|
@ -31,6 +31,7 @@ public class AnnotationValue {
|
||||||
public static final byte LIST = 9;
|
public static final byte LIST = 9;
|
||||||
public static final byte ENUM = 10;
|
public static final byte ENUM = 10;
|
||||||
public static final byte ANNOTATION = 11;
|
public static final byte ANNOTATION = 11;
|
||||||
|
public static final byte CHAR = 12;
|
||||||
private byte type;
|
private byte type;
|
||||||
private Object value;
|
private Object value;
|
||||||
|
|
||||||
|
@ -44,6 +45,11 @@ public class AnnotationValue {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AnnotationValue(char value) {
|
||||||
|
this.type = CHAR;
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
public AnnotationValue(short value) {
|
public AnnotationValue(short value) {
|
||||||
this.type = SHORT;
|
this.type = SHORT;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
|
@ -101,6 +107,13 @@ public class AnnotationValue {
|
||||||
return (Boolean) value;
|
return (Boolean) value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public char getChar() {
|
||||||
|
if (type != CHAR) {
|
||||||
|
throw new IllegalStateException("There is no char value");
|
||||||
|
}
|
||||||
|
return (Character) value;
|
||||||
|
}
|
||||||
|
|
||||||
public byte getByte() {
|
public byte getByte() {
|
||||||
if (type != BYTE) {
|
if (type != BYTE) {
|
||||||
throw new IllegalStateException("There is no byte value");
|
throw new IllegalStateException("There is no byte value");
|
||||||
|
|
|
@ -538,6 +538,8 @@ public class Parser {
|
||||||
return new AnnotationValue((String) value);
|
return new AnnotationValue((String) value);
|
||||||
} else if (value instanceof Boolean) {
|
} else if (value instanceof Boolean) {
|
||||||
return new AnnotationValue((Boolean) value);
|
return new AnnotationValue((Boolean) value);
|
||||||
|
} else if (value instanceof Character) {
|
||||||
|
return new AnnotationValue((Character) value);
|
||||||
} else if (value instanceof Byte) {
|
} else if (value instanceof Byte) {
|
||||||
return new AnnotationValue((Byte) value);
|
return new AnnotationValue((Byte) value);
|
||||||
} else if (value instanceof Short) {
|
} else if (value instanceof Short) {
|
||||||
|
|
|
@ -87,7 +87,7 @@ class AnnotationProxy implements InvocationHandler {
|
||||||
case DOUBLE:
|
case DOUBLE:
|
||||||
return value.getDouble();
|
return value.getDouble();
|
||||||
case CHARACTER:
|
case CHARACTER:
|
||||||
break;
|
return value.getChar();
|
||||||
}
|
}
|
||||||
} else if (type.isObject(String.class)) {
|
} else if (type.isObject(String.class)) {
|
||||||
return value.getString();
|
return value.getString();
|
||||||
|
|
|
@ -224,9 +224,9 @@ public class MetaprogrammingTest {
|
||||||
@Test
|
@Test
|
||||||
public void annotationsWork() {
|
public void annotationsWork() {
|
||||||
assertEquals(""
|
assertEquals(""
|
||||||
+ "foo:23:Object\n"
|
+ "foo:23:Object:?\n"
|
||||||
+ "foo=!:42:String:int\n"
|
+ "foo=!:42:String:int:?\n"
|
||||||
+ "f=!:23\n",
|
+ "f=!:23:^\n",
|
||||||
readAnnotations(WithAnnotations.class, new WithAnnotations()));
|
readAnnotations(WithAnnotations.class, new WithAnnotations()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,6 +264,7 @@ public class MetaprogrammingTest {
|
||||||
for (Class<?> cls : annot.c()) {
|
for (Class<?> cls : annot.c()) {
|
||||||
sb.append(':').append(cls.getSimpleName());
|
sb.append(':').append(cls.getSimpleName());
|
||||||
}
|
}
|
||||||
|
sb.append(':').append(annot.d());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,7 +535,7 @@ public class MetaprogrammingTest {
|
||||||
@TestAnnotation(a = "foo", c = Object.class)
|
@TestAnnotation(a = "foo", c = Object.class)
|
||||||
@MetaprogrammingClass
|
@MetaprogrammingClass
|
||||||
static class WithAnnotations {
|
static class WithAnnotations {
|
||||||
@TestAnnotation(c = {})
|
@TestAnnotation(c = {}, d = '^')
|
||||||
int f;
|
int f;
|
||||||
|
|
||||||
@TestAnnotation(b = 42, c = { String.class, int.class })
|
@TestAnnotation(b = 42, c = { String.class, int.class })
|
||||||
|
|
|
@ -25,4 +25,6 @@ public @interface TestAnnotation {
|
||||||
int b() default 23;
|
int b() default 23;
|
||||||
|
|
||||||
Class<?>[] c();
|
Class<?>[] c();
|
||||||
|
|
||||||
|
char d() default '?';
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user