├── .gitignore ├── readme └── v1.0.0.gif ├── .vscode ├── settings.json ├── extensions.json └── launch.json ├── .vscodeignore ├── jsconfig.json ├── CHANGELOG.md ├── README.md ├── .eslintrc.json ├── test ├── extension.test.js └── index.js ├── LICENSE ├── package.json └── extension.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | *.vsix -------------------------------------------------------------------------------- /readme/v1.0.0.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/afmicc/getter-setter-generator/HEAD/readme/v1.0.0.gif -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | // Place your settings in this file to overwrite default and user settings. 2 | { 3 | } -------------------------------------------------------------------------------- /.vscodeignore: -------------------------------------------------------------------------------- 1 | .vscode/** 2 | .vscode-test/** 3 | test/** 4 | .gitignore 5 | jsconfig.json 6 | vsc-extension-quickstart.md 7 | .eslintrc.json 8 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | // See http://go.microsoft.com/fwlink/?LinkId=827846 3 | // for the documentation about the extensions.json format 4 | "recommendations": [ 5 | "dbaeumer.vscode-eslint" 6 | ] 7 | } -------------------------------------------------------------------------------- /jsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "module": "commonjs", 4 | "target": "es6", 5 | "checkJs": true, /* Typecheck .js files. */ 6 | "lib": [ 7 | "es6" 8 | ] 9 | }, 10 | "exclude": [ 11 | "node_modules" 12 | ] 13 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | ## [1.0.3] - 2020-01-20 4 | ### Changed 5 | - Names for boolean and Boolean types by [@WashingtonGuedes]https://github.com/WashingtonGuedes). 6 | 7 | ## [1.0.2] - 2019-08-21 8 | ### Changed 9 | - Splitting pattern. 10 | - Formatting added code. 11 | 12 | ## [1.0.1] - 2019-03-15 13 | ### Changed 14 | - Pascal case format. 15 | - Curly brackets according to java rule. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getter and Setter Generator 2 | ### Extension for Visual Studio Code 3 | This extension generate get and set methods from the class variable declarations. 4 | 5 | ## Usage 6 | ![how use](https://raw.githubusercontent.com/afmicc/getter-setter-generator/master/readme/v1.0.0.gif) 7 | 8 | ## Authors 9 | 10 | * afmicc - Extension 11 | 12 | ## License 13 | MIT © [afmicc](https://github.com/afmicc) 14 | 15 | **Enjoy!** 16 | -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": false, 4 | "commonjs": true, 5 | "es6": true, 6 | "node": true 7 | }, 8 | "parserOptions": { 9 | "ecmaFeatures": { 10 | "jsx": true 11 | }, 12 | "sourceType": "module" 13 | }, 14 | "rules": { 15 | "no-const-assign": "warn", 16 | "no-this-before-super": "warn", 17 | "no-undef": "warn", 18 | "no-unreachable": "warn", 19 | "no-unused-vars": "warn", 20 | "constructor-super": "warn", 21 | "valid-typeof": "warn" 22 | } 23 | } -------------------------------------------------------------------------------- /test/extension.test.js: -------------------------------------------------------------------------------- 1 | /* global suite, test */ 2 | 3 | // 4 | // Note: This example test is leveraging the Mocha test framework. 5 | // Please refer to their documentation on https://mochajs.org/ for help. 6 | // 7 | 8 | // The module 'assert' provides assertion methods from node 9 | const assert = require('assert'); 10 | 11 | // You can import and use all API from the 'vscode' module 12 | // as well as import your extension to test it 13 | // const vscode = require('vscode'); 14 | // const myExtension = require('../extension'); 15 | 16 | // Defines a Mocha test suite to group tests of similar kind together 17 | suite("Extension Tests", function() { 18 | 19 | // Defines a Mocha unit test 20 | test("Something 1", function() { 21 | assert.equal(-1, [1, 2, 3].indexOf(5)); 22 | assert.equal(-1, [1, 2, 3].indexOf(0)); 23 | }); 24 | }); -------------------------------------------------------------------------------- /.vscode/launch.json: -------------------------------------------------------------------------------- 1 | // A launch configuration that launches the extension inside a new window 2 | // Use IntelliSense to learn about possible attributes. 3 | // Hover to view descriptions of existing attributes. 4 | // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 5 | { 6 | "version": "0.2.0", 7 | "configurations": [ 8 | { 9 | "name": "Extension", 10 | "type": "extensionHost", 11 | "request": "launch", 12 | "runtimeExecutable": "${execPath}", 13 | "args": [ 14 | "--extensionDevelopmentPath=${workspaceFolder}" 15 | ] 16 | }, 17 | { 18 | "name": "Extension Tests", 19 | "type": "extensionHost", 20 | "request": "launch", 21 | "runtimeExecutable": "${execPath}", 22 | "args": [ 23 | "--extensionDevelopmentPath=${workspaceFolder}", 24 | "--extensionTestsPath=${workspaceFolder}/test" 25 | ] 26 | } 27 | ] 28 | } -------------------------------------------------------------------------------- /test/index.js: -------------------------------------------------------------------------------- 1 | // 2 | // PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING 3 | // 4 | // This file is providing the test runner to use when running extension tests. 5 | // By default the test runner in use is Mocha based. 6 | // 7 | // You can provide your own test runner if you want to override it by exporting 8 | // a function run(testRoot: string, clb: (error:Error) => void) that the extension 9 | // host can call to run the tests. The test runner is expected to use console.log 10 | // to report the results back to the caller. When the tests are finished, return 11 | // a possible error to the callback or null if none. 12 | 13 | const testRunner = require('vscode/lib/testrunner'); 14 | 15 | // You can directly control Mocha options by uncommenting the following lines 16 | // See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info 17 | testRunner.configure({ 18 | ui: 'tdd', // the TDD UI is being used in extension.test.js (suite, test, etc.) 19 | useColors: true // colored output from test results 20 | }); 21 | 22 | module.exports = testRunner; -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Agustin Martinez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GetterAndSetterGenerator", 3 | "displayName": "Getter and Setter Generator", 4 | "description": "This extension generate get and set methods from the class variable declarations.", 5 | "version": "1.0.3", 6 | "publisher": "afmicc", 7 | "repository": 8 | { 9 | "type": "git", 10 | "url": "https://github.com/afmicc/getter-setter-generator" 11 | }, 12 | "engines": { 13 | "vscode": "^1.20.0" 14 | }, 15 | "categories": [ 16 | "Other" 17 | ], 18 | "activationEvents": [ 19 | "onCommand:extension.generateGetterAndSetters" 20 | ], 21 | "main": "./extension", 22 | "contributes": { 23 | "commands": [{ 24 | "command": "extension.generateGetterAndSetters", 25 | "title": "Generate get and set methods" 26 | }] 27 | }, 28 | "scripts": { 29 | "postinstall": "node ./node_modules/vscode/bin/install", 30 | "test": "node ./node_modules/vscode/bin/test" 31 | }, 32 | "devDependencies": { 33 | "typescript": "^2.6.1", 34 | "vscode": "^1.1.6", 35 | "eslint": "^4.11.0", 36 | "@types/node": "^7.0.43", 37 | "@types/mocha": "^2.2.42" 38 | } 39 | } -------------------------------------------------------------------------------- /extension.js: -------------------------------------------------------------------------------- 1 | const vscode = require('vscode'); 2 | 3 | function activate(context) 4 | { 5 | 6 | let disposable = vscode.commands.registerCommand('extension.generateGetterAndSetters', function () 7 | { 8 | var editor = vscode.window.activeTextEditor; 9 | if (!editor) 10 | return; // No open text editor 11 | 12 | var selection = editor.selection; 13 | var text = editor.document.getText(selection); 14 | 15 | if (text.length < 1) 16 | { 17 | vscode.window.showErrorMessage('No selected properties.'); 18 | return; 19 | } 20 | 21 | try 22 | { 23 | var getterAndSetter = createGetterAndSetter(text); 24 | 25 | editor.edit( 26 | edit => editor.selections.forEach( 27 | selection => 28 | { 29 | edit.insert(selection.end, getterAndSetter); 30 | } 31 | ) 32 | ); 33 | 34 | // format getterAndSetter 35 | vscode.commands.executeCommand('editor.action.formatSelection'); 36 | } 37 | catch (error) 38 | { 39 | console.log(error); 40 | vscode.window.showErrorMessage('Something went wrong! Try that the properties are in this format: "private String name;"'); 41 | } 42 | }); 43 | 44 | context.subscriptions.push(disposable); 45 | } 46 | 47 | function toPascalCase(str) 48 | { 49 | return str.replace(/\w+/g,w => w[0].toUpperCase() + w.slice(1)); 50 | } 51 | 52 | function createGetterAndSetter(textPorperties) 53 | { 54 | var properties = textPorperties.split(/\r?\n/).filter(x => x.length > 2).map(x => x.replace(';', '')); 55 | 56 | var generatedCode = ` 57 | `; 58 | for (let p of properties) 59 | { 60 | while (p.startsWith(" ")) p = p.substr(1); 61 | while (p.startsWith("\t")) p = p.substr(1); 62 | 63 | let words = p.split(" ").map(x => x.replace(/\r?\n/, '')); 64 | let type, attribute, Attribute = ""; 65 | let create = false; 66 | 67 | // if words == ["private", "String", "name"]; 68 | if (words.length > 2) 69 | { 70 | type = words[1]; 71 | attribute = words[2]; 72 | Attribute = toPascalCase(words[2]); 73 | 74 | create = true; 75 | } 76 | // if words == ["String", "name"]; 77 | else if (words.length == 2) 78 | { 79 | type = words[0]; 80 | attribute = words[1]; 81 | Attribute = toPascalCase(words[1]); 82 | 83 | create = true; 84 | } 85 | // if words == ["name"]; 86 | else if (words.length) 87 | { 88 | type = "Object"; 89 | attribute = words[0]; 90 | Attribute = toPascalCase(words[0]); 91 | 92 | create = true; 93 | } 94 | 95 | if (create) 96 | { 97 | 98 | let code = 99 | ` 100 | \tpublic ${type} ${type.startsWith('bool') ? 'is' : 'get'}${Attribute}() { 101 | \t\treturn this.${attribute}; 102 | \t} 103 | 104 | \tpublic void set${Attribute}(${type} ${attribute}) { 105 | \t\tthis.${attribute} = ${attribute}; 106 | \t} 107 | `; 108 | generatedCode += code; 109 | } 110 | } 111 | 112 | return generatedCode; 113 | } 114 | 115 | exports.activate = activate; 116 | 117 | // this method is called when your extension is deactivated 118 | function deactivate() { } 119 | 120 | exports.deactivate = deactivate; --------------------------------------------------------------------------------