From 7c039992391517263b94ce8f13bb68a3ea647bb9 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Wed, 17 Mar 2004 21:12:43 +0000 Subject: [PATCH] Work to take advantage of the ICDescriptor manager the Core Model is now a listener to this manager. --- core/org.eclipse.cdt.core/ChangeLog | 10 +++ .../org/eclipse/cdt/core/model/CoreModel.java | 11 +++- .../internal/core/model/CModelManager.java | 54 ++++++++++++--- .../eclipse/cdt/core/BinaryParserConfig.java | 33 ++++++++++ .../src/org/eclipse/cdt/core/CCorePlugin.java | 65 ++++++++++++++++++- .../cdt/utils/elf/parser/BinaryArchive.java | 1 - 6 files changed, 163 insertions(+), 11 deletions(-) create mode 100644 core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/BinaryParserConfig.java diff --git a/core/org.eclipse.cdt.core/ChangeLog b/core/org.eclipse.cdt.core/ChangeLog index b38df8f08f9..b757b1f41ce 100644 --- a/core/org.eclipse.cdt.core/ChangeLog +++ b/core/org.eclipse.cdt.core/ChangeLog @@ -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 diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java index 98385bd117e..3d89c48b5ae 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/core/model/CoreModel.java @@ -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. diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java index ce75f1e6c79..07c76441341 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/model/CModelManager.java @@ -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. diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/BinaryParserConfig.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/BinaryParserConfig.java new file mode 100644 index 00000000000..1abc848e38f --- /dev/null +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/BinaryParserConfig.java @@ -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; + } +} diff --git a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java index 1a865ad8e9b..3a6f53909e7 100644 --- a/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java +++ b/core/org.eclipse.cdt.core/src/org/eclipse/cdt/core/CCorePlugin.java @@ -239,7 +239,11 @@ 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) { diff --git a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java index 397fa6d19d5..69d8dd8a384 100644 --- a/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java +++ b/core/org.eclipse.cdt.core/utils/org/eclipse/cdt/utils/elf/parser/BinaryArchive.java @@ -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; /**