From 7a708e12e8bc8da43fc1e18944d53f6e96ef867c Mon Sep 17 00:00:00 2001 From: Anton Leherbauer Date: Mon, 2 Apr 2007 10:50:40 +0000 Subject: [PATCH] Fix for 178265: CModelManager#createTranslationUnitFrom only works for external header files, not source --- .../internal/core/model/CModelManager.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index 310ed66e091..24092979df6 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -9,6 +9,8 @@ * QNX Software Systems - Initial API and implementation * James Blackburn - Modified patch for 149428 * Markus Schorn (Wind River Systems) + * Anton Leherbauer (Wind River Systems) + * Warren Paul (Nokia) *******************************************************************************/ package org.eclipse.cdt.internal.core.model; @@ -408,39 +410,46 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe if (path == null || cproject == null) { return null; } + + final IProject project= cproject.getProject(); + final String contentTypeId = CoreModel.getRegistedContentTypeId(project, path.lastSegment()); + if (path.isAbsolute()) { if (! Util.isNonZeroLengthFile(path)) { return null; } + try { IIncludeReference[] includeReferences = cproject.getIncludeReferences(); for (int i = 0; i < includeReferences.length; i++) { if (includeReferences[i].isOnIncludeEntry(path)) { - IProject project= cproject.getProject(); - String id = CoreModel.getRegistedContentTypeId(project, path.lastSegment()); - if (id == null) { - // happens, when a translation unit for a file on the path is created, but - // the content-type is not registered for any language: - // fallback to C or C++ Header - id = CoreModel.hasCCNature(project) ? CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER; + String headerContentTypeId= contentTypeId; + if (headerContentTypeId == null) { + headerContentTypeId= CoreModel.hasCCNature(project) ? CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER; } - return new ExternalTranslationUnit(includeReferences[i], path, id); + return new ExternalTranslationUnit(includeReferences[i], path, headerContentTypeId); } } } catch (CModelException e) { } + + // if the file exists and it has a known C/C++ file extension then just create + // an external translation unit for it. + if (contentTypeId != null && path.toFile().exists()) { + return new ExternalTranslationUnit(cproject, path, contentTypeId); + } } else { + // !path.isAbsolute() try { IIncludeReference[] includeReferences = cproject.getIncludeReferences(); for (int i = 0; i < includeReferences.length; i++) { IPath includePath = includeReferences[i].getPath().append(path); if (Util.isNonZeroLengthFile(includePath)) { - String id = CoreModel.getRegistedContentTypeId(cproject.getProject(), includePath.lastSegment()); - if (id == null) { - // fallbakc to C Header - id = CCorePlugin.CONTENT_TYPE_CHEADER; + String headerContentTypeId= contentTypeId; + if (headerContentTypeId == null) { + headerContentTypeId= CoreModel.hasCCNature(project) ? CCorePlugin.CONTENT_TYPE_CXXHEADER : CCorePlugin.CONTENT_TYPE_CHEADER; } - return new ExternalTranslationUnit(includeReferences[i], includePath, id); + return new ExternalTranslationUnit(includeReferences[i], includePath, headerContentTypeId); } } } catch (CModelException e) {