HOW TO: Generate docs for your extensions [Java/JAR]

Hi :slightly_smiling_face:,
Many extension developers spend a lot of time in making extensions but even after that they need to work on documentation which is sometimes a big job.
So, this tutorial will surely help you, if you are one of them. :wink:
Let's get started.

1.Get component.json file

  • Open aix using any Zip software
  • Navigate to package name until you saw some files
  • Double click on component.json file and copy contents of it

2.Open any Java IDE [Intellij IDEA or Eclipse](Shouldn't be online one)

  • Create a class
  • Add these imports
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;

import java.awt.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
  • Add main method
  • Add following variables
public static String docs = "component.json content";
public static StringBuilder builder = new StringBuilder();
  • Add following code in main method
       try {
            addEvents();
            addMethods();
            addProperties();
            StringSelection stringSelection = new StringSelection(builder.toString());
            Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
            clipboard.setContents(stringSelection, null);
        } catch (ParseException e) {
            e.printStackTrace();
        }
  • Add following methods
public void addEvents() throws ParseException {
        JSONObject object = (JSONObject) new JSONParser().parse(text);
        JSONArray array = (JSONArray) object.get("events");
        if (!array.isEmpty()) {
            for (Object item : array) {
                JSONObject ob = (JSONObject) item;
                builder.append("> <h3>");
                builder.append(ob.get("name"));
                builder.append("</h3>");
                builder.append(ob.get("description"));
                JSONArray arr = (JSONArray) ob.get("params");
                if (!arr.isEmpty()) {
                    builder.append("\n" +
                            "Params           |  []()       \n" +
                            "---------------- | ------- \n" +
                            "\n");
                    for (Object value : arr) {
                        JSONObject o = (JSONObject) value;
                        builder.append("```` ").append(o.get("name")).append(" | ");
                        builder.append(o.get("type")).append("````\n");
                    }
                }
                builder.append("\n ____________________________________\n\n");
            }
        }
    }
    public void addMethods() throws ParseException {
        JSONObject object = (JSONObject) new JSONParser().parse(text);
        JSONArray array = (JSONArray) object.get("methods");
        if (!array.isEmpty()) {
            for (Object item : array) {
                JSONObject ob = (JSONObject) item;
                builder.append("> <h3>");
                builder.append(ob.get("name"));
                builder.append("</h3>");
                builder.append(ob.get("description"));
                JSONArray arr = (JSONArray) ob.get("params");
                if (!arr.isEmpty()) {
                    builder.append("\n" +
                            "Params           |  []()       \n" +
                            "---------------- | ------- \n" +
                            "\n");
                    for (Object value : arr) {
                        JSONObject o = (JSONObject) value;
                        builder.append("```` ").append(o.get("name")).append(" | ");
                        builder.append(o.get("type")).append("````<br>\n");
                    }
                }
                if (ob.containsKey("returnType")){
                    builder.append("\n<i>Return type : ").append(ob.get("returnType")).append("</i>\n");
                }
                builder.append("\n____________________________________\n\n");
            }
        }
    }
    public void addProperties() throws ParseException {
        JSONObject object = (JSONObject) new JSONParser().parse(text);
        JSONArray array = (JSONArray) object.get("blockProperties");
        if (!array.isEmpty()) {
            for (Object item : array) {
                JSONObject ob = (JSONObject) item;
                builder.append("> <h3>");
                builder.append(ob.get("name"));
                builder.append("</h3>");
                builder.append(ob.get("description"));
                if (ob.containsKey("rw")){
                    builder.append("\n<i>Property Type : ").append(ob.get("rw")).append("</i>");
                }
                if (ob.containsKey("type")){
                    builder.append("<br><i>Accepts : ").append(ob.get("type")).append("</i>");
                }
                builder.append("\n____________________________________\n\n");
            }
        }
    }

Now run the method/class once and docs will get copied to clipboard. :smiley:

How it looks ->

Method/Event name

Description

Params

param1 | type1
param2 | type2

8 Likes

Great guide! :grinning: Useful to me!

Nice guide @vknow360
Also there is a generator by @Ct_tricks
https://cttricks.com/extension-docs/index.php

There are many cons for not choosing that.

cool guide !

Nice Guide :innocent: :kissing_heart:

1 Like

Meanwhile you can just run this jar:


ChangeLog Version 2

  • Tool is now compatible with Rush which does generate component.json file
  • Now you can drag and drop aix file (Any other file will not get dropped)
  • Errors are shown in a dialog
  • Minor UI improvements, like file path label is now responsive
4 Likes

Now Open Source. :+1:

1 Like

there is a problem when i generated docs it repeated function twice i did not saw everything in detail but few were repeated
docs generated -

RefreshWithNewProperties

Refreshes the rubiks cube with new properties set.

AnimateMoveReversed

Animates in reverse (i.e. with opposite twisting direction) only the previous move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMove

Animates only the next move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMoveSequence

Animates all the moves in the currently set move sequence one move at a time. When a move has completed, the next one is automatically started.

SetMoveSequence

Sets the move sequence. Note you still have to use one of the blocks starting with animate.
Params

sequence | text


AnimateMoveSequenceReversed

Animates all the moves in the currently set move sequence one move at a time, in reverse (i.e. from end to start with opposite twisting direction).

SetupRubiksCube

Sets up Rubiks cube in a layout with porperties set.
Params

layout | component


SetDoubleRotationSpeed

Sets the rotation speed of a double rotation. This property allows to customize the speed of face turns separately from quarter turns.

Property Type : write-only
Accepts : number


SetFaceletsBorderColor

Sets border color of the facelets in rubik cube.

Property Type : write-only
Accepts : number


SetBackFacesDistance

Sets back faces distance from the cube. Typically, a value smaller than 2 means they won't be visible.

Property Type : write-only
Accepts : number


SetSingleRotationSpeed

Sets the rotation speed of a single rotation. This porperty allows to customize the speed of quarter turn separately from face turns.

Property Type : write-only
Accepts : number


SetBackgroundColor

Sets background colors of the rubik cube view.

Property Type : write-only
Accepts : number


SetEditable

Sets if rubiks cube can be changed by user or not.

Property Type : write-only
Accepts : boolean


SetCubeColors

Sets the list of colors given.

Property Type : write-only
Accepts : list


RefreshWithNewProperties

Refreshes the rubiks cube with new properties set.

AnimateMoveReversed

Animates in reverse (i.e. with opposite twisting direction) only the previous move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMove

Animates only the next move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMoveSequence

Animates all the moves in the currently set move sequence one move at a time. When a move has completed, the next one is automatically started.

SetMoveSequence

Sets the move sequence. Note you still have to use one of the blocks starting with animate.
Params

sequence | text


AnimateMoveSequenceReversed

Animates all the moves in the currently set move sequence one move at a time, in reverse (i.e. from end to start with opposite twisting direction).

SetupRubiksCube

Sets up Rubiks cube in a layout with porperties set.
Params

layout | component


SetDoubleRotationSpeed

Sets the rotation speed of a double rotation. This property allows to customize the speed of face turns separately from quarter turns.

Property Type : write-only
Accepts : number


SetFaceletsBorderColor

Sets border color of the facelets in rubik cube.

Property Type : write-only
Accepts : number


SetBackFacesDistance

Sets back faces distance from the cube. Typically, a value smaller than 2 means they won't be visible.

Property Type : write-only
Accepts : number


SetSingleRotationSpeed

Sets the rotation speed of a single rotation. This porperty allows to customize the speed of quarter turn separately from face turns.

Property Type : write-only
Accepts : number


SetBackgroundColor

Sets background colors of the rubik cube view.

Property Type : write-only
Accepts : number


SetEditable

Sets if rubiks cube can be changed by user or not.

Property Type : write-only
Accepts : boolean


SetCubeColors

Sets the list of colors given.

Property Type : write-only
Accepts : list


StopAnimation

Stops an in-progress animation. No operation if an animation is not in progress.

RefreshWithNewProperties

Refreshes the rubiks cube with new properties set.

AnimateMoveReversed

Animates in reverse (i.e. with opposite twisting direction) only the previous move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMove

Animates only the next move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMoveSequence

Animates all the moves in the currently set move sequence one move at a time. When a move has completed, the next one is automatically started.

ApplyMove

Instantly applies the next move on the cube, without animation.

ApplyMoveReversed

Instantly applies the previous move on reverse, on the cube, without animation.

SetMoveSequence

Sets the move sequence. Note you still have to use one of the blocks starting with animate.
Params

sequence | text


AnimateMoveSequenceReversed

Animates all the moves in the currently set move sequence one move at a time, in reverse (i.e. from end to start with opposite twisting direction).

ApplyMoveSequence

Instantly applies the whole move sequence on the cube, without animation.

SetupRubiksCube

Sets up Rubiks cube in a layout with porperties set.
Params

layout | component


SetDoubleRotationSpeed

Sets the rotation speed of a double rotation. This property allows to customize the speed of face turns separately from quarter turns.

Property Type : write-only
Accepts : number


SetFaceletsBorderColor

Sets border color of the facelets in rubik cube.

Property Type : write-only
Accepts : number


SetBackFacesDistance

Sets back faces distance from the cube. Typically, a value smaller than 2 means they won't be visible.

Property Type : write-only
Accepts : number


SetSingleRotationSpeed

Sets the rotation speed of a single rotation. This porperty allows to customize the speed of quarter turn separately from face turns.

Property Type : write-only
Accepts : number


SetBackgroundColor

Sets background colors of the rubik cube view.

Property Type : write-only
Accepts : number


SetEditable

Sets if rubiks cube can be changed by user or not.

Property Type : write-only
Accepts : boolean


SetCubeColors

Sets the list of colors given.

Property Type : write-only
Accepts : list


StopAnimation

Stops an in-progress animation. No operation if an animation is not in progress.

RefreshWithNewProperties

Refreshes the rubiks cube with new properties set.

AnimateMoveReversed

Animates in reverse (i.e. with opposite twisting direction) only the previous move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMove

Animates only the next move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMoveSequence

Animates all the moves in the currently set move sequence one move at a time. When a move has completed, the next one is automatically started.

ApplyMove

Instantly applies the next move on the cube, without animation.

ApplyMoveReversed

Instantly applies the previous move on reverse, on the cube, without animation.

SetMoveSequence

Sets the move sequence. Note you still have to use one of the blocks starting with animate.
Params

sequence | text


AnimateMoveSequenceReversed

Animates all the moves in the currently set move sequence one move at a time, in reverse (i.e. from end to start with opposite twisting direction).

ApplyMoveSequence

Instantly applies the whole move sequence on the cube, without animation.

SetupRubiksCube

Sets up Rubiks cube in a layout with porperties set.
Params

layout | component


ResetToInitialState

Resets the cube to solved position. Note : this does not include animation.

SetDoubleRotationSpeed

Sets the rotation speed of a double rotation. This property allows to customize the speed of face turns separately from quarter turns.

Property Type : write-only
Accepts : number


SetFaceletsBorderColor

Sets border color of the facelets in rubik cube.

Property Type : write-only
Accepts : number


SetBackFacesDistance

Sets back faces distance from the cube. Typically, a value smaller than 2 means they won't be visible.

Property Type : write-only
Accepts : number


SetSingleRotationSpeed

Sets the rotation speed of a single rotation. This porperty allows to customize the speed of quarter turn separately from face turns.

Property Type : write-only
Accepts : number


SetBackgroundColor

Sets background colors of the rubik cube view.

Property Type : write-only
Accepts : number


SetEditable

Sets if rubiks cube can be changed by user or not.

Property Type : write-only
Accepts : boolean


SetCubeColors

Sets the list of colors given.

Property Type : write-only
Accepts : list


StopAnimation

Stops an in-progress animation. No operation if an animation is not in progress.

RefreshWithNewProperties

Refreshes the rubiks cube with new properties set.

AnimateMoveReversed

Animates in reverse (i.e. with opposite twisting direction) only the previous move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMove

Animates only the next move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMoveSequence

Animates all the moves in the currently set move sequence one move at a time. When a move has completed, the next one is automatically started.

ApplyMove

Instantly applies the next move on the cube, without animation.

ApplyMoveReversed

Instantly applies the previous move on reverse, on the cube, without animation.

SetMoveSequence

Sets the move sequence. Note you still have to use one of the blocks starting with animate.
Params

sequence | text


AnimateMoveSequenceReversed

Animates all the moves in the currently set move sequence one move at a time, in reverse (i.e. from end to start with opposite twisting direction).

ApplyMoveSequence

Instantly applies the whole move sequence on the cube, without animation.

SetupRubiksCube

Sets up Rubiks cube in a layout with porperties set.
Params

layout | component


ResetToInitialState

Resets the cube to solved position. Note : this does not include animation.

SetDoubleRotationSpeed

Sets the rotation speed of a double rotation. This property allows to customize the speed of face turns separately from quarter turns.

Property Type : write-only
Accepts : number


SetFaceletsBorderColor

Sets border color of the facelets in rubik cube.

Property Type : write-only
Accepts : number


SetBackFacesDistance

Sets back faces distance from the cube. Typically, a value smaller than 2 means they won't be visible.

Property Type : write-only
Accepts : number


SetSingleRotationSpeed

Sets the rotation speed of a single rotation. This porperty allows to customize the speed of quarter turn separately from face turns.

Property Type : write-only
Accepts : number


SetBackgroundColor

Sets background colors of the rubik cube view.

Property Type : write-only
Accepts : number


SetEditable

Sets if rubiks cube can be changed by user or not.

Property Type : write-only
Accepts : boolean


SetCubeColors

Sets the list of colors given.

Property Type : write-only
Accepts : list


StopAnimation

Stops an in-progress animation. No operation if an animation is not in progress.

RefreshWithNewProperties

Refreshes the rubiks cube with new properties set.

AnimateMoveReversed

Animates in reverse (i.e. with opposite twisting direction) only the previous move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMove

Animates only the next move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMoveSequence

Animates all the moves in the currently set move sequence one move at a time. When a move has completed, the next one is automatically started.

ApplyMove

Instantly applies the next move on the cube, without animation.

ApplyMoveReversed

Instantly applies the previous move on reverse, on the cube, without animation.

SetMoveSequence

Sets the move sequence. Note you still have to use one of the blocks starting with animate.
Params

sequence | text


AnimateMoveSequenceReversed

Animates all the moves in the currently set move sequence one move at a time, in reverse (i.e. from end to start with opposite twisting direction).

ApplyMoveSequence

Instantly applies the whole move sequence on the cube, without animation.

SetupRubiksCube

Sets up Rubiks cube in a layout with porperties set.
Params

layout | component


ResetToInitialState

Resets the cube to solved position. Note : this does not include animation.

SetDoubleRotationSpeed

Sets the rotation speed of a double rotation. This property allows to customize the speed of face turns separately from quarter turns.

Property Type : write-only
Accepts : number


SetFaceletsBorderColor

Sets border color of the facelets in rubik cube.

Property Type : write-only
Accepts : number


SetBackFacesDistance

Sets back faces distance from the cube. Typically, a value smaller than 2 means they won't be visible.

Property Type : write-only
Accepts : number


SetSingleRotationSpeed

Sets the rotation speed of a single rotation. This porperty allows to customize the speed of quarter turn separately from face turns.

Property Type : write-only
Accepts : number


SetBackgroundColor

Sets background colors of the rubik cube view.

Property Type : write-only
Accepts : number


SetEditable

Sets if rubiks cube can be changed by user or not.

Property Type : write-only
Accepts : boolean


SetCubeColors

Sets the list of colors given.

Property Type : write-only
Accepts : list


StopAnimation

Stops an in-progress animation. No operation if an animation is not in progress.

RefreshWithNewProperties

Refreshes the rubiks cube with new properties set.

AnimateMoveReversed

Animates in reverse (i.e. with opposite twisting direction) only the previous move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMove

Animates only the next move from the move sequence. When it has completed, the next one is not automatically started.

AnimateMoveSequence

Animates all the moves in the currently set move sequence one move at a time. When a move has completed, the next one is automatically started.

ApplyMove

Instantly applies the next move on the cube, without animation.

ApplyMoveReversed

Instantly applies the previous move on reverse, on the cube, without animation.

SetMoveSequence

Sets the move sequence. Note you still have to use one of the blocks starting with animate.
Params

sequence | text


AnimateMoveSequenceReversed

Animates all the moves in the currently set move sequence one move at a time, in reverse (i.e. from end to start with opposite twisting direction).

ApplyMoveSequence

Instantly applies the whole move sequence on the cube, without animation.

SetupRubiksCube

Sets up Rubiks cube in a layout with porperties set.
Params

layout | component


ResetToInitialState

Resets the cube to solved position. Note : this does not include animation.

SetDoubleRotationSpeed

Sets the rotation speed of a double rotation. This property allows to customize the speed of face turns separately from quarter turns.

Property Type : write-only
Accepts : number


SetFaceletsBorderColor

Sets border color of the facelets in rubik cube.

Property Type : write-only
Accepts : number


SetBackFacesDistance

Sets back faces distance from the cube. Typically, a value smaller than 2 means they won't be visible.

Property Type : write-only
Accepts : number


SetSingleRotationSpeed

Sets the rotation speed of a single rotation. This porperty allows to customize the speed of quarter turn separately from face turns.

Property Type : write-only
Accepts : number


SetBackgroundColor

Sets background colors of the rubik cube view.

Property Type : write-only
Accepts : number


SetEditable

Sets if rubiks cube can be changed by user or not.

Property Type : write-only
Accepts : boolean


SetCubeColors

Sets the list of colors given.

Property Type : write-only
Accepts : list


Sorry, I am late, but it was fixed a long time ago.
You can download latest jar from here:

1 Like

In recent times, I started to like docs presented in tabular form.
So here is how you can create docs in a more beautiful way:

        public void addEvents(int index) throws ParseException {
            JSONObject object = (JSONObject) array.get(index);
            JSONArray array = (JSONArray) object.get("events");
            if (!array.isEmpty()) {
                for (Object item : array) {
                    JSONObject ob = (JSONObject) item;
                    builder.append("<tr><td><img class=\"wp-image-97\" style=\"width: 250px;\" src=\"https://sunnythedeveloper.in/wp-content/uploads/2023/06/Pasted.jpg\" alt=\"\"></td><td>");
                    builder.append(ob.get("description"));
                    JSONArray arr = (JSONArray) ob.get("params");
                    if (!arr.isEmpty()) {
                        builder.append("<br><em><sub>");
                        for (Object value : arr) {
                            JSONObject o = (JSONObject) value;
                            builder.append("<code>").append(o.get("name")).append(" | ");
                            builder.append(o.get("type")).append("</code><br>");
                        }
                        builder.append("</sub></em>");
                    }
                    builder.append("</td></tr>");
                }
            }
        }
        public void addMethods(int index) throws ParseException {
            JSONObject object = (JSONObject)array.get(index);
            JSONArray array = (JSONArray) object.get("methods");
            if (!array.isEmpty()) {
                for (Object item : array) {
                    JSONObject ob = (JSONObject) item;
                    builder.append("<tr><td><img class=\"wp-image-97\" style=\"width: 250px;\" src=\"https://sunnythedeveloper.in/wp-content/uploads/2023/06/Pasted.jpg\" alt=\"\"></td><td>");
                    builder.append(ob.get("description"));
                    JSONArray arr = (JSONArray) ob.get("params");
                    if (!arr.isEmpty()) {
                        builder.append("<br><em><sub>");
                        for (Object value : arr) {
                            JSONObject o = (JSONObject) value;
                            builder.append("<code>").append(o.get("name")).append(" | ");
                            builder.append(o.get("type")).append("</code><br>");
                        }
                        builder.append("</sub></em>");
                    }
                    /*if (ob.containsKey("returnType")){
                        String rType = String.valueOf(ob.get("returnType"));
                        builder.append("\n<i>Return type : ").append(rType.equalsIgnoreCase("any") ? "object":rType).append("</i>\n");
                    }*/
                    builder.append("</td></tr>");
                }
            }
        }
        public void addProperties(int index) throws ParseException {
            JSONObject object = (JSONObject)array.get(index);
            JSONArray array = (JSONArray) object.get("blockProperties");
            if (!array.isEmpty()) {
                for (Object item : array) {
                    JSONObject ob = (JSONObject) item;
                    builder.append("<tr><td><img class=\"wp-image-97\" style=\"width: 250px;\" src=\"https://sunnythedeveloper.in/wp-content/uploads/2023/06/Pasted.jpg\" alt=\"\"></td><td>");
                    builder.append(ob.get("description")).append("<br>");
                    if (ob.containsKey("rw")){
                        builder.append("<b>Property Type : ").append("</b>").append(ob.get("rw")).append("<br>");
                    }
                    if (ob.containsKey("type")){
                        builder.append("<b>Accepts : ").append("</b>").append(ob.get("type")).append("<br>");
                    }
                    builder.append("</td></tr>");
                }
            }
        }

Replace image src with your image's link.

A better one with block colors.

Does it highlight the text with block colors? I am asking this question because I don't understand what you mean by block colors :confused:

It'll look like this:

1 Like

When I go to download the latest version from Google Drive and run the JAR file, why does it say that a JNI and a JVM error had occured?

I have installed Java 1.8.0_271, checked java and javac version and they both are same (1.8.0_271)

Java 11 is required to run jar.

1 Like