Извлеките все методы с их именами и телом из кода Java и перенаправьте в файл JSON - PullRequest
1 голос
/ 17 июня 2020

Я хочу извлечь имя методов и тело из заданного Java кода. Например, если у меня есть

public void addNode(int data) {    
    //Create a new node    
    Node newNode = new Node(data);    

    //Checks if the list is empty    
    if(head == null) {    
        //If list is empty, both head and tail will point to new node    
        head = newNode;    
        tail = newNode;    
    }    
    else {    
        //newNode will be added after tail such that tail's next will point to newNode    
        tail.next = newNode;    
        //newNode will become new tail of the list    
        tail = newNode;    
    }    
}    

//display() will display all the nodes present in the list    
public void display() {    
    //Node current will point to head    
    Node current = head;    

    if(head == null) {    
        System.out.println("List is empty");    
        return;    
    }    
    System.out.println("Nodes of singly linked list: ");    
    while(current != null) {    
        //Prints each node by incrementing pointer    
        System.out.print(current.data + " ");    
        current = current.next;    
    }    
    System.out.println();    
}    

, поэтому я хочу извлечь методы с их телом и перенаправить его в файл в формате json. Например, конечный результат должен быть таким:

{method 1: public void addNode(int data) { ......}
 method 2: public void display(){....}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...