Skip to content

Commit

Permalink
Show inheritance + allow more annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
kantenkugel committed Mar 24, 2020
1 parent cb08692 commit ffa9571
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
Expand Up @@ -70,7 +70,13 @@ public static List<Documentation> get(final String name) {
if(classDoc.methodDocs.containsKey(methodName.toLowerCase())) {
return getMethodDocs(classDoc, methodName, fixedSearchObj, fuzzy);
} else if(classDoc.inheritedMethods.containsKey(methodName.toLowerCase())) {
return get(classDoc.inheritedMethods.get(methodName.toLowerCase()) + '.' + searchObj);
List<Documentation> inherited = get(classDoc.inheritedMethods.get(methodName.toLowerCase()) + '.' + searchObj);
JDocParser.ClassDocumentation extendingClass = classDoc;
inherited = inherited.stream()
.filter(i -> i instanceof JDocParser.MethodDocumentation)
.map(i -> new InheritedDoc((JDocParser.MethodDocumentation) i, extendingClass))
.collect(Collectors.toList());
return inherited;
}
return Collections.emptyList();
}
Expand Down Expand Up @@ -295,4 +301,12 @@ private static void fetchJavaClassIndexes() {
JDocUtil.LOG.error("Failed fetching the j8 class index", e);
}
}

private static class InheritedDoc extends JDocParser.MethodDocumentation {
public InheritedDoc(JDocParser.MethodDocumentation inheritedDoc, JDocParser.ClassDocumentation childClass) {
super(childClass, inheritedDoc.functionSig, inheritedDoc.hashLink,
String.format("**Inherited from %s**\n\n%s", inheritedDoc.parent.className, inheritedDoc.desc),
inheritedDoc.fields);
}
}
}
Expand Up @@ -42,7 +42,7 @@ public class JDocParser {
//annotations in front of method
public static final Pattern ANNOTATION_PATTERN = Pattern.compile("^((?:@[^\n]+\n)+)");
//annotation splitter
public static final Pattern ANNOTATION_PARTS = Pattern.compile("@([a-zA-Z]+)(\\(\\S*\\))?\n");
public static final Pattern ANNOTATION_PARTS = Pattern.compile("@([a-zA-Z]+)(\\((\"?).*?\\3\\))?\n");
//type, name
public static final Pattern METHOD_ARG_PATTERN = Pattern.compile("(?:[a-z]+\\.)*([a-zA-Z][a-zA-Z0-9.<,?>\\[\\]]*)\\s+([a-zA-Z][a-zA-Z0-9]*)(?:\\s*,|$)");

Expand Down Expand Up @@ -369,22 +369,27 @@ static class MethodDocumentation implements Documentation {
final String desc;
final OrderedMap<String, List<String>> fields;

private MethodDocumentation(ClassDocumentation parent, String functionSig, final String hashLink, final String desc, final OrderedMap<String, List<String>> fields) {
protected MethodDocumentation(ClassDocumentation parent, String functionSig, final String hashLink, final String desc, final OrderedMap<String, List<String>> fields) {
functionSig = JDocUtil.fixSignature(functionSig);
Matcher methodMatcher = METHOD_PATTERN.matcher(functionSig);
if(!methodMatcher.find()) {
System.out.println('"' + functionSig + '"');
throw new RuntimeException("Got method with no proper method signature: " + functionSig);
}
String noAnnoSig = functionSig;

//check for documented annotations of method
this.methodAnnos = new ArrayList<>();
Matcher annoGroupMatcher = ANNOTATION_PATTERN.matcher(functionSig);
if(annoGroupMatcher.find()) {
noAnnoSig = annoGroupMatcher.replaceFirst("");
Matcher annoMatcher = ANNOTATION_PARTS.matcher(annoGroupMatcher.group(1));
while(annoMatcher.find()) {
this.methodAnnos.add(new MethodAnnotation(annoMatcher.group(1), annoMatcher.group(2)));
}
}

Matcher methodMatcher = METHOD_PATTERN.matcher(noAnnoSig);
if(!methodMatcher.find()) {
System.out.println('"' + functionSig + '"');
throw new RuntimeException("Got method with no proper method signature: " + functionSig);
}

this.parent = parent;
this.returnType = methodMatcher.group(1);
this.functionName = methodMatcher.group(2);
Expand Down

0 comments on commit ffa9571

Please sign in to comment.