Skip to content
This repository has been archived by the owner on Aug 9, 2022. It is now read-only.

Commit

Permalink
fix inheritance chain (BUG 88737 and BUG 88742) (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
anmeng10101 authored Jul 3, 2019
1 parent a71e7b7 commit 5a540e9
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 19 deletions.
15 changes: 7 additions & 8 deletions src/main/java/com/microsoft/lookup/BaseLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -38,7 +35,7 @@ public abstract class BaseLookup<T extends Element> {
}};

protected Map<T, ExtendedMetadataFileItem> map = new HashMap<>();
private final DocletEnvironment environment;
public final DocletEnvironment environment;

protected BaseLookup(DocletEnvironment environment) {
this.environment = environment;
Expand Down Expand Up @@ -131,8 +128,10 @@ public List<TypeParameter> extractTypeParameters(T key) {
return resolve(key).getTypeParameters();
}

public String extractSuperclass(T key) {
return resolve(key).getSuperclassValue();
public List<String> extractSuperclass(T key) {
List<String> sortedList = resolve(key).getSuperclass();
Collections.reverse(sortedList);
return sortedList;
}

public List<String> extractInterfaces(T key) {
Expand Down
21 changes: 20 additions & 1 deletion src/main/java/com/microsoft/lookup/ClassLookup.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("."), ""));

Expand Down Expand Up @@ -101,6 +103,23 @@ String determineSuperclass(TypeElement classElement) {
return String.valueOf(superclass);
}

List<String> determineNestedSuperclass(TypeElement classElement, ExtendedMetadataFileItem result) {
List<String> 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<TypeParameter> determineTypeParameters(TypeElement element) {
return element.getTypeParameters().stream()
.map(typeParameter -> new TypeParameter(String.valueOf(typeParameter)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class ExtendedMetadataFileItem extends MetadataFileItem {
private Return returnValue;
private String content;
private List<TypeParameter> typeParameters;
private String superclass;
private List<String> superclass;
private String tocName;
private Set<MetadataFileItem> references = new LinkedHashSet<>();

Expand Down Expand Up @@ -88,11 +88,11 @@ public void setTypeParameters(List<TypeParameter> typeParameters) {
this.typeParameters = typeParameters;
}

public String getSuperclassValue() {
public List<String> getSuperclass() {
return superclass;
}

public void setSuperclass(String superclass) {
public void setSuperclass(List<String> superclass) {
this.superclass = superclass;
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/microsoft/model/MetadataFileItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ public List<String> getInheritance() {
return inheritance;
}

public void setInheritance(String superclass) {
this.inheritance = (superclass == null) ? null : Arrays.asList(superclass);
public void setInheritance(List<String> superclass) {
this.inheritance = (superclass == null) ? null : superclass;
}

public List<String> getInterfaces() {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/com/microsoft/lookup/BaseLookupTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand All @@ -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")));
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/microsoft/model/MetadataFileItemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ items:
syntax:
content: "public abstract class BasePartnerComponentString extends BasePartnerComponent<String>"
inheritance:
- "com.microsoft.samples.BasePartnerComponent<java.lang.String>"
- "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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ items:
syntax:
content: "public enum Person.IdentificationInfo.Gender extends Enum<Person.IdentificationInfo.Gender>"
inheritance:
- "java.lang.Enum<com.microsoft.samples.subpackage.Person.IdentificationInfo.Gender>"
- "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"
Expand Down

0 comments on commit 5a540e9

Please sign in to comment.