mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-23 17:05:26 +02:00
CDT Variables (macros) resolving for the language setting entries
This commit is contained in:
parent
fdc6c2b7fe
commit
7360d17945
4 changed files with 90 additions and 7 deletions
|
@ -37,7 +37,7 @@ public interface ICSettingEntry {
|
|||
|
||||
boolean isBuiltIn();
|
||||
|
||||
// boolean isResolved();
|
||||
boolean isResolved();
|
||||
|
||||
boolean equalsByName(ICLanguageSettingEntry entry);
|
||||
|
||||
|
|
|
@ -15,6 +15,19 @@ import java.util.List;
|
|||
import java.util.Random;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.cdtvariables.CdtVariableException;
|
||||
import org.eclipse.cdt.core.cdtvariables.ICdtVariableManager;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludeFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CIncludePathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CLibraryPathEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroEntry;
|
||||
import org.eclipse.cdt.core.settings.model.CMacroFileEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
||||
import org.eclipse.cdt.core.settings.model.ICSettingEntry;
|
||||
|
||||
public class CDataUtil {
|
||||
private static Random randomNumber;
|
||||
public static final String[] EMPTY_STRING_ARRAY = new String[0];
|
||||
|
@ -73,5 +86,56 @@ public class CDataUtil {
|
|||
}
|
||||
return (String[])list.toArray(new String[list.size()]);
|
||||
}
|
||||
|
||||
public static ICLanguageSettingEntry[] resolveEntries(ICLanguageSettingEntry entries[], ICConfigurationDescription cfgDes){
|
||||
if(entries.length == 0)
|
||||
return entries;
|
||||
|
||||
ICLanguageSettingEntry[] resolved = new ICLanguageSettingEntry[entries.length];
|
||||
ICdtVariableManager mngr = CCorePlugin.getDefault().getCdtVariableManager();
|
||||
|
||||
for(int i = 0; i < entries.length; i++){
|
||||
ICLanguageSettingEntry entry = entries[i];
|
||||
resolved[i] = createResolvedEntry(entry, cfgDes, mngr);
|
||||
}
|
||||
|
||||
return resolved;
|
||||
}
|
||||
|
||||
private static ICLanguageSettingEntry createResolvedEntry(ICLanguageSettingEntry entry, ICConfigurationDescription cfg, ICdtVariableManager mngr){
|
||||
if(entry.isResolved())
|
||||
return entry;
|
||||
|
||||
String name = entry.getName();
|
||||
try {
|
||||
name = mngr.resolveValue(name, "", " ", cfg); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (CdtVariableException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
|
||||
switch (entry.getKind()) {
|
||||
case ICLanguageSettingEntry.INCLUDE_PATH:
|
||||
return new CIncludePathEntry(name, ICSettingEntry.RESOLVED | entry.getFlags());
|
||||
case ICLanguageSettingEntry.INCLUDE_FILE:
|
||||
return new CIncludeFileEntry(name, ICSettingEntry.RESOLVED | entry.getFlags());
|
||||
case ICLanguageSettingEntry.MACRO:
|
||||
String value = entry.getValue();
|
||||
try {
|
||||
value = mngr.resolveValue(value, "", " ", cfg); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
} catch (CdtVariableException e) {
|
||||
CCorePlugin.log(e);
|
||||
}
|
||||
return new CMacroEntry(name, value, ICSettingEntry.RESOLVED | entry.getFlags());
|
||||
case ICLanguageSettingEntry.MACRO_FILE:
|
||||
return new CMacroFileEntry(name, ICSettingEntry.RESOLVED | entry.getFlags());
|
||||
case ICLanguageSettingEntry.LIBRARY_PATH:
|
||||
return new CLibraryPathEntry(name, ICSettingEntry.RESOLVED | entry.getFlags());
|
||||
case ICLanguageSettingEntry.LIBRARY_FILE:
|
||||
return new CLibraryFileEntry(name, ICSettingEntry.RESOLVED | entry.getFlags());
|
||||
default:
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -20,8 +20,8 @@ import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry;
|
|||
import org.eclipse.cdt.core.settings.model.ICSettingBase;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CLanguageData;
|
||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.core.settings.model.util.EntryStore;
|
||||
import org.eclipse.cdt.core.settings.model.util.KindBasedStore;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ProjectScope;
|
||||
import org.eclipse.core.runtime.Platform;
|
||||
|
@ -380,8 +380,9 @@ public class CLanguageSetting extends CDataProxy implements
|
|||
// }
|
||||
|
||||
public ICLanguageSettingEntry[] getResolvedSettingEntries(int kind) {
|
||||
// TODO Auto-generated method stub
|
||||
return getSettingEntries(kind);
|
||||
ICLanguageSettingEntry entries[] = getSettingEntries(kind);
|
||||
entries = CDataUtil.resolveEntries(entries, getConfiguration());
|
||||
return entries;
|
||||
}
|
||||
|
||||
public void setSourceContentTypeIds(String[] ids) {
|
||||
|
|
|
@ -19,10 +19,14 @@ import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
|||
import org.eclipse.cdt.core.settings.model.ICSettingContainer;
|
||||
import org.eclipse.cdt.core.settings.model.extension.CLanguageData;
|
||||
import org.eclipse.cdt.core.settings.model.extension.impl.CDefaultLanguageData;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.core.settings.model.util.EntryStore;
|
||||
|
||||
public class CLanguageSettingCache extends CDefaultLanguageData implements
|
||||
ICLanguageSetting, ICachedData {
|
||||
private ICResourceDescription fParent;
|
||||
protected EntryStore fResolvedEntriesStore;
|
||||
|
||||
public CLanguageSettingCache(CLanguageData base, CFolderDescriptionCache folderCache) {
|
||||
fId = base.getId();
|
||||
fParent = folderCache;
|
||||
|
@ -41,10 +45,24 @@ public class CLanguageSettingCache extends CDefaultLanguageData implements
|
|||
}
|
||||
*/
|
||||
public ICLanguageSettingEntry[] getResolvedSettingEntries(int kind) {
|
||||
// TODO Auto-generated method stub
|
||||
return getSettingEntries(kind);
|
||||
ICLanguageSettingEntry[] entries = getSettingEntries(kind);
|
||||
if(entries.length != 0){
|
||||
if(fResolvedEntriesStore == null){
|
||||
fResolvedEntriesStore = new EntryStore();
|
||||
}
|
||||
|
||||
ICLanguageSettingEntry[] resolved = fResolvedEntriesStore.getEntries();
|
||||
if(resolved.length == 0){
|
||||
resolved = CDataUtil.resolveEntries(entries, getConfiguration());
|
||||
fResolvedEntriesStore.storeEntries(kind, resolved);
|
||||
}
|
||||
|
||||
entries = resolved;
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public ICLanguageSettingEntry[] getSettingEntries(int kind) {
|
||||
// int kinds[] = KindBasedStore.getSupportedKinds();
|
||||
// List list = new ArrayList();
|
||||
|
|
Loading…
Add table
Reference in a new issue