Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.File;
import java.net.URI;
import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;

Expand Down Expand Up @@ -36,11 +37,14 @@
*
*/
public class ToolchainSettings implements IToolchainSettings {
private static final String EXTENSION_CPP = "cpp";
private final List<ICLanguageSetting> languageSettings;
private final ICConfigurationDescription activeConfiguration;
private final IProject project;
private final IWorkspaceRoot root;
private static final String[] C_EXTENSIONS = { ".c", ".cl" };
private static final String[] CPP_EXTENSIONS = {
".cpp", ".cxx", ".cc", ".c++", ".tpp", ".txx", ".ipp", ".ixx"
};

public ToolchainSettings(IProject project) throws IllegalStateException {
languageSettings = new LinkedList<ICLanguageSetting>();
Expand All @@ -67,13 +71,14 @@ public ToolchainSettings(IProject project) throws IllegalStateException {
ICLanguageSetting[] allLanguageSettings = folderDescription
.getLanguageSettings();

// fetch the include settings from the first tool which supports c
for (ICLanguageSetting languageSetting : allLanguageSettings) {
String extensions[] = languageSetting.getSourceExtensions();
for (String extension : extensions) {
if (EXTENSION_CPP.equalsIgnoreCase(extension)) { //$NON-NLS-1$
languageSettings.add(languageSetting);
}
for (ICLanguageSetting ls : allLanguageSettings) {
String[] exts = ls.getSourceExtensions();
for (String ext : exts) {
if (containsIgnoreCase(C_EXTENSIONS, ext)
|| containsIgnoreCase(CPP_EXTENSIONS, ext)) {
languageSettings.add(ls);
break;
}
}
}

Expand Down Expand Up @@ -161,7 +166,7 @@ protected Collection<File> resolveIncludePath(File includePath)
* @return all include folders in a list
*/
protected Collection<File> getIncludes(boolean onlyUserDefined) {
Collection<File> paths = new LinkedList<File>();
Collection<File> paths = new LinkedHashSet<File>();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to avoid duplicates if same includes are added in both c and c++ language settings

IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
URI workspaceUri = workspaceRoot.getLocationURI();

Expand Down Expand Up @@ -238,4 +243,22 @@ protected Collection<Symbol> getSymbols(boolean onlyUserDefined) {
}
return symbols;
}

/**
* Helper function to check if array of strings contain a given string, ignoring case.
*
* @param values
* Array of strings to check
* @param value
* String to check against
* @return whether values contains value (ignoring case)
*/
private static boolean containsIgnoreCase(String[] values, String value) {
for (String s : values) {
if (s.equalsIgnoreCase(value)) {
return true;
}
}
return false;
}
}
Loading