Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlain Magloire2004-04-06 19:41:08 -0400
committerAlain Magloire2004-04-06 19:41:08 -0400
commitb937c683b48e131371504840782b630c1054de77 (patch)
tree14c7d27912a97208b38d4384466c778557518233
parent9ac35a9e9763c27d22b9a739212550b84c8d6be8 (diff)
downloadorg.eclipse.cdt-b937c683b48e131371504840782b630c1054de77.tar.gz
org.eclipse.cdt-b937c683b48e131371504840782b630c1054de77.tar.xz
org.eclipse.cdt-b937c683b48e131371504840782b630c1054de77.zip
First effort in providing the infrastructure
for recognizing TranslationUnit base on name.
-rw-r--r--core/org.eclipse.cdt.core/ChangeLog23
-rw-r--r--core/org.eclipse.cdt.core/plugin.xml56
-rw-r--r--core/org.eclipse.cdt.core/schema/CFileType.exsd134
-rw-r--r--core/org.eclipse.cdt.core/schema/CFileTypeAssociation.exsd142
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java33
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileType.java58
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeAssociation.java37
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeConstants.java31
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeResolver.java83
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileType.java53
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeAssociation.java43
-rw-r--r--core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeResolver.java327
-rw-r--r--core/org.eclipse.cdt.core/template/cpp_headers31
13 files changed, 1050 insertions, 1 deletions
diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog
index 3b5ed26521..053ad6f918 100644
--- a/core/org.eclipse.cdt.core/ChangeLog
+++ b/core/org.eclipse.cdt.core/ChangeLog
@@ -1,5 +1,28 @@
2004-04-06 Alain Magloire
+ Patch from Sam Robb covering part of PR #52864
+ This is the first effort in making a difference
+ between header and source files.
+
+ * template/cpp_headers
+ * src/org/eclipse/cdt/core/internal/filetype/CFileType.java
+ * src/org/eclipse/cdt/core/internal/filetype/CFileTypeAssociation.java
+ * src/org/eclipse/cdt/core/internal/filetype/CFileTypeResolver.java
+
+ * src/org/eclipse/cdt/core/filetype/ICFileType.java
+ * src/org/eclipse/cdt/core/filetype/ICFileTypeAssociation.java
+ * src/org/eclipse/cdt/core/filetype/ICFileTypeResolver.java
+ * src/org/eclipse/cdt/core/filetype/ICFileTypeConstants.java
+
+ * src/org/eclipse/cdt/core/CCorePlugin.java
+
+ * schema/CFileTyp.exsd
+ * schema/CFileTypeAssociation.exsd
+
+ * plugin.xml
+
+2004-04-06 Alain Magloire
+
Fix possible NPE.
* model/org/eclipse/cdt/internal/core/model/IncludeRefence.java
diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml
index 76653bc99e..9cbc28cc39 100644
--- a/core/org.eclipse.cdt.core/plugin.xml
+++ b/core/org.eclipse.cdt.core/plugin.xml
@@ -40,6 +40,11 @@
<!-- =================================================================================== -->
<extension-point id="BinaryParser" name="BinaryParser"/>
<extension-point id="ScannerInfoProvider" name="Scanner Information Provider"/>
+<!-- =================================================================================== -->
+<!-- Extension Point: CFileType and CFileTypeAssociation for translation unit ident -->
+<!-- =================================================================================== -->
+ <extension-point id="CFileType" name="CFileType" schema="schema/CFileType.exsd"/>
+ <extension-point id="CFileTypeAssociation" name="CFileTypeAssociation" schema="schema/CFileTypeAssociation.exsd"/>
<!-- =================================================================================== -->
<!-- Define the list of the Binary Parser provided by the CDT -->
@@ -168,6 +173,57 @@
</runtime>
</extension>
<!-- =================================================================================== -->
+<!-- CDT file type mappings -->
+<!-- =================================================================================== -->
+ <extension
+ point="org.eclipse.cdt.core.CFileType">
+ <fileType
+ name="C Source File"
+ type="source"
+ id="org.eclipse.cdt.core.fileType.c_source">
+ </fileType>
+ <fileType
+ name="C Header File"
+ type="header"
+ id="org.eclipse.cdt.core.fileType.c_header">
+ </fileType>
+ <fileType
+ name="C++ Source File"
+ type="source"
+ id="org.eclipse.cdt.core.fileType.cxx_source">
+ </fileType>
+ <fileType
+ name="C++ Header File"
+ type="header"
+ id="org.eclipse.cdt.core.fileType.cxx_header">
+ </fileType>
+ <fileType
+ name="Assembly Source File"
+ type="source"
+ id="org.eclipse.cdt.core.fileType.asm_source">
+ </fileType>
+ </extension>
+ <extension
+ point="org.eclipse.cdt.core.CFileTypeAssociation">
+ <association
+ pattern="*.c"
+ type="org.eclipse.cdt.core.fileType.c_source" />
+ <association
+ pattern="*.h"
+ type="org.eclipse.cdt.core.fileType.c_header" />
+ <association
+ pattern="*.cpp,*.cxx,*.cc,*.C"
+ type="org.eclipse.cdt.core.fileType.cxx_source" />
+ <association
+ pattern="*.hpp,*.hxx,*.hh,*.H"
+ file="template/cpp_headers"
+ type="org.eclipse.cdt.core.fileType.cxx_header" />
+ <association
+ pattern="*.asm,*.s,*.S"
+ type="org.eclipse.cdt.core.fileType.asm_source" />
+ </extension>
+
+<!-- =================================================================================== -->
<!-- Some well known C file extensions override for the team plugins -->
<!-- =================================================================================== -->
<extension
diff --git a/core/org.eclipse.cdt.core/schema/CFileType.exsd b/core/org.eclipse.cdt.core/schema/CFileType.exsd
new file mode 100644
index 0000000000..e36e31122a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/schema/CFileType.exsd
@@ -0,0 +1,134 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.cdt.core">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.cdt.core" id="CFileType" name="CFileType"/>
+ </appInfo>
+ <documentation>
+ Extension point representing the of a CDT file type. File types consist of a unique identifier (id), a human-readable name, and an enumerated value that indicates how this file should be treated by CDT.
+
+By themselves, file types don&apos;t serve much purpose. However, they are used to build file type assocations (see the CFileTypeAssocation extension point), which are used by CDT to classify files and determine how they should be processed.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="fileType" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="fileType">
+ <complexType>
+ <attribute name="type" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ <simpleType>
+ <restriction base="string">
+ <enumeration value="source">
+ </enumeration>
+ <enumeration value="header">
+ </enumeration>
+ </restriction>
+ </simpleType>
+ </attribute>
+ <attribute name="id" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ CDT 2.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ To declare a new type:
+
+ &lt;extension
+ point=&quot;org.eclipse.cdt.core.CFileType&quot;&gt;
+ &lt;fileType
+ name=&quot;My File Type&quot;
+ type=&quot;source&quot;
+ id=&quot;com.example.product.fileType.my_file_type&quot;&gt;
+ &lt;/fileType&gt;
+ &lt;/extension&gt;
+
+This indicates to CDT that there is a new file type, identified using the file type id &quot;com.example.product.fileType.my_file_type&quot;, and that files that have this file type should be handled as source files.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ This extension point is purely declarative.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/core/org.eclipse.cdt.core/schema/CFileTypeAssociation.exsd b/core/org.eclipse.cdt.core/schema/CFileTypeAssociation.exsd
new file mode 100644
index 0000000000..a253640d7b
--- /dev/null
+++ b/core/org.eclipse.cdt.core/schema/CFileTypeAssociation.exsd
@@ -0,0 +1,142 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.cdt.core">
+<annotation>
+ <appInfo>
+ <meta.schema plugin="org.eclipse.cdt.core" id="CFileType" name="CFileType"/>
+ </appInfo>
+ <documentation>
+ Extension point representing an association between a file type (see CFileType extension point) and a filename pattern. Patterns may be added to an association using the &quot;pattern&quot; and &quot;file&quot; attrributes of the filetype element; the associated file type is indicated by the &quot;type&quot; attribute.
+
+The &quot;pattern&quot; attribute consists of one or more filename patterns. Wildcards (&quot;*&quot; and &quot;?&quot;) may be used in the pattern. Multiple patterns may be present if they are seperated by commas.
+
+The &quot;file&quot; attribute consists of a plugin-relative path to a plain text file that contains one filename pattern per line.
+
+The &quot;pattern&quot; and &quot;file&quot; attributes may be combined in a single filetype element, if desired.
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <complexType>
+ <sequence>
+ <element ref="association" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="association">
+ <complexType>
+ <attribute name="pattern" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="file" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appInfo>
+ <meta.attribute kind="resource"/>
+ </appInfo>
+ </annotation>
+ </attribute>
+ <attribute name="type" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="since"/>
+ </appInfo>
+ <documentation>
+ CDT 2.0
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="examples"/>
+ </appInfo>
+ <documentation>
+ A file type association between a simple filename pattern and a file type.
+
+ &lt;association
+ pattern=&quot;*.c&quot;
+ type=&quot;org.eclipse.cdt.core.fileType.c_source&quot;&gt;
+ &lt;/association&gt;
+
+A file type association between multiple filename patterns and a file type.
+
+ &lt;association
+ pattern=&quot;*.cxx,*.cc,*.cpp,*.C&quot;
+ type=&quot;org.eclipse.cdt.core.fileType.cxx_source&quot;&gt;
+ &lt;/association&gt;
+
+A file type association that uses both &quot;pattern&quot; and &quot;file&quot; attributes to specify filename patterns.
+
+ &lt;association
+ pattern=&quot;*.hxx,*.hh,*.hpp,*.H&quot;
+ file=&quot;template/cpp_headers&quot;
+ type=&quot;org.eclipse.cdt.core.fileType.cxx_header&quot;&gt;
+ &lt;/association&gt;
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="apiInfo"/>
+ </appInfo>
+ <documentation>
+ This extension point is purely declarative.
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="implementation"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appInfo>
+ <meta.section type="copyright"/>
+ </appInfo>
+ <documentation>
+
+ </documentation>
+ </annotation>
+
+</schema>
diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
index 5eb2173cd1..5bec35425c 100644
--- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java
@@ -17,6 +17,9 @@ import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
+import org.eclipse.cdt.core.filetype.ICFileType;
+import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
+import org.eclipse.cdt.core.internal.filetype.CFileTypeResolver;
import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.IWorkingCopy;
import org.eclipse.cdt.core.parser.IScannerInfoProvider;
@@ -124,6 +127,8 @@ public class CCorePlugin extends Plugin {
private CDescriptorManager fDescriptorManager = new CDescriptorManager();
private CoreModel fCoreModel;
+
+ private ICFileTypeResolver fFileTypeResolver;
// -------- static methods --------
@@ -243,7 +248,9 @@ public class CCorePlugin extends Plugin {
// Set the default for using the structual parse mode to build the CModel
getPluginPreferences().setDefault(PREF_USE_STRUCTURAL_PARSE_MODE, false);
-
+
+ // Start file type manager
+ fFileTypeResolver = CFileTypeResolver.getDefault();
}
@@ -608,6 +615,30 @@ public class CCorePlugin extends Plugin {
return parser;
}
+ /**
+ * Returns the file type object corresponding to the provided
+ * file name.
+ *
+ * If no file type object exists, a default file type object is
+ * returned.
+ *
+ * The implementation checks for a match for the provided file name
+ * - By looking for an exact filename match ("iostream" == "iostream")
+ * - By looking for an extension match ("foo.c" == "*.c")
+ * - By looking for a pattern match ("libfoo.so.1.0" == "*.so*")
+ *
+ * @param fileName Name of the file to resolve type infor for.
+ *
+ * @return File type object for the provided file name.
+ */
+ public ICFileType getFileType(IProject project, String fileName) {
+ return fFileTypeResolver.getFileType(fileName);
+ }
+
+ public ICFileTypeResolver getFileTypeResolver() {
+ return fFileTypeResolver;
+ }
+
public CoreModel getCoreModel() {
return fCoreModel;
}
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
new file mode 100644
index 0000000000..9400fd4738
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileType.java
@@ -0,0 +1,58 @@
+/**********************************************************************
+ * 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 v0.5
+ * 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 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
new file mode 100644
index 0000000000..fd537d51b2
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeAssociation.java
@@ -0,0 +1,37 @@
+/**********************************************************************
+ * 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 v0.5
+ * 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.CFileTypeAssociation entry.
+ */
+public interface ICFileTypeAssociation {
+
+ /**
+ * @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
new file mode 100644
index 0000000000..ae380c45c8
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeConstants.java
@@ -0,0 +1,31 @@
+/**********************************************************************
+ * 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 v0.5
+ * 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.fileType."; //$NON-NLS-1$
+
+ public static String UNKNOWN = ID_PREFIX + "unknown"; //$NON-NLS-1$
+
+ public static String C_SOURCE = ID_PREFIX + "c_source"; //$NON-NLS-1$
+
+ public static String C_HEADER = ID_PREFIX + "c_header"; //$NON-NLS-1$
+
+ public static String CXX_HEADER = ID_PREFIX + "cxx_source"; //$NON-NLS-1$
+
+ public static String CXX_SOURCE = ID_PREFIX + "cxx_header"; //$NON-NLS-1$
+
+ public static String ASM_SOURCE = ID_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
new file mode 100644
index 0000000000..25689c411a
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICFileTypeResolver.java
@@ -0,0 +1,83 @@
+/**********************************************************************
+ * 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 v0.5
+ * 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;
+
+/**
+ * Class responsible for resolving a file name into the
+ * associated file type.
+ *
+ * Accessed by ICFileTypeResolver and file type management UI.
+ *
+ * The implementation checks for a match for the provided file name
+ * - By looking for an exact filename match ("iostream" == "iostream")
+ * - By looking for an extension match ("foo.c" == "*.c")
+ * - By looking for a pattern match ("libfoo.so.1.0" == "*.so*")
+ */
+public interface ICFileTypeResolver {
+ /**
+ * 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);
+
+ /**
+ * @return array containing all known file types.
+ */
+ public ICFileType[] getFileTypes();
+
+ /**
+ * @return array containing all known file types.
+ */
+ public ICFileTypeAssociation[] getFileTypeAssociations();
+
+ /**
+ * Add a new file type to the resolver's list.
+ *
+ * @param type file type to add.
+ *
+ * @return true if the file type object was added.
+ */
+ public boolean addFileType(ICFileType type);
+
+ /**
+ * Remove the file specified file type object from the
+ * resolver's list.
+ *
+ * @param type file type to remove.
+ *
+ * @return true if the file type was found and removed.
+ */
+ public boolean removeFileType(ICFileType type);
+
+ /**
+ * Add a new file type association to the resolver's list.
+ *
+ * @param pattern file name pattern to add.
+ * @param type file type associated with pattern.
+ *
+ * @return true if the file type association was added.
+ */
+ public boolean addFileTypeAssociation(ICFileTypeAssociation assoc);
+
+ /**
+ * Remove a file type association from the resolver's list.
+ *
+ * @param pattern file name pattern to remove.
+ *
+ * @return true if the file type association was removed.
+ */
+ public boolean removeFileTypeAssociation(ICFileTypeAssociation assoc);
+
+}
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
new file mode 100644
index 0000000000..3180d9267f
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileType.java
@@ -0,0 +1,53 @@
+/**********************************************************************
+ * 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 v0.5
+ * 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;
+
+/**
+ * Representation of a declared file type.
+ */
+public class CFileType implements ICFileType {
+
+ private String fId;
+ private String fName;
+ private int fType;
+
+ public CFileType(String id, String name, int type) {
+ fId = id;
+ fName = name;
+ fType = type;
+ }
+
+ public String getId() {
+ return fId;
+ }
+
+ 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());
+ }
+}
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
new file mode 100644
index 0000000000..a39fb46dd7
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeAssociation.java
@@ -0,0 +1,43 @@
+/**********************************************************************
+ * 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 v0.5
+ * 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) {
+ 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) {
+ return fMatcher.match(fileName);
+ }
+}
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
new file mode 100644
index 0000000000..6dfec37615
--- /dev/null
+++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileTypeResolver.java
@@ -0,0 +1,327 @@
+/**********************************************************************
+ * 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 v0.5
+ * 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.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+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.ICFileTypeAssociation;
+import org.eclipse.cdt.core.filetype.ICFileTypeConstants;
+import org.eclipse.cdt.core.filetype.ICFileTypeResolver;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+
+/**
+ * @author sam.robb
+ *
+ * To change the template for this generated type comment go to
+ * Window - Preferences - Java - Code Generation - Code and Comments
+ */
+public class CFileTypeResolver implements ICFileTypeResolver {
+
+ 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_ID = "id"; //$NON-NLS-1$
+ private static final String ATTR_NAME = "name"; //$NON-NLS-1$
+ private static final String ATTR_TYPE = "type"; //$NON-NLS-1$
+ private static final String ATTR_EXT = "pattern"; //$NON-NLS-1$
+ private static final String ATTR_FILE = "file"; //$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$
+
+ /**
+ * Default file type, returned when no other file type matches a file name.
+ */
+ public static final ICFileType DEFAULT_FILE_TYPE =
+ new CFileType(ICFileTypeConstants.UNKNOWN, "", ICFileType.TYPE_UNKNOWN);
+
+ // Singleton
+ private static ICFileTypeResolver instance = new CFileTypeResolver();
+
+ // Private ctor to preserve singleton status
+ private CFileTypeResolver() {
+ loadTypes();
+ loadAssociations();
+
+ String[] test = { "foo.c", "bar.h", "baz.s", "numeric" };
+ for (int i = 0; i < test.length; i++) {
+ ICFileType ft = getFileType(test[i]);
+ System.out.println("Self test: " + test[i] + " mapped to " + ft.getId());
+ }
+ }
+
+ /**
+ * @return the default instance of this singleton
+ */
+ public static ICFileTypeResolver getDefault() {
+ return instance;
+ }
+
+ /**
+ * The type map holds a map of file type IDs to file types.
+ */
+ private Map fTypeMap = new HashMap();
+
+ /**
+ * The association list holds a list of known file associations.
+ */
+ private List fAssocList = new ArrayList();
+
+ /**
+ * Get the file type assocated with the specified file name.
+ * Returns DEFAULT_FILE_TYPE if the file name could not be
+ * resolved to a particular file type.
+ *
+ * @param fileName name of the file to resolve
+ *
+ * @return associated file type, or DEFAULT_FILE_TYPE
+ */
+ public ICFileType getFileType(String fileName) {
+ for (Iterator iter = fAssocList.iterator(); iter.hasNext();) {
+ ICFileTypeAssociation element = (ICFileTypeAssociation) iter.next();
+ if (element.matches(fileName)) {
+ return element.getType();
+ }
+ }
+ return DEFAULT_FILE_TYPE;
+ }
+
+ /**
+ * 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) {
+ ICFileType type = (ICFileType) fTypeMap.get(typeId);
+ return ((null != type) ? type : DEFAULT_FILE_TYPE);
+ }
+
+ /**
+ * @return the file types know to the resolver
+ */
+ public ICFileType[] getFileTypes() {
+ Collection values = fTypeMap.values();
+ return (ICFileType[]) values.toArray(new ICFileType[values.size()]);
+ }
+
+ /**
+ * @return the file type associations know to the resolver
+ */
+ public ICFileTypeAssociation[] getFileTypeAssociations() {
+ return (ICFileTypeAssociation[]) fAssocList.toArray(new ICFileTypeAssociation[fAssocList.size()]);
+ }
+
+ /**
+ * 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 addFileType(ICFileType type) {
+ if (CCorePlugin.getDefault().isDebugging()) {
+ System.out.println("File Type Resolver: adding type " + type.getId() + " as " + type.getName());
+ }
+ System.out.println();
+ boolean added = false;
+ if (!fTypeMap.containsValue(type)) {
+ added = (null != fTypeMap.put(type.getId(), type));
+ }
+ return added;
+ }
+
+ /**
+ * 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 removeFileType(ICFileType type) {
+ if (CCorePlugin.getDefault().isDebugging()) {
+ System.out.println("File Type Resolver: removing type " + type.getId() + " as " + type.getName());
+ }
+ // TODO: must remove any associations based on this file type as well
+ return (null != fTypeMap.remove(type));
+ }
+
+ /**
+ * Add an instance of a file type association to the associations
+ * 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 assoc association to add
+ *
+ * @return true if the association is added, false otherwise
+ */
+ public boolean addFileTypeAssociation(ICFileTypeAssociation assoc) {
+ if (CCorePlugin.getDefault().isDebugging()) {
+ System.out.println("File Type Resolver: adding association " + assoc.getPattern() + " as " + assoc.getType().getId());
+ }
+ boolean added = false;
+ if (!fAssocList.contains(assoc)) {
+ added = fAssocList.add(assoc);
+ }
+ return added;
+ }
+
+ public boolean removeFileTypeAssociation(ICFileTypeAssociation assoc) {
+ if (CCorePlugin.getDefault().isDebugging()) {
+ System.out.println("File Type Resolver: removing association " + assoc.getPattern() + " as " + assoc.getType().getId());
+ }
+ return fAssocList.remove(assoc);
+ }
+
+ /**
+ * Load file type declared through the CFileType extension point.
+ */
+ private void loadTypes() {
+ IExtensionPoint point = getExtensionPoint(EXTENSION_TYPE);
+ 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++) {
+ String id = elements[j].getAttribute(ATTR_ID);
+ String name = elements[j].getAttribute(ATTR_NAME);
+ String type = elements[j].getAttribute(ATTR_TYPE);
+ addFileType(new CFileType(id, name, parseType(type)));
+ }
+ }
+ }
+
+ /**
+ * Load file type associations declared through the CFileTypeAssociation
+ * extension point.
+ */
+ private void loadAssociations() {
+ IExtensionPoint point = getExtensionPoint(EXTENSION_ASSOC);
+ IExtension[] extensions = point.getExtensions();
+ IConfigurationElement[] elements = null;
+ ICFileTypeAssociation[] assocs = null;
+
+ for (int i = 0; i < extensions.length; i++) {
+ elements = extensions[i].getConfigurationElements();
+ for (int j = 0; j < elements.length; j++) {
+ ICFileType typeRef = getFileTypeById(elements[j].getAttribute(ATTR_TYPE));
+ if (null != typeRef) {
+ addAssocFromPattern(typeRef, elements[j]);
+ addAssocFromFile(typeRef, elements[j]);
+ }
+ }
+ }
+ }
+
+ /**
+ * Convenience method for getting an IExtensionPoint instance.
+ *
+ * @see org.eclipse.core.runtime.IPluginDescriptor#getExtensionPoint(String)
+ *
+ * @param extensionPointId the simple identifier of the extension point
+ *
+ * @return the extension point, or null
+ */
+ private IExtensionPoint getExtensionPoint(String extensionPointId) {
+ return CCorePlugin.getDefault().getDescriptor().getExtensionPoint(extensionPointId);
+ }
+
+ /**
+ * 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;
+ }
+
+ /**
+ * 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 void addAssocFromPattern(ICFileType typeRef, IConfigurationElement element) {
+ String attr = element.getAttribute(ATTR_EXT);
+ if (null != attr) {
+ String[] item = attr.split(",");
+ for (int i = 0; i < item.length; i++) {
+ addFileTypeAssociation(new CFileTypeAssociation(item[i].trim(), typeRef));
+ }
+ }
+ }
+
+ /**
+ * 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 void addAssocFromFile(ICFileType typeRef, IConfigurationElement element) {
+ String attr = element.getAttribute(ATTR_FILE);
+
+ if (null != attr) {
+ URL baseURL = null;
+ URL fileURL = null;
+ BufferedReader in = null;
+ String line = null;
+
+ try {
+ baseURL = element.getDeclaringExtension().getDeclaringPluginDescriptor().getInstallURL();
+ fileURL = new URL(baseURL, attr);
+ in = new BufferedReader(new InputStreamReader(fileURL.openStream()));
+ line = in.readLine();
+ while (null != line) {
+ addFileTypeAssociation(new CFileTypeAssociation(line, typeRef));
+ line = in.readLine();
+ }
+ in.close();
+ } catch (IOException e) {
+ }
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.core/template/cpp_headers b/core/org.eclipse.cdt.core/template/cpp_headers
new file mode 100644
index 0000000000..30bd9a0948
--- /dev/null
+++ b/core/org.eclipse.cdt.core/template/cpp_headers
@@ -0,0 +1,31 @@
+algorithm
+bitset
+deque
+exception
+fstream
+functional
+iomanip
+ios
+iosfwd
+iostream
+istream
+iterator
+limits
+list
+locale
+map
+memory
+new
+numeric
+ostream
+queue
+set
+sstream
+stack
+stdexcept
+streambuf
+string
+typeinfo
+utility
+valarray
+vector

Back to the top