Bug 478947 - Allow create .sh file outside shell project
Two problems for achieving it spotted in DLTK Core:
* ScriptModuleUtil.getFileExtensions documents being fine to return null
but doesn't handle the case where languageToolkit might be null which
results in NPE instead of returning null for file extension.
* NewSourceModulePage.getFileName adds dot at the end of the file if it
wasn't able to find any extension in either language toolkit or proposed
file name. As it is common use case to have shell scripts without
extension method is changed to not append "." (dot) at the end of the
file name if extension is empty.
Change-Id: I1926da8782b01da09e24169bab735cfd441a9c4d
Signed-off-by: Alexander Kurtakov <akurtako@redhat.com>
diff --git a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/wizards/NewSourceModulePage.java b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/wizards/NewSourceModulePage.java
index 1cb6cfd..86ddf64 100644
--- a/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/wizards/NewSourceModulePage.java
+++ b/core/plugins/org.eclipse.dltk.ui/src/org/eclipse/dltk/ui/wizards/NewSourceModulePage.java
@@ -699,11 +699,13 @@
String[] extensions = getFileExtensions();
for (int i = 0; i < extensions.length; ++i) {
String extension = extensions[i];
- if (extension.length() > 0 && fileText.endsWith("." + extension)) { //$NON-NLS-1$
+ if (!extension.isEmpty() && fileText.endsWith("." + extension)) { //$NON-NLS-1$
return fileText;
}
}
-
+ if (extensions[0].isEmpty()) {
+ return fileText;
+ }
return fileText + "." + extensions[0]; //$NON-NLS-1$
}
@@ -712,9 +714,11 @@
IDLTKLanguageToolkit toolkit = DLTKLanguageManager
.getLanguageToolkit(requiredNature);
- String[] extensions = ScriptModelUtil.getFileExtensions(toolkit);
- if (extensions != null) {
- return extensions;
+ if (toolkit != null) {
+ String[] extensions = ScriptModelUtil.getFileExtensions(toolkit);
+ if (extensions != null) {
+ return extensions;
+ }
}
return new String[] { Util.EMPTY_STRING };