From 06e1b830a8e843fb3dd25531eb02db4bc4afb778 Mon Sep 17 00:00:00 2001 From: Sergey Prigogin Date: Tue, 4 Jun 2013 18:15:51 -0700 Subject: [PATCH] Don't produce a blank line at the top of the file if file comment template is blank. Trim blank lines at the end of the file. --- .../corext/codemanipulation/StubUtility.java | 18 ++++++++++++++++-- .../templates/default-codetemplates.xml | 9 +++------ .../templates/default-filetemplates.xml | 1 - 3 files changed, 19 insertions(+), 9 deletions(-) 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} - */ + */ +