[ 
https://issues.apache.org/jira/browse/GROOVY-11117?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17806497#comment-17806497
 ] 

Eric Milles commented on GROOVY-11117:
--------------------------------------

{{AstBuilder#visitClassDeclaration}} is doing this when it parses source.  In 
your case, the outer class is an interface so it is not added to 
{{classNodeList}} until after its body is processed, so the inner class is 
added first.
{code:java}
        // we put the class already in output to avoid the most inner classes
        // will be used as first class later in the loader. The first class
        // there determines what GCL#parseClass for example will return, so we
        // have here to ensure it won't be the inner class
        if (asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT())) {
            classNodeList.add(classNode);
        }

        classNodeStack.push(classNode);
        ctx.classBody().putNodeMetaData(CLASS_DECLARATION_CLASS_NODE, 
classNode);
        this.visitClassBody(ctx.classBody());
        if (isRecord) {
            classNode.getFields().stream().filter(f -> !isTrue(f, 
IS_RECORD_GENERATED) && !f.isStatic()).findFirst()
                    .ifPresent(fn -> 
this.createParsingFailedException("Instance field is not allowed in `record`", 
fn));
        }
        classNodeStack.pop();

        if (!(asBoolean(ctx.CLASS()) || asBoolean(ctx.TRAIT()))) {
            classNodeList.add(classNode);
        }
{code}

> return first nested interface when GroovyClassLoader.parseClass parse 
> interfaces with nested interfaces
> -------------------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-11117
>                 URL: https://issues.apache.org/jira/browse/GROOVY-11117
>             Project: Groovy
>          Issue Type: Bug
>            Reporter: Hai Shi
>            Priority: Major
>
> When I have a groovy file:
> {code:groovy}
> interface A {
>     interface B { }
>    interface C { }
> }
> {code}
> When I use classLoader to parse this file, I only get the interface {{B}}
> {code:groovy}
> def gcl = new GroovyClassLoader()
> // this just get the interface B, Something Do I missed?
> def loadedClass = gcl.parseClass(new File("xxxx"))
> {code}
> my version:
>  * jdk:18.0.1
>  * groovy: 4.0.2



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to