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:
* 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);
}

View file

@ -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,8 +703,11 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
// content type string
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType contentType = manager.getContentType(contentTypeId);
if (contentType != null) {
return LanguageManager.getInstance().getLanguage(contentType);
}
return null;
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#getContentTypeId()

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
* 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());
}
/**