11diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java
2- index 891bfa328d..91172fda4b 100644
2+ index 891bfa328d..2370891a9b 100644
33--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java
44+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/protocol/LspTemplateUI.java
55@@ -27,6 +27,7 @@ import java.net.MalformedURLException;
@@ -10,15 +10,20 @@ index 891bfa328d..91172fda4b 100644
1010 import java.util.ArrayList;
1111 import java.util.Arrays;
1212 import java.util.Collections;
13- @@ -39,6 +40,7 @@ import java.util.function.Function;
13+ @@ -39,9 +40,12 @@ import java.util.function.Function;
1414 import java.util.logging.Level;
1515 import java.util.logging.Logger;
1616 import java.util.stream.Collectors;
1717+ import javax.lang.model.SourceVersion;
1818 import org.eclipse.lsp4j.ExecuteCommandParams;
19+ + import org.eclipse.lsp4j.MessageActionItem;
1920 import org.eclipse.lsp4j.MessageParams;
2021 import org.eclipse.lsp4j.MessageType;
21- @@ -73,14 +75,21 @@ import org.openide.util.Utilities;
22+ + import org.eclipse.lsp4j.ShowMessageRequestParams;
23+ import org.eclipse.lsp4j.WorkspaceFolder;
24+ import org.netbeans.api.project.FileOwnerQuery;
25+ import org.netbeans.api.project.Project;
26+ @@ -73,14 +77,25 @@ import org.openide.util.Utilities;
2227 "CTL_TemplateUI_SelectGroup=Select Template Type",
2328 "CTL_TemplateUI_SelectTemplate=Select Template",
2429 "CTL_TemplateUI_SelectTarget=Where to put the object?",
@@ -27,6 +32,10 @@ index 891bfa328d..91172fda4b 100644
2732 "CTL_TemplateUI_SelectPackageName=Package name of your project?",
2833 "CTL_TemplateUI_SelectPackageNameSuggestion=org.yourcompany.yourproject",
2934 "CTL_TemplateUI_SelectName=Name of the object?",
35+ + "PROMPT_AskObjectNameWarningConfirmation=Object name contains $, not recommended for user defined objects , "
36+ + + "Do you want to continue with the current name or try again ?",
37+ + "PROMPT_AskObjectNameWarningConfirmation_Continue=Continue",
38+ + "PROMPT_AskObjectNameWarningConfirmation_TryAgain=Try again",
3039 "# {0} - path",
3140- "ERR_InvalidPath={0} isn't valid folder",
3241+ "ERR_InvalidPath={0} isn't a valid folder or is read-only",
@@ -42,7 +51,7 @@ index 891bfa328d..91172fda4b 100644
4251 })
4352 final class LspTemplateUI {
4453 /**
45- @@ -165,8 +174 ,20 @@ final class LspTemplateUI {
54+ @@ -165,8 +180 ,20 @@ final class LspTemplateUI {
4655 }
4756
4857 private static CompletionStage<String> findPackage(CompletionStage<?> uiBefore, NbCodeLanguageClient client) {
@@ -65,7 +74,7 @@ index 891bfa328d..91172fda4b 100644
6574 );
6675 }
6776
68- @@ -188,8 +209 ,9 @@ final class LspTemplateUI {
77+ @@ -188,8 +215 ,9 @@ final class LspTemplateUI {
6978 if (path == null) {
7079 throw raise(RuntimeException.class, new UserCancelException(path));
7180 }
@@ -77,7 +86,7 @@ index 891bfa328d..91172fda4b 100644
7786 client.showMessage(new MessageParams(MessageType.Error, Bundle.ERR_InvalidPath(path)));
7887 return client.showInputBox(new ShowInputBoxParams(Bundle.CTL_TemplateUI_SelectTarget(), suggestion.getPrimaryFile().getPath())).thenCompose(this);
7988 }
80- @@ -202,7 +224 ,7 @@ final class LspTemplateUI {
89+ @@ -202,7 +230 ,7 @@ final class LspTemplateUI {
8190
8291 private static CompletionStage<Pair<DataFolder, String>> findTargetAndNameForProject(CompletionStage<DataObject> findTemplate, NbCodeLanguageClient client) {
8392 return findTemplate.thenCompose(__ -> client.workspaceFolders()).thenCompose(folders -> {
@@ -86,7 +95,7 @@ index 891bfa328d..91172fda4b 100644
8695 @Override
8796 public CompletionStage<Pair<DataFolder,String>> apply(String path) {
8897 if (path == null) {
89- @@ -215,12 +237 ,14 @@ final class LspTemplateUI {
98+ @@ -215,12 +243 ,14 @@ final class LspTemplateUI {
9099 }
91100 targetPath.getParentFile().mkdirs();
92101 FileObject fo = FileUtil.toFileObject(targetPath.getParentFile());
@@ -103,7 +112,7 @@ index 891bfa328d..91172fda4b 100644
103112 });
104113 }
105114
106- @@ -229,9 +253,23 @@ final class LspTemplateUI {
115+ @@ -229,9 +259,35 @@ final class LspTemplateUI {
107116 FileObject template = desc.getTemplate();
108117 Object handler = template.getAttribute(FileBuilder.ATTR_TEMPLATE_HANDLER);
109118 if (handler == null) {
@@ -119,6 +128,18 @@ index 891bfa328d..91172fda4b 100644
119128+ {
120129+ client.showMessage(new MessageParams(MessageType.Error,Bundle.ERR_InvalidObjectName(name)));
121130+ return client.showInputBox(new ShowInputBoxParams(Bundle.CTL_TemplateUI_SelectName(), desc.getProposedName())).thenCompose(this);
131+ + } else if (name.contains("$")) {
132+ + final MessageActionItem continueAction = new MessageActionItem(Bundle.PROMPT_AskObjectNameWarningConfirmation_Continue());
133+ + final MessageActionItem tryAgain = new MessageActionItem(Bundle.PROMPT_AskObjectNameWarningConfirmation_TryAgain());
134+ + ShowMessageRequestParams smrp = new ShowMessageRequestParams(Arrays.asList(continueAction, tryAgain));
135+ + smrp.setMessage(Bundle.PROMPT_AskObjectNameWarningConfirmation());
136+ + smrp.setType(MessageType.Warning);
137+ + return client.showMessageRequest(smrp).thenCompose(ai -> {
138+ + if(ai==null) throw raise(RuntimeException.class, new UserCancelException(""));
139+ + return ai.equals(continueAction) ?
140+ + CompletableFuture.completedFuture(name) :
141+ + client.showInputBox(new ShowInputBoxParams(Bundle.CTL_TemplateUI_SelectName(), desc.getProposedName())).thenCompose(this);
142+ + });
122143+ }
123144+ return CompletableFuture.completedFuture(name);
124145+ }
@@ -130,7 +151,7 @@ index 891bfa328d..91172fda4b 100644
130151 }
131152 return CompletableFuture.completedFuture(builder);
132153 }
133- @@ -242,7 +280 ,7 @@ final class LspTemplateUI {
154+ @@ -242,7 +298 ,7 @@ final class LspTemplateUI {
134155 suggestion = Utilities.toFile(new URI(folders.get(0).getUri())).getParent();
135156 } catch (URISyntaxException ex) {
136157 }
0 commit comments