Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2005-06-09 16:06:09 +0000
committerAlain Magloire2005-06-09 16:06:09 +0000
commitf441ff377812ab8556fed7cd25bfe9dd2b087848 (patch)
tree63f7d20b1a46334c2022868d48d363a866cf5c17
parent954e809c34bb5ccbb0f4f2b5f89158163e9ee85d (diff)
downloadorg.eclipse.cdt-f441ff377812ab8556fed7cd25bfe9dd2b087848.tar.gz
org.eclipse.cdt-f441ff377812ab8556fed7cd25bfe9dd2b087848.tar.xz
org.eclipse.cdt-f441ff377812ab8556fed7cd25bfe9dd2b087848.zip
2005-06-08 Alain Magloire
Move to the IContentTypeManager framework: PR 86645 * index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java * index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java * index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java * index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java * model/org/eclipse/cdt/core/model/CoreModel.java * model/org/eclipse/cdt/core/model/ITranslationUnit.java * model/org/eclipse/cdt/internal/core/model/CContainer.java * model/org/eclipse/cdt/internal/core/model/CModelManager.java + model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java * model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java * model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java * model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java * model/org/eclipse/cdt/internal/core/model/IncludeReference.java * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java - model/org/eclipse/cdt/internal/core/model/ResolverProcessor.java * model/org/eclipse/cdt/internal/core/model/TranslationUnit.java * model/org/eclipse/cdt/internal/core/model/WorkingCopy.java * plugin.xml - schema/CFileType.exsd - schema//CFileTypeAssociation.exsd - template/cpp_headers * search/org/eclipse/cdt/core/search * src/org/eclipse/cdt/core/CCorePlugin.java - src/org/eclipse/cdt/core/filetype/* - src/org/eclipse/cdt/core/internal/filetype/*
-rw-r--r--core/org.eclipse.cdt.core/ChangeLog33
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java28
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java8
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java12
-rw-r--r--core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java6
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java147
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java8
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java42
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java38
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java (renamed from core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ResolverProcessor.java)150
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java2
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java6
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java4
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java8
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java2
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/TranslationUnit.java62
-rw-r--r--core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/WorkingCopy.java16
-rw-r--r--core/org.eclipse.cdt.core/plugin.xml54
-rw-r--r--core/org.eclipse.cdt.core/schema/CFileType.exsd142
-rw-r--r--core/org.eclipse.cdt.core/schema/CFileTypeAssociation.exsd142
-rw-r--r--core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java50
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java108
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileType.java63
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeAssociation.java47
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeConstants.java47
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeResolver.java85
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICLanguage.java27
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/IResolverChangeListener.java19
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/IResolverModel.java125
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ResolverChangeEvent.java104
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ResolverDelta.java110
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/Argument.java80
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileType.java80
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeAssociation.java62
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeResolver.java152
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CLanguage.java50
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CustomResolver.java311
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/ResolverModel.java816
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/WorkspaceResolver.java357
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/internal/core/dom/InternalASTServiceProvider.java35
-rw-r--r--core/org.eclipse.cdt.core/template/cpp_headers53
41 files changed, 538 insertions, 3153 deletions
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog
index 23a0229a98..3b0da5f839 100644
--- a/core/org.eclipse.cdt.core/ChangeLog
+++ b/core/org.eclipse.cdt.core/ChangeLog
@@ -1,3 +1,36 @@
+2005-06-08 Alain Magloire
+ Move to the IContentTypeManager framework: PR 86645
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java
+ * index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
+
+ * model/org/eclipse/cdt/core/model/CoreModel.java
+ * model/org/eclipse/cdt/core/model/ITranslationUnit.java
+
+ * model/org/eclipse/cdt/internal/core/model/CContainer.java
+ * model/org/eclipse/cdt/internal/core/model/CModelManager.java
+ + model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java
+ * model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java
+ * model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
+ * model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java
+ * model/org/eclipse/cdt/internal/core/model/IncludeReference.java
+ * model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
+ - model/org/eclipse/cdt/internal/core/model/ResolverProcessor.java
+ * model/org/eclipse/cdt/internal/core/model/TranslationUnit.java
+ * model/org/eclipse/cdt/internal/core/model/WorkingCopy.java
+
+ * plugin.xml
+ - schema/CFileType.exsd
+ - schema//CFileTypeAssociation.exsd
+ - template/cpp_headers
+
+ * search/org/eclipse/cdt/core/search
+ * src/org/eclipse/cdt/core/CCorePlugin.java
+
+ - src/org/eclipse/cdt/core/filetype/*
+ - src/org/eclipse/cdt/core/internal/filetype/*
+
2005-06-07 Vladimir Hirsl
Fix for a problem with DOM indexer, where external header files in translation unit's
inclusion tree were not visited.
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
index feb9070503..9da405abbe 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AbstractIndexer.java
@@ -19,8 +19,6 @@ import java.util.List;
import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
import org.eclipse.cdt.core.model.ICModelMarker;
import org.eclipse.cdt.core.search.ICSearchConstants;
import org.eclipse.cdt.internal.core.Util;
@@ -35,6 +33,7 @@ import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.jobs.Job;
public abstract class AbstractIndexer implements IIndexer, ICSearchConstants {
@@ -85,15 +84,22 @@ public abstract class AbstractIndexer implements IIndexer, ICSearchConstants {
*/
public boolean shouldIndex(IFile fileToBeIndexed) {
if (fileToBeIndexed != null){
- ICFileType type = CCorePlugin.getDefault().getFileType(fileToBeIndexed.getProject(),fileToBeIndexed.getName());
- if (type.isSource() || type.isHeader()){
- String id = type.getId();
- if (id.equals(ICFileTypeConstants.FT_C_SOURCE) ||
- id.equals(ICFileTypeConstants.FT_CXX_SOURCE) ||
- id.equals(ICFileTypeConstants.FT_C_HEADER) ||
- id.equals(ICFileTypeConstants.FT_CXX_HEADER))
- return true;
- }
+ String id = null;
+ IContentType contentType = CCorePlugin.getContentType(fileToBeIndexed.getProject(), fileToBeIndexed.getName());
+ if (contentType != null) {
+ id = contentType.getId();
+ }
+ if (id != null) {
+ if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)
+ || CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)
+ || CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)
+ || CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
+ return true;
+ } else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
+ // FIXME: ALAIN
+ // What do we do here ?
+ }
+ }
}
return false;
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java
index b398795ef8..f36ac13a7e 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFileToIndex.java
@@ -12,9 +12,8 @@ package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.io.IOException;
-import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.ICLogConstants;
-import org.eclipse.cdt.core.filetype.ICFileType;
+import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.internal.core.index.IIndex;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
import org.eclipse.cdt.internal.core.search.indexing.ReadWriteMonitor;
@@ -45,10 +44,9 @@ public abstract class AddFileToIndex extends IndexRequest {
if (checkEncounteredHeaders) {
IProject resourceProject = resource.getProject();
/* Check to see if this is a header file */
- ICFileType type = CCorePlugin.getDefault().getFileType(resourceProject,resource.getName());
-
+ boolean isHeader = CoreModel.isValidHeaderUnitName(resourceProject, resource.getName());
/* See if this file has been encountered before */
- if (type.isHeader() &&
+ if (isHeader &&
indexer.haveEncounteredHeader(resourceProject.getFullPath(),resource.getLocation(), true))
return true;
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java
index 158c51d615..5f6956914e 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/AddFolderToIndex.java
@@ -13,8 +13,6 @@ package org.eclipse.cdt.internal.core.index.sourceindexer;
import java.util.ArrayList;
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.internal.core.Util;
import org.eclipse.cdt.internal.core.index.IIndex;
@@ -135,13 +133,13 @@ public class AddFolderToIndex extends IndexRequest {
protected void sortFiles(IFile file){
/* Check to see if this is a header file */
- ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName());
-
+ boolean isHeader = CoreModel.isValidHeaderUnitName(file.getProject(), file.getName());
/* See if this file has been encountered before */
- if (type.isHeader())
+ if (isHeader)
headerFilesToIndex.add(file);
-
- if (type.isSource())
+
+ boolean isSource = CoreModel.isValidSourceUnitName(file.getProject(), file.getName());
+ if (isSource)
sourceFilesToIndex.add(file);
}
diff --git a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
index ef1e5f3229..529d528ecc 100644
--- a/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
+++ b/core/org.eclipse.cdt.core/index/org/eclipse/cdt/internal/core/index/sourceindexer/SourceIndexerRequestor.java
@@ -21,7 +21,7 @@ import java.util.Iterator;
import java.util.LinkedList;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.filetype.ICFileType;
+import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IParser;
import org.eclipse.cdt.core.parser.IProblem;
@@ -199,11 +199,11 @@ public class SourceIndexerRequestor implements ISourceElementRequestor {
IProject resourceProject = resourceFile.getProject();
/* Check to see if this is a header file */
- ICFileType type = CCorePlugin.getDefault().getFileType(resourceProject,
+ boolean isHeader = CoreModel.isValidHeaderUnitName(resourceProject,
inclusion.getFullFileName());
/* See if this file has been encountered before */
- if (type.isHeader())
+ if (isHeader)
indexer.haveEncounteredHeader(resourceProject.getFullPath(),new Path(inclusion.getFullFileName()));
}
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 598e8941f9..df1f33a43a 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
@@ -14,7 +14,6 @@ package org.eclipse.cdt.core.model;
import org.eclipse.cdt.core.CCProjectNature;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.CProjectNature;
-import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.resources.IPathEntryStore;
import org.eclipse.cdt.internal.core.model.APathEntry;
import org.eclipse.cdt.internal.core.model.BatchOperation;
@@ -42,12 +41,16 @@ import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
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();
+
public final static String CORE_MODEL_ID = CCorePlugin.PLUGIN_ID + ".coremodel"; //$NON-NLS-1$
/**
@@ -165,44 +168,168 @@ public class CoreModel {
}
/**
- * Return true if IFile is a TranslationUnit.
+ * Return true if IFile is a possible TranslationUnit.
*/
public static boolean isTranslationUnit(IFile file) {
if (file != null) {
IProject p = file.getProject();
if (hasCNature(p) || hasCCNature(p)) {
- ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName());
- return type.isTranslationUnit();
+ return isValidTranslationUnitName(p, file.getFullPath().lastSegment());
}
}
return false;
}
/**
+ * Return an array of the register contentTypes.
+ * @return String[] ids
+ */
+ public static String[] getRegistedContentTypeIds() {
+ return new String[] {
+ CCorePlugin.CONTENT_TYPE_ASMSOURCE,
+ CCorePlugin.CONTENT_TYPE_CHEADER,
+ CCorePlugin.CONTENT_TYPE_CSOURCE,
+ CCorePlugin.CONTENT_TYPE_CXXHEADER,
+ CCorePlugin.CONTENT_TYPE_CXXSOURCE
+ };
+ }
+ /**
* Return true if name is a valid name for a translation unit.
*/
public static boolean isValidTranslationUnitName(IProject project, String name) {
- ICFileType type = CCorePlugin.getDefault().getFileType(project, name);
- return type.isTranslationUnit();
+ if (isValidHeaderUnitName(project, name)) {
+ return true;
+ } else if (isValidSourceUnitName(project, name)) {
+ return true;
+ }
+ return false;
}
/**
* Return true if name is a valid name for a translation unit.
*/
public static boolean isValidHeaderUnitName(IProject project, String name) {
- ICFileType type = CCorePlugin.getDefault().getFileType(project, name);
- return type.isHeader();
+ if (isValidCHeaderUnitName(project, name)) {
+ return true;
+ } else if (isValidCXXHeaderUnitName(project, name)) {
+ return true;
+ }
+ return false;
}
/**
* Return true if name is a valid name for a translation unit.
*/
public static boolean isValidSourceUnitName(IProject project, String name) {
- ICFileType type = CCorePlugin.getDefault().getFileType(project, name);
- return type.isSource();
+ if (isValidCSourceUnitName(project, name)) {
+ return true;
+ } else if (isValidCXXSourceUnitName(project, name)) {
+ return true;
+ } else if (isValidASMSourceUnitName(project, name)) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Return true if name is a valid name for a translation unit.
+ */
+ public static boolean isValidCSourceUnitName(IProject project, String name) {
+ IContentType contentType = CCorePlugin.getContentType(project, name);
+ if (contentType != null) {
+ String id = contentType.getId();
+ if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return true if name is a valid name for a translation unit.
+ */
+ public static boolean isValidCXXSourceUnitName(IProject project, String name) {
+ IContentType contentType = CCorePlugin.getContentType(project, name);
+ if (contentType != null) {
+ String id = contentType.getId();
+ if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return true if name is a valid name for a translation unit.
+ */
+ public static boolean isValidASMSourceUnitName(IProject project, String name) {
+ IContentType contentType = CCorePlugin.getContentType(project, name);
+ if (contentType != null) {
+ String id = contentType.getId();
+ if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
+ return true;
+ }
+ }
+ return false;
}
/**
+ * Return true if name is a valid name for a translation unit.
+ */
+ public static boolean isValidCXXHeaderUnitName(IProject project, String name) {
+ IContentType contentType = CCorePlugin.getContentType(project, name);
+ if (contentType != null) {
+ String id = contentType.getId();
+ if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return true if name is a valid name for a translation unit.
+ */
+ public static boolean isValidCHeaderUnitName(IProject project, String name) {
+ IContentType contentType = CCorePlugin.getContentType(project, name);
+ if (contentType != null) {
+ String id = contentType.getId();
+ if (CCorePlugin.CONTENT_TYPE_CHEADER.equals(id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Return the registed content type id, for example:
+ * <ul>
+ * <li>CONTENT_TYPE_CHEADER
+ * <li>CONTENT_TYPE_CXXHEADER
+ * <li>CONTENT_TYPE_CSOURCE
+ * <li>CONTENT_TYPE_CXXSOURCE
+ * <li>CONTENT_TYPE_ASMSOURCE
+ * </ul>
+ * or null is return if no id match the list
+ * @param file
+ * @return the know id or null
+ */
+ public static String getRegistedContentTypeId(IProject project, String name) {
+ IContentType contentType = CCorePlugin.getContentType(project, name);
+ if (contentType != null) {
+ String id = contentType.getId();
+ String[] ids = getRegistedContentTypeIds();
+ for (int i = 0; i < ids.length; i++) {
+ if (ids[i].equals(id)) {
+ return id;
+ }
+ }
+ }
+ return null;
+ }
+
+
+ /**
* Return true if project has C nature.
*/
public static boolean hasCNature(IProject project) {
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java
index b7b49617d8..8663c2be48 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/ITranslationUnit.java
@@ -341,7 +341,13 @@ public interface ITranslationUnit extends ICElement, IParent, IOpenable, ISource
* @return IWorkingCopy
*/
IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory) throws CModelException;
-
+
+ /**
+ * Return the contentType id for this file.
+ * @return String - contentType id
+ */
+ String getContentTypeId();
+
/**
* Checks if this is a working copy.
* @return boolean
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java
index e1ec283a35..2f9d314cd7 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CContainer.java
@@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.core.model;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
+
import org.eclipse.cdt.core.IBinaryParser;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
@@ -122,7 +123,8 @@ public class CContainer extends Openable implements ICContainer {
}
public ITranslationUnit getTranslationUnit(IFile file) {
- return new TranslationUnit(this, file);
+ String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
+ return new TranslationUnit(this, file, id);
}
/*
@@ -234,29 +236,29 @@ public class CContainer extends Openable implements ICContainer {
protected ICElement computeChild(IResource res, ICProject cproject) throws CModelException {
ICElement celement = null;
switch (res.getType()) {
- case IResource.FILE :
- {
- IFile file = (IFile) res;
- if (CoreModel.isTranslationUnit(file)) {
- celement = new TranslationUnit(this, file);
- } else if (cproject.isOnOutputEntry(file)) {
- IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file);
- if (bin != null) {
- if (bin.getType() == IBinaryFile.ARCHIVE) {
- celement = new Archive(this, file, (IBinaryArchive)bin);
- ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
- vlib.addChild(celement);
- } else {
- celement = new Binary(this, file, (IBinaryObject)bin);
- if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) {
- BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
- vbin.addChild(celement);
- }
+ case IResource.FILE : {
+ IFile file = (IFile) res;
+ String id = CoreModel.getRegistedContentTypeId(file.getProject(), file.getName());
+ if (id != null) {
+ celement = new TranslationUnit(this, file, id);
+ } else if (cproject.isOnOutputEntry(file)) {
+ IBinaryParser.IBinaryFile bin = factory.createBinaryFile(file);
+ if (bin != null) {
+ if (bin.getType() == IBinaryFile.ARCHIVE) {
+ celement = new Archive(this, file, (IBinaryArchive)bin);
+ ArchiveContainer vlib = (ArchiveContainer)cproject.getArchiveContainer();
+ vlib.addChild(celement);
+ } else {
+ celement = new Binary(this, file, (IBinaryObject)bin);
+ if (bin.getType() == IBinaryFile.EXECUTABLE || bin.getType() == IBinaryFile.SHARED) {
+ BinaryContainer vbin = (BinaryContainer)cproject.getBinaryContainer();
+ vbin.addChild(celement);
}
}
}
- break;
}
+ break;
+ }
case IResource.FOLDER :
celement = new CContainer(this, res);
break;
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 823e2fbeb4..b0ebe47071 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
@@ -28,8 +28,6 @@ import org.eclipse.cdt.core.ICExtensionReference;
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
-import org.eclipse.cdt.core.filetype.IResolverChangeListener;
-import org.eclipse.cdt.core.filetype.ResolverChangeEvent;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
@@ -61,8 +59,10 @@ import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentTypeManager.IContentTypeChangeListener;
+import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent;
-public class CModelManager implements IResourceChangeListener, ICDescriptorListener, IResolverChangeListener {
+public class CModelManager implements IResourceChangeListener, ICDescriptorListener, IContentTypeChangeListener {
public static boolean VERBOSE = false;
@@ -80,7 +80,7 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
*/
protected DeltaProcessor fDeltaProcessor = new DeltaProcessor();
- protected ResolverProcessor fResolverProcessor = new ResolverProcessor();
+ protected ContentTypeProcessor fContentTypeProcessor = new ContentTypeProcessor();
/**
* Queue of deltas created explicily by the C Model that
@@ -163,9 +163,9 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
// Register the Core Model on the Descriptor
// Manager, it needs to know about changes.
CCorePlugin.getDefault().getCDescriptorManager().addDescriptorListener(factory);
- // Register the Core Model on the Resolver
- // Manager, it needs to know about changes.
- CCorePlugin.getDefault().getResolverModel().addResolverChangeListener(factory);
+ // Register the Core Model on the ContentTypeManager
+ // it needs to know about changes.
+ Platform.getContentTypeManager().addContentTypeChangeListener(factory);
}
return factory;
}
@@ -402,7 +402,12 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
IIncludeReference[] includeReferences = cproject.getIncludeReferences();
for (int i = 0; i < includeReferences.length; i++) {
if (includeReferences[i].isOnIncludeEntry(path)) {
- return new ExternalTranslationUnit(includeReferences[i], path);
+ String id = CoreModel.getRegistedContentTypeId(cproject.getProject(), path.lastSegment());
+ if (id == null) {
+ // fallback to C Header
+ id = CCorePlugin.CONTENT_TYPE_CHEADER;
+ }
+ return new ExternalTranslationUnit(includeReferences[i], path, id);
}
}
} catch (CModelException e) {
@@ -414,7 +419,12 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
IPath includePath = includeReferences[i].getPath().append(path);
File file = includePath.toFile();
if (file != null && file.isFile()) {
- return new ExternalTranslationUnit(includeReferences[i], includePath);
+ String id = CoreModel.getRegistedContentTypeId(cproject.getProject(), includePath.lastSegment());
+ if (id == null) {
+ // fallbakc to C Header
+ id = CCorePlugin.CONTENT_TYPE_CHEADER;
+ }
+ return new ExternalTranslationUnit(includeReferences[i], includePath, id);
}
}
} catch (CModelException e) {
@@ -756,10 +766,10 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
}
/* (non-Javadoc)
- * @see org.eclipse.cdt.core.filetype.IResolverChangeListener#resolverChanged(org.eclipse.cdt.core.filetype.ResolverChangeEvent)
+ * @see org.eclipse.core.runtime.content.IContentTypeManager.IContentTypeListener#contentTypeChanged()
*/
- public void resolverChanged(ResolverChangeEvent event) {
- fResolverProcessor.processResolverChanges(event);
+ public void contentTypeChanged(ContentTypeChangeEvent event) {
+ fContentTypeProcessor.processContentTypeChanges(event);
}
public void fire(int eventType) {
@@ -1098,8 +1108,8 @@ public class CModelManager implements IResourceChangeListener, ICDescriptorListe
// Remove ourself from the DescriptorManager.
CCorePlugin.getDefault().getCDescriptorManager().removeDescriptorListener(factory);
- // Remove ourself from the ResolverManager.
- CCorePlugin.getDefault().getResolverModel().removeResolverChangeListener(factory);
+ // Remove ourself from the ContentTypeManager
+ Platform.getContentTypeManager().removeContentTypeChangeListener(factory);
// Do any shutdown of services.
ResourcesPlugin.getWorkspace().removeResourceChangeListener(factory);
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ResolverProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java
index d81149863c..2f82494f52 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ResolverProcessor.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ContentTypeProcessor.java
@@ -15,11 +15,6 @@ import java.util.ArrayList;
import java.util.List;
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
-import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
-import org.eclipse.cdt.core.filetype.IResolverModel;
-import org.eclipse.cdt.core.filetype.ResolverChangeEvent;
-import org.eclipse.cdt.core.filetype.ResolverDelta;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ElementChangedEvent;
@@ -28,50 +23,38 @@ import org.eclipse.cdt.core.model.ICModel;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.IOpenable;
import org.eclipse.cdt.core.model.ISourceRoot;
+import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.core.resources.IContainer;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ProjectScope;
import org.eclipse.core.runtime.CoreException;
-
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.core.runtime.content.IContentTypeManager.ContentTypeChangeEvent;
+import org.eclipse.core.runtime.preferences.IScopeContext;
/**
- * ResolverProcessor
+ * ContentType processor
*/
-public class ResolverProcessor {
+public class ContentTypeProcessor {
CModelManager fManager;
CElementDelta fCurrentDelta;
- public void processResolverChanges(ResolverChangeEvent event) {
+ public void processContentTypeChanges(ContentTypeChangeEvent event) {
ICElement root = CModelManager.getDefault().getCModel();
fCurrentDelta = new CElementDelta(root);
fManager = CModelManager.getDefault();
+ IContentType contentType = event.getContentType();
- // Go through the events and generate deltas
- ResolverDelta[] deltas = event.getDeltas();
- ICElement[] celements = getAffectedElements(event.getResolver());
- for (int k = 0; k < celements.length; ++k) {
- ICElement celement = celements[k];
- for (int i = 0; i < deltas.length; ++i) {
- ResolverDelta delta = deltas[i];
- if (delta.getElementType() == ResolverDelta.ELEMENT_ASSOCIATION) {
- ICFileTypeAssociation association = (ICFileTypeAssociation)delta.getElement();
- if (association.getType().isTranslationUnit()) {
- try {
- switch (delta.getEventType()) {
- case ResolverDelta.EVENT_ADD:
- add(celement, association);
- break;
- case ResolverDelta.EVENT_REMOVE:
- remove(celement, association);
- break;
- }
- } catch (CModelException e) {
- //
- }
- }
- }
+ // only interested in our contentTypes
+ if (isRegisteredContentTypeId(contentType.getId())) {
+ // Go through the events and generate deltas
+ ICProject[] cprojects = getAffectedProjects(event);
+ for (int k = 0; k < cprojects.length; ++k) {
+ ICProject cproject = cprojects[k];
+ processContentType(cproject, contentType, event.getContext());
}
}
if (fCurrentDelta.getAffectedChildren().length > 0) {
@@ -79,23 +62,50 @@ public class ResolverProcessor {
}
}
- void add(ICElement celement, ICFileTypeAssociation association) throws CModelException {
+ boolean isRegisteredContentTypeId(String id) {
+ String[] ids = CoreModel.getRegistedContentTypeIds();
+ for (int i = 0; i < ids.length; i++) {
+ if (ids[i].equals(id)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ void processContentType(ICElement celement, IContentType contentType, IScopeContext context) {
if (celement instanceof IOpenable) {
int type = celement.getElementType();
- if (type < ICElement.C_UNIT) {
+ // if the type is not a TranslationUnit
+ switch (type) {
+ case ICElement.C_PROJECT: {
+ CElementInfo info = (CElementInfo)fManager.peekAtInfo(celement);
+ if (info != null) {
+ ICElement[] celements = info.getChildren();
+ for (int i = 0; i < celements.length; ++i) {
+ processContentType(celements[i], contentType, context);
+ }
+ }
+ break;
+ }
+ case ICElement.C_CCONTAINER: {
CElementInfo info = (CElementInfo)fManager.peekAtInfo(celement);
if (info != null) {
try {
+ ICElement[] celements = info.getChildren();
IResource resource = celement.getResource();
IResource[] members = null;
if (resource instanceof IContainer) {
members = ((IContainer)resource).members();
}
if (members != null) {
+ //IContentTypeMatcher matcher = resource.getProject().getContentTypeMatcher();
for (int i = 0; i < members.length; ++i) {
if (members[i] instanceof IFile) {
IFile file = (IFile) members[i];
- if (association.matches(file.getName())) {
+ //if (contentType.isAssociatedWith(file.getName(), context)) {
+ IContentType cType = CCorePlugin.getContentType(file.getProject(), file.getName());
+ if (cType != null && cType.equals(contentType)) {
+// if (CoreModel.isValidTranslationUnitName(file.getProject(), file.getName())) {
ICElement newElement = CoreModel.getDefault().create(file);
if (newElement != null) {
elementAdded(newElement, celement);
@@ -103,40 +113,34 @@ public class ResolverProcessor {
}
}
}
- ICElement[] celements = info.getChildren();
- for (int i = 0; i < celements.length; ++i) {
- add(celements[i], association);
- }
+ }
+ for (int i = 0; i < celements.length; ++i) {
+ processContentType(celements[i], contentType, context);
}
} catch (CoreException e) {
//
}
}
}
- }
- }
-
- void remove(ICElement celement, ICFileTypeAssociation association) throws CModelException {
- if (celement instanceof IOpenable) {
- int type = celement.getElementType();
- if (type < ICElement.C_UNIT) {
- CElementInfo cinfo = (CElementInfo)fManager.peekAtInfo(celement);
- if (cinfo != null) {
- ICElement[] celements = cinfo.getChildren();
- for (int i = 0; i < celements.length; ++i) {
- if (celements[i].getElementType() == ICElement.C_UNIT) {
- if (association.matches(celements[i].getElementName())) {
- elementRemoved(celements[i], celement);
- }
- } else {
- remove(celements[i], association);
+ break;
+ case ICElement.C_UNIT: {
+ String id = ((ITranslationUnit)celement).getContentTypeId();
+ if (contentType.getId().equals(id)) {
+ try {
+ if (! contentType.isAssociatedWith(celement.getElementName(), context)) {
+ elementRemoved(celement, celement.getParent());
}
+ } catch (CoreException e) {
+ //
}
}
+ break;
}
- }
+ }
+ }
}
+
/**
* Add the resource delta to the right CElementDelta tree.
* @param parent
@@ -217,33 +221,33 @@ public class ResolverProcessor {
}
}
- private ICElement[] getAffectedElements(ICFileTypeResolver resolver) {
+ private ICProject[] getAffectedProjects(ContentTypeChangeEvent event) {
try {
- IResolverModel rmodel = CCorePlugin.getDefault().getResolverModel();
ICModel cmodel = CoreModel.getDefault().getCModel();
ICProject[] cprojects = cmodel.getCProjects();
- IContainer container = resolver.getContainer();
- if (container instanceof IProject || container instanceof IFolder) {
- IProject project = container.getProject();
- for (int i = 0; i < cprojects.length; i++) {
- if (project.equals(cprojects[i].getProject())) {
- return new ICElement[] { cprojects[i] };
+ IScopeContext context = event.getContext();
+ if (context != null) {
+ if (ProjectScope.SCOPE.equals((context.getName()))) {
+ IPath location = context.getLocation();
+ for (int i = 0; i < cprojects.length; i++) {
+ if (cprojects[i].getProject().getLocation().isPrefixOf(location)) {
+ return new ICProject[] { cprojects[i] };
+ }
}
+ return new ICProject[0];
}
- return CElement.NO_ELEMENTS;
}
// Assume a workspace resolver
List list = new ArrayList(cprojects.length);
for (int i = 0; i < cprojects.length; ++i) {
- if (!rmodel.hasCustomResolver(cprojects[i].getProject())) {
- list.add(cprojects[i]);
- }
+ list.add(cprojects[i]);
}
- return (ICElement[]) list.toArray(new ICElement[list.size()]);
+ return (ICProject[]) list.toArray(new ICProject[list.size()]);
} catch (CModelException e) {
//
}
- return CElement.NO_ELEMENTS;
+ return new ICProject[0];
}
+
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java
index 7329584057..09627fa4db 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CreateWorkingCopyOperation.java
@@ -41,7 +41,7 @@ public class CreateWorkingCopyOperation extends CModelOperation {
protected void executeOperation() throws CModelException {
ITranslationUnit tu = getTranslationUnit();
- WorkingCopy workingCopy = new WorkingCopy(tu.getParent(), (IFile)tu.getResource(), this.factory, this.problemRequestor);
+ WorkingCopy workingCopy = new WorkingCopy(tu.getParent(), (IFile)tu.getResource(), tu.getContentTypeId(), this.factory, this.problemRequestor);
// open the working copy now to ensure contents are that of the current state of this element
// Alain: Actually no, delay the parsing 'till it is really needed. Doing the parsing here
// really slows down the opening of the CEditor.
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
index 082fa8f37b..5622b3aff7 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/DeltaProcessor.java
@@ -5,8 +5,6 @@ package org.eclipse.cdt.internal.core.model;
* All Rights Reserved.
*/
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.filetype.ICFileType;
import org.eclipse.cdt.core.index.ICDTIndexer;
import org.eclipse.cdt.core.model.CModelException;
import org.eclipse.cdt.core.model.CoreModel;
@@ -20,7 +18,6 @@ import org.eclipse.cdt.core.model.ICElementDelta;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.model.ISourceRoot;
import org.eclipse.cdt.internal.core.search.indexing.IndexManager;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceDelta;
@@ -627,8 +624,7 @@ public class DeltaProcessor {
boolean shouldAddFile=false;
IProject project = element.getCProject().getProject();
if (elementHasChanged){
- ICFileType type = CCorePlugin.getDefault().getFileType(project,((IFile) delta.getResource()).getName());
- if (type.isSource())
+ if (CoreModel.isValidSourceUnitName(project, element.getElementName()))
shouldAddFile=true;
} else {
shouldAddFile = true;
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java
index b25b747bd2..f57f4b2fbb 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/ExternalTranslationUnit.java
@@ -34,8 +34,8 @@ public class ExternalTranslationUnit extends TranslationUnit {
* @param parent
* @param path
*/
- public ExternalTranslationUnit(ICElement parent, IPath path) {
- super(parent, (IResource)null, path.toString());
+ public ExternalTranslationUnit(ICElement parent, IPath path, String contentTypeID) {
+ super(parent, (IResource)null, path.toString(), contentTypeID);
fPath = path;
}
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java
index d5b8316e25..657053a7d4 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/IncludeReference.java
@@ -108,9 +108,11 @@ public class IncludeReference extends Openable implements IIncludeReference {
ICElement celement = null;
if (child.isDirectory()) {
celement = new IncludeReference(this, fIncludeEntry, new Path(child.getAbsolutePath()));
- } else if (CoreModel.isValidTranslationUnitName(getCProject().getProject(), names[i]) &&
- child.isFile()) {
- celement = new ExternalTranslationUnit(this, path.append(names[i]));
+ } else if (child.isFile()){
+ String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), names[i]);
+ if (id != null) {
+ celement = new ExternalTranslationUnit(this, path.append(names[i]), id);
+ }
}
if (celement != null) {
vChildren.add(celement);
diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
index 4757eb5ae0..fcaef267af 100644
--- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
+++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/PathEntryManager.java
@@ -217,7 +217,7 @@ public class PathEntryManager implements IPathEntryStoreListener, IElementChange
for (int i = 0; i < containers.length; ++i) {
if (containers[i] instanceof IPathEntryContainerExtension) {
IPathEntryContainerExtension extension = (IPathEntryContainerExtension)containers[i];
- IPathEntry[] incs = (IPathEntry[])extension.getPathEntries(resPath, IPathEntry.CDT_MACRO);
+ IPathEntry[] incs = extension.getPathEntries(resPath, IPathEntry.CDT_MACRO);
macroList.addAll(Arrays.asList(incs));
}
}
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 0f7baa5c5a..027e9e7d18 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
@@ -11,10 +11,7 @@ import java.util.Map;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
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.IInclude;
@@ -27,7 +24,6 @@ import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.core.model.IUsing;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
@@ -38,6 +34,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
public class TranslationUnit extends Openable implements ITranslationUnit {
IPath location = null;
+ String fContentTypeID;
/**
* If set, this is the problem requestor which will be used to notify problems
@@ -48,16 +45,19 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
SourceManipulationInfo sourceManipulationInfo = null;
- public TranslationUnit(ICElement parent, IFile file) {
+ public TranslationUnit(ICElement parent, IFile file, String idType) {
super(parent, file, ICElement.C_UNIT);
+ setContentTypeID(idType);
}
- public TranslationUnit(ICElement parent, IPath path) {
+ public TranslationUnit(ICElement parent, IPath path, String idType) {
super(parent, path, ICElement.C_UNIT);
+ setContentTypeID(idType);
}
- public TranslationUnit(ICElement parent, IResource res, String name) {
+ public TranslationUnit(ICElement parent, IResource res, String name, String idType) {
super(parent, res, name, ICElement.C_UNIT);
+ setContentTypeID(idType);
}
public ITranslationUnit getTranslationUnit () {
@@ -479,7 +479,7 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
* @see org.eclipse.cdt.core.model.ITranslationUnit#getWorkingCopy(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.cdt.internal.core.model.IBufferFactory)
*/
public IWorkingCopy getWorkingCopy(IProgressMonitor monitor, IBufferFactory factory)throws CModelException{
- WorkingCopy workingCopy = new WorkingCopy(getParent(), getFile(), factory);
+ WorkingCopy workingCopy = new WorkingCopy(getParent(), getFile(), getContentTypeId(), factory);
// open the working copy now to ensure contents are that of the current state of this element
workingCopy.open(monitor);
return workingCopy;
@@ -586,46 +586,48 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
* @see org.eclipse.cdt.core.model.ITranslationUnit#isHeaderUnit()
*/
public boolean isHeaderUnit() {
- IProject project = getCProject().getProject();
- return CoreModel.isValidHeaderUnitName(project, getPath().lastSegment());
+ return (
+ CCorePlugin.CONTENT_TYPE_CHEADER.equals(fContentTypeID)
+ || CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(fContentTypeID)
+ );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isSourceUnit()
*/
public boolean isSourceUnit() {
- IProject project = getCProject().getProject();
- return CoreModel.isValidSourceUnitName(project, getPath().lastSegment());
+ return (
+ CCorePlugin.CONTENT_TYPE_CSOURCE.equals(fContentTypeID)
+ || CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(fContentTypeID)
+ || CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(fContentTypeID)
+ );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isCLanguage()
*/
public boolean isCLanguage() {
- IProject project = getCProject().getProject();
- ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment());
- String lid = type.getLanguage().getId();
- return lid != null && lid.equals(ICFileTypeConstants.LANG_C);
+ return (
+ CCorePlugin.CONTENT_TYPE_CSOURCE.equals(fContentTypeID)
+ || CCorePlugin.CONTENT_TYPE_CHEADER.equals(fContentTypeID)
+ );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isCXXLanguage()
*/
public boolean isCXXLanguage() {
- IProject project = getCProject().getProject();
- ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment());
- String lid = type.getLanguage().getId();
- return lid != null && lid.equals(ICFileTypeConstants.LANG_CXX);
+ return (
+ CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(fContentTypeID)
+ || CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(fContentTypeID)
+ );
}
/* (non-Javadoc)
* @see org.eclipse.cdt.core.model.ITranslationUnit#isASMLanguage()
*/
public boolean isASMLanguage() {
- IProject project = getCProject().getProject();
- ICFileType type = CCorePlugin.getDefault().getFileType(project, getPath().lastSegment());
- String lid = type.getLanguage().getId();
- return lid != null && lid.equals(ICFileTypeConstants.LANG_ASM);
+ return CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(fContentTypeID);
}
@@ -646,5 +648,15 @@ public class TranslationUnit extends Openable implements ITranslationUnit {
// TODO Auto-generated method stub
return null;
}
-
+
+ /* (non-Javadoc)
+ * @see org.eclipse.cdt.core.model.ITranslationUnit#getContentTypeId()
+ */
+ public String getContentTypeId() {
+ return fContentTypeID;
+ }
+
+ protected void setContentTypeID(String id) {
+ fContentTypeID = id;
+ }
}
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 276ad0f826..6534a32e94 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
@@ -16,6 +16,7 @@ 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;
@@ -54,11 +55,11 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
/**
* Creates a working copy of this element
*/
- public WorkingCopy(ICElement parent, IFile file, IBufferFactory bufferFactory) {
- this(parent, file, bufferFactory, null);
+ public WorkingCopy(ICElement parent, IFile file, String id, IBufferFactory bufferFactory) {
+ this(parent, file, id, bufferFactory, null);
}
- public WorkingCopy(ICElement parent, IFile file, IBufferFactory bufferFactory, IProblemRequestor requestor) {
- super(parent, file);
+ public WorkingCopy(ICElement parent, IFile file, String id, IBufferFactory bufferFactory, IProblemRequestor requestor) {
+ super(parent, file, id);
this.bufferFactory =
bufferFactory == null ?
getBufferManager() :
@@ -66,8 +67,8 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
problemRequestor = requestor;
}
- public WorkingCopy(ICElement parent, IPath path, IBufferFactory bufferFactory) {
- super(parent, path);
+ public WorkingCopy(ICElement parent, IPath path, String id, IBufferFactory bufferFactory) {
+ super(parent, path, id);
this.bufferFactory =
bufferFactory == null ?
getBufferManager() :
@@ -224,7 +225,8 @@ public class WorkingCopy extends TranslationUnit implements IWorkingCopy {
* @see org.eclipse.cdt.core.model.IWorkingCopy#getOriginalElement()
*/
public ITranslationUnit getOriginalElement() {
- return new TranslationUnit(getParent(), getFile());
+ String id = CoreModel.getRegistedContentTypeId(getCProject().getProject(), getElementName());
+ return new TranslationUnit(getParent(), getFile(), id);
}
/**
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index a78e1221a9..693f8833bb 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -241,7 +241,7 @@
<!-- =================================================================================== -->
<!-- CDT file type mappings -->
<!-- =================================================================================== -->
- <extension
+ <!--extension
point="org.eclipse.cdt.core.CLanguage">
<language
name="C"
@@ -312,7 +312,7 @@
type="org.eclipse.cdt.core.fileType.asm_source"
pattern="*.asm,*.s,*.S">
</association>
- </extension>
+ </extension-->
<!-- =================================================================================== -->
<!-- Some well known C file extensions override for the team plugins -->
<!-- =================================================================================== -->
@@ -492,35 +492,57 @@
priority="high"/>
</extension>
- <!--extension point="org.eclipse.core.runtime.contentTypes">
+ <extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.cSource"
file-extensions="c"/>
- </extension-->
+ </extension>
- <!--extension point="org.eclipse.core.runtime.contentTypes">
+ <extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.cxxSource"
file-extensions="cpp,cxx,cc"/>
- </extension-->
+ </extension>
- <!--extension point="org.eclipse.core.runtime.contentTypes">
+ <extension point="org.eclipse.core.runtime.contentTypes">
<file-association
- content-type="org.eclipse.cdt.core.cxxHeader"
- file-extensions="hpp,hh"/>
- </extension-->
+ content-type="org.eclipse.cdt.core.asmSource"
+ file-extensions="s,asm"/>
+ </extension>
- <!--extension point="org.eclipse.core.runtime.contentTypes">
+ <extension point="org.eclipse.core.runtime.contentTypes">
<file-association
content-type="org.eclipse.cdt.core.cHeader"
file-extensions="h"/>
- </extension-->
+ </extension>
- <!--extension point="org.eclipse.core.runtime.contentTypes">
+ <extension point="org.eclipse.core.runtime.contentTypes">
<file-association
- content-type="org.eclipse.cdt.core.asmSource"
- file-extensions="asm,s"/>
- </extension-->
+ content-type="org.eclipse.cdt.core.cxxHeader"
+ file-extensions="hpp,hh,hxx"/>
+ </extension>
+
+ <!-- the reserved filenames by the C++ standard -->
+ <extension point="org.eclipse.core.runtime.contentTypes">
+ <file-association
+ content-type="org.eclipse.cdt.core.cxxHeader"
+ file-names="algorithm,bitset,cassert,cctype,cerrno,cfloat,ciso646,climits,clocale,cmath,complex,csetjmp,csignal"/>
+ </extension>
+ <extension point="org.eclipse.core.runtime.contentTypes">
+ <file-association
+ content-type="org.eclipse.cdt.core.cxxHeader"
+ file-names="cstdarg,cstddef,cstdio,cstdlib,cstring,ctime,cwchar,cwctype,deque,exception,fstream,functional"/>
+ </extension>
+ <extension point="org.eclipse.core.runtime.contentTypes">
+ <file-association
+ content-type="org.eclipse.cdt.core.cxxHeader"
+ file-names="hash_map,hash_set,iomanip,ios,iosfwd,iostream,istream,iterator,limits,list,locale,map,memory"/>
+ </extension>
+ <extension point="org.eclipse.core.runtime.contentTypes">
+ <file-association
+ content-type="org.eclipse.cdt.core.cxxHeader"
+ file-names="new,numeric,ostream,queue,set,sstream,stack,stdexcept,streambuf,string,strstream,typeinfo,utility,valarray,vector"/>
+ </extension>
<!-- =================================================================================== -->
<!-- Initialize the preference for the Core Plugin -->
diff --git a/core/org.eclipse.cdt.core/schema/CFileType.exsd b/core/org.eclipse.cdt.core/schema/CFileType.exsd
deleted file mode 100644
index 88cbc6a391..0000000000
--- a/core/org.eclipse.cdt.core/schema/CFileType.exsd
+++ /dev/null
@@ -1,142 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.cdt.core">
-<annotation>
- <appInfo>
- <meta.schema plugin="org.eclipse.cdt.core" id="CFileType" name="CFileType"/>
- </appInfo>
- <documentation>
- Extension point representing a CDT file type. File types consist of a unique identifier (id), a human-readable name, an associated source language, and an enumerated value that indicates how this file should be treated by CDT.
-
-By themselves, file types don&apos;t serve much purpose. However, they are used to build file type assocations (see the CFileTypeAssocation extension point), which are used by CDT to classify files and determine how they should be processed.
- </documentation>
- </annotation>
-
- <element name="extension">
- <complexType>
- <sequence>
- <element ref="fileType" minOccurs="1" maxOccurs="unbounded"/>
- </sequence>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="fileType">
- <complexType>
- <attribute name="type" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- <simpleType>
- <restriction base="string">
- <enumeration value="source">
- </enumeration>
- <enumeration value="header">
- </enumeration>
- </restriction>
- </simpleType>
- </attribute>
- <attribute name="id" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="language" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appInfo>
- <meta.section type="since"/>
- </appInfo>
- <documentation>
- CDT 2.0
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="examples"/>
- </appInfo>
- <documentation>
- To declare a new type:
-
- &lt;extension
- point=&quot;org.eclipse.cdt.core.CFileType&quot;&gt;
- &lt;fileType
- name=&quot;My File Type&quot;
- type=&quot;source&quot;
- language=&quot;com.example.product.language.my_language&quot;
- id=&quot;com.example.product.fileType.my_language_source&quot;&gt;
- &lt;/fileType&gt;
- &lt;/extension&gt;
-
-This indicates to CDT that there is a new file type, identified using the file type id &quot;com.example.product.fileType.my_file_type&quot;, and that files that have this file type should be handled as source files.
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="apiInfo"/>
- </appInfo>
- <documentation>
- This extension point is purely declarative.
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="implementation"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="copyright"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
-
-</schema>
diff --git a/core/org.eclipse.cdt.core/schema/CFileTypeAssociation.exsd b/core/org.eclipse.cdt.core/schema/CFileTypeAssociation.exsd
deleted file mode 100644
index a253640d7b..0000000000
--- a/core/org.eclipse.cdt.core/schema/CFileTypeAssociation.exsd
+++ /dev/null
@@ -1,142 +0,0 @@
-<?xml version='1.0' encoding='UTF-8'?>
-<!-- Schema file written by PDE -->
-<schema targetNamespace="org.eclipse.cdt.core">
-<annotation>
- <appInfo>
- <meta.schema plugin="org.eclipse.cdt.core" id="CFileType" name="CFileType"/>
- </appInfo>
- <documentation>
- Extension point representing an association between a file type (see CFileType extension point) and a filename pattern. Patterns may be added to an association using the &quot;pattern&quot; and &quot;file&quot; attrributes of the filetype element; the associated file type is indicated by the &quot;type&quot; attribute.
-
-The &quot;pattern&quot; attribute consists of one or more filename patterns. Wildcards (&quot;*&quot; and &quot;?&quot;) may be used in the pattern. Multiple patterns may be present if they are seperated by commas.
-
-The &quot;file&quot; attribute consists of a plugin-relative path to a plain text file that contains one filename pattern per line.
-
-The &quot;pattern&quot; and &quot;file&quot; attributes may be combined in a single filetype element, if desired.
- </documentation>
- </annotation>
-
- <element name="extension">
- <complexType>
- <sequence>
- <element ref="association" minOccurs="1" maxOccurs="unbounded"/>
- </sequence>
- <attribute name="point" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="id" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="name" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <element name="association">
- <complexType>
- <attribute name="pattern" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- <attribute name="file" type="string">
- <annotation>
- <documentation>
-
- </documentation>
- <appInfo>
- <meta.attribute kind="resource"/>
- </appInfo>
- </annotation>
- </attribute>
- <attribute name="type" type="string" use="required">
- <annotation>
- <documentation>
-
- </documentation>
- </annotation>
- </attribute>
- </complexType>
- </element>
-
- <annotation>
- <appInfo>
- <meta.section type="since"/>
- </appInfo>
- <documentation>
- CDT 2.0
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="examples"/>
- </appInfo>
- <documentation>
- A file type association between a simple filename pattern and a file type.
-
- &lt;association
- pattern=&quot;*.c&quot;
- type=&quot;org.eclipse.cdt.core.fileType.c_source&quot;&gt;
- &lt;/association&gt;
-
-A file type association between multiple filename patterns and a file type.
-
- &lt;association
- pattern=&quot;*.cxx,*.cc,*.cpp,*.C&quot;
- type=&quot;org.eclipse.cdt.core.fileType.cxx_source&quot;&gt;
- &lt;/association&gt;
-
-A file type association that uses both &quot;pattern&quot; and &quot;file&quot; attributes to specify filename patterns.
-
- &lt;association
- pattern=&quot;*.hxx,*.hh,*.hpp,*.H&quot;
- file=&quot;template/cpp_headers&quot;
- type=&quot;org.eclipse.cdt.core.fileType.cxx_header&quot;&gt;
- &lt;/association&gt;
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="apiInfo"/>
- </appInfo>
- <documentation>
- This extension point is purely declarative.
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="implementation"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
-
- <annotation>
- <appInfo>
- <meta.section type="copyright"/>
- </appInfo>
- <documentation>
-
- </documentation>
- </annotation>
-
-</schema>
diff --git a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java
index e5354f4890..8c5d5d2477 100644
--- a/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java
+++ b/core/org.eclipse.cdt.core/search/org/eclipse/cdt/core/search/DOMSearchUtil.java
@@ -46,8 +46,6 @@ import org.eclipse.cdt.core.dom.ast.cpp.ICPPField;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPMethod;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespace;
import org.eclipse.cdt.core.dom.ast.cpp.ICPPNamespaceAlias;
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
import org.eclipse.cdt.core.parser.ParseError;
import org.eclipse.cdt.core.parser.ParserLanguage;
import org.eclipse.cdt.core.parser.util.ArrayUtil;
@@ -59,6 +57,7 @@ import org.eclipse.cdt.internal.core.search.matching.CSearchPattern;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.content.IContentType;
/**
* Utility class to have commonly used algorithms in one place for searching with the DOM.
@@ -330,12 +329,13 @@ public class DOMSearchUtil {
*/
public static ParserLanguage getLanguageFromFile(IFile file) {
IProject project = file.getProject();
- ICFileType type = CCorePlugin.getDefault().getFileType(project, file.getFullPath().lastSegment());
- String lid = type.getLanguage().getId();
- if ( lid != null && lid.equals(ICFileTypeConstants.LANG_CXX) ) {
- return ParserLanguage.CPP;
- }
-
+ IContentType contentType = CCorePlugin.getContentType(project, file.getFullPath().lastSegment());
+ if (contentType != null) {
+ String lid = contentType.getId();
+ if (CCorePlugin.CONTENT_TYPE_CXXSOURCE.equals(lid)) {
+ return ParserLanguage.CPP;
+ }
+ }
return ParserLanguage.C;
}
@@ -443,17 +443,29 @@ public class DOMSearchUtil {
* @return
*/
public static ParserLanguage getLanguage( IPath path, IProject project )
- {
- ICFileType type = CCorePlugin.getDefault().getFileType(project, path.lastSegment());
- boolean isHeader= type.isHeader();
- if( isHeader )
- return ParserLanguage.CPP; // assumption
- String lid = type.getLanguage().getId();
- if( lid.equals(ICFileTypeConstants.LANG_CXX))
- return ParserLanguage.CPP;
- if( lid.equals( ICFileTypeConstants.LANG_C ) )
- return ParserLanguage.C;
- return ParserLanguage.CPP;
+ {
+ //FIXME: ALAIN, for headers should we assume CPP ??
+ // The problem is that it really depends on how the header was included.
+ String id = null;
+ IContentType contentType = CCorePlugin.getContentType(project, path.lastSegment());
+ if (contentType != null) {
+ id = contentType.getId();
+ }
+ if (id != null) {
+ if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) {
+ return ParserLanguage.CPP;
+ } 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 ?
+ } else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
+ return ParserLanguage.C;
+ } else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
+ // ???
+ // What do we do here ?
+ }
+ }
+ return ParserLanguage.CPP;
}
/**
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
index ba166f80d4..2550a772ce 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
@@ -17,10 +17,6 @@ import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.cdt.core.dom.CDOM;
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
-import org.eclipse.cdt.core.filetype.IResolverModel;
-import org.eclipse.cdt.core.internal.filetype.ResolverModel;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
@@ -59,6 +55,9 @@ import org.eclipse.core.runtime.Plugin;
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.osgi.framework.BundleContext;
public class CCorePlugin extends Plugin {
@@ -119,7 +118,30 @@ public class CCorePlugin extends Plugin {
* @see #getDefaultOptions
*/
public static final String CORE_ENCODING = PLUGIN_ID + ".encoding"; //$NON-NLS-1$
- public CDTLogWriter cdtLog = null;
+
+ /**
+ * IContentType id for C Source Unit
+ */
+ public final static String CONTENT_TYPE_CSOURCE = "org.eclipse.cdt.core.cSource"; //$NON-NLS-1$
+ /**
+ * IContentType id for C Header Unit
+ */
+ public final static String CONTENT_TYPE_CHEADER = "org.eclipse.cdt.core.cHeader"; //$NON-NLS-1$
+ /**
+ * IContentType id for C++ Source Unit
+ */
+ public final static String CONTENT_TYPE_CXXSOURCE = "org.eclipse.cdt.core.cxxSource"; //$NON-NLS-1$
+ /**
+ * IContentType id for C++ Header Unit
+ */
+ public final static String CONTENT_TYPE_CXXHEADER = "org.eclipse.cdt.core.cxxHeader"; //$NON-NLS-1$
+ /**
+ * IContentType id for ASM Unit
+ */
+ public final static String CONTENT_TYPE_ASMSOURCE = "org.eclipse.cdt.core.asmSource"; //$NON-NLS-1$
+
+
+ public CDTLogWriter cdtLog = null;
private static CCorePlugin fgCPlugin;
private static ResourceBundle fgResourceBundle;
@@ -578,43 +600,6 @@ public class CCorePlugin extends Plugin {
return parser;
}
- /**
- * Returns the file type object corresponding to the provided
- * file name.
- *
- * If no file type object exists, a default file type object is
- * returned.
- *
- * @param project Project to resolve type info for.
- * @param fileName Name of the file to resolve type info for.
- *
- * @return File type object for the provided file name, in the context
- * of the given project (or the workspace, if project is null)
- */
- public ICFileType getFileType(IProject project, String fileName) {
- return getFileTypeResolver(project).getFileType(fileName);
- }
-
- /**
- * Return the file type resolver for the specified project.
- * Specifying a null project returns the file type resolver
- * for the workspace.
- *
- * @param project Project to get file type resolver for.
- * *
- * @return File type resolver for the project.
- */
- public ICFileTypeResolver getFileTypeResolver(IProject project) {
- if (null == project) {
- return getResolverModel().getResolver();
- }
- return getResolverModel().getResolver(project);
- }
-
- public IResolverModel getResolverModel() {
- return ResolverModel.getDefault();
- }
-
public CoreModel getCoreModel() {
return fCoreModel;
}
@@ -864,6 +849,41 @@ public class CCorePlugin extends Plugin {
return provider;
}
+ /**
+ * Helper function, returning the contenttype for a filename
+ * Same as: <p><p>
+ * getContentType(null, filename)
+ * <br>
+ * @param project
+ * @param name
+ * @return
+ */
+ public static IContentType getContentType(String filename) {
+ return getContentType(null, filename);
+ }
+
+ /**
+ * Helper function, returning the contenttype for a filename
+ * @param project
+ * @param name
+ * @return
+ */
+ public static IContentType getContentType(IProject project, String filename) {
+ // try with the project settings
+ if (project != null) {
+ try {
+ IContentTypeMatcher matcher = project.getContentTypeMatcher();
+ return matcher.findContentTypeFor(filename);
+ } catch (CoreException e) {
+ // ignore.
+ }
+ }
+ // Try in the workspace.
+ IContentTypeManager manager = Platform.getContentTypeManager();
+ return manager.findContentTypeFor(filename);
+ }
+
+
private static final String MODEL = CCorePlugin.PLUGIN_ID + "/debug/model" ; //$NON-NLS-1$
private static final String INDEXER = CCorePlugin.PLUGIN_ID + "/debug/indexer"; //$NON-NLS-1$
private static final String INDEX_MANAGER = CCorePlugin.PLUGIN_ID + "/debug/indexmanager"; //$NON-NLS-1$
@@ -873,7 +893,6 @@ public class CCorePlugin extends Plugin {
private static final String PARSER = CCorePlugin.PLUGIN_ID + "/debug/parser" ; //$NON-NLS-1$
private static final String SCANNER = CCorePlugin.PLUGIN_ID + "/debug/scanner"; //$NON-NLS-1$
private static final String DELTA = CCorePlugin.PLUGIN_ID + "/debug/deltaprocessor" ; //$NON-NLS-1$
- private static final String RESOLVER = CCorePlugin.PLUGIN_ID + "/debug/typeresolver" ; //$NON-NLS-1$
//private static final String CONTENTASSIST = CCorePlugin.PLUGIN_ID + "/debug/contentassist" ; //$NON-NLS-1$
/**
@@ -913,9 +932,6 @@ public class CCorePlugin extends Plugin {
option = Platform.getDebugOption(MATCH_LOCATOR);
if(option != null) MatchLocator.VERBOSE = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
- option = Platform.getDebugOption(RESOLVER);
- if(option != null) ResolverModel.VERBOSE = option.equalsIgnoreCase("true") ; //$NON-NLS-1$
-
if (indexFlag == true){
JobManager.VERBOSE = true;
}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileType.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileType.java
deleted file mode 100644
index afe4aa4fbe..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileType.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-/**
- * Corresponds to an org.eclipse.cdt.core.CFileType entry.
- */
-public interface ICFileType {
-
- /** Value indicating an unknown file type **/
- static public final int TYPE_UNKNOWN = 0;
-
- /** Value indicating a source file type **/
- static public final int TYPE_SOURCE = 1;
-
- /** Value indicating a header file **/
- static public final int TYPE_HEADER = 2;
-
- /**
- * @return Id associated with this file type.
- */
- public String getId();
-
- /**
- * @return Language associated with this file type.
- */
- public ICLanguage getLanguage();
-
- /**
- * @return Name of this file type.
- */
- public String getName();
-
- /**
- * Return the integer value indicating file type.
- *
- * @return the TYPE_* value indicating the file type.
- */
- public int getType();
-
- /**
- * @return True if this is a known source file type.
- */
- public boolean isSource();
-
- /**
- * @return True if this is a known header file type.
- */
- public boolean isHeader();
-
- /**
- * @return True if this is a known source or header file type.
- */
- public boolean isTranslationUnit();
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeAssociation.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeAssociation.java
deleted file mode 100644
index 0d2551059e..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeAssociation.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-import java.util.Comparator;
-
-/**
- * Corresponds to an org.eclipse.cdt.core.CFileTypeAssociation entry.
- */
-public interface ICFileTypeAssociation {
-
- public static Comparator Comparator = new Comparator() {
- public int compare(Object arg0, Object arg1) {
- ICFileTypeAssociation lhs = (ICFileTypeAssociation) arg0;
- ICFileTypeAssociation rhs = (ICFileTypeAssociation) arg1;
- return (lhs.getPattern().compareTo(rhs.getPattern()));
- }
- };
-
- /**
- * @return the file name pattern used for this file association
- */
- public String getPattern();
-
- /**
- * @return the ICFileType associated with the file name pattern
- */
- public ICFileType getType();
-
- /**
- * Determine if the file name pattern for this association
- * matches the provided name.
- *
- * @param fileName file name to match.
- *
- * @return true if the file name pattern matches the provided name
- */
- public boolean matches(String fileName);
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeConstants.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeConstants.java
deleted file mode 100644
index f36e99b809..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeConstants.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-/**
- * Constants that identify base attribute and language IDs
- */
-public interface ICFileTypeConstants {
-
- public static String ID_PREFIX = "org.eclipse.cdt.core."; //$NON-NLS-1$
-
- // Default languages known to CDT
-
- public static String LANG_PREFIX = ID_PREFIX + "language."; //$NON-NLS-1$
-
- public static String LANG_UNKNOWN = LANG_PREFIX + "unknown"; //$NON-NLS-1$
-
- public static String LANG_C = LANG_PREFIX + "c"; //$NON-NLS-1$
-
- public static String LANG_CXX = LANG_PREFIX + "cxx"; //$NON-NLS-1$
-
- public static String LANG_ASM = LANG_PREFIX + "asm"; //$NON-NLS-1$
-
- // Default file types known to CDT
-
- public static String FT_PREFIX = ID_PREFIX + "fileType."; //$NON-NLS-1$
-
- public static String FT_UNKNOWN = FT_PREFIX + "unknown"; //$NON-NLS-1$
-
- public static String FT_C_SOURCE = FT_PREFIX + "c_source"; //$NON-NLS-1$
-
- public static String FT_C_HEADER = FT_PREFIX + "c_header"; //$NON-NLS-1$
-
- public static String FT_CXX_SOURCE = FT_PREFIX + "cxx_source"; //$NON-NLS-1$
-
- public static String FT_CXX_HEADER = FT_PREFIX + "cxx_header"; //$NON-NLS-1$
-
- public static String FT_ASM_SOURCE = FT_PREFIX + "asm_source"; //$NON-NLS-1$
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeResolver.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeResolver.java
deleted file mode 100644
index bac5968979..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeResolver.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-import org.eclipse.core.resources.IContainer;
-
-/**
- * Class responsible for resolving a file name into the
- * associated file type.
- *
- * Accessed by ICFileTypeResolver and file type management UI.
- */
-public interface ICFileTypeResolver {
- /**
- * @return array containing all known file types.
- */
- public ICFileTypeAssociation[] getFileTypeAssociations();
-
- /**
- * Determine which file type corresponds to the given
- * file name.
- *
- * @param fileName file name to check.
- *
- * @return file type for the provided file name
- */
- public ICFileType getFileType(String fileName);
-
- /**
- * Add multiple file type associations to the resolver's list.
- * This method does not fire delta changes use adjustAssociations.
- *
- * @param assocs array of file type associations to add; may be null.
- *
- * @return true if at least one file type association was added.
- */
- public boolean addAssociations(ICFileTypeAssociation[] assocs);
-
- /**
- * Remove multiple file type associations from the resolver's list.
- * This method does not fire delta changes use adjustAssociations.
- *
- * @param assoc array of file type association to remove; may be null
- *
- * @return true if at least one file type association was removed.
- */
- public boolean removeAssociations(ICFileTypeAssociation[] assocs);
-
- /**
- * Add and/or remove associations from the resolver in a
- * batch operation. Either (or both) of the parameters
- * may be null. This method fires delta change events.
- *
- * @param add associations to add to the resolver; may be null
- * @param rem associations to remove from the resolver; may be null
- *
- * @return true if at least one file type association was added or removed
- */
- public boolean adjustAssociations(ICFileTypeAssociation[] add, ICFileTypeAssociation[] remove);
-
- /**
- * Create a working copy of this file type resolver.
- *
- * The copy contains the current set of associations that
- * make up the resolver.
- *
- * @return working copy of this file type resolver
- */
- public ICFileTypeResolver createWorkingCopy();
-
- /**
- * The container of the resolver can be IWorkspaceRoot or IProject.
- *
- * @return
- */
- public IContainer getContainer();
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICLanguage.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICLanguage.java
deleted file mode 100644
index 4ff131364f..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICLanguage.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-/**
- * Corresponds to an org.eclipse.cdt.core.CLanguage entry.
- */
-public interface ICLanguage {
-
- /**
- * @return Id associated with this language.
- */
- public String getId();
-
- /**
- * @return Name of this language.
- */
- public String getName();
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/IResolverChangeListener.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/IResolverChangeListener.java
deleted file mode 100644
index 2a8b7ca0cf..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/IResolverChangeListener.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-/**
- * Listener interface for clients interested in changes to an
- * individual resolver.
- */
-public interface IResolverChangeListener {
- public void resolverChanged(ResolverChangeEvent event);
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/IResolverModel.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/IResolverModel.java
deleted file mode 100644
index 0b5fecf4f1..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/IResolverModel.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-import org.eclipse.core.resources.IProject;
-
-/**
- * Main entry point for dealign with the resolver model.
- */
-public interface IResolverModel {
- /**
- * @return array containing all known languages.
- */
- public ICLanguage[] getLanguages();
-
- /**
- * @return array containing all known file types.
- */
- public ICFileType[] getFileTypes();
-
- /**
- * Get the language that has the specified id.
- * Returns null if no language has that id.
- *
- * @param languageId language id
- *
- * @return language with the specified id, or null
- */
- public ICLanguage getLanguageById(String languageId);
-
- /**
- * Get the file type that has the specified id.
- * Returns null if no file type has that id.
- *
- * @param typeId file type id
- *
- * @return file type with the specified id, or null
- */
- public ICFileType getFileTypeById(String typeId);
-
- /**
- * Get the resolver for the current workspace.
- *
- * @return workspace resolver
- */
- public ICFileTypeResolver getResolver();
-
- /**
- * Create a custom resolver for the specified project.
- *
- * The project resolver is set to a custom
- * resolver, and the resolver data is persisted
- * in the project (in the .cdtproject file).
- *
- * This method fires changed event
- *
- * @param project - project this resolver applied to
- * @param copyResolver - retrieve associations for the copy to populate the custom resolver.
- */
- public ICFileTypeResolver createCustomResolver(IProject project, ICFileTypeResolver copyResolver);
-
- /**
- * Remove the custom resolver on the project.
- * This method fires changed event
- *
- * @param project
- */
- public void removeCustomResolver(IProject project);
-
- /**
- * Return true if the project has a custom resolver.
- *
- * @param project
- * @return true if a custom resolver
- */
- public boolean hasCustomResolver(IProject project);
-
- /**
- * Get the resolver for the specified project.
- *
- * If the project resolver is unavailable, or the
- * project does not use a custom resolver, then the
- * workspace resolver is returned.
- *
- * @param project to retrieve resolver for
- *
- * @return project resolver
- */
- public ICFileTypeResolver getResolver(IProject project);
-
- /**
- * Create a new file type assocation. The association
- * may be added to a type resolver.
- *
- * @param pattern filename pattern for the association.
- * @param type association file type.
- *
- * @return newly created file type association
- */
- public ICFileTypeAssociation createAssocation(String pattern, ICFileType type);
-
- /**
- * Adds the given listener for model change events to the model.
- * Has no effect if an identical listener is already registered.
- *
- * @param listener listener to add
- */
- public void addResolverChangeListener(IResolverChangeListener listener);
-
- /**
- * Removes the given change listener from the model.
- * Has no effect if an identical listener is not registered.
- *
- * @param listener listener to remove
- */
- public void removeResolverChangeListener(IResolverChangeListener listener);
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ResolverChangeEvent.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ResolverChangeEvent.java
deleted file mode 100644
index caa2c56057..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ResolverChangeEvent.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-import java.util.ArrayList;
-import java.util.EventObject;
-import java.util.Iterator;
-import java.util.List;
-
-
-public class ResolverChangeEvent extends EventObject {
-
- /**
- * Comment for <code>serialVersionUID</code>
- */
- private static final long serialVersionUID = 4121128156301178929L;
- private List fDeltas = new ArrayList();
- private ICFileTypeResolver fNewResolver;
- private ICFileTypeResolver fOldResolver;
-
- /**
- * Create a new resolver change event. The event is empty
- * of any change deltas, and references the provided file
- * type resolver.
- *
- * @param resolver file type resolver this event applies to
- */
- public ResolverChangeEvent(IResolverModel model, ICFileTypeResolver resolver) {
- this(model, resolver, null);
- }
-
- /**
- * Create a new resolver change event. The event is empty
- * of any change deltas, and references the provided file
- * type resolver.
- *
- * @param resolver file type resolver this event applies to
- */
- public ResolverChangeEvent(IResolverModel model, ICFileTypeResolver newResolver, ICFileTypeResolver oldResolver) {
- super(model);
- fNewResolver = newResolver;
- fOldResolver = oldResolver;
- }
-
- public boolean resolverHasChanged() {
- return fOldResolver != null;
- }
-
- /**
- * @return resolver affected by this change
- */
- public ICFileTypeResolver getResolver() {
- return fNewResolver;
- }
-
- /**
- * @return number of resolver deltas involved in this change
- */
- public int getDeltaCount() {
- return fDeltas.size();
- }
-
- /**
- * @return ResolverDelta[] for this change
- */
- public ResolverDelta[] getDeltas() {
- return (ResolverDelta[]) fDeltas.toArray(new ResolverDelta[fDeltas.size()]);
- }
-
- /**
- * Add a new delta to the list of deltas.
- *
- * @param delta instance of ResolverDelta to add to the list.
- */
- public void addDelta(ResolverDelta delta) {
- fDeltas.add(delta);
- }
-
- public String toString() {
- StringBuffer buf = new StringBuffer();
-
- buf.append("ResolverChangeEvent ["); //$NON-NLS-1$
- buf.append(fDeltas.size());
- buf.append(" delta(s)]"); //$NON-NLS-1$
-
- for (Iterator iter = fDeltas.iterator(); iter.hasNext();) {
- ResolverDelta element = (ResolverDelta) iter.next();
- buf.append("\n "); //$NON-NLS-1$
- buf.append(element.toString());
- }
-
- return buf.toString();
- }
-
-
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ResolverDelta.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ResolverDelta.java
deleted file mode 100644
index cc8e62bf1c..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ResolverDelta.java
+++ /dev/null
@@ -1,110 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.filetype;
-
-
-public class ResolverDelta {
- public static final int EVENT_ADD = 0x10;
- public static final int EVENT_REMOVE = 0x20;
- public static final int EVENT_SET = 0x40;
- public static final int EVENT_MASK = 0xF0;
-
- public static final int ELEMENT_LANGUAGE = 0x01;
- public static final int ELEMENT_FILETYPE = 0x02;
- public static final int ELEMENT_ASSOCIATION = 0x04;
- public static final int ELEMENT_MASK = 0x0F;
-
- private Object fElement;
- private int fEvent;
-
- public ResolverDelta(int eventType, int elementType, Object element) {
- fElement = element;
- fEvent = eventType | elementType;
- }
-
- public ResolverDelta(ICLanguage lang, int event) {
- this(event, ELEMENT_LANGUAGE, lang);
- }
-
- public ResolverDelta(ICFileType type, int event) {
- this(event, ELEMENT_FILETYPE, type);
- }
-
- public ResolverDelta(ICFileTypeAssociation assoc, int event) {
- this(event, ELEMENT_ASSOCIATION, assoc);
- }
-
- public Object getElement() {
- return fElement;
- }
-
- public int getElementType() {
- return fEvent & ELEMENT_MASK;
- }
-
- public int getEventType() {
- return fEvent & EVENT_MASK;
- }
-
- public ICLanguage getLanguage() {
- return ((fElement instanceof ICLanguage) ? ((ICLanguage) fElement) : null);
- }
-
- public ICFileType getFileType() {
- return ((fElement instanceof ICFileType) ? ((ICFileType) fElement) : null);
- }
-
- public ICFileTypeAssociation getAssociation() {
- return ((fElement instanceof ICFileTypeAssociation) ? ((ICFileTypeAssociation) fElement) : null);
- }
-
- public int getEvent() {
- return fEvent;
- }
-
- public String toString() {
- StringBuffer buf = new StringBuffer();
- switch (getEventType()) {
- case EVENT_ADD:
- buf.append("add"); //$NON-NLS-1$
- break;
- case EVENT_REMOVE:
- buf.append("remove"); //$NON-NLS-1$
- break;
- case EVENT_SET:
- buf.append("set"); //$NON-NLS-1$
- break;
- default:
- buf.append("?unknown event?"); //$NON-NLS-1$
- break;
- }
- buf.append(' ');
- switch (getElementType()) {
- case ELEMENT_LANGUAGE:
- buf.append("language "); //$NON-NLS-1$
- buf.append(null != getLanguage() ? getLanguage().getName() : "?"); //$NON-NLS-1$
- break;
- case ELEMENT_FILETYPE:
- buf.append("filetype "); //$NON-NLS-1$
- buf.append(null != getFileType() ? getFileType().getName() : "?"); //$NON-NLS-1$
- break;
- case ELEMENT_ASSOCIATION:
- buf.append("assoc "); //$NON-NLS-1$
- buf.append(null != getAssociation() ? getAssociation().getPattern() : "?"); //$NON-NLS-1$
- break;
- default:
- buf.append("?unknown source?"); //$NON-NLS-1$
- break;
- }
-
- return buf.toString();
- }
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/Argument.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/Argument.java
deleted file mode 100644
index cc96c97068..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/Argument.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.internal.filetype;
-
-/**
- * Utility class used to check arguments and generate an
- * IllegalArgumentException if they fail to meet some
- * minimum requirements (null ref, empty string, etc.)
- */
-public class Argument {
-
- /**
- * Throw an exception if a string argument is null or empty.
- *
- * @param arg String to check
- *
- * @throws IllegalArgumentException
- */
- static public void check(String arg) throws IllegalArgumentException {
- check(arg, false);
- }
-
- /**
- * Throw an exception if a string argument is null (and optionally,
- * if the string is empty).
- *
- * @param arg String to check
- * @param allowEmpty True to allow an empty string.
- *
- * @throws IllegalArgumentException
- */
- static public void check(String arg, boolean allowEmpty) throws IllegalArgumentException {
- if (null == arg) {
- throw new IllegalArgumentException("Null string argument"); //$NON-NLS-1$
- } else if (0 == arg.length()) {
- throw new IllegalArgumentException("Empty string argument"); //$NON-NLS-1$
- }
- }
-
- /**
- * Throws an exception if an object argument is null.
- *
- * @param arg Object to check
- *
- * @throws IllegalArgumentException
- */
- static public void check(Object arg) throws IllegalArgumentException {
- if (null == arg) {
- throw new IllegalArgumentException("Null reference argument"); //$NON-NLS-1$
- }
- }
-
- /**
- * Throws an exception if an integer argument lies outside the specified
- * range.
- *
- * @param arg Integer to check
- * @param min Minimum allowed value for the argument.
- * @param max Maximum allowed value for the argument.
- *
- * @throws IllegalArgumentException
- */
- static public void check(int arg, int min, int max) throws IllegalArgumentException {
- if (arg < min) {
- throw new IllegalArgumentException("Integer argument out of range (low)"); //$NON-NLS-1$
- } else if (arg > max) {
- throw new IllegalArgumentException("Integer argument out of range (high)"); //$NON-NLS-1$
- }
- }
-
-
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileType.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileType.java
deleted file mode 100644
index 9cb3149fe0..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileType.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.internal.filetype;
-
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICLanguage;
-
-/**
- * Representation of a declared file type.
- */
-public class CFileType implements ICFileType {
-
- private ICLanguage fLang;
- private String fId;
- private String fName;
- private int fType;
-
- public CFileType(String id, ICLanguage language, String name, int type) {
- Argument.check(id);
- Argument.check(language);
- Argument.check(name);
- Argument.check(type, ICFileType.TYPE_UNKNOWN, ICFileType.TYPE_HEADER);
-
- fId = id;
- fLang = language;
- fName = name;
- fType = type;
- }
-
- public String getId() {
- return fId;
- }
-
- public ICLanguage getLanguage() {
- return fLang;
- }
-
- public String getName() {
- return fName;
- }
-
- public int getType() {
- return fType;
- }
-
- public boolean isSource() {
- return (ICFileType.TYPE_SOURCE == fType);
- }
-
- public boolean isHeader() {
- return (ICFileType.TYPE_HEADER == fType);
- }
-
- public boolean isTranslationUnit() {
- return (isSource() || isHeader());
- }
-
- public boolean equals(Object object) {
- if (!(object instanceof ICFileType)) {
- return false;
- }
-
- ICFileType rhs = (ICFileType) object;
- boolean eq = (fType == rhs.getType());
-
- if (eq) eq = fId.equals(rhs.getId());
- if (eq) eq = fLang.equals(rhs.getLanguage());
- if (eq) eq = fName.equals(rhs.getName());
-
- return eq;
- }
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeAssociation.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeAssociation.java
deleted file mode 100644
index 16b8749ed6..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeAssociation.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.internal.filetype;
-
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
-import org.eclipse.cdt.internal.core.index.StringMatcher;
-
-/**
- * Representation of a declared file type association.
- */
-public class CFileTypeAssociation implements ICFileTypeAssociation {
-
- private String fPattern;
- private ICFileType fType;
- private StringMatcher fMatcher;
-
- public CFileTypeAssociation(String pattern, ICFileType type) {
- Argument.check(pattern);
- Argument.check(type);
-
- fPattern = pattern;
- fType = type;
- fMatcher = new StringMatcher(pattern, false, false);
- }
-
- public String getPattern() {
- return fPattern;
- }
-
- public ICFileType getType() {
- return fType;
- }
-
- public boolean matches(String fileName) {
- if (null == fileName) {
- return (null == fPattern);
- }
- return fMatcher.match(fileName);
- }
-
- public boolean equals(Object object) {
- if (!(object instanceof ICFileTypeAssociation)) {
- return false;
- }
-
- ICFileTypeAssociation rhs = (ICFileTypeAssociation) object;
- boolean eq = fPattern.equals(rhs.getPattern());
-
- if (eq) eq = fType.equals(rhs.getType());
-
- return eq;
- }
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeResolver.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeResolver.java
deleted file mode 100644
index ec18795bfc..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeResolver.java
+++ /dev/null
@@ -1,152 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.internal.filetype;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
-import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
-import org.eclipse.core.resources.IContainer;
-
-public abstract class CFileTypeResolver implements ICFileTypeResolver {
-
- // the container of the resolver
- protected IContainer fContainer;
-
- // The association list holds a list of known file associations.
- protected List fAssocList;
-
- public CFileTypeResolver(IContainer container) {
- fContainer = container;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.filetype.ICFileTypeResolver#getContainer()
- */
- public IContainer getContainer() {
- return fContainer;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.filetype.ICFileTypeResolver#addAssociations(org.eclipse.cdt.core.filetype.ICFileTypeAssociation[])
- */
- public boolean addAssociations(ICFileTypeAssociation[] assocs) {
- return adjustAssociations(assocs, null, false);
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.filetype.ICFileTypeResolver#getFileType(java.lang.String)
- */
- public ICFileType getFileType(String fileName) {
- ICFileTypeAssociation[] assocs = getFileTypeAssociations();
- for (int i = 0; i < assocs.length; ++i) {
- ICFileTypeAssociation element = assocs[i];
- if (element.matches(fileName)) {
- return element.getType();
- }
- }
- return ResolverModel.DEFAULT_FILE_TYPE;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.filetype.ICFileTypeResolver#removeAssociations(org.eclipse.cdt.core.filetype.ICFileTypeAssociation[])
- */
- public boolean removeAssociations(ICFileTypeAssociation[] assocs) {
- return adjustAssociations(null, assocs, false);
- }
-
-
- public synchronized ICFileTypeAssociation[] getFileTypeAssociations() {
- if (fAssocList == null) {
- loadAssociationList();
- }
- return (ICFileTypeAssociation[]) fAssocList.toArray(new ICFileTypeAssociation[fAssocList.size()]);
- }
-
- public boolean adjustAssociations(ICFileTypeAssociation[] addAssocs, ICFileTypeAssociation[] delAssocs) {
- return adjustAssociations(addAssocs, delAssocs, true);
- }
-
- protected synchronized boolean adjustAssociations(ICFileTypeAssociation[] addAssocs,
- ICFileTypeAssociation[] delAssocs, boolean triggerEvent) {
- List addList = new ArrayList();
- List delList = new ArrayList();
-
- loadAssociationList();
-
- // check the adds
- if (null != addAssocs) {
- for (int i = 0; i < addAssocs.length; i++) {
- if (!fAssocList.contains(addAssocs[i])) {
- fAssocList.add(addAssocs[i]);
- addList.add(addAssocs[i]);
- }
- }
- }
-
- // check the removes
- if (null != delAssocs) {
- for (int i = 0; i < delAssocs.length; i++) {
- if (fAssocList.remove(delAssocs[i])) {
- delList.add(delAssocs[i]);
- }
- }
- }
-
- // Anything change ?
- boolean changed = !addList.isEmpty() || !delList.isEmpty();
-
- if (changed) {
- Collections.sort(fAssocList, ICFileTypeAssociation.Comparator);
- addAssocs = (ICFileTypeAssociation[]) addList.toArray(new ICFileTypeAssociation[addList.size()]);
- delAssocs = (ICFileTypeAssociation[]) delList.toArray(new ICFileTypeAssociation[delList.size()]);
- doAdjustAssociations(addAssocs, delAssocs, triggerEvent);
- }
-
- return changed;
- }
-
- public ICFileTypeResolver createWorkingCopy() {
- final ICFileTypeAssociation[] associations = getFileTypeAssociations();
- CFileTypeResolver copy = new CFileTypeResolver(fContainer) {
- public void doAdjustAssociations(ICFileTypeAssociation[] add, ICFileTypeAssociation[] del,
- boolean triggerEvent) {
- //
- }
- protected ICFileTypeAssociation[] loadAssociations() {
- return associations;
- }
- };
- return copy;
- }
-
- protected abstract void doAdjustAssociations(ICFileTypeAssociation[] addAssocs, ICFileTypeAssociation[] delAssocs,
- boolean triggerEvent);
- protected abstract ICFileTypeAssociation[] loadAssociations();
-
-
- private synchronized List loadAssociationList() {
- if (fAssocList == null) {
- fAssocList = new ArrayList();
- ICFileTypeAssociation[] assocs = loadAssociations();
- if (assocs != null) {
- fAssocList.addAll(Arrays.asList(assocs));
- Collections.sort(fAssocList, ICFileTypeAssociation.Comparator);
- }
- }
- return fAssocList;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CLanguage.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CLanguage.java
deleted file mode 100644
index ddfde8b3ac..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CLanguage.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.internal.filetype;
-
-import org.eclipse.cdt.core.filetype.ICLanguage;
-
-/**
- * Representation of a declared file type.
- */
-public class CLanguage implements ICLanguage {
-
- private String fId;
- private String fName;
-
- public CLanguage(String id, String name) {
- Argument.check(id);
- Argument.check(name);
-
- fId = id;
- fName = name;
- }
-
- public String getId() {
- return fId;
- }
-
- public String getName() {
- return fName;
- }
-
- public boolean equals(Object object) {
- if (!(object instanceof ICLanguage)) {
- return false;
- }
-
- ICLanguage rhs = (ICLanguage) object;
- boolean eq = fId.equals(rhs.getId());
- if (eq) eq = fName.equals(rhs.getName());
-
- return eq;
- }
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CustomResolver.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CustomResolver.java
deleted file mode 100644
index 2d89a0f9eb..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CustomResolver.java
+++ /dev/null
@@ -1,311 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * QNX Software Systems - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.cdt.core.internal.filetype;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.ICDescriptor;
-import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
-import org.eclipse.cdt.core.filetype.IResolverModel;
-import org.eclipse.cdt.core.filetype.ResolverChangeEvent;
-import org.eclipse.cdt.core.filetype.ResolverDelta;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-
-/**
- */
-public class CustomResolver extends CFileTypeResolver {
-
- // XML tag names, etc.
- private static final String OLD_RESOLVER = "cdt_resolver"; //$NON-NLS-1$
- private static final String CDT_RESOLVER = CCorePlugin.PLUGIN_ID + ".resolver"; //$NON-NLS-1$
- private static final String TAG_CUSTOM = "custom"; //$NON-NLS-1$
- private static final String TAG_ASSOC = "associations"; //$NON-NLS-1$
- private static final String TAG_ENTRY = "entry"; //$NON-NLS-1$
- private static final String ATTR_TYPE = "type"; //$NON-NLS-1$
- private static final String ATTR_PATTERN = "pattern"; //$NON-NLS-1$
- private static final String ATTR_VALUE = "value"; //$NON-NLS-1$
-
- private ResolverModel fModel;
-
- public CustomResolver(ResolverModel model, IProject p) {
- super(p);
- fModel = model;
- }
-
- public static boolean hasCustomResolver(IProject project) {
- Boolean custom = new Boolean(false);
- // Check for old custom resolver but do not convert
-
- Element data = getProjectOldResolverData(project, false);
- custom = hasCustomTag(data);
-
- if (!custom.booleanValue()) {
- data = getProjectResolverData(project, false);
- custom = hasCustomTag(data);
- }
-
- return custom.booleanValue();
- }
-
- /**
- * @param project
- */
- public static void removeCustomResover(IProject project) {
- Element root = getProjectResolverData(project, false);
- if (root != null) {
- Node child = root.getFirstChild();
- Element element = null;
-
- // Clear the old stuff.
- while (child != null) {
- root.removeChild(child);
- child = root.getFirstChild();
- }
- try {
- getProjectDescriptor(project, true).saveProjectData();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- }
- }
- }
-
- protected void doAdjustAssociations(ICFileTypeAssociation[] addAssocs, ICFileTypeAssociation[] delAssocs,
- boolean triggerEvent) {
- IProject project = (IProject)getContainer();
- List deltas = new ArrayList();
-
- // add
- if (triggerEvent && null != addAssocs && addAssocs.length > 0) {
- for (int i = 0; i < addAssocs.length; i++) {
- deltas.add(new ResolverDelta(addAssocs[i], ResolverDelta.EVENT_ADD));
- }
- }
-
- // remove
- if (triggerEvent && null != delAssocs && delAssocs.length > 0) {
- for (int i = 0; i < delAssocs.length; i++) {
- deltas.add(new ResolverDelta(delAssocs[i], ResolverDelta.EVENT_REMOVE));
- }
- }
-
- // fire the deltas.
- if (triggerEvent && !deltas.isEmpty()) {
- ResolverChangeEvent event = new ResolverChangeEvent(fModel, this);
- for (int i = 0; i < deltas.size(); ++i) {
- ResolverDelta delta = (ResolverDelta)deltas.get(i);
- event.addDelta(delta);
- }
- fModel.fireEvent(event);
- }
-
- // Save to the file.
-
- Element root = getProjectResolverData(project, true);
- Document doc = root.getOwnerDocument();
- Node child = root.getFirstChild();
- Element element = null;
-
- // Clear the old stuff.
- while (child != null) {
- root.removeChild(child);
- child = root.getFirstChild();
- }
-
- element = doc.createElement(TAG_CUSTOM);
- element.setAttribute(ATTR_VALUE, Boolean.TRUE.toString());
- root.appendChild(element);
-
- element = doc.createElement(TAG_ASSOC);
- root.appendChild(element);
-
- root = element; // Note that root changes...
-
- ICFileTypeAssociation[] assoc = getFileTypeAssociations();
-
- for (int i = 0; i < assoc.length; i++) {
- element = doc.createElement(TAG_ENTRY);
- element.setAttribute(ATTR_PATTERN, assoc[i].getPattern());
- element.setAttribute(ATTR_TYPE, assoc[i].getType().getId());
- root.appendChild(element);
- }
-
- try {
- getProjectDescriptor(project, true).saveProjectData();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- }
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.internal.filetype.CFileTypeResolver#loadAssociations()
- */
- protected ICFileTypeAssociation[] loadAssociations() {
-
- IProject project = (IProject)getContainer();
-
- convert20(project);
-
- List assocs = new ArrayList();
- Element data = getProjectResolverData(project, false);
- Node child = ((null != data) ? data.getFirstChild() : null);
- while (child != null) {
- if (child.getNodeName().equals(TAG_ASSOC)) {
- Node assoc = child.getFirstChild();
- while (assoc != null) {
- if (assoc.getNodeName().equals(TAG_ENTRY)) {
- Element element = (Element) assoc;
- String pattern = element.getAttribute(ATTR_PATTERN);
- String typeId = element.getAttribute(ATTR_TYPE);
- try {
- assocs.add(fModel.createAssocation(pattern, fModel.getFileTypeById(typeId)));
- } catch (IllegalArgumentException e) {
- CCorePlugin.log(e);
- }
- }
- assoc = assoc.getNextSibling();
- }
- }
- child = child.getNextSibling();
- }
- return (ICFileTypeAssociation[]) assocs.toArray(new ICFileTypeAssociation[assocs.size()]);
- }
-
- private static Element getProjectResolverData(IProject project, boolean create) {
- Element data = null;
- try {
- ICDescriptor desc = getProjectDescriptor(project, create);
- if (desc != null) {
- data = desc.getProjectData(CDT_RESOLVER);
- }
- } catch (CoreException e) {
- // ignore
- }
- return data;
- }
-
- private static ICDescriptor getProjectDescriptor(IProject project, boolean create) throws CoreException {
- ICDescriptor descriptor = null;
- descriptor = CCorePlugin.getDefault().getCProjectDescription(project, create);
- return descriptor;
- }
-
- private static Element getProjectOldResolverData(IProject project, boolean create) {
- Element data = null;
- try {
- ICDescriptor desc = getProjectDescriptor(project, create);
- if (desc != null) {
- data = desc.getProjectData(OLD_RESOLVER);
- }
- } catch (CoreException e) {
- // ignore
- }
- return data;
- }
-
- private static void convert20(IProject project) {
- Element root = getProjectOldResolverData(project, false);
- if (root != null) {
- IResolverModel model = ResolverModel.getDefault();
- List assocList = new ArrayList();
-
- // 1 - get the old stuff
- Node child = root.getFirstChild();
- while (child != null) {
- if (child.getNodeName().equals(TAG_ASSOC)) {
- Node assoc = child.getFirstChild();
- while (assoc != null) {
- if (assoc.getNodeName().equals(TAG_ENTRY)) {
- Element element = (Element) assoc;
- String pattern = element.getAttribute(ATTR_PATTERN);
- String typeId = element.getAttribute(ATTR_TYPE);
- try {
- assocList.add(model.createAssocation(pattern, model.getFileTypeById(typeId)));
- } catch (IllegalArgumentException e) {
- CCorePlugin.log(e);
- }
- }
- assoc = assoc.getNextSibling();
- }
- }
- child = child.getNextSibling();
- }
-
- // 2 - Clear the old stuff.
- child = root.getFirstChild();
- while (child != null) {
- root.removeChild(child);
- child = root.getFirstChild();
- }
-
- ICFileTypeAssociation[] assocs = (ICFileTypeAssociation[]) assocList.toArray(new ICFileTypeAssociation[assocList.size()]);
-
- if (assocs.length > 0) {
- // 3 - save the old stuff on the new id
- root = getProjectResolverData(project, true);
- if (root != null) {
- Document doc = root.getOwnerDocument();
- child = root.getFirstChild();
- Element element = null;
-
- // Clear the old stuff.
- while (child != null) {
- root.removeChild(child);
- child = root.getFirstChild();
- }
-
- element = doc.createElement(TAG_CUSTOM);
- element.setAttribute(ATTR_VALUE, Boolean.TRUE.toString());
- root.appendChild(element);
-
- element = doc.createElement(TAG_ASSOC);
- root.appendChild(element);
-
- root = element; // Note that root changes...
-
- for (int i = 0; i < assocs.length; i++) {
- element = doc.createElement(TAG_ENTRY);
- element.setAttribute(ATTR_PATTERN, assocs[i].getPattern());
- element.setAttribute(ATTR_TYPE, assocs[i].getType().getId());
- root.appendChild(element);
- }
-
- }
- }
- try {
- getProjectDescriptor(project, true).saveProjectData();
- } catch (CoreException e) {
- CCorePlugin.log(e);
- }
- }
- }
-
- private static Boolean hasCustomTag(Element data) {
- Node child = ((null != data) ? data.getFirstChild() : null);
- Boolean custom = new Boolean(false);
-
- while (child != null) {
- if (child.getNodeName().equals(TAG_CUSTOM)) {
- return Boolean.valueOf(((Element)child).getAttribute(ATTR_VALUE));
- }
- child = child.getNextSibling();
- }
- return Boolean.FALSE;
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/ResolverModel.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/ResolverModel.java
deleted file mode 100644
index 1bc773d2e5..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/ResolverModel.java
+++ /dev/null
@@ -1,816 +0,0 @@
-/**********************************************************************
- * Copyright (c) 2004 TimeSys Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * TimeSys Corporation - Initial API and implementation
-***********************************************************************/
-package org.eclipse.cdt.core.internal.filetype;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Vector;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
-import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
-import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
-import org.eclipse.cdt.core.filetype.ICLanguage;
-import org.eclipse.cdt.core.filetype.IResolverChangeListener;
-import org.eclipse.cdt.core.filetype.IResolverModel;
-import org.eclipse.cdt.core.filetype.ResolverChangeEvent;
-import org.eclipse.cdt.core.filetype.ResolverDelta;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionDelta;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IRegistryChangeEvent;
-import org.eclipse.core.runtime.IRegistryChangeListener;
-import org.eclipse.core.runtime.ISafeRunnable;
-import org.eclipse.core.runtime.IStatus;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Preferences;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.Preferences.PropertyChangeEvent;
-import org.eclipse.core.runtime.content.IContentType;
-import org.eclipse.core.runtime.content.IContentTypeManager;
-
-/**
- * Implementation of the file type resolver interface.
- */
-public class ResolverModel implements IResolverModel {
-
- /**
- * Name used to describe an unknown language or file type
- */
- public static final String NAME_UNKNOWN = "Unknown"; //$NON-NLS-1$
-
- /**
- * Default language, returned when no other language matches a language id.
- */
- public static final ICLanguage DEFAULT_LANG_TYPE =
- new CLanguage(ICFileTypeConstants.LANG_UNKNOWN, NAME_UNKNOWN);
-
- /**
- * Default file type, returned when no other file type matches a file name.
- */
- public static final ICFileType DEFAULT_FILE_TYPE =
- new CFileType(ICFileTypeConstants.FT_UNKNOWN, DEFAULT_LANG_TYPE, NAME_UNKNOWN, ICFileType.TYPE_UNKNOWN);
-
- // The language map holds a map of language IDs to descriptive strings.
- private Map fLangMap = new HashMap();
-
- // The type map holds a map of file type IDs to file types.
- private Map fTypeMap = new HashMap();
-
- // Default resolver
- private ICFileTypeResolver fWorkspaceResolver = null;
-
- // XML tag names, etc.
- private static final String EXTENSION_LANG = "CLanguage"; //$NON-NLS-1$
- private static final String EXTENSION_TYPE = "CFileType"; //$NON-NLS-1$
- private static final String EXTENSION_ASSOC = "CFileTypeAssociation"; //$NON-NLS-1$
- private static final String ATTR_TYPE = "type"; //$NON-NLS-1$
- private static final String ATTR_ID = "id"; //$NON-NLS-1$
- private static final String ATTR_LANGUAGE = "language"; //$NON-NLS-1$
- private static final String ATTR_NAME = "name"; //$NON-NLS-1$
- private static final String ATTR_VAL_SOURCE = "source"; //$NON-NLS-1$
- private static final String ATTR_VAL_HEADER = "header"; //$NON-NLS-1$
-
- // Trace flag
- public static boolean VERBOSE = false;
-
- // Singleton
- private static ResolverModel fInstance = null;
-
- // Qualified names used to identify project session properties
- private static final String QN_RESOLVER_MODEL_ID = CCorePlugin.PLUGIN_ID + ".resolver"; //$NON-NLS-1$
- private static final QualifiedName QN_CUSTOM_RESOLVER = new QualifiedName(QN_RESOLVER_MODEL_ID, "custom"); //$NON-NLS-1$
-
- // List of listeners on the model
- private List fListeners = new Vector();
-
- // Private ctor to preserve singleton status
- private ResolverModel() {
- try {
- loadDeclaredLanguages();
- loadDeclaredTypes();
-
- fWorkspaceResolver = loadWorkspaceResolver();
- convertFrom20();
-
- initRegistryChangeListener();
- initPreferenceChangeListener();
- } catch (Exception e) {
- CCorePlugin.log(e);
- }
- }
-
- /**
- * @return the default instance of this singleton
- */
- synchronized public static ResolverModel getDefault() {
- if (null == fInstance) {
- fInstance = new ResolverModel();
- }
- return fInstance;
- }
-
- public ICLanguage[] getLanguages() {
- Collection values = fLangMap.values();
- return (ICLanguage[]) values.toArray(new ICLanguage[values.size()]);
- }
-
- public ICFileType[] getFileTypes() {
- Collection values = fTypeMap.values();
- return (ICFileType[]) values.toArray(new ICFileType[values.size()]);
- }
-
- public ICLanguage getLanguageById(String languageId) {
- ICLanguage lang = (ICLanguage) fLangMap.get(languageId);
- return ((null != lang) ? lang : DEFAULT_LANG_TYPE);
- }
-
- public ICFileType getFileTypeById(String typeId) {
- ICFileType type = (ICFileType) fTypeMap.get(typeId);
- return ((null != type) ? type : DEFAULT_FILE_TYPE);
- }
-
- /**
- * Add an instance of a language to the languages known to the
- * resolver.
- *
- * Returns true if the instance is added; returns false if the
- * instance is not added, or if it is already present in the list.
- *
- * @param lang language instance to add
- *
- * @return true if the language is added, false otherwise
- */
- public boolean addLanguages(ICLanguage[] langs) {
- ResolverChangeEvent event = new ResolverChangeEvent(this, getResolver());
- boolean result = addLanguages(langs, event);
- if (true == result) {
- fireEvent(event);
- }
- return result;
- }
-
- /**
- * Add an instance of a file type to the file types known to the
- * resolver.
- *
- * Returns true if the instance is added; returns false if the
- * instance is not added, or if it is already present in the list.
- *
- * @param type file type to add
- *
- * @return true if the file type is added, false otherwise
- */
- public boolean addFileTypes(ICFileType[] types) {
- ResolverChangeEvent event = new ResolverChangeEvent(this, getResolver());
- boolean result = addFileTypes(types, event);
- if (true == result) {
- fireEvent(event);
- }
- return result;
- }
-
- /**
- * Remove a language from the list of languages known to the resolver.
- *
- * @param lang language to remove
- *
- * @return true if the language is removed, false otherwise
- */
- public boolean removeLanguages(ICLanguage[] langs) {
- ResolverChangeEvent event = new ResolverChangeEvent(this, getResolver());
- boolean result = removeLanguages(langs, event);
- if (true == result) {
- fireEvent(event);
- }
- return result;
- }
-
- /**
- * Remove a file type from the list of type known to the resolver.
- *
- * @param type file type to remove
- *
- * @return true if the file type is removed, false otherwise
- */
- public boolean removeFileTypes(ICFileType[] types) {
- ResolverChangeEvent event = new ResolverChangeEvent(this, getResolver());
- boolean result = removeFileTypes(types, event);
- if (true == result) {
- fireEvent(event);
- }
- return result;
- }
-
- public ICFileTypeResolver getResolver() {
- return fWorkspaceResolver;
- }
-
- public boolean hasCustomResolver(IProject project) {
- return CustomResolver.hasCustomResolver(project);
- }
-
- public ICFileTypeResolver createCustomResolver(IProject project, ICFileTypeResolver copy) {
- ICFileTypeAssociation[] oldAssocs = null;
- ICFileTypeAssociation[] newAssocs = null;
-
- // get the old resolver first
- ICFileTypeResolver oldResolver = getResolver(project);
- oldAssocs = oldResolver.getFileTypeAssociations();
-
- // erase the old stuff.
- if (hasCustomResolver(project)) {
- CustomResolver.removeCustomResover(project);
- }
-
- ICFileTypeResolver newResolver = new CustomResolver(this, project);
-
- if (copy != null) {
- newAssocs = copy.getFileTypeAssociations();
- newResolver.addAssociations(newAssocs);
- }
-
- // cache the result in project session property.
- try {
- project.setSessionProperty(QN_CUSTOM_RESOLVER, newResolver);
- } catch (CoreException e) {
- }
-
- ResolverChangeEvent event = new ResolverChangeEvent(this, newResolver, oldResolver);
-
- fireResolverChangeEvent(event, newAssocs, oldAssocs);
- return newResolver;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.filetype.IResolverModel#removeCustomResolver(org.eclipse.core.resources.IProject)
- */
- public void removeCustomResolver(IProject project) {
- if (hasCustomResolver(project)) {
- ICFileTypeAssociation[] oldAssocs = null;
- ICFileTypeAssociation[] newAssocs = null;
-
- ICFileTypeResolver oldResolver = getResolver(project);
- oldAssocs = oldResolver.getFileTypeAssociations();
-
- ICFileTypeResolver newResolver = getResolver();
- newAssocs = newResolver.getFileTypeAssociations();
-
- // remove the cache in project session property.
- try {
- project.setSessionProperty(QN_CUSTOM_RESOLVER, null);
- } catch (CoreException e) {
- }
-
- CustomResolver.removeCustomResover(project);
-
- ResolverChangeEvent event = new ResolverChangeEvent(this, newResolver, oldResolver);
- fireResolverChangeEvent(event, newAssocs, oldAssocs);
- }
- }
-
-
- public ICFileTypeResolver getResolver(IProject project) {
- ICFileTypeResolver resolver = null;
-
- if (null != project) {
- try {
- Object obj = project.getSessionProperty(QN_CUSTOM_RESOLVER);
- if (obj instanceof ICFileTypeResolver) {
- resolver = (ICFileTypeResolver) obj;
- }
- } catch (CoreException e) {
- }
- if (null == resolver) {
- if (hasCustomResolver(project)) {
- resolver = new CustomResolver(this, project);
- // cache the result in the session property.
- try {
- project.setSessionProperty(QN_CUSTOM_RESOLVER, resolver);
- } catch (CoreException e) {
- }
- }
- }
- }
-
- if (null == resolver) {
- resolver = getResolver();
- }
-
- return resolver;
- }
-
- public ICFileTypeAssociation createAssocation(String pattern, ICFileType type) {
- return new CFileTypeAssociation(pattern, type);
- }
-
- public void addResolverChangeListener(IResolverChangeListener listener) {
- fListeners.add(listener);
- }
-
- public void removeResolverChangeListener(IResolverChangeListener listener) {
- fListeners.remove(listener);
- }
-
- //----------------------------------------------------------------------
- // Misc. internal
- //----------------------------------------------------------------------
-
- private IExtensionPoint getExtensionPoint(String extensionPointId) {
- return Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, extensionPointId);
- }
-
- private static boolean isDebugging() {
- return VERBOSE;
- }
-
- private static void debugLog(String message) {
- System.out.println("CDT Resolver: " + message); //$NON-NLS-1$
- }
-
- public void fireEvent(final ResolverChangeEvent event) {
-
- if (event == null) {
- return;
- }
-
- if (isDebugging()) {
- debugLog(event.toString());
- }
-
- if (fListeners.isEmpty()) {
- return;
- }
-
- // Convert the change for the IContentTypeManager
- convertToContentType(event);
-
- final IResolverChangeListener[] listeners;
- listeners = (IResolverChangeListener[]) fListeners.toArray(new IResolverChangeListener[fListeners.size()]);
-
- for (int i = 0; i < listeners.length; i++) {
- final int index = i;
- Platform.run(new ISafeRunnable() {
- public void handleException(Throwable exception) {
- IStatus status = new Status(IStatus.ERROR, CCorePlugin.PLUGIN_ID, -1,
- CCorePlugin.getResourceString("ResolverModel.exception.listenerError"), exception); //$NON-NLS-1$
- CCorePlugin.log(status);
- }
- public void run() throws Exception {
- listeners[index].resolverChanged(event);
- }
- });
- }
- }
-
- private void fireResolverChangeEvent(ResolverChangeEvent event, ICFileTypeAssociation[] newAssocs,
- ICFileTypeAssociation[] oldAssocs) {
-
- if ((null != oldAssocs) && (null != newAssocs)) {
-
- for (int i = 0; i < oldAssocs.length; i++) {
- if (Arrays.binarySearch(newAssocs, oldAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
- event.addDelta(new ResolverDelta(oldAssocs[i], ResolverDelta.EVENT_REMOVE));
- }
- }
-
- for (int i = 0; i < newAssocs.length; i++) {
- if (Arrays.binarySearch(oldAssocs, newAssocs[i], ICFileTypeAssociation.Comparator) < 0) {
- event.addDelta(new ResolverDelta(newAssocs[i], ResolverDelta.EVENT_ADD));
- }
- }
- }
- fireEvent(event);
- }
-
- private void initRegistryChangeListener() {
- Platform.getExtensionRegistry().addRegistryChangeListener(new IRegistryChangeListener() {
- public void registryChanged(IRegistryChangeEvent event) {
- handleRegistryChanged(event);
- }
- }, CCorePlugin.PLUGIN_ID);
- }
-
- private void initPreferenceChangeListener() {
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
- prefs.addPropertyChangeListener(new Preferences.IPropertyChangeListener() {
- /* (non-Javadoc)
- * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent)
- */
- public void propertyChange(PropertyChangeEvent event) {
- handlePropertyChanged(event);
- }
- });
- }
-
- protected void handlePropertyChanged(Preferences.PropertyChangeEvent event) {
- String property = event.getProperty();
- if (property != null) {
- if (WorkspaceResolver.PREFS_ASSOCIATIONS_EXCLUSION.equals(property) ||
- WorkspaceResolver.PREFS_ASSOCIATIONS_INCLUSION.equals(property)) {
- fWorkspaceResolver = loadWorkspaceResolver();
- }
- }
- }
-
- protected void handleRegistryChanged(IRegistryChangeEvent event) {
- IExtensionDelta[] deltas = null;
- ResolverChangeEvent modelEvent = new ResolverChangeEvent(this, getResolver());
-
- deltas = event.getExtensionDeltas(CCorePlugin.PLUGIN_ID, EXTENSION_LANG);
- for (int i = 0; i < deltas.length; i++) {
- processLanguageExtension(modelEvent, deltas[i].getExtension(), IExtensionDelta.ADDED == deltas[i].getKind());
- }
-
- deltas = event.getExtensionDeltas(CCorePlugin.PLUGIN_ID, EXTENSION_TYPE);
- for (int i = 0; i < deltas.length; i++) {
- processTypeExtension(modelEvent, deltas[i].getExtension(), IExtensionDelta.ADDED == deltas[i].getKind());
- }
-
- deltas = event.getExtensionDeltas(CCorePlugin.PLUGIN_ID, EXTENSION_ASSOC);
- if (deltas.length != 0) {
- fWorkspaceResolver = loadWorkspaceResolver();
- }
-
- fireEvent(modelEvent);
- }
-
- private boolean addLanguages(ICLanguage[] langs, ResolverChangeEvent event) {
- boolean added = false;
- for (int i = 0; i < langs.length; ++i) {
- ICLanguage lang = langs[i];
- if (!fLangMap.containsValue(lang)) {
- fLangMap.put(lang.getId(), lang);
- if (null != event) {
- event.addDelta(new ResolverDelta(lang, ResolverDelta.EVENT_ADD));
- }
- added = true;
- }
- }
- return added;
- }
-
- private boolean addFileTypes(ICFileType[] types, ResolverChangeEvent event) {
- boolean added = false;
- for (int i = 0; i < types.length; ++i) {
- ICFileType type = types[i];
- if (!fTypeMap.containsValue(type)) {
- fTypeMap.put(type.getId(), type);
- event.addDelta(new ResolverDelta(type, ResolverDelta.EVENT_ADD));
- added = true;
- }
- }
- return added;
- }
-
- private boolean removeLanguages(ICLanguage[] langs, ResolverChangeEvent event) {
- boolean del = false;
- ArrayList removeTypeList = new ArrayList(langs.length);
- for (int i = 0; i < langs.length; ++i) {
- ICLanguage lang = langs[i];
- boolean removed = (null != fLangMap.remove(lang.getId()));
-
- if (removed) {
- event.addDelta(new ResolverDelta(lang, ResolverDelta.EVENT_REMOVE));
- del = true;
- for (Iterator iter = fTypeMap.values().iterator(); iter.hasNext();) {
- ICFileType type = (ICFileType) iter.next();
- if (lang.equals(type.getLanguage())) {
- removeTypeList.add(type);
- }
- }
- }
- }
- if (!removeTypeList.isEmpty()) {
- ICFileType[] types = (ICFileType[]) removeTypeList.toArray(new ICFileType[removeTypeList.size()]);
- removeFileTypes(types, event);
- }
- return del;
- }
-
- private boolean removeFileTypes(ICFileType[] types, ResolverChangeEvent event) {
- boolean changed = false;
- for (int i = 0; i < types.length; ++i) {
- ICFileType type = types[i];
- boolean removed = (null != fTypeMap.remove(type.getId()));
- if (removed) {
- changed = true;
- if (null != event) {
- event.addDelta(new ResolverDelta(type, ResolverDelta.EVENT_REMOVE));
- }
- // TODO: must remove any associations based on this file type as well
- // Unforuntately, at this point, that means iterating over the contents
- // of the default, workspace, and project resolvers. Ugh.
- }
- }
- return changed;
- }
-
-
- //----------------------------------------------------------------------
- // Extension point handling
- //----------------------------------------------------------------------
-
- /**
- * Load languages declared through the CLanguage extension point.
- */
- private void loadDeclaredLanguages() {
- IExtensionPoint point = getExtensionPoint(EXTENSION_LANG);
- IExtension[] extensions = point.getExtensions();
- ResolverChangeEvent event = new ResolverChangeEvent(this, getResolver());
-
- for (int i = 0; i < extensions.length; i++) {
- processLanguageExtension(event, extensions[i], true);
- }
-
- // Shouldn't have anything listening here, but generating
- // the events helps maintain internal consistency w/logging
-
- fireEvent(event);
- }
-
- /**
- * Load file type declared through the CFileType extension point.
- */
- private void loadDeclaredTypes() {
- IExtensionPoint point = getExtensionPoint(EXTENSION_TYPE);
- IExtension[] extensions = point.getExtensions();
- ResolverChangeEvent event = new ResolverChangeEvent(this, getResolver());
-
- for (int i = 0; i < extensions.length; i++) {
- processTypeExtension(event, extensions[i], true);
- }
-
- // Shouldn't have anything listening here, but generating
- // the events helps maintain internal consistency w/logging
-
- fireEvent(event);
- }
-
- private void processLanguageExtension(ResolverChangeEvent event, IExtension extension, boolean add) {
- IConfigurationElement[] elements = extension.getConfigurationElements();
- List list = new ArrayList(elements.length);
- for (int i = 0; i < elements.length; i++) {
- String id = elements[i].getAttribute(ATTR_ID);
- String name = elements[i].getAttribute(ATTR_NAME);
- try {
- ICLanguage element = new CLanguage(id, name);
- list.add (element);
- } catch (IllegalArgumentException e) {
- CCorePlugin.log(e);
- }
- }
- ICLanguage[] langs = (ICLanguage[]) list.toArray(new ICLanguage[list.size()]);
- if (add) {
- addLanguages(langs, event);
- } else {
- removeLanguages(langs, event);
- }
- }
-
- private void processTypeExtension(ResolverChangeEvent event, IExtension extension, boolean add) {
- IConfigurationElement[] elements = extension.getConfigurationElements();
- List list = new ArrayList(elements.length);
- for (int i = 0; i < elements.length; i++) {
- String id = elements[i].getAttribute(ATTR_ID);
- String lang = elements[i].getAttribute(ATTR_LANGUAGE);
- String name = elements[i].getAttribute(ATTR_NAME);
- String type = elements[i].getAttribute(ATTR_TYPE);
-
- try {
- ICFileType element = new CFileType(id, getLanguageById(lang), name, parseType(type));
- list.add(element);
- } catch (IllegalArgumentException e) {
- CCorePlugin.log(e);
- }
- }
- ICFileType[] types = (ICFileType[]) list.toArray(new ICFileType[list.size()]);
- if (add) {
- addFileTypes(types, event);
- } else {
- removeFileTypes(types, event);
- }
- }
-
- /**
- * Turn a type string into an ICFileType.TYPE_* value.
- *
- * @param typeString type string ("source" or "header")
- *
- * @return corresponding ICFileType.TYPE_* value, or ICFileType.UNKNOWN
- */
- private int parseType(String typeString) {
- int type = ICFileType.TYPE_UNKNOWN;
-
- if (typeString.equals(ATTR_VAL_SOURCE)) {
- type = ICFileType.TYPE_SOURCE;
- } else if (typeString.equals(ATTR_VAL_HEADER)) {
- type = ICFileType.TYPE_HEADER;
- }
-
- return type;
- }
-
-
- //----------------------------------------------------------------------
- // Default resolver
- //----------------------------------------------------------------------
-
- /**
- * Initialize the default resolver by loading data from
- * declared extension points.
- */
- private ICFileTypeResolver loadWorkspaceResolver() {
- ICFileTypeResolver resolver = new WorkspaceResolver(this);
- convertToContentTypes(resolver);
- return resolver;
- }
-
- final static String CSOURCE = "org.eclipse.cdt.core.cSource"; //$NON-NLS-1$
- final static String CHEADER = "org.eclipse.cdt.core.cHeader"; //$NON-NLS-1$
- final static String CXXSOURCE = "org.eclipse.cdt.core.cxxSource"; //$NON-NLS-1$
- final static String CXXHEADER = "org.eclipse.cdt.core.cxxHeader"; //$NON-NLS-1$
- final static String ASMSOURCE = "org.eclipse.cdt.core.asmSource"; //$NON-NLS-1$
- static String FILE_EXT_PATTERN = "*."; //$NON-NLS-1$
- static int FILE_EXT_PATTERN_LENGTH = FILE_EXT_PATTERN.length();
-
- private void convertToContentTypes(ICFileTypeResolver resolver) {
- ICFileTypeAssociation[] associations = resolver.getFileTypeAssociations();
- IContentTypeManager manager = Platform.getContentTypeManager();
- try {
- for (int i = 0; i < associations.length; ++i) {
- String contentTypeId = getContentTypeIdentifier(associations[i]);
- if (contentTypeId != null) {
- IContentType contentType = manager.getContentType(contentTypeId);
- if (contentType != null) {
- String pattern = associations[i].getPattern();
- int spec = IContentType.FILE_NAME_SPEC;
- if (isFileSpecExtension(pattern)) {
- pattern = getFileSpecExtension(pattern);
- spec = IContentType.FILE_EXTENSION_SPEC;
- }
- contentType.addFileSpec(pattern, spec);
- }
- }
- }
- } catch (CoreException e) {
- //
- }
- }
-
- private void convertToContentType(ResolverChangeEvent event) {
- ResolverDelta[] deltas = event.getDeltas();
- IContentTypeManager manager = Platform.getContentTypeManager();
- for (int i = 0; i < deltas.length; ++i) {
- ResolverDelta delta = deltas[i];
- if (delta.getElementType() == ResolverDelta.ELEMENT_ASSOCIATION) {
- ICFileTypeAssociation association = delta.getAssociation();
- String contentTypeId = getContentTypeIdentifier(association);
- if (contentTypeId != null) {
- try {
- IContentType contentType = manager.getContentType(contentTypeId);
- String pattern = association.getPattern();
- int spec = IContentType.FILE_NAME_SPEC;
- if (isFileSpecExtension(pattern)) {
- pattern = getFileSpecExtension(pattern);
- spec = IContentType.FILE_EXTENSION_SPEC;
- }
- if (delta.getEventType() == ResolverDelta.EVENT_ADD) {
- contentType.addFileSpec(pattern, spec);
- } else if (delta.getEventType() == ResolverDelta.EVENT_REMOVE) {
- contentType.removeFileSpec(pattern, spec);
- }
- } catch (CoreException e) {
- //
- }
- }
- }
- }
- }
-
- String getContentTypeIdentifier(ICFileTypeAssociation association) {
- ICFileType fileType = association.getType();
- ICLanguage lang = fileType.getLanguage();
- String langId = lang.getId();
- if (fileType.isSource()) {
- if (langId.equals(ICFileTypeConstants.LANG_C)) {
- return CSOURCE;
- } else if (langId.equals(ICFileTypeConstants.LANG_CXX)) {
- return CXXSOURCE;
- } else if (langId.equals(ICFileTypeConstants.LANG_ASM)) {
- return ASMSOURCE;
- }
- } else if (fileType.isHeader()) {
- if (langId.equals(ICFileTypeConstants.LANG_C)) {
- return CHEADER;
- } else if (langId.equals(ICFileTypeConstants.LANG_CXX)) {
- return CXXHEADER;
- } else if (langId.equals(ICFileTypeConstants.LANG_ASM)) {
- return ASMSOURCE;
- }
- }
- return null;
- }
-
- boolean isFileSpecExtension(String pattern) {
- return (pattern.startsWith(FILE_EXT_PATTERN));
- }
- String getFileSpecExtension(String pattern) {
- int i = pattern.indexOf(FILE_EXT_PATTERN);
- if (i != -1) {
- return pattern.substring(i + FILE_EXT_PATTERN_LENGTH);
- }
- return pattern;
- }
-
- //----------------------------------------------------------------------
- // Workspace resolver
- //----------------------------------------------------------------------
-
- private static final String WKSP_STATE_FILE = "resolver.properties"; //$NON-NLS-1$
-
- private void convertFrom20() {
- if (customWorkspaceResolverExists()) {
- ICFileTypeAssociation[] assocs = loadOldWorkspaceResolver();
- if (assocs != null && assocs.length > 0) {
- getResolver().addAssociations(assocs);
- }
- try {
- getWorkspaceResolverStateFilePath().toFile().delete();
- } catch (Exception e) {
- //
- }
- }
- }
-
- private boolean customWorkspaceResolverExists() {
- return getWorkspaceResolverStateFilePath().toFile().exists();
- }
-
- private IPath getWorkspaceResolverStateFilePath() {
- return CCorePlugin.getDefault().getStateLocation().append(WKSP_STATE_FILE);
- }
-
- private ICFileTypeAssociation[] loadOldWorkspaceResolver() {
- List assocs = new ArrayList();
- File file = getWorkspaceResolverStateFilePath().toFile();
-
- if (file.exists()) {
- Properties props = new Properties();
- FileInputStream in = null;
-
- try {
- in = new FileInputStream(file);
-
- props.load(in);
-
- for (Iterator iter = props.entrySet().iterator(); iter.hasNext();) {
- Map.Entry element = (Map.Entry) iter.next();
- ICFileType type = getFileTypeById(element.getValue().toString());
- try {
- assocs.add(createAssocation(element.getKey().toString(), type));
- } catch (IllegalArgumentException e) {
- CCorePlugin.log(e);
- }
- }
-
- } catch (IOException e) {
- CCorePlugin.log(e);
- } finally {
- if (in != null) {
- try {
- in.close();
- } catch (IOException e) {
- //
- }
- }
- }
- }
-
- return ((ICFileTypeAssociation[]) assocs.toArray(new ICFileTypeAssociation[assocs.size()]));
- }
-
-}
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/WorkspaceResolver.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/WorkspaceResolver.java
deleted file mode 100644
index 4ef06e8aec..0000000000
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/WorkspaceResolver.java
+++ /dev/null
@@ -1,357 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 QNX Software Systems and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Common Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/cpl-v10.html
- *
- * Contributors:
- * QNX Software Systems - Initial API and implementation
- *******************************************************************************/
-
-package org.eclipse.cdt.core.internal.filetype;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeAssociation;
-import org.eclipse.cdt.core.filetype.ResolverChangeEvent;
-import org.eclipse.cdt.core.filetype.ResolverDelta;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IConfigurationElement;
-import org.eclipse.core.runtime.IExtension;
-import org.eclipse.core.runtime.IExtensionPoint;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.Preferences;
-
-/**
- * The new CFileTypeAssociations are save in a property String
- * The removed CFileTypeAssociations are save in a property String
- *
- */
-public class WorkspaceResolver extends CFileTypeResolver {
-
- public static final String PREFS_ASSOCIATIONS_INCLUSION = CCorePlugin.PLUGIN_ID + ".associationInclusion"; //$NON-NLS-1$
- public static final String PREFS_ASSOCIATIONS_EXCLUSION = CCorePlugin.PLUGIN_ID + ".associationExclusion"; //$NON-NLS-1$
-
- ResolverModel fModel;
- List extensionsList;
-
- private static final String EXTENSION_ASSOC = "CFileTypeAssociation"; //$NON-NLS-1$
- private static final String ATTR_TYPE = "type"; //$NON-NLS-1$
- private static final String ATTR_PATTERN = "pattern"; //$NON-NLS-1$
- private static final String ATTR_FILE = "file"; //$NON-NLS-1$
-
- public WorkspaceResolver() {
- this(ResolverModel.getDefault());
- }
-
- public WorkspaceResolver(ResolverModel model) {
- super(ResourcesPlugin.getWorkspace().getRoot());
- fModel = model;
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.internal.filetype.CFileTypeResolver#doAdjustAssociations(org.eclipse.cdt.core.filetype.ICFileTypeAssociation[], org.eclipse.cdt.core.filetype.ICFileTypeAssociation[], boolean, org.eclipse.core.runtime.IProgressMonitor)
- */
- protected void doAdjustAssociations(ICFileTypeAssociation[] addAssocs,
- ICFileTypeAssociation[] delAssocs, boolean triggerEvent) {
-
- List deltas = new ArrayList();
-
- // add
- if (triggerEvent && null != addAssocs && addAssocs.length > 0) {
- for (int i = 0; i < addAssocs.length; i++) {
- deltas.add(new ResolverDelta(addAssocs[i], ResolverDelta.EVENT_ADD));
- }
- }
-
- // remove
- if (triggerEvent && null != delAssocs && delAssocs.length > 0) {
- for (int i = 0; i < delAssocs.length; i++) {
- deltas.add(new ResolverDelta(delAssocs[i], ResolverDelta.EVENT_REMOVE));
- }
- }
-
- // add
- // For adding we have to
- // - check if the association was define in an extension
- // if yes make sure we remove in the inclusion list
- // if not add as a new association in the inclusion list
- if (null != addAssocs && addAssocs.length > 0) {
- List newIncList = new ArrayList();
- List newExcList = new ArrayList();
- List extensionsList = getExtensionsAssociations();
- for (int i = 0; i < addAssocs.length; ++i) {
- if (!extensionsList.contains(addAssocs[i])) {
- newIncList.add(addAssocs[i]);
- } else {
- newExcList.add(addAssocs[i]);
- }
- }
- if (!newIncList.isEmpty()) {
- List inclusion = getInclusionAssociations();
- inclusion.addAll(newIncList);
- ICFileTypeAssociation[] newInclusion = ((ICFileTypeAssociation[]) inclusion.toArray(new ICFileTypeAssociation[inclusion.size()]));
- setInclusionAssociations(newInclusion);
- }
- if (!newExcList.isEmpty()) {
- List exclusion = getExclusionAssociations();
- exclusion.removeAll(newExcList);
- ICFileTypeAssociation[] newInclusion = ((ICFileTypeAssociation[]) exclusion.toArray(new ICFileTypeAssociation[exclusion.size()]));
- setInclusionAssociations(newInclusion);
- }
- }
-
- // remove
- // For removing we have to
- // - check if the association was define in an extension
- // if yes make sure we remove in the exclusion list
- // if not remove in the inclusion list
- if (null != delAssocs && delAssocs.length > 0) {
- List newIncList = new ArrayList();
- List newExcList = new ArrayList();
- List extensionsList = getExtensionsAssociations();
- for (int i = 0; i < delAssocs.length; ++i) {
- if (extensionsList.contains(delAssocs[i])) {
- newExcList.add(delAssocs[i]);
- } else {
- newIncList.add(delAssocs[i]);
- }
- }
- if (!newExcList.isEmpty()) {
- List exclusion = getExclusionAssociations();
- exclusion.addAll(newExcList);
- ICFileTypeAssociation[] newExclusion = ((ICFileTypeAssociation[]) exclusion.toArray(new ICFileTypeAssociation[exclusion.size()]));
- setExclusionAssociations(newExclusion);
- }
- if (!newIncList.isEmpty()) {
- List inclusion = getInclusionAssociations();
- inclusion.removeAll(newIncList);
- ICFileTypeAssociation[] newInclusion = ((ICFileTypeAssociation[]) inclusion.toArray(new ICFileTypeAssociation[inclusion.size()]));
- setInclusionAssociations(newInclusion);
- }
- }
-
- if ((null != addAssocs && addAssocs.length > 0) || (null != delAssocs && delAssocs.length > 0)) {
- CCorePlugin.getDefault().savePluginPreferences();
- }
-
- // fire the deltas.
- if (triggerEvent && !deltas.isEmpty()) {
- ResolverChangeEvent event = new ResolverChangeEvent(fModel, this);
- for (int i = 0; i < deltas.size(); ++i) {
- ResolverDelta delta = (ResolverDelta)deltas.get(i);
- event.addDelta(delta);
- }
- fModel.fireEvent(event);
- }
-
- }
-
- public List getExtensionsAssociations() {
- if (extensionsList == null) {
- extensionsList = new ArrayList();
- IExtensionPoint point = getExtensionPoint(EXTENSION_ASSOC);
- IExtension[] extensions = point.getExtensions();
- IConfigurationElement[] elements = null;
-
- for (int i = 0; i < extensions.length; i++) {
- elements = extensions[i].getConfigurationElements();
- for (int j = 0; j < elements.length; j++) {
- ICFileType typeRef = fModel.getFileTypeById(elements[j].getAttribute(ATTR_TYPE));
- if (null != typeRef) {
- extensionsList.addAll(getAssocFromExtension(typeRef, elements[j]));
- extensionsList.addAll(getAssocFromFile(typeRef, elements[j]));
- }
- }
- }
- }
- return extensionsList;
- }
-
- public List getDefaultInclusionAssociations() {
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
- String s = prefs.getDefaultString(PREFS_ASSOCIATIONS_INCLUSION);
- String[] items = s.split(";"); //$NON-NLS-1$
- List assoc = getAssocFromPreferences(items);
- return assoc;
- }
-
- public List getInclusionAssociations() {
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
- String s = prefs.getString(PREFS_ASSOCIATIONS_INCLUSION);
- String[] items = s.split(";"); //$NON-NLS-1$
- List assoc = getAssocFromPreferences(items);
- return assoc;
- }
-
- private void setInclusionAssociations(ICFileTypeAssociation[] addAssocs) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < addAssocs.length; ++i) {
- if (sb.length() > 0) {
- sb.append(';');
- }
- sb.append(addAssocs[i].getPattern());
- sb.append("!!"); //$NON-NLS-1$
- sb.append(addAssocs[i].getType().getId());
- }
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
- String s = prefs.getString(PREFS_ASSOCIATIONS_INCLUSION);
-
- if (s.length() > 0) {
- sb.append(';').append(s);
- }
- prefs.setValue(PREFS_ASSOCIATIONS_INCLUSION, sb.toString());
- }
-
- public List getDefaultExclusionAssociations() {
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
- String s = prefs.getDefaultString(PREFS_ASSOCIATIONS_EXCLUSION);
- String[] items = s.split(";"); //$NON-NLS-1$
- List assocs = getAssocFromPreferences(items);
- return assocs;
- }
-
- public List getExclusionAssociations() {
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
- String s = prefs.getString(PREFS_ASSOCIATIONS_EXCLUSION);
- String[] items = s.split(";"); //$NON-NLS-1$
- List assocs = getAssocFromPreferences(items);
- return assocs;
- }
-
- private void setExclusionAssociations(ICFileTypeAssociation[] addAssocs) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < addAssocs.length; ++i) {
- if (sb.length() > 0) {
- sb.append(';');
- }
- sb.append(addAssocs[i].getPattern());
- sb.append("!!"); //$NON-NLS-1$
- sb.append(addAssocs[i].getType().getId());
- }
- Preferences prefs = CCorePlugin.getDefault().getPluginPreferences();
- String s = prefs.getString(PREFS_ASSOCIATIONS_EXCLUSION);
- if (s.length() > 0) {
- sb.append(';').append(s);
- }
- prefs.setValue(PREFS_ASSOCIATIONS_EXCLUSION, sb.toString());
- }
-
- /* (non-Javadoc)
- * @see org.eclipse.cdt.core.internal.filetype.CFileTypeResolver#loadAssociations()
- */
- protected ICFileTypeAssociation[] loadAssociations() {
- List assocs = new ArrayList();
- List exclusion = getExclusionAssociations();
- List inclusion = getInclusionAssociations();
- for (int i = 0; i < inclusion.size(); ++i) {
- Object inc = inclusion.get(i);
- if (!exclusion.contains(inc)) {
- assocs.add(inc);
- }
- }
- List extensions = getExtensionsAssociations();
- for (int i = 0; i < extensions.size(); ++i) {
- Object ext = extensions.get(i);
- if (!exclusion.contains(ext)) {
- assocs.add(ext);
- }
- }
- return ((ICFileTypeAssociation[]) assocs.toArray(new ICFileTypeAssociation[assocs.size()]));
- }
-
- /**
- * Associate one or more file extensions with an ICFileType instance.
- *
- * @param typeRef reference to the ICFileType instance
- *
- * @param element configuration element to get file extensions from
- */
- private List getAssocFromExtension(ICFileType typeRef, IConfigurationElement element) {
- List assocs = new ArrayList();
- String attr = element.getAttribute(ATTR_PATTERN);
- if (null != attr) {
- String[] item = attr.split(","); //$NON-NLS-1$
- for (int i = 0; i < item.length; i++) {
- try {
- assocs.add(fModel.createAssocation(item[i].trim(), typeRef));
- } catch (IllegalArgumentException e) {
- CCorePlugin.log(e);
- }
- }
- }
- return assocs;
- }
-
- private List getAssocFromPreferences(String[] items) {
- List assocs = new ArrayList();
- for (int i = 0; i < items.length; ++i) {
- String[] item = items[i].split("!!"); //$NON-NLS-1$
- if (item.length == 2) {
- String pattern = item[0].trim();
- ICFileType typeRef = fModel.getFileTypeById(item[1]);
- try {
- assocs.add(fModel.createAssocation(pattern, typeRef));
- } catch (IllegalArgumentException e) {
- CCorePlugin.log(e);
- }
- }
- }
- return assocs;
- }
-
- /**
- * Associate the contents of a file with an ICFileType instance.
- *
- * The file is read, one entry per line; each line is taken as
- * a pattern that should be associated with the specified ICFileType
- * instance.
- *
- * @param typeRef reference to the ICFileType instance
- *
- * @param element configuration element to get file extensions from
- */
- private List getAssocFromFile(ICFileType typeRef, IConfigurationElement element) {
- List assocs = new ArrayList();
- String attr = element.getAttribute(ATTR_FILE);
-
- if (null != attr) {
- URL baseURL = null;
- URL fileURL = null;
- BufferedReader in = null;
- String line = null;
-
- try {
- baseURL = Platform.getBundle(element.getDeclaringExtension().getNamespace()).getEntry("/"); //$NON-NLS-1$
- fileURL = new URL(baseURL, attr);
- in = new BufferedReader(new InputStreamReader(fileURL.openStream()));
- line = in.readLine();
- while (null != line) {
- try {
- assocs.add(fModel.createAssocation(line.trim(), typeRef));
- } catch (IllegalArgumentException e) {
- CCorePlugin.log(e);
- }
- line = in.readLine();
- }
- in.close();
- } catch (IOException e) {
- CCorePlugin.log(e);
- }
- }
- return assocs;
- }
-
- private IExtensionPoint getExtensionPoint(String extensionPointId) {
- return Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, extensionPointId);
- }
-
-}
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 3046a01ca2..3e61b43756 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
@@ -16,8 +16,6 @@ import org.eclipse.cdt.core.dom.ICodeReaderFactory;
import org.eclipse.cdt.core.dom.IParserConfiguration;
import org.eclipse.cdt.core.dom.ast.ASTCompletionNode;
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
-import org.eclipse.cdt.core.filetype.ICFileType;
-import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
import org.eclipse.cdt.core.parser.CodeReader;
import org.eclipse.cdt.core.parser.IScanner;
import org.eclipse.cdt.core.parser.IScannerInfo;
@@ -45,6 +43,7 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IStorage;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.content.IContentType;
/**
* @author jcamelon
@@ -241,16 +240,28 @@ public class InternalASTServiceProvider implements IASTServiceProvider {
}
private ParserLanguage getLanguage( IPath path, IProject project )
- {
- ICFileType type = CCorePlugin.getDefault().getFileType(project, path.lastSegment());
- boolean isHeader= type.isHeader();
- if( isHeader )
- return ParserLanguage.CPP; // assumption
- String lid = type.getLanguage().getId();
- if( lid.equals(ICFileTypeConstants.LANG_CXX))
- return ParserLanguage.CPP;
- if( lid.equals( ICFileTypeConstants.LANG_C ) )
- return ParserLanguage.C;
+ {
+ //FIXME: ALAIN, for headers should we assume CPP ??
+ // The problem is that it really depends on how the header was included.
+ String id = null;
+ IContentType contentType = CCorePlugin.getContentType(project, path.lastSegment());
+ if (contentType != null) {
+ id = contentType.getId();
+ }
+ if (id != null) {
+ if (CCorePlugin.CONTENT_TYPE_CXXHEADER.equals(id)) {
+ return ParserLanguage.CPP;
+ } 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 ?
+ } else if (CCorePlugin.CONTENT_TYPE_CSOURCE.equals(id)) {
+ return ParserLanguage.C;
+ } else if (CCorePlugin.CONTENT_TYPE_ASMSOURCE.equals(id)) {
+ // ???
+ // What do we do here ?
+ }
+ }
return ParserLanguage.CPP;
}
diff --git a/core/org.eclipse.cdt.core/template/cpp_headers b/core/org.eclipse.cdt.core/template/cpp_headers
deleted file mode 100644
index c526313584..0000000000
--- a/core/org.eclipse.cdt.core/template/cpp_headers
+++ /dev/null
@@ -1,53 +0,0 @@
-algorithm
-bitset
-cassert
-cctype
-cerrno
-cfloat
-ciso646
-climits
-clocale
-cmath
-complex
-csetjmp
-csignal
-cstdarg
-cstddef
-cstdio
-cstdlib
-cstring
-ctime
-cwchar
-cwctype
-deque
-exception
-fstream
-functional
-hash_map
-hash_set
-iomanip
-ios
-iosfwd
-iostream
-istream
-iterator
-limits
-list
-locale
-map
-memory
-new
-numeric
-ostream
-queue
-set
-sstream
-stack
-stdexcept
-streambuf
-string
-strstream
-typeinfo
-utility
-valarray
-vector

Back to the top