33import java .io .File ;
44import java .net .URI ;
55import java .util .Collection ;
6+ import java .util .LinkedHashSet ;
67import java .util .LinkedList ;
78import java .util .List ;
89
3637 *
3738 */
3839public class ToolchainSettings implements IToolchainSettings {
39- private static final String EXTENSION_CPP = "cpp" ;
4040 private final List <ICLanguageSetting > languageSettings ;
4141 private final ICConfigurationDescription activeConfiguration ;
4242 private final IProject project ;
4343 private final IWorkspaceRoot root ;
44+ private static final String [] C_EXTENSIONS = { ".c" , ".cl" };
45+ private static final String [] CPP_EXTENSIONS = {
46+ ".cpp" , ".cxx" , ".cc" , ".c++" , ".tpp" , ".txx" , ".ipp" , ".ixx"
47+ };
4448
4549 public ToolchainSettings (IProject project ) throws IllegalStateException {
4650 languageSettings = new LinkedList <ICLanguageSetting >();
@@ -67,13 +71,14 @@ public ToolchainSettings(IProject project) throws IllegalStateException {
6771 ICLanguageSetting [] allLanguageSettings = folderDescription
6872 .getLanguageSettings ();
6973
70- // fetch the include settings from the first tool which supports c
71- for (ICLanguageSetting languageSetting : allLanguageSettings ) {
72- String extensions [] = languageSetting .getSourceExtensions ();
73- for (String extension : extensions ) {
74- if (EXTENSION_CPP .equalsIgnoreCase (extension )) { //$NON-NLS-1$
75- languageSettings .add (languageSetting );
76- }
74+ for (ICLanguageSetting ls : allLanguageSettings ) {
75+ String [] exts = ls .getSourceExtensions ();
76+ for (String ext : exts ) {
77+ if (containsIgnoreCase (C_EXTENSIONS , ext )
78+ || containsIgnoreCase (CPP_EXTENSIONS , ext )) {
79+ languageSettings .add (ls );
80+ break ;
81+ }
7782 }
7883 }
7984
@@ -161,7 +166,7 @@ protected Collection<File> resolveIncludePath(File includePath)
161166 * @return all include folders in a list
162167 */
163168 protected Collection <File > getIncludes (boolean onlyUserDefined ) {
164- Collection <File > paths = new LinkedList <File >();
169+ Collection <File > paths = new LinkedHashSet <File >();
165170 IWorkspaceRoot workspaceRoot = project .getWorkspace ().getRoot ();
166171 URI workspaceUri = workspaceRoot .getLocationURI ();
167172
@@ -238,4 +243,22 @@ protected Collection<Symbol> getSymbols(boolean onlyUserDefined) {
238243 }
239244 return symbols ;
240245 }
246+
247+ /**
248+ * Helper function to check if array of strings contain a given string, ignoring case.
249+ *
250+ * @param values
251+ * Array of strings to check
252+ * @param value
253+ * String to check against
254+ * @return whether values contains value (ignoring case)
255+ */
256+ private static boolean containsIgnoreCase (String [] values , String value ) {
257+ for (String s : values ) {
258+ if (s .equalsIgnoreCase (value )) {
259+ return true ;
260+ }
261+ }
262+ return false ;
263+ }
241264}
0 commit comments