Skip to content

Commit

Permalink
Closes #95: Display overrides that upgrade visibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
agi committed Nov 30, 2021
1 parent 93f6516 commit e7438ee
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 8 deletions.
28 changes: 20 additions & 8 deletions apidoc-plugin/src/main/java/org/mozilla/doclet/ApiDoclet.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,15 @@ private int kindOrder(Element e) {
default -> 3;
};
}
};

private boolean isPublic(Element e) {
return e.getModifiers().contains(Modifier.PUBLIC);
}
private static boolean isPublic(Element e) {
return e.getModifiers().contains(Modifier.PUBLIC);
}

private boolean isProtected(Element e) {
return e.getModifiers().contains(Modifier.PROTECTED);
}
};
private static boolean isProtected(Element e) {
return e.getModifiers().contains(Modifier.PROTECTED);
}

private String classNameFragment(TypeElement classDoc) {
StringBuilder fragment = new StringBuilder(classDoc.getSimpleName().toString());
Expand Down Expand Up @@ -375,7 +375,19 @@ private void writeClass(TypeElement typeElement, Writer writer) {
|| e.getKind() == ElementKind.CONSTRUCTOR
|| e.getKind().isField())
// Don't add @Override methods to the API
.filter(m -> findSuperMethod(m, writer) == null)
.filter(
m -> {
// Always show the method if the visibility is upgraded
// or there's no super method at all
Element superMethod = findSuperMethod(m, writer);
if (superMethod == null) {
return true;
}
if (!isPublic(superMethod) && !isProtected(superMethod)) {
return true;
}
return isPublic(m) && !isPublic(superMethod);
})
.filter(
m ->
m.getModifiers().stream()
Expand Down
14 changes: 14 additions & 0 deletions apidoc-plugin/src/test/fake_root/org/mozilla/test/TestClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,18 @@ private TestSortC() {}
public static final int TEST_INT = 1;
public static final long TEST_LONG = 2;
public static final double TEST_DOUBLE = 2.0;

public static class TestPackageProtected {
private TestPackageProtected() {}
// This shouldn't appear in the API
/* package */ void testPackageProtected();
}

public static class TestOverrideNonVisibleApi extends TestPackageProtected {
private TestOverrideNonVisibleApi() {}
// This should appear in the API
@Override
public void testPackageProtected();
}

}
7 changes: 7 additions & 0 deletions apidoc-plugin/src/test/resources/expected-doclet-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ package org.mozilla.test {
ctor public TestMultipleInterfaceImpl();
}

public static class TestClass.TestOverrideNonVisibleApi extends TestClass.TestPackageProtected {
method public void testPackageProtected();
}

public static class TestClass.TestPackageProtected {
}

public static class TestClass.TestSort {
method public void testSortA0();
method public void testSortB0();
Expand Down
7 changes: 7 additions & 0 deletions apidoc-plugin/src/test/resources/expected-map-output.txt
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ org/mozilla/test/TestClass.java:57:5
org/mozilla/test/TestClass.java:57:19


org/mozilla/test/TestClass.java:237:5
org/mozilla/test/TestClass.java:240:9


org/mozilla/test/TestClass.java:231:5


org/mozilla/test/TestClass.java:191:5
org/mozilla/test/TestClass.java:202:9
org/mozilla/test/TestClass.java:204:9
Expand Down

0 comments on commit e7438ee

Please sign in to comment.