Skip to content

Allow plural types in docs.json #7698

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

Merged
merged 10 commits into from
May 1, 2025
46 changes: 26 additions & 20 deletions src/main/java/ch/njol/skript/doc/JSONGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,12 +176,22 @@ private static JsonArray getEventValues(SkriptEventInfo<?> info) {
continue;
}

ClassInfo<?> exactClassInfo = Classes.getExactClassInfo(eventValueInfo.valueClass());
if (exactClassInfo == null) {
Class<?> valueClass = eventValueInfo.valueClass();
ClassInfo<?> classInfo;
if (valueClass.isArray()) {
classInfo = Classes.getExactClassInfo(valueClass.componentType());
} else {
classInfo = Classes.getExactClassInfo(valueClass);
}

if (classInfo == null) {
continue;
}

String name = getClassInfoName(exactClassInfo).toLowerCase(Locale.ENGLISH);
String name = classInfo.getName().getSingular();
if (valueClass.isArray()) {
name = classInfo.getName().getPlural();
}
if (name.isBlank()) {
continue;
}
Expand All @@ -193,8 +203,8 @@ private static JsonArray getEventValues(SkriptEventInfo<?> info) {
}

JsonObject object = new JsonObject();
object.addProperty("id", DocumentationIdProvider.getId(exactClassInfo));
object.addProperty("name", name);
object.addProperty("id", DocumentationIdProvider.getId(classInfo));
object.addProperty("name", name.toLowerCase(Locale.ENGLISH));
eventValues.add(object);
}
}
Expand Down Expand Up @@ -277,7 +287,7 @@ private static JsonObject generateClassInfoElement(ClassInfo<?> classInfo) {

JsonObject syntaxJsonObject = new JsonObject();
syntaxJsonObject.addProperty("id", DocumentationIdProvider.getId(classInfo));
syntaxJsonObject.addProperty("name", getClassInfoName(classInfo));
syntaxJsonObject.addProperty("name", Objects.requireNonNullElse(classInfo.getDocName(), classInfo.getCodeName()));
syntaxJsonObject.addProperty("since", classInfo.getSince());

syntaxJsonObject.add("patterns", cleanPatterns(classInfo.getUsage()));
Expand All @@ -304,16 +314,6 @@ private static JsonArray generateClassInfoArray(Iterator<ClassInfo<?>> classInfo
return syntaxArray;
}

/**
* Gets either the explicitly declared documentation name or code name of a ClassInfo
*
* @param classInfo the ClassInfo to get the effective name of
* @return the effective name of the ClassInfo
*/
private static String getClassInfoName(ClassInfo<?> classInfo) {
return Objects.requireNonNullElse(classInfo.getDocName(), classInfo.getCodeName());
}

/**
* Generates the documentation JsonObject for a JavaFunction
*
Expand Down Expand Up @@ -342,10 +342,16 @@ private static JsonObject generateFunctionElement(JavaFunction<?> function) {
* @return the JsonObject representing the return type of the JavaFunction
*/
private static JsonObject getReturnType(JavaFunction<?> function) {
JsonObject returnType = new JsonObject();
returnType.addProperty("name", getClassInfoName(function.getReturnType()));
returnType.addProperty("id", DocumentationIdProvider.getId(function.getReturnType()));
return returnType;
JsonObject object = new JsonObject();

ClassInfo<?> returnType = function.getReturnType();
if (returnType == null) {
return null;
}

object.addProperty("id", DocumentationIdProvider.getId(returnType));
object.addProperty("name", Objects.requireNonNullElse(returnType.getDocName(), returnType.getCodeName()));
return object;
}

/**
Expand Down