diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java
index 8c78f87894a..a937b0ade25 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/corext/codemanipulation/StubUtility.java
@@ -212,8 +212,22 @@ public class StubUtility {
String[] fullLine= { CodeTemplateContextType.FILE_COMMENT };
String text = evaluateTemplate(context, template, fullLine);
- if (text != null && !text.endsWith(lineDelimiter))
- text += lineDelimiter;
+ if (text != null) {
+ // Remove blank lines at the end.
+ int len = text.length();
+ while (true) {
+ int offset = len - lineDelimiter.length();
+ if (!text.startsWith(lineDelimiter, offset))
+ break;
+ len = offset;
+ }
+ len += lineDelimiter.length();
+ if (len < text.length()) {
+ text = text.substring(0, len);
+ } else if (!text.endsWith(lineDelimiter)) {
+ text += lineDelimiter; // Add a line delimiter at the end.
+ }
+ }
return text;
}
diff --git a/core/org.eclipse.cdt.ui/templates/default-codetemplates.xml b/core/org.eclipse.cdt.ui/templates/default-codetemplates.xml
index 7efcef21724..eb158263cf2 100644
--- a/core/org.eclipse.cdt.ui/templates/default-codetemplates.xml
+++ b/core/org.eclipse.cdt.ui/templates/default-codetemplates.xml
@@ -30,7 +30,8 @@
*
* Created on: ${date}
* Author: ${user}
- */
+ */
+
${filecomment}
-
${includes}
${namespace_begin}
@@ -55,7 +55,6 @@ ${declarations}
${namespace_end}
${filecomment}
-
${includes}
${namespace_begin}
@@ -65,7 +64,6 @@ ${declarations}
${namespace_end}
${filecomment}
-
${includes}
${declarations}
${file_name}
-
Created on: ${date}
Author: ${user}