Skip to content

Commit fb78ae7

Browse files
committed
Improve quality of dumped API output
* Always use leading underscore for non-public methods. * Include Downloads and Environments utility classes. * Mark nullable argument of Downloads#download method.
1 parent f7687ac commit fb78ae7

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

src/main/java/org/apposed/appose/util/Downloads.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
3939
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
4040
import org.apposed.appose.Appose;
41+
import org.apposed.appose.Nullable;
4142

4243
import java.io.BufferedInputStream;
4344
import java.io.File;
@@ -68,7 +69,7 @@ private Downloads() {
6869
// Prevent instantiation of utility class.
6970
}
7071

71-
public static File download(String name, String urlPath, BiConsumer<Long, Long> progressConsumer)
72+
public static File download(String name, String urlPath, @Nullable BiConsumer<Long, Long> progressConsumer)
7273
throws IOException, InterruptedException, URISyntaxException
7374
{
7475
final File tempFile = File.createTempFile(name + "-", FilePaths.fileType(urlPath));

src/test/java/org/apposed/appose/DumpApi.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public class DumpApi {
110110
PACKAGE_TO_MODULE.put("org.apposed.appose.tool.Uv", "tool/uv.api");
111111

112112
// Utility packages - singular naming.
113+
PACKAGE_TO_MODULE.put("org.apposed.appose.util.Downloads", "util/download.api");
114+
PACKAGE_TO_MODULE.put("org.apposed.appose.util.Environments", "util/environment.api");
113115
PACKAGE_TO_MODULE.put("org.apposed.appose.util.FilePaths", "util/filepath.api");
114116
PACKAGE_TO_MODULE.put("org.apposed.appose.util.Platforms", "util/platform.api");
115117
PACKAGE_TO_MODULE.put("org.apposed.appose.util.Processes", "util/process.api");
@@ -124,6 +126,8 @@ public class DumpApi {
124126
private static final Set<String> STATIC_UTILITY_CLASSES = new HashSet<>(Arrays.asList(
125127
"org.apposed.appose.Appose",
126128
"org.apposed.appose.builder.Builders",
129+
"org.apposed.appose.util.Downloads",
130+
"org.apposed.appose.util.Environments",
127131
"org.apposed.appose.util.FilePaths",
128132
"org.apposed.appose.util.Platforms",
129133
"org.apposed.appose.util.Processes",
@@ -329,27 +333,27 @@ static void dumpStaticUtilityAsModuleFunctions(TypeDeclaration<?> type) {
329333
}
330334
}
331335

332-
// Output public static fields as module-level constants.
336+
// Output static fields as module-level constants (public and private if INCLUDE_PRIVATE).
333337
for (BodyDeclaration<?> member : type.getMembers()) {
334338
if (member instanceof FieldDeclaration) {
335339
FieldDeclaration field = (FieldDeclaration) member;
336-
if (field.isPublic() && field.isStatic()) {
340+
if (field.isStatic() && (field.isPublic() || INCLUDE_PRIVATE)) {
337341
for (VariableDeclarator var : field.getVariables()) {
338-
String fieldName = toSnakeCase(var.getNameAsString()).toUpperCase();
342+
String fieldName = nonClassName(field, var).toUpperCase();
339343
String fieldType = pythonType(var.getType());
340344
out.println(fieldName + ": " + fieldType);
341345
}
342346
}
343347
}
344348
}
345349

346-
// Collect all public static methods.
350+
// Collect all static methods (public and private if INCLUDE_PRIVATE).
347351
Map<String, List<MethodDeclaration>> methodsByName = new LinkedHashMap<>();
348352
for (BodyDeclaration<?> member : type.getMembers()) {
349353
if (member instanceof MethodDeclaration) {
350354
MethodDeclaration method = (MethodDeclaration) member;
351-
if (method.isPublic() && method.isStatic()) {
352-
String methodName = toSnakeCase(method.getNameAsString());
355+
if (method.isStatic() && (method.isPublic() || INCLUDE_PRIVATE)) {
356+
String methodName = nonClassName(method);
353357
methodsByName.computeIfAbsent(methodName, k -> new ArrayList<>()).add(method);
354358
}
355359
}
@@ -454,7 +458,7 @@ static String formatParameterType(Parameter param) {
454458
static String formatModuleFunction(MethodDeclaration method) {
455459
StringBuilder sb = new StringBuilder("def ");
456460

457-
String methodName = toSnakeCase(method.getNameAsString());
461+
String methodName = nonClassName(method);
458462
sb.append(methodName).append("(");
459463

460464
NodeList<Parameter> params = method.getParameters();
@@ -488,7 +492,7 @@ static String formatModuleFunctionWithOptionalParams(List<MethodDeclaration> met
488492

489493
StringBuilder sb = new StringBuilder("def ");
490494

491-
String methodName = toSnakeCase(longest.getNameAsString());
495+
String methodName = nonClassName(longest);
492496
sb.append(methodName).append("(");
493497

494498
NodeList<Parameter> params = longest.getParameters();

0 commit comments

Comments
 (0)