mirror of
https://github.com/corda/corda.git
synced 2025-01-06 05:04:20 +00:00
Fixing some issues with runtime annotations within avian.
We were not properly converting dots to slashes internally for package names and we did not properly handle Method.getAnnotations and Method.getAnnotation(Class<T>) on methods without any annotations. Added some tests to cover these cases.
This commit is contained in:
parent
0addd8c814
commit
a5c9dd6f24
@ -24,4 +24,8 @@ public class VMMethod {
|
|||||||
public MethodAddendum addendum;
|
public MethodAddendum addendum;
|
||||||
public VMClass class_;
|
public VMClass class_;
|
||||||
public Object code;
|
public Object code;
|
||||||
|
|
||||||
|
public boolean hasAnnotations() {
|
||||||
|
return addendum != null && addendum.annotationTable != null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ public class Method<T> extends AccessibleObject implements Member {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public <T extends Annotation> T getAnnotation(Class<T> class_) {
|
public <T extends Annotation> T getAnnotation(Class<T> class_) {
|
||||||
if (vmMethod.addendum.annotationTable != null) {
|
if (vmMethod.hasAnnotations()) {
|
||||||
Object[] table = (Object[]) vmMethod.addendum.annotationTable;
|
Object[] table = (Object[]) vmMethod.addendum.annotationTable;
|
||||||
for (int i = 0; i < table.length; ++i) {
|
for (int i = 0; i < table.length; ++i) {
|
||||||
Object[] a = (Object[]) table[i];
|
Object[] a = (Object[]) table[i];
|
||||||
@ -183,7 +183,7 @@ public class Method<T> extends AccessibleObject implements Member {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Annotation[] getAnnotations() {
|
public Annotation[] getAnnotations() {
|
||||||
if (vmMethod.addendum.annotationTable != null) {
|
if (vmMethod.hasAnnotations()) {
|
||||||
Object[] table = (Object[]) vmMethod.addendum.annotationTable;
|
Object[] table = (Object[]) vmMethod.addendum.annotationTable;
|
||||||
Annotation[] array = new Annotation[table.length];
|
Annotation[] array = new Annotation[table.length];
|
||||||
for (int i = 0; i < table.length; ++i) {
|
for (int i = 0; i < table.length; ++i) {
|
||||||
|
@ -358,7 +358,7 @@ public class Proxy {
|
|||||||
int[] interfaceIndexes = new int[interfaces.length];
|
int[] interfaceIndexes = new int[interfaces.length];
|
||||||
for (int i = 0; i < interfaces.length; ++i) {
|
for (int i = 0; i < interfaces.length; ++i) {
|
||||||
interfaceIndexes[i] = ConstantPool.addClass
|
interfaceIndexes[i] = ConstantPool.addClass
|
||||||
(pool, interfaces[i].getName());
|
(pool, interfaces[i].getName().replace('.', '/'));
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String,avian.VMMethod> virtualMap = new HashMap();
|
Map<String,avian.VMMethod> virtualMap = new HashMap();
|
||||||
|
5
makefile
5
makefile
@ -685,7 +685,10 @@ vm-classes = \
|
|||||||
avian/*.class \
|
avian/*.class \
|
||||||
avian/resource/*.class
|
avian/resource/*.class
|
||||||
|
|
||||||
|
test-support-sources = $(shell find $(test)/avian/ -name '*.java')
|
||||||
test-sources = $(wildcard $(test)/*.java)
|
test-sources = $(wildcard $(test)/*.java)
|
||||||
|
test-sources += $(test-support-sources)
|
||||||
|
test-support-classes = $(call java-classes, $(test-support-sources),$(test),$(test-build))
|
||||||
test-classes = $(call java-classes,$(test-sources),$(test),$(test-build))
|
test-classes = $(call java-classes,$(test-sources),$(test),$(test-build))
|
||||||
test-dep = $(test-build).dep
|
test-dep = $(test-build).dep
|
||||||
|
|
||||||
@ -765,7 +768,7 @@ vg: build
|
|||||||
test: build
|
test: build
|
||||||
$(library-path) /bin/sh $(test)/test.sh 2>/dev/null \
|
$(library-path) /bin/sh $(test)/test.sh 2>/dev/null \
|
||||||
$(test-executable) $(mode) "$(test-flags)" \
|
$(test-executable) $(mode) "$(test-flags)" \
|
||||||
$(call class-names,$(test-build),$(test-classes)) \
|
$(call class-names,$(test-build),$(filter-out $(test-support-classes), $(test-classes))) \
|
||||||
$(continuation-tests) $(tail-tests)
|
$(continuation-tests) $(tail-tests)
|
||||||
|
|
||||||
.PHONY: tarball
|
.PHONY: tarball
|
||||||
|
@ -1,7 +1,10 @@
|
|||||||
import java.lang.annotation.Retention;
|
|
||||||
import java.lang.annotation.RetentionPolicy;
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
import avian.testing.annotations.Color;
|
||||||
|
import avian.testing.annotations.Test;
|
||||||
|
import avian.testing.annotations.TestEnum;
|
||||||
|
import avian.testing.annotations.TestInteger;
|
||||||
|
|
||||||
public class Annotations {
|
public class Annotations {
|
||||||
private static void expect(boolean v) {
|
private static void expect(boolean v) {
|
||||||
if (! v) throw new RuntimeException();
|
if (! v) throw new RuntimeException();
|
||||||
@ -18,6 +21,12 @@ public class Annotations {
|
|||||||
.equals(Color.Red));
|
.equals(Color.Red));
|
||||||
|
|
||||||
expect(((TestInteger) m.getAnnotation(TestInteger.class)).value() == 42);
|
expect(((TestInteger) m.getAnnotation(TestInteger.class)).value() == 42);
|
||||||
|
|
||||||
|
expect(m.getAnnotations().length == 3);
|
||||||
|
|
||||||
|
Method noAnno = Annotations.class.getMethod("noAnnotation");
|
||||||
|
expect(noAnno.getAnnotation(Test.class) == null);
|
||||||
|
expect(noAnno.getAnnotations().length == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test("couscous")
|
@Test("couscous")
|
||||||
@ -27,23 +36,7 @@ public class Annotations {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
public static void noAnnotation() {
|
||||||
private @interface Test {
|
|
||||||
public String value();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
private @interface TestEnum {
|
|
||||||
public Color value();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Retention(RetentionPolicy.RUNTIME)
|
|
||||||
private @interface TestInteger {
|
|
||||||
public int value();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static enum Color {
|
|
||||||
Red, Yellow, Blue
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
5
test/avian/testing/annotations/Color.java
Normal file
5
test/avian/testing/annotations/Color.java
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package avian.testing.annotations;
|
||||||
|
|
||||||
|
public enum Color {
|
||||||
|
Red, Yellow, Blue
|
||||||
|
}
|
9
test/avian/testing/annotations/Test.java
Normal file
9
test/avian/testing/annotations/Test.java
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
package avian.testing.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Test {
|
||||||
|
public String value();
|
||||||
|
}
|
8
test/avian/testing/annotations/TestEnum.java
Normal file
8
test/avian/testing/annotations/TestEnum.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package avian.testing.annotations;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface TestEnum {
|
||||||
|
public Color value();
|
||||||
|
}
|
8
test/avian/testing/annotations/TestInteger.java
Normal file
8
test/avian/testing/annotations/TestInteger.java
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
package avian.testing.annotations;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface TestInteger {
|
||||||
|
public int value();
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user