From e16fe328eb6b11a3145824c0f21d7e4e24e9e07c Mon Sep 17 00:00:00 2001 From: Andrew Gvozdev Date: Sat, 28 Jan 2012 15:37:37 -0500 Subject: [PATCH] bug 290631: Caching of ICSettingEntry objects in CDataUtil - CLibraryPathEntry/CLibraryFileEntry. --- .../internal/core/Configuration.java | 14 +++--- .../settings/model/CLibraryFileEntry.java | 43 +++++++++++++++--- .../settings/model/CLibraryPathEntry.java | 44 ++++++++++++++++--- .../core/settings/model/util/CDataUtil.java | 20 +++++++++ .../cdt/ui/newui/ExpLibraryPathTab.java | 4 +- .../eclipse/cdt/ui/newui/ExpLibraryTab.java | 4 +- .../eclipse/cdt/ui/newui/LibraryPathTab.java | 6 +-- .../org/eclipse/cdt/ui/newui/LibraryTab.java | 6 +-- 8 files changed, 110 insertions(+), 31 deletions(-) diff --git a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java index 8c519746873..10656406854 100644 --- a/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java +++ b/build/org.eclipse.cdt.managedbuilder.core/src/org/eclipse/cdt/managedbuilder/internal/core/Configuration.java @@ -27,8 +27,6 @@ import java.util.Vector; import org.eclipse.cdt.build.core.scannerconfig.ICfgScannerConfigBuilderInfo2Set; import org.eclipse.cdt.build.internal.core.scannerconfig.CfgDiscoveredPathManager.PathInfoCache; import org.eclipse.cdt.core.ErrorParserManager; -import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; -import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; import org.eclipse.cdt.core.settings.model.CSourceEntry; import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; import org.eclipse.cdt.core.settings.model.ICExternalSetting; @@ -1487,8 +1485,8 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild if (canExportedArtifactInfo()) { // Remove existing exported library, if it exists ICConfigurationDescription des = ManagedBuildManager.getDescriptionForConfiguration(this); - ICSettingEntry[] libs = CDataUtil.resolveEntries(new ICSettingEntry[] { - new CLibraryFileEntry(getArtifactName(), 0)}, des); + ICSettingEntry[] unresolved = new ICSettingEntry[] {CDataUtil.createCLibraryFileEntry(getArtifactName(), 0)}; + ICSettingEntry[] libs = CDataUtil.resolveEntries(unresolved, des); if (libs.length > 0) { for (ICExternalSetting setting : des.getExternalSettings()) { Set entries = new LinkedHashSet(Arrays.asList(setting.getEntries())); @@ -2807,14 +2805,14 @@ public class Configuration extends BuildObject implements IConfiguration, IBuild IPath p = new Path(value); if(!p.isAbsolute()) value = getOwner().getFullPath().append(value).toString(); - ICLibraryPathEntry lib = new CLibraryPathEntry(value, out.getFlags() & (~ICSettingEntry.RESOLVED)); + ICLibraryPathEntry lib = CDataUtil.createCLibraryPathEntry(value, out.getFlags() & (~ICSettingEntry.RESOLVED)); list.add(lib); } // Add 'libs' artifact names themselves - ICSettingEntry[] libFile = new ICSettingEntry[] {new CLibraryFileEntry(getArtifactName(), 0)}; - libFile = CDataUtil.resolveEntries(libFile, des); - list.add(libFile[0]); + ICSettingEntry[] unresolved = new ICSettingEntry[] {CDataUtil.createCLibraryFileEntry(getArtifactName(), 0)}; + ICSettingEntry[] libFiles = CDataUtil.resolveEntries(unresolved, des); + list.add(libFiles[0]); // Contribute the settings back as 'exported' des.createExternalSetting(null, null, null, list.toArray(new ICSettingEntry[list.size()])); 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 4d693cf33d8..42b787de15c 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 @@ -1,12 +1,12 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 Intel Corporation and others. + * Copyright (c) 2007, 2012 Intel Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Intel Corporation - Initial API and implementation + * Intel Corporation - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.settings.model; @@ -15,20 +15,51 @@ 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 { +/** + * Representation in the project model of library file settings entries. + * As an example, those are supplied by a gcc compiler with option "-l". + */ +public final class CLibraryFileEntry extends ACPathEntry implements ICLibraryFileEntry { private IPath fSourceAttachmentPath; private IPath fSourceAttachmentRootPath; private IPath fSourceAttachmentPrefixMapping; - public CLibraryFileEntry(String value, int flags) { - this(value, flags, null, null, null); + /** + * This constructor is discouraged to be referenced by clients. + * + * Instead, use pooled entries with CDataUtil.createCLibraryFileEntry(name, flags). + * + * @param name - library file path. The path can be an absolute location on the local file-system + * or with flag {@link #VALUE_WORKSPACE_PATH} it is treated as workspace full path. + * @param flags - bitwise combination of {@link ICSettingEntry} flags. + */ + public CLibraryFileEntry(String name, int flags) { + this(name, flags, null, null, null); } + /** + * This constructor is discouraged to be used directly. + * + * Instead, use pooled entries with CDataUtil.createCLibraryFileEntry(location.toString(), flags) + * or wrap it with CDataUtil.getPooledEntry(new CLibraryFileEntry(location, flags)). + * + * @param location - library file path. The path can be an absolute location on the local + * file-system or with flag {@link #VALUE_WORKSPACE_PATH} it is treated as workspace full path. + * @param flags - bitwise combination of {@link ICSettingEntry} flags. + */ public CLibraryFileEntry(IPath location, int flags) { this(location, flags, null, null, null); } + /** + * This constructor is discouraged to be used directly. + * + * Instead, use pooled entries wrapping with CDataUtil.getPooledEntry(new CLibraryFileEntry(rc, flags)). + * + * @param rc - library file as a resource in the workspace. + * @param flags - bitwise combination of {@link ICSettingEntry} flags. + * If {@link #VALUE_WORKSPACE_PATH} is missing it will be supplied. + */ public CLibraryFileEntry(IFile rc, int flags) { this(rc, flags, null, null, null); } diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CLibraryPathEntry.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CLibraryPathEntry.java index 90b832a5b09..62ef34e5d26 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CLibraryPathEntry.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/settings/model/CLibraryPathEntry.java @@ -1,29 +1,59 @@ /******************************************************************************* - * Copyright (c) 2007, 2008 Intel Corporation and others. + * Copyright (c) 2007, 2012 Intel Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: - * Intel Corporation - Initial API and implementation + * Intel Corporation - Initial API and implementation *******************************************************************************/ package org.eclipse.cdt.core.settings.model; import org.eclipse.core.resources.IFolder; import org.eclipse.core.runtime.IPath; -public final class CLibraryPathEntry extends ACPathEntry implements - ICLibraryPathEntry { - - public CLibraryPathEntry(String value, int flags) { - super(value, flags); +/** + * Representation in the project model of library path settings entries. + * As an example, those are supplied by a gcc compiler with option "-L". + */ +public final class CLibraryPathEntry extends ACPathEntry implements ICLibraryPathEntry { + /** + * This constructor is discouraged to be referenced by clients. + * + * Instead, use pooled entries with CDataUtil.createCLibraryPathEntry(name, flags). + * + * @param name - library path. The path can be an absolute location on the local file-system + * or with flag {@link #VALUE_WORKSPACE_PATH} it is treated as workspace full path. + * @param flags - bitwise combination of {@link ICSettingEntry} flags. + */ + public CLibraryPathEntry(String name, int flags) { + super(name, flags); } + /** + * This constructor is discouraged to be used directly. + * + * Instead, use pooled entries with CDataUtil.createCLibraryPathEntry(location.toString(), flags) + * or wrap it with CDataUtil.getPooledEntry(new CLibraryPathEntry(location, flags)). + * + * @param location - library path. The path can be an absolute location on the local + * file-system or with flag {@link #VALUE_WORKSPACE_PATH} it is treated as workspace full path. + * @param flags - bitwise combination of {@link ICSettingEntry} flags. + */ public CLibraryPathEntry(IPath location, int flags) { super(location, flags); } + /** + * This constructor is discouraged to be used directly. + * + * Instead, use pooled entries wrapping with CDataUtil.getPooledEntry(new CLibraryPathEntry(rc, flags)). + * + * @param rc - include path as a resource in the workspace. + * @param flags - bitwise combination of {@link ICSettingEntry} flags. + * If {@link #VALUE_WORKSPACE_PATH} is missing it will be supplied. + */ public CLibraryPathEntry(IFolder rc, int flags) { super(rc, flags); } 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 6103750e7e4..eda51685d14 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 @@ -419,6 +419,26 @@ public class CDataUtil { return (CMacroFileEntry) getPooledEntry(new CMacroFileEntry(name, flags)); } + /** + * Utility method to create {@link CLibraryPathEntry}. + * Note that this method keeps the entries in the pool to avoid proliferation of duplicates. + * + * @since 5.4 + */ + public static CLibraryPathEntry createCLibraryPathEntry(String name, int flags) { + return (CLibraryPathEntry) getPooledEntry(new CLibraryPathEntry(name, flags)); + } + + /** + * Utility method to create {@link CLibraryFileEntry}. + * Note that this method keeps the entries in the pool to avoid proliferation of duplicates. + * + * @since 5.4 + */ + public static CLibraryFileEntry createCLibraryFileEntry(String name, int flags) { + return (CLibraryFileEntry) getPooledEntry(new CLibraryFileEntry(name, flags)); + } + public static String[] getSourceExtensions(IProject project, CLanguageData data) { String[] exts = null; String[] typeIds = data.getSourceContentTypeIds(); diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpLibraryPathTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpLibraryPathTab.java index 2ff8f2d3fcf..38b551a6ca7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpLibraryPathTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpLibraryPathTab.java @@ -12,9 +12,9 @@ package org.eclipse.cdt.ui.newui; import org.eclipse.cdt.core.resources.IPathEntryStoreListener; import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; -import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; /** * @noextend This class is not intended to be subclassed by clients. @@ -29,7 +29,7 @@ public class ExpLibraryPathTab extends AbstractExportTab implements IPathEntrySt @Override public ICLanguageSettingEntry doAdd(String s1, String s2, boolean isWsp) { int flags = isWsp ? ICSettingEntry.VALUE_WORKSPACE_PATH : 0; - return new CLibraryPathEntry(s2, flags); + return CDataUtil.createCLibraryPathEntry(s2, flags); } @Override diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpLibraryTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpLibraryTab.java index 944bc892aab..b00c855a8ad 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpLibraryTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/ExpLibraryTab.java @@ -12,9 +12,9 @@ package org.eclipse.cdt.ui.newui; import org.eclipse.cdt.core.resources.IPathEntryStoreListener; import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; -import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; /** * @noextend This class is not intended to be subclassed by clients. @@ -29,7 +29,7 @@ public class ExpLibraryTab extends AbstractExportTab implements IPathEntryStoreL @Override public ICLanguageSettingEntry doAdd(String s1, String s2, boolean isWsp) { int flags = isWsp ? ICSettingEntry.VALUE_WORKSPACE_PATH : 0; - return new CLibraryFileEntry(s2, flags); + return CDataUtil.createCLibraryFileEntry(s2, flags); } @Override diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryPathTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryPathTab.java index f1b7cbbf7af..4dd400bb576 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryPathTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryPathTab.java @@ -17,9 +17,9 @@ import org.eclipse.swt.widgets.TableColumn; import org.eclipse.cdt.core.resources.IPathEntryStoreListener; import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; -import org.eclipse.cdt.core.settings.model.CLibraryPathEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.internal.ui.newui.Messages; @@ -57,7 +57,7 @@ public class LibraryPathTab extends AbstractLangsListTab implements IPathEntrySt toAllLang = dlg.check3; int flags = 0; if (dlg.check2) flags = ICSettingEntry.VALUE_WORKSPACE_PATH; - return new CLibraryPathEntry(dlg.text1, flags); + return CDataUtil.createCLibraryPathEntry(dlg.text1, flags); } return null; } @@ -72,7 +72,7 @@ public class LibraryPathTab extends AbstractLangsListTab implements IPathEntrySt if (dlg.open() && dlg.text1.trim().length() > 0 ) { int flags = 0; if (dlg.check2) flags = ICSettingEntry.VALUE_WORKSPACE_PATH; - return new CLibraryPathEntry(dlg.text1, flags); + return CDataUtil.createCLibraryPathEntry(dlg.text1, flags); } return null; } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryTab.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryTab.java index 21105f5cf76..ea8f9113628 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryTab.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/LibraryTab.java @@ -16,9 +16,9 @@ import org.eclipse.swt.widgets.TableColumn; import org.eclipse.cdt.core.resources.IPathEntryStoreListener; import org.eclipse.cdt.core.resources.PathEntryStoreChangedEvent; -import org.eclipse.cdt.core.settings.model.CLibraryFileEntry; import org.eclipse.cdt.core.settings.model.ICLanguageSettingEntry; import org.eclipse.cdt.core.settings.model.ICSettingEntry; +import org.eclipse.cdt.core.settings.model.util.CDataUtil; import org.eclipse.cdt.internal.ui.newui.Messages; @@ -59,7 +59,7 @@ public class LibraryTab extends AbstractLangsListTab implements IPathEntryStoreL toAllLang = dlg.check3; int flags = 0; if (dlg.check2) flags = ICSettingEntry.VALUE_WORKSPACE_PATH; - return new CLibraryFileEntry(dlg.text1, flags); + return CDataUtil.createCLibraryFileEntry(dlg.text1, flags); } return null; } @@ -76,7 +76,7 @@ public class LibraryTab extends AbstractLangsListTab implements IPathEntryStoreL if (dlg.open() && dlg.text1.trim().length() > 0 ) { int flags = 0; if (dlg.check2) flags = ICSettingEntry.VALUE_WORKSPACE_PATH; - return new CLibraryFileEntry(dlg.text1, flags); + return CDataUtil.createCLibraryFileEntry(dlg.text1, flags); } return null; }