1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Bug 45203. Work in progress.

Change-Id: Ib3ba9b36c2e699ae192b56fd4c011a4cfa9f6db5
This commit is contained in:
Sergey Prigogin 2013-02-14 20:43:15 -08:00
parent 3198d038d4
commit 1d9cb380ee
3 changed files with 25 additions and 13 deletions

View file

@ -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);

View file

@ -288,12 +288,18 @@ public class IncludeOrganizer {
}
List<String> includeDirectives = new ArrayList<String>();
IncludeGroupStyle previousParentStyle = null;
for (List<IPath> 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);

View file

@ -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<IncludeGroupStyle> styles = new ArrayList<IncludeGroupStyle>(includeStyles.values());
Collections.sort(styles);