diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index 23a0229a981..3b0da5f839a 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 feb9070503c..9da405abbef 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 b398795ef83..f36ac13a7e3 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 158c51d615c..5f6956914e8 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 ef1e5f32295..529d528eccb 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 598e8941f9b..df1f33a43a9 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,14 +168,78 @@ 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) { + 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) { + 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) { + 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; @@ -181,27 +248,87 @@ public class CoreModel { /** * 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(); + 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 isValidHeaderUnitName(IProject project, String name) { - ICFileType type = CCorePlugin.getDefault().getFileType(project, name); - return type.isHeader(); + 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 isValidSourceUnitName(IProject project, String name) { - ICFileType type = CCorePlugin.getDefault().getFileType(project, name); - return type.isSource(); + 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: + *
+ * getContentType(null, filename)
+ *
+ * @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 afe4aa4fbe3..00000000000
--- 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 0d2551059e6..00000000000
--- 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 f36e99b8092..00000000000
--- 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 bac59689794..00000000000
--- 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 4ff131364f6..00000000000
--- 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 2a8b7ca0cf4..00000000000
--- 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 0b5fecf4f1b..00000000000
--- 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 caa2c560570..00000000000
--- 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 serialVersionUID
- */
- 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 cc8e62bf1cd..00000000000
--- 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 cc96c970684..00000000000
--- 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 9cb3149fe0c..00000000000
--- 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 16b8749ed67..00000000000
--- 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 ec18795bfc9..00000000000
--- 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 ddfde8b3ac6..00000000000
--- 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 2d89a0f9ebc..00000000000
--- 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 1bc773d2e52..00000000000
--- 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 4ef06e8aec8..00000000000
--- 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 3046a01ca27..3e61b43756a 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 c526313584c..00000000000
--- 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