ArchUnit icon indicating copy to clipboard operation
ArchUnit copied to clipboard

missing type argument on outer class when using inner class

Open StefanGraeber opened this issue 2 months ago • 0 comments

When I have a class with type parameters and an inner class, I can specify the type arguments of the outer class when accessing the inner class. These type information are not represented in ArchUnit. Example

public class Outer<T> {
    public Outer<T>.Inner field;

    public class Inner {

    }
}

is loaded in ArchUnit as a field with type JavaClass(Outer$Inner). Since this class is not linked to the usage of the parameterized type in any way, it is not possible to retrieve the type argument given to Outer. Note that this does not have to be the same class I'm currently in and the type argument value might deviate as well.

In the type resolution, we currently drop signature information entirely, if the type itself is a class, but we must check for enclosing classes as well. These type parameters can also be annotated with type use annotations, such that this blocks #1382

This missign feature is equivalent to the reflection method ParameterizedType#getOwnerType

naming Owner might also be Enclosing for consistency with JavaClass.getEnclosingClass and upcoming AnnotatedType#getAnnotatedEnclosingType (which shall not contain Owner in it's name to avoid confusion with ownership on annotated Type.

StefanGraeber avatar Oct 03 '26 15:10 StefanGraeber