private ObjectReferenceImpl createObjectMirror()

in core/src/main/java/com/jetbrains/sa/jdi/VirtualMachineImpl.java [599:662]


    private ObjectReferenceImpl createObjectMirror(long id, Oop key) {
        ObjectReferenceImpl object = null;
        Klass klass = key.getKlass();
        ReferenceTypeImpl type = referenceType(klass);
        if (key instanceof Instance) {
            // look for well-known classes
            Symbol classNameSymbol = klass.getName();
            if (Assert.ASSERTS_ENABLED) {
                Assert.that(classNameSymbol != null, "Null class name");
            }
            String className = classNameSymbol.asString();
            Instance inst = (Instance) key;
            if (className.equals(javaLangString)) {
                object = new StringReferenceImpl(type, inst);
            } else if (className.equals(javaLangThread)) {
                object = new ThreadReferenceImpl(type, inst);
            } else if (className.equals(javaLangThreadGroup)) {
                object = new ThreadGroupReferenceImpl(type, inst);
            } else if (className.equals(javaLangClass)) {
                object = new ClassObjectReferenceImpl(type, inst);
            } else if (className.equals(javaLangClassLoader)) {
                object = new ClassLoaderReferenceImpl(type, inst);
            } else {
                // not a well-known class. But the base class may be
                // one of the known classes.
                Klass kls = klass.getSuper();
                while (kls != null) {
                    className = kls.getName().asString();
                    // java.lang.Class and java.lang.String are final classes
                    if (className.equals(javaLangThread)) {
                        object = new ThreadReferenceImpl(type, inst);
                        break;
                    } else if(className.equals(javaLangThreadGroup)) {
                        object = new ThreadGroupReferenceImpl(type, inst);
                        break;
                    } else if (className.equals(javaLangClassLoader)) {
                        object = new ClassLoaderReferenceImpl(type, inst);
                        break;
                    }
                    kls = kls.getSuper();
                }

                if (object == null) {
                    // create generic object reference
                    object = new ObjectReferenceImpl(type, inst);
                }
            }
        } else if (key instanceof TypeArray || key instanceof ObjArray) {
            object = new ArrayReferenceImpl(type, (Array) key);
        } else {
            throw new RuntimeException("unexpected object type " + key);
        }

        /*
         * If there was no previous entry in the table, we add one here
         * If the previous entry was cleared, we replace it here.
         */
        if (Assert.ASSERTS_ENABLED) {
            Assert.that(id == object.uniqueID(), "Unique id does not match");
        }
        objectsByID.put(id, new SoftObjectReference(id, object, referenceQueue));

        return object;
    }