-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Qualified name of inner classes missing the enclosing type #218
Comments
Here is a test using assertions based on your report: package org.jboss.forge.test.roaster.model;
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.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
public class InnerClassesTest
{
private static final String CONTENTS =
"package alpha.beta.gamma;"
+ "public class Outer {"
+ " public class InnerExtendsClass extends InnerClass implements InnerInterface {"
+ " private InnerInnerExtendsClass h;"
+ " public InnerInnerExtendsClass getInnerInnerExtendsClass(InnerInnerExtendsClass huu) throws Exception {return null;}"
+ " public class InnerInnerExtendsClass {}"
+ " }"
+ " public class InnerClass {}"
+ " public interface InnerInterface {}"
+ "}";
private static JavaClassSource innerExtendsClass;
private static JavaClassSource innerClass;
private static JavaInterfaceSource innerInterface;
private static JavaClassSource innerInnerExtendsClass;
@BeforeAll
static void setUp()
{
JavaClassSource outer = Roaster.parse(JavaClassSource.class, CONTENTS);
List<JavaSource<?>> nestedTypes = outer.getNestedTypes();
innerExtendsClass = (JavaClassSource) nestedTypes.get(0);
innerClass = (JavaClassSource) nestedTypes.get(1);
innerInterface = (JavaInterfaceSource) nestedTypes.get(2);
innerInnerExtendsClass = (JavaClassSource) innerExtendsClass.getNestedTypes().get(0);
}
@Test
void test_super_type_should_match_qualified_name()
{
assertThat(innerExtendsClass.getSuperType()).isEqualTo(innerClass.getQualifiedName());
}
@Test
void test_interface_should_match_qualified_name()
{
assertThat(innerExtendsClass.getInterfaces().get(0)).isEqualTo(innerInterface.getQualifiedName());
}
@Test
void test_field_type_should_match_qualified_name() {
assertThat(innerExtendsClass.getFields().get(0).getType().getQualifiedNameWithGenerics()).isEqualTo(
innerInnerExtendsClass.getQualifiedName());
}
@Test
void test_method_return_type_should_match_qualified_name() {
assertThat(innerExtendsClass.getMethods().get(0).getReturnType().getQualifiedNameWithGenerics())
.isEqualTo(innerInnerExtendsClass.getQualifiedName());
}
@Test
void test_method_parameter_type_should_match_qualified_name() {
assertThat(innerExtendsClass.getMethods().get(0).getParameters().get(0).getType().getQualifiedNameWithGenerics())
.isEqualTo(innerInnerExtendsClass.getQualifiedName());
}
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
Produced output:
The text was updated successfully, but these errors were encountered: