mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 421544 - When searching for the target file for Toggle Source/Header,
prefer files closer to the origin file in the directory structure Change-Id: I82a3c1dc3f09cecb69e07511dd5b8bed62676b6a Signed-off-by: Nathan Ridge <zeratul976@hotmail.com>
This commit is contained in:
parent
91f4a98335
commit
5623c39492
4 changed files with 117 additions and 11 deletions
|
@ -18,6 +18,7 @@ import junit.framework.TestSuite;
|
|||
import org.eclipse.cdt.ui.tests.buildconsole.BuildConsoleTests;
|
||||
import org.eclipse.cdt.ui.tests.callhierarchy.CallHierarchyTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.chelp.CHelpTest;
|
||||
import org.eclipse.cdt.ui.tests.editor.EditorTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.includebrowser.IncludeBrowserTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.misc.MiscTestSuite;
|
||||
import org.eclipse.cdt.ui.tests.outline.OutlineTestSuite;
|
||||
|
@ -102,6 +103,9 @@ public class AutomatedSuite extends TestSuite {
|
|||
|
||||
// tests from package org.eclipse.cdt.ui.tests.misc
|
||||
addTest(MiscTestSuite.suite());
|
||||
|
||||
// tests from package org.eclipse.cdt.ui.tests.editor
|
||||
addTest(EditorTestSuite.suite());
|
||||
|
||||
addTest(AllTemplateEngineTests.suite());
|
||||
}
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Nathan Ridge.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Nathan Ridge - initial implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.editor;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
/**
|
||||
* Tests for functionality in the package org.eclipse.cdt.internal.ui.editor.
|
||||
*/
|
||||
public class EditorTestSuite extends TestSuite {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return new EditorTestSuite();
|
||||
}
|
||||
|
||||
public EditorTestSuite() {
|
||||
super(EditorTestSuite.class.getName());
|
||||
addTest(SourceHeaderPartnerFinderTest.suite());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2015 Nathan Ridge.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Nathan Ridge - initial implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.tests.editor;
|
||||
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.NullProgressMonitor;
|
||||
|
||||
import org.eclipse.cdt.core.dom.IPDOMManager;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.ui.tests.BaseUITestCase;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder;
|
||||
|
||||
/**
|
||||
* Tests for org.eclipse.cdt.internal.ui.editor.SourceHeaderPartnerFinder.
|
||||
*/
|
||||
public class SourceHeaderPartnerFinderTest extends BaseUITestCase {
|
||||
|
||||
public static TestSuite suite() {
|
||||
return suite(SourceHeaderPartnerFinderTest.class);
|
||||
}
|
||||
|
||||
protected static IProgressMonitor NPM= new NullProgressMonitor();
|
||||
|
||||
private ICProject fCProject;
|
||||
|
||||
public SourceHeaderPartnerFinderTest(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
fCProject= CProjectHelper.createCCProject(getName() + System.currentTimeMillis(), "bin",
|
||||
IPDOMManager.ID_FAST_INDEXER);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (fCProject != null) {
|
||||
CProjectHelper.delete(fCProject);
|
||||
}
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testFilesWithSameNameInSubdirectory_421544() throws Exception {
|
||||
IProject project = fCProject.getProject();
|
||||
IFile originFile = createFile(project, "code.cc", "");
|
||||
IFile expectedTargetFile = createFile(project, "code.h", "");
|
||||
createFile(project, "sub/code.cc", "");
|
||||
createFile(project, "sub/code.h", "");
|
||||
ITranslationUnit originTU = (ITranslationUnit) CoreModel.getDefault().create(originFile);
|
||||
ITranslationUnit targetTU = SourceHeaderPartnerFinder.getPartnerTranslationUnit(originTU);
|
||||
IFile targetFile = (IFile) targetTU.getResource();
|
||||
assertEquals(expectedTargetFile, targetFile);
|
||||
}
|
||||
}
|
|
@ -217,14 +217,19 @@ public final class SourceHeaderPartnerFinder {
|
|||
IResourceProxyVisitor visitor= new IResourceProxyVisitor() {
|
||||
@Override
|
||||
public boolean visit(IResourceProxy proxy) throws CoreException {
|
||||
if (result[0] != null) {
|
||||
return false;
|
||||
}
|
||||
if (!proxy.isAccessible()) {
|
||||
return false;
|
||||
}
|
||||
if (proxy.getType() == IResource.FILE && proxy.getName().equals(basename)) {
|
||||
result[0]= (IFile)proxy.requestResource();
|
||||
IFile candidate = (IFile) proxy.requestResource();
|
||||
if (result[0] == null) {
|
||||
result[0] = candidate;
|
||||
} else {
|
||||
// Prefer files closer to the root of the container.
|
||||
if (candidate.getFullPath().segmentCount() < result[0].getFullPath().segmentCount()) {
|
||||
result[0] = candidate;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -278,13 +283,10 @@ public final class SourceHeaderPartnerFinder {
|
|||
}
|
||||
IPath partnerBasePath= sourceFileLocation.removeFileExtension();
|
||||
IContentType[] contentTypes= getPartnerContentTypes(tu.getContentTypeId());
|
||||
HashSet<String> extensionsTried= new HashSet<String>();
|
||||
for (int j = 0; j < contentTypes.length; j++) {
|
||||
IContentType contentType= contentTypes[j];
|
||||
String[] partnerExtensions;
|
||||
partnerExtensions= contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
|
||||
for (int i= 0; i < partnerExtensions.length; i++) {
|
||||
String ext= partnerExtensions[i];
|
||||
HashSet<String> extensionsTried= new HashSet<>();
|
||||
for (IContentType contentType : contentTypes) {
|
||||
String[] partnerExtensions = contentType.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
|
||||
for (String ext : partnerExtensions) {
|
||||
if (extensionsTried.add(ext)) {
|
||||
String partnerFileBasename= partnerBasePath.addFileExtension(ext).lastSegment();
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue