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

Open
wants to merge 8 commits into
base: dev/patch
Choose a base branch
from
Open
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
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 @@ -273,7 +283,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 @@ -300,16 +310,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 @@ -338,10 +338,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