From 815f0df72f86d3bc96a45d46499ada8e93386c8d Mon Sep 17 00:00:00 2001 From: Markus Schorn Date: Fri, 29 Sep 2006 09:25:32 +0000 Subject: [PATCH] Fix for bug 158195, fallback for language of included files with unknown extension. --- .../internal/core/model/CModelManager.java | 10 +++++++--- .../internal/core/model/TranslationUnit.java | 19 +++++++++++-------- .../cdt/internal/core/model/WorkingCopy.java | 7 +++---- 3 files changed, 21 insertions(+), 15 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 e4a359c29bd..b8402f4238b 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 @@ -8,6 +8,7 @@ * Contributors: * QNX Software Systems - Initial API and implementation * James Blackburn - Modified patch for 149428 + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.model; @@ -413,10 +414,13 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe IIncludeReference[] includeReferences = cproject.getIncludeReferences(); for (int i = 0; i < includeReferences.length; i++) { if (includeReferences[i].isOnIncludeEntry(path)) { - String id = CoreModel.getRegistedContentTypeId(cproject.getProject(), path.lastSegment()); + IProject project= cproject.getProject(); + String id = CoreModel.getRegistedContentTypeId(project, path.lastSegment()); if (id == null) { - // fallback to C Header - id = CCorePlugin.CONTENT_TYPE_CHEADER; + // 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; } return new ExternalTranslationUnit(includeReferences[i], path, id); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java index 75922b24b10..bf95096134a 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java @@ -46,9 +46,9 @@ import org.eclipse.core.runtime.content.IContentTypeManager; */ public class TranslationUnit extends Openable implements ITranslationUnit { - IPath location = null; - String contentTypeId; - ILanguage language; + private IPath location = null; + private String contentTypeId; + private ILanguage language; /** * If set, this is the problem requestor which will be used to notify problems @@ -686,12 +686,12 @@ public class TranslationUnit extends Openable implements ITranslationUnit { // Special magic for C/C++ header files if (language == null && isHeaderUnit()) { - if (contentTypeId.equals(CCorePlugin.CONTENT_TYPE_CXXHEADER)) { - language= computeLanguage(CCorePlugin.CONTENT_TYPE_CXXSOURCE); - } - else { + if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(contentTypeId)) { language= computeLanguage(CCorePlugin.CONTENT_TYPE_CSOURCE); } + else if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(contentTypeId)) { + language= computeLanguage(CCorePlugin.CONTENT_TYPE_CXXSOURCE); + } } } @@ -703,7 +703,10 @@ public class TranslationUnit extends Openable implements ITranslationUnit { // content type string IContentTypeManager manager = Platform.getContentTypeManager(); IContentType contentType = manager.getContentType(contentTypeId); - return LanguageManager.getInstance().getLanguage(contentType); + if (contentType != null) { + return LanguageManager.getInstance().getLanguage(contentType); + } + return null; } /* (non-Javadoc) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java index ab50a643b3a..2c628927b52 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2005 IBM Corporation and others. + * Copyright (c) 2002, 2006 IBM Corporation and others. * 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 @@ -7,6 +7,7 @@ * * Contributors: * Rational Software - Initial API and implementation + * Markus Schorn (Wind River Systems) *******************************************************************************/ package org.eclipse.cdt.internal.core.model; @@ -16,7 +17,6 @@ import java.io.IOException; import java.util.ArrayList; import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.IBuffer; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICModelStatusConstants; @@ -225,8 +225,7 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy { * @see org.eclipse.cdt.core.model.IWorkingCopy#getOriginalElement() */ public ITranslationUnit getOriginalElement() { - String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), getElementName()); - return new TranslationUnit(getParent(), getFile(), id); + return new TranslationUnit(getParent(), getFile(), getContentTypeId()); } /**