private static Set parseConstantPoolClassReferences()

in src/main/java/org/apache/maven/shared/dependency/analyzer/asm/ConstantPoolParser.java [111:197]


    private static Set<String> parseConstantPoolClassReferences(ByteBuffer buf) {
        if (buf.order(ByteOrder.BIG_ENDIAN).getInt() != HEAD) {
            return Collections.emptySet();
        }
        buf.getChar();
        buf.getChar(); // minor + ver
        Set<Integer> classReferences = new HashSet<>();
        Set<Integer> typeReferences = new HashSet<>();
        Map<Integer, String> stringConstants = new HashMap<>();
        for (int ix = 1, num = buf.getChar(); ix < num; ix++) {
            byte tag = buf.get();
            switch (tag) {
                case CONSTANT_UTF8:
                    stringConstants.put(ix, decodeString(buf));
                    break;
                case CONSTANT_CLASS:
                    classReferences.add((int) buf.getChar());
                    break;
                case CONSTANT_METHOD_TYPE:
                    consumeMethodType(buf);
                    break;
                case CONSTANT_FIELDREF:
                case CONSTANT_METHODREF:
                case CONSTANT_INTERFACEMETHODREF:
                    consumeReference(buf);
                    break;
                case CONSTANT_NAME_AND_TYPE:
                    buf.getChar();
                    typeReferences.add((int) buf.getChar());
                    break;
                case CONSTANT_INTEGER:
                    consumeInt(buf);
                    break;
                case CONSTANT_FLOAT:
                    consumeFloat(buf);
                    break;
                case CONSTANT_DOUBLE:
                    consumeDouble(buf);
                    ix++;
                    break;
                case CONSTANT_LONG:
                    consumeLong(buf);
                    ix++;
                    break;
                case CONSTANT_STRING:
                    consumeString(buf);
                    break;
                case CONSTANT_METHODHANDLE:
                    consumeMethodHandle(buf);
                    break;
                case CONSTANT_INVOKE:
                    consumeDynamic(buf);
                    break;
                case CONSTANT_INVOKE_DYNAMIC:
                    consumeInvokeDynamic(buf);
                    break;
                case CONSTANT_MODULE:
                    consumeModule(buf);
                    break;
                case CONSTANT_PACKAGE:
                    consumePackage(buf);
                    break;
                default:
                    throw new RuntimeException("Unknown constant pool type '" + tag + "'");
            }
        }

        Set<String> result = new HashSet<>();

        for (Integer classRef : classReferences) {
            addClassToResult(result, stringConstants.get(classRef));
        }

        for (Integer typeRef : typeReferences) {
            String typeName = stringConstants.get(typeRef);

            if (Type.getType(typeName).getSort() == Type.METHOD) {
                addClassToResult(result, Type.getReturnType(typeName).getInternalName());
                Type[] argumentTypes = Type.getArgumentTypes(typeName);
                for (Type argumentType : argumentTypes) {
                    addClassToResult(result, argumentType.getInternalName());
                }
            }
        }

        return result;
    }