1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Fix for 132201, prefer content types with a case-sensitive match.

This commit is contained in:
Markus Schorn 2006-07-11 15:08:57 +00:00
parent 468da823b3
commit b259cae666
11 changed files with 217 additions and 182 deletions

View file

@ -7,12 +7,11 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.model;
import java.util.ArrayList;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
@ -50,8 +49,8 @@ public class CoreModel {
private static CoreModel cmodel = null;
private static CModelManager manager = CModelManager.getDefault();
private static PathEntryManager pathEntryManager = PathEntryManager.getDefault();
private static String FILE_EXT_PATTERN = "*."; //$NON-NLS-1$
private static int FILE_EXT_PATTERN_LENGTH = FILE_EXT_PATTERN.length();
// private static String FILE_EXT_PATTERN = "*."; //$NON-NLS-1$
// private static int FILE_EXT_PATTERN_LENGTH = FILE_EXT_PATTERN.length();
public final static String CORE_MODEL_ID = CCorePlugin.PLUGIN_ID + ".coremodel"; //$NON-NLS-1$
@ -187,10 +186,7 @@ public class CoreModel {
* @return String[] ids
*/
public static String[] getRegistedContentTypeIds() {
ArrayList a = LanguageManager.getInstance().getAllContentTypes();
String[] result = new String[a.size()];
a.toArray(result);
return result;
return LanguageManager.getInstance().getRegisteredContentTypeIds();
}
/**

View file

@ -6,14 +6,17 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* QNX - Initial API and implementation
* QNX - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.model;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
@ -51,7 +54,7 @@ public class LanguageManager {
IConfigurationElement[] languages = extension.getConfigurationElements();
for (int j = 0; j < languages.length; ++j) {
IConfigurationElement languageElem = languages[j];
String langId = extension.getNamespace() + "." + languageElem.getAttribute("id"); //$NON-NLS-1$ $NON-NLS-2$
String langId = extension.getNamespaceIdentifier() + "." + languageElem.getAttribute("id"); //$NON-NLS-1$ //$NON-NLS-2$ $NON-NLS-2$
if (langId.equals(id)) {
language = (ILanguage)languageElem.createExecutableExtension("class"); //$NON-NLS-1$
cache.put(id, language);
@ -64,7 +67,6 @@ public class LanguageManager {
}
public ILanguage getLanguage(IContentType contentType) throws CoreException {
IContentTypeManager manager = Platform.getContentTypeManager();
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ILanguage.KEY);
IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; ++i) {
@ -73,8 +75,7 @@ public class LanguageManager {
IConfigurationElement language = languages[j];
IConfigurationElement[] contentTypes = language.getChildren("contentType"); //$NON-NLS-1$
for (int k = 0; k < contentTypes.length; ++k) {
IContentType langContType = manager.getContentType(contentTypes[k].getAttribute("id")); //$NON-NLS-1$
if (contentType.equals(langContType)) {
if (contentType.equals(contentType.getId())) {
return (ILanguage)language.createExecutableExtension("class"); //$NON-NLS-1$
}
}
@ -83,6 +84,9 @@ public class LanguageManager {
return null;
}
/**
* @deprecated use getRegisteredContentTypes() instead.
*/
public ArrayList/*<String>*/ getAllContentTypes() {
ArrayList/*<String>*/ allTypes = new ArrayList();
allTypes.add(CCorePlugin.CONTENT_TYPE_ASMSOURCE);
@ -109,8 +113,43 @@ public class LanguageManager {
return allTypes;
}
/**
* Returns all content types that are registered with CDT.
* @since 3.1.1
*/
public String[] getRegisteredContentTypeIds() {
Set contentTypes= collectContentTypeIds();
return (String[]) contentTypes.toArray(new String[contentTypes.size()]);
}
private Set collectContentTypeIds() {
HashSet/*<String>*/ allTypes = new HashSet();
allTypes.add(CCorePlugin.CONTENT_TYPE_ASMSOURCE);
allTypes.add(CCorePlugin.CONTENT_TYPE_CHEADER);
allTypes.add(CCorePlugin.CONTENT_TYPE_CSOURCE);
allTypes.add(CCorePlugin.CONTENT_TYPE_CXXHEADER);
allTypes.add(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
IContentTypeManager manager = Platform.getContentTypeManager();
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, ILanguage.KEY);
IExtension[] extensions = point.getExtensions();
for (int i = 0; i < extensions.length; ++i) {
IConfigurationElement[] languages = extensions[i].getConfigurationElements();
for (int j = 0; j < languages.length; ++j) {
IConfigurationElement language = languages[j];
IConfigurationElement[] contentTypes = language.getChildren("contentType"); //$NON-NLS-1$
for (int k = 0; k < contentTypes.length; ++k) {
IContentType langContType = manager.getContentType(contentTypes[k].getAttribute("id")); //$NON-NLS-1$
allTypes.add(langContType.getId());
}
}
}
return allTypes;
}
public boolean isContributedContentType(String contentTypeId) {
return getAllContentTypes().contains(contentTypeId);
return collectContentTypeIds().contains(contentTypeId);
}
public IContributedModelBuilder getContributedModelBuilderFor(TranslationUnit tu) {

View file

@ -7,6 +7,7 @@
*
* Contributors:
* QNX Software Systems - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.core.model;
@ -17,7 +18,6 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
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.IContributedModelBuilder;
@ -682,25 +682,30 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
public ILanguage getLanguage() throws CoreException {
if (language == null) {
// Look for the language extension registered against the
// content type string
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType contentType = manager.getContentType(contentTypeId);
language = LanguageManager.getInstance().getLanguage(contentType);
language= computeLanguage(contentTypeId);
// Special magic for C/C++ header files
if (language == null && isHeaderUnit()) {
IResource resource = getResource();
contentType = resource != null && CoreModel.hasCCNature(resource.getProject())
? manager.getContentType(CCorePlugin.CONTENT_TYPE_CXXSOURCE)
: manager.getContentType(CCorePlugin.CONTENT_TYPE_CSOURCE);
language = LanguageManager.getInstance().getLanguage(contentType);
if (contentTypeId.equals(CCorePlugin.CONTENT_TYPE_CXXHEADER)) {
language= computeLanguage(CCorePlugin.CONTENT_TYPE_CXXSOURCE);
}
else {
language= computeLanguage(CCorePlugin.CONTENT_TYPE_CSOURCE);
}
}
}
return language;
}
private ILanguage computeLanguage(String contentTypeId) throws CoreException {
// Look for the language extension registered against the
// content type string
IContentTypeManager manager = Platform.getContentTypeManager();
IContentType contentType = manager.getContentType(contentTypeId);
return LanguageManager.getInstance().getLanguage(contentType);
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#getContentTypeId()
*/
@ -734,7 +739,6 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
try {
this.getElementInfo().setIsStructureKnown(wasSuccessful);
} catch (CModelException e) {
;
}
}
}

View file

@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.core.dom;
@ -40,7 +41,7 @@ import org.eclipse.core.runtime.content.IContentType;
*/
public class DOMSearchUtil {
private static final IASTName[] BLANK_NAME_ARRAY = new IASTName[0];
private static final IASTName[] EMPTY_NAME_LIST = BLANK_NAME_ARRAY;
// private static final IASTName[] EMPTY_NAME_LIST = BLANK_NAME_ARRAY;
public static final int DECLARATIONS = 1;
public static final int DEFINITIONS = 2;
@ -58,7 +59,8 @@ public class DOMSearchUtil {
IContentType contentType = CCorePlugin.getContentType(project, file.getFullPath().lastSegment());
if (contentType != null) {
String lid = contentType.getId();
if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(lid)) {
if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(lid) ||
CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(lid)) {
return ParserLanguage.CPP;
}
}
@ -131,7 +133,7 @@ public class DOMSearchUtil {
} else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
return ParserLanguage.CPP;
} else if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) {
return ParserLanguage.CPP; // <============== is that right ? should not this be C ?
return ParserLanguage.C;
} else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
return ParserLanguage.C;
} else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {

View file

@ -450,60 +450,35 @@
<!-- =================================================================================== -->
<!-- Define C/C++ files ContentTypes -->
<!-- =================================================================================== -->
<extension point="org.eclipse.core.runtime.contentTypes">
<extension point="org.eclipse.core.runtime.contentTypes">
<!-- declares a content type for C source files -->
<content-type id="cSource" name="%cSourceName"
base-type="org.eclipse.core.runtime.text"
priority="high"/>
<content-type id="cSource" name="%cSourceName"
base-type="org.eclipse.core.runtime.text"
file-extensions="c"
priority="high"/>
<!-- declares a content type for C header files -->
<content-type id="cHeader" name="%cHeaderName"
base-type="org.eclipse.cdt.core.cSource"
file-extensions="h"
priority="high"/>
<!-- declares a content type for C++ source files -->
<content-type id="cxxSource" name="%cxxSourceName"
base-type="org.eclipse.cdt.core.cSource"
file-extensions="C,cpp,cxx,cc,c++"
priority="high"/>
<!-- declares a content type for C++ header files -->
<content-type id="cxxHeader" name="%cxxHeaderName"
base-type="org.eclipse.cdt.core.cxxSource"
file-extensions="h,hpp,hh,hxx"
priority="high"/>
<!-- declares a content type for ASM Source files -->
<content-type id="asmSource" name="%asmSourceName"
base-type="org.eclipse.core.runtime.text"
file-extensions="s,asm"
priority="high"/>
</extension>
</extension>
<extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.cSource"
file-extensions="c"/>
</extension>
<extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.cxxSource"
file-extensions="C,cpp,cxx,cc,c++"/>
</extension>
<extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.asmSource"
file-extensions="s,asm"/>
</extension>
<extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.cHeader"
file-extensions="h"/>
</extension>
<extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.cxxHeader"
file-extensions="hpp,hh,hxx"/>
</extension>
<!-- the reserved filenames by the C++ standard -->
<!-- the reserved filenames by the C++ standard -->
<extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.cxxHeader"

View file

@ -47,6 +47,7 @@ import org.eclipse.core.resources.IProjectDescription;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
@ -62,8 +63,9 @@ import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.SubProgressMonitor;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.core.runtime.content.IContentTypeMatcher;
import org.eclipse.core.runtime.content.IContentTypeSettings;
import org.eclipse.core.runtime.preferences.IScopeContext;
import org.osgi.framework.BundleContext;
public class CCorePlugin extends Plugin {
@ -880,26 +882,114 @@ public class CCorePlugin extends Plugin {
}
/**
* Helper function, returning the contenttype for a filename
* @param project
* @param name
* @return
* Returns the content type for a filename. The method respects project
* project specific content type definitions. The lookup prefers case-
* sensitive matches over the others.
* @param project a project with possible project specific settings. Can be <code>null</code>
* @param filename a filename to compute the content type for
* @return the content type found or <code>null</code>
*/
public static IContentType getContentType(IProject project, String filename) {
// Always try in the workspace (for multi-language support)
// try with the project settings
IContentTypeMatcher matcher= null;
IScopeContext scopeCtx= null;
boolean preferCpp= true;
if (project != null) {
// try with the project settings
try {
IContentTypeMatcher matcher = project.getContentTypeMatcher();
IContentType ct = matcher.findContentTypeFor(filename);
if (ct != null) return ct;
matcher= project.getContentTypeMatcher();
scopeCtx= new ProjectScope(project);
preferCpp= CoreModel.hasCCNature(project);
} catch (CoreException e) {
// ignore.
// fallback to workspace wide definitions.
matcher= Platform.getContentTypeManager();
}
}
// Try in the workspace.
IContentTypeManager manager = Platform.getContentTypeManager();
return manager.findContentTypeFor(filename);
else {
matcher= Platform.getContentTypeManager();
}
IContentType[] cts = matcher.findContentTypesFor(filename);
switch (cts.length) {
case 0:
return null;
case 1:
return cts[0];
}
int maxPossiblePriority= scopeCtx == null ? 11 : 101;
int bestPriority= -1;
IContentType bestResult= null;
for (int i = 0; i < cts.length; i++) {
IContentType candidate= cts[i];
int priority= 0;
try {
if (scopeCtx != null) {
IContentTypeSettings settings= candidate.getSettings(scopeCtx);
if (isStrictlyAssociatedWith(settings, filename)) {
priority= 100;
}
}
if (priority == 0 && bestPriority < 100) {
if (isStrictlyAssociatedWith(candidate, filename)) {
priority= 10;
}
}
if (isPreferredContentType(candidate, preferCpp)) {
priority+= 1;
}
}
catch (CoreException e) {
// skip it
}
if (priority > bestPriority) {
if (priority == maxPossiblePriority) {
return candidate;
}
bestPriority= priority;
bestResult= candidate;
}
}
return bestResult;
}
private static boolean isPreferredContentType(IContentType candidate, boolean preferCpp) {
while (candidate != null) {
String id= candidate.getId();
boolean isCpp= CONTENT_TYPE_CXXHEADER.equals(id) || CONTENT_TYPE_CXXSOURCE.equals(id);
if (isCpp) {
return preferCpp;
}
boolean isC= CONTENT_TYPE_CHEADER.equals(id) || CONTENT_TYPE_CSOURCE.equals(id);
if (isC) {
return !preferCpp;
}
candidate= candidate.getBaseType();
}
return false;
}
private static boolean isStrictlyAssociatedWith(IContentTypeSettings settings, String filename) {
String[] namespecs= settings.getFileSpecs(IContentType.FILE_NAME_SPEC);
for (int i = 0; i < namespecs.length; i++) {
String name = namespecs[i];
if (name.equals(filename)) {
return true;
}
}
// check the file extensions only
int dotPosition = filename.lastIndexOf('.');
if (dotPosition >= 0 && dotPosition < filename.length()-1) {
String fileExtension= filename.substring(dotPosition + 1);
String[] extensions= settings.getFileSpecs(IContentType.FILE_EXTENSION_SPEC);
for (int i = 0; i < extensions.length; i++) {
String ext = extensions[i];
if (ext.equals(fileExtension)) {
return true;
}
}
}
return false;
}

View file

@ -254,7 +254,7 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
} else if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
return ParserLanguage.CPP;
} else if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) {
return ParserLanguage.CPP; // <============== is that right ? should not this be C ?
return ParserLanguage.C;
} else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
return ParserLanguage.C;
} else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {

View file

@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* QNX Software System
* Anton Leherbauer (Wind River Systems)
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.editor;
@ -17,7 +18,6 @@ import java.util.Iterator;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jface.action.Action;
@ -114,7 +114,6 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CCorePreferenceConstants;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ISourceRange;
import org.eclipse.cdt.core.model.ISourceReference;
@ -1461,12 +1460,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS
ITranslationUnit unit = mgr.getWorkingCopy(getEditorInput());
String fileType = LANGUAGE_CPP;
if (unit != null) {
// default is C++ unless the project as C Nature Only
// we can then be smarter.
IProject p = unit.getCProject().getProject();
if (!CoreModel.hasCCNature(p)) {
fileType = unit.isCXXLanguage() ? LANGUAGE_CPP : LANGUAGE_C;
}
fileType= unit.isCLanguage() ? LANGUAGE_C : LANGUAGE_CPP;
}
fAnnotationAccess = createAnnotationAccess();

View file

@ -151,16 +151,13 @@ public class IBViewPart extends ViewPart
public void setInput(ITranslationUnit input) {
if (input == null) {
setMessage(IBMessages.IBViewPart_instructionMessage);
fTreeViewer.setInput(null);
return;
}
fShowsMessage= false;
boolean isHeader= false;
String contentType= input.getContentTypeId();
if (contentType.equals(CCorePlugin.CONTENT_TYPE_CXXHEADER) ||
contentType.equals(CCorePlugin.CONTENT_TYPE_CHEADER)) {
isHeader= true;
}
boolean isHeader= input.isHeaderUnit();
fTreeViewer.setInput(null);
if (!isHeader) {
fContentProvider.setComputeIncludedBy(isHeader);

View file

@ -7,38 +7,13 @@
*
* Contributors:
* IBM Corp. - Rational Software - initial implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search.actions;
import java.io.IOException;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IScannerInfo;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.parser.NullSourceElementRequestor;
import org.eclipse.cdt.core.parser.ParserFactory;
import org.eclipse.cdt.core.parser.ParserFactoryError;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.ParserMode;
import org.eclipse.cdt.core.parser.ParserUtil;
import org.eclipse.cdt.core.parser.ScannerInfo;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.ExternalSearchEditor;
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@ -61,6 +36,18 @@ import org.eclipse.ui.ide.IDE;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.cdt.core.dom.ast.IASTFileLocation;
import org.eclipse.cdt.core.dom.ast.IASTName;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.parser.Keywords;
import org.eclipse.cdt.core.resources.FileStorage;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.editor.CEditor;
import org.eclipse.cdt.internal.ui.editor.ExternalSearchEditor;
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.util.ExternalEditorInput;
/**
* @author aniefer
* Created on Jun 2, 2004
@ -90,60 +77,6 @@ public class SelectionParseAction extends Action {
fSite=site;
}
protected IParser setupParser(IFile resourceFile) {
//Get the scanner info
IProject currentProject = resourceFile.getProject();
IScannerInfo scanInfo = new ScannerInfo();
IScannerInfoProvider provider = CCorePlugin.getDefault().getScannerInfoProvider(currentProject);
if (provider != null){
IScannerInfo buildScanInfo = provider.getScannerInformation(resourceFile);
if (buildScanInfo != null){
scanInfo = new ScannerInfo(buildScanInfo.getDefinedSymbols(), buildScanInfo.getIncludePaths());
}
}
//C or CPP?
ParserLanguage language = CoreModel.hasCCNature(currentProject) ? ParserLanguage.CPP : ParserLanguage.C;
IWorkingCopy workingCopy = null;
if( fEditor.isDirty() ){
IWorkingCopy [] workingCopies = CUIPlugin.getSharedWorkingCopies();
if( workingCopies != null ){
for( int i = 0; i < workingCopies.length; i++ ){
if( workingCopies[i].getUnderlyingResource().equals( resourceFile ) ){
workingCopy = workingCopies[i];
break;
}
}
}
}
IParser parser = null;
CodeReader reader = null;
try {
if( workingCopy == null )
reader = new CodeReader(resourceFile.getLocation().toOSString(), resourceFile.getCharset() );
else
reader = new CodeReader(resourceFile.getLocation().toOSString(), workingCopy.getContents());
} catch (IOException e) {
e.printStackTrace();
} catch ( CoreException e ) {
e.printStackTrace();
}
try
{
parser = ParserFactory.createParser(
ParserFactory.createScanner( reader, scanInfo, ParserMode.SELECTION_PARSE, language, new NullSourceElementRequestor(), ParserUtil.getScannerLogService(), null ),
new NullSourceElementRequestor(), ParserMode.SELECTION_PARSE, language, ParserUtil.getParserLogService() );
} catch( ParserFactoryError pfe ){}
return parser;
}
protected void operationNotAvailable(final String message) {
// run the code to update the status line on the Display thread
// this way any other thread can invoke operationNotAvailable(String)

View file

@ -6,7 +6,8 @@
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
* IBM Rational Software - Initial API and implementation
* Markus Schorn (Wind River Systems)
*******************************************************************************/
package org.eclipse.cdt.internal.ui.text.contentassist;
@ -15,9 +16,14 @@ import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IMacro;
@ -57,15 +63,13 @@ import org.eclipse.cdt.core.parser.ast.IASTNode.ILookupResult;
import org.eclipse.cdt.core.parser.ast.IASTNode.LookupKind;
import org.eclipse.cdt.core.parser.util.CharArrayObjectMap;
import org.eclipse.cdt.core.parser.util.CharArrayUtils;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.core.CharOperation;
import org.eclipse.cdt.internal.ui.CUIMessages;
import org.eclipse.cdt.internal.ui.util.IDebugLogConstants;
import org.eclipse.cdt.internal.ui.util.Util;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.preference.IPreferenceStore;
/**
*
@ -143,6 +147,7 @@ public class CompletionEngine implements RelevanceConstants {
}
private IASTCompletionNode parse(IWorkingCopy sourceUnit, int completionOffset){
// Get resource info
ITranslationUnit tu= sourceUnit.getOriginalElement();
IResource currentResource = sourceUnit.getResource();
IPath realPath = currentResource.getLocation();
IProject project = currentResource.getProject();
@ -158,7 +163,7 @@ public class CompletionEngine implements RelevanceConstants {
}
//C or CPP?
ParserLanguage language = CoreModel.hasCCNature(project) ? ParserLanguage.CPP : ParserLanguage.C;
ParserLanguage language = tu != null && tu.isCLanguage() ? ParserLanguage.C : ParserLanguage.CPP;
IParser parser = null;
IScanner scanner = null;