diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index c5316b64f83..6192c464355 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -1,3 +1,16 @@ +2004-04-16 Alain Magloire + + Patch from Sam Robb to cover PR 52864 + * src/org/eclipse/cdt/core/internal/fileType/CFileType.java + * src/org/eclipse/cdt/core/internal/fileType/CFileTypeResolver.java + * src/org/eclipse/cdt/core/internal/fileType/CLanguage.java + * srcorg.eclipse/cdt/core/filetype/ICFileType.java + * srcorg.eclipse/cdt/core/filetype/ICFileTypeConstants.java + * srcorg.eclipse/cdt/core/filetype/ICLanguage.java + * schema/CFileType.exsd + * schema/CLanguage.exsd + * plugin.xml + 2004-04-16 Hoda Amer -CModelBuilder and scalability problems: Starting children list with initial size = 0 Now 25,000 element Translation unit takes 450 ms in CModelBuilder. diff --git a/core/org.eclipse.cdt.core/plugin.xml b/core/org.eclipse.cdt.core/plugin.xml index 9cbc28cc391..c1ba437a99c 100644 --- a/core/org.eclipse.cdt.core/plugin.xml +++ b/core/org.eclipse.cdt.core/plugin.xml @@ -43,6 +43,7 @@ + @@ -175,54 +176,78 @@ + + + + + + + + - - - - - + + + + + + + + + + - diff --git a/core/org.eclipse.cdt.core/schema/CFileType.exsd b/core/org.eclipse.cdt.core/schema/CFileType.exsd index e36e31122ae..88cbc6a3918 100644 --- a/core/org.eclipse.cdt.core/schema/CFileType.exsd +++ b/core/org.eclipse.cdt.core/schema/CFileType.exsd @@ -6,7 +6,7 @@ - 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. + Extension point representing a CDT file type. File types consist of a unique identifier (id), a human-readable name, an associated source language, and an enumerated value that indicates how this file should be treated by CDT. By themselves, file types don'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. @@ -72,6 +72,13 @@ By themselves, file types don't serve much purpose. However, they are used + + + + + + + @@ -96,7 +103,8 @@ By themselves, file types don't serve much purpose. However, they are used <fileType name="My File Type" type="source" - id="com.example.product.fileType.my_file_type"> + language="com.example.product.language.my_language" + id="com.example.product.fileType.my_language_source"> </fileType> </extension> diff --git a/core/org.eclipse.cdt.core/schema/CLanguage.exsd b/core/org.eclipse.cdt.core/schema/CLanguage.exsd new file mode 100644 index 00000000000..9224a64b9dd --- /dev/null +++ b/core/org.eclipse.cdt.core/schema/CLanguage.exsd @@ -0,0 +1,118 @@ + + + + + + + + + Extension point representing a CDT language. At the moment, languages consist of a unique identifier (id), and a human-readable name. + +By themselves, languages don't serve much purpose. However, they are used to build file types (see the CFileType extension point), which are used by CDT to classify files and determine how they should be processed. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + CDT 2.0 + + + + + + + + + To declare a new language: + + <extension + point="org.eclipse.cdt.core.CLanguage"> + <language + name="My Language" + id="com.example.product.language.my_language"> + </fileType> + </extension> + +This indicates to CDT that there is a new language, identified using the language id "com.example.product.language.my_language". + + + + + + + + + This extension point is purely declarative. + + + + + + + + + + + + + + + + + + + + + + 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 index 9400fd4738a..d8d794b7b3e 100644 --- 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 @@ -28,7 +28,12 @@ public interface ICFileType { * @return Id associated with this file type. */ public String getId(); - + + /** + * @return Language id associated with this file type. + */ + public String getLanguageId(); + /** * @return Name of this file type. */ 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 index ae380c45c80..26c92a9c84c 100644 --- 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 @@ -15,17 +15,33 @@ package org.eclipse.cdt.core.filetype; */ public interface ICFileTypeConstants { - public static String ID_PREFIX = "org.eclipse.cdt.core.fileType."; //$NON-NLS-1$ + public static String ID_PREFIX = "org.eclipse.cdt.core."; //$NON-NLS-1$ - public static String UNKNOWN = ID_PREFIX + "unknown"; //$NON-NLS-1$ + // Default languages known to CDT + + public static String LANG_PREFIX = ID_PREFIX + "language."; //$NON-NLS-1$ - public static String C_SOURCE = ID_PREFIX + "c_source"; //$NON-NLS-1$ + public static String LANG_UNKNOWN = LANG_PREFIX + "unknown"; //$NON-NLS-1$ - public static String C_HEADER = ID_PREFIX + "c_header"; //$NON-NLS-1$ + public static String LANG_C = LANG_PREFIX + "c"; //$NON-NLS-1$ - public static String CXX_HEADER = ID_PREFIX + "cxx_source"; //$NON-NLS-1$ + public static String LANG_CXX = LANG_PREFIX + "cxx"; //$NON-NLS-1$ - public static String CXX_SOURCE = ID_PREFIX + "cxx_header"; //$NON-NLS-1$ + public static String LANG_ASM = LANG_PREFIX + "asm"; //$NON-NLS-1$ + + // Default file types known to CDT - public static String ASM_SOURCE = ID_PREFIX + "asm_source"; //$NON-NLS-1$ + 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_HEADER = FT_PREFIX + "cxx_source"; //$NON-NLS-1$ + + public static String FT_CXX_SOURCE = 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/ICLanguage.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICLanguage.java new file mode 100644 index 00000000000..26977017a5a --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/filetype/ICLanguage.java @@ -0,0 +1,27 @@ +/********************************************************************** + * 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.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/internal/filetype/CFileType.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CFileType.java index 3180d9267fe..f26adf22af9 100644 --- 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 @@ -18,11 +18,13 @@ import org.eclipse.cdt.core.filetype.ICFileType; public class CFileType implements ICFileType { private String fId; + private String fLangId; private String fName; private int fType; - public CFileType(String id, String name, int type) { + public CFileType(String id, String languageId, String name, int type) { fId = id; + fLangId = languageId; fName = name; fType = type; } @@ -31,6 +33,10 @@ public class CFileType implements ICFileType { return fId; } + public String getLanguageId() { + return fLangId; + } + public String getName() { return fName; } 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 index 2cf7151ecfd..742dddc3aab 100644 --- 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 @@ -26,6 +26,7 @@ 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.core.runtime.IConfigurationElement; import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; @@ -38,9 +39,11 @@ import org.eclipse.core.runtime.IExtensionPoint; */ public class CFileTypeResolver implements ICFileTypeResolver { + 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_ID = "id"; //$NON-NLS-1$ + private static final String ATTR_LANGUAGE = "langauge"; //$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$ @@ -48,19 +51,27 @@ public class CFileTypeResolver implements ICFileTypeResolver { private static final String ATTR_VAL_SOURCE = "source"; //$NON-NLS-1$ private static final String ATTR_VAL_HEADER = "header"; //$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, ""); //$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); + new CFileType(ICFileTypeConstants.FT_UNKNOWN, ICFileTypeConstants.LANG_UNKNOWN, "", ICFileType.TYPE_UNKNOWN); //$NON-NLS-1$ // Singleton private static ICFileTypeResolver instance = new CFileTypeResolver(); // Private ctor to preserve singleton status private CFileTypeResolver() { + loadLanguages(); loadTypes(); loadAssociations(); + if (CCorePlugin.getDefault().isDebugging()) { String[] test = { "foo.c", "bar.h", "baz.s", "numeric" }; for (int i = 0; i < test.length; i++) { @@ -77,6 +88,11 @@ public class CFileTypeResolver implements ICFileTypeResolver { return instance; } + /** + * 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. */ @@ -120,7 +136,29 @@ public class CFileTypeResolver implements ICFileTypeResolver { } /** - * @return the file types know to the resolver + * 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) { + ICLanguage lang = (ICLanguage) fLangMap.get(languageId); + return ((null != lang) ? lang : DEFAULT_LANG_TYPE); + } + + + /** + * @return the languages known to the resolver + */ + public ICLanguage[] getLanguages() { + Collection values = fLangMap.values(); + return (ICLanguage[]) values.toArray(new ICLanguage[values.size()]); + } + + /** + * @return the file types known to the resolver */ public ICFileType[] getFileTypes() { Collection values = fTypeMap.values(); @@ -128,12 +166,49 @@ public class CFileTypeResolver implements ICFileTypeResolver { } /** - * @return the file type associations know to the resolver + * @return the file type associations known to the resolver */ public ICFileTypeAssociation[] getFileTypeAssociations() { return (ICFileTypeAssociation[]) fAssocList.toArray(new ICFileTypeAssociation[fAssocList.size()]); } + /** + * 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 addLanguage(ICLanguage lang) { + if (CCorePlugin.getDefault().isDebugging()) { + System.out.println("File Type Resolver: adding language " + lang.getId() + " as " + lang.getName()); + } + boolean added = false; + if (!fLangMap.containsValue(lang)) { + added = (null != fTypeMap.put(lang.getId(), lang)); + } + return added; + } + + /** + * 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 removeLanguage(ICLanguage lang) { + if (CCorePlugin.getDefault().isDebugging()) { + System.out.println("File Type Resolver: removing language " + lang.getId() + " as " + lang.getName()); + } + // TODO: must remove any file types based on this language as well + return (null != fLangMap.remove(lang)); + } + /** * Add an instance of a file type to the file types known to the * resolver. @@ -148,7 +223,6 @@ public class CFileTypeResolver implements ICFileTypeResolver { 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)) { @@ -200,6 +274,25 @@ public class CFileTypeResolver implements ICFileTypeResolver { } return fAssocList.remove(assoc); } + + /** + * Load languages declared through the CLanguage extension point. + */ + private void loadLanguages() { + IExtensionPoint point = getExtensionPoint(EXTENSION_LANG); + 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); + addLanguage(new CLanguage(id, name)); + } + } + + } /** * Load file type declared through the CFileType extension point. @@ -213,9 +306,10 @@ public class CFileTypeResolver implements ICFileTypeResolver { elements = extensions[i].getConfigurationElements(); for (int j = 0; j < elements.length; j++) { String id = elements[j].getAttribute(ATTR_ID); + String lang = elements[j].getAttribute(ATTR_LANGUAGE); String name = elements[j].getAttribute(ATTR_NAME); String type = elements[j].getAttribute(ATTR_TYPE); - addFileType(new CFileType(id, name, parseType(type))); + addFileType(new CFileType(id, lang, name, parseType(type))); } } } 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 new file mode 100644 index 00000000000..c325e9ed51e --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/internal/filetype/CLanguage.java @@ -0,0 +1,35 @@ +/********************************************************************** + * 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.ICLanguage; + +/** + * Representation of a declared file type. + */ +public class CLanguage implements ICLanguage { + + private String fId; + private String fName; + + public CLanguage(String id, String name) { + fId = id; + fName = name; + } + + public String getId() { + return fId; + } + + public String getName() { + return fName; + } +}