8000 Qualified name of inner classes missing the enclosing type · Issue #218 · forge/roaster · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Qualified name of inner classes missing the enclosing type #218
Open
@thorstengross

Description

@thorstengross

If you reference an inner class (or interface) in the extends clause / implements clause / field / return type of method / parameter of method, the parent types are missing. I provided a small example:

import org.jboss.forge.roaster.Roaster;
import org.jboss.forge.roaster.model.source.JavaClassSource;
import org.jboss.forge.roaster.model.source.JavaInterfaceSource;
import org.jboss.forge.roaster.model.source.JavaSource;
import org.junit.jupiter.api.Test;

public class InnerClassesTest {

	private String testClass = """
			package alpha.beta.gamma;

				public class Foo {

					public class Bar extends Bar2 implements BarInterface {
						
						private Huu h;
					
						public Huu getHuu(Huu huu) throws BarException {return null;}

						public class Huu {

						}
					}
					
					public class Bar2 {}
					
					public interface BarInterface {}
					
				}

			""";

	@Test
	public void test() {
		JavaClassSource foo = (JavaClassSource) Roaster.parse(JavaSource.class, testClass);
		JavaClassSource bar = (JavaClassSource) foo.getNestedTypes().get(0);
		JavaClassSource bar2 = (JavaClassSource) foo.getNestedTypes().get(1);
		JavaInterfaceSource bar2Interface = (JavaInterfaceSource) foo.getNestedTypes().get(2);	
		JavaClassSource huu = (JavaClassSource) bar.getNestedTypes().get(0);
		
		System.out.println(bar.getSuperType()+" should be "+bar2.getQualifiedName());		
		System.out.println(bar.getInterfaces().get(0)+" should be "+bar2Interface.getQualifiedName());	
		System.out.println(bar.getFields().get(0).getType().getQualifiedNameWithGenerics() +" should be "+huu.getQualifiedName());
		System.out.println(bar.getMethods().get(0).getReturnType().getQualifiedNameWithGenerics()+" should be "+huu.getQualifiedName());
		System.out.println(bar.getMethods().get(0).getParameters().get(0).getType().getQualifiedNameWithGenerics()+" should be "+huu.getQualifiedName());
		System.out.println(bar.getMethods().get(0).getParameters().get(0).getType().getQualifiedNameWithGenerics()+" should be "+huu.getQualifiedName());
	}
}

Produced output:

alpha.beta.gamma.Bar2 should be alpha.beta.gamma.Foo$Bar2
alpha.beta.gamma.BarInterface should be alpha.beta.gamma.Foo$BarInterface
alpha.beta.gamma.Huu should be alpha.beta.gamma.Foo$Bar$Huu
alpha.beta.gamma.Huu should be alpha.beta.gamma.Foo$Bar$Huu
alpha.beta.gamma.Huu should be alpha.beta.gamma.Foo$Bar$Huu
alpha.beta.gamma.Huu should be alpha.beta.gamma.Foo$Bar$Huu

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0