mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Work to take advantage of the ICDescriptor manager
the Core Model is now a listener to this manager.
This commit is contained in:
parent
b3f004b2a3
commit
7c03999239
6 changed files with 163 additions and 11 deletions
|
@ -1,3 +1,13 @@
|
|||
2004-03-17 Alain Magloire
|
||||
|
||||
Put the framework in to take advantage of being a
|
||||
listener to the ICDescriptor Manager.
|
||||
|
||||
* model/org/eclipse/cdt/core/model/CoreModel.java
|
||||
* model/org/eclipse/cdt/core/internal/core/model/CModelManager.java
|
||||
* src/org/eclipse/cdt/core/BinaryParserConfig.java
|
||||
* src/org/eclipse/cdt/core/CCorePlugin.java
|
||||
|
||||
2004-03-17 David Inglis
|
||||
|
||||
- Added new ICDescriptorManager providing listerner abilities on ICDescriptor and batch operations
|
||||
|
|
|
@ -5,6 +5,8 @@ package org.eclipse.cdt.core.model;
|
|||
*/
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CDescriptorEvent;
|
||||
import org.eclipse.cdt.core.ICDescriptorListener;
|
||||
import org.eclipse.cdt.internal.core.model.BatchOperation;
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
import org.eclipse.cdt.internal.core.model.ContainerEntry;
|
||||
|
@ -26,7 +28,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public class CoreModel {
|
||||
public class CoreModel implements ICDescriptorListener {
|
||||
|
||||
private static CoreModel cmodel = null;
|
||||
private static CModelManager manager = null;
|
||||
|
@ -679,6 +681,13 @@ public class CoreModel {
|
|||
manager.addElementChangedListener(listener);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.ICDescriptorListener#descriptorChanged(org.eclipse.cdt.core.CDescriptorEvent)
|
||||
*/
|
||||
public void descriptorChanged(CDescriptorEvent event) {
|
||||
manager.descriptorChanged(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the given element changed listener. Has no affect if an
|
||||
* identical listener is not registered.
|
||||
|
|
|
@ -13,10 +13,14 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.BinaryParserConfig;
|
||||
import org.eclipse.cdt.core.CCProjectNature;
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.CDescriptorEvent;
|
||||
import org.eclipse.cdt.core.CProjectNature;
|
||||
import org.eclipse.cdt.core.IBinaryParser;
|
||||
import org.eclipse.cdt.core.ICDescriptor;
|
||||
import org.eclipse.cdt.core.ICDescriptorListener;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryArchive;
|
||||
import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
|
@ -47,7 +51,7 @@ import org.eclipse.core.runtime.CoreException;
|
|||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
|
||||
public class CModelManager implements IResourceChangeListener {
|
||||
public class CModelManager implements IResourceChangeListener, ICDescriptorListener {
|
||||
|
||||
/**
|
||||
* Unique handle onto the CModel
|
||||
|
@ -394,11 +398,11 @@ public class CModelManager implements IResourceChangeListener {
|
|||
removeInfo(celement);
|
||||
}
|
||||
|
||||
public IBinaryParser[] getBinaryParser(IProject project) {
|
||||
public BinaryParserConfig[] getBinaryParser(IProject project) {
|
||||
try {
|
||||
IBinaryParser[] parsers = (IBinaryParser[])binaryParsersMap.get(project);
|
||||
BinaryParserConfig[] parsers = (BinaryParserConfig[])binaryParsersMap.get(project);
|
||||
if (parsers == null) {
|
||||
parsers = CCorePlugin.getDefault().getBinaryParser(project);
|
||||
parsers = CCorePlugin.getDefault().getBinaryParserConfigs(project);
|
||||
}
|
||||
if (parsers != null) {
|
||||
binaryParsersMap.put(project, parsers);
|
||||
|
@ -406,14 +410,17 @@ public class CModelManager implements IResourceChangeListener {
|
|||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
return new IBinaryParser[] {new NullBinaryParser()};
|
||||
IBinaryParser nullParser = new NullBinaryParser();
|
||||
BinaryParserConfig config = new BinaryParserConfig(nullParser, ""); //$NON-NLS-1$
|
||||
BinaryParserConfig[] configs = new BinaryParserConfig[] {config};
|
||||
return configs;
|
||||
}
|
||||
|
||||
public IBinaryFile createBinaryFile(IFile file) {
|
||||
IBinaryParser[] parsers = getBinaryParser(file.getProject());
|
||||
BinaryParserConfig[] parsers = getBinaryParser(file.getProject());
|
||||
int hints = 0;
|
||||
for (int i = 0; i < parsers.length; i++) {
|
||||
IBinaryParser parser = parsers[i];
|
||||
IBinaryParser parser = parsers[i].getBinaryParser();
|
||||
if (parser.getHintBufferSize() > hints) {
|
||||
hints = parser.getHintBufferSize();
|
||||
}
|
||||
|
@ -440,7 +447,7 @@ public class CModelManager implements IResourceChangeListener {
|
|||
|
||||
for (int i = 0; i < parsers.length; i++) {
|
||||
try {
|
||||
IBinaryFile bin = parsers[i].getBinary(bytes, location);
|
||||
IBinaryFile bin = parsers[i].getBinaryParser().getBinary(bytes, location);
|
||||
if (bin != null) {
|
||||
return bin;
|
||||
}
|
||||
|
@ -749,6 +756,37 @@ public class CModelManager implements IResourceChangeListener {
|
|||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.ICDescriptorListener#descriptorChanged(org.eclipse.cdt.core.CDescriptorEvent)
|
||||
*/
|
||||
public void descriptorChanged(CDescriptorEvent event) {
|
||||
/* int flags = event.getFlags();
|
||||
if ((flags & CDescriptorEvent.EXTENSION_CHANGED) != 0) {
|
||||
ICDescriptor cdesc = event.getDescriptor();
|
||||
if (cdesc != null) {
|
||||
IProject project = cdesc.getProject();
|
||||
try {
|
||||
String[] newIds = CCorePlugin.getDefault().getBinaryParserIds(project);
|
||||
BinaryParserConfig[] currentConfigs = getBinaryParser(project);
|
||||
// anything added/removed
|
||||
if (newIds.length != currentConfigs.length) {
|
||||
resetBinaryParser(project);
|
||||
} else { // may reorder
|
||||
for (int i = 0; i < newIds.length; i++) {
|
||||
String id = newIds[i];
|
||||
if (!id.equals(currentConfigs)) {
|
||||
resetBinaryParser(project);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
*/ }
|
||||
|
||||
/**
|
||||
* Fire C Model deltas, flushing them after the fact.
|
||||
* If the firing mode has been turned off, this has no effect.
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
/**********************************************************************
|
||||
* Copyright (c) 2002,2003,2004 QNX Software Systems and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Common Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/cpl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* QNX Software Systems - Initial API and implementation
|
||||
***********************************************************************/
|
||||
package org.eclipse.cdt.core;
|
||||
|
||||
/*
|
||||
* BinaryParserConfig
|
||||
*/
|
||||
public class BinaryParserConfig {
|
||||
|
||||
IBinaryParser parser;
|
||||
String id;
|
||||
|
||||
public BinaryParserConfig(IBinaryParser parser, String id) {
|
||||
this.parser = parser;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public IBinaryParser getBinaryParser() {
|
||||
return parser;
|
||||
}
|
||||
}
|
|
@ -240,6 +240,10 @@ public class CCorePlugin extends Plugin {
|
|||
fDescriptorManager = new CDescriptorManager();
|
||||
fDescriptorManager.startup();
|
||||
|
||||
// Register the Core Model on the Descriptor
|
||||
// Manager, it needs to know about changes.
|
||||
fDescriptorManager.addDescriptorListener(fCoreModel);
|
||||
|
||||
// Set the default for using the structual parse mode to build the CModel
|
||||
getPluginPreferences().setDefault(PREF_USE_STRUCTURAL_PARSE_MODE, false);
|
||||
|
||||
|
@ -487,6 +491,65 @@ public class CCorePlugin extends Plugin {
|
|||
return getConsole(null);
|
||||
}
|
||||
|
||||
public BinaryParserConfig[] getBinaryParserConfigs(IProject project) throws CoreException {
|
||||
BinaryParserConfig configs[] = null;
|
||||
if (project != null) {
|
||||
try {
|
||||
ICDescriptor cdesc = getCProjectDescription(project);
|
||||
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
|
||||
if (cextensions.length > 0) {
|
||||
ArrayList list = new ArrayList(cextensions.length);
|
||||
for (int i = 0; i < cextensions.length; i++) {
|
||||
IBinaryParser parser = null;
|
||||
try {
|
||||
parser = (IBinaryParser) cextensions[i].createExtension();
|
||||
} catch (ClassCastException e) {
|
||||
//
|
||||
}
|
||||
if (parser != null) {
|
||||
BinaryParserConfig config = new BinaryParserConfig(parser, cextensions[i].getID());
|
||||
list.add(config);
|
||||
}
|
||||
}
|
||||
configs = new BinaryParserConfig[list.size()];
|
||||
list.toArray(configs);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
if (configs == null) {
|
||||
IBinaryParser parser = getDefaultBinaryParser();
|
||||
if (parser != null) {
|
||||
BinaryParserConfig config = new BinaryParserConfig(parser, DEFAULT_BINARY_PARSER_UNIQ_ID);
|
||||
configs = new BinaryParserConfig[] {config};
|
||||
}
|
||||
}
|
||||
return configs;
|
||||
}
|
||||
|
||||
public String[] getBinaryParserIds(IProject project) throws CoreException {
|
||||
String ids[] = null;
|
||||
if (project != null) {
|
||||
try {
|
||||
ICDescriptor cdesc = getCProjectDescription(project);
|
||||
ICExtensionReference[] cextensions = cdesc.get(BINARY_PARSER_UNIQ_ID, true);
|
||||
if (cextensions.length > 0) {
|
||||
ArrayList list = new ArrayList(cextensions.length);
|
||||
for (int i = 0; i < cextensions.length; i++) {
|
||||
list.add(cextensions[i].getID());
|
||||
}
|
||||
ids = new String[list.size()];
|
||||
list.toArray(ids);
|
||||
}
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
}
|
||||
if (ids == null) {
|
||||
ids = new String[] {DEFAULT_BINARY_PARSER_UNIQ_ID};
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
public IBinaryParser[] getBinaryParser(IProject project) throws CoreException {
|
||||
IBinaryParser parsers[] = null;
|
||||
if (project != null) {
|
||||
|
|
|
@ -19,7 +19,6 @@ import org.eclipse.cdt.core.IBinaryParser.IBinaryFile;
|
|||
import org.eclipse.cdt.core.IBinaryParser.IBinaryObject;
|
||||
import org.eclipse.cdt.utils.BinaryFile;
|
||||
import org.eclipse.cdt.utils.elf.AR;
|
||||
import org.eclipse.cdt.utils.elf.Elf.Attribute;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue