diff --git a/src/main/java/com/microsoft/lookup/BaseLookup.java b/src/main/java/com/microsoft/lookup/BaseLookup.java index 8a8c477..7d3a513 100644 --- a/src/main/java/com/microsoft/lookup/BaseLookup.java +++ b/src/main/java/com/microsoft/lookup/BaseLookup.java @@ -10,11 +10,8 @@ import com.sun.source.doctree.DocTree; import com.sun.source.doctree.LinkTree; import com.sun.source.doctree.LiteralTree; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.Set; + +import java.util.*; import java.util.stream.Collectors; import java.util.stream.Stream; import javax.lang.model.element.Element; @@ -38,7 +35,7 @@ public abstract class BaseLookup { }}; protected Map map = new HashMap<>(); - private final DocletEnvironment environment; + public final DocletEnvironment environment; protected BaseLookup(DocletEnvironment environment) { this.environment = environment; @@ -131,8 +128,10 @@ public List extractTypeParameters(T key) { return resolve(key).getTypeParameters(); } - public String extractSuperclass(T key) { - return resolve(key).getSuperclassValue(); + public List extractSuperclass(T key) { + List sortedList = resolve(key).getSuperclass(); + Collections.reverse(sortedList); + return sortedList; } public List extractInterfaces(T key) { diff --git a/src/main/java/com/microsoft/lookup/ClassLookup.java b/src/main/java/com/microsoft/lookup/ClassLookup.java index df24667..c703635 100644 --- a/src/main/java/com/microsoft/lookup/ClassLookup.java +++ b/src/main/java/com/microsoft/lookup/ClassLookup.java @@ -3,6 +3,8 @@ import com.microsoft.lookup.model.ExtendedMetadataFileItem; import com.microsoft.model.MetadataFileItem; import com.microsoft.model.TypeParameter; + +import java.util.ArrayList; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -41,7 +43,7 @@ protected ExtendedMetadataFileItem buildMetadataFileItem(TypeElement classElemen result.setPackageName(packageName); result.setSummary(determineComment(classElement)); populateContent(classElement, classSNameWithGenericsSupport, result); - result.setSuperclass(determineSuperclass(classElement)); + result.setSuperclass(determineNestedSuperclass(classElement, result)); result.setTypeParameters(determineTypeParameters(classElement)); result.setTocName(classQName.replace(packageName.concat("."), "")); @@ -101,6 +103,23 @@ String determineSuperclass(TypeElement classElement) { return String.valueOf(superclass); } + List determineNestedSuperclass(TypeElement classElement, ExtendedMetadataFileItem result) { + List nestedList = new ArrayList<>(); + + if (result.getSuperclass() != null) { + nestedList = result.getSuperclass(); + } + + TypeMirror supperclass = classElement.getSuperclass(); + if (supperclass.getKind() != TypeKind.NONE) { + TypeElement supperClassElement = (TypeElement) environment.getTypeUtils().asElement(supperclass); + nestedList.add(supperClassElement.getQualifiedName().toString()); + result.setSuperclass(nestedList); + determineNestedSuperclass(supperClassElement, result); + } + return nestedList; + } + List determineTypeParameters(TypeElement element) { return element.getTypeParameters().stream() .map(typeParameter -> new TypeParameter(String.valueOf(typeParameter))) diff --git a/src/main/java/com/microsoft/lookup/model/ExtendedMetadataFileItem.java b/src/main/java/com/microsoft/lookup/model/ExtendedMetadataFileItem.java index 60446cb..15406ff 100644 --- a/src/main/java/com/microsoft/lookup/model/ExtendedMetadataFileItem.java +++ b/src/main/java/com/microsoft/lookup/model/ExtendedMetadataFileItem.java @@ -20,7 +20,7 @@ public class ExtendedMetadataFileItem extends MetadataFileItem { private Return returnValue; private String content; private List typeParameters; - private String superclass; + private List superclass; private String tocName; private Set references = new LinkedHashSet<>(); @@ -88,11 +88,11 @@ public void setTypeParameters(List typeParameters) { this.typeParameters = typeParameters; } - public String getSuperclassValue() { + public List getSuperclass() { return superclass; } - public void setSuperclass(String superclass) { + public void setSuperclass(List superclass) { this.superclass = superclass; } diff --git a/src/main/java/com/microsoft/model/MetadataFileItem.java b/src/main/java/com/microsoft/model/MetadataFileItem.java index 3c6af0c..eab5846 100644 --- a/src/main/java/com/microsoft/model/MetadataFileItem.java +++ b/src/main/java/com/microsoft/model/MetadataFileItem.java @@ -170,8 +170,8 @@ public List getInheritance() { return inheritance; } - public void setInheritance(String superclass) { - this.inheritance = (superclass == null) ? null : Arrays.asList(superclass); + public void setInheritance(List superclass) { + this.inheritance = (superclass == null) ? null : superclass; } public List getInterfaces() { diff --git a/src/test/java/com/microsoft/lookup/BaseLookupTest.java b/src/test/java/com/microsoft/lookup/BaseLookupTest.java index 1e77d70..3ff7c83 100644 --- a/src/test/java/com/microsoft/lookup/BaseLookupTest.java +++ b/src/test/java/com/microsoft/lookup/BaseLookupTest.java @@ -222,7 +222,7 @@ public void testExtractMethods() { assertThat("Wrong content", baseLookup.extractContent(element), is(lastBuiltItem.getContent())); assertThat("Wrong typeParameters", baseLookup.extractTypeParameters(element), is(lastBuiltItem.getTypeParameters())); - assertThat("Wrong superclass", baseLookup.extractSuperclass(element), is(lastBuiltItem.getSuperclassValue())); + assertThat("Wrong superclass", baseLookup.extractSuperclass(element), is(lastBuiltItem.getSuperclass())); assertThat("Wrong interfaces", baseLookup.extractInterfaces(element), is(lastBuiltItem.getInterfaces())); assertThat("Wrong tocName", baseLookup.extractTocName(element), is(lastBuiltItem.getTocName())); assertThat("Wrong references", baseLookup.extractReferences(element), is(lastBuiltItem.getReferences())); @@ -248,7 +248,7 @@ private ExtendedMetadataFileItem buildExtendedMetadataFileItem(Element element) result.setType("Some type"); result.setContent("Some content"); result.setTypeParameters(Arrays.asList(new TypeParameter("type param id"))); - result.setSuperclass("Some "); + result.setSuperclass(Arrays.asList("Some ")); result.setInterfaces(Arrays.asList("Some interface")); result.setTocName("Some toc name"); result.addReferences(Set.of(new MetadataFileItem("ref uid"))); diff --git a/src/test/java/com/microsoft/model/MetadataFileItemTest.java b/src/test/java/com/microsoft/model/MetadataFileItemTest.java index a4ef254..3183109 100644 --- a/src/test/java/com/microsoft/model/MetadataFileItemTest.java +++ b/src/test/java/com/microsoft/model/MetadataFileItemTest.java @@ -7,6 +7,7 @@ import static org.junit.Assert.assertThat; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import org.junit.Test; @@ -133,7 +134,7 @@ public void setContentWhenSyntaxAlreadyPresent() { public void setInheritance() { MetadataFileItem object = new MetadataFileItem("123"); - object.setInheritance("Some value"); + object.setInheritance(Arrays.asList("Some value")); assertThat("Wrong inheritance size", object.getInheritance().size(), is(1)); assertThat("Wrong inheritance content", object.getInheritance(), hasItem("Some value")); diff --git a/src/test/resources/expected-generated-files/com.microsoft.samples.BasePartnerComponentString.yml b/src/test/resources/expected-generated-files/com.microsoft.samples.BasePartnerComponentString.yml index 873c33b..67359f7 100644 --- a/src/test/resources/expected-generated-files/com.microsoft.samples.BasePartnerComponentString.yml +++ b/src/test/resources/expected-generated-files/com.microsoft.samples.BasePartnerComponentString.yml @@ -17,7 +17,8 @@ items: syntax: content: "public abstract class BasePartnerComponentString extends BasePartnerComponent" inheritance: - - "com.microsoft.samples.BasePartnerComponent" + - "java.lang.Object" + - "com.microsoft.samples.BasePartnerComponent" - uid: "com.microsoft.samples.BasePartnerComponentString.BasePartnerComponentString(com.microsoft.samples.IPartner)" id: "BasePartnerComponentString(com.microsoft.samples.IPartner)" parent: "com.microsoft.samples.BasePartnerComponentString" diff --git a/src/test/resources/expected-generated-files/com.microsoft.samples.SuperHero.yml b/src/test/resources/expected-generated-files/com.microsoft.samples.SuperHero.yml index 4f3b622..738d893 100644 --- a/src/test/resources/expected-generated-files/com.microsoft.samples.SuperHero.yml +++ b/src/test/resources/expected-generated-files/com.microsoft.samples.SuperHero.yml @@ -28,6 +28,7 @@ items: syntax: content: "public class SuperHero extends Person implements Serializable, Cloneable" inheritance: + - "java.lang.Object" - "com.microsoft.samples.subpackage.Person" implements: - "java.io.Serializable" diff --git a/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.AgreementDetailsCollectionOperations.yml b/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.AgreementDetailsCollectionOperations.yml index 38c767e..6b594f5 100644 --- a/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.AgreementDetailsCollectionOperations.yml +++ b/src/test/resources/expected-generated-files/com.microsoft.samples.agreements.AgreementDetailsCollectionOperations.yml @@ -17,6 +17,8 @@ items: syntax: content: "public class AgreementDetailsCollectionOperations extends BasePartnerComponentString implements IAgreementDetailsCollection" inheritance: + - "java.lang.Object" + - "com.microsoft.samples.BasePartnerComponent" - "com.microsoft.samples.BasePartnerComponentString" implements: - "com.microsoft.samples.agreements.IAgreementDetailsCollection" diff --git a/src/test/resources/expected-generated-files/com.microsoft.samples.subpackage.CustomException.yml b/src/test/resources/expected-generated-files/com.microsoft.samples.subpackage.CustomException.yml index 9e5959b..c1d5e08 100644 --- a/src/test/resources/expected-generated-files/com.microsoft.samples.subpackage.CustomException.yml +++ b/src/test/resources/expected-generated-files/com.microsoft.samples.subpackage.CustomException.yml @@ -16,6 +16,8 @@ items: syntax: content: "public class CustomException extends Exception" inheritance: + - "java.lang.Object" + - "java.lang.Throwable" - "java.lang.Exception" - uid: "com.microsoft.samples.subpackage.CustomException.CustomException(java.lang.String)" id: "CustomException(java.lang.String)" diff --git a/src/test/resources/expected-generated-files/com.microsoft.samples.subpackage.Person.IdentificationInfo.Gender.yml b/src/test/resources/expected-generated-files/com.microsoft.samples.subpackage.Person.IdentificationInfo.Gender.yml index 57e58c5..9cf6897 100644 --- a/src/test/resources/expected-generated-files/com.microsoft.samples.subpackage.Person.IdentificationInfo.Gender.yml +++ b/src/test/resources/expected-generated-files/com.microsoft.samples.subpackage.Person.IdentificationInfo.Gender.yml @@ -19,7 +19,8 @@ items: syntax: content: "public enum Person.IdentificationInfo.Gender extends Enum" inheritance: - - "java.lang.Enum" + - "java.lang.Object" + - "java.lang.Enum" - uid: "com.microsoft.samples.subpackage.Person.IdentificationInfo.Gender.FEMALE" id: "FEMALE" parent: "com.microsoft.samples.subpackage.Person.IdentificationInfo.Gender"