diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CLibraryFileEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CLibraryFileEntry.java index a08eefcb213..8afdd7e7570 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CLibraryFileEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CLibraryFileEntry.java @@ -10,22 +10,65 @@ *******************************************************************************/ package org.eclipse.cdt.core.settings.model; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; public final class CLibraryFileEntry extends ACPathEntry implements ICLibraryFileEntry { - + private IPath fSourceAttachmentPath; + private IPath fSourceAttachmentRootPath; + private IPath fSourceAttachmentPrefixMapping; + public CLibraryFileEntry(String value, int flags) { - super(value, flags); + this(value, flags, null, null, null); } public CLibraryFileEntry(IPath location, int flags) { - super(location, flags); + this(location, flags, null, null, null); } public CLibraryFileEntry(IFile rc, int flags) { + this(rc, flags, null, null, null); + } + + public CLibraryFileEntry(String value, + int flags, + IPath sourceAttachmentPath, + IPath sourceAttachmentRootPath, + IPath sourceAttachmentPrefixMapping) { + super(value, flags); + setSourceAttachmentSettings(sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping); + } + + public CLibraryFileEntry(IPath location, + int flags, + IPath sourceAttachmentPath, + IPath sourceAttachmentRootPath, + IPath sourceAttachmentPrefixMapping) { + super(location, flags); + setSourceAttachmentSettings(sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping); + } + + public CLibraryFileEntry(IFile rc, + int flags, + IPath sourceAttachmentPath, + IPath sourceAttachmentRootPath, + IPath sourceAttachmentPrefixMapping) { super(rc, flags); + setSourceAttachmentSettings(sourceAttachmentPath, sourceAttachmentRootPath, sourceAttachmentPrefixMapping); + } + + private void setSourceAttachmentSettings(IPath sourceAttachmentPath, + IPath sourceAttachmentRootPath, + IPath sourceAttachmentPrefixMapping){ + if(sourceAttachmentPath == null) + return; + + fSourceAttachmentPath = sourceAttachmentPath; + fSourceAttachmentRootPath = sourceAttachmentRootPath != null ? sourceAttachmentRootPath : Path.EMPTY; + fSourceAttachmentPrefixMapping = sourceAttachmentPrefixMapping != null ? sourceAttachmentPrefixMapping : Path.EMPTY; } public final int getKind() { @@ -36,4 +79,45 @@ public final class CLibraryFileEntry extends ACPathEntry implements return true; } + public IPath getSourceAttachmentPath() { + return fSourceAttachmentPath; + } + + public IPath getSourceAttachmentPrefixMapping() { + return fSourceAttachmentPrefixMapping; + } + + public IPath getSourceAttachmentRootPath() { + return fSourceAttachmentRootPath; + } + + public boolean equals(Object other) { + if(other == this) + return true; + + if(!super.equals(other)) + return false; + + return sourceAttachmentSettingsEqual((CLibraryFileEntry)other); + } + + public boolean equalsByContents(ICSettingEntry entry) { + if(entry == this) + return true; + + if(!super.equalsByContents(entry)) + return false; + + return sourceAttachmentSettingsEqual((CLibraryFileEntry)entry); + } + + private boolean sourceAttachmentSettingsEqual(CLibraryFileEntry otherEntry){ + if(!CDataUtil.objectsEqual(fSourceAttachmentPath, otherEntry.fSourceAttachmentPath)) + return false; + if(!CDataUtil.objectsEqual(fSourceAttachmentRootPath, otherEntry.fSourceAttachmentRootPath)) + return false; + if(!CDataUtil.objectsEqual(fSourceAttachmentPrefixMapping, otherEntry.fSourceAttachmentPrefixMapping)) + return false; + return true; + } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICLibraryFileEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICLibraryFileEntry.java index 1cbcf750a15..99b4e80565b 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICLibraryFileEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/ICLibraryFileEntry.java @@ -10,6 +10,49 @@ *******************************************************************************/ package org.eclipse.cdt.core.settings.model; +import org.eclipse.core.runtime.IPath; + public interface ICLibraryFileEntry extends ICLanguageSettingPathEntry { + /** + * Returns the path to the source archive or folder associated with this + * C path entry, or null if this C path entry has no + * source attachment. + *

+ * Only library and variable C path entries may have source attachments. + * For library C path entries, the result path (if present) locates a source + * archive or folder. This archive or folder can be located in a project of the + * workspace or outside thr workspace. For variable c path entries, the + * result path (if present) has an analogous form and meaning as the + * variable path, namely the first segment is the name of a c path variable. + *

+ * + * @return the path to the source archive or folder, or null if none + */ + IPath getSourceAttachmentPath(); + + /** + * Returns the path within the source archive or folder where source + * are located. An empty path indicates that packages are located at + * the root of the source archive or folder. Returns a non-null value + * if and only if getSourceAttachmentPath returns + * a non-null value. + * + * @return the path within the source archive or folder, or null if + * not applicable + */ + IPath getSourceAttachmentRootPath(); + + /** + * Returns the path to map the source paths with to the source achive or folder + * An empty path indicates that the is a one-to-one mapping of source paths to the + * source achive or folder path. Returns a non-null value + * if and only if getSourceAttachmentPath returns + * a non-null value. + * + * @return the path mapping within the source archive or folder, or null if + * not applicable + */ + IPath getSourceAttachmentPrefixMapping(); + } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java index f07ca395ec3..536e06089b4 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/CDataUtil.java @@ -41,6 +41,7 @@ import org.eclipse.cdt.core.settings.model.CSourceEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICExclusionPatternPathEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICLibraryFileEntry; import org.eclipse.cdt.core.settings.model.ICOutputEntry; import org.eclipse.cdt.core.settings.model.ICSettingBase; import org.eclipse.cdt.core.settings.model.ICSettingEntry; @@ -239,7 +240,13 @@ public class CDataUtil { entry = new CLibraryPathEntry(entry.getName(), flags); break; case ICLanguageSettingEntry.LIBRARY_FILE: - entry = new CLibraryFileEntry(entry.getName(), flags); + ICLibraryFileEntry libFile = (ICLibraryFileEntry)entry; + entry = new CLibraryFileEntry(entry.getName(), + flags, + libFile.getSourceAttachmentPath(), + libFile.getSourceAttachmentRootPath(), + libFile.getSourceAttachmentPrefixMapping() + ); break; } return entry; diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java index 00338cfd8fc..e7751a92408 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/LanguageSettingEntriesSerializer.java @@ -24,6 +24,7 @@ import org.eclipse.cdt.core.settings.model.COutputEntry; import org.eclipse.cdt.core.settings.model.CSourceEntry; import org.eclipse.cdt.core.settings.model.ICExclusionPatternPathEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; +import org.eclipse.cdt.core.settings.model.ICLibraryFileEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; import org.eclipse.cdt.core.settings.model.ICStorageElement; import org.eclipse.core.runtime.IPath; @@ -36,6 +37,9 @@ public class LanguageSettingEntriesSerializer { public static final String ATTRIBUTE_VALUE = "value"; //$NON-NLS-1$ public static final String ATTRIBUTE_FLAGS = "flags"; //$NON-NLS-1$ public static final String ATTRIBUTE_EXCLUDING = "excluding"; //$NON-NLS-1$ + public static final String ATTRIBUTE_SOURCE_ATTACHMENT_PATH = "srcPath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_SOURCE_ATTACHMENT_ROOT_PATH = "srcRootPath"; //$NON-NLS-1$ + public static final String ATTRIBUTE_SOURCE_ATTACHMENT_PREFIX_MAPPING = "srcPrefixMapping"; //$NON-NLS-1$ // public static final String ATTRIBUTE_FULL_PATH = "fullPath"; //$NON-NLS-1$ // public static final String ATTRIBUTE_LOCATION = "location"; //$NON-NLS-1$ @@ -111,7 +115,10 @@ public class LanguageSettingEntriesSerializer { case ICLanguageSettingEntry.LIBRARY_PATH: return new CLibraryPathEntry(name, flags); case ICLanguageSettingEntry.LIBRARY_FILE: - return new CLibraryFileEntry(name, flags); + IPath srcPath = loadPath(el, ATTRIBUTE_SOURCE_ATTACHMENT_PATH); + IPath srcRootPath = loadPath(el, ATTRIBUTE_SOURCE_ATTACHMENT_ROOT_PATH); + IPath srcPrefixMapping = loadPath(el, ATTRIBUTE_SOURCE_ATTACHMENT_PREFIX_MAPPING); + return new CLibraryFileEntry(name, flags, srcPath, srcRootPath, srcPrefixMapping); case ICLanguageSettingEntry.OUTPUT_PATH: return new COutputEntry(name, loadExclusions(el), flags); case ICLanguageSettingEntry.SOURCE_PATH: @@ -120,6 +127,18 @@ public class LanguageSettingEntriesSerializer { return null; } + private static IPath loadPath(ICStorageElement el, String attr){ + String value = el.getAttribute(attr); + if(value != null) + return new Path(value); + return null; + } + + private static void storePath(ICStorageElement el, String attr, IPath path){ + if(path != null) + el.setAttribute(attr, path.toString()); + } + private static IPath[] loadExclusions(ICStorageElement el){ String attr = el.getAttribute(ATTRIBUTE_EXCLUDING); if(attr != null){ @@ -173,6 +192,19 @@ public class LanguageSettingEntriesSerializer { IPath paths[] = ((ICExclusionPatternPathEntry)entry).getExclusionPatterns(); storeExclusions(element, paths); break; + case ICLanguageSettingEntry.LIBRARY_FILE: + ICLibraryFileEntry libFile = (ICLibraryFileEntry)entry; + IPath path = libFile.getSourceAttachmentPath(); + if(path != null) + element.setAttribute(ATTRIBUTE_SOURCE_ATTACHMENT_PATH, path.toString()); + + path = libFile.getSourceAttachmentRootPath(); + if(path != null) + element.setAttribute(ATTRIBUTE_SOURCE_ATTACHMENT_ROOT_PATH, path.toString()); + + path = libFile.getSourceAttachmentPrefixMapping(); + if(path != null) + element.setAttribute(ATTRIBUTE_SOURCE_ATTACHMENT_PREFIX_MAPPING, path.toString()); } } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java index 015c02d90b1..67457c2cdbf 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/util/PathEntryTranslator.java @@ -409,6 +409,7 @@ public class PathEntryTranslator { switch(entry.fEntry.getEntryKind()){ case IPathEntry.CDT_LIBRARY:{ + ILibraryEntry libEntry = (ILibraryEntry)entry.fEntry; IPath path = value.getFullPath(); if(path != null){ flags |= ICLanguageSettingEntry.VALUE_WORKSPACE_PATH; @@ -417,7 +418,10 @@ public class PathEntryTranslator { } if(path != null){ - return new CLibraryFileEntry(value.getName(), flags); + return new CLibraryFileEntry(value.getName(), flags, + libEntry.getSourceAttachmentPath(), + libEntry.getSourceAttachmentRootPath(), + libEntry.getSourceAttachmentPrefixMapping()); } break; }