mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 512150 - Don't allow indirect inclusion by partner header for test
files Change-Id: I6d0eb9078b92b4cf6e9345cc58824994dd679324
This commit is contained in:
parent
e431143a97
commit
f78a7306b3
3 changed files with 17 additions and 4 deletions
|
@ -40,6 +40,8 @@ import org.eclipse.cdt.internal.ui.refactoring.includes.IncludeGroupStyle.Includ
|
|||
import org.eclipse.cdt.internal.ui.refactoring.includes.IncludePreferences;
|
||||
|
||||
public class InclusionContext {
|
||||
private static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
||||
private static final IPath UNRESOLVED_INCLUDE = Path.EMPTY;
|
||||
|
||||
private final ITranslationUnit fTu;
|
||||
|
@ -255,6 +257,15 @@ public class InclusionContext {
|
|||
fPreferences.partnerFileSuffixes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the given path points to a close partner header of the current translation unit.
|
||||
* A header is considered a close partner if its name without extension is the same as the name of
|
||||
* the translation unit.
|
||||
*/
|
||||
public boolean isClosePartnerFile(IPath path) {
|
||||
return SourceHeaderPartnerFinder.isPartnerFile(getTranslationUnitLocation(), path, EMPTY_STRING_ARRAY);
|
||||
}
|
||||
|
||||
public IncludeInfo createIncludeInfo(IPath header, IncludeGroupStyle style) {
|
||||
String name = null;
|
||||
if (style.isRelativePath()) {
|
||||
|
|
|
@ -616,13 +616,13 @@ public class IncludeOrganizer {
|
|||
}
|
||||
|
||||
if (fContext.getPreferences().allowPartnerIndirectInclusion) {
|
||||
// Mark all headers included by the partner header as already included.
|
||||
// Mark all headers included by a close partner header as already included.
|
||||
if (partnerHeader == null) {
|
||||
for (IASTPreprocessorIncludeStatement include : existingIncludes) {
|
||||
if (include.isPartOfTranslationUnitFile()) {
|
||||
IIndexFile header = include.getImportedIndexFile();
|
||||
if (header != null) {
|
||||
if (fContext.isPartnerFile(new Path(include.getPath()))) {
|
||||
if (fContext.isClosePartnerFile(new Path(include.getPath()))) {
|
||||
partnerHeader = header;
|
||||
break;
|
||||
}
|
||||
|
@ -630,7 +630,8 @@ public class IncludeOrganizer {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (partnerHeader != null) {
|
||||
if (partnerHeader != null
|
||||
&& fContext.isClosePartnerFile(getAbsolutePath(partnerHeader.getLocation()))) {
|
||||
for (IIndexInclude include : partnerHeader.getIncludes()) {
|
||||
IIndexFileLocation headerLocation = include.getIncludesLocation();
|
||||
if (headerLocation != null) {
|
||||
|
|
|
@ -1982,7 +1982,8 @@ public class PreferenceConstants {
|
|||
public static final String INCLUDES_ALLOW_REORDERING = "organizeIncludes.allowReordering"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Whether indirect inclusion through a partner header file is allowed.
|
||||
* Whether indirect inclusion through a close partner header file is allowed. A header is considered
|
||||
* a close partner if its name without extension is the same as the name of the translation unit.
|
||||
*
|
||||
* @since 5.7
|
||||
*/
|
||||
|
|
Loading…
Add table
Reference in a new issue