mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Fix for 217860: toggle source/header switches to wrong source file
This commit is contained in:
parent
7a90025fb4
commit
7e9700c5a7
1 changed files with 24 additions and 11 deletions
|
@ -257,18 +257,31 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// search partner file based on filename/extension
|
||||||
|
ITranslationUnit partnerUnit= getPartnerFileFromFilename(tUnit);
|
||||||
|
|
||||||
|
if (partnerUnit == null) {
|
||||||
|
// search partner file based on definition/declaration association
|
||||||
IProgressMonitor monitor= new NullProgressMonitor();
|
IProgressMonitor monitor= new NullProgressMonitor();
|
||||||
PartnerFileComputer computer= new PartnerFileComputer();
|
PartnerFileComputer computer= new PartnerFileComputer();
|
||||||
ASTProvider.getASTProvider().runOnAST(tUnit, ASTProvider.WAIT_ACTIVE_ONLY, monitor, computer);
|
ASTProvider.getASTProvider().runOnAST(tUnit, ASTProvider.WAIT_ACTIVE_ONLY, monitor, computer);
|
||||||
IPath partnerFileLoation= computer.getPartnerFileLocation();
|
IPath partnerFileLoation= computer.getPartnerFileLocation();
|
||||||
if (partnerFileLoation != null) {
|
if (partnerFileLoation != null) {
|
||||||
ITranslationUnit partnerUnit= (ITranslationUnit) CoreModel.getDefault().create(partnerFileLoation);
|
partnerUnit= (ITranslationUnit) CoreModel.getDefault().create(partnerFileLoation);
|
||||||
if (partnerUnit == null) {
|
if (partnerUnit == null) {
|
||||||
partnerUnit= CoreModel.getDefault().createTranslationUnitFrom(tUnit.getCProject(), partnerFileLoation);
|
partnerUnit= CoreModel.getDefault().createTranslationUnitFrom(tUnit.getCProject(), partnerFileLoation);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return partnerUnit;
|
return partnerUnit;
|
||||||
}
|
}
|
||||||
// search partnerfile based on filename/extension
|
|
||||||
|
/**
|
||||||
|
* Find a partner translation unit based on filename/extension matching.
|
||||||
|
*
|
||||||
|
* @param a partner translation unit or <code>null</code>
|
||||||
|
*/
|
||||||
|
private ITranslationUnit getPartnerFileFromFilename(ITranslationUnit tUnit) {
|
||||||
IPath sourceFileLocation= tUnit.getLocation();
|
IPath sourceFileLocation= tUnit.getLocation();
|
||||||
if (sourceFileLocation == null) {
|
if (sourceFileLocation == null) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -300,7 +313,7 @@ public class ToggleSourceAndHeaderAction extends TextEditorAction {
|
||||||
}
|
}
|
||||||
// external tanslation unit - try in same directory
|
// external tanslation unit - try in same directory
|
||||||
if (tUnit.getResource() == null) {
|
if (tUnit.getResource() == null) {
|
||||||
partnerFileLoation= partnerBasePath.removeLastSegments(1).append(partnerFileBasename);
|
IPath partnerFileLoation= partnerBasePath.removeLastSegments(1).append(partnerFileBasename);
|
||||||
ITranslationUnit partnerUnit= CoreModel.getDefault().createTranslationUnitFrom(tUnit.getCProject(), partnerFileLoation);
|
ITranslationUnit partnerUnit= CoreModel.getDefault().createTranslationUnitFrom(tUnit.getCProject(), partnerFileLoation);
|
||||||
if (partnerUnit != null) {
|
if (partnerUnit != null) {
|
||||||
return partnerUnit;
|
return partnerUnit;
|
||||||
|
|
Loading…
Add table
Reference in a new issue