diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OrganizeIncludesBlock.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OrganizeIncludesBlock.java index f16087f9a9b..c82bfe53231 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OrganizeIncludesBlock.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/preferences/OrganizeIncludesBlock.java @@ -73,22 +73,22 @@ public class OrganizeIncludesBlock extends OptionsConfigurationBlock { composite.setLayout(layout); Control control = addCheckBox(composite, PreferencesMessages.OrganizeIncludesBlock_allow_reordering, - KEY_INCLUDES_REORDERING, FALSE_TRUE, 0); + KEY_INCLUDES_REORDERING, TRUE_FALSE, 0); LayoutUtil.setHorizontalSpan(control, 2); control = addCheckBox(composite, PreferencesMessages.OrganizeIncludesBlock_heuristic_header_substitution, - KEY_HEURISTIC_HEADER_SUBSTITUTION, FALSE_TRUE, 0); + KEY_HEURISTIC_HEADER_SUBSTITUTION, TRUE_FALSE, 0); LayoutUtil.setHorizontalSpan(control, 2); control = addCheckBox(composite, PreferencesMessages.OrganizeIncludesBlock_forward_declare_composite_types, - KEY_FORWARD_DECLARE_COMPOSITE_TYPES, FALSE_TRUE, 0); + KEY_FORWARD_DECLARE_COMPOSITE_TYPES, TRUE_FALSE, 0); LayoutUtil.setHorizontalSpan(control, 2); control = addCheckBox(composite, PreferencesMessages.OrganizeIncludesBlock_forward_declare_enums, - KEY_FORWARD_DECLARE_ENUMS, FALSE_TRUE, 0); + KEY_FORWARD_DECLARE_ENUMS, TRUE_FALSE, 0); LayoutUtil.setHorizontalSpan(control, 2); control = addCheckBox(composite, PreferencesMessages.OrganizeIncludesBlock_forward_declare_functions, - KEY_FORWARD_DECLARE_FUNCTIONS, FALSE_TRUE, 0); + KEY_FORWARD_DECLARE_FUNCTIONS, TRUE_FALSE, 0); LayoutUtil.setHorizontalSpan(control, 2); control = addCheckBox(composite, PreferencesMessages.OrganizeIncludesBlock_forward_declare_namespace_elements, - KEY_FORWARD_DECLARE_NAMESPACE_ELEMENTS, FALSE_TRUE, 0); + KEY_FORWARD_DECLARE_NAMESPACE_ELEMENTS, TRUE_FALSE, 0); LayoutUtil.setHorizontalSpan(control, 2); control = addComboBox(composite, PreferencesMessages.OrganizeIncludesBlock_unused_statements, KEY_UNUSED_STATEMENTS_DISPOSITION, DISPOSITION_VALUES, DISPOSITION_LABELS, 0); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java index 6e4da24f873..87f92b7f119 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludeOrganizer.java @@ -288,12 +288,18 @@ public class IncludeOrganizer { } List includeDirectives = new ArrayList(); + IncludeGroupStyle previousParentStyle = null; for (List headers : orderedHeaders) { if (headers != null && !headers.isEmpty()) { Collections.sort(headers, PATH_COMPARATOR); IncludeGroupStyle style = classifiedHeaders.get(headers.get(0)); IncludeGroupStyle groupingStyle = getGroupingStyle(style); - if (!includeDirectives.isEmpty() && groupingStyle.isBlankLineBefore()) + IncludeGroupStyle parentStyle = getParentStyle(groupingStyle); + boolean blankLineBefore = groupingStyle.isBlankLineBefore() || + (parentStyle != null && parentStyle != previousParentStyle && + parentStyle.isKeepTogether() && parentStyle.isBlankLineBefore()); + previousParentStyle = parentStyle; + if (!includeDirectives.isEmpty() && blankLineBefore) includeDirectives.add(""); // Blank line separator //$NON-NLS-1$ for (IPath header : headers) { style = classifiedHeaders.get(header); @@ -335,15 +341,19 @@ public class IncludeOrganizer { private IncludeGroupStyle getGroupingStyle(IncludeGroupStyle style) { if (style.isKeepTogether()) return style; - IncludeKind kind = style.getIncludeKind().parent; - if (kind != null) { - IncludeGroupStyle parent = fContext.getPreferences().includeStyles.get(kind); - if (parent != null && (parent.isKeepTogether() || parent.getIncludeKind() == IncludeKind.OTHER)) - return parent; - } + IncludeGroupStyle parent = getParentStyle(style); + if (parent != null && (parent.isKeepTogether() || parent.getIncludeKind() == IncludeKind.OTHER)) + return parent; return fContext.getPreferences().includeStyles.get(IncludeKind.OTHER); } + private IncludeGroupStyle getParentStyle(IncludeGroupStyle style) { + IncludeKind kind = style.getIncludeKind().parent; + if (kind == null) + return null; + return fContext.getPreferences().includeStyles.get(kind); + } + private IncludeGroupStyle getIncludeStyle(IPath headerPath) { IncludeKind includeKind; IncludeInfo includeInfo = fContext.getIncludeForHeaderFile(headerPath); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludePreferences.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludePreferences.java index 03a06f8ac02..3a7fb38653e 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludePreferences.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/refactoring/includes/IncludePreferences.java @@ -54,6 +54,8 @@ public class IncludePreferences { loadStyle(IncludeKind.IN_SAME_PROJECT, PREF_INCLUDE_STYLE_SAME_PROJECT, project); loadStyle(IncludeKind.IN_OTHER_PROJECT, PREF_INCLUDE_STYLE_OTHER_PROJECT, project); loadStyle(IncludeKind.EXTERNAL, PREF_INCLUDE_STYLE_EXTERNAL, project); + // Unclassified includes are always kept together. + includeStyles.get(IncludeKind.OTHER).setKeepTogether(true); // Normalize order property of the styles to make sure that the numbers are sequential. List styles = new ArrayList(includeStyles.values()); Collections.sort(styles);