Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const vscode = require("vscode");
- class Analyzer {
- analyzeCode() {
- const editor = vscode.window.activeTextEditor;
- if (!editor) {
- vscode.window.showErrorMessage("There is no open text editor");
- return;
- }
- const doc = editor.document;
- const text = doc.getText();
- var fields = [];
- var publicMethods = [[]];
- var publicMethodCount = 0;
- var publicMethodBool = false;
- var privateMethods = [[]];
- var privateMethodCount = 0;
- var privateMethodBool = false;
- var constructor = [];
- var consructorBool = false;
- var classDeclaration = "";
- var className = "";
- var linesCount = text.split("\n").length;
- text.split("\n").map((codeLine, idx) => {
- if (idx == linesCount - 1) {
- return
- } else {
- if (codeLine.includes("public class")) {
- classDeclaration = codeLine;
- className = codeLine.slice(13);
- var brace = className.indexOf("{");
- className = className.substring(0, brace);
- if (className[className.length - 1] == ' ') {
- className = className.substring(0, className.length - 1);
- }
- } else {
- if (codeLine.includes("public") && codeLine.includes(className)) {
- consructorBool = true;
- constructor.push(codeLine);
- } else {
- if (consructorBool == true && !codeLine.includes("public") && !codeLine.includes("private")) {
- constructor.push(codeLine);
- return;
- }
- else {
- consructorBool = false;
- if ((codeLine.includes("public") || codeLine.includes("private")) && codeLine.includes(";")) {
- fields.push(codeLine);
- } else {
- if (codeLine.includes("public")) {
- publicMethodBool = true;
- publicMethodCount += 1;
- publicMethods[publicMethodCount - 1].push(codeLine);
- } else {
- if (publicMethodBool == true && !codeLine.includes("public") && !codeLine.includes("private")) {
- publicMethods[publicMethodCount - 1].push(codeLine);
- }
- else {
- publicMethodBool = false;
- if (codeLine.includes("private")) {
- privateMethodBool = true;
- privateMethodCount += 1;
- privateMethods[privateMethodCount - 1].push(codeLine);
- } else {
- if (privateMethodBool == true && !codeLine.includes("public") && !codeLine.includes("private")) {
- privateMethods[privateMethodCount - 1].push(codeLine);
- } else {
- privateMethodBool = false;
- }
- }
- }
- }
- }
- }
- }
- }
- }
- });
- var newText = "";
- newText += classDeclaration;
- newText += '\n';
- for (let i = 0; i < fields.length; i += 1) {
- newText += fields[i];
- }
- for (let i = 0; i < constructor.length; i += 1) {
- newText += constructor[i];
- }
- for (let i = 0; i < publicMethods.length; i += 1) {
- for (let j = 0; j < publicMethods[i].length; j += 1) {
- newText += publicMethods[i][j];
- }
- }
- for (let i = 0; i < privateMethods.length; i += 1) {
- for (let j = 0; j < privateMethods[i].length; j += 1) {
- newText += privateMethods[i][j];
- }
- }
- newText += "}";
- editor.edit(builder => builder.replace(editor.selection, newText));
- }
- }
- module.exports = Analyzer;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement