mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
bug 166092 - users should be able to pass in own linkage factory mappings
This commit is contained in:
parent
4c5225719b
commit
716d881e6b
10 changed files with 57 additions and 50 deletions
|
@ -35,6 +35,7 @@ import org.eclipse.cdt.core.index.URIRelativeLocationConverter;
|
|||
import org.eclipse.cdt.core.index.export.ExternalExportProjectProvider;
|
||||
import org.eclipse.cdt.core.index.export.IExportProjectProvider;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.CTestPlugin;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
|
@ -107,7 +108,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider3.class.getName()
|
||||
});
|
||||
assertTrue(target.exists());
|
||||
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI));
|
||||
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI), LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
verifyProject1Content(wpdom);
|
||||
|
||||
String fid= wpdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||
|
@ -122,7 +123,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
GeneratePDOMApplication.OPT_PROJECTPROVIDER, TestProjectProvider4.class.getName()
|
||||
});
|
||||
assertTrue(target.exists());
|
||||
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI));
|
||||
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI), LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
verifyProject1Content(wpdom);
|
||||
|
||||
String fid= wpdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||
|
@ -187,7 +188,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
});
|
||||
assertTrue(target.exists());
|
||||
|
||||
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI));
|
||||
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI), LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
verifyProject1Content(wpdom);
|
||||
|
||||
String fid= wpdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||
|
@ -219,7 +220,7 @@ public class GeneratePDOMApplicationTest extends PDOMTestBase {
|
|||
});
|
||||
assertTrue(target.exists());
|
||||
|
||||
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI));
|
||||
WritablePDOM wpdom= new WritablePDOM(target, new URIRelativeLocationConverter(baseURI), LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
verifyProject2Content(wpdom);
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.dom.IPDOMManager;
|
|||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||
import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
import org.eclipse.cdt.core.testplugin.util.BaseTestCase;
|
||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||
|
@ -95,7 +96,7 @@ public class PDOMBugsTest extends BaseTestCase {
|
|||
final PDOMManager pdomManager = CCoreInternals.getPDOMManager();
|
||||
pdomManager.exportProjectPDOM(cproject, tmp, cvr);
|
||||
|
||||
IWritableIndexFragment pdom = new WritablePDOM(tmp, cvr, new ChunkCache());
|
||||
IWritableIndexFragment pdom = new WritablePDOM(tmp, cvr, new ChunkCache(), LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
pdom.acquireReadLock();
|
||||
try {
|
||||
String id= pdom.getProperty(IIndexFragment.PROPERTY_FRAGMENT_ID);
|
||||
|
|
|
@ -27,6 +27,7 @@ import org.eclipse.cdt.core.index.URIRelativeLocationConverter;
|
|||
import org.eclipse.cdt.core.index.provider.IPDOMDescriptor;
|
||||
import org.eclipse.cdt.core.index.provider.IReadOnlyPDOMProvider;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.testplugin.CProjectHelper;
|
||||
|
@ -231,7 +232,7 @@ public class PDOMProviderTests extends PDOMTestBase {
|
|||
CProjectHelper.delete(cproject);
|
||||
|
||||
// mimic a pdom with superceded version
|
||||
WritablePDOM wpdom= new WritablePDOM(tempPDOM, cvr);
|
||||
WritablePDOM wpdom= new WritablePDOM(tempPDOM, cvr, LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
wpdom.acquireWriteLock();
|
||||
try {
|
||||
wpdom.getDB().setVersion(1);
|
||||
|
|
|
@ -15,6 +15,7 @@
|
|||
package org.eclipse.cdt.core.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
@ -294,38 +295,36 @@ public class LanguageManager {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns a factory for the given linkage ID. The IDs are defined in {@link ILinkage}.
|
||||
* @param linkageID an ID for a linkage.
|
||||
* @return a factory or <code>null</code>.
|
||||
* Returns mappings between IDs and IPDOMLinkageFactory. The IDs are defined in {@link ILinkage}.
|
||||
* @return a map.
|
||||
* @since 4.0
|
||||
*/
|
||||
public IPDOMLinkageFactory getPDOMLinkageFactory(String linkageID) {
|
||||
final IPDOMLinkageFactory[] result= new IPDOMLinkageFactory[] {null};
|
||||
result[0]= (IPDOMLinkageFactory) fPDOMLinkageFactoryCache.get(linkageID);
|
||||
|
||||
if (result[0] == null) {
|
||||
// read configuration
|
||||
IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
|
||||
for (int i = 0; result[0] == null && i < configs.length; i++) {
|
||||
final IConfigurationElement element = configs[i];
|
||||
if (ELEMENT_PDOM_LINKAGE_FACTORY.equals(element.getName())) {
|
||||
if (linkageID.equals(element.getAttribute(ATTRIBUTE_ID))) {
|
||||
SafeRunner.run(new ISafeRunnable(){
|
||||
public void handleException(Throwable exception) {
|
||||
CCorePlugin.log(exception);
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
result[0]= (IPDOMLinkageFactory) element.createExecutableExtension(ATTRIBUTE_CLASS);
|
||||
}}
|
||||
);
|
||||
public Map getPDOMLinkageFactoryMappings() {
|
||||
if (!fPDOMLinkageFactoryCache.isEmpty())
|
||||
return Collections.unmodifiableMap(fPDOMLinkageFactoryCache);
|
||||
|
||||
fPDOMLinkageFactoryCache.clear();
|
||||
final IPDOMLinkageFactory[] result = new IPDOMLinkageFactory[] {null};
|
||||
|
||||
// read configuration
|
||||
IConfigurationElement[] configs= Platform.getExtensionRegistry().getConfigurationElementsFor(LANGUAGE_EXTENSION_POINT_ID);
|
||||
for (int i = 0; i < configs.length; i++) {
|
||||
final IConfigurationElement element = configs[i];
|
||||
if (ELEMENT_PDOM_LINKAGE_FACTORY.equals(element.getName())) {
|
||||
SafeRunner.run(new ISafeRunnable(){
|
||||
public void handleException(Throwable exception) {
|
||||
CCorePlugin.log(exception);
|
||||
}
|
||||
}
|
||||
}
|
||||
fPDOMLinkageFactoryCache.put(linkageID, result[0]);
|
||||
}
|
||||
return result[0];
|
||||
}
|
||||
|
||||
public void run() throws Exception {
|
||||
result[0] = (IPDOMLinkageFactory) element.createExecutableExtension(ATTRIBUTE_CLASS);
|
||||
}}
|
||||
);
|
||||
fPDOMLinkageFactoryCache.put(element.getAttribute(ATTRIBUTE_ID), result[0]);
|
||||
}
|
||||
}
|
||||
return Collections.unmodifiableMap(fPDOMLinkageFactoryCache);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all of the languages registered with the <code>Platform</code>.
|
||||
|
|
|
@ -19,6 +19,7 @@ import java.util.Set;
|
|||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.internal.core.pdom.PDOM;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
@ -69,7 +70,7 @@ class PDOMCache {
|
|||
}
|
||||
if(result==null) {
|
||||
try {
|
||||
result = new PDOM(file, converter);
|
||||
result = new PDOM(file, converter, LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
|
||||
result.acquireReadLock();
|
||||
try {
|
||||
|
|
|
@ -40,7 +40,6 @@ import org.eclipse.cdt.core.index.IIndexLinkage;
|
|||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||
import org.eclipse.cdt.core.index.IIndexName;
|
||||
import org.eclipse.cdt.core.index.IndexFilter;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragment;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentBinding;
|
||||
import org.eclipse.cdt.internal.core.index.IIndexFragmentFile;
|
||||
|
@ -114,12 +113,14 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
private Map fLinkageIDCache = new HashMap();
|
||||
private File fPath;
|
||||
private IIndexLocationConverter locationConverter;
|
||||
private Map fPDOMLinkageFactoryCache;
|
||||
|
||||
public PDOM(File dbPath, IIndexLocationConverter locationConverter) throws CoreException {
|
||||
this(dbPath, locationConverter, ChunkCache.getSharedInstance());
|
||||
public PDOM(File dbPath, IIndexLocationConverter locationConverter, Map linkageFactoryMappings) throws CoreException {
|
||||
this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings);
|
||||
}
|
||||
|
||||
public PDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache) throws CoreException {
|
||||
public PDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache, Map linkageFactoryMappings) throws CoreException {
|
||||
fPDOMLinkageFactoryCache = linkageFactoryMappings;
|
||||
loadDatabase(dbPath, cache);
|
||||
this.locationConverter = locationConverter;
|
||||
}
|
||||
|
@ -421,7 +422,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
int record= getFirstLinkageRecord();
|
||||
while (record != 0) {
|
||||
String linkageID= PDOMLinkage.getId(this, record).getString();
|
||||
IPDOMLinkageFactory factory= LanguageManager.getInstance().getPDOMLinkageFactory(linkageID);
|
||||
IPDOMLinkageFactory factory= (IPDOMLinkageFactory) fPDOMLinkageFactoryCache.get(linkageID);
|
||||
if (factory != null) {
|
||||
PDOMLinkage linkage= factory.getLinkage(this, record);
|
||||
fLinkageIDCache.put(linkageID, linkage);
|
||||
|
@ -438,7 +439,7 @@ public class PDOM extends PlatformObject implements IIndexFragment, IPDOM {
|
|||
PDOMLinkage pdomLinkage= (PDOMLinkage) fLinkageIDCache.get(linkageID);
|
||||
if (pdomLinkage == null) {
|
||||
// Need to create it
|
||||
IPDOMLinkageFactory factory= LanguageManager.getInstance().getPDOMLinkageFactory(linkageID);
|
||||
IPDOMLinkageFactory factory= (IPDOMLinkageFactory) fPDOMLinkageFactoryCache.get(linkageID);
|
||||
if (factory != null) {
|
||||
return factory.createLinkage(this);
|
||||
}
|
||||
|
|
|
@ -248,7 +248,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
fromScratch= true;
|
||||
}
|
||||
|
||||
pdom= new WritablePDOM(dbFile, new PDOMProjectIndexLocationConverter(rproject));
|
||||
pdom= new WritablePDOM(dbFile, new PDOMProjectIndexLocationConverter(rproject), LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
if (pdom.versionMismatch() || fromScratch) {
|
||||
try {
|
||||
pdom.acquireWriteLock();
|
||||
|
@ -966,7 +966,7 @@ public class PDOMManager implements IWritableIndexManager, IListener {
|
|||
}
|
||||
|
||||
// overwrite internal location representations
|
||||
final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter());
|
||||
final WritablePDOM newPDOM = new WritablePDOM(targetLocation, pdom.getLocationConverter(), LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
try {
|
||||
newPDOM.acquireWriteLock();
|
||||
try {
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||
import org.eclipse.cdt.core.index.ResourceContainerRelativeLocationConverter;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||
import org.eclipse.cdt.internal.core.index.IndexFileLocation;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
||||
|
@ -95,7 +96,7 @@ public class TeamPDOMExportOperation implements IWorkspaceRunnable {
|
|||
monitor.worked(5);
|
||||
|
||||
// create checksums
|
||||
PDOM pdom= new PDOM(tmpPDOM, converter);
|
||||
PDOM pdom= new PDOM(tmpPDOM, converter, LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
try {
|
||||
monitor.setTaskName(Messages.Checksums_taskComputeChecksums);
|
||||
createChecksums(fProject, pdom, tmpChecksums, subMonitor(monitor, 94));
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.text.MessageFormat;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.dom.ast.IASTName;
|
||||
|
@ -38,12 +39,12 @@ public class WritablePDOM extends PDOM implements IWritableIndexFragment {
|
|||
private boolean fClearedBecauseOfVersionMismatch= false;
|
||||
private boolean fCreatedFromScratch= false;
|
||||
|
||||
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter) throws CoreException {
|
||||
this(dbPath, locationConverter, ChunkCache.getSharedInstance());
|
||||
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, Map linkageFactoryMappings) throws CoreException {
|
||||
this(dbPath, locationConverter, ChunkCache.getSharedInstance(), linkageFactoryMappings);
|
||||
}
|
||||
|
||||
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache) throws CoreException {
|
||||
super(dbPath, locationConverter, cache);
|
||||
public WritablePDOM(File dbPath, IIndexLocationConverter locationConverter, ChunkCache cache, Map linkageFactoryMappings) throws CoreException {
|
||||
super(dbPath, locationConverter, cache, linkageFactoryMappings);
|
||||
}
|
||||
|
||||
public IIndexFragmentFile addFile(IIndexFileLocation location) throws CoreException {
|
||||
|
|
|
@ -19,6 +19,7 @@ import org.eclipse.cdt.core.CCorePlugin;
|
|||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||
import org.eclipse.cdt.core.index.export.IExportProjectProvider;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.LanguageManager;
|
||||
import org.eclipse.cdt.internal.core.CCoreInternals;
|
||||
import org.eclipse.cdt.internal.core.pdom.WritablePDOM;
|
||||
import org.eclipse.cdt.internal.core.pdom.indexer.IndexerPreferences;
|
||||
|
@ -67,7 +68,7 @@ public class GeneratePDOM implements ISafeRunnable {
|
|||
|
||||
try {
|
||||
CCoreInternals.getPDOMManager().exportProjectPDOM(cproject, targetLocation, converter);
|
||||
WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter);
|
||||
WritablePDOM exportedPDOM= new WritablePDOM(targetLocation, converter, LanguageManager.getInstance().getPDOMLinkageFactoryMappings());
|
||||
|
||||
exportedPDOM.acquireWriteLock(0);
|
||||
try {
|
||||
|
|
Loading…
Add table
Reference in a new issue