mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-15 04:55:22 +02:00
Bug 416194 - Partner include should never be removed
This commit is contained in:
parent
ed07561521
commit
c6f0b99ab7
2 changed files with 25 additions and 3 deletions
|
@ -299,6 +299,26 @@ public class IncludeOrganizerTest extends IncludesTestBase {
|
||||||
assertExpectedResults();
|
assertExpectedResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//f.h
|
||||||
|
//void f(int p);
|
||||||
|
|
||||||
|
//f.cpp
|
||||||
|
//#include "f.h"
|
||||||
|
//void f(int p) {
|
||||||
|
//}
|
||||||
|
//====================
|
||||||
|
//#include "f.h"
|
||||||
|
//
|
||||||
|
//void f(int p) {
|
||||||
|
//}
|
||||||
|
public void testExistingPartnerIncludeIsNotRemoved() throws Exception {
|
||||||
|
IPreferenceStore preferenceStore = getPreferenceStore();
|
||||||
|
preferenceStore.setValue(PreferenceConstants.INCLUDES_UNUSED_STATEMENTS_DISPOSITION,
|
||||||
|
UnusedStatementDisposition.REMOVE.toString());
|
||||||
|
preferenceStore.setValue(PreferenceConstants.FORWARD_DECLARE_FUNCTIONS, true);
|
||||||
|
assertExpectedResults();
|
||||||
|
}
|
||||||
|
|
||||||
//h1.h
|
//h1.h
|
||||||
//class A {};
|
//class A {};
|
||||||
|
|
||||||
|
|
|
@ -264,7 +264,8 @@ public class IncludeOrganizer {
|
||||||
prototypes.add(prototype);
|
prototypes.add(prototype);
|
||||||
}
|
}
|
||||||
if (!allowReordering && prototype.getExistingInclude() != null
|
if (!allowReordering && prototype.getExistingInclude() != null
|
||||||
&& !prototype.isRequired() && prototype.getHeader() != null // Unused and resolved.
|
&& !prototype.isRequired() && prototype.getHeader() != null // Unused and resolved.
|
||||||
|
&& !fContext.isPartnerFile(prototype.getHeader())
|
||||||
&& isContainedInRegion(prototype.getExistingInclude(), includeReplacementRegion)) {
|
&& isContainedInRegion(prototype.getExistingInclude(), includeReplacementRegion)) {
|
||||||
switch (preferences.unusedStatementsDisposition) {
|
switch (preferences.unusedStatementsDisposition) {
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
|
@ -1082,8 +1083,9 @@ public class IncludeOrganizer {
|
||||||
|
|
||||||
private String createIncludeDirective(IncludePrototype include, String lineComment) {
|
private String createIncludeDirective(IncludePrototype include, String lineComment) {
|
||||||
StringBuilder buf = new StringBuilder();
|
StringBuilder buf = new StringBuilder();
|
||||||
// Unresolved includes are preserved out of caution.
|
// Unresolved includes are preserved out of caution. Partner include is always preserved.
|
||||||
if (!include.isRequired() && include.getHeader() != null) {
|
if (!include.isRequired() && include.getHeader() != null
|
||||||
|
&& !fContext.isPartnerFile(include.getHeader())) {
|
||||||
switch (fContext.getPreferences().unusedStatementsDisposition) {
|
switch (fContext.getPreferences().unusedStatementsDisposition) {
|
||||||
case REMOVE:
|
case REMOVE:
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue