Skip to content

Commit

Permalink
Import classes from extends fragments.
Browse files Browse the repository at this point in the history
  • Loading branch information
agi committed Jul 30, 2019
1 parent fc13e89 commit d8c8667
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
22 changes: 16 additions & 6 deletions apidoc-plugin/src/main/java/org/mozilla/doclet/ApiDoclet.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ private String toLine(ClassDoc classDoc, Writer writer) {

classLine += classDoc.name();

String typeParams = typeParamsFragment(classDoc.typeParameters());
String typeParams = typeParamsFragment(classDoc.typeParameters(), writer);
classLine += typeParams;

if (typeParams.equals("")) {
Expand Down Expand Up @@ -378,9 +378,19 @@ private String valueFragment(FieldDoc field) {
return " = " + field.constantValueExpression();
}

private String typeParamsFragment(TypeVariable[] typeVariables) {
private String typeParamFragment(TypeVariable typeVariable, Writer writer) {
String fragment = typeVariable.typeName();
if (typeVariable.bounds().length > 0) {
fragment += " extends " + Stream.of(typeVariable.bounds())
.map(t -> typeFragment(t, writer))
.collect(Collectors.joining(" & "));
}
return fragment;
}

private String typeParamsFragment(TypeVariable[] typeVariables, Writer writer) {
String parameters = Stream.of(typeVariables)
.map(TypeVariable::toString)
.map(tv -> typeParamFragment(tv, writer))
.collect(Collectors.joining(","));

if (parameters.equals("")) {
Expand All @@ -390,8 +400,8 @@ private String typeParamsFragment(TypeVariable[] typeVariables) {
return "<" + parameters + "> ";
}

private String typeParamsFragment(ExecutableMemberDoc executable) {
return typeParamsFragment(executable.typeParameters());
private String typeParamsFragment(ExecutableMemberDoc executable, Writer writer) {
return typeParamsFragment(executable.typeParameters(), writer);
}

static class MethodWalker implements Walker<MethodDoc> {
Expand Down Expand Up @@ -454,7 +464,7 @@ private String toLine(ProgramElementDoc member, Writer writer) {
}

if (member instanceof ExecutableMemberDoc) {
line += typeParamsFragment((ExecutableMemberDoc) member);
line += typeParamsFragment((ExecutableMemberDoc) member, writer);
}

if (member instanceof MethodDoc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public TestClass(int arg0, float arg1) {}
public <T> void testTypeVariableUnbounded(T arg) {}
public <T extends java.lang.Runnable> void testTypeVariableWithBounds(T arg) {}
public <T extends java.lang.Runnable & java.lang.Cloneable> void testTypeVariableWithMultipleBounds(T arg) {}
public <T extends java.util.Map<Integer, Long>> void testTypeVariableWithMapBounds(T arg) {}

public <T> T testReturnTypeUnbounded() { return null; }
public <T extends java.lang.Runnable> T testReturnTypeWithBound() { return null; }
Expand Down
14 changes: 10 additions & 4 deletions apidoc-plugin/src/test/resources/expected-doclet-output.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import android.support.annotation.NonNull;
import java.lang.Class;
import java.lang.Cloneable;
import java.lang.Deprecated;
import java.lang.Integer;
import java.lang.Long;
import java.lang.Runnable;
import java.lang.String;
import java.lang.annotation.Annotation;
import java.util.List;
import java.util.Map;
import org.mozilla.test.TestClass;
import org.mozilla.test.testsorta.TestSort;

Expand All @@ -29,14 +34,15 @@ package org.mozilla.test {
method public <T> List<List<T>> testReturnNestedCompositeType();
method @NonNull public final String testReturnTypeAnnotation();
method public <T> T testReturnTypeUnbounded();
method public <T extends java.lang.Runnable> T testReturnTypeWithBound();
method public <T extends Runnable> T testReturnTypeWithBound();
method public static void testStatic();
method public String testStringMethod();
method public String testStringMethodWithArg(String);
method public synchronized void testSynchronized();
method public <T> void testTypeVariableUnbounded(T);
method public <T extends java.lang.Runnable> void testTypeVariableWithBounds(T);
method public <T extends java.lang.Runnable & java.lang.Cloneable> void testTypeVariableWithMultipleBounds(T);
method public <T extends Runnable> void testTypeVariableWithBounds(T);
method public <T extends Map<Integer,Long>> void testTypeVariableWithMapBounds(T);
method public <T extends Runnable & Cloneable> void testTypeVariableWithMultipleBounds(T);
method public void testVarArgsOneArg(int...);
method public void testVarArgsTwoArgs(int, int...);
method public void testVoidMethod();
Expand Down Expand Up @@ -155,7 +161,7 @@ package org.mozilla.test {
ctor public TestSubclass();
}

public static class TestClass.TestTypeBoundVariable<T extends java.lang.Runnable> {
public static class TestClass.TestTypeBoundVariable<T extends Runnable> {
ctor public TestTypeBoundVariable();
method public void testTypeVariableMethod(T);
}
Expand Down

0 comments on commit d8c8667

Please sign in to comment.