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

Commit efc79d0

Browse files
authored
Merge pull request #41 from docascode/develop
June Release for 2020
2 parents 0b3bd2a + 7732efa commit efc79d0

34 files changed

Lines changed: 1994 additions & 102 deletions

src/main/java/com/microsoft/build/YmlFilesBuilder.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.microsoft.model.*;
88
import com.microsoft.util.ElementUtil;
99
import com.microsoft.util.FileUtil;
10+
import com.microsoft.util.Utils;
1011
import com.microsoft.util.YamlUtil;
1112
import jdk.javadoc.doclet.DocletEnvironment;
1213
import org.apache.commons.lang3.RegExUtils;
@@ -166,7 +167,7 @@ void addChildren(TypeElement classElement, List<String> children) {
166167

167168
List<? extends Element> filterPrivateElements(List<? extends Element> elements) {
168169
return elements.stream()
169-
.filter(element -> !ElementUtil.isPrivateOrPackagePrivate(element)).collect(Collectors.toList());
170+
.filter(element -> !Utils.isPrivateOrPackagePrivate(element)).collect(Collectors.toList());
170171
}
171172

172173
void collect(TypeElement classElement, List<String> children,
@@ -193,14 +194,15 @@ void addConstructorsInfo(TypeElement classElement, MetadataFile classMetadataFil
193194

194195
void addMethodsInfo(TypeElement classElement, MetadataFile classMetadataFile) {
195196
ElementFilter.methodsIn(classElement.getEnclosedElements()).stream()
196-
.filter(methodElement -> !ElementUtil.isPrivateOrPackagePrivate(methodElement))
197+
.filter(methodElement -> !Utils.isPrivateOrPackagePrivate(methodElement))
197198
.forEach(methodElement -> {
198199
MetadataFileItem methodItem = buildMetadataFileItem(methodElement);
199200
methodItem.setOverload(classItemsLookup.extractOverload(methodElement));
200201
methodItem.setContent(classItemsLookup.extractMethodContent(methodElement));
201202
methodItem.setExceptions(classItemsLookup.extractExceptions(methodElement));
202203
methodItem.setParameters(classItemsLookup.extractParameters(methodElement));
203204
methodItem.setReturn(classItemsLookup.extractReturn(methodElement));
205+
methodItem.setOverridden(classItemsLookup.extractOverridden(methodElement));
204206

205207
classMetadataFile.getItems().add(methodItem);
206208
addExceptionReferences(methodItem, classMetadataFile);
@@ -212,7 +214,7 @@ void addMethodsInfo(TypeElement classElement, MetadataFile classMetadataFile) {
212214

213215
void addFieldsInfo(TypeElement classElement, MetadataFile classMetadataFile) {
214216
ElementFilter.fieldsIn(classElement.getEnclosedElements()).stream()
215-
.filter(fieldElement -> !ElementUtil.isPrivateOrPackagePrivate(fieldElement))
217+
.filter(fieldElement -> !Utils.isPrivateOrPackagePrivate(fieldElement))
216218
.forEach(fieldElement -> {
217219
MetadataFileItem fieldItem = buildMetadataFileItem(fieldElement);
218220
fieldItem.setContent(classItemsLookup.extractFieldContent(fieldElement));
@@ -286,7 +288,7 @@ void addSuperclassAndInterfacesReferences(TypeElement classElement, MetadataFile
286288

287289
void addInnerClassesReferences(TypeElement classElement, MetadataFile classMetadataFile) {
288290
classMetadataFile.getReferences().addAll(
289-
ElementFilter.typesIn(classElement.getEnclosedElements()).stream()
291+
ElementFilter.typesIn(elementUtil.extractSortedElements(classElement)).stream()
290292
.map(this::buildClassReference)
291293
.collect(Collectors.toList()));
292294
}
@@ -488,7 +490,7 @@ String resolveUidFromReference(String linkContent, LookupContext lookupContext)
488490
return uid;
489491
}
490492

491-
String resolveUidByLookup(String signature, LookupContext lookupContext){
493+
String resolveUidByLookup(String signature, LookupContext lookupContext) {
492494
if (StringUtils.isBlank(signature) || lookupContext == null) {
493495
return "";
494496
}

src/main/java/com/microsoft/lookup/BaseLookup.java

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.microsoft.model.MethodParameter;
77
import com.microsoft.model.Return;
88
import com.microsoft.model.TypeParameter;
9+
910
import com.sun.source.doctree.DocCommentTree;
1011
import com.sun.source.doctree.DocTree;
1112
import com.sun.source.doctree.LinkTree;
@@ -14,9 +15,12 @@
1415
import java.util.*;
1516
import java.util.stream.Collectors;
1617
import java.util.stream.Stream;
18+
1719
import javax.lang.model.element.Element;
1820
import javax.lang.model.element.ElementKind;
21+
1922
import jdk.javadoc.doclet.DocletEnvironment;
23+
2024
import org.apache.commons.lang3.RegExUtils;
2125
import org.apache.commons.lang3.StringUtils;
2226

@@ -152,6 +156,10 @@ public Set<MetadataFileItem> extractReferences(T key) {
152156
return resolve(key).getReferences();
153157
}
154158

159+
public String extractOverridden(T key) {
160+
return resolve(key).getOverridden();
161+
}
162+
155163
protected String determineType(T element) {
156164
return elementKindLookup.get(element.getKind());
157165
}
@@ -162,9 +170,9 @@ protected String determinePackageName(T element) {
162170

163171
protected String determineComment(T element) {
164172
return getDocCommentTree(element)
165-
.map(DocCommentTree::getFullBody)
166-
.map(this::replaceLinksAndCodes)
167-
.orElse(null);
173+
.map(DocCommentTree::getFullBody)
174+
.map(this::replaceLinksAndCodes)
175+
.orElse(null);
168176
}
169177

170178
/**
@@ -175,19 +183,19 @@ protected String determineComment(T element) {
175183
*/
176184
String replaceLinksAndCodes(List<? extends DocTree> items) {
177185
return items.stream().map(
178-
bodyItem -> {
179-
switch (bodyItem.getKind()) {
180-
case LINK:
181-
case LINK_PLAIN:
182-
return buildXrefTag((LinkTree) bodyItem);
183-
case CODE:
184-
return buildCodeTag((LiteralTree) bodyItem);
185-
case LITERAL:
186-
return expandLiteralBody((LiteralTree) bodyItem);
187-
default:
188-
return String.valueOf(bodyItem);
186+
bodyItem -> {
187+
switch (bodyItem.getKind()) {
188+
case LINK:
189+
case LINK_PLAIN:
190+
return buildXrefTag((LinkTree) bodyItem);
191+
case CODE:
192+
return buildCodeTag((LiteralTree) bodyItem);
193+
case LITERAL:
194+
return expandLiteralBody((LiteralTree) bodyItem);
195+
default:
196+
return String.valueOf(bodyItem);
197+
}
189198
}
190-
}
191199
).collect(Collectors.joining());
192200
}
193201

@@ -223,7 +231,7 @@ public String makeTypeShort(String value) {
223231
return value;
224232
}
225233
return Stream.of(StringUtils.split(value, "<"))
226-
.map(s -> RegExUtils.removeAll(s, "\\b[a-z0-9_.]+\\."))
227-
.collect(Collectors.joining("<"));
234+
.map(s -> RegExUtils.removeAll(s, "\\b[a-z0-9_.]+\\."))
235+
.collect(Collectors.joining("<"));
228236
}
229237
}

src/main/java/com/microsoft/lookup/ClassItemsLookup.java

Lines changed: 85 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
11
package com.microsoft.lookup;
22

33
import com.microsoft.lookup.model.ExtendedMetadataFileItem;
4+
45
import com.microsoft.model.ExceptionItem;
56
import com.microsoft.model.MethodParameter;
67
import com.microsoft.model.Return;
8+
9+
import com.microsoft.util.CommentHelper;
10+
import com.microsoft.util.Utils;
11+
12+
import com.sun.source.doctree.DocTree;
713
import com.sun.source.doctree.DocTree.Kind;
814
import com.sun.source.doctree.ParamTree;
915
import com.sun.source.doctree.ReturnTree;
1016
import com.sun.source.doctree.ThrowsTree;
17+
18+
import java.util.ArrayList;
1119
import java.util.List;
1220
import java.util.stream.Collectors;
13-
import javax.lang.model.element.Element;
14-
import javax.lang.model.element.ExecutableElement;
15-
import javax.lang.model.element.TypeElement;
16-
import javax.lang.model.element.VariableElement;
21+
22+
import javax.lang.model.element.*;
1723
import javax.lang.model.type.TypeKind;
24+
1825
import jdk.javadoc.doclet.DocletEnvironment;
1926

2027
public class ClassItemsLookup extends BaseLookup<Element> {
28+
private Utils utils;
2129

2230
public ClassItemsLookup(DocletEnvironment environment) {
2331
super(environment);
32+
utils = new Utils(environment);
2433
}
2534

2635
@Override
@@ -48,18 +57,22 @@ protected ExtendedMetadataFileItem buildMetadataFileItem(Element element) {
4857
ExecutableElement exeElement = (ExecutableElement) element;
4958
List<MethodParameter> parameters = extractParameters(exeElement);
5059
String paramsString = parameters.stream()
51-
.map(parameter -> String.format("%s %s", makeTypeShort(parameter.getType()), parameter.getId()))
52-
.collect(Collectors.joining(", "));
60+
.map(parameter -> String.format("%s %s", makeTypeShort(parameter.getType()), parameter.getId()))
61+
.collect(Collectors.joining(", "));
5362
String nameWithoutBrackets = elementQName.replaceAll("\\(.*\\)", "");
5463
String methodName = String.format("%s(%s)", nameWithoutBrackets, paramsString);
5564

5665
result.setName(methodName);
5766
result.setMethodContent(String.format("%s %s %s", modifiers,
58-
makeTypeShort(String.valueOf(exeElement.getReturnType())), result.getName()));
67+
makeTypeShort(String.valueOf(exeElement.getReturnType())), result.getName()));
5968
result.setConstructorContent(String.format("%s %s", modifiers, result.getName()));
6069
result.setParameters(parameters);
6170
result.setExceptions(extractExceptions(exeElement));
6271
result.setReturn(extractReturn(exeElement));
72+
if (exeElement.getKind() == ElementKind.METHOD) {
73+
result.setOverridden(extractOverriddenUid(utils.overriddenMethod(exeElement)));
74+
result.setSummary(getInheritedInlineCommentString(exeElement));
75+
}
6376
}
6477
result.setNameWithType(String.format("%s.%s", classSNameWithGenericsSupport, result.getName()));
6578
result.setFullName(String.format("%s.%s", classQNameWithGenericsSupport, result.getName()));
@@ -83,11 +96,11 @@ List<MethodParameter> extractParameters(ExecutableElement element) {
8396

8497
String extractParameterDescription(ExecutableElement method, String paramName) {
8598
return getDocCommentTree(method).map(docTree -> docTree.getBlockTags().stream()
86-
.filter(o -> o.getKind() == Kind.PARAM)
87-
.map(o -> (ParamTree) o)
88-
.filter(o -> paramName.equals(String.valueOf(o.getName())))
89-
.map(o -> replaceLinksAndCodes(o.getDescription()))
90-
.findFirst().orElse(null)
99+
.filter(o -> o.getKind() == Kind.PARAM)
100+
.map(o -> (ParamTree) o)
101+
.filter(o -> paramName.equals(String.valueOf(o.getName())))
102+
.map(o -> replaceLinksAndCodes(o.getDescription()))
103+
.findFirst().orElse(null)
91104
).orElse(null);
92105
}
93106

@@ -100,10 +113,10 @@ List<ExceptionItem> extractExceptions(ExecutableElement methodElement) {
100113

101114
String extractExceptionDescription(ExecutableElement methodElement) {
102115
return getDocCommentTree(methodElement).map(docTree -> docTree.getBlockTags().stream()
103-
.filter(o -> o.getKind() == Kind.THROWS)
104-
.map(o -> (ThrowsTree) o)
105-
.map(o -> replaceLinksAndCodes(o.getDescription()))
106-
.findFirst().orElse(null)
116+
.filter(o -> o.getKind() == Kind.THROWS)
117+
.map(o -> (ThrowsTree) o)
118+
.map(o -> replaceLinksAndCodes(o.getDescription()))
119+
.findFirst().orElse(null)
107120
).orElse(null);
108121
}
109122

@@ -116,10 +129,10 @@ Return extractReturn(ExecutableElement methodElement) {
116129

117130
String extractReturnDescription(ExecutableElement methodElement) {
118131
return getDocCommentTree(methodElement).map(docTree -> docTree.getBlockTags().stream()
119-
.filter(o -> o.getKind() == Kind.RETURN)
120-
.map(o -> (ReturnTree)o)
121-
.map(o -> replaceLinksAndCodes(o.getDescription()))
122-
.findFirst().orElse(null)
132+
.filter(o -> o.getKind() == Kind.RETURN)
133+
.map(o -> (ReturnTree) o)
134+
.map(o -> replaceLinksAndCodes(o.getDescription()))
135+
.findFirst().orElse(null)
123136
).orElse(null);
124137
}
125138

@@ -130,4 +143,56 @@ Return extractReturn(VariableElement fieldElement) {
130143
String convertFullNameToOverload(String fullName) {
131144
return fullName.replaceAll("\\(.*\\)", "*");
132145
}
146+
147+
String extractOverriddenUid(ExecutableElement ovr) {
148+
if (ovr != null) {
149+
TypeElement te = utils.getEnclosingTypeElement(ovr);
150+
String uid = te.getQualifiedName().toString().concat(".") + String.valueOf(ovr);
151+
return uid;
152+
}
153+
154+
return "";
155+
}
156+
157+
/**
158+
* If the item being inherited from is declared from external compiled package,
159+
* or is declared in the packages like java.lang.Object,
160+
* comments may be not available as doclet resolves from byte code.
161+
*/
162+
String getInheritedInlineCommentString(ExecutableElement exeElement) {
163+
CommentHelper ch = getInheritedInlineTags(new CommentHelper(exeElement, utils));
164+
// Remove unresolved "@inheritDoc" tag.
165+
List<? extends DocTree> dctree = utils.removeBlockTag(ch.inlineTags, DocTree.Kind.INHERIT_DOC);
166+
return replaceLinksAndCodes(dctree);
167+
}
168+
169+
CommentHelper getInheritedInlineTags(CommentHelper input) {
170+
CommentHelper output = input.copy();
171+
if (!output.hasInheritDocTag()&& !output.isSimpleOverride()) {
172+
return output;
173+
}
174+
175+
CommentHelper inheritedSearchInput = input.copy();
176+
ExecutableElement overriddenMethod = utils.overriddenMethod((ExecutableElement) input.element);
177+
178+
if (overriddenMethod != null) {
179+
inheritedSearchInput.element = overriddenMethod;
180+
CommentHelper ch = getInheritedInlineTags(inheritedSearchInput);
181+
if (!ch.isSimpleOverride()) {
182+
output = output.inherit(ch);
183+
}
184+
}
185+
186+
TypeElement encl = utils.getEnclosingTypeElement(input.element);
187+
List<Element> implementedMethods = utils.getImplementedMethods(input.element.toString(), encl, new ArrayList<Element>());
188+
for (Element implementedMethod : implementedMethods) {
189+
inheritedSearchInput.element = implementedMethod;
190+
CommentHelper ch = getInheritedInlineTags(inheritedSearchInput);
191+
if (!ch.isSimpleOverride()) {
192+
output = output.inherit(ch);
193+
}
194+
}
195+
196+
return output;
197+
}
133198
}

src/main/java/com/microsoft/lookup/ClassLookup.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import com.microsoft.lookup.model.ExtendedMetadataFileItem;
44
import com.microsoft.model.MetadataFileItem;
55
import com.microsoft.model.TypeParameter;
6-
import com.microsoft.util.ElementUtil;
6+
import com.microsoft.util.Utils;
77
import jdk.javadoc.doclet.DocletEnvironment;
88
import org.apache.commons.collections4.CollectionUtils;
99
import org.apache.commons.lang3.StringUtils;
@@ -146,7 +146,7 @@ void appendInheritedMethods(TypeElement element, List<ExtendedMetadataFileItem>
146146
.orElse(0);
147147

148148
for (Element m : members) {
149-
if (m.getKind() == ElementKind.METHOD && !ElementUtil.isPrivateOrPackagePrivate(m)) {
149+
if (m.getKind() == ElementKind.METHOD && !Utils.isPrivateOrPackagePrivate(m)) {
150150
String uid = element.getQualifiedName().toString().concat(".") + String.valueOf(m);
151151

152152
ExtendedMetadataFileItem item = new ExtendedMetadataFileItem(uid);

src/main/java/com/microsoft/model/MetadataFileItem.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import org.apache.commons.lang3.RegExUtils;
1212

1313
@JsonPropertyOrder({"uid", "id", "parent", "children", "href", "langs", "isExternal", "name", "nameWithType",
14-
"fullName", "overload", "type", "package", "summary", "syntax", "inheritance", "implements", "exceptions",
14+
"fullName", "overload", "overridden", "type", "package", "summary", "syntax", "inheritance", "implements", "exceptions",
1515
"spec.java", "inheritedMembers"})
1616
public class MetadataFileItem implements Comparable<MetadataFileItem> {
1717

@@ -25,6 +25,7 @@ public class MetadataFileItem implements Comparable<MetadataFileItem> {
2525
private String nameWithType;
2626
private String fullName;
2727
private String overload;
28+
private String overridden;
2829
private String type;
2930
@JsonProperty("package")
3031
private String packageName;
@@ -232,6 +233,14 @@ public void setReturn(Return returnValue) {
232233
syntax.setReturnValue(returnValue);
233234
}
234235

236+
public void setOverridden(String overridden) {
237+
this.overridden = overridden;
238+
}
239+
240+
public String getOverridden() {
241+
return overridden;
242+
}
243+
235244
@Override
236245
public boolean equals(Object o) {
237246
if (this == o) {

0 commit comments

Comments
 (0)