diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index 8116dddb9a7..7c3713ec083 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -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(); } /** diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java index c6a915a8df0..94510a6e741 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/LanguageManager.java @@ -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/**/ getAllContentTypes() { ArrayList/**/ 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/**/ 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) { 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 2845761c186..75922b24b10 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 @@ -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) { - ; } } } diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/DOMSearchUtil.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/DOMSearchUtil.java index beb62c4af02..0ed2343ae39 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/DOMSearchUtil.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/core/dom/DOMSearchUtil.java @@ -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)) { diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 0bf72ba3f69..f5bcf9c3f5d 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -450,60 +450,35 @@ - + - + - + - - - - - - - - - - - - - - - - - - - - - + null + * @param filename a filename to compute the content type for + * @return the content type found or null */ 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; } diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java index 854267e5bd5..d4fd71e3510 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java @@ -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)) { diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index c6a960d07b7..2694217ec80 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -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(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java index 2bc63362a9d..53ac6997b58 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/includebrowser/IBViewPart.java @@ -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); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java index d0b78edf42c..6070d9d5673 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/SelectionParseAction.java @@ -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) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java index 3780de2a4be..5cbeb6b2999 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/text/contentassist/CompletionEngine.java @@ -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;