├── settings.zip ├── load_bytes └── example.gif ├── entity_uuid └── example.gif ├── slf4j_logger └── example.gif ├── test_method └── example.gif ├── test_mvc_method └── example.gif ├── test_resource_file └── example.gif ├── .gitignore ├── LICENSE ├── custom.xml └── README.md /settings.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrTimeey/java-live-templates/HEAD/settings.zip -------------------------------------------------------------------------------- /load_bytes/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrTimeey/java-live-templates/HEAD/load_bytes/example.gif -------------------------------------------------------------------------------- /entity_uuid/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrTimeey/java-live-templates/HEAD/entity_uuid/example.gif -------------------------------------------------------------------------------- /slf4j_logger/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrTimeey/java-live-templates/HEAD/slf4j_logger/example.gif -------------------------------------------------------------------------------- /test_method/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrTimeey/java-live-templates/HEAD/test_method/example.gif -------------------------------------------------------------------------------- /test_mvc_method/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrTimeey/java-live-templates/HEAD/test_mvc_method/example.gif -------------------------------------------------------------------------------- /test_resource_file/example.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MrTimeey/java-live-templates/HEAD/test_resource_file/example.gif -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | HELP.md 2 | target/ 3 | !.mvn/wrapper/maven-wrapper.jar 4 | !**/src/main/**/target/ 5 | !**/src/test/**/target/ 6 | 7 | ### STS ### 8 | .apt_generated 9 | .classpath 10 | .factorypath 11 | .project 12 | .settings 13 | .springBeans 14 | .sts4-cache 15 | 16 | ### IntelliJ IDEA ### 17 | .idea 18 | *.iws 19 | *.iml 20 | *.ipr 21 | 22 | ### NetBeans ### 23 | /nbproject/private/ 24 | /nbbuild/ 25 | /dist/ 26 | /nbdist/ 27 | /.nb-gradle/ 28 | build/ 29 | !**/src/main/**/build/ 30 | !**/src/test/**/build/ 31 | 32 | ### VS Code ### 33 | .vscode/ 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Tim Siegler 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 | -------------------------------------------------------------------------------- /custom.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 17 | 22 | 28 | 34 | 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Custom Live Templates for Java 2 | 3 | These are my custom [IntelliJ IDEA Live Templates](https://www.jetbrains.com/help/idea/using-live-templates.html) for Java that i'm currently using. 4 | 5 | I thought some of them might be helpful for others so i shared them. If you got other cool custom Java live templates which you want to share, feel free to contribute! 6 | 7 | ## Export and Import 8 | All these custom live templates are placed in a custom group. According to [sharing live templates](https://www.jetbrains.com/help/idea/sharing-live-templates.html) I've selected only the live templates and created an export. You can import these settings if you want to get all these templates. 9 | Furthermore I've added the templates config file from the IDEA settings. Copy this file to your IDEA settings directory and you are ready to go. 10 | 11 | If you just want to add a single live template you can also create it manually. 12 | 13 | ## Java 14 | The live templates are all applicable in Java classes. 15 | 16 | ### JUnit Test Method 17 | Simple test method generation with imported `assertThat` from AssertJ. 18 | 19 | ![Generate simple test method](test_method/example.gif) 20 | 21 | Abbreviation: __test__ 22 | Template text: 23 | ``` 24 | @org.junit.jupiter.api.Test 25 | void test$Function$() throws java.io.IOException { 26 | org.assertj.core.api.Assertions.assertThat("").isEqualTo("false"); 27 | } 28 | ``` 29 | Options: 30 | - [x] Reformat according to style 31 | - [x] Use static import if possible 32 | - [x] Shorten FQ names 33 | 34 | ### JUnit Test Method with MockMvc 35 | Test method generation with imported `MockMvc` from Spring. 36 | 37 | ![Generate mockmvc test method](test_mvc_method/example.gif) 38 | 39 | Abbreviation: __testmvc__ 40 | Template text: 41 | ``` 42 | @org.springframework.beans.factory.annotation.Autowired 43 | private org.springframework.test.web.servlet.MockMvc mockMvc; 44 | 45 | @org.junit.jupiter.api.Test 46 | void test$Function$() throws java.lang.Exception { 47 | org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder request = org.springframework.test.web.servlet.request.MockMvcRequestBuilders 48 | .get("") 49 | .contentType(org.springframework.http.MediaType.APPLICATION_JSON); 50 | 51 | mockMvc.perform(request) 52 | .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status().isOk()) 53 | .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content().contentType(org.springframework.http.MediaType.APPLICATION_JSON)) 54 | .andExpect(org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath("", org.hamcrest.Matchers.is(""))); 55 | } 56 | ``` 57 | Options: 58 | - [x] Reformat according to style 59 | - [ ] Use static import if possible 60 | - [x] Shorten FQ names 61 | 62 | ### Create SLF4J-Logger 63 | Creates SLF4J logger and adds the static imports. 64 | 65 | ![Generate simple test method](slf4j_logger/example.gif) 66 | 67 | Abbreviation: __log__ 68 | 69 | Template text: 70 | ```java 71 | private static final org.slf4j.Logger LOGGER = org.slf4j.LoggerFactory.getLogger($CLASS$.class); 72 | ``` 73 | Options: 74 | - [x] Reformat according to style 75 | - [ ] Use static import if possible 76 | - [x] Shorten FQ names 77 | 78 | ### Load file from resources directory (for test) 79 | Load a file from resources directory. Often used in tests to load expected data or other files. 80 | Do not use in production code because it will result into an ``IllegalArgumentException``. 81 | 82 | ![Load resource file](test_resource_file/example.gif) 83 | 84 | Abbreviation: __testfile__ 85 | 86 | Template text: 87 | ``` 88 | java.net.URL resource = getClass().getResource("$Function$"); 89 | java.nio.file.Path filePath = java.nio.file.Paths.get(resource.toURI()); 90 | ``` 91 | Options: 92 | - [x] Reformat according to style 93 | - [ ] Use static import if possible 94 | - [x] Shorten FQ names 95 | 96 | ### Load byte[] from resources directory 97 | Loads byte[] from resources directory. 98 | 99 | ![Load bytes from resource file](load_bytes/example.gif) 100 | 101 | Abbreviation: __bytesfile__ 102 | 103 | Template text: 104 | ``` 105 | try (java.io.InputStream is = getClass().getClassLoader().getResourceAsStream("$Function$")) { 106 | byte[] bytes = is.readAllBytes(); 107 | } 108 | ``` 109 | Options: 110 | - [x] Reformat according to style 111 | - [ ] Use static import if possible 112 | - [x] Shorten FQ names 113 | 114 | 115 | ### Create UUID for Spring Data Entity 116 | Creates ID field for entity class which will be auto generated as UUID. 117 | 118 | ![Generate UUID id field for entity](entity_uuid/example.gif) 119 | 120 | Abbreviation: __id__ 121 | 122 | Template text: 123 | ``` 124 | @javax.persistence.Id 125 | @javax.persistence.GeneratedValue(generator = "system-uuid") 126 | @org.hibernate.annotations.GenericGenerator(name = "system-uuid", strategy = "uuid") 127 | private String id; 128 | 129 | 130 | ``` 131 | Options: 132 | - [x] Reformat according to style 133 | - [ ] Use static import if possible 134 | - [x] Shorten FQ names 135 | 136 | Applicable: Java - declartion 137 | 138 | ## Contributing 139 | Want to add some more live templates? Send a pull request or open a ticket! 140 | --------------------------------------------------------------------------------