1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-29 19:45:01 +02:00

Fix for bug 158195, fallback for language of included files with unknown extension.

This commit is contained in:
Markus Schorn 2006-09-29 09:25:32 +00:00
parent 75cbff035e
commit 815f0df72f
3 changed files with 21 additions and 15 deletions

View file

@ -8,6 +8,7 @@
* Contributors: * Contributors:
* QNX Software Systems - Initial API and implementation * QNX Software Systems - Initial API and implementation
* James Blackburn - Modified patch for 149428 * James Blackburn - Modified patch for 149428
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
@ -413,10 +414,13 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
IIncludeReference[] includeReferences = cproject.getIncludeReferences(); IIncludeReference[] includeReferences = cproject.getIncludeReferences();
for (int i = 0; i < includeReferences.length; i++) { for (int i = 0; i < includeReferences.length; i++) {
if (includeReferences[i].isOnIncludeEntry(path)) { 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) { if (id == null) {
// fallback to C Header // happens, when a translation unit for a file on the path is created, but
id = CCorePlugin.CONTENT_TYPE_CHEADER; // 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); return new ExternalTranslationUnit(includeReferences[i], path, id);
} }

View file

@ -46,9 +46,9 @@ import org.eclipse.core.runtime.content.IContentTypeManager;
*/ */
public class TranslationUnit extends Openable implements ITranslationUnit { public class TranslationUnit extends Openable implements ITranslationUnit {
IPath location = null; private IPath location = null;
String contentTypeId; private String contentTypeId;
ILanguage language; private ILanguage language;
/** /**
* If set, this is the problem requestor which will be used to notify problems * 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 // Special magic for C/C++ header files
if (language == null && isHeaderUnit()) { if (language == null && isHeaderUnit()) {
if (contentTypeId.equals(CCorePlugin.CONTENT_TYPE_CXXHEADER)) { if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(contentTypeId)) {
language= computeLanguage(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
}
else {
language= computeLanguage(CCorePlugin.CONTENT_TYPE_CSOURCE); 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 // content type string
IContentTypeManager manager = Platform.getContentTypeManager(); IContentTypeManager manager = Platform.getContentTypeManager();
IContentType contentType = manager.getContentType(contentTypeId); IContentType contentType = manager.getContentType(contentTypeId);
return LanguageManager.getInstance().getLanguage(contentType); if (contentType != null) {
return LanguageManager.getInstance().getLanguage(contentType);
}
return null;
} }
/* (non-Javadoc) /* (non-Javadoc)

View file

@ -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 * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,6 +7,7 @@
* *
* Contributors: * Contributors:
* Rational Software - Initial API and implementation * Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.core.model; package org.eclipse.cdt.internal.core.model;
@ -16,7 +17,6 @@ import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import org.eclipse.cdt.core.model.CModelException; 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.IBuffer;
import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICModelStatusConstants; 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() * @see org.eclipse.cdt.core.model.IWorkingCopy#getOriginalElement()
*/ */
public ITranslationUnit getOriginalElement() { public ITranslationUnit getOriginalElement() {
String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), getElementName()); return new TranslationUnit(getParent(), getFile(), getContentTypeId());
return new TranslationUnit(getParent(), getFile(), id);
} }
/** /**