changeset 14073:c92f241d60b6

Merge
author dsimms
date Tue, 28 Jun 2016 11:05:10 +0200
parents 00a9cf4de5b4 14f4659703c8
children 7ad88bd23c4e
files src/java.base/share/classes/valhalla/reflect/runtime/impl/DelegatedMirrorImpl.java
diffstat 15 files changed, 233 insertions(+), 241 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/valhalla/reflect/runtime/ClassLookup.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/ClassLookup.java	Tue Jun 28 11:05:10 2016 +0200
@@ -5,17 +5,17 @@
 public interface ClassLookup extends MemberLookup<ClassMirror> {
 
     @Override
-    ClassLookup withFlags(int mods);
+    ClassLookup withModifiers(int mods);
 
     @Override
     ClassLookup withAccessContext(Lookup lookup);
 
     /**
      * Forces a given inheritance mode on this class lookup.
-     * @param kind inheritance mode
+     * @param mode inheritance mode
      * @return this class lookup
      */
-    ClassLookup withInheritanceKind(InheritanceMode kind);
+    ClassLookup withInheritanceMode(InheritanceMode mode);
 
     /**
      * Restrict lookup to fields with given name.
--- a/src/java.base/share/classes/valhalla/reflect/runtime/ConstructorLookup.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/ConstructorLookup.java	Tue Jun 28 11:05:10 2016 +0200
@@ -5,7 +5,7 @@
 public interface ConstructorLookup extends MemberLookup<ConstructorMirror> {
 
     @Override
-    ConstructorLookup withFlags(int mods);
+    ConstructorLookup withModifiers(int mods);
 
     @Override
     ConstructorLookup withAccessContext(Lookup lookup);
--- a/src/java.base/share/classes/valhalla/reflect/runtime/FieldLookup.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/FieldLookup.java	Tue Jun 28 11:05:10 2016 +0200
@@ -8,17 +8,17 @@
 public interface FieldLookup extends MemberLookup<FieldMirror> {
 
     @Override
-    FieldLookup withFlags(int mods);
+    FieldLookup withModifiers(int mods);
 
     @Override
     FieldLookup withAccessContext(Lookup lookup);
 
     /**
      * Forces a given inheritance mode on this field lookup.
-     * @param kind inheritance mode
+     * @param mode inheritance mode
      * @return this field lookup
      */
-    FieldLookup withInheritanceMode(InheritanceMode kind);
+    FieldLookup withInheritanceMode(InheritanceMode mode);
 
     /**
      * Restrict lookup to fields with given name.
--- a/src/java.base/share/classes/valhalla/reflect/runtime/MemberLookup.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/MemberLookup.java	Tue Jun 28 11:05:10 2016 +0200
@@ -21,11 +21,11 @@
     }
 
     /**
-     * Restrict lookup to members with given flags.
-     * @param mods flag mask
+     * Restrict lookup to members with given modifier flags.
+     * @param mods modifier flags
      * @return this member lookup
      */
-    MemberLookup<M> withFlags(int mods);
+    MemberLookup<M> withModifiers(int mods);
 
     /**
      * Restrict lookup to members that are accessible within a given {@link MethodLookup}.
--- a/src/java.base/share/classes/valhalla/reflect/runtime/MemberMirror.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/MemberMirror.java	Tue Jun 28 11:05:10 2016 +0200
@@ -7,13 +7,19 @@
 public interface MemberMirror {
 
     /**
+     * Retrieves the modifier flags associated with this member mirror.
+     * @return modifier flags (see {@link java.lang.reflect.Modifier})
+     */
+    int getModifiers();
+
+    /**
      * Retrieves the name of the member.
      * @return the name of the member.
      */
      String getName();
 
      /**
-      * Retrieves the enclosing type of this class type.
+      * Retrieves the enclosing type of this member mirror.
       * @return the enclosing type or {@code null} if no such type exists
       */
      ScopeMirror getEnclosingType();
--- a/src/java.base/share/classes/valhalla/reflect/runtime/MethodLookup.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/MethodLookup.java	Tue Jun 28 11:05:10 2016 +0200
@@ -8,17 +8,17 @@
 public interface MethodLookup extends MemberLookup<MethodMirror> {
 
     @Override
-    MethodLookup withFlags(int mods);
+    MethodLookup withModifiers(int mods);
 
     @Override
     MethodLookup withAccessContext(Lookup lookup);
 
     /**
      * Forces a given inheritance mode on this method lookup.
-     * @param kind inheritance mode
+     * @param mode inheritance mode
      * @return this method lookup
      */
-    MethodLookup withInheritanceKind(InheritanceMode kind);
+    MethodLookup withInheritanceMode(InheritanceMode mode);
 
     /**
      * Restrict lookup to methods with given name.
--- a/src/java.base/share/classes/valhalla/reflect/runtime/RuntimeMirror.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/RuntimeMirror.java	Tue Jun 28 11:05:10 2016 +0200
@@ -86,8 +86,9 @@
  * actual type-arguments. Once a specialized mirror is obtained, one can always go back to the unspecialized version - using
  * {@link GenericMirror#asGenericMirror()}:
  *
- * <p>
- * {@code assertEquals(s_mirror.asGenericMirror(), mirror);}
+ * <blockquote><pre>{@code
+ * assertEquals(s_mirror.asGenericMirror(), mirror);
+ * }</pre></blockquote>
  *
  * <p>There are two kinds of generic mirrors: class mirrors and method mirrors (since both classes and methods can be specialized).
  *
@@ -129,15 +130,18 @@
  * <p>Lookups can be either loose or strict, depending on whether the method {@link MemberLookup#findAll()} or
  * {@link MemberLookup#findOrFail()} is used to perform the lookup. A loose lookup looks like the following:
  *
- * <p>
- * {@code mirror.methodLookup().findAll();}
+ * <blockquote><pre>{@code
+ * mirror.methodLookup().findAll();
+ * }</pre></blockquote>
  *
  * <p>Which returns all methods in {@code mirror} (either declared or inherited).
  *
  * <p>If the user knows more about the method to be looked up, a more precise lookup can be attempted:
  * <blockquote><pre>{@code
  * RuntimeMirror[] paramTypes = { ... }
- * mirror.findMethod("foo", paramTypes);
+ * mirror.lookupMethod()
+ *       .withName("foo")
+ *       .withParameterTypes(paramTypes).getOrFail();
  * }</pre></blockquote>
  *
  * <p>Since a method can be generic, sometimes a strict lookup cannot be defined using the above method (because a generic
@@ -146,7 +150,11 @@
  * which can be used as follows:
  *
  * <p>
- * {@code mirror.findGenericMethod("gfoo", tvars -> Arrays.asList(tvars.get(1)));}
+ * <blockquote><pre>{@code
+ * mirror.lookupMethod()
+ *       .withName("gfoo")
+ *       .withParameterTypes(tvars -> Optional.of(Arrays.asList(tvars.get(1)))).getOrFail();
+ * }</pre></blockquote>
  *
  * <p>The above lookup searches for a generic method whose name is 'gfoo' and whose parameter list is the generic method's
  * second type-variable.
--- a/src/java.base/share/classes/valhalla/reflect/runtime/impl/AbstractLookupImpl.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/impl/AbstractLookupImpl.java	Tue Jun 28 11:05:10 2016 +0200
@@ -30,7 +30,7 @@
 import java.util.function.Predicate;
 import java.util.stream.Collectors;
 
-abstract class AbstractLookupImpl<M extends MemberMirror, I extends M, R> implements MemberLookup<M> {
+abstract class AbstractLookupImpl<L extends AbstractLookupImpl<L, M, I, R>, M extends MemberMirror, I extends AbstractMemberMirrorImpl<R, M>, R> implements MemberLookup<M> {
 
     protected final Function<Class<?>, R[]> membersFunc;
     protected Predicate<I> membersFilter;
@@ -49,9 +49,10 @@
 
     @Override
     public List<? extends M> findAll() {
-        return membersClosure(site.clazz).stream()
+        return membersClosure(site.member).stream()
                 .map(memberMapper)
                 .filter(membersFilter)
+                .map(AbstractMemberMirrorImpl<R, M>::asMirror)
                 .collect(Collectors.toList());
     }
 
@@ -65,6 +66,23 @@
         }
     }
 
+    @Override
+    @SuppressWarnings("unchecked")
+    public L withModifiers(int flags) {
+        membersFilter = membersFilter.and(c -> (c.getModifiers() & flags) != 0);
+        return (L)this;
+    }
+
+    @Override
+    @SuppressWarnings("unchecked")
+    public L withAccessContext(Lookup lookup) {
+        membersFilter = membersFilter.and(f -> isMemberAccessible(getDeclaringClass(f),
+                getDeclaringClass(f), f.getModifiers(), lookup.lookupClass(), ALL_ACCESS_MODES));
+        return (L)this;
+    }
+
+    abstract Class<?> getDeclaringClass(I i);
+
     private static final int ALL_ACCESS_MODES = Modifier.PUBLIC |
             Modifier.PRIVATE |
             Modifier.PROTECTED |
@@ -90,7 +108,7 @@
         return members;
     }
 
-    static class FieldLookupImpl extends AbstractLookupImpl<FieldMirror, FieldMirrorImpl, Field> implements FieldLookup {
+    static class FieldLookupImpl extends AbstractLookupImpl<FieldLookupImpl, FieldMirror, FieldMirrorImpl, Field> implements FieldLookup {
 
         FieldLookupImpl(ClassMirrorImpl site) {
             super(Class::getDeclaredFields,
@@ -99,19 +117,6 @@
         }
 
         @Override
-        public FieldLookupImpl withFlags(int flags) {
-            membersFilter = membersFilter.and(f -> (f.member.getModifiers() & flags) != 0);
-            return this;
-        }
-
-        @Override
-        public FieldLookup withAccessContext(Lookup lookup) {
-            membersFilter = membersFilter.and(f -> isMemberAccessible(f.member.getDeclaringClass(),
-                    f.member.getDeclaringClass(), f.member.getModifiers(), lookup.lookupClass(), ALL_ACCESS_MODES));
-            return this;
-        }
-
-        @Override
         public FieldLookup withInheritanceMode(InheritanceMode kind) {
             inheritanceMode = kind;
             return this;
@@ -128,9 +133,14 @@
             membersFilter = membersFilter.and(f -> f.getType().equals(type));
             return this;
         }
+
+        @Override
+        Class<?> getDeclaringClass(FieldMirrorImpl fieldMirror) {
+            return fieldMirror.member.getDeclaringClass();
+        }
     }
     
-    static class ConstructorLookupImpl extends AbstractLookupImpl<ConstructorMirror, ConstructorMirrorImpl, Constructor<?>> implements ConstructorLookup {
+    static class ConstructorLookupImpl extends AbstractLookupImpl<ConstructorLookupImpl, ConstructorMirror, ConstructorMirrorImpl, Constructor<?>> implements ConstructorLookup {
 
         ConstructorLookupImpl(ClassMirrorImpl site) {
             super(Class::getDeclaredConstructors,
@@ -139,26 +149,18 @@
         }
 
         @Override
-        public ConstructorLookup withFlags(int flags) {
-            membersFilter = membersFilter.and(c -> (c.member.getModifiers() & flags) != 0);
+        public ConstructorLookup withParameterTypes(RuntimeMirror... paramTypes) {
+            membersFilter = membersFilter.and(f -> f.getParameterTypes().equals(Arrays.asList(paramTypes)));
             return this;
         }
 
         @Override
-        public ConstructorLookup withAccessContext(Lookup lookup) {
-            membersFilter = membersFilter.and(f -> isMemberAccessible(f.member.getDeclaringClass(),
-                    f.member.getDeclaringClass(), f.member.getModifiers(), lookup.lookupClass(), ALL_ACCESS_MODES));
-            return this;
-        }
-
-        @Override
-        public ConstructorLookup withParameterTypes(RuntimeMirror... paramTypes) {
-            membersFilter = membersFilter.and(f -> f.getParameterTypes().equals(Arrays.asList(paramTypes)));
-            return this;
+        Class<?> getDeclaringClass(ConstructorMirrorImpl fieldMirror) {
+            return fieldMirror.member.getDeclaringClass();
         }
     }
     
-    static class MethodLookupImpl extends AbstractLookupImpl<MethodMirror, MethodMirrorImpl, Method> implements MethodLookup {
+    static class MethodLookupImpl extends AbstractLookupImpl<MethodLookupImpl, MethodMirror, MethodMirrorImpl, Method> implements MethodLookup {
 
         MethodLookupImpl(ClassMirrorImpl site) {
             super(Class::getDeclaredMethods,
@@ -167,20 +169,7 @@
         }
 
         @Override
-        public MethodLookupImpl withFlags(int flags) {
-            membersFilter = membersFilter.and(f -> (f.member.getModifiers() & flags) != 0);
-            return this;
-        }
-
-        @Override
-        public MethodLookup withAccessContext(Lookup lookup) {
-            membersFilter = membersFilter.and(f -> isMemberAccessible(f.member.getDeclaringClass(),
-                    f.member.getDeclaringClass(), f.member.getModifiers(), lookup.lookupClass(), ALL_ACCESS_MODES));
-            return this;
-        }
-
-        @Override
-        public MethodLookup withInheritanceKind(InheritanceMode kind) {
+        public MethodLookup withInheritanceMode(InheritanceMode kind) {
             inheritanceMode = kind;
             return this;
         }
@@ -222,9 +211,14 @@
             });
             return this;
         }
+
+        @Override
+        Class<?> getDeclaringClass(MethodMirrorImpl fieldMirror) {
+            return fieldMirror.member.getDeclaringClass();
+        }
     }
     
-    static class ClassLookupImpl extends AbstractLookupImpl<ClassMirror, ClassMirrorImpl, Class<?>> implements ClassLookup {
+    static class ClassLookupImpl extends AbstractLookupImpl<ClassLookupImpl, ClassMirror, ClassMirrorImpl, Class<?>> implements ClassLookup {
 
         ClassLookupImpl(ClassMirrorImpl site) {
             super(Class::getDeclaredClasses,
@@ -233,28 +227,20 @@
         }
 
         @Override
-        public ClassLookupImpl withFlags(int flags) {
-            membersFilter = membersFilter.and(f -> (f.clazz.getModifiers() & flags) != 0);
-            return this;
-        }
-
-        @Override
-        public ClassLookup withAccessContext(Lookup lookup) {
-            membersFilter = membersFilter.and(f -> isMemberAccessible(f.clazz.getDeclaringClass(),
-                    f.clazz.getDeclaringClass(), f.clazz.getModifiers(), lookup.lookupClass(), ALL_ACCESS_MODES));
-            return this;
-        }
-
-        @Override
-        public ClassLookup withInheritanceKind(InheritanceMode kind) {
+        public ClassLookup withInheritanceMode(InheritanceMode kind) {
             inheritanceMode = kind;
             return this;
         }
 
         @Override
         public ClassLookup withName(String name) {
-            membersFilter = membersFilter.and(f -> f.clazz.getName().equals(name));
+            membersFilter = membersFilter.and(f -> f.member.getName().equals(name));
             return this;
         }
+
+        @Override
+        Class<?> getDeclaringClass(ClassMirrorImpl fieldMirror) {
+            return fieldMirror.member.getDeclaringClass();
+        }
     }
 }
--- a/src/java.base/share/classes/valhalla/reflect/runtime/impl/AbstractMemberMirrorImpl.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/impl/AbstractMemberMirrorImpl.java	Tue Jun 28 11:05:10 2016 +0200
@@ -24,32 +24,46 @@
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-class AbstractMemberMirrorImpl<M extends Member> implements MemberMirror {
+abstract class AbstractMemberMirrorImpl<R, M extends MemberMirror> implements MemberMirror {
 
     protected final ClassMirrorImpl owner;
-    protected final M member;
+    protected final R member;
 
     @SuppressWarnings("unchecked")
     protected <Z extends RuntimeMirror> Z map(Type t) {
         return (Z)owner.map(t);
     }
 
-    protected AbstractMemberMirrorImpl(ClassMirrorImpl owner, M member) {
+    protected AbstractMemberMirrorImpl(ClassMirrorImpl owner, R member) {
         this.owner = owner;
         this.member = member;
     }
 
     @Override
-    public String getName() {
-        return member.getName();
-    }
-
-    @Override
     public ClassMirror getEnclosingType() {
         return owner;
     }
 
-    static class FieldMirrorImpl extends AbstractMemberMirrorImpl<Field> implements FieldMirror {
+    abstract M asMirror();
+
+    static abstract class BasicMemberMirrorImpl<R extends Member, M extends MemberMirror> extends AbstractMemberMirrorImpl<R, M> {
+
+        BasicMemberMirrorImpl(ClassMirrorImpl owner, R member) {
+            super(owner, member);
+        }
+
+        @Override
+        public int getModifiers() {
+            return member.getModifiers();
+        }
+
+        @Override
+        public String getName() {
+            return member.getName();
+        }
+    }
+
+    static class FieldMirrorImpl extends BasicMemberMirrorImpl<Field, FieldMirror> implements FieldMirror {
 
         FieldMirrorImpl(ClassMirrorImpl owner, Field field) {
             super(owner, field);
@@ -86,9 +100,14 @@
                 throw new IllegalStateException();
             }
         }
+
+        @Override
+        FieldMirror asMirror() {
+            return this;
+        }
     }
 
-    static class MethodMirrorImpl extends AbstractMemberMirrorImpl<Method> implements MethodMirror {
+    static class MethodMirrorImpl extends BasicMemberMirrorImpl<Method, MethodMirror> implements MethodMirror {
 
         MethodMirrorImpl(ClassMirrorImpl owner, Method method) {
             super(owner, method);
@@ -143,9 +162,14 @@
         public MethodMirror asGenericMirror() {
             throw new IllegalStateException();
         }
+
+        @Override
+        MethodMirror asMirror() {
+            return this;
+        }
     }
 
-    static class ConstructorMirrorImpl extends AbstractMemberMirrorImpl<Constructor<?>> implements ConstructorMirror {
+    static class ConstructorMirrorImpl extends BasicMemberMirrorImpl<Constructor<?>, ConstructorMirror> implements ConstructorMirror {
 
         ConstructorMirrorImpl(ClassMirrorImpl owner, Constructor<?> member) {
             super(owner, member);
@@ -185,6 +209,11 @@
         public String getName() {
             return "<init>";
         }
+
+        @Override
+        ConstructorMirror asMirror() {
+            return this;
+        }
     }
 
     static class GenericMethodMirrorImpl extends MethodMirrorImpl {
@@ -195,7 +224,7 @@
         GenericMethodMirrorImpl(ClassMirrorImpl owner, Method method, List<RuntimeMirror> typeArgs) {
             super(owner, method);
             this.genericClassMirror = (ClassMirrorImpl) owner.classLookup()
-                    .withInheritanceKind(InheritanceMode.DECLARED)
+                    .withInheritanceMode(InheritanceMode.DECLARED)
                     .withName(innerName(method)).findOrFail();
             this.typeArgs = typeArgs;
         }
--- a/src/java.base/share/classes/valhalla/reflect/runtime/impl/ClassMirrorImpl.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/impl/ClassMirrorImpl.java	Tue Jun 28 11:05:10 2016 +0200
@@ -19,24 +19,37 @@
 import java.util.stream.Collectors;
 import java.util.stream.Stream;
 
-class ClassMirrorImpl extends DelegatedMirrorImpl implements ClassMirror {
+class ClassMirrorImpl extends AbstractMemberMirrorImpl<Class<?>, ClassMirror> implements ClassMirror {
 
     protected List<RuntimeMirror> typeArgs;
 
-    ClassMirrorImpl(Class<?> clazz) {
-        super(clazz);
+    ClassMirrorImpl(ClassMirrorImpl encl, Class<?> clazz) {
+        super(encl, clazz);
     }
 
     @SuppressWarnings("unchecked")
-    <Z extends RuntimeMirror> Z map(Type t) {
-        return (Z)MirrorUtils.typeToMirror(t);
+    public <Z extends RuntimeMirror> Z map(Type t) {
+        return owner == null ?
+                (Z)MirrorUtils.typeToMirror(t) :
+                super.map(t);
     }
 
     @Override
-    public boolean equals(Object that) {
-        return super.equals(that) &&
-                ((ClassMirrorImpl)that).getTypeArguments().equals(getTypeArguments());
+    public Kind getKind() {
+        return Kind.CLASS;
+    }
 
+    @Override
+    public boolean equals(Object o) {
+        if (o instanceof ClassMirrorImpl) {
+            ClassMirrorImpl that = (ClassMirrorImpl) o;
+            return that.member.equals(member) &&
+                    that.getTypeArguments().equals(getTypeArguments()) &&
+                    ((that.getEnclosingType() == null && getEnclosingType() == null) ||
+                    that.getEnclosingType().equals(getEnclosingType()));
+        } else {
+            return false;
+        }
     }
 
     @Override
@@ -46,7 +59,7 @@
             return true;
         } else if (that.getKind() == Kind.CLASS) {
             ClassMirrorImpl thatClazz = (ClassMirrorImpl)that;
-            ClassMirror sup = MirrorUtils.asSuper(this, thatClazz.clazz);
+            ClassMirror sup = MirrorUtils.asSuper(this, thatClazz.member);
             if (sup == null) {
                 return false;
             }
@@ -65,7 +78,11 @@
 
     @Override
     public int hashCode() {
-        return super.hashCode() | getTypeArguments().hashCode();
+        int hash = member.hashCode() | getTypeArguments().hashCode();
+        if (owner != null) {
+            hash |= owner.hashCode();
+        }
+        return  hash;
     }
 
     //structural queries
@@ -74,7 +91,7 @@
     public List<? extends RuntimeMirror> getTypeArguments() {
         if (typeArgs == null) {
             //delay computation to prevent factory deadlocks
-            typeArgs = Stream.of(clazz.getTypeParameters())
+            typeArgs = Stream.of(member.getTypeParameters())
                     .filter(TypeVariable::isAny)
                     .map(MirrorUtils.factory::typeVarMirror)
                     .collect(Collectors.toList());
@@ -84,16 +101,16 @@
 
     @Override
     public ClassMirror getEnclosingType() {
-        return null;
+        return owner;
     }
 
     @Override
     public List<? extends ClassMirror> getSupertypes() {
         List<ClassMirror> sups = new ArrayList<>();
-        if (clazz.getGenericSuperclass() != null) {
-            sups.add(map(clazz.getGenericSuperclass()));
+        if (member.getGenericSuperclass() != null) {
+            sups.add(map(member.getGenericSuperclass()));
         }
-        Stream.of(clazz.getGenericInterfaces())
+        Stream.of(member.getGenericInterfaces())
                 .map(this::<ClassMirror>map)
                 .collect(Collectors.toCollection(() -> sups));
         return sups;
@@ -137,9 +154,12 @@
         if (actualTypeArgs.size() != getTypeArguments().size()) {
             throw new IllegalStateException();
         }
-        ClassMirror encl = getEnclosingType();
-        if (encl != null && encl.isSpecializable()) {
-            throw new IllegalStateException("Open type variables in owner!");
+        ClassMirror encl1 = getEnclosingType();
+        while (encl1 != null) {
+            if (encl1.isSpecializable()) {
+                throw new IllegalStateException("Open type variables in enclosing type!");
+            }
+            encl1 = (ClassMirrorImpl)encl1.getEnclosingType();
         }
         return new SpecializedClassMirrorImpl(this, actualTypeArgs);
     }
@@ -152,8 +172,8 @@
     @Override
     public String getTypeString() {
         String res = getEnclosingType() == null ?
-                super.getTypeString() :
-                getEnclosingType().getTypeString() + "." + clazz.getSimpleName();
+                member.getName() :
+                getEnclosingType().getTypeString() + "." + member.getSimpleName();
         if (getTypeArguments().size() > 0) {
             res += getTypeArguments().stream()
                     .map(RuntimeMirror::getTypeString)
@@ -163,8 +183,18 @@
     }
 
     @Override
+    public int getModifiers() {
+        return member.getModifiers();
+    }
+
+    @Override
     public String getName() {
-        return clazz.getSimpleName();
+        return member.getSimpleName();
+    }
+
+    @Override
+    ClassMirror asMirror() {
+        return this;
     }
 
     @Override
@@ -186,15 +216,15 @@
             try {
                 String prefix;
                 if (encl != null) {
-                    String innerName = clazz.getName();
+                    String innerName = member.getName();
                     if (innerName.contains(".")) { //skip packages here!
                         innerName = innerName.substring(innerName.lastIndexOf('.') + 1);
                     }
                     prefix = encl + "$$$" + innerName;
                 } else {
-                    prefix = clazz.getName();
+                    prefix = member.getName();
                 }
-                return MirrorUtils.factory.forName(prefix + args, clazz);
+                return MirrorUtils.factory.forName(prefix + args, member);
             } catch (ReflectiveOperationException ex) {
                 throw new IllegalStateException(ex);
             }
@@ -202,8 +232,8 @@
     }
 
     private String toDesc(RuntimeMirror r) {
-        if (r instanceof DelegatedMirrorImpl) {
-            Class<?> c = ((DelegatedMirrorImpl)r).clazz;
+        if (r instanceof PrimitiveMirrorImpl) {
+            Class<?> c = ((PrimitiveMirrorImpl)r).clazz;
             if (c.isPrimitive()) {
                 if (c.equals(Byte.TYPE)) {
                     return "B";
@@ -240,29 +270,18 @@
         final List<RuntimeMirror> actualTypeArgs;
 
         private SpecializedClassMirrorImpl(ClassMirrorImpl genericMirror, List<RuntimeMirror> actualTypeArgs) {
-            super(genericMirror.clazz);
+            super(genericMirror.owner, genericMirror.member);
             this.genericMirror = genericMirror;
             this.actualTypeArgs = actualTypeArgs;
         }
 
         @Override
         @SuppressWarnings("unchecked")
-        <Z extends RuntimeMirror> Z map(Type t) {
+        public <Z extends RuntimeMirror> Z map(Type t) {
             return (Z)MirrorUtils.subst(genericMirror.map(t), (List<RuntimeMirror>)genericMirror.getTypeArguments(), actualTypeArgs);
         }
 
         @Override
-        public boolean equals(Object that) {
-            return super.equals(that) &&
-                    genericMirror.equals(((SpecializedClassMirrorImpl)that).genericMirror);
-        }
-
-        @Override
-        public int hashCode() {
-            return super.hashCode() | genericMirror.hashCode();
-        }
-
-        @Override
         public boolean isSpecializable() {
             return false;
         }
@@ -281,54 +300,5 @@
         public ClassMirror asGenericMirror() {
             return genericMirror;
         }
-
-        @Override
-        public ClassMirror getEnclosingType() {
-            return genericMirror.getEnclosingType();
-        }
-    }
-
-    static class InnerClassMirrorImpl extends ClassMirrorImpl {
-
-        final ClassMirrorImpl encl;
-
-        InnerClassMirrorImpl(Class<?> clazz, ClassMirrorImpl encl) {
-            super(clazz);
-            this.encl = encl;
-        }
-
-        @Override
-        <Z extends RuntimeMirror> Z map(Type t) {
-            return encl.map(t);
-        }
-
-        @Override
-        public ClassMirror getEnclosingType() {
-            return encl;
-        }
-
-        @Override
-        public boolean equals(Object that) {
-            return super.equals(that) &&
-                    encl.equals(((ClassMirror)that).getEnclosingType());
-
-        }
-
-        @Override
-        public ClassMirror asSpecializedMirror(RuntimeMirror... typeArgs) {
-            ClassMirror encl1 = encl;
-            while (encl1 != null) {
-                if (encl1.isSpecializable()) {
-                    throw new IllegalStateException("Open type variables in enclosing type!");
-                }
-                encl1 = (ClassMirrorImpl)encl1.getEnclosingType();
-            }
-            return super.asSpecializedMirror(typeArgs);
-        }
-
-        @Override
-        public int hashCode() {
-            return super.hashCode() | getEnclosingType().hashCode();
-        }
     }
 }
--- a/src/java.base/share/classes/valhalla/reflect/runtime/impl/DelegatedMirrorImpl.java	Tue Jun 21 12:43:44 2016 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,50 +0,0 @@
-package valhalla.reflect.runtime.impl;
-
-import valhalla.reflect.runtime.RuntimeMirror;
-
-class DelegatedMirrorImpl implements RuntimeMirror {
-
-    final Class<?> clazz;
-
-    DelegatedMirrorImpl(Class<?> clazz) {
-        this.clazz = clazz;
-    }
-
-    @Override
-    public Kind getKind() {
-        if (clazz.isPrimitive()) {
-            return Kind.VALUE;
-        } else if (clazz.isArray()) {
-            return Kind.ARRAY;
-        } else {
-            return Kind.CLASS;
-        }
-    }
-
-    @Override
-    public boolean equals(Object that) {
-        return that instanceof DelegatedMirrorImpl &&
-                clazz.equals(((DelegatedMirrorImpl) that).clazz);
-    }
-
-    @Override
-    public int hashCode() {
-        return clazz.hashCode();
-    }
-
-    @Override
-    public boolean isSubtypeOf(RuntimeMirror that) {
-        return that instanceof DelegatedMirrorImpl &&
-                ((DelegatedMirrorImpl) that).clazz.isAssignableFrom(clazz);
-    }
-
-    @Override
-    public String getTypeString() {
-        return clazz.getName();
-    }
-
-    @Override
-    public Class<?> reflect() {
-        return clazz;
-    }
-}
--- a/src/java.base/share/classes/valhalla/reflect/runtime/impl/MirrorFactoryImpl.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/impl/MirrorFactoryImpl.java	Tue Jun 28 11:05:10 2016 +0200
@@ -11,7 +11,6 @@
 import valhalla.reflect.runtime.RuntimeMirror;
 import valhalla.reflect.runtime.RuntimeMirror.Kind;
 import valhalla.reflect.runtime.TypeVariableMirror;
-import valhalla.reflect.runtime.impl.ClassMirrorImpl.InnerClassMirrorImpl;
 
 import valhalla.reflect.runtime.impl.AbstractMemberMirrorImpl.ConstructorMirrorImpl;
 import valhalla.reflect.runtime.impl.AbstractMemberMirrorImpl.FieldMirrorImpl;
@@ -95,7 +94,7 @@
     @SuppressWarnings("unchecked")
     <Z extends RuntimeMirror> Z from(Class<?> clazz) {
         if (clazz.isPrimitive()) {
-            return (Z)type_cache.computeIfAbsent(clazz, tv -> new DelegatedMirrorImpl(clazz));
+            return (Z)type_cache.computeIfAbsent(clazz, tv -> new PrimitiveMirrorImpl(clazz));
         } else if (clazz.isArray()) {
             RuntimeMirror componentType = from(clazz.getComponentType());
             return (Z)arrayMirror(componentType);
@@ -135,9 +134,9 @@
         if (MirrorUtils.needsEnclosingType(memberClazz)) {
             Map<RuntimeMirror, MemberMirror> memberClasses =
                     members_cache.computeIfAbsent(memberClazz, _unused -> new ConcurrentHashMap<>());
-            return (ClassMirror)memberClasses.computeIfAbsent(encl, _unused -> new InnerClassMirrorImpl(memberClazz, (ClassMirrorImpl)encl));
+            return (ClassMirror)memberClasses.computeIfAbsent(encl, _unused -> new ClassMirrorImpl((ClassMirrorImpl)encl, memberClazz));
         } else {
-            return (ClassMirror)type_cache.computeIfAbsent(memberClazz, tv -> new ClassMirrorImpl(memberClazz));
+            return (ClassMirror)type_cache.computeIfAbsent(memberClazz, tv -> new ClassMirrorImpl(null, memberClazz));
         }
     }
 
--- a/src/java.base/share/classes/valhalla/reflect/runtime/impl/MirrorUtils.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/impl/MirrorUtils.java	Tue Jun 28 11:05:10 2016 +0200
@@ -129,7 +129,7 @@
     }
 
     static ClassMirrorImpl asSuper(ClassMirrorImpl site, Class<?> sym) {
-        if (site.clazz.equals(sym)) {
+        if (site.member.equals(sym)) {
             return site;
         } else {
             return site.getSupertypes().stream()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/java.base/share/classes/valhalla/reflect/runtime/impl/PrimitiveMirrorImpl.java	Tue Jun 28 11:05:10 2016 +0200
@@ -0,0 +1,44 @@
+package valhalla.reflect.runtime.impl;
+
+import valhalla.reflect.runtime.RuntimeMirror;
+
+class PrimitiveMirrorImpl implements RuntimeMirror {
+
+    final Class<?> clazz;
+
+    PrimitiveMirrorImpl(Class<?> clazz) {
+        this.clazz = clazz;
+    }
+
+    @Override
+    public Kind getKind() {
+        return Kind.VALUE;
+    }
+
+    @Override
+    public boolean equals(Object that) {
+        return that instanceof PrimitiveMirrorImpl &&
+                clazz.equals(((PrimitiveMirrorImpl) that).clazz);
+    }
+
+    @Override
+    public int hashCode() {
+        return clazz.hashCode();
+    }
+
+    @Override
+    public boolean isSubtypeOf(RuntimeMirror that) {
+        return that instanceof PrimitiveMirrorImpl &&
+                ((PrimitiveMirrorImpl) that).clazz.isAssignableFrom(clazz);
+    }
+
+    @Override
+    public String getTypeString() {
+        return clazz.getName();
+    }
+
+    @Override
+    public Class<?> reflect() {
+        return clazz;
+    }
+}
--- a/test/valhalla/test/valhalla/reflect/runtime/TestLookup.java	Tue Jun 21 12:43:44 2016 +0200
+++ b/test/valhalla/test/valhalla/reflect/runtime/TestLookup.java	Tue Jun 28 11:05:10 2016 +0200
@@ -48,7 +48,7 @@
         lookupHelper(staticKind, accessKind, nameKind, inheritanceMode, typeArg, paramType,
                 ClassMirror::methodLookup,
                 (l, paramTypeMirror) -> l.withName(nameKind.name)
-                        .withInheritanceKind(inheritanceMode)
+                        .withInheritanceMode(inheritanceMode)
                         .withParameterTypes(paramTypeMirror),
                 (m, paramTypeMirror) -> {
                     Assert.assertEquals(m.getReturnType(), paramTypeMirror);
@@ -64,7 +64,7 @@
         lookupHelper(staticKind, accessKind, nameKind, inheritanceMode, typeArg, paramType,
                 ClassMirror::methodLookup,
                 (l, retTypeMirror) -> l.withName(nameKind.name)
-                        .withInheritanceKind(inheritanceMode)
+                        .withInheritanceMode(inheritanceMode)
                         .withReturnType(retTypeMirror),
                 (m, retTypeMirror) -> {
                     Assert.assertEquals(m.getReturnType(), retTypeMirror);
@@ -92,7 +92,7 @@
         lookupHelper(staticKind, accessKind, nameKind, inheritanceMode, typeArg, paramType,
                 ClassMirror::methodLookup,
                 (l, paramTypeMirror) -> l.withName(nameKind.name)
-                        .withInheritanceKind(inheritanceMode)
+                        .withInheritanceMode(inheritanceMode)
                         .withParameterTypes(tvars -> (tvars.size() == 1) ?
                                 Optional.of(List.of(tvars.get(0), paramTypeMirror)) : Optional.empty()),
                 (m, paramTypeMirror) -> {
@@ -109,7 +109,7 @@
         lookupHelper(staticKind, accessKind, nameKind, inheritanceMode, typeArg, paramType,
                 ClassMirror::methodLookup,
                 (l, retTypeMirror) -> l.withName(nameKind.name)
-                        .withInheritanceKind(inheritanceMode)
+                        .withInheritanceMode(inheritanceMode)
                         .withReturnType(tvars -> (tvars.size() == 1) ?
                                 Optional.of(tvars.get(0)) : Optional.empty()),
                 (m, retTypeMirror) -> {
@@ -131,10 +131,10 @@
         L lookup = lookupFunc.apply(mirror);
         lookupInit.accept(lookup, lookupTypeMirror);
         if (staticKind != StaticKind.NON_STATIC) {
-            lookup = (L)lookup.withFlags(staticKind.mods);
+            lookup = (L)lookup.withModifiers(staticKind.mods);
         }
         if (accessKind != AccessKind.PACKAGE) {
-            lookup = (L)lookup.withFlags(accessKind.mods);
+            lookup = (L)lookup.withModifiers(accessKind.mods);
         }
         L lookup2 = lookup;
         if (staticKind == StaticKind.NON_STATIC && accessKind == AccessKind.PACKAGE &&