Search in sources :

Example 1 with ObjectHolder

use of org.apache.groovy.util.ObjectHolder in project groovy by apache.

the class ClassSignatureParser method configureClass.

static void configureClass(ClassNode classNode, ClassStub stub, AsmReferenceResolver resolver) {
    if (stub.signature != null) {
        parseClassSignature(classNode, stub.signature, resolver);
        return;
    }
    if (stub.superName != null) {
        classNode.setSuperClass(resolver.resolveClass(AsmDecompiler.fromInternalName(stub.superName)));
    }
    ClassNode[] interfaces = new ClassNode[stub.interfaceNames.length];
    for (int i = 0; i < stub.interfaceNames.length; i++) {
        interfaces[i] = resolver.resolveClass(AsmDecompiler.fromInternalName(stub.interfaceNames[i]));
    }
    classNode.setInterfaces(interfaces);
    if (!stub.permittedSubclasses.isEmpty()) {
        List<ClassNode> permittedSubclasses = classNode.getPermittedSubclasses();
        for (String name : stub.permittedSubclasses) {
            permittedSubclasses.add(resolver.resolveClass(AsmDecompiler.fromInternalName(name)));
        }
    }
    if (!stub.recordComponents.isEmpty()) {
        classNode.setRecordComponents(stub.recordComponents.stream().map(r -> {
            ClassNode type = resolver.resolveType(Type.getType(r.descriptor));
            ObjectHolder<ClassNode> typeHolder = new ObjectHolder<>(type);
            if (null != r.signature) {
                new SignatureReader(r.signature).accept(new TypeSignatureParser(resolver) {

                    @Override
                    void finished(final ClassNode result) {
                        typeHolder.setObject(applyErasure(result, typeHolder.getObject()));
                    }
                });
            }
            ClassNode cn = typeHolder.getObject();
            Annotations.addTypeAnnotations(r, cn, resolver);
            RecordComponentNode recordComponentNode = new RecordComponentNode(classNode, r.name, cn);
            Annotations.addAnnotations(r, recordComponentNode, resolver);
            return recordComponentNode;
        }).collect(Collectors.toList()));
    }
}
Also used : ClassNode(org.codehaus.groovy.ast.ClassNode) ObjectHolder(org.apache.groovy.util.ObjectHolder) RecordComponentNode(org.codehaus.groovy.ast.RecordComponentNode) SignatureReader(org.objectweb.asm.signature.SignatureReader)

Aggregations

ObjectHolder (org.apache.groovy.util.ObjectHolder)1 ClassNode (org.codehaus.groovy.ast.ClassNode)1 RecordComponentNode (org.codehaus.groovy.ast.RecordComponentNode)1 SignatureReader (org.objectweb.asm.signature.SignatureReader)1