# HG changeset patch # User Roland Schatz # Date 1462533680 -7200 # Node ID ae27c683c12882fb019bc4d525eea4ee96c39188 # Parent 3f70efb8f473c860f9908f5cd06719d7948ac60d Make ResolvedJava* types extend AnnotatedElement. Contributed-by: Vojin Jovanovic diff -r 3f70efb8f473 -r ae27c683c128 jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java --- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java Wed May 04 12:06:51 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaFieldImpl.java Fri May 06 13:21:20 2016 +0200 @@ -210,6 +210,15 @@ } @Override + public Annotation[] getDeclaredAnnotations() { + Field javaField = toJava(); + if (javaField != null) { + return javaField.getDeclaredAnnotations(); + } + return new Annotation[0]; + } + + @Override public T getAnnotation(Class annotationClass) { Field javaField = toJava(); if (javaField != null) { diff -r 3f70efb8f473 -r ae27c683c128 jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java --- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java Wed May 04 12:06:51 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedJavaMethodImpl.java Fri May 06 13:21:20 2016 +0200 @@ -477,6 +477,12 @@ } @Override + public Annotation[] getDeclaredAnnotations() { + Executable javaMethod = toJava(); + return javaMethod == null ? null : javaMethod.getDeclaredAnnotations(); + } + + @Override public T getAnnotation(Class annotationClass) { Executable javaMethod = toJava(); return javaMethod == null ? null : javaMethod.getAnnotation(annotationClass); diff -r 3f70efb8f473 -r ae27c683c128 jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java --- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java Wed May 04 12:06:51 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedObjectTypeImpl.java Fri May 06 13:21:20 2016 +0200 @@ -768,6 +768,11 @@ } @Override + public Annotation[] getDeclaredAnnotations() { + return mirror().getDeclaredAnnotations(); + } + + @Override public T getAnnotation(Class annotationClass) { return mirror().getAnnotation(annotationClass); } diff -r 3f70efb8f473 -r ae27c683c128 jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java --- a/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java Wed May 04 12:06:51 2016 +0200 +++ b/jvmci/jdk.vm.ci.hotspot/src/jdk/vm/ci/hotspot/HotSpotResolvedPrimitiveType.java Fri May 06 13:21:20 2016 +0200 @@ -199,6 +199,11 @@ } @Override + public Annotation[] getDeclaredAnnotations() { + return new Annotation[0]; + } + + @Override public T getAnnotation(Class annotationClass) { return null; } diff -r 3f70efb8f473 -r ae27c683c128 jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaField.java --- a/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaField.java Wed May 04 12:06:51 2016 +0200 +++ b/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaField.java Fri May 06 13:21:20 2016 +0200 @@ -22,14 +22,14 @@ */ package jdk.vm.ci.meta; -import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Modifier; /** * Represents a reference to a resolved Java field. Fields, like methods and types, are resolved * through {@link ConstantPool constant pools}. */ -public interface ResolvedJavaField extends JavaField, ModifiersProvider { +public interface ResolvedJavaField extends JavaField, ModifiersProvider, AnnotatedElement { /** * {@inheritDoc} @@ -61,22 +61,6 @@ ResolvedJavaType getDeclaringClass(); /** - * Returns all annotations of this field. If no annotations are present, an array of length 0 is - * returned. - */ - Annotation[] getAnnotations(); - - /** - * Returns the annotation for the specified type of this field, if such an annotation is - * present. - * - * @param annotationClass the Class object corresponding to the annotation type - * @return this element's annotation for the specified annotation type if present on this field, - * else {@code null} - */ - T getAnnotation(Class annotationClass); - - /** * Returns an object representing the unique location identity of this resolved Java field. * * @return the location identity of the field diff -r 3f70efb8f473 -r ae27c683c128 jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaMethod.java --- a/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaMethod.java Wed May 04 12:06:51 2016 +0200 +++ b/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaMethod.java Fri May 06 13:21:20 2016 +0200 @@ -24,6 +24,7 @@ import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandle; +import java.lang.reflect.AnnotatedElement; import java.lang.reflect.Array; import java.lang.reflect.Method; import java.lang.reflect.Modifier; @@ -33,7 +34,7 @@ * Represents a resolved Java method. Methods, like fields and types, are resolved through * {@link ConstantPool constant pools}. */ -public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersProvider { +public interface ResolvedJavaMethod extends JavaMethod, InvokeTarget, ModifiersProvider, AnnotatedElement { /** * Returns the bytecode of this method, if the method has code. The returned byte array does not @@ -189,22 +190,6 @@ ConstantPool getConstantPool(); /** - * Returns all annotations of this method. If no annotations are present, an array of length 0 - * is returned. - */ - Annotation[] getAnnotations(); - - /** - * Returns the annotation for the specified type of this method, if such an annotation is - * present. - * - * @param annotationClass the Class object corresponding to the annotation type - * @return this element's annotation for the specified annotation type if present on this - * method, else {@code null} - */ - T getAnnotation(Class annotationClass); - - /** * Returns an array of arrays that represent the annotations on the formal parameters, in * declaration order, of this method. * diff -r 3f70efb8f473 -r ae27c683c128 jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaType.java --- a/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaType.java Wed May 04 12:06:51 2016 +0200 +++ b/jvmci/jdk.vm.ci.meta/src/jdk/vm/ci/meta/ResolvedJavaType.java Fri May 06 13:21:20 2016 +0200 @@ -22,7 +22,7 @@ */ package jdk.vm.ci.meta; -import java.lang.annotation.Annotation; +import java.lang.reflect.AnnotatedElement; import jdk.vm.ci.meta.Assumptions.AssumptionResult; @@ -31,7 +31,7 @@ * thereof. Types, like fields and methods, are resolved through {@link ConstantPool constant pools} * . */ -public interface ResolvedJavaType extends JavaType, ModifiersProvider { +public interface ResolvedJavaType extends JavaType, ModifiersProvider, AnnotatedElement { /** * Checks whether this type has a finalizer method. * @@ -276,22 +276,6 @@ ResolvedJavaField[] getStaticFields(); /** - * Returns all annotations of this class. If no annotations are present, an array of length 0 is - * returned. - */ - Annotation[] getAnnotations(); - - /** - * Returns the annotation for the specified type of this class, if such an annotation is - * present. - * - * @param annotationClass the Class object corresponding to the annotation type - * @return this element's annotation for the specified annotation type if present on this class, - * else {@code null} - */ - T getAnnotation(Class annotationClass); - - /** * Returns the instance field of this class (or one of its super classes) at the given offset, * or {@code null} if there is no such field. *