Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

Commit 45ad2bf

Browse files
committed
Add Java template for singleton pattern, remove extra spacing in TypeScript singleton
1 parent cbd0f6d commit 45ad2bf

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

PRTTMPRPHT-JAVA.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<templateSet group="PRTTMPRPHT-JAVA">
2+
<template name="sing" value="public class $FILE_NAME$ {&#10; private static $FILE_NAME$ instance;&#10;&#10; private $FILE_NAME$() {}&#10;&#10; $END$&#10;&#10; public static $FILE_NAME$ get() {&#10; if (instance == null) {&#10; instance = new $FILE_NAME$();&#10; }&#10; return instance;&#10; }&#10;}" description="Singleton class" toReformat="false" toShortenFQNames="true">
3+
<variable name="FILE_NAME" expression="capitalize(camelCase(fileNameWithoutExtension()))" defaultValue="" alwaysStopAt="true" />
4+
<context>
5+
<option name="COMPLETION" value="false" />
6+
<option name="JAVA_CODE" value="true" />
7+
<option name="JAVA_COMMENT" value="false" />
8+
<option name="JAVA_CONSUMER" value="false" />
9+
<option name="JAVA_EXPRESSION" value="false" />
10+
<option name="JAVA_STATEMENT" value="false" />
11+
<option name="JAVA_STRING" value="false" />
12+
</context>
13+
</template>
14+
</templateSet>

PRTTMPRPHT-TS.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<templateSet group="PRTTMPRPHT-TS">
2-
<template name="sing" value="export class $FILE_NAME$ {&#10; private static instance: $FILE_NAME$;&#10;&#10; private constructor() {}&#10; &#10; $END$&#10; &#10; public static get(): $FILE_NAME$ {&#10; if (!$FILE_NAME$.instance) {&#10; $FILE_NAME$.instance = new $FILE_NAME$();&#10; }&#10; &#10; return $FILE_NAME$.instance;&#10; }&#10;}" description="Singleton class" toReformat="false" toShortenFQNames="true">
2+
<template name="sing" value="export class $FILE_NAME$ {&#10; private static instance: $FILE_NAME$;&#10;&#10; private constructor() {}&#10;&#10; $END$&#10;&#10; public static get(): $FILE_NAME$ {&#10; if (!$FILE_NAME$.instance) {&#10; $FILE_NAME$.instance = new $FILE_NAME$();&#10; }&#10;&#10; return $FILE_NAME$.instance;&#10; }&#10;}" description="Singleton class" toReformat="false" toShortenFQNames="true">
33
<variable name="FILE_NAME" expression="capitalize(camelCase(fileNameWithoutExtension()))" defaultValue="" alwaysStopAt="true" />
44
<context>
55
<option name="TypeScript" value="true" />

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,29 @@ public final native void set$NAME$(boolean $NAME_LC$)/*-{
250250
}-*/;
251251
```
252252

253+
### Java
254+
255+
#### sing
256+
257+
Basic singleton class. Name is derived from the file name.
258+
259+
```
260+
public class $FILE_NAME$ {
261+
private static $FILE_NAME$ instance;
262+
263+
private $FILE_NAME$() {}
264+
265+
$END$
266+
267+
public static $FILE_NAME$ get() {
268+
if (instance == null) {
269+
instance = new $FILE_NAME$();
270+
}
271+
return instance;
272+
}
273+
}
274+
```
275+
253276
### JavaScript
254277

255278
#### clof

0 commit comments

Comments
 (0)