Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes from appling apilint to exoplayer2. #70

Merged
merged 2 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 8 additions & 2 deletions apilint/src/main/resources/apilint.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,12 +240,18 @@ def __init__(self, clazz, source, raw, location, blame, imports):
else:
self.generics = []

self.is_array = False
self.is_var_arg = False
if raw.endswith("[]"):
self.name = self.resolve(raw[:-2], imports)
while raw.endswith("[]"):
raw = raw[:-2]
self.name = self.resolve(raw, imports)
self.is_array = True
elif raw.endswith("..."):
self.name = self.resolve(raw[:-3], imports)
self.is_var_arg = True
else:
self.name = self.resolve(raw, imports)
self.is_array = False

def resolve(self, name, imports):
# Never resolve primitive types
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package test {
public class TestClass {
method public long testLong();
method public int testInt();
method public void testIntParam(int);
method public void testIntParamVarArg(int...);
method public long[] testLongArray();
method public long[][] testLongArrayArray();
method public long[][][] testLongArrayArrayArray();
}
}

6 changes: 6 additions & 0 deletions apilint/src/test/resources/apilint_test/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@
"check_compat": false,
"filter": "GV",
"allowed_packages": ["test"]
},{
"test": "test-built-in-types-allowed",
"expected": "SUCCESS",
"check_compat": false,
"filter": "GV7",
"allowed_packages": ["test"]
},{
"test": "test-fields-only-class",
"expected": "API_ERROR",
Expand Down